[1/2] apps: common: dng_writer: Fix thumbnail generation on BE machines
diff mbox series

Message ID 20240628213535.6906-2-laurent.pinchart@ideasonboard.com
State New
Headers show
Series
  • apps: common: dng_write: Endianness fixes
Related show

Commit Message

Laurent Pinchart June 28, 2024, 9:35 p.m. UTC
The 16-bit padded raw 10 and raw 12 formats are stored in memory in
little endian order, regardless of the machine's endianness. Swap the
16-bit values on big-endian machines when reading pixels from memory to
generate thumbnails.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/apps/common/dng_writer.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Umang Jain June 30, 2024, 4:55 a.m. UTC | #1
Hi Laurent,

Thank you for the patch

On 29/06/24 3:05 am, Laurent Pinchart wrote:
> The 16-bit padded raw 10 and raw 12 formats are stored in memory in
> little endian order, regardless of the machine's endianness. Swap the
> 16-bit values on big-endian machines when reading pixels from memory to
> generate thumbnails.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

LGTM,

Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
> ---
>   src/apps/common/dng_writer.cpp | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/apps/common/dng_writer.cpp b/src/apps/common/dng_writer.cpp
> index 9241f23fb806..50db5eb33c83 100644
> --- a/src/apps/common/dng_writer.cpp
> +++ b/src/apps/common/dng_writer.cpp
> @@ -8,6 +8,7 @@
>   #include "dng_writer.h"
>   
>   #include <algorithm>
> +#include <endian.h>
>   #include <iostream>
>   #include <map>
>   
> @@ -185,7 +186,8 @@ void thumbScanlineRaw(const FormatInfo &info, void *output, const void *input,
>   
>   	/* Simple averaging that produces greyscale RGB values. */
>   	for (unsigned int x = 0; x < width; x++) {
> -		uint16_t value = (in[0] + in[1] + in2[0] + in2[1]) >> 2;
> +		uint16_t value = (le16toh(in[0]) + le16toh(in[1]) +
> +				  le16toh(in2[0]) + le16toh(in2[1])) >> 2;
>   		value = value >> shift;
>   		*out++ = value;
>   		*out++ = value;
Stefan Klug July 1, 2024, 7:21 a.m. UTC | #2
Hi Laurent,

Thanks for the patch.

On Sat, Jun 29, 2024 at 12:35:34AM +0300, Laurent Pinchart wrote:
> The 16-bit padded raw 10 and raw 12 formats are stored in memory in
> little endian order, regardless of the machine's endianness. Swap the
> 16-bit values on big-endian machines when reading pixels from memory to
> generate thumbnails.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> 

Regards,
Stefan

> ---
>  src/apps/common/dng_writer.cpp | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/src/apps/common/dng_writer.cpp b/src/apps/common/dng_writer.cpp
> index 9241f23fb806..50db5eb33c83 100644
> --- a/src/apps/common/dng_writer.cpp
> +++ b/src/apps/common/dng_writer.cpp
> @@ -8,6 +8,7 @@
>  #include "dng_writer.h"
>  
>  #include <algorithm>
> +#include <endian.h>
>  #include <iostream>
>  #include <map>
>  
> @@ -185,7 +186,8 @@ void thumbScanlineRaw(const FormatInfo &info, void *output, const void *input,
>  
>  	/* Simple averaging that produces greyscale RGB values. */
>  	for (unsigned int x = 0; x < width; x++) {
> -		uint16_t value = (in[0] + in[1] + in2[0] + in2[1]) >> 2;
> +		uint16_t value = (le16toh(in[0]) + le16toh(in[1]) +
> +				  le16toh(in2[0]) + le16toh(in2[1])) >> 2;
>  		value = value >> shift;
>  		*out++ = value;
>  		*out++ = value;
> -- 
> Regards,
> 
> Laurent Pinchart
>
Laurent Pinchart July 1, 2024, 7:29 a.m. UTC | #3
On Mon, Jul 01, 2024 at 09:21:08AM +0200, Stefan Klug wrote:
> Hi Laurent,
> 
> Thanks for the patch.
> 
> On Sat, Jun 29, 2024 at 12:35:34AM +0300, Laurent Pinchart wrote:
> > The 16-bit padded raw 10 and raw 12 formats are stored in memory in
> > little endian order, regardless of the machine's endianness. Swap the
> > 16-bit values on big-endian machines when reading pixels from memory to
> > generate thumbnails.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> 

Did you mean Reviewed-by ?

> > ---
> >  src/apps/common/dng_writer.cpp | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/src/apps/common/dng_writer.cpp b/src/apps/common/dng_writer.cpp
> > index 9241f23fb806..50db5eb33c83 100644
> > --- a/src/apps/common/dng_writer.cpp
> > +++ b/src/apps/common/dng_writer.cpp
> > @@ -8,6 +8,7 @@
> >  #include "dng_writer.h"
> >  
> >  #include <algorithm>
> > +#include <endian.h>
> >  #include <iostream>
> >  #include <map>
> >  
> > @@ -185,7 +186,8 @@ void thumbScanlineRaw(const FormatInfo &info, void *output, const void *input,
> >  
> >  	/* Simple averaging that produces greyscale RGB values. */
> >  	for (unsigned int x = 0; x < width; x++) {
> > -		uint16_t value = (in[0] + in[1] + in2[0] + in2[1]) >> 2;
> > +		uint16_t value = (le16toh(in[0]) + le16toh(in[1]) +
> > +				  le16toh(in2[0]) + le16toh(in2[1])) >> 2;
> >  		value = value >> shift;
> >  		*out++ = value;
> >  		*out++ = value;
Stefan Klug July 1, 2024, 8:35 a.m. UTC | #4
On Mon, Jul 01, 2024 at 10:29:06AM +0300, Laurent Pinchart wrote:
> On Mon, Jul 01, 2024 at 09:21:08AM +0200, Stefan Klug wrote:
> > Hi Laurent,
> > 
> > Thanks for the patch.
> > 
> > On Sat, Jun 29, 2024 at 12:35:34AM +0300, Laurent Pinchart wrote:
> > > The 16-bit padded raw 10 and raw 12 formats are stored in memory in
> > > little endian order, regardless of the machine's endianness. Swap the
> > > 16-bit values on big-endian machines when reading pixels from memory to
> > > generate thumbnails.
> > > 
> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > 
> > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> 
> 
> Did you mean Reviewed-by ?

Oh, monday morning... yes, that was meant to be
Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com> 

Regards,
Stefan

> 
> > > ---
> > >  src/apps/common/dng_writer.cpp | 4 +++-
> > >  1 file changed, 3 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/src/apps/common/dng_writer.cpp b/src/apps/common/dng_writer.cpp
> > > index 9241f23fb806..50db5eb33c83 100644
> > > --- a/src/apps/common/dng_writer.cpp
> > > +++ b/src/apps/common/dng_writer.cpp
> > > @@ -8,6 +8,7 @@
> > >  #include "dng_writer.h"
> > >  
> > >  #include <algorithm>
> > > +#include <endian.h>
> > >  #include <iostream>
> > >  #include <map>
> > >  
> > > @@ -185,7 +186,8 @@ void thumbScanlineRaw(const FormatInfo &info, void *output, const void *input,
> > >  
> > >  	/* Simple averaging that produces greyscale RGB values. */
> > >  	for (unsigned int x = 0; x < width; x++) {
> > > -		uint16_t value = (in[0] + in[1] + in2[0] + in2[1]) >> 2;
> > > +		uint16_t value = (le16toh(in[0]) + le16toh(in[1]) +
> > > +				  le16toh(in2[0]) + le16toh(in2[1])) >> 2;
> > >  		value = value >> shift;
> > >  		*out++ = value;
> > >  		*out++ = value;
> 
> -- 
> Regards,
> 
> Laurent Pinchart

Patch
diff mbox series

diff --git a/src/apps/common/dng_writer.cpp b/src/apps/common/dng_writer.cpp
index 9241f23fb806..50db5eb33c83 100644
--- a/src/apps/common/dng_writer.cpp
+++ b/src/apps/common/dng_writer.cpp
@@ -8,6 +8,7 @@ 
 #include "dng_writer.h"
 
 #include <algorithm>
+#include <endian.h>
 #include <iostream>
 #include <map>
 
@@ -185,7 +186,8 @@  void thumbScanlineRaw(const FormatInfo &info, void *output, const void *input,
 
 	/* Simple averaging that produces greyscale RGB values. */
 	for (unsigned int x = 0; x < width; x++) {
-		uint16_t value = (in[0] + in[1] + in2[0] + in2[1]) >> 2;
+		uint16_t value = (le16toh(in[0]) + le16toh(in[1]) +
+				  le16toh(in2[0]) + le16toh(in2[1])) >> 2;
 		value = value >> shift;
 		*out++ = value;
 		*out++ = value;