3
//#include "colorspace.h" // Common routines
8
write_png(char * filename, gavl_video_format_t * format, gavl_video_frame_t * frame)
11
unsigned char ** rows;
19
gavl_video_converter_t * cnv;
21
gavl_video_format_t format_1;
22
gavl_video_frame_t * frame_1 = (gavl_video_frame_t*)0;
25
if((format->pixelformat != GAVL_RGB_24) && (format->pixelformat != GAVL_RGBA_32))
27
cnv = gavl_video_converter_create();
29
gavl_video_format_copy(&format_1, format);
31
if(gavl_pixelformat_has_alpha(format->pixelformat))
33
format_1.pixelformat = GAVL_RGBA_32;
34
color_type = PNG_COLOR_TYPE_RGBA;
38
format_1.pixelformat = GAVL_RGB_24;
39
color_type = PNG_COLOR_TYPE_RGB;
41
frame_1 = gavl_video_frame_create(&format_1);
43
gavl_video_converter_init(cnv, format, &format_1);
45
gavl_video_convert(cnv, frame, frame_1);
46
gavl_video_converter_destroy(cnv);
48
else if(format->pixelformat == GAVL_RGB_24)
50
color_type = PNG_COLOR_TYPE_RGB;
54
color_type = PNG_COLOR_TYPE_RGBA;
57
output = fopen(filename, "wb");
61
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,
64
info_ptr = png_create_info_struct(png_ptr);
65
setjmp(png_jmpbuf(png_ptr));
66
png_init_io(png_ptr, output);
68
png_set_IHDR(png_ptr, info_ptr,
71
8, color_type, PNG_INTERLACE_NONE,
72
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
74
rows = malloc(format->image_height * sizeof(*rows));
78
for(i = 0; i < format->image_height; i++)
79
rows[i] = frame_1->planes[0] + i * frame_1->strides[0];
83
for(i = 0; i < format->image_height; i++)
84
rows[i] = frame->planes[0] + i * frame->strides[0];
87
png_set_rows(png_ptr, info_ptr, rows);
88
png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
90
png_destroy_write_struct(&png_ptr, &info_ptr);
94
gavl_video_frame_destroy(frame_1);
97
int main(int argc, char ** argv)
100
char filename_buffer[1024];
103
gavl_video_format_t frame_format;
105
gavl_video_frame_t * frame;
106
float color[4] = { 0.0, 1.0, 0.0, 0.5 };
108
memset(&frame_format, 0, sizeof(frame_format));
110
frame_format.image_width = 128;
111
frame_format.image_height = 128;
112
frame_format.frame_width = 128;
113
frame_format.frame_height = 128;
115
frame_format.pixel_width = 1;
116
frame_format.pixel_height = 1;
118
imax = gavl_num_pixelformats();
120
for(i = 0; i < imax; i++)
122
frame_format.pixelformat = gavl_get_pixelformat(i);
124
// if(frame_csp != GAVL_YUVA_32)
127
// csp = GAVL_RGB_24;
129
frame = gavl_video_frame_create(&frame_format);
131
sprintf(filename_buffer, "fill_%s.png",
132
gavl_pixelformat_to_string(frame_format.pixelformat));
134
gavl_video_frame_fill(frame, &frame_format, color);
135
write_png(filename_buffer, &frame_format, frame);
136
gavl_video_frame_destroy(frame);
137
fprintf(stderr, "Wrote %s\n", filename_buffer);