Lines Matching refs:zlib
2010 struct zlib struct
2040 zlib_flevel(struct zlib *zlib) in zlib_flevel() argument
2042 switch (zlib->header[1] >> 6) in zlib_flevel()
2055 zlib_rc(struct zlib *zlib) in zlib_rc() argument
2058 switch (zlib->rc) in zlib_rc()
2074 zlib_message(struct zlib *zlib, int unexpected) in zlib_message() argument
2077 if (zlib->global->errors) in zlib_message()
2079 const char *reason = zlib->z.msg; in zlib_message()
2084 fputs(zlib->file->file_name, stderr); in zlib_message()
2086 type_name(zlib->chunk->chunk_type, stderr); in zlib_message()
2088 unexpected ? "unexpected " : "", zlib->rc, zlib_rc(zlib), reason); in zlib_message()
2093 zlib_end(struct zlib *zlib) in zlib_end() argument
2098 if (!zlib->global->quiet) in zlib_end()
2100 if (zlib->ok_bits < 16) /* stream was read ok */ in zlib_end()
2104 if (zlib->cksum) in zlib_end()
2107 else if (zlib->ok_bits > zlib->file_bits) in zlib_end()
2110 else if (zlib->ok_bits == zlib->file_bits) in zlib_end()
2120 type_name(zlib->chunk->chunk_type, stdout); in zlib_end()
2121 printf(" %s %s %d %d ", reason, zlib_flevel(zlib), zlib->file_bits, in zlib_end()
2122 zlib->ok_bits); in zlib_end()
2123 uarb_print(zlib->compressed_bytes, zlib->compressed_digits, stdout); in zlib_end()
2125 uarb_print(zlib->uncompressed_bytes, zlib->uncompressed_digits, in zlib_end()
2128 fputs(zlib->file->file_name, stdout); in zlib_end()
2145 type_name(zlib->chunk->chunk_type, stdout); in zlib_end()
2146 printf(" SKP %s %d %s ", zlib_flevel(zlib), zlib->file_bits, in zlib_end()
2147 zlib_rc(zlib)); in zlib_end()
2148 uarb_print(zlib->compressed_bytes, zlib->compressed_digits, stdout); in zlib_end()
2150 emit_string(zlib->z.msg ? zlib->z.msg : "[no_message]", stdout); in zlib_end()
2152 fputs(zlib->file->file_name, stdout); in zlib_end()
2157 if (zlib->state >= 0) in zlib_end()
2159 zlib->rc = inflateEnd(&zlib->z); in zlib_end()
2161 if (zlib->rc != Z_OK) in zlib_end()
2162 zlib_message(zlib, 1/*unexpected*/); in zlib_end()
2165 CLEAR(*zlib); in zlib_end()
2169 zlib_reset(struct zlib *zlib, int window_bits) in zlib_reset() argument
2172 assert(zlib->state >= 0); /* initialized by zlib_init */ in zlib_reset()
2174 zlib->z.next_in = Z_NULL; in zlib_reset()
2175 zlib->z.avail_in = 0; in zlib_reset()
2176 zlib->z.next_out = Z_NULL; in zlib_reset()
2177 zlib->z.avail_out = 0; in zlib_reset()
2179 zlib->window_bits = window_bits; in zlib_reset()
2180 zlib->compressed_digits = 0; in zlib_reset()
2181 zlib->uncompressed_digits = 0; in zlib_reset()
2183 zlib->state = 0; /* initialized, once */ in zlib_reset()
2184 zlib->rc = inflateReset2(&zlib->z, 0); in zlib_reset()
2185 if (zlib->rc != Z_OK) in zlib_reset()
2187 zlib_message(zlib, 1/*unexpected*/); in zlib_reset()
2195 zlib_init(struct zlib *zlib, struct IDAT *idat, struct chunk *chunk, in zlib_init() argument
2199 CLEAR(*zlib); in zlib_init()
2201 zlib->idat = idat; in zlib_init()
2202 zlib->chunk = chunk; in zlib_init()
2203 zlib->file = chunk->file; in zlib_init()
2204 zlib->global = chunk->global; in zlib_init()
2205 zlib->rewrite_offset = offset; /* never changed for this zlib */ in zlib_init()
2208 zlib->z.next_in = Z_NULL; in zlib_init()
2209 zlib->z.avail_in = 0; in zlib_init()
2210 zlib->z.zalloc = Z_NULL; in zlib_init()
2211 zlib->z.zfree = Z_NULL; in zlib_init()
2212 zlib->z.opaque = Z_NULL; in zlib_init()
2214 zlib->state = -1; in zlib_init()
2215 zlib->window_bits = window_bits; in zlib_init()
2217 zlib->compressed_digits = 0; in zlib_init()
2218 zlib->uncompressed_digits = 0; in zlib_init()
2223 zlib->file_bits = 24; in zlib_init()
2224 zlib->ok_bits = 16; /* unset */ in zlib_init()
2225 zlib->cksum = 0; /* set when a checksum error is detected */ in zlib_init()
2230 zlib->rc = inflateInit2(&zlib->z, 0); in zlib_init()
2231 if (zlib->rc != Z_OK) in zlib_init()
2233 zlib_message(zlib, 1/*unexpected*/); in zlib_init()
2239 zlib->state = 0; /* initialized */ in zlib_init()
2266 zlib_advance(struct zlib *zlib, png_uint_32 nbytes) in zlib_advance() argument
2282 int state = zlib->state; in zlib_advance()
2285 struct file *file = zlib->file; in zlib_advance()
2301 int new_bits = zlib->window_bits; in zlib_advance()
2303 zlib->file_bits = file_bits; in zlib_advance()
2311 zlib->window_bits = ((file_bits > 15) ? 15 : file_bits); in zlib_advance()
2317 zlib->header[0] = bIn; in zlib_advance()
2318 zlib->state = state = 1; in zlib_advance()
2326 b2 += 0x1f - ((zlib->header[0] << 8) + b2) % 0x1f; in zlib_advance()
2334 if (zlib->file_bits == zlib->window_bits) in zlib_advance()
2335 zlib->cksum = 1; in zlib_advance()
2341 zlib->header[1] = bIn; in zlib_advance()
2342 zlib->state = state = 2; in zlib_advance()
2355 zlib->z.next_in = &bIn; in zlib_advance()
2356 zlib->z.avail_in = 1; in zlib_advance()
2357 zlib->z.next_out = &bOut; in zlib_advance()
2358 zlib->z.avail_out = 0; /* Initially */ in zlib_advance()
2371 zlib->z.next_out = &bOut, in zlib_advance()
2372 zlib->z.avail_out = 1, in zlib_advance()
2375 zlib->rc = inflate(&zlib->z, flush); in zlib_advance()
2376 out_bytes -= zlib->z.avail_out; in zlib_advance()
2378 switch (zlib->rc) in zlib_advance()
2381 if (zlib->z.avail_out == 0) in zlib_advance()
2384 if (zlib->z.avail_in == 0) in zlib_advance()
2390 zlib_message(zlib, 1/*unexpected*/); in zlib_advance()
2396 assert(zlib->z.avail_out == 0 || zlib->z.avail_in == 0); in zlib_advance()
2401 zlib->state = 3; /* end of stream */ in zlib_advance()
2406 zlib_message(zlib, 0/*stream error*/); in zlib_advance()
2412 if (zlib->z.msg != NULL && in zlib_advance()
2413 strcmp(zlib->z.msg, "invalid distance too far back") == 0) in zlib_advance()
2421 zlib_message(zlib, 0/*stream error*/); in zlib_advance()
2433 zlib->uncompressed_digits = uarb_add32(zlib->uncompressed_bytes, in zlib_advance()
2434 zlib->uncompressed_digits, out_bytes); in zlib_advance()
2440 assert(zlib->z.avail_in == 0 || endrc != ZLIB_OK); in zlib_advance()
2442 in_bytes += 1 - zlib->z.avail_in; in zlib_advance()
2448 zlib->compressed_digits = uarb_add32(zlib->compressed_bytes, in zlib_advance()
2449 zlib->compressed_digits, in_bytes - zlib->z.avail_in); in zlib_advance()
2454 if (endrc == ZLIB_STREAM_END && zlib->window_bits < zlib->ok_bits) in zlib_advance()
2456 struct chunk *chunk = zlib->chunk; in zlib_advance()
2459 zlib->uncompressed_bytes, zlib->uncompressed_digits); in zlib_advance()
2461 zlib->compressed_bytes, zlib->compressed_digits); in zlib_advance()
2462 chunk->rewrite_buffer[0] = zlib->header[0]; in zlib_advance()
2463 chunk->rewrite_buffer[1] = zlib->header[1]; in zlib_advance()
2465 if (zlib->window_bits != zlib->file_bits || zlib->cksum) in zlib_advance()
2468 chunk->rewrite_offset = zlib->rewrite_offset; in zlib_advance()
2481 zlib->extra_bytes = nbytes - in_bytes; in zlib_advance()
2482 zlib->ok_bits = zlib->window_bits; in zlib_advance()
2489 zlib_run(struct zlib *zlib) in zlib_run() argument
2499 zlib->extra_bytes = 0; in zlib_run()
2501 if (zlib->idat != NULL) in zlib_run()
2503 struct IDAT_list *list = zlib->idat->idat_list_head; in zlib_run()
2504 struct IDAT_list *last = zlib->idat->idat_list_tail; in zlib_run()
2510 assert(zlib->rewrite_offset == 0); in zlib_run()
2525 skip_12(zlib->file); in zlib_run()
2529 rc = zlib_advance(zlib, list->lengths[i]); in zlib_run()
2541 if (zlib->global->errors && zlib->extra_bytes == 0) in zlib_run()
2551 chunk_message(zlib->chunk, in zlib_run()
2569 list->lengths[i] -= zlib->extra_bytes; in zlib_run()
2571 zlib->idat->idat_list_tail = list; in zlib_run()
2589 struct chunk *chunk = zlib->chunk; in zlib_run()
2592 assert(zlib->rewrite_offset < chunk->chunk_length); in zlib_run()
2594 rc = zlib_advance(zlib, chunk->chunk_length - zlib->rewrite_offset); in zlib_run()
2601 chunk->chunk_length -= zlib->extra_bytes; in zlib_run()
2622 struct zlib zlib; in zlib_check() local
2628 if (zlib_init(&zlib, file->idat, file->chunk, 0/*window bits*/, offset)) in zlib_check()
2633 rc = zlib_run(&zlib); in zlib_check()
2640 min_bits = zlib.window_bits + 1; in zlib_check()
2645 if (!zlib.global->optimize_zlib && in zlib_check()
2646 zlib.window_bits == zlib.file_bits && !zlib.cksum) in zlib_check()
2651 zlib_end(&zlib); in zlib_check()
2655 max_bits = max_window_bits(zlib.uncompressed_bytes, in zlib_check()
2656 zlib.uncompressed_digits); in zlib_check()
2657 if (zlib.ok_bits < max_bits) in zlib_check()
2658 max_bits = zlib.ok_bits; in zlib_check()
2666 if (zlib.cksum) in zlib_check()
2667 chunk_message(zlib.chunk, "zlib checkum"); in zlib_check()
2673 zlib.z.msg = PNGZ_MSG_CAST("[truncated]"); in zlib_check()
2674 zlib_message(&zlib, 0/*expected*/); in zlib_check()
2681 zlib_end(&zlib); in zlib_check()
2689 while (min_bits < max_bits || max_bits < zlib.ok_bits/*if 16*/) in zlib_check()
2693 if (zlib_reset(&zlib, test_bits)) in zlib_check()
2696 rc = zlib_run(&zlib); in zlib_check()
2711 if (zlib.z.msg == NULL) in zlib_check()
2712 zlib.z.msg = PNGZ_MSG_CAST( in zlib_check()
2714 zlib_message(&zlib, 0/*stream error*/); in zlib_check()
2715 zlib_end(&zlib); in zlib_check()
2729 zlib_end(&zlib); in zlib_check()
2736 zlib_end(&zlib); in zlib_check()
2742 assert(zlib.ok_bits == max_bits); in zlib_check()
2743 zlib_end(&zlib); in zlib_check()
2749 zlib_end(&zlib); in zlib_check()