picopng does not support big-endian CPUs

Antony Pavlov antonynpavlov at gmail.com
Sun Jan 25 10:26:29 PST 2015


Hi All!

Current lib/gui/picopng.c has problems on big-endian CPUs.

Here are two examples from PNG_readPngHeader():

	if (*(uint64_t *) in != PNG_SIGNATURE) {
...
	if (*(uint32_t *) &in[12] != CHUNK_IHDR) {


Using memcmp in this situation is much better, e.g.

+	uint8_t png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
...
+	if (memcmp(in, png_signature, 8)) {


+	uint8_t chunk_header[4] = {0x49, 0x48, 0x44, 0x52};
...
+	if (memcmp(&in[12], chunk_header, 4)) {


Current lodepng works fine on big-endian, but can we disable picopng
in Kconfig for big-endian CPUs?

On mips I have CPU_BIG_ENDIAN option, so I can add
'depends on !CPU_BIG_ENDIAN' to lib/gui/Kconfig, e.g.

 config PICOPNG
+	depends on !CPU_BIG_ENDIAN
 	bool "picoPNG"

-- 
Best regards,
  Antony Pavlov



More information about the barebox mailing list