Home | History | Annotate | Download | only in libtests

Lines Matching defs:this

8  * This code is released under the libpng license.
13 * This is a C program that is intended to be linked against libpng. It
37 /* Define the following to use this test against your installed libpng, rather
67 /* This deliberately lacks the PNG_CONST. */
70 /* This is copied from 1.5.1 png.h: */
96 /* This comes from pnglibconf.h afer 1.5: */
133 # define this not_the_cpp_this
206 /* Generate random bytes. This uses a boring repeatable algorithm and it
252 #define RANDOMIZE(this) randomize(&(this), sizeof (this))
464 * while this is basically bit addressed there is an implicit assumption
466 * do not otherwise cross byte boundaries. (This is, so far as I know,
594 png_size_t datacount; /* In this (the last) buffer */
609 /* Statistics for this run. */
625 * png_store (in fact it never does in this program.)
655 png_size_t cb_image; /* Size of this buffer */
682 /* Use this for random 32 bit values; this function makes sure the result is
1026 * the start and three at the end of each (this ensures that the row
1033 * This deliberately doesn't match the bits in the size test image which are
1228 /* Notice that a call to store_read will cause this function to fail because
1245 /* The caller must fill this in: */
1255 /* This function can only return NULL if called with '0'! */
1274 /* This is an internal error (the call has been made outside a read
1300 /* Handle a fatal error in memory allocation. This calls png_error if the
1301 * libpng struct is non-NULL, else it outputs a message and returns. This means
1324 * found 'memory' in pool->list *and* unlinked this entry, so this is a valid
1373 /* The NULL means this will always return, even if the memory is
1446 * To handle this store_malloc can log a message, but can't do anything
1460 store_memory *this = voidcast(store_memory*, memory), **test;
1470 /* First check that this 'memory' really is valid memory - it must be in the
1473 --this;
1474 for (test = &pool->list; *test != this; test = &(*test)->next)
1483 /* Unlink this entry, *test == this. */
1484 *test = this->next;
1485 this->next = NULL;
1486 store_memory_free(pp, pool, this);
1511 /* And make sure that all the memory has been freed - this will output
1512 * spurious errors in the case of memory corruption above, but this is safe.
1523 * store_storefile above to record this file after it has been written. The
1577 * This routine exists even when there is no read support to make the code
1602 /* Always do this to be safe. */
1662 * we don't ever expect NULL in this program.
1705 * saved files. This does not delete the store itself.
1719 * read callback for libpng. To use this the 'modifications' field must be set
1736 * all spectra that produce this response as the same color, therefore this
1744 /* A description of an (R,G,B) encoding of color (as defined above); this
1844 png_store this; /* I am a png_store */
1874 unsigned int repeat :1; /* Repeat this transform test. */
1893 /* This is set by transforms that need to allow a higher limit, it is an
1895 * not ridiculous; without this it is too easy to make a mistake in pngvalid
1900 /* Log limits - values above this are logged, but not necessarily
1933 /* When to use the use_input_precision option, this controls the gamma
1936 * within the normal limits. It should not be necessary to set this; the
1974 /* This returns true if the test should be stopped now because it has already
1979 return !pm->log && !pm->this.verbose && (pm->this.nerrors > 0 ||
1980 (pm->this.treat_warnings_as_errors && pm->this.nwarnings > 0));
1987 store_init(&pm->this);
2035 /* This controls use of checks that explicitly know how libpng digitizes the
2036 * samples in calculations; setting this circumvents simple error limit checking
2046 * bit precision. This only affects those of the following limits that pertain
2107 * value is a percentage but this routine returns a simple number.
2116 /* Output error - the error in the encoded value. This is determined by the
2122 * This limit is not determined by the bit depth of internal calculations.
2131 * error in 4 bit grayscale gamma is up to the value below. This is a hack
2134 * TODO: fix this in libpng
2145 /* This is the case where the value was calculated at 8-bit precision then
2155 /* This does the same thing as the above however it returns the value to log,
2156 * rather than raising a warning. This is useful for debugging to track down
2183 /* This is the case where the value was calculated at 8-bit precision then
2192 /* This
2193 * final value. Normally this would just be quantization to an integral value,
2296 * that this function changes the colour space encoding so it must only be
2297 * called on completion of the previous test. This is what 'modifier_reset'
2314 * For this reason do not rely on this function outside a call to
2330 pm->encoding_counter = 0; /* This will stop the repeat */
2355 store_read_reset(&pm->this);
2382 * first clear out all the settings - this corresponds to an encoding_counter
2482 store_read_imp(&pm->this, pm->buffer, 8); /* size of signature. */
2487 png_error(pm->this.pread, "invalid PNG file signature");
2492 store_read_imp(&pm->this, pm->buffer, 13+12); /* size of IHDR */
2498 png_error(pm->this.pread, "invalid IHDR");
2533 store_read_imp(&pm->this, pb, cb);
2550 store_read_imp(&pm->this, pm->buffer, 8);
2574 * this again.
2591 * so output this. Pend the current chunk.
2610 /* If we get to here then this chunk may need to be modified. To
2611 * do this it must be less than 1024 bytes in total size, otherwise
2616 store_read_imp(&pm->this, pm->buffer+pm->buffer_count,
2628 /* Remove this chunk */
2680 if (pm == NULL || pm->this.pread != pp)
2692 if (pm->this.pread != pp || pm->this.current == NULL ||
2693 this.next == NULL)
2696 /* This is another Horowitz and Hill random noise generator. In this case
2712 /* Check that this number of bytes are available (in the current buffer.)
2713 * (This doesn't quite work - the modifier might delete a chunk; unlikely
2717 cbAvail = store_read_buffer_avail(&pm->this);
2734 /* Check the invariants at the end (if this fails it's a problem in this
2738 pm->this.next != &pm->this.current->data ||
2739 pm->this.readpos < pm->this.current->datacount)
2748 /* Do this first so that the modifier fields are cleared even if an error
2762 return set_store_for_read(&pm->this, ppi, id, name);
2768 * macros because the chunks can be there regardless of whether this specific
2773 png_modification this;
2781 /* This simply dumps the given gamma value into the buffer. */
2793 modification_init(&me->this);
2794 me->this.chunk = CHUNK_gAMA;
2795 me->this.modify_fn = gama_modify;
2796 me->this.add = CHUNK_PLTE;
2799 me->this.next = pm->modifications;
2800 pm->modifications = &me->this;
2805 png_modification this;
2814 /* As with gAMA this just adds the required cHRM chunk to the buffer. */
2848 modification_init(&me->this);
2849 me->this.chunk = CHUNK_cHRM;
2850 me->this.modify_fn = chrm_modify;
2851 me->this.add = CHUNK_PLTE;
2852 me->this.next = pm->modifications;
2853 pm->modifications = &me->this;
2858 png_modification this;
2876 modification_init(&me->this);
2877 me->this.chunk = CHUNK_sBIT;
2881 me->this.modify_fn = srgb_modify;
2882 me->this.add = CHUNK_PLTE;
2888 me->this.modify_fn = 0;
2889 me->this.add = 0;
2893 me->this.next = pm->modifications;
2894 pm->modifications = &me->this;
2900 png_modification this;
2931 png_error(pm->this.pread,
2956 modification_init(&me->this);
2957 me->this.chunk = CHUNK_sBIT;
2958 me->this.modify_fn = sbit_modify;
2959 me->this.add = CHUNK_PLTE;
2961 me->this.next = pm->modifications;
2962 pm->modifications = &me->this;
2981 * buffer. This makes allocation easier below. Further regardless of the file
2995 * libpng itself there is a tendency to attempt to optimize it. This results in
2996 * special case code which needs to be validated. To cause this to happen the
2997 * 'size' images are made to use each possible filter, in so far as this is
3008 * (maximum) this actually makes a random palette in the hope that enough tests
3012 * at the same test! This is why pseudo-random number generators are useful for
3015 * The store must be open for write when this is called, otherwise an internal
3016 * error will occur. This routine contains its own magic number seed, so the
3096 * range of colors. Do this by randomly permuting values into the low
3097 * 'npalette' entries using an XOR mask generated here. This also
3166 * API to determine this prior to 1.5, so we need an inquiry function:
3283 /* This won't overflow: */
3402 /* This is just to do the right cast - could be changed to a function to check
3407 /* This is just a helper for compiling on minimal systems with no write
3423 /* This is an internal error - --interlace tests should be skipped, not
3506 /* Somewhat confusingly this must be called *after* png_write_info
3553 /* And store this under the appropriate id, then clean up. */
3562 /* Use the png_store returned by the exception. This may help the compiler
3563 * because 'ps' is not used in this branch of the setjmp. Note that fault
3577 /* This is in case of errors. */
3609 /* Note that this can, trivially, be optimized to a memcpy on pass 7, the
3610 * code is presented this way to make it easier to understand. In practice
3611 * consult the code in the libpng source to see other ways of doing this.
3629 * in 'buffer'. The image is 'w' wide and this is pass 'pass', distribute
3631 * this to be checked).
3646 /* Build a single row for the 'size' test images; this fills in only the
3737 /* Calculate the bit size, divide by 8 to get the byte size - this won't
3755 /* To help consistent error detection make the parts of this buffer
3782 * need a reduced interlace row; this may be reduced
3791 * can be used to skip the whole y loop in this case.
3852 /* And store this under the appropriate id, then clean up. */
3860 /* Use the png_store returned by the exception. This may help the compiler
3861 * because 'ps' is not used in this branch of the setjmp. Note that fault
3904 /* This is in case of errors. */
4012 /* Expect this to throw: */
4101 make_error(&pm->this, colour_type, DEPTH(bdlo), interlace_type,
4118 /* Need to do this here because we just write in this test. */
4119 safecat(pm->this.test, sizeof pm->this.test, 0, "error test");
4140 /* This is just to validate the internal PNG formatting code - if this fails
4147 /* The handle into the formatting code is the RFC1123 support; this test does
4218 * reader callbacks only have one parameter (png_get_progressive_ptr()), so this
4228 * addresses), this code requires one more pointer to make the display - the
4232 * Perhaps confusingly this technique is confounded with classes - the
4236 * same as the pointer to the structure. This allows us to reuse standard_
4309 /* Initialize the palette fields - this must be done later because the palette
4341 * store_palette format. This returns 1 if there is any transparency in the
4379 /* But there is no palette, so record this: */
4393 !(trans_alpha != NULL && num == 0)) /* TODO: fix this in libpng. */
4401 * last, png_color_16p, variable too it couldn't rely on this.
4474 * The code for the info callback is split into two because this callback calls
4561 /* Important: this is validating the value *before* any transforms have been
4569 /* Validate the colour type 3 palette (this can be present on other color
4615 * creating the image (interlaced or not). This has the side effect of
4627 /* This must be called *after* the png_read_update_info call to get the correct
4658 /* And the info callback has to call this (or png_read_update_info - see
4698 * callback still gets called, but with a NULL pointer. This is checked
4712 /* Use this opportunity to validate the png 'current' APIs: */
4723 /* Validate this just in case. */
4772 /* wPass may be zero or this row may not be in this pass.
4784 * display to make this easier. Don't use 0xff (which is used in
4908 /* This exists because prior to 1.5.18 the progressive reader left the
4967 /* In this case use pixel_cmp because we need to compare a partial
4969 * of 8 bits wide. (This is fixed in libpng-1.5.6 and pixel_cmp is
5000 /* This avoids false positives if the validation code is never called! */
5042 /* Get a png_struct for reading the image. This will throw an error if it
5065 /* Note that this takes the store, not the display. */
5076 /* Need the total bytes in the image below; we can't get to this point
5104 d.ps = fault; /* make sure this hasn't been clobbered. */
5121 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
5164 * width and height. This is a waste of time in practice, hence the
5176 * reader using libpng to deinterlace (where required.) This
5180 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
5187 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
5195 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
5202 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
5211 * in the progressive case this does actually make a difference
5214 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
5222 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
5267 * fashion. To deal with this some measure of restraint is required, otherwise
5286 * channel is stored. This sBIT value is folded in to the stored error value
5296 image_pixel_setf(image_pixel *this, unsigned int max)
5298 this->redf = this->red / (double)max;
5299 this->greenf = this->green / (double)max;
5300 this->bluef = this->blue / (double)max;
5301 this->alphaf = this->alpha / (double)max;
5303 if (this->red < max)
5304 this->rede = this->redf * DBL_EPSILON;
5306 this->rede = 0;
5307 if (this->green < max)
5308 this->greene = this->greenf * DBL_EPSILON;
5310 this->greene = 0;
5311 if (this->blue < max)
5312 this->bluee = this->bluef * DBL_EPSILON;
5314 this->bluee = 0;
5315 if (this->alpha < max)
5316 this->alphae = this->alphaf * DBL_EPSILON;
5318 this->alphae = 0;
5321 /* Initialize the structure for the next pixel - call this before doing any
5326 image_pixel_init(image_pixel *this, png_const_bytep row, png_byte colour_type,
5334 * Note that this currently assumes a simple palette where entry x has colour
5337 this->palette_index = this->red = this->green = this->blue =
5339 this->alpha = max;
5340 this->red_sBIT = this->green_sBIT = this->blue_sBIT = this->alpha_sBIT =
5346 /* This permits the caller to default to the sample value. */
5349 PNG_CONST unsigned int i = this->palette_index;
5351 this->red = palette[i].red;
5352 this->green = palette[i].green;
5353 this->blue = palette[i].blue;
5354 this->alpha = palette[i].alpha;
5364 this->green = sample(row, colour_type, bit_depth, x, 1);
5365 this->blue = sample(row, colour_type, bit_depth, x, 2);
5369 this->alpha = sample(row, colour_type, bit_depth, x, ++i);
5376 image_pixel_setf(this, max);
5381 this->colour_type = colour_type;
5382 this->bit_depth = bit_depth;
5383 this->sample_depth = sample_depth;
5384 this->have_tRNS = 0;
5387 /* Convert a palette image to an rgb image. This necessarily converts the tRNS
5391 * corresponding palette entry and *this* is updated. Consequently this routine
5395 image_pixel_convert_PLTE(image_pixel *this)
5397 if (this->colour_type == PNG_COLOR_TYPE_PALETTE)
5399 if (this->have_tRNS)
5401 this->colour_type = PNG_COLOR_TYPE_RGB_ALPHA;
5402 this->have_tRNS = 0;
5405 this->colour_type = PNG_COLOR_TYPE_RGB;
5407 /* The bit depth of the row changes at this point too (notice that this is
5410 this->bit_depth = 8;
5414 /* Add an alpha channel; this will import the tRNS information because tRNS is
5419 image_pixel_add_alpha(image_pixel *this, PNG_CONST standard_display *display)
5421 if (this->colour_type == PNG_COLOR_TYPE_PALETTE)
5422 image_pixel_convert_PLTE(this);
5424 if ((this->colour_type & PNG_COLOR_MASK_ALPHA) == 0)
5426 if (this->colour_type == PNG_COLOR_TYPE_GRAY)
5428 if (this->bit_depth < 8)
5429 this->bit_depth = 8;
5431 if (this->have_tRNS)
5433 this->have_tRNS = 0;
5438 if (this->red == display->transparent.red)
5439 this->alphaf = 0;
5441 this->alphaf = 1;
5444 this->alphaf = 1;
5446 this->colour_type = PNG_COLOR_TYPE_GRAY_ALPHA;
5449 else if (this->colour_type == PNG_COLOR_TYPE_RGB)
5451 if (this->have_tRNS)
5453 this->have_tRNS = 0;
5458 if (this->red == display->transparent.red &&
5459 this->green == display->transparent.green &&
5460 this->blue == display->transparent.blue)
5461 this->alphaf = 0;
5463 this->alphaf = 1;
5465 this->colour_type = PNG_COLOR_TYPE_RGB_ALPHA;
5472 this->alphae = 0;
5473 this->alpha_sBIT = display->alpha_sBIT;
5480 /* The name of this transform: a string. */
5489 /* The global count of the number of times this transform has been set on an
5494 /* The local count of the number of times this transform has been set. */
5506 * this gets called just before the modifier is set up for read.
5508 void (*ini)(PNG_CONST struct image_transform *this,
5513 void (*set)(PNG_CONST struct image_transform *this,
5522 void (*mod)(PNG_CONST struct image_transform *this, image_pixel *that,
5525 /* Add this transform to the list and return true if the transform is
5526 * meaningful for this colour type and bit depth - if false then the
5530 int (*add)(struct image_transform *this,
5537 standard_display this;
5555 transform_set_encoding(transform_display *this)
5560 png_modifier *pm = this->pm;
5567 srgb_modification_init(&this->srgb_mod, pm, PNG_sRGB_INTENT_ABSOLUTE);
5572 gama_modification_init(&this->gama_mod, pm, pm->current_gamma);
5575 chrm_modification_init(&this->chrm_mod, pm, pm->current_encoding);
5582 image_transform_ini_end(PNG_CONST image_transform *this,
5585 UNUSED(this)
5590 image_transform_set_end(PNG_CONST image_transform *this,
5593 UNUSED(this)
5617 image_transform_mod_end(PNG_CONST image_transform *this, image_pixel *that,
5622 UNUSED(this)
5638 * the sBIT allows the implementation to be worse than this. In addition the
5641 * below to the digitized value of the error limits - this has the net effect
5670 that->alpha = 1; /* Override this. */
5700 standard_display_init(&dp->this, &pm->this, id, 0/*do_interlace*/,
5716 standard_info_part1(&dp->this, pp, pi);
5723 int i = dp->this.use_update_info;
5731 standard_info_part2(&dp->this, pp, pi, 1/*images*/);
5771 * this avoids running the whole test if the output is unexpected.
5777 test_pixel.colour_type = dp->this.colour_type; /* input */
5778 test_pixel.bit_depth = dp->this.bit_depth;
5786 test_pixel.have_tRNS = dp->this.is_transparent;
5894 PNG_CONST png_store* PNG_CONST ps = dp->this.ps;
5895 PNG_CONST png_byte in_ct = dp->this.colour_type;
5896 PNG_CONST png_byte in_bd = dp->this.bit_depth;
5897 PNG_CONST png_uint_32 w = dp->this.w;
5898 PNG_CONST png_uint_32 h = dp->this.h;
5903 PNG_CONST png_byte red_sBIT = dp->this.red_sBIT;
5904 PNG_CONST png_byte green_sBIT = dp->this.green_sBIT;
5905 PNG_CONST png_byte blue_sBIT = dp->this.blue_sBIT;
5906 PNG_CONST png_byte alpha_sBIT = dp->this.alpha_sBIT;
5907 PNG_CONST int have_tRNS = dp->this.is_transparent;
5916 store_image_check(dp->this.ps, pp, 0);
5923 /* Validate that the palette count itself has not changed - this is not
5929 if (npalette != dp->this.npalette)
5979 image_pixel_init(&in_pixel, std, in_ct, in_bd, x, dp->this.palette);
6043 dp->this.ps->validated = 1;
6053 if (!dp->this.speed)
6056 dp->this.ps->validated = 1;
6065 context(&pmIn->this, fault);
6089 pp = set_modifier_for_read(d.pm, &pi, d.this.id, full_name);
6090 standard_palette_init(&d.this);
6097 (void)store_message(&d.pm->this, pp, buffer, sizeof buffer, 0,
6105 if (d.pm->this.progressive)
6125 sequential_row(&d.this, pp, pi, -1, 0);
6127 if (!d.this.speed)
6130 d.this.ps->validated = 1;
6164 image_transform_default_ini(PNG_CONST image_transform *this,
6167 this->next->ini(this->next, that);
6172 image_transform_default_add(image_transform *this,
6178 this->next = *that;
6179 *that = this;
6188 image_transform_png_set_palette_to_rgb_set(PNG_CONST image_transform *this,
6192 this->next->set(this->next, that, pp, pi);
6196 image_transform_png_set_palette_to_rgb_mod(PNG_CONST image_transform *this,
6203 this->next->mod(this->next, that, pp, display);
6207 image_transform_png_set_palette_to_rgb_add(image_transform *this,
6212 this->next = *that;
6213 *that = this;
6226 image_transform_png_set_tRNS_to_alpha_set(PNG_CONST image_transform *this,
6230 this->next->set(this->next, that, pp, pi);
6234 image_transform_png_set_tRNS_to_alpha_mod(PNG_CONST image_transform *this,
6238 /* LIBPNG BUG: this always forces palette images to RGB. */
6242 /* This effectively does an 'expand' only if there is some transparency to
6246 image_pixel_add_alpha(that, &display->this);
6257 this->next->mod(this->next, that, pp, display);
6261 image_transform_png_set_tRNS_to_alpha_add(image_transform *this,
6266 this->next = *that;
6267 *that = this;
6270 * this transformation should do nothing if there already is an alpha
6284 image_transform_png_set_gray_to_rgb_set(PNG_CONST image_transform *this,
6288 this->next->set(this->next, that, pp, pi);
6292 image_transform_png_set_gray_to_rgb_mod(PNG_CONST image_transform *this,
6296 /* NOTE: we can actually pend the tRNS processing at this point because we
6299 * doesn't do this, so we don't either.
6302 image_pixel_add_alpha(that, &display->this);
6320 this->next->mod(this->next, that, pp, display);
6324 image_transform_png_set_gray_to_rgb_add(image_transform *this,
6329 this->next = *that;
6330 *that = this;
6343 image_transform_png_set_expand_set(PNG_CONST image_transform *this,
6347 this->next->set(this->next, that, pp, pi);
6351 image_transform_png_set_expand_mod(PNG_CONST image_transform *this,
6362 image_pixel_add_alpha(that, &display->this);
6364 this->next->mod(this->next, that, pp, display);
6368 image_transform_png_set_expand_add(image_transform *this,
6373 this->next = *that;
6374 *that = this;
6389 * LIBPNG BUG: this just does an 'expand'
6393 PNG_CONST image_transform *this, transform_display *that, png_structp pp,
6397 this->next->set(this->next, that, pp, pi);
6402 PNG_CONST image_transform *this, image_pixel *that, png_const_structp pp,
6405 image_transform_png_set_expand_mod(this, that, pp, display);
6409 image_transform_png_set_expand_gray_1_2_4_to_8_add(image_transform *this,
6412 return image_transform_png_set_expand_add(this, that, colour_type,
6424 image_transform_png_set_expand_16_set(PNG_CONST image_transform *this,
6428 this->next->set(this->next, that, pp, pi);
6432 image_transform_png_set_expand_16_mod(PNG_CONST image_transform *this,
6443 image_pixel_add_alpha(that, &display->this);
6448 this->next->mod(this->next, that, pp, display);
6452 image_transform_png_set_expand_16_add(image_transform *this,
6457 this->next = *that;
6458 *that = this;
6472 image_transform_png_set_scale_16_set(PNG_CONST image_transform *this,
6476 this->next->set(this->next, that, pp, pi);
6480 image_transform_png_set_scale_16_mod(PNG_CONST image_transform *this,
6493 this->next->mod(this->next, that, pp, display);
6497 image_transform_png_set_scale_16_add(image_transform *this,
6502 this->next = *that;
6503 *that = this;
6516 image_transform_png_set_strip_16_set(PNG_CONST image_transform *this,
6520 this->next->set(this->next, that, pp, pi);
6524 image_transform_png_set_strip_16_mod(PNG_CONST image_transform *this,
6536 /* Prior to 1.5.4 png_set_strip_16 would use an 'accurate' method if this
6547 * Notice that this is only relevant prior to the addition of the
6560 this->next->mod(this->next, that, pp, display);
6564 image_transform_png_set_strip_16_add(image_transform *this,
6569 this->next = *that;
6570 *that = this;
6583 image_transform_png_set_strip_alpha_set(PNG_CONST image_transform *this,
6587 this->next->set(this->next, that, pp, pi);
6591 image_transform_png_set_strip_alpha_mod(PNG_CONST image_transform *this,
6603 this->next->mod(this->next, that, pp, display);
6607 image_transform_png_set_strip_alpha_add(image_transform *this,
6612 this->next = *that;
6613 *that = this;
6666 image_transform_png_set_rgb_to_gray_ini(PNG_CONST image_transform *this,
6672 UNUSED(this)
6674 /* Since we check the encoding this flag must be set: */
6720 * so repeat if it is set. If a test fails this may mean we subsequently
6768 if (that->this.bit_depth == 16 || pm->assume_16_bit_calculations)
6781 (that->this.bit_depth == 16 ? 8. :
6798 * NOTE: this magic number was determined by experiment to be 1.1 (when
6819 if (that->this.bit_depth != 16 && !pm->assume_16_bit_calculations)
6825 image_transform_png_set_rgb_to_gray_set(PNG_CONST image_transform *this,
6896 /* This should match the original one from the png_modifier, within
6948 this->next->set(this->next, that, pp, pi);
6952 image_transform_png_set_rgb_to_gray_mod(PNG_CONST image_transform *this,
6976 /* Do this using interval arithmetic, otherwise it is too difficult to
6981 * will be identical after this operation if there is only one
6982 * transform, feel free to delete the png_error checks on this below in
6983 * the future (this is just me trying to ensure it works!)
7013 * to handle the upper and lower bounds of the values. This is
7083 /* Check that this worked: */
7123 * global error limits to take this into account.)
7133 /* The calculation happens in linear space, and this produces much
7160 * previously added input quantization error at this point.
7189 /* Validate that the error is within limits (this has caused
7224 this->next->mod(this->next, that, pp, display);
7228 image_transform_png_set_rgb_to_gray_add(image_transform *this,
7233 this->next = *that;
7234 *that = this;
7254 * This ignores the gamma (at present.)
7260 image_transform_png_set_background_set(PNG_CONST image_transform *this,
7278 colour_type = that->this.colour_type;
7288 bit_depth = that->this.bit_depth;
7295 /* Extract the background colour from this image_pixel, but make sure the
7316 this->next->set(this->next, that, pp, pi);
7320 image_transform_png_set_background_mod(PNG_CONST image_transform *this,
7326 image_pixel_add_alpha(that, &display->this);
7328 /* This is only necessary if the alpha value is less than 1. */
7373 this->next->mod(this->next, that, pp, display);
7384 /* This may just be 'end' if all the transforms are disabled! */
7455 /* This can only happen if we every have more than 32 transforms (excluding
7484 image_transform_add(PNG_CONST image_transform **this, unsigned int max,
7493 /* Find the next counter value, if the counter is zero this is the start
7494 * of the list. This routine always returns the current counter (not the
7516 *this = &image_transform_end;
7527 if (list->add(list, this, colour_type, bit_depth) || max == 0)
7536 /* Not useful and max>0, so remove it from *this: */
7537 *this = list->next;
7541 * in this run:
7552 if (*this != &image_transform_end)
7563 image_transform_png_set_@_set(PNG_CONST image_transform *this,
7567 this->next->set(this->next, that, pp, pi);
7571 image_transform_png_set_@_mod(PNG_CONST image_transform *this,
7575 this->next->mod(this->next, that, pp, display);
7579 image_transform_png_set_@_add(image_transform *this,
7583 this->next = *that;
7584 *that = this;
7597 * Very difficult to validate this!
7658 /* 'max' is currently hardwired to '1'; this should be settable on the
7667 /* The command line can change this to checking interlaced images. */
7690 standard_display this;
7721 standard_display_init(&dp->this, &pm->this, id, 0/*do_interlace*/,
7748 standard_info_part1(&dp->this, pp, pi);
7750 /* If requested strip 16 to 8 bits - this is handled automagically below
7778 /* This tests the alpha mode handling, if supported. */
7783 * gamma, but since the file has a gAMA chunk this does not matter.
7831 /* NOTE: this assumes the caller provided the correct background gamma!
7852 int i = dp->this.use_update_info;
7860 standard_info_part2(&dp->this, pp, pi, 1 /*images*/);
7928 /* This mimics the libpng threshold test, '0' is used to prevent gamma
7947 if ((dp->this.colour_type & PNG_COLOR_MASK_ALPHA) != 0 ||
7948 (dp->this.colour_type == 3 && dp->this.is_transparent))
7963 /* libpng doesn't do this optimization, if we do pngvalid will fail.
7995 /* This function handles composition of a single non-alpha component. The
7998 * this is the alpha component and the function should not be called!
8035 * while the opaque pixels are gamma encoded, but this only affects the
8066 /* This API returns the encoded *input* component, in the range 0..1 */
8081 * value, id, and compare this against the actual digitized result, 'od'.
8087 * this is the alpha channel ('alpha' < 0) or if the pixel is opaque then
8128 * contrast of the image. There's nothing we can do about this - we don't
8262 * integer arithmetic. This introduces an extra error of +/- 0.5 (at
8263 * least) in the integer space used. 'maxcalc' records this, taking
8270 * this encode input_sample adjusted by the maximum error (tmp) above.
8282 /* Quantize this appropriately: */
8321 /* There has been an error in processing, or we need to log this
8326 /* pass is set at this point if either of the tests above would have
8332 /* Ok, something is wrong - this actually happens in current libpng
8340 * lost. This can result in up to a +/-1 error in the presence of
8394 /* One last chance. If this is an alpha channel and the 16to8
8399 * This is only done for older libpng versions when the 'inaccurate'
8404 /* This may be required for other components in the future,
8407 * understand why, but since it's better this way I care not
8451 * because this changes what parameters were actually used above.
8515 * alpha value, 'compose' says whether this is relevant.
8540 * (this function is not passed the original, non-linear,
8554 * libpng value (output) unless this is just a component gamma
8583 /* This is the non-composition case, the internal linear
8603 /* This is our calculated encoded_sample which should (but does
8627 else /* logging this value */
8628 store_verbose(&vi->dp->pm->this, vi->pp, pass, msg);
8641 PNG_CONST png_store* PNG_CONST ps = dp->this.ps;
8642 PNG_CONST png_byte in_ct = dp->this.colour_type;
8643 PNG_CONST png_byte in_bd = dp->this.bit_depth;
8644 PNG_CONST png_uint_32 w = dp->this.w;
8645 PNG_CONST png_uint_32 h = dp->this.h;
8646 PNG_CONST size_t cbRow = dp->this.cbRow;
8654 * Since this API receives the screen and file gamma in double
8662 * a fundamental limit on the accuracy of the output of +/-.5 - this
8674 * This means that only a subset of the possible PNG values should
8686 * The basic tests below do not do this, however if 'use_input_precision'
8692 PNG_CONST store_palette_entry *in_palette = dp->this.palette;
8693 PNG_CONST int in_is_transparent = dp->this.is_transparent;
8700 store_image_check(dp->this.ps, pp, 0);
8710 /* TODO: FIX THIS: MAJOR BUG! If the transformations all happen inside
8751 dp->this.palette[in_index].alpha :
8772 /* This is a copy of the calculation of 'i' above in order to
8824 dp->this.ps->validated = 1;
8833 if (!dp->this.speed)
8836 dp->this.ps->validated = 1;
8857 context(&pmIn->this, fault);
8890 pp = set_modifier_for_read(d.pm, &pi, d.this.id, name);
8891 standard_palette_init(&d.this);
8894 if (d.pm->this.progressive)
8914 sequential_row(&d.this, pp, pi, -1, 0);
8916 if (!d.this.speed)
8919 d.this.ps->validated = 1;
8924 if (d.pm->log && !d.threshold_test && !d.this.speed)
8926 d.this.bit_depth, colour_types[d.this.colour_type], name,
8930 if (d.this.colour_type == 0 || d.this.colour_type == 4)
8932 switch (d.this.bit_depth)
8966 else if (d.this.colour_type == 2 || d.this.colour_type == 6)
8968 switch (d.this.bit_depth)
8989 else if (d.this.colour_type == 3)
9026 * fact this test is somewhat excessive since libpng doesn't make this
9036 * but this can be set from the command line.
9145 /* Note that this requires a 16 bit source image but produces 8 bit output, so
9162 * by much) - this could be fixed, it only appears with the -g option.
9238 /* This tests the handling of a unique value, the math is such that the
9280 this gamma
9329 /* This assumes no expand gray->rgb - the current code won't handle that!
9429 /*TODO: remove this*/
9438 if (!pm->this.speed && pm->test_gamma_threshold)
9459 printf("Expect this value to be less than .5 for 8 bit formats,\n");
9468 /*TODO: remove this. Necessary because the current libpng
9523 /*TODO: remove this. Necessary because the current libpng
9552 /*TODO: remove this. Necessary because the current libpng
9577 /* This is copied verbatim from the specification, it is simply the pass
9595 /* This routine validates all the interlace support macros in png.h for
9925 * which typically don't exceed 4 decimal places. This allows testing of the
9931 * specially: do not change the first entry in this list!
9935 /* sRGB: must be first in this list! */
9959 * This attempts to trap signals and escape without crashing. It needs a
9961 * from the condition; this is handled by making the png_modifier used by 'main'
10006 store_log(&pm.this, NULL/*png_structp*/, msg, 1/*error*/);
10008 /* And finally throw an exception so we can keep going, unless this is
10014 &pm.this.exception_context;
10016 Throw &pm.this;
10032 /* This is an array of standard gamma values (believe it or not I've seen
10040 /* This records the command and arguments: */
10044 anon_context(&pm.this);
10056 * disabled; this is not necessary but if it is not done pngvalid will likely
10069 store_ensure_image(&pm.this, NULL, 2, TRANSFORM_ROWMAX, TRANSFORM_HEIGHTMAX);
10075 pm.this.treat_warnings_as_errors = 1;
10077 /* Default assume_16_bit_calculations appropriately; this tells the checking
10086 * TODO: fix this
10102 * transformed range [input-.5,input+.5]; this is is required because of the
10106 * TODO: review this
10127 /* NOTE: this is a reasonable perceptual limit. We assume that humans can
10133 * this is only allowed for values >38149 by the following:
10147 pm.this.verbose = 1;
10153 summary = pm.this.verbose = pm.log = 0;
10156 pm.this.treat_warnings_as_errors = 0;
10159 pm.this.speed = 1, pm.ngamma_tests = pm.ngammas, pm.test_standard = 0,
10263 pm.this.progressive = 1;
10384 pm.this.options[pm.this.noptions].option = option;
10385 pm.this.options[pm.this.noptions++].setting = setting;
10408 /* Make this do all the tests done in the test shell scripts with the same
10446 make_transform_images(&pm.this);
10452 perform_formatting_test(&pm.this);
10462 make_size_images(&pm.this);
10483 if (!pm.this.verbose)
10485 if (pm.this.error[0] != 0)
10486 fprintf(stderr, "pngvalid: first error: %s\n", pm.this.error);
10496 (pm.this.nerrors || (pm.this.treat_warnings_as_errors &&
10497 pm.this.nwarnings)) ? "FAIL" : "PASS",
10512 (unsigned long)pm.this.read_memory_pool.max_max,
10513 (unsigned long)pm.this.read_memory_pool.max_limit,
10514 (unsigned long)pm.this.read_memory_pool.max_total,
10515 (unsigned long)pm.this.write_memory_pool.max_max,
10516 (unsigned long)pm.this.write_memory_pool.max_limit,
10517 (unsigned long)pm.this.write_memory_pool.max_total);
10520 /* Do this here to provoke memory corruption errors in memory not directly
10523 store_delete(&pm.this);
10528 if (pm.this.nerrors || (pm.this.treat_warnings_as_errors &&
10529 pm.this.nwarnings))
10531 if (!pm.this.verbose)
10532 fprintf(stderr, "pngvalid: %s\n", pm.this.error);
10534 fprintf(stderr, "pngvalid: %d errors, %d warnings\n", pm.this.nerrors,
10535 pm.this.nwarnings);
10566 /* This is required because some very minimal configurations do not use it: