Home | History | Annotate | Download | only in libtests

Lines Matching refs:pm

2500 static int fail(png_modifier *pm)
2502 return !pm->log && !pm->this.verbose && (pm->this.nerrors > 0 ||
2503 (pm->this.treat_warnings_as_errors && pm->this.nwarnings > 0));
2507 modifier_init(png_modifier *pm)
2509 memset(pm, 0, sizeof *pm);
2510 store_init(&pm->this);
2511 pm->modifications = NULL;
2512 pm->state = modifier_start;
2513 pm->sbitlow = 1U;
2514 pm->ngammas = 0;
2515 pm->ngamma_tests = 0;
2516 pm->gammas = 0;
2517 pm->current_gamma = 0;
2518 pm->encodings = 0;
2519 pm->nencodings = 0;
2520 pm->current_encoding = 0;
2521 pm->encoding_counter = 0;
2522 pm->encoding_ignored = 0;
2523 pm->repeat = 0;
2524 pm->test_uses_encoding = 0;
2525 pm->maxout8 = pm->maxpc8 = pm->maxabs8 = pm->maxcalc8 = 0;
2526 pm->maxout16 = pm->maxpc16 = pm->maxabs16 = pm->maxcalc16 = 0;
2527 pm->maxcalcG = 0;
2528 pm->limit = 4E-3;
2529 pm->log8 = pm->log16 = 0; /* Means 'off' */
2530 pm->error_gray_2 = pm->error_gray_4 = pm->error_gray_8 = 0;
2531 pm->error_gray_16 = pm->error_color_8 = pm->error_color_16 = 0;
2532 pm->error_indexed = 0;
2533 pm->use_update_info = 0;
2534 pm->interlace_type = PNG_INTERLACE_NONE;
2535 pm->test_standard = 0;
2536 pm->test_size = 0;
2537 pm->test_transform = 0;
2539 pm->test_tRNS = 1;
2541 pm->test_tRNS = 0;
2543 pm->use_input_precision = 0;
2544 pm->use_input_precision_sbit = 0;
2545 pm->use_input_precision_16to8 = 0;
2546 pm->calculations_use_input_precision = 0;
2547 pm->assume_16_bit_calculations = 0;
2548 pm->test_gamma_threshold = 0;
2549 pm->test_gamma_transform = 0;
2550 pm->test_gamma_sbit = 0;
2551 pm->test_gamma_scale16 = 0;
2552 pm->test_gamma_background = 0;
2553 pm->test_gamma_alpha_mode = 0;
2554 pm->test_gamma_expand16 = 0;
2555 pm->test_lbg = 1;
2556 pm->test_lbg_gamma_threshold = 1;
2557 pm->test_lbg_gamma_transform = 1;
2558 pm->test_lbg_gamma_sbit = 1;
2559 pm->test_lbg_gamma_composition = 1;
2560 pm->test_exhaustive = 0;
2561 pm->log = 0;
2575 /* If pm->calculations_use_input_precision is set then operations will happen
2578 * If pm->assume_16_bit_calculations is set then even 8 bit calculations use 16
2612 static double abserr(const png_modifier *pm, int in_depth, int out_depth)
2617 if (pm->assume_16_bit_calculations ||
2618 (pm->calculations_use_input_precision ? in_depth : out_depth) == 16)
2619 return pm->maxabs16;
2621 return pm->maxabs8;
2624 static double calcerr(const png_modifier *pm, int in_depth, int out_depth)
2629 if ((pm->calculations_use_input_precision ? in_depth : out_depth) == 16)
2630 return pm->maxcalc16;
2631 else if (pm->assume_16_bit_calculations)
2632 return pm->maxcalcG;
2634 return pm->maxcalc8;
2637 static double pcerr(const png_modifier *pm, int in_depth, int out_depth)
2642 if (pm->assume_16_bit_calculations ||
2643 (pm->calculations_use_input_precision ? in_depth : out_depth) == 16)
2644 return pm->maxpc16 * .01;
2646 return pm->maxpc8 * .01;
2660 static double outerr(const png_modifier *pm, int in_depth, int out_depth)
2675 if ((pm->calculations_use_input_precision ? in_depth : out_depth) == 16)
2676 return pm->maxout16;
2682 return pm->maxout8 * 257;
2685 return pm->maxout8;
2692 static double outlog(const png_modifier *pm, int in_depth, int out_depth)
2699 if (pm->log8 == 0) /* switched off */
2703 return pm
2705 return pm->log8;
2708 if ((pm->calculations_use_input_precision ? in_depth : out_depth) == 16)
2710 if (pm->log16 == 0)
2713 return pm->log16;
2719 if (pm->log8 == 0)
2722 return pm->log8 * 257;
2730 static int output_quantization_factor(const png_modifier *pm, int in_depth,
2734 pm->calculations_use_input_precision)
2756 int (*modify_fn)(struct png_modifier *pm,
2794 modifier_current_encoding(const png_modifier *pm, color_encoding *ce)
2796 if (pm->current_encoding != 0)
2797 *ce = *pm->current_encoding;
2802 ce->gamma = pm->current_gamma;
2809 const png_modifier *pm)
2811 pos = safecat_color_encoding(buffer, bufsize, pos, pm->current_encoding,
2812 pm->current_gamma);
2814 if (pm->encoding_ignored)
2839 modifier_total_encodings(const png_modifier *pm)
2842 pm->ngammas + /* (2) gamma values to test */
2843 pm->nencodings + /* (3) total number of encodings */
2852 ((pm->bit_depth == 16 || pm->assume_16_bit_calculations) ?
2853 pm->nencodings : 0); /* (4) encodings with gamma == 1.0 */
2857 modifier_encoding_iterate(png_modifier *pm)
2859 if (!pm->repeat && /* Else something needs the current encoding again. */
2860 pm->test_uses_encoding) /* Some transform is encoding dependent */
2862 if (pm->test_exhaustive)
2864 if (++pm->encoding_counter >= modifier_total_encodings(pm))
2865 pm->encoding_counter = 0; /* This will stop the repeat */
2873 if (pm->encoding_counter == 0)
2874 pm->encoding_counter = random_mod(modifier_total_encodings(pm)-1)+1;
2876 pm->encoding_counter = 0;
2879 if (pm->encoding_counter > 0)
2880 pm->repeat = 1;
2883 else if (!pm->repeat)
2884 pm->encoding_counter = 0;
2888 modifier_reset(png_modifier *pm)
2890 store_read_reset(&pm->this);
2891 pm->limit = 4E-3;
2892 pm->pending_len = pm->pending_chunk = 0;
2893 pm->flush = pm->buffer_count = pm->buffer_position = 0;
2894 pm->modifications = NULL;
2895 pm->state = modifier_start;
2896 modifier_encoding_iterate(pm);
2901 pm->test_uses_encoding = 0;
2902 pm->current_gamma = 0;
2903 pm->current_encoding = 0;
2904 pm->encoding_ignored = 0;
2906 pm->bit_depth = pm->colour_type = 0;
2914 modifier_set_encoding(png_modifier *pm)
2920 pm->current_gamma = 0;
2921 pm->current_encoding = 0;
2922 pm->encoding_ignored = 0; /* not ignored yet - happens in _ini functions. */
2925 if (pm->encoding_counter > 0)
2930 if (pm->encoding_counter <= pm->ngammas)
2931 pm->current_gamma = 1/pm->gammas[pm->encoding_counter-1];
2935 unsigned int i = pm->encoding_counter - pm->ngammas;
2937 if (i >= pm->nencodings)
2939 i %= pm->nencodings;
2940 pm->current_gamma = 1; /* Linear, only in the 16 bit case */
2944 pm->current_gamma = pm->encodings[i].gamma;
2946 pm->current_encoding = pm->encodings + i;
2955 modifier_color_encoding_is_sRGB(const png_modifier *pm)
2957 return pm->current_encoding != 0 && pm->current_encoding == pm->encodings &&
2958 pm->current_encoding->gamma == pm->current_gamma;
2962 modifier_color_encoding_is_set(const png_modifier *pm)
2964 return pm->current_gamma != 0;
2982 modifier_setbuffer(png_modifier *pm)
2984 modifier_crc(pm->buffer);
2985 pm->buffer_count = png_get_uint_32(pm->buffer)+12;
2986 pm->buffer_position = 0;
2994 modifier_read_imp(png_modifier *pm, png_bytep pb, png_size_t st)
3002 if (pm->buffer_position >= pm->buffer_count) switch (pm->state)
3006 store_read_chunk(&pm->this, pm->buffer, 8, 8); /* signature. */
3007 pm->buffer_count = 8;
3008 pm->buffer_position = 0;
3010 if (memcmp(pm->buffer, sign, 8) != 0)
3011 png_error(pm->this.pread, "invalid PNG file signature");
3012 pm->state = modifier_signature;
3016 store_read_chunk(&pm->this, pm->buffer, 13+12, 13+12); /* IHDR */
3017 pm->buffer_count = 13+12;
3018 pm->buffer_position = 0;
3020 if (png_get_uint_32(pm->buffer) != 13 ||
3021 png_get_uint_32(pm->buffer+4) != CHUNK_IHDR)
3022 png_error(pm->this.pread, "invalid IHDR");
3025 mod = pm->modifications;
3029 (*mod->modify_fn)(pm, mod, 0))
3032 modifier_setbuffer(pm);
3040 pm->bit_depth = pm->buffer[8+8];
3041 pm->colour_type = pm->buffer[8+8+1];
3043 pm->state = modifier_IHDR;
3044 pm->flush = 0;
3053 if ((cb = pm->flush) > 0)
3056 pm->flush -= cb;
3057 store_read_chunk(&pm->this, pb, cb, cb);
3066 if (pm->pending_chunk != 0)
3068 png_save_uint_32(pm->buffer, pm->pending_len);
3069 png_save_uint_32(pm->buffer+4, pm->pending_chunk);
3070 pm->pending_len = 0;
3071 pm->pending_chunk = 0;
3074 store_read_chunk(&pm->this, pm->buffer, 8, 8);
3076 pm->buffer_count = 8;
3077 pm->buffer_position = 0;
3080 len = png_get_uint_32(pm->buffer);
3081 chunk = png_get_uint_32(pm->buffer+4);
3089 mod = pm->modifications;
3102 if ((*mod->modify_fn)(pm, mod, 1 /*add*/))
3105 if (pm->buffer_count > 0)
3106 modifier_setbuffer(pm);
3110 pm->buffer_position = 0;
3117 pm->pending_len = len;
3118 pm->pending_chunk = chunk;
3138 if (len+12 <= sizeof pm->buffer)
3140 png_size_t s = len+12-pm->buffer_count;
3141 store_read_chunk(&pm->this, pm->buffer+pm->buffer_count, s, s);
3142 pm->buffer_count = len+12;
3145 mod = pm->modifications;
3153 pm->buffer_count = pm->buffer_position = 0;
3158 else if ((*mod->modify_fn)(pm, mod, 0))
3162 if (pm->buffer_count == 0)
3164 pm->buffer_position = 0;
3167 modifier_setbuffer(pm);
3176 pm->flush = len+12 - pm->buffer_count; /* data + crc */
3185 cb = pm->buffer_count - pm->buffer_position;
3190 memcpy(pb, pm->buffer + pm->buffer_position, cb);
3193 pm->buffer_position += cb;
3202 png_modifier *pm = voidcast(png_modifier*, png_get_io_ptr(pp));
3204 if (pm == NULL || pm->this.pread != pp)
3207 modifier_read_imp(pm, pb, st);
3214 pm, png_structp pp, png_infop pi)
3216 if (pm->this.pread != pp || pm->this.current == NULL ||
3217 pm->this.next == NULL)
3241 cbAvail = store_read_buffer_avail(&pm->this);
3242 if (pm->buffer_count > pm->buffer_position)
3243 cbAvail += pm->buffer_count - pm->buffer_position;
3254 modifier_read_imp(pm, buffer, cb);
3261 if (pm->buffer_count > pm->buffer_position ||
3262 pm->this.next != &pm->this.current->data ||
3263 pm->this.readpos < pm->this.current->datacount)
3269 set_modifier_for_read(png_modifier *pm, png_infopp ppi, png_uint_32 id,
3276 pm->state = modifier_start;
3277 pm->bit_depth = 0;
3278 pm->colour_type = 255;
3280 pm->pending_len = 0;
3281 pm->pending_chunk = 0;
3282 pm->flush = 0;
3283 pm->buffer_count = 0;
3284 pm->buffer_position = 0;
3286 return set_store_for_read(&pm->this, ppi, id, name);
3302 gama_modify(png_modifier *pm, png_modification *me, int add)
3306 png_save_uint_32(pm->buffer, 4);
3307 png_save_uint_32(pm->buffer+4, CHUNK_gAMA);
3308 png_save_uint_32(pm->buffer+8, ((gama_modification*)me)->gamma);
3313 gama_modification_init(gama_modification *me, png_modifier *pm, double gammad)
3323 me->this.next = pm->modifications;
3324 pm->modifications = &me->this;
3335 chrm_modify(png_modifier *pm, png_modification *me, int add)
3339 png_save_uint_32(pm->buffer , 32);
3340 png_save_uint_32(pm->buffer+ 4, CHUNK_cHRM);
3341 png_save_uint_32(pm->buffer+ 8, ((chrm_modification*)me)->wx);
3342 png_save_uint_32(pm->buffer+12, ((chrm_modification*)me)->wy);
3343 png_save_uint_32(pm->buffer+16, ((chrm_modification*)me)->rx);
3344 png_save_uint_32(pm->buffer+20, ((chrm_modification*)me)->ry);
3345 png_save_uint_32(pm->buffer+24, ((chrm_modification*)me)->gx);
3346 png_save_uint_32(pm->buffer+28, ((chrm_modification*)me)->gy);
3347 png_save_uint_32(pm->buffer+32, ((chrm_modification*)me)->bx);
3348 png_save_uint_32(pm->buffer+36, ((chrm_modification*)me)->by);
3353 chrm_modification_init(chrm_modification *me, png_modifier *pm,
3376 me->this.next = pm->modifications;
3377 pm->modifications = &me->this;
3387 srgb_modify(png_modifier *pm, png_modification *me, int add)
3391 png_save_uint_32(pm->buffer, 1);
3392 png_save_uint_32(pm->buffer+4, CHUNK_sRGB);
3393 pm->buffer[8] = ((srgb_modification*)me)->intent;
3398 srgb_modification_init(srgb_modification *me, png_modifier *pm, png_byte intent)
3417 me->this.next = pm->modifications;
3418 pm->modifications = &me->this;
3429 sbit_modify(png_modifier *pm, png_modification *me, int add)
3432 if (pm->bit_depth > sbit)
3435 switch (pm->colour_type)
3455 png_error(pm->this.pread,
3459 png_save_uint_32(pm->buffer, cb);
3460 png_save_uint_32(pm->buffer+4, CHUNK_sBIT);
3463 (pm->buffer+8)[--cb] = sbit;
3470 pm->buffer_count = pm->buffer_position = 0;
3478 sbit_modification_init(sbit_modification *me, png_modifier *pm, png_byte sbit)
3485 me->this.next = pm->modifications;
3486 pm->modifications = &me->this;
4269 make_transform_images(png_modifier *pm)
4276 safecat(pm->this.test, sizeof pm->this.test, 0, "make standard images");
4293 make_transform_image(&pm->this, colour_type, bit_depth, palette_number,
4778 make_errors(png_modifier* const pm, png_byte const colour_type,
4796 make_error(&pm->this, colour_type, DEPTH(bdlo), interlace_type,
4799 if (fail(pm))
4810 perform_error_test(png_modifier *pm)
4814 safecat(pm->this.test, sizeof pm->this.test, 0, "error test");
4816 if (!make_errors(pm, 0, 0, WRITE_BDHI))
4819 if (!make_errors(pm, 2, 3, WRITE_BDHI))
4822 if (!make_errors(pm, 3, 0, 3))
4825 if (!make_errors(pm, 4, 3, WRITE_BDHI))
4828 if (!make_errors(pm, 6, 3, WRITE_BDHI))
4831 UNUSED(pm)
5815 test_standard(png_modifier* const pm, png_byte const colour_type,
5825 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
5826 interlace_type, 0, 0, 0), do_read_interlace, pm->use_update_info);
5828 if (fail(pm))
5837 perform_standard_test(png_modifier *pm)
5842 if (!test_standard(pm, 0, 0, READ_BDHI))
5845 if (!test_standard(pm, 2, 3, READ_BDHI))
5848 if (!test_standard(pm, 3, 0, 3))
5851 if (!test_standard(pm, 4, 3, READ_BDHI))
5854 if (!test_standard(pm, 6, 3, READ_BDHI))
5861 test_size(png_modifier* const pm, png_byte const colour_type,
5886 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
5888 pm->use_update_info);
5890 if (fail(pm))
5893 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
5895 pm->use_update_info);
5897 if (fail(pm))
5904 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
5906 pm->use_update_info);
5908 if (fail(pm))
5913 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
5915 pm->use_update_info);
5917 if (fail(pm))
5939 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
5941 pm->use_update_info);
5943 if (fail(pm))
5950 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
5952 pm->use_update_info);
5954 if (fail(pm))
5961 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
5963 pm->use_update_info);
5965 if (fail(pm))
5976 perform_size_test(png_modifier *pm)
5981 if (!test_size(pm, 0, 0, READ_BDHI))
5984 if (!test_size(pm, 2, 3, READ_BDHI))
5991 if (!test_size(pm, 3, 0, 3))
5995 if (!test_size(pm, 4, 3, READ_BDHI))
5998 if (!test_size(pm, 6, 3, READ_BDHI))
6353 png_modifier* pm;
6375 png_modifier *pm = this->pm;
6377 modifier_set_encoding(pm);
6379 if (modifier_color_encoding_is_set(pm))
6381 if (modifier_color_encoding_is_sRGB(pm))
6382 srgb_modification_init(&this->srgb_mod, pm, PNG_sRGB_INTENT_ABSOLUTE);
6387 gama_modification_init(&this->gama_mod, pm, pm->current_gamma);
6389 if (pm->current_encoding != 0)
6390 chrm_modification_init(&this->chrm_mod, pm, pm->current_encoding);
6526 transform_display_init(transform_display *dp, png_modifier *pm, png_uint_32 id,
6532 standard_display_init(&dp->this, &pm->this, id, do_read_interlace,
6533 pm->use_update_info);
6536 dp->pm = pm;
6814 !dp->pm->calculations_use_input_precision)
6887 dp->pm->limit + 1./(2*((1U<<in_pixel.red_sBIT)-1)), "red/gray",
6894 dp->pm->limit + 1./(2*((1U<<in_pixel.green_sBIT)-1)), "green",
6901 dp->pm->limit + 1./(2*((1U<<in_pixel.blue_sBIT)-1)), "blue",
6908 dp->pm->limit + 1./(2*((1U<<in_pixel.alpha_sBIT)-1)), "alpha",
6957 pos = safecat_current_encoding(full_name, sizeof full_name, pos, d.pm);
6960 pp = set_modifier_for_read(d.pm, &pi, d.this.id, full_name);
6968 (void)store_message(&d.pm->this, pp, buffer, sizeof buffer, 0,
6976 if (d.pm->this.progressive)
6983 modifier_progressive_read(d.pm, pp, pi);
6988 png_set_read_fn(pp, d.pm, modifier_read);
7004 modifier_reset(d.pm);
7606 png_modifier *pm = that->pm;
7607 const color_encoding *e = pm->current_encoding;
7612 pm->test_uses_encoding = 1;
7650 data.gamma = pm->current_gamma;
7660 if (pm->test_exhaustive)
7667 pm->repeat = data.coefficients_overridden != 0;
7697 pm->encoding_ignored = 1;
7711 if (that->this.bit_depth == 16 || pm->assume_16_bit_calculations)
7726 that->pm->limit += pow(
7746 that->pm->limit += pow( 2.0/255, data.gamma);
7748 that->pm->limit += pow( 1.0/255, data.gamma);
7758 if (that->this.bit_depth != 16 && !pm->assume_16_bit_calculations)
7759 that->pm->limit += 4E-3;
7777 if (that->pm->current_encoding != 0)
7810 modifier_current_encoding(that->pm, &o);
7907 png_modifier *pm = display->pm;
7909 const unsigned int calc_depth = (pm->assume_16_bit_calculations ? 16 :
7914 (pm->assume_16_bit_calculations ?
8062 if (err > pm->limit)
8070 pos = safecatd(buffer, sizeof buffer, pos, pm->limit, 6);
8072 pm->limit = err;
8136 png_modifier *pm = display->pm;
8139 (pm->assume_16_bit_calculations ? .5/(1<<display->max_gamma_8) :
8190 if (err > pm->limit)
8198 pos = safecatd(buffer, sizeof buffer, pos, pm->limit, 6);
8200 pm->limit = err;
9158 perform_transform_test(png_modifier *pm)
9164 while (next_format(&colour_type, &bit_depth, &palette_number, pm->test_lbg,
9165 pm->test_tRNS))
9190 pm->repeat = 0;
9191 transform_test(pm, FILEID(colour_type, bit_depth, palette_number,
9192 pm->interlace_type, 0, 0, 0), list, name);
9194 if (fail(pm))
9197 while (pm->repeat);
9213 png_modifier* pm;
9234 gamma_display_init(gamma_display *dp, png_modifier *pm, png_uint_32 id,
9241 standard_display_init(&dp->this, &pm->this, id, do_read_interlace,
9242 pm->use_update_info);
9245 dp->pm = pm;
9459 vi->maxabs = abserr(dp->pm, in_depth, out_depth);
9460 vi->maxpc = pcerr(dp->pm, in_depth, out_depth);
9461 vi->maxcalc = calcerr(dp->pm, in_depth, out_depth);
9462 vi->maxout = outerr(dp->pm, in_depth, out_depth);
9463 vi->outquant = output_quantization_factor(dp->pm, in_depth, out_depth);
9465 vi->outlog = outlog(dp->pm, in_depth, out_depth);
10150 store_verbose(&vi->dp->pm->this, vi->pp, pass, msg);
10427 d.pm->encoding_counter = 0;
10428 modifier_set_encoding(d.pm); /* Just resets everything */
10429 d.pm->current_gamma = d.file_gamma;
10434 d.pm->modifications = NULL;
10435 gama_modification_init(&gama_mod, d.pm, d.file_gamma);
10436 srgb_modification_init(&srgb_mod, d.pm, 127 /*delete*/);
10438 sbit_modification_init(&sbit_mod, d.pm, d.sbit);
10440 modification_reset(d.pm->modifications);
10443 pp = set_modifier_for_read(d.pm, &pi, d.this.id, name);
10447 if (d.pm->this.progressive)
10454 modifier_progressive_read(d.pm, pp, pi);
10459 png_set_read_fn(pp, d.pm, modifier_read);
10475 modifier_reset(d.pm);
10477 if (d.pm->log && !d.threshold_test && !d.this.speed)
10491 if (d.maxerrout > d.pm->error_gray_2)
10492 d.pm->error_gray_2 = d.maxerrout;
10497 if (d.maxerrout > d.pm->error_gray_4)
10498 d.pm->error_gray_4 = d.maxerrout;
10503 if (d.maxerrout > d.pm->error_gray_8)
10504 d.pm->error_gray_8 = d.maxerrout;
10509 if (d.maxerrout > d.pm->error_gray_16)
10510 d.pm->error_gray_16 = d.maxerrout;
10525 if (d.maxerrout > d.pm->error_color_8)
10526 d.pm->error_color_8 = d.maxerrout;
10532 if (d.maxerrout > d.pm->error_color_16)
10533 d.pm->error_color_16 = d.maxerrout;
10544 if (d.maxerrout > d.pm->error_indexed)
10545 d.pm->error_indexed = d.maxerrout;
10553 static void gamma_threshold_test(png_modifier *pm, png_byte colour_type,
10564 (void)gamma_test(pm, colour_type, bit_depth, 0/*palette*/, interlace_type,
10572 perform_gamma_threshold_tests(png_modifier *pm)
10586 pm->test_lbg_gamma_threshold, pm->test_tRNS))
10595 gamma_threshold_test(pm, colour_type, bit_depth, pm->interlace_type,
10601 gamma_threshold_test(pm, colour_type, bit_depth, pm->interlace_type,
10604 if (fail(pm))
10609 static void gamma_transform_test(png_modifier *pm,
10636 gamma_test(pm, colour_type, bit_depth, palette_number, interlace_type,
10638 scale16, pm->test_gamma_expand16, 0 , 0, 0);
10641 static void perform_gamma_transform_tests(png_modifier *pm)
10648 pm->test_lbg_gamma_transform, pm->test_tRNS))
10652 for (i=0; i<pm->ngamma_tests; ++i) for (j=0; j<pm->ngamma_tests; ++j)
10655 gamma_transform_test(pm, colour_type, bit_depth, palette_number,
10656 pm->interlace_type, 1/pm->gammas[i], pm->gammas[j], 0/*sBIT*/,
10657 pm->use_input_precision, 0 /*do not scale16*/);
10659 if (fail(pm))
10665 static void perform_gamma_sbit_tests(png_modifier *pm)
10673 for (sbit=pm->sbitlow; sbit<(1<<READ_BDHI); ++sbit)
10679 pm->test_lbg_gamma_sbit, pm->test_tRNS))
10686 for (i=0; i<pm->ngamma_tests; ++i)
10690 for (j=0; j<pm->ngamma_tests; ++j) if (i != j)
10692 gamma_transform_test(pm, colour_type, bit_depth, npalette,
10693 pm->interlace_type, 1/pm->gammas[i], pm->gammas[j],
10694 sbit, pm->use_input_precision_sbit, 0 /*scale16*/);
10696 if (fail(pm))
10709 static void perform_gamma_scale16_tests(png_modifier *pm)
10728 for (i=0; i<pm->ngamma_tests; ++i)
10730 for (j=0; j<pm->ngamma_tests; ++j)
10733 fabs(pm->gammas[j]/pm->gammas[i]-1) >= PNG_GAMMA_THRESHOLD)
10735 gamma_transform_test(pm, 0, 16, 0, pm->interlace_type,
10736 1/pm->gammas[i], pm->gammas[j], SBIT_16_TO_8,
10737 pm->use_input_precision_16to8, 1 /*scale16*/);
10739 if (fail(pm))
10742 gamma_transform_test(pm, 2, 16, 0, pm->interlace_type,
10743 1/pm->gammas[i], pm->gammas[j], SBIT_16_TO_8,
10744 pm->use_input_precision_16to8, 1 /*scale16*/);
10746 if (fail(pm))
10749 gamma_transform_test(pm, 4, 16, 0, pm->interlace_type,
10750 1/pm->gammas[i], pm->gammas[j], SBIT_16_TO_8,
10751 pm->use_input_precision_16to8, 1 /*scale16*/);
10753 if (fail(pm))
10756 gamma_transform_test(pm, 6, 16, 0, pm->interlace_type,
10757 1/pm->gammas[i], pm->gammas[j], SBIT_16_TO_8,
10758 pm->use_input_precision_16to8, 1 /*scale16*/);
10760 if (fail(pm))
10770 static void gamma_composition_test(png_modifier *pm,
10917 gamma_test(pm, colour_type, bit_depth, palette_number, interlace_type,
10924 perform_gamma_composition_tests(png_modifier *pm, int do_background,
10938 pm->test_lbg_gamma_composition, pm->test_tRNS))
10949 for (i=0; i<pm->ngamma_tests; ++i) for (j=0; j<pm->ngamma_tests; ++j)
10951 gamma_composition_test(pm, colour_type, bit_depth, palette_number,
10952 pm->interlace_type, 1/pm->gammas[i], pm->gammas[j],
10953 pm->use_input_precision, do_background, expand_16);
10955 if (fail(pm))
10963 init_gamma_errors(png_modifier *pm)
10966 pm->error_gray_2 = pm->error_gray_4 = pm->error_gray_8 = -1.;
10967 pm->error_color_8 = -1.;
10968 pm->error_indexed = -1.;
10969 pm->error_gray_16 = pm->error_color_16 = -1.;
10980 summarize_gamma_errors(png_modifier *pm, png_const_charp who, int low_bit_depth,
10993 print_one(" 2 bit gray: ", pm->error_gray_2);
10994 print_one(" 4 bit gray: ", pm->error_gray_4);
10995 print_one(" 8 bit gray: ", pm->error_gray_8);
10996 print_one(" 8 bit color:", pm->error_color_8);
10998 print_one(" indexed: ", pm->error_indexed);
11001 print_one("16 bit gray: ", pm->error_gray_16);
11002 print_one("16 bit color:", pm->error_color_16);
11008 perform_gamma_test(png_modifier *pm, int summary)
11013 pm->calculations_use_input_precision;
11015 double maxout8 = pm->maxout8;
11019 if (!pm->this.speed && pm->test_gamma_threshold)
11021 perform_gamma_threshold_tests(pm);
11023 if (fail(pm))
11028 if (pm->test_gamma_transform)
11048 init_gamma_errors(pm);
11052 if (pm->test_gamma_expand16)
11053 pm->calculations_use_input_precision = 1;
11054 perform_gamma_transform_tests(pm);
11056 pm->calculations_use_input_precision = 0;
11059 summarize_gamma_errors(pm, 0/*who*/, 1/*low bit depth*/, 1/*indexed*/);
11061 if (fail(pm))
11066 if (pm->test_gamma_sbit)
11068 init_gamma_errors(pm);
11069 perform_gamma_sbit_tests(pm);
11072 summarize_gamma_errors(pm, "sBIT", pm->sbitlow < 8U, 1/*indexed*/);
11074 if (fail(pm))
11079 if (pm->test_gamma_scale16)
11082 init_gamma_errors(pm);
11083 perform_gamma_scale16_tests(pm);
11089 printf(" 16 bit gray: %.5f\n", pm->error_gray_16);
11090 printf(" 16 bit color: %.5f\n", pm->error_color_16);
11094 if (fail(pm))
11100 if (pm->test_gamma_background)
11102 init_gamma_errors(pm);
11107 if (pm->test_gamma_expand16)
11109 pm->calculations_use_input_precision = 1;
11110 pm->maxout8 = .499; /* because the 16 bit background is smashed */
11112 perform_gamma_composition_tests(pm, PNG_BACKGROUND_GAMMA_UNIQUE,
11113 pm->test_gamma_expand16);
11115 pm->calculations_use_input_precision = 0;
11116 pm->maxout8 = maxout8;
11119 summarize_gamma_errors(pm, "background", 1, 0/*indexed*/);
11121 if (fail(pm))
11127 if (pm->test_gamma_alpha_mode)
11131 init_gamma_errors(pm);
11136 if (pm->test_gamma_expand16)
11137 pm->calculations_use_input_precision = 1;
11139 do_background <= ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN && !fail(pm);
11141 perform_gamma_composition_tests(pm, do_background,
11142 pm->test_gamma_expand16);
11144 pm->calculations_use_input_precision = 0;
11147 summarize_gamma_errors(pm, "alpha mode", 1, 0/*indexed*/);
11149 if (fail(pm))
11563 static png_modifier pm;
11605 store_log(&pm.this, NULL/*png_structp*/, msg, 1/*error*/);
11613 &pm.this.exception_context;
11615 Throw &pm.this;
11643 anon_context(&pm.this);
11665 modifier_init(&pm);
11672 store_ensure_image(&pm.this, NULL, 2, TRANSFORM_ROWMAX, TRANSFORM_HEIGHTMAX);
11678 pm.this.treat_warnings_as_errors = 1;
11684 pm.assume_16_bit_calculations = PNG_LIBPNG_VER >= 10700;
11691 pm.calculations_use_input_precision = 1U;
11694 pm.gammas = gammas;
11695 pm.ngammas = ARRAY_SIZE(gammas);
11696 pm.ngamma_tests = 0; /* default to off */
11702 pm.test_tRNS = 1;
11704 pm.test_lbg = PNG_LIBPNG_VER >= 10600;
11705 pm.test_lbg_gamma_threshold = 1;
11706 pm.test_lbg_gamma_transform = PNG_LIBPNG_VER >= 10600;
11707 pm.test_lbg_gamma_sbit = 1;
11708 pm.test_lbg_gamma_composition = PNG_LIBPNG_VER >= 10700;
11711 pm.encodings = test_encodings;
11712 pm.nencodings = ARRAY_SIZE(test_encodings);
11715 pm.sbitlow = 8U; /* because libpng doesn't do sBIT below 8! */
11717 pm.sbitlow = 1U;
11727 pm.use_input_precision_16to8 = 1U;
11728 pm.use_input_precision_sbit = 1U; /* because libpng now rounds sBIT */
11737 pm.maxout8 = .1; /* Arithmetic error in *encoded* value */
11738 pm.maxabs8 = .00005; /* 1/20000 */
11739 pm.maxcalc8 = 1./255; /* +/-1 in 8 bits for compose errors */
11740 pm.maxpc8 = .499; /* I.e., .499% fractional error */
11741 pm.maxout16 = .499; /* Error in *encoded* value */
11742 pm.maxabs16 = .00005;/* 1/20000 */
11743 pm.maxcalc16 =1./65535;/* +/-1 in 16 bits for compose errors */
11745 pm.maxcalcG = 1./((1<<PNG_MAX_GAMMA_8)-1);
11747 pm.maxcalcG = 1./((1<<16)-1);
11758 pm.maxpc16 = .005; /* I.e., 1/200% - 1/20000 */
11770 pm.this.verbose = 1;
11773 pm.log = 1;
11776 summary = pm.this.verbose = pm.log = 0;
11780 pm.this.treat_warnings_as_errors = 1; /* NOTE: this is the default! */
11783 pm.this.treat_warnings_as_errors = 0;
11786 pm.this.speed = 1, pm.ngamma_tests = pm.ngammas, pm.test_standard = 0,
11793 pm.test_size = 1;
11796 pm.test_size = 0;
11799 pm.test_standard = 1;
11802 pm.test_standard = 0;
11805 pm.test_transform = 1;
11808 pm.test_transform = 0;
11814 pm.test_transform = 1;
11821 pm.test_transform = 1;
11829 pm.ngamma_tests = 2U;
11830 pm.test_gamma_threshold = 1;
11831 pm.test_gamma_transform = 1;
11832 pm.test_gamma_sbit = 1;
11833 pm.test_gamma_scale16 = 1;
11834 pm.test_gamma_background = 1; /* composition */
11835 pm.test_gamma_alpha_mode = 1;
11839 pm.ngamma_tests = 0;
11842 pm.ngamma_tests = 2U, pm.test_gamma_threshold = 1;
11845 pm.test_gamma_threshold = 0;
11848 pm.ngamma_tests = 2U, pm.test_gamma_transform = 1;
11851 pm.test_gamma_transform = 0;
11854 pm.ngamma_tests = 2U, pm.test_gamma_sbit = 1;
11857 pm.test_gamma_sbit = 0;
11860 pm.ngamma_tests = 2U, pm.test_gamma_scale16 = 1;
11863 pm.test_gamma_scale16 = 0;
11866 pm.ngamma_tests = 2U, pm.test_gamma_background = 1;
11869 pm.test_gamma_background = 0;
11872 pm.ngamma_tests = 2U, pm.test_gamma_alpha_mode = 1;
11875 pm.test_gamma_alpha_mode = 0;
11878 pm.test_gamma_expand16 = 1;
11881 pm.test_gamma_expand16 = 0;
11884 pm.test_lbg = pm.test_lbg_gamma_threshold =
11885 pm.test_lbg_gamma_transform = pm.test_lbg_gamma_sbit =
11886 pm.test_lbg_gamma_composition = 1;
11889 pm.test_lbg = pm.test_lbg_gamma_threshold =
11890 pm.test_lbg_gamma_transform = pm.test_lbg_gamma_sbit =
11891 pm.test_lbg_gamma_composition = 0;
11895 pm.test_tRNS = 1;
11899 pm.test_tRNS = 0;
11902 pm.ngamma_tests = 3U;
11905 pm.ngamma_tests = pm.ngammas;
11908 pm.this.progressive = 1;
11911 pm.use_update_info; /* Can call multiple times */
11916 pm.interlace_type = PNG_INTERLACE_ADAM7;
11924 pm.use_input_precision = 1U;
11927 pm.use_input_precision = 0;
11930 pm.calculations_use_input_precision = 1U;
11933 pm.assume_16_bit_calculations = 1U;
11936 pm.calculations_use_input_precision =
11937 pm.assume_16_bit_calculations = 0;
11940 pm.test_exhaustive = 1;
11943 --argc, pm.sbitlow = (png_byte)atoi(*++argv), catmore = 1;
11953 pm.maxabs8 = atof(*++argv);
11956 pm.maxabs16 = atof(*++argv);
11959 pm.maxcalc8 = atof(*++argv);
11962 pm.maxcalc16 = atof(*++argv);
11965 pm.maxout8 = atof(*++argv);
11968 pm.maxout16 = atof(*++argv);
11971 pm.maxpc8 = atof(*++argv);
11974 pm.maxpc16 = atof(*++argv);
11986 --argc, pm.log8 = atof(*++argv), catmore = 1;
11989 --argc, pm.log16 = atof(*++argv), catmore = 1;
12035 pm.this.options[pm.this.noptions].option = option;
12036 pm.this.options[pm.this.noptions++].setting = setting;
12056 if (pm.test_standard == 0 && pm.test_size == 0 && pm.test_transform == 0 &&
12057 pm.ngamma_tests == 0)
12064 pm.test_standard = 1;
12065 pm.test_size = 1;
12066 pm.test_transform = 1;
12067 pm.ngamma_tests = 2U;
12070 if (pm.ngamma_tests > 0 &&
12071 pm.test_gamma_threshold == 0 && pm.test_gamma_transform == 0 &&
12072 pm.test_gamma_sbit == 0 && pm.test_gamma_scale16 == 0 &&
12073 pm.test_gamma_background == 0 && pm.test_gamma_alpha_mode == 0)
12075 pm.test_gamma_threshold = 1;
12076 pm.test_gamma_transform = 1;
12077 pm.test_gamma_sbit = 1;
12078 pm.test_gamma_scale16 = 1;
12079 pm.test_gamma_background = 1;
12080 pm.test_gamma_alpha_mode = 1;
12083 else if (pm.ngamma_tests == 0)
12086 pm.test_gamma_threshold = 0;
12087 pm.test_gamma_transform = 0;
12088 pm.test_gamma_sbit = 0;
12089 pm.test_gamma_scale16 = 0;
12090 pm.test_gamma_background = 0;
12091 pm.test_gamma_alpha_mode = 0;
12097 make_transform_images(&pm);
12100 if (pm.test_standard)
12103 perform_formatting_test(&pm.this);
12105 perform_standard_test(&pm);
12107 perform_error_test(&pm);
12111 if (pm.test_size)
12113 make_size_images(&pm.this);
12115 perform_size_test(&pm);
12121 if (pm.test_transform)
12122 perform_transform_test(&pm);
12126 if (pm.ngamma_tests > 0)
12127 perform_gamma_test(&pm, summary);
12134 if (!pm.this.verbose)
12136 if (pm.this.error[0] != 0)
12137 fprintf(stderr, "pngvalid: first error: %s\n", pm.this.error);
12147 (pm.this.nerrors || (pm.this.treat_warnings_as_errors &&
12148 pm.this.nwarnings)) ? "FAIL" : "PASS",
12163 (unsigned long)pm.this.read_memory_pool.max_max,
12164 (unsigned long)pm.this.read_memory_pool.max_limit,
12165 (unsigned long)pm.this.read_memory_pool.max_total,
12166 (unsigned long)pm.this.write_memory_pool.max_max,
12167 (unsigned long)pm.this.write_memory_pool.max_limit,
12168 (unsigned long)pm.this.write_memory_pool.max_total);
12174 store_delete(&pm.this);
12179 if (pm.this.nerrors || (pm.this.treat_warnings_as_errors &&
12180 pm.this.nwarnings))
12182 if (!pm.this.verbose)
12183 fprintf(stderr, "pngvalid: %s\n", pm.this.error);
12185 fprintf(stderr, "pngvalid: %d errors, %d warnings\n", pm.this.nerrors,
12186 pm.this.nwarnings);