Discussion:
[PATCH] Swap bytes in 16-bit PNGs, because PNG is big-endian.
Add Reply
Aaron Muir Hamilton
2017-04-16 00:27:54 UTC
Reply
Permalink
Raw Message
---
frontend/scanimage.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/frontend/scanimage.c b/frontend/scanimage.c
index 77c2288..d719c4b 100644
--- a/frontend/scanimage.c
+++ b/frontend/scanimage.c
@@ -1529,6 +1529,19 @@ scan_it (FILE *ofp)
for(j = 0; j < parm.bytes_per_line; j++)
pngbuf[j] = ~pngbuf[j];
}
+ /* PNG is big-endian, */
+ /* see: https://www.w3.org/TR/2003/REC-PNG-20031110/#7Integers-and-byte-order */
+ if (parm.depth == 16)
+ {
+ int j;
+ for (j = 0; j < parm.bytes_per_line; j += 2)
+ {
+ SANE_Byte LSB;
+ LSB = pngbuf[j];
+ pngbuf[j] = pngbuf[j + 1];
+ pngbuf[j + 1] = LSB;
+ }
+ }
png_write_row(png_ptr, pngbuf);
i += parm.bytes_per_line - pngrow;
left -= parm.bytes_per_line - pngrow;
--
1.8.3.1
--
sane-devel mailing list: sane-***@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel
Unsubscribe: Send mail with subject "unsubscribe your_password"
to sane-devel-***@lists.alioth.debian.org
a***@correspondwith.me
2017-04-16 00:27:54 UTC
Reply
Permalink
Raw Message
---
frontend/scanimage.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/frontend/scanimage.c b/frontend/scanimage.c
index 77c2288..961ca49 100644
--- a/frontend/scanimage.c
+++ b/frontend/scanimage.c
@@ -1529,6 +1529,19 @@ scan_it (FILE *ofp)
for(j = 0; j < parm.bytes_per_line; j++)
pngbuf[j] = ~pngbuf[j];
}
+ /* PNG is big-endian, */
+ /* see: https://www.w3.org/TR/2003/REC-PNG-20031110/#7Integers-and-byte-order */
+ if (parm.depth == 16)
+ {
+ int j;
+ for (j = 0; j < parm.bytes_per_line; j += 2)
+ {
+ SANE_Byte LSB;
+ LSB = pngbuf[j];
+ pngbuf[j] = pngbuf[j + 1];
+ pngbuf[j + 1] = LSB;
+ }
+ }
png_write_row(png_ptr, pngbuf);
i += parm.bytes_per_line - pngrow;
left -= parm.bytes_per_line - pngrow;
--
1.8.3.1
--
sane-devel mailing list: sane-***@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel
Unsubscribe: Send mail with subject "unsubscribe your_password"
to sane-devel-***@lists.alioth.debian.org
Aaron Muir Hamilton
2017-04-16 00:27:54 UTC
Reply
Permalink
Raw Message
---
frontend/scanimage.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/frontend/scanimage.c b/frontend/scanimage.c
index 77c2288..0925039 100644
--- a/frontend/scanimage.c
+++ b/frontend/scanimage.c
@@ -1529,6 +1529,19 @@ scan_it (FILE *ofp)
for(j = 0; j < parm.bytes_per_line; j++)
pngbuf[j] = ~pngbuf[j];
}
+ /* PNG is big-endian */
+ /* see: https://www.w3.org/TR/2003/REC-PNG-20031110/#7Integers-and-byte-order */
+ if (parm.depth == 16)
+ {
+ int j;
+ for (j = 0; j < parm.bytes_per_line; j += 2)
+ {
+ SANE_Byte LSB;
+ LSB = pngbuf[j];
+ pngbuf[j] = pngbuf[j + 1];
+ pngbuf[j + 1] = LSB;
+ }
+ }
png_write_row(png_ptr, pngbuf);
i += parm.bytes_per_line - pngrow;
left -= parm.bytes_per_line - pngrow;
--
1.8.3.1
--
sane-devel mailing list: sane-***@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel
Unsubscribe: Send mail with subject "unsubscribe your_password"
to sane-devel-***@lists.alioth.debian.org
Aaron Muir Hamilton
2017-04-16 02:01:02 UTC
Reply
Permalink
Raw Message
Sorry about the volume, third time is definitely the charm.
Admittedly I struggled to grasp the style rules.

I noticed the PNG byte order issue fixed by this patch when using
genesys with a CanoScan LiDE 220. I do not have any other supported
scanners close at hand, so I hope somebody can confirm if this is an
issue specific to genesys. The TIFF 16-bit output already worked
correctly since TIFF is happy to be little-endian.

Cheers!
--
sane-devel mailing list: sane-***@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel
Unsubscribe: Send mail with subject "unsubscribe your_password"
to sane-devel-***@lists.alioth.debian.org
Loading...