+ wxT("PNG files (*.png)|*.png|")
+#endif
+#if wxUSE_LIBJPEG
+ wxT("JPEG files (*.jpg)|*.jpg|")
+#endif
+#if wxUSE_GIF
+ wxT("GIF files (*.gif)|*.gif|")
+#endif
+#if wxUSE_LIBTIFF
+ wxT("TIFF files (*.tif)|*.tif|")
+#endif
+#if wxUSE_PCX
+ wxT("PCX files (*.pcx)|*.pcx|")
+#endif
+#if wxUSE_XPM
+ wxT("X PixMap files (*.xpm)|*.xpm|")
+#endif
+ wxT("ICO files (*.ico)|*.ico|")
+ wxT("CUR files (*.cur)|*.cur"),
+ wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
+ this);
+
+ if ( savefilename.empty() )
+ return;
+
+ wxString extension;
+ wxFileName::SplitPath(savefilename, NULL, NULL, &extension);
+
+ bool saved = false;
+ if ( extension == wxT("bmp") )
+ {
+ static const int bppvalues[] =
+ {
+ wxBMP_1BPP,
+ wxBMP_1BPP_BW,
+ wxBMP_4BPP,
+ wxBMP_8BPP,
+ wxBMP_8BPP_GREY,
+ wxBMP_8BPP_RED,
+ wxBMP_8BPP_PALETTE,
+ wxBMP_24BPP
+ };
+
+ const wxString bppchoices[] =
+ {
+ wxT("1 bpp color"),
+ wxT("1 bpp B&W"),
+ wxT("4 bpp color"),
+ wxT("8 bpp color"),
+ wxT("8 bpp greyscale"),
+ wxT("8 bpp red"),
+ wxT("8 bpp own palette"),
+ wxT("24 bpp")
+ };
+
+ int bppselection = wxGetSingleChoiceIndex(wxT("Set BMP BPP"),
+ wxT("Image sample: save file"),
+ WXSIZEOF(bppchoices),
+ bppchoices,
+ this);
+ if ( bppselection != -1 )
+ {
+ int format = bppvalues[bppselection];
+ image.SetOption(wxIMAGE_OPTION_BMP_FORMAT, format);
+
+ if ( format == wxBMP_8BPP_PALETTE )
+ {
+ unsigned char *cmap = new unsigned char [256];
+ for ( int i = 0; i < 256; i++ )
+ cmap[i] = (unsigned char)i;
+ image.SetPalette(wxPalette(256, cmap, cmap, cmap));
+
+ delete[] cmap;
+ }
+ }
+ }
+#if wxUSE_LIBPNG
+ else if ( extension == wxT("png") )
+ {
+ static const int pngvalues[] =
+ {
+ wxPNG_TYPE_COLOUR,
+ wxPNG_TYPE_COLOUR,
+ wxPNG_TYPE_GREY,
+ wxPNG_TYPE_GREY,
+ wxPNG_TYPE_GREY_RED,
+ wxPNG_TYPE_GREY_RED,
+ };
+
+ const wxString pngchoices[] =
+ {
+ wxT("Colour 8bpp"),
+ wxT("Colour 16bpp"),
+ wxT("Grey 8bpp"),
+ wxT("Grey 16bpp"),
+ wxT("Grey red 8bpp"),
+ wxT("Grey red 16bpp"),
+ };
+
+ int sel = wxGetSingleChoiceIndex(wxT("Set PNG format"),
+ wxT("Image sample: save file"),
+ WXSIZEOF(pngchoices),
+ pngchoices,
+ this);
+ if ( sel != -1 )
+ {
+ image.SetOption(wxIMAGE_OPTION_PNG_FORMAT, pngvalues[sel]);
+ image.SetOption(wxIMAGE_OPTION_PNG_BITDEPTH, sel % 2 ? 16 : 8);
+
+ // these values are taken from OptiPNG with -o3 switch
+ const wxString compressionChoices[] =
+ {
+ wxT("compression = 9, memory = 8, strategy = 0, filter = 0"),
+ wxT("compression = 9, memory = 9, strategy = 0, filter = 0"),
+ wxT("compression = 9, memory = 8, strategy = 1, filter = 0"),
+ wxT("compression = 9, memory = 9, strategy = 1, filter = 0"),
+ wxT("compression = 1, memory = 8, strategy = 2, filter = 0"),
+ wxT("compression = 1, memory = 9, strategy = 2, filter = 0"),
+ wxT("compression = 9, memory = 8, strategy = 0, filter = 5"),
+ wxT("compression = 9, memory = 9, strategy = 0, filter = 5"),
+ wxT("compression = 9, memory = 8, strategy = 1, filter = 5"),
+ wxT("compression = 9, memory = 9, strategy = 1, filter = 5"),
+ wxT("compression = 1, memory = 8, strategy = 2, filter = 5"),
+ wxT("compression = 1, memory = 9, strategy = 2, filter = 5"),
+ };
+
+ int sel = wxGetSingleChoiceIndex(wxT("Select compression option (Cancel to use default)\n"),
+ wxT("PNG Compression Options"),
+ WXSIZEOF(compressionChoices),
+ compressionChoices,
+ this);
+ if (sel != -1)
+ {
+ const int zc[] = {9, 9, 9, 9, 1, 1, 9, 9, 9, 9, 1, 1};
+ const int zm[] = {8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9};
+ const int zs[] = {0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2};
+ const int f[] = {0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
+ 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8};
+
+ image.SetOption(wxIMAGE_OPTION_PNG_COMPRESSION_LEVEL , zc[sel]);
+ image.SetOption(wxIMAGE_OPTION_PNG_COMPRESSION_MEM_LEVEL , zm[sel]);
+ image.SetOption(wxIMAGE_OPTION_PNG_COMPRESSION_STRATEGY , zs[sel]);
+ image.SetOption(wxIMAGE_OPTION_PNG_FILTER , f[sel]);
+ image.SetOption(wxIMAGE_OPTION_PNG_COMPRESSION_BUFFER_SIZE, 1048576); // 1 MB
+ }
+ }
+ }