1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| png_structp struct_ptr;
png_infop info_ptr;
FILE *stream;
png_byte magic_number[8];
png_bytep *row_pointers;
unsigned int y;
char *buffer;
struct_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (struct_ptr == NULL)
{
vlc_msg_error("The pointer png_struct can't be created", ERRNO_OFF);
return (-1);
}
info_ptr = png_create_info_struct (struct_ptr);
if (info_ptr == NULL)
{
vlc_msg_error("The pointer png_info can't be created", ERRNO_OFF);
return (-1);
}
stream = fopen(path_image, "r");
if (stream == NULL)
{
vlc_msg_error(path_image, ERRNO_ON);
return (-1);
}
if (fread(magic_number, 1, sizeof(magic_number), stream) != sizeof(magic_number))
{
vlc_msg_error("The file can't be read", ERRNO_OFF);
return (-1);
}
if (png_check_sig (magic_number, sizeof(magic_number)) == 0)
{
vlc_msg_error("The file is not a PNG image", ERRNO_OFF);
return (-1);
}
png_init_io(struct_ptr, stream);
png_set_sig_bytes(struct_ptr, sizeof(magic_number));
png_read_info (struct_ptr, info_ptr);
if (png_get_color_type(struct_ptr, info_ptr) != PNG_COLOR_TYPE_RGBA)
{
png_set_palette_to_rgb(struct_ptr);
}
png_read_update_info (struct_ptr, info_ptr);
row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * info_ptr->height);
for (y = 0 ; y < info_ptr->height ; y++)
{
row_pointers[y] = (png_byte*) malloc(info_ptr->rowbytes);
}
png_read_image(struct_ptr, row_pointers);
image->ximage = XCreateImage(winunix->x11server.display, winunix->x11server.visual,
png_get_bit_depth(struct_ptr, info_ptr), ZPixmap, 0, (char *) row_pointers,
info_ptr->width, info_ptr->height, 8, 0);
if (image->ximage == NULL)
{
vlc_msg_error("The image can't be created", ERRNO_OFF);
return (-1);
}
image->size.width = info_ptr->width;
image->size.height = info_ptr->height;
image->pos.x = x_image;
image->pos.y = y_image;
png_read_end(struct_ptr, info_ptr);
if (fclose(stream) != 0)
{
vlc_msg_warning("The file can't be closed", ERRNO_ON);
return (-1);
}
png_destroy_info_struct(struct_ptr, &(info_ptr));
png_destroy_read_struct(&(struct_ptr), NULL, NULL);
return (0); |
Partager