Lines 61-87
static int load_png(stheme_t *theme, char *filename, u8 **data, struct fb_cmap *
Link Here
|
61 |
png_init_io(png_ptr, fp); |
61 |
png_init_io(png_ptr, fp); |
62 |
png_read_info(png_ptr, info_ptr); |
62 |
png_read_info(png_ptr, info_ptr); |
63 |
|
63 |
|
64 |
if (cmap && info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) |
64 |
if (cmap && png_get_color_type(png_ptr, info_ptr) != PNG_COLOR_TYPE_PALETTE) |
65 |
return -2; |
65 |
return -2; |
66 |
|
66 |
|
67 |
if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY || |
67 |
if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY || |
68 |
info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) |
68 |
png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY_ALPHA) |
69 |
png_set_gray_to_rgb(png_ptr); |
69 |
png_set_gray_to_rgb(png_ptr); |
70 |
|
70 |
|
71 |
if (info_ptr->bit_depth == 16) |
71 |
if (png_get_bit_depth(png_ptr, info_ptr) == 16) |
72 |
png_set_strip_16(png_ptr); |
72 |
png_set_strip_16(png_ptr); |
73 |
|
73 |
|
74 |
if (!want_alpha && info_ptr->color_type & PNG_COLOR_MASK_ALPHA) |
74 |
if (!want_alpha && png_get_color_type(png_ptr, info_ptr) & PNG_COLOR_MASK_ALPHA) |
75 |
png_set_strip_alpha(png_ptr); |
75 |
png_set_strip_alpha(png_ptr); |
76 |
|
76 |
|
77 |
#ifndef TARGET_KERNEL |
77 |
#ifndef TARGET_KERNEL |
78 |
if (!(info_ptr->color_type & PNG_COLOR_MASK_ALPHA) & want_alpha) { |
78 |
if (!(png_get_color_type(png_ptr, info_ptr) & PNG_COLOR_MASK_ALPHA) & want_alpha) { |
79 |
png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER); |
79 |
png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER); |
80 |
} |
80 |
} |
81 |
#endif |
81 |
#endif |
82 |
png_read_update_info(png_ptr, info_ptr); |
82 |
png_read_update_info(png_ptr, info_ptr); |
83 |
|
83 |
|
84 |
if (!cmap && info_ptr->color_type != PNG_COLOR_TYPE_RGB && info_ptr->color_type != PNG_COLOR_TYPE_RGBA) |
84 |
if (!cmap && png_get_color_type(png_ptr, info_ptr) != PNG_COLOR_TYPE_RGB && png_get_color_type(png_ptr, info_ptr) != PNG_COLOR_TYPE_RGBA) |
85 |
return -3; |
85 |
return -3; |
86 |
|
86 |
|
87 |
if (cmap) { |
87 |
if (cmap) { |
Lines 93-104
static int load_png(stheme_t *theme, char *filename, u8 **data, struct fb_cmap *
Link Here
|
93 |
|
93 |
|
94 |
rowbytes = png_get_rowbytes(png_ptr, info_ptr); |
94 |
rowbytes = png_get_rowbytes(png_ptr, info_ptr); |
95 |
|
95 |
|
96 |
if ((width && *width && info_ptr->width != *width) || (height && *height && info_ptr->height != *height)) { |
96 |
if ((width && *width && png_get_image_width(png_ptr, info_ptr) != *width) || (height && *height && png_get_image_height(png_ptr, info_ptr) != *height)) { |
97 |
iprint(MSG_ERROR, "Image size mismatch: %s.\n", filename); |
97 |
iprint(MSG_ERROR, "Image size mismatch: %s.\n", filename); |
98 |
return -2; |
98 |
return -2; |
99 |
} else { |
99 |
} else { |
100 |
*width = info_ptr->width; |
100 |
*width = png_get_image_width(png_ptr, info_ptr); |
101 |
*height = info_ptr->height; |
101 |
*height = png_get_image_height(png_ptr, info_ptr); |
102 |
} |
102 |
} |
103 |
|
103 |
|
104 |
*data = malloc(theme->xres * theme->yres * fbd.bytespp); |
104 |
*data = malloc(theme->xres * theme->yres * fbd.bytespp); |
Lines 114-124
static int load_png(stheme_t *theme, char *filename, u8 **data, struct fb_cmap *
Link Here
|
114 |
return -4; |
114 |
return -4; |
115 |
} |
115 |
} |
116 |
|
116 |
|
117 |
for (i = 0; i < info_ptr->height; i++) { |
117 |
for (i = 0; i < png_get_image_height(png_ptr, info_ptr); i++) { |
118 |
if (cmap) { |
118 |
if (cmap) { |
119 |
row_pointer = *data + info_ptr->width * i; |
119 |
row_pointer = *data + png_get_image_width(png_ptr, info_ptr) * i; |
120 |
} else if (want_alpha) { |
120 |
} else if (want_alpha) { |
121 |
row_pointer = *data + info_ptr->width * i * 4; |
121 |
row_pointer = *data + png_get_image_width(png_ptr, info_ptr) * i * 4; |
122 |
} else { |
122 |
} else { |
123 |
row_pointer = buf; |
123 |
row_pointer = buf; |
124 |
} |
124 |
} |
Lines 127-133
static int load_png(stheme_t *theme, char *filename, u8 **data, struct fb_cmap *
Link Here
|
127 |
|
127 |
|
128 |
if (cmap) { |
128 |
if (cmap) { |
129 |
int h = 256 - cmap->len; |
129 |
int h = 256 - cmap->len; |
130 |
t = *data + info_ptr->width * i; |
130 |
t = *data + png_get_image_width(png_ptr, info_ptr) * i; |
131 |
|
131 |
|
132 |
if (h) { |
132 |
if (h) { |
133 |
/* Move the colors up by 'h' offset. This is used because fbcon |
133 |
/* Move the colors up by 'h' offset. This is used because fbcon |
Lines 139-146
static int load_png(stheme_t *theme, char *filename, u8 **data, struct fb_cmap *
Link Here
|
139 |
|
139 |
|
140 |
/* We only need to convert the image if the alpha channel is not required */ |
140 |
/* We only need to convert the image if the alpha channel is not required */ |
141 |
} else if (!want_alpha) { |
141 |
} else if (!want_alpha) { |
142 |
u8 *tmp = *data + info_ptr->width * bytespp * i; |
142 |
u8 *tmp = *data + png_get_image_width(png_ptr, info_ptr) * bytespp * i; |
143 |
rgba2fb((rgbacolor*)buf, tmp, tmp, info_ptr->width, i, 0, 0xff); |
143 |
rgba2fb((rgbacolor*)buf, tmp, tmp, png_get_image_width(png_ptr, info_ptr), i, 0, 0xff); |
144 |
} |
144 |
} |
145 |
} |
145 |
} |
146 |
|
146 |
|