|
Author: fabien
Date: 2007-04-05 15:31:58 -0400 (Thu, 05 Apr 2007)
New Revision: 5763
Log:
added a new write() api too pngImage so we can now easily flush a memory image uchar buffer to a file. updated some osx code to compile, lot of mess here though to fix ... even fluid "saves as" is broken !
Modified:
branches/fctrunk/fltk/SharedImage.h
branches/fctrunk/fluid/fluid.cxx
branches/fctrunk/images/fl_png.cxx
branches/fctrunk/src/Offscreen.cxx
branches/fctrunk/test/keyboard_ui.cxx
Modified: branches/fctrunk/fltk/SharedImage.h
===================================================================
--- branches/fctrunk/fltk/SharedImage.h 2007-04-05 15:58:57 UTC (rev 5762)
+++ branches/fctrunk/fltk/SharedImage.h 2007-04-05 19:31:58 UTC (rev 5763)
@@ -224,6 +224,7 @@
static SharedImage* get(const char* name, const uchar* datas = 0) {
return SharedImage::get(create, name, datas);
}
+ static bool write(const char * filename, const uchar* datas, int w, int h); // writes a buffer to a file ...
bool fetch();
};
Modified: branches/fctrunk/fluid/fluid.cxx
===================================================================
--- branches/fctrunk/fluid/fluid.cxx 2007-04-05 15:58:57 UTC (rev 5762)
+++ branches/fctrunk/fluid/fluid.cxx 2007-04-05 19:31:58 UTC (rev 5763)
@@ -60,7 +60,6 @@
#include <fltk/ask.h>
#include <fltk/draw.h>
#include <fltk/file_chooser.h>
-#include <fltk/ask.h>
#include <fltk/filename.h>
#include <fltk/FileIcon.h>
#include <fltk/Preferences.h>
@@ -103,17 +102,6 @@
DECL_MENUCBV2(toggle_sourceview_cb,DoubleBufferWindow);
-#if HAVE_LIBPNG
-
-# ifdef HAVE_LOCAL_PNG_H
-# include "libpng/png.h"
-#elif defined(HAVE_PNG_H)
-# include <png.h>
-#elif defined(HAVE_LIBPNG_PNG_H)
-# include <libpng/png.h>
-#endif
-#endif
-
/////////////////////////////////////////
// Read preferences file
PrefsData prefs(Preferences::USER, "fltk.org", "fluid2");
@@ -399,37 +387,9 @@
// Save to a PNG file...
filename_setext(filename, sizeof(filename), ".png");
-
- FILE *fp;
-
- if ((fp = fopen(filename, "wb")) == NULL) {
- delete[] pixels;
- fltk::alert("Error writing %s: %s", filename, strerror(errno));
- return;
- }
- // debug put smtg green in the buffer we can see: for (int tb=1;tb< w*h*3*sizeof(uchar);tb+=3) pixels[tb]=0xC0;
-
- // TODO png write code
- 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);
-
+ printf("***** png filename %s ******\n",filename);
+ pngImage::write(filename, pixels, w, h);
+
#if 0 // The original PPM output code...
strcpy(ext, ".ppm");
fp = fopen(filename, "wb");
Modified: branches/fctrunk/images/fl_png.cxx
===================================================================
--- branches/fctrunk/images/fl_png.cxx 2007-04-05 15:58:57 UTC (rev 5762)
+++ branches/fctrunk/images/fl_png.cxx 2007-04-05 19:31:58 UTC (rev 5763)
@@ -38,7 +38,9 @@
# include <libpng/png.h>
#endif
+#include <fltk/ask.h>
# include <stdlib.h>
+#include <errno.h>
static png_bytep cur_datas;
@@ -57,6 +59,41 @@
using namespace fltk;
+//! writes a buffer to a file ...
+bool pngImage::write(const char * filename, const uchar* pixels, int w, int h) {
+ FILE *fp;
+
+ if ((fp = fopen(filename, "wb")) == NULL) {
+ delete[] pixels;
+ fltk::alert("Error writing png image %s: %s", filename, strerror(errno));
+ return false;
+ }
+ // debug put smtg green that we can see: for (int tb=1;tb< w*h*3*sizeof(uchar);tb+=3) pixels[tb]=0xC0;
+
+ // TODO png write code
+ 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 1
+ fltk::alert("Writes successfully png image %s\n", filename);
+#endif
+ return true;
+}
+
bool pngImage::test(const uchar* datas, unsigned size)
{
#if !HAVE_LIBPNG
Modified: branches/fctrunk/src/Offscreen.cxx
===================================================================
--- branches/fctrunk/src/Offscreen.cxx 2007-04-05 15:58:57 UTC (rev 5762)
+++ branches/fctrunk/src/Offscreen.cxx 2007-04-05 19:31:58 UTC (rev 5763)
@@ -259,6 +259,10 @@
CGDataProviderRelease(src_bytes);
return true;
}
+// temporary for testing the lib, will be re-implemented:
+bool Offscreen::copy_with_alpha(int x, int y, int w, int h, int srcx, int srcy) {
+ return copy(x, y, w, h, srcx, srcy);
+}
#else // QD
// TODO : finish the work for the optional QD impl.:
Modified: branches/fctrunk/test/keyboard_ui.cxx
===================================================================
--- branches/fctrunk/test/keyboard_ui.cxx 2007-04-05 15:58:57 UTC (rev 5762)
+++ branches/fctrunk/test/keyboard_ui.cxx 2007-04-05 19:31:58 UTC (rev 5763)
@@ -11,6 +11,7 @@
fltk::Window* w;
{fltk::Window* o = new fltk::Window(490, 190);
w = o;
+ o->shortcut(0xff1b);
o->begin();
{fltk::Output* o = key_output = new fltk::Output(15, 15, 170, 30, "Fl::event_key():");
o->textfont(fltk::COURIER);
[ Direct Link to Message ] | |