diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2021-11-09 19:55:35 +0100 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2021-11-09 20:36:23 +0100 |
| commit | 500e470d392a547e6b72ac3fec92e0cd638c0d2f (patch) | |
| tree | 7e308cfe1aaa4881ac75fdafeffe6bc9518efd62 /fluid | |
| parent | 5c5244b1622561809173cbfc41fa9c1290d55fe2 (diff) | |
Refactor fluid: make fl_write_png() public
The new function fl_write_png() was moved to its own file and is now
publicly available ("exported") so other programs can use it.
This function was used in fluid to write a window screenshot (.png)
together with a template (.fl) to preferences storage.
Diffstat (limited to 'fluid')
| -rw-r--r-- | fluid/fluid.cxx | 25 |
1 files changed, 2 insertions, 23 deletions
diff --git a/fluid/fluid.cxx b/fluid/fluid.cxx index b5e01f316..fdc005d42 100644 --- a/fluid/fluid.cxx +++ b/fluid/fluid.cxx @@ -347,34 +347,13 @@ void save_template_cb(Fl_Widget *, void *) { // Save to a PNG file... strcpy(ext, ".png"); - FILE *fp; - - if ((fp = fl_fopen(filename, "wb")) == NULL) { + errno = 0; + if (fl_write_png(filename, w, h, 3, pixels) != 0) { delete[] pixels; fl_alert("Error writing %s: %s", filename, strerror(errno)); return; } - png_structp pptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); - png_infop iptr = png_create_info_struct(pptr); - png_bytep ptr = (png_bytep)pixels; - - png_init_io(pptr, fp); - png_set_IHDR(pptr, iptr, w, h, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - png_set_sRGB(pptr, iptr, PNG_sRGB_INTENT_PERCEPTUAL); - - png_write_info(pptr, iptr); - - for (int i = h; i > 0; i --, ptr += w * 3) { - png_write_row(pptr, ptr); - } - - png_write_end(pptr, iptr); - png_destroy_write_struct(&pptr, &iptr); - - fclose(fp); - # if 0 // The original PPM output code... strcpy(ext, ".ppm"); fp = fl_fopen(filename, "wb"); |
