Lines Matching defs:Image
570 /* THE Image STRUCTURE */
571 /* The super-class of a png_image, contains the decoded image plus the input
576 png_image image;
590 Image;
594 newimage(Image *image)
596 memset(image, 0, sizeof *image);
599 /* Reset the image to be read again - only needs to rewind the FILE* at present.
602 resetimage(Image *image)
604 if (image->input_file != NULL)
605 rewind(image->input_file);
608 /* Free the image buffer; the buffer is re-used on a re-read, this is just for
612 freebuffer(Image *image)
614 if (image->buffer) free(image->buffer);
615 image->buffer = NULL;
616 image->bufsize = 0;
617 image->allocsize = 0;
621 * the image.
624 freeimage(Image *image)
626 freebuffer(image);
627 png_image_free(&image->image);
629 if (image->input_file != NULL)
631 fclose(image->input_file);
632 image->input_file = NULL;
635 if (image->input_memory != NULL)
637 free(image->input_memory);
638 image->input_memory = NULL;
639 image->input_memory_size = 0;
642 if (image->tmpfile_name[0] != 0 && (image->opts & KEEP_TMPFILES) == 0)
644 (void)remove(image->tmpfile_name);
645 image->tmpfile_name[0] = 0;
649 /* This is actually a re-initializer; allows an image structure to be re-used by
650 * freeing everything that relates to an old image.
652 static void initimage(Image *image, png_uint_32 opts, const char *file_name,
655 freeimage(image);
656 memset(&image->image, 0, sizeof image->image);
657 image->opts = opts;
658 image->file_name = file_name;
659 image->stride_extra = stride_extra;
662 /* Make sure the image buffer is big enough; allows re-use of the buffer if the
663 * image is re-read.
667 allocbuffer(Image *image)
669 png_size_t size = PNG_IMAGE_BUFFER_SIZE(image->image, image->stride);
671 if (size+32 > image->bufsize)
673 freebuffer(image);
674 image->buffer = voidcast(png_bytep, malloc(size+32));
675 if (image->buffer == NULL)
683 image->bufsize = size+32;
686 memset(image->buffer, 95, image
687 memset(image->buffer+16, BUFFER_INIT8, size);
688 image->allocsize = size;
704 /* Check for overwrite in the image buffer. */
706 checkbuffer(Image *image, const char *arg)
708 if (check16(image->buffer, 95))
711 fprintf(stderr, "%s: overwrite at start of image buffer\n", arg);
715 if (check16(image->buffer+16+image->allocsize, 95))
718 fprintf(stderr, "%s: overwrite at end of image buffer\n", arg);
724 /* Log a terminal error, also frees the libpng part of the image if necessary.
727 logerror(Image *image, const char *a1, const char *a2, const char *a3)
730 if (image->image.warning_or_error)
731 fprintf(stderr, "%s%s%s: %s\n", a1, a2, a3, image->image.message);
736 if (image->image.opaque != NULL)
738 fprintf(stderr, "%s: image opaque pointer non-NULL on error\n",
739 image->file_name);
740 png_image_free(&image->image);
750 logclose(Image *image, FILE *f, const char *name, const char *operation)
755 return logerror(image, name, operation, strerror(e));
759 * the spec says and freeing the image.
762 checkopaque(Image *image)
764 if (image->image.opaque != NULL)
766 png_image_free(&image->image);
767 return logerror(image, image->file_name, ": opaque not NULL", "");
773 else if (image->image.warning_or_error != 0 &&
774 (strcmp(image->image.message,
776 (image->opts & GBG_ERROR) != 0 : (image->opts & STRICT) != 0))
777 return logerror(image, image->file_name, (image->opts & GBG_ERROR) != 0 ?
784 /* IMAGE COMPARISON/CHECKING */
806 /* Basic image formats; control the data but not the layout thereof. */
1024 * returned must either pass the buffer or, for a color-mapped image, the
2027 Image* in_image; /* Input image */
2028 const Image* out_image; /* Output image */
2064 transform_from_formats(Transform *result, Image *in_image,
2065 const Image *out_image, png_const_colorp background, int via_linear)
2076 in_format = in_image->image.format;
2077 out_format = out_image->image.format;
2350 const png_uint_32 in_format = transform->in_image->image.format;
2351 const png_uint_32 out_format = transform->out_image->image.format;
2596 * to * give image 'b'. The formats may have been changed.
2599 compare_two_images(Image *a, Image *b, int via_linear,
2606 const png_uint_32 width = a->image.width;
2607 const png_uint_32 height = a->image.height;
2608 const png_uint_32 formata = a->image.format;
2609 const png_uint_32 formatb = b->image.format;
2619 if (width != b->image.width || height != b->image.height)
2638 /* First shortcut the two colormap case by comparing the image data; if it
2640 * absolutely necessary for an image match. If the colormaps fail to match
2697 * do any checking at present the original image may contain invalid
2701 if (y >= a->image.colormap_entries)
2707 (unsigned long)a->image.colormap_entries);
2713 else if (y >= b->image.colormap_entries)
2719 (unsigned long)b->image.colormap_entries);
2743 /* else the image buffers don't match pixel-wise so compare sample values
2749 /* Check the original image first,
2752 if (amax >= a->image.colormap_entries)
2756 (unsigned long)a->image.colormap_entries);
2760 else if (bmax >= b->image.colormap_entries)
2764 (unsigned long)b->image.colormap_entries);
2824 alpha_added = bloc[0]; /* location of alpha channel in image b */
2827 alpha_added = 4; /* Won't match an image b channel */
2830 alpha_removed = aloc[0]; /* location of alpha channel in image a */
2941 read_file(Image *image, png_uint_32 format, png_const_colorp background)
2943 memset(&image->image, 0, sizeof image->image);
2944 image->image.version = PNG_IMAGE_VERSION;
2946 if (image->input_memory != NULL)
2948 if (!png_image_begin_read_from_memory(&image->image, image->input_memory,
2949 image->input_memory_size))
2950 return logerror(image, "memory init: ", image->file_name, "");
2954 else if (image->input_file != NULL)
2956 if (!png_image_begin_read_from_stdio(&image->image, image->input_file))
2957 return logerror(image, "stdio init: ", image->file_name, "");
2962 if (!png_image_begin_read_from_file(&image->image, image->file_name))
2963 return logerror(image, "file init: ", image->file_name, "");
2968 return logerror(image, "unsupported file/stdio init: ",
2969 image->file_name, "");
2974 if (image->opts & sRGB_16BIT)
2975 image->image.flags |= PNG_IMAGE_FLAG_16BIT_sRGB;
2977 /* Have an initialized image with all the data we need plus, maybe, an
2985 image_format = image->image.format;
2987 if (image->opts & VERBOSE)
2989 printf("%s %lu x %lu %s -> %s", image->file_name,
2990 (unsigned long)image->image.width,
2991 (unsigned long)image->image.height,
2993 (format & FORMAT_NO_CHANGE) != 0 || image->image.format == format
3019 image->image.format = format;
3021 image->stride = PNG_IMAGE_ROW_STRIDE(image->image) + image->stride_extra;
3022 allocbuffer(image);
3024 result = png_image_finish_read(&image->image, background,
3025 image->buffer+16, (png_int_32)image->stride, image->colormap);
3027 checkbuffer(image, image->file_name);
3030 return checkopaque(image);
3033 return logerror(image, image->file_name, ": image read failed", "");
3037 image->file_name, but uses
3038 * image->opts to choose the method. The file is always read in its native
3042 read_one_file(Image *image)
3044 if (!(image->opts & USE_FILE) || (image->opts & USE_STDIO))
3047 FILE *f = fopen(image->file_name, "rb");
3051 if (image->opts & USE_FILE)
3052 image->input_file = f;
3075 image->input_memory_size = cb;
3076 image->input_memory = b;
3082 return logclose(image, f, image->file_name,
3088 return logclose(image, f, image->file_name,
3093 return logclose(image, f, image->file_name,
3102 return logclose(image, f, image->file_name,
3106 return logclose(image, f, image->file_name,
3111 return logclose(image, f, image->file_name, ": seek failed: ");
3116 return logerror(image, image->file_name, ": open failed: ",
3120 return read_file(image, FORMAT_NO_CHANGE, NULL);
3125 write_one_file(Image *output, Image *image, int convert_to_8bit)
3127 if (image->opts & FAST_WRITE)
3128 image->image.flags |= PNG_IMAGE_FLAG_FAST;
3130 if (image->opts & USE_STDIO)
3170 if (png_image_write_to_stdio(&image->image, f, convert_to_8bit,
3171 image->buffer+16, (png_int_32)image->stride, image->colormap))
3176 initimage(output, image->opts, "tmpfile", image->stride_extra);
3178 if (!checkopaque(image))
3183 return logclose(image, f, "tmpfile", ": flush: ");
3189 return logerror(image, "tmpfile", ": write failed", "");
3194 return logerror(image, "tmpfile", ": open: ", strerror(errno));
3196 return logerror(image, "tmpfile", ": open: unsupported", "");
3200 else if (image->opts & USE_FILE)
3208 if (png_image_write_to_file(&image->image, name, convert_to_8bit,
3209 image->buffer+16, (png_int_32)image->stride, image->colormap))
3211 initimage(output, image->opts, output->tmpfile_name,
3212 image->stride_extra);
3216 if (!checkopaque(image))
3221 return logerror(image, name, ": write failed", "");
3223 return logerror(image, "stdio", ": open: unsupported", "");
3231 if (png_image_write_get_memory_size(image->image, size, convert_to_8bit,
3232 image->buffer+16, (png_int_32)image->stride, image->colormap))
3237 if (size > PNG_IMAGE_PNG_SIZE_MAX(image->image))
3238 return logerror(image, "memory", ": PNG_IMAGE_SIZE_MAX wrong", "");
3240 initimage(output, image->opts, "memory", image->stride_extra);
3247 if (png_image_write_to_memory(&image->image, output->input_memory,
3248 &output->input_memory_size, convert_to_8bit, image->buffer+16,
3249 (png_int_32)image->stride, image->colormap))
3254 return logerror(image, "memory", ": memory size wrong", "");
3258 return logerror(image, "memory", ": write failed", "");
3262 return logerror(image, "memory", ": out of memory", "");
3266 return logerror(image, "memory", ": get size:", "");
3269 /* 'output' has an initialized temporary image, read this back in and compare
3272 * However, if the original image was color-mapped, a simple read will zap
3276 if (read_file(output, image->image.format | FORMAT_NO_CHANGE, NULL))
3278 png_uint_32 original_format = image->image.format;
3283 if ((output->image.format & BASE_FORMATS) !=
3285 return logerror(image, image->file_name, ": format changed on read: ",
3288 return compare_two_images(image, output, 0/*via linear*/, NULL);
3298 testimage(Image *image, png_uint_32 opts, format_list *pf)
3301 Image copy;
3303 /* Copy the original data, stealing it from 'image' */
3304 checkopaque(image);
3305 copy = *image;
3312 image->input_file = NULL;
3313 image->input_memory = NULL;
3314 image->input_memory_size = 0;
3315 image->tmpfile_name[0] = 0;
3319 Image output;
3326 * removal with a background color or by composting onto the image; this
3346 (image->image.format & PNG_FORMAT_FLAG_ALPHA) != 0)
3379 result = compare_two_images(image, ©, 0/*via linear*/, background);
3396 result = compare_two_images(image, &output, 0, background);
3414 * 'image' has an alpha channel but 'output' does not then there
3419 result = compare_two_images(image, &output, 1/*via_linear*/,
3440 Image image;
3444 newimage(&image);
3445 initimage(&image, opts, file_name, stride_extra);
3446 result = read_one_file(&image);
3448 result = testimage(&image, opts, formats);
3449 freeimage(&image);