26 #if PNG_LIBPNG_VER < 10209 27 #define png_set_expand_gray_1_2_4_to_8(png) png_set_gray_1_2_4_to_8(png) 30 static png_structp
png;
40 #define WIDTH (is_cursor?raw_width-1:raw_width) 41 #define HEIGHT (is_cursor?raw_height-1:raw_height) 43 #define HOT_X (is_cursor?raw_hot_x-1:0) 44 #define HOT_Y (is_cursor?raw_hot_y-1:0) 46 #define REAL(v) (is_cursor?v+1:v) 48 #define PPIX_AT(x,y) ((bitmap_data + (rowstride * y)) + (x * 4)) 55 #define R_AT(x,y) *(PPIX_AT(x,y) + R_OFF) 56 #define G_AT(x,y) *(PPIX_AT(x,y) + G_OFF) 57 #define B_AT(x,y) *(PPIX_AT(x,y) + B_OFF) 58 #define A_AT(x,y) *(PPIX_AT(x,y) + A_OFF) 64 fprintf(stderr,
"usage: fb_convert_image input.png output.inc varname\n");
75 if (
A_AT(i, 0) == 255) {
76 if (
G_AT(i, 0) == 255) {
80 if ((
B_AT(i, 0) != 0) || (
R_AT(i, 0) != 0)) {
84 }
else if (
A_AT(i, 0) != 0) {
89 if (greenpixels != 1) {
95 if (
A_AT(0, i) == 255) {
96 if (
G_AT(0, i) == 255) {
100 if ((
B_AT(0, i) != 0) || (
R_AT(0, i) != 0)) {
104 }
else if (
A_AT(0, i) != 0) {
109 if (greenpixels != 2) {
113 printf(
" Pointer detected. Adjusted hotspot at %d, %d (0-based)\n",
121 int bit_depth, color_type,
interlace, intent;
126 png_get_IHDR(png, info, &width, &height, &bit_depth,
127 &color_type, &interlace, 0, 0);
130 if (color_type == PNG_COLOR_TYPE_PALETTE)
131 png_set_palette_to_rgb(png);
132 if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
134 if (png_get_valid(png, info, PNG_INFO_tRNS))
135 png_set_tRNS_to_alpha(png);
137 png_set_strip_16(png);
138 if (color_type == PNG_COLOR_TYPE_GRAY ||
139 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
140 png_set_gray_to_rgb(png);
141 if (!(color_type & PNG_COLOR_MASK_ALPHA))
142 png_set_filler(png, 0xff, PNG_FILLER_AFTER);
147 if (png_get_sRGB(png, info, &intent))
148 png_set_gamma(png, 2.2, 0.45455);
150 if (png_get_gAMA(png, info, &gamma))
151 png_set_gamma(png, 2.2, gamma);
153 png_set_gamma(png, 2.2, 0.45455);
157 png_read_update_info(png, info);
159 rowbytes = png_get_rowbytes(png, info);
160 interlace = (interlace == PNG_INTERLACE_ADAM7);
175 png_uint_32 row_num,
int pass)
178 unsigned int start, step;
193 for (j = 0, i = start; i <
rowbytes; i += step) {
194 row[i++] = new_row[j++];
195 row[i++] = new_row[j++];
196 row[i++] = new_row[j++];
197 row[i++] = new_row[j++];
214 unsigned char buffer[1024];
223 printf(
" CONVERT: %s (%s)\n", argv[1], argv[3]);
225 png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
226 info = png_create_info_struct(
png);
230 f = fopen(argv[1],
"rb");
232 printf(
" Unable to open %s\n", argv[1]);
237 br = fread(buffer, 1, 1024, f);
239 png_process_data(
png,
info, buffer, br);
244 printf(
"Error reading input: %s\n", strerror(errno));
253 f = fopen(argv[2],
"w");
255 printf(
" Unable to open %s\n", argv[2]);
259 fprintf(f,
"/* This file is auto-generated from %s\n", argv[1]);
260 fprintf(f,
" *\n * Do not edit this file directly.\n */\n\n");
261 fprintf(f,
"#include <sys/types.h>\n\n");
262 fprintf(f,
"#include <stdint.h>\n\n");
263 fprintf(f,
"#include <stdbool.h>\n\n");
264 fprintf(f,
"#include <libnsfb.h>\n\n");
265 fprintf(f,
"#include \"netsurf/plot_style.h\"\n");
266 fprintf(f,
"#include \"framebuffer/gui.h\"\n");
267 fprintf(f,
"#include \"framebuffer/fbtk.h\"\n\n");
269 fprintf(f,
"static uint8_t %s_pixdata[] = {\n", argv[3]);
270 for (y = 0; y <
HEIGHT; ++y) {
277 for (x = 0; x <
WIDTH; ++x) {
278 for (c = 0; c < 4; ++c) {
279 unsigned char b = *rowptr++;
280 fprintf(f,
"0x%02x, ", b);
285 fprintf(f,
"};\n\n");
287 fprintf(f,
"struct fbtk_bitmap %s = {\n", argv[3]);
288 fprintf(f,
"\t.width\t\t= %d,\n",
WIDTH);
289 fprintf(f,
"\t.height\t\t= %d,\n", HEIGHT);
290 fprintf(f,
"\t.hot_x\t\t= %d,\n",
HOT_X);
291 fprintf(f,
"\t.hot_y\t\t= %d,\n",
HOT_Y);
292 fprintf(f,
"\t.pixdata\t= %s_pixdata,\n", argv[3]);
294 fprintf(f,
"};\n\n");
static void end_callback(png_structp png, png_infop info)
Interface to utility string handling.
static unsigned int interlace_row_step[8]
static unsigned char * bitmap_data
static unsigned int interlace_row_start[8]
static void row_callback(png_structp png, png_bytep new_row, png_uint_32 row_num, int pass)
int main(int argc, char **argv)
Normal entry point from OS.
static osspriteop_area * buffer
The buffer characteristics.
static void info_callback(png_structp png, png_infop info)
static unsigned int interlace_step[8]
static void detect_hotspot(void)
static unsigned int interlace_start[8]
#define png_set_expand_gray_1_2_4_to_8(png)