Giter VIP home page Giter VIP logo

Comments (6)

mo271 avatar mo271 commented on June 13, 2024

Thanks for bringing this up. Could you point to the file where something fails?!

from libjxl.

nnphongphu avatar nnphongphu commented on June 13, 2024

Thanks for bringing this up. Could you point to the file where something fails?!

// IDAT
WriteU32BE(dst, idat_size);
WriteU32(dst, 0x54414449);
size_t offset = 0;
size_t bytes_to_next_row = 0;
uint32_t adler_s1 = 1;
uint32_t adler_s2 = 0;
WriteU8(dst, 0x08); // CM = 8 (deflate), CINFO = 0 (window size = 2**(0+8))
WriteU8(dst, 29); // FCHECK; (FCHECK + 256* CMF) % 31 = 0
for (size_t i = 0; i < num_deflate_blocks; ++i) {
size_t block_size = data_size - offset;
if (block_size > kMaxDeflateBlock) {
block_size = kMaxDeflateBlock;
}
bool is_last = ((i + 1) == num_deflate_blocks);
WriteU8(dst, is_last); // btype = 00 (uncompressed)
offset += block_size;
WriteU16(dst, block_size);
WriteU16(dst, ~block_size);
while (block_size > 0) {
if (bytes_to_next_row == 0) {
WriteU8(dst, 0); // filter: raw
adler_s2 += adler_s1;
bytes_to_next_row = row_size;
block_size--;
continue;
}
size_t bytes_to_copy = std::min(block_size, bytes_to_next_row);
AdlerCopy(input, dst, bytes_to_copy, &adler_s1, &adler_s2);
dst += bytes_to_copy;
input += bytes_to_copy;
block_size -= bytes_to_copy;
bytes_to_next_row -= bytes_to_copy;
}
}
// Fake Adler works well in Chrome; so let's not waste CPU cycles.
uint32_t adler = 0; // (adler_s2 << 8) | adler_s1;
WriteU32BE(dst, adler);
WriteU32BE(dst, 0); // Fake CRC32
// IEND
WriteU32BE(dst, 0);
chunk_start = dst;
WriteU32(dst, 0x444E4549);
// TODO(eustas): this is fixed value; precalculate?
crc32 = CalculateCrc32(chunk_start, dst);
WriteU32BE(dst, crc32);

I think it's somewhere here. I checked the output png file with pngcheck and the output is something like this:

File: image.png (4917485 bytes)
chunk IHDR at offset 0x0000c, length 13
1280 x 1280 image, 24-bit RGB, non-interlaced
chunk iCCP at offset 0x00025, length 550
profile name = 1, compression method = 0 (deflate)
compressed profile = 547 bytes
chunk IDAT at offset 0x00257, length 4916866
zlib: deflated, 256-byte window, superfast compression
CRC error in chunk IDAT (computed 33609e4c, expected 00000000)
ERRORS DETECTED in image.png

from libjxl.

nnphongphu avatar nnphongphu commented on June 13, 2024

It's definitely because of the Fake CRC32 at the end of IDAT. Fixed it. But would it cost much performance-wise?

from libjxl.

mo271 avatar mo271 commented on June 13, 2024

@eustas probably can give you an answer

Can this be closed?

from libjxl.

eustas avatar eustas commented on June 13, 2024

IIRC we had that checksum calculation in the past, but removed it for the sake of performance.
I can re-add it as a build option. That way "careless" browsers will be able to get max performance, while others will not fail.
Ping me regularly to make that happen, please.

from libjxl.

jonsneyers avatar jonsneyers commented on June 13, 2024

It would be more useful to make this a runtime thing, and have some detection code to test whether correct CRCs are needed or not, computing them only when needed. There's no point in a wasm polyfill that doesn't work on some browsers...

from libjxl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.