Merged from the trunk

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_GTK3@68793 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
John Chain
2011-08-20 05:09:45 +00:00
12 changed files with 234 additions and 81 deletions
+11 -4
View File
@@ -22,10 +22,17 @@
#include "wx/versioninfo.h"
// defines for wxImage::SetOption
#define wxIMAGE_OPTION_BITSPERSAMPLE wxString(wxT("BitsPerSample"))
#define wxIMAGE_OPTION_SAMPLESPERPIXEL wxString(wxT("SamplesPerPixel"))
#define wxIMAGE_OPTION_COMPRESSION wxString(wxT("Compression"))
#define wxIMAGE_OPTION_IMAGEDESCRIPTOR wxString(wxT("ImageDescriptor"))
#define wxIMAGE_OPTION_TIFF_BITSPERSAMPLE wxString(wxT("BitsPerSample"))
#define wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL wxString(wxT("SamplesPerPixel"))
#define wxIMAGE_OPTION_TIFF_COMPRESSION wxString(wxT("Compression"))
#define wxIMAGE_OPTION_TIFF_PHOTOMETRIC wxString(wxT("Photometric"))
#define wxIMAGE_OPTION_TIFF_IMAGEDESCRIPTOR wxString(wxT("ImageDescriptor"))
// for backwards compatibility
#define wxIMAGE_OPTION_BITSPERSAMPLE wxIMAGE_OPTION_TIFF_BITSPERSAMPLE
#define wxIMAGE_OPTION_SAMPLESPERPIXEL wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL
#define wxIMAGE_OPTION_COMPRESSION wxIMAGE_OPTION_TIFF_COMPRESSION
#define wxIMAGE_OPTION_IMAGEDESCRIPTOR wxIMAGE_OPTION_TIFF_IMAGEDESCRIPTOR
class WXDLLIMPEXP_CORE wxTIFFHandler: public wxImageHandler
{
+39 -6
View File
@@ -1084,10 +1084,16 @@ public:
/**
Gets a user-defined string-valued option.
Currently the only defined string option is
Generic options:
@li @c wxIMAGE_OPTION_FILENAME: The name of the file from which the image
was loaded.
Options specific to wxGIFHandler:
@li @c wxIMAGE_OPTION_GIF_COMMENT: The comment text that is read from
or written to the GIF file. In an animated GIF each frame can have
its own comment. If there is only a comment in the first frame of
a GIF it will not be repeated in other frames.
@param name
The name of the option, case-insensitive.
@return
@@ -1162,11 +1168,38 @@ public:
the resulting PNG file. Use this option if your application produces
images with small size variation.
Options specific to wxGIFHandler:
@li @c wxIMAGE_OPTION_GIF_COMMENT: The comment text that is read from
or written to the GIF file. In an animated GIF each frame can have
its own comment. If there is only a comment in the first frame of
a GIF it will not be repeated in other frames.
Options specific to wxTIFFHandler:
@li @c wxIMAGE_OPTION_TIFF_BITSPERSAMPLE: Number of bits per
sample (channel). Currently values of 1 and 8 are supported. A
value of 1 results in a black and white image. A value of 8 (the
default) can mean greyscale or RGB, depending on the value of
@c wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL.
@li @c wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL: Number of samples
(channels) per pixel. Currently values of 1 and 3 are supported.
A value of 1 results in either a greyscale (by default) or black and
white image, depending on the value of
@c wxIMAGE_OPTION_TIFF_BITSPERSAMPLE. A value of 3 (the default)
will result in an RGB image.
@li @c wxIMAGE_OPTION_TIFF_COMPRESSION: Compression type. By default
it is set to 1 (COMPRESSION_NONE). Typical other values are
5 (COMPRESSION_LZW) and 7 (COMPRESSION_JPEG). See tiff.h for more
options.
@li @c wxIMAGE_OPTION_TIFF_PHOTOMETRIC: Specifies the photometric
interpretation. By default it is set to 2 (PHOTOMETRIC_RGB) for RGB
images and 0 (PHOTOMETRIC_MINISWHITE) for greyscale or black and
white images. It can also be set to 1 (PHOTOMETRIC_MINISBLACK) to
treat the lowest value as black and highest as white.
If you want a greyscale image it is also sufficient to only specify
@c wxIMAGE_OPTION_TIFF_PHOTOMETRIC and set it to either
PHOTOMETRIC_MINISWHITE or PHOTOMETRIC_MINISBLACK. The other values
are taken care of.
@note
Be careful when combining the options @c wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL,
@c wxIMAGE_OPTION_TIFF_BITSPERSAMPLE, and @c wxIMAGE_OPTION_TIFF_PHOTOMETRIC.
While some measures are taken to prevent illegal combinations and/or
values, it is still easy to abuse them and come up with invalid
results in the form of either corrupted images or crashes.
@param name
The name of the option, case-insensitive.
+21 -21
View File
@@ -503,29 +503,29 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
dc.DrawBitmap(my_toucan_blur, x, y+15, true);
}
// if (my_smile_xbm.IsOk())
// {
// int x = 300, y = 1800;
if (my_smile_xbm.IsOk())
{
int x = 300, y = 1800;
// dc.DrawText( wxT("XBM bitmap"), x, y );
// dc.DrawText( wxT("(green on red)"), x, y + 15 );
// dc.SetTextForeground( wxT("GREEN") );
// dc.SetTextBackground( wxT("RED") );
// // dc.DrawBitmap( my_smile_xbm, x, y + 30 );
dc.DrawText( wxT("XBM bitmap"), x, y );
dc.DrawText( wxT("(green on red)"), x, y + 15 );
dc.SetTextForeground( wxT("GREEN") );
dc.SetTextBackground( wxT("RED") );
dc.DrawBitmap( my_smile_xbm, x, y + 30 );
// dc.SetTextForeground( *wxBLACK );
// dc.DrawText( wxT("After wxImage conversion"), x + 120, y );
// dc.DrawText( wxT("(red on white)"), x + 120, y + 15 );
// dc.SetTextForeground( wxT("RED") );
// wxImage i = my_smile_xbm.ConvertToImage();
// i.SetMaskColour( 255, 255, 255 );
// i.Replace( 0, 0, 0,
// wxRED_PEN->GetColour().Red(),
// wxRED_PEN->GetColour().Green(),
// wxRED_PEN->GetColour().Blue() );
// dc.DrawBitmap( wxBitmap(i), x + 120, y + 30, true );
// dc.SetTextForeground( *wxBLACK );
// }
dc.SetTextForeground( *wxBLACK );
dc.DrawText( wxT("After wxImage conversion"), x + 120, y );
dc.DrawText( wxT("(red on white)"), x + 120, y + 15 );
dc.SetTextForeground( wxT("RED") );
wxImage i = my_smile_xbm.ConvertToImage();
i.SetMaskColour( 255, 255, 255 );
i.Replace( 0, 0, 0,
wxRED_PEN->GetColour().Red(),
wxRED_PEN->GetColour().Green(),
wxRED_PEN->GetColour().Blue() );
dc.DrawBitmap( wxBitmap(i), x + 120, y + 30, true );
dc.SetTextForeground( *wxBLACK );
}
// wxBitmap mono( 60,50,1 );
+64 -20
View File
@@ -437,24 +437,26 @@ bool wxTIFFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos
}
uint16 spp, bpp, compression;
image->SetOption(wxIMAGE_OPTION_TIFF_PHOTOMETRIC, photometric);
uint16 spp, bps, compression;
/*
Read some baseline TIFF tags which helps when re-saving a TIFF
to be similar to the original image.
*/
if ( TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &spp) )
{
image->SetOption(wxIMAGE_OPTION_SAMPLESPERPIXEL, spp);
image->SetOption(wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL, spp);
}
if ( TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &bpp) )
if ( TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &bps) )
{
image->SetOption(wxIMAGE_OPTION_BITSPERSAMPLE, bpp);
image->SetOption(wxIMAGE_OPTION_TIFF_BITSPERSAMPLE, bps);
}
if ( TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &compression) )
{
image->SetOption(wxIMAGE_OPTION_COMPRESSION, compression);
image->SetOption(wxIMAGE_OPTION_TIFF_COMPRESSION, compression);
}
// Set the resolution unit.
@@ -587,15 +589,44 @@ bool wxTIFFHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbo
}
int spp = image->GetOptionInt(wxIMAGE_OPTION_SAMPLESPERPIXEL);
int spp = image->GetOptionInt(wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL);
if ( !spp )
spp = 3;
int bpp = image->GetOptionInt(wxIMAGE_OPTION_BITSPERSAMPLE);
if ( !bpp )
bpp = 8;
int bps = image->GetOptionInt(wxIMAGE_OPTION_TIFF_BITSPERSAMPLE);
if ( !bps )
{
bps = 8;
}
else if (bps == 1)
{
// One bit per sample combined with 3 samples per pixel is
// not allowed and crashes libtiff.
spp = 1;
}
int compression = image->GetOptionInt(wxIMAGE_OPTION_COMPRESSION);
int photometric = PHOTOMETRIC_RGB;
if ( image->HasOption(wxIMAGE_OPTION_TIFF_PHOTOMETRIC) )
{
photometric = image->GetOptionInt(wxIMAGE_OPTION_TIFF_PHOTOMETRIC);
if (photometric == PHOTOMETRIC_MINISWHITE
|| photometric == PHOTOMETRIC_MINISBLACK)
{
// either b/w or greyscale
spp = 1;
}
}
else if (spp == 1)
{
photometric = PHOTOMETRIC_MINISWHITE;
}
const bool isColouredImage = (spp > 1)
&& (photometric != PHOTOMETRIC_MINISWHITE)
&& (photometric != PHOTOMETRIC_MINISBLACK);
int compression = image->GetOptionInt(wxIMAGE_OPTION_TIFF_COMPRESSION);
if ( !compression )
{
// we can't use COMPRESSION_LZW because current version of libtiff
@@ -606,20 +637,19 @@ bool wxTIFFHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbo
}
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, spp);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bpp);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, spp*bpp == 1 ? PHOTOMETRIC_MINISBLACK
: PHOTOMETRIC_RGB);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photometric);
TIFFSetField(tif, TIFFTAG_COMPRESSION, compression);
// scanlinesize if determined by spp and bpp
tsize_t linebytes = (tsize_t)image->GetWidth() * spp * bpp / 8;
// scanlinesize if determined by spp and bps
tsize_t linebytes = (tsize_t)image->GetWidth() * spp * bps / 8;
if ( (image->GetWidth() % 8 > 0) && (spp * bpp < 8) )
if ( (image->GetWidth() % 8 > 0) && (spp * bps < 8) )
linebytes+=1;
unsigned char *buf;
if (TIFFScanlineSize(tif) > linebytes || (spp * bpp < 24))
if (TIFFScanlineSize(tif) > linebytes || !isColouredImage)
{
buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(tif));
if (!buf)
@@ -641,16 +671,30 @@ bool wxTIFFHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbo
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP,TIFFDefaultStripSize(tif, (uint32) -1));
const bool minIsWhite = (photometric == PHOTOMETRIC_MINISWHITE);
unsigned char *ptr = image->GetData();
for ( int row = 0; row < image->GetHeight(); row++ )
{
if ( buf )
{
if ( spp * bpp > 1 )
if (isColouredImage)
{
// color image
memcpy(buf, ptr, image->GetWidth());
}
else if (spp * bps == 8) // greyscale image
{
for ( int column = 0; column < linebytes; column++ )
{
uint8 value = ptr[column*3 + 1];
if (minIsWhite)
{
value = 255 - value;
}
buf[column] = value;
}
}
else // black and white image
{
for ( int column = 0; column < linebytes; column++ )
@@ -658,9 +702,9 @@ bool wxTIFFHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbo
uint8 reverse = 0;
for ( int bp = 0; bp < 8; bp++ )
{
if ( ptr[column*24 + bp*3] > 0 )
if ( (ptr[column*24 + bp*3 + 1] <=127) == minIsWhite )
{
// check only red as this is sufficient
// check only green as this is sufficient
reverse = (uint8)(reverse | 128 >> bp);
}
}
+24 -23
View File
@@ -1976,33 +1976,34 @@ bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxData
wxDataViewVirtualListModel *list_model =
(wxDataViewVirtualListModel*) GetOwner()->GetModel();
m_count = list_model->GetCount();
UpdateDisplay();
return true;
}
SortPrepare();
wxDataViewTreeNode * node;
node = FindNode(parent);
if( node == NULL )
return false;
node->SetHasChildren( true );
if( g_model->IsContainer( item ) )
{
wxDataViewTreeNode * newnode = new wxDataViewTreeNode( node );
newnode->SetItem(item);
newnode->SetHasChildren( true );
node->AddNode( newnode);
}
else
node->AddLeaf( item.GetID() );
{
SortPrepare();
node->ChangeSubTreeCount(1);
wxDataViewTreeNode * node;
node = FindNode(parent);
if( node == NULL )
return false;
node->SetHasChildren( true );
if( g_model->IsContainer( item ) )
{
wxDataViewTreeNode * newnode = new wxDataViewTreeNode( node );
newnode->SetItem(item);
newnode->SetHasChildren( true );
node->AddNode( newnode);
}
else
node->AddLeaf( item.GetID() );
node->ChangeSubTreeCount(1);
m_count = -1;
}
m_count = -1;
UpdateDisplay();
return true;
+14 -2
View File
@@ -338,7 +338,7 @@ COND_wxUSE_REGEX_builtin___LIB_REGEX_p = \
### Targets: ###
all: test$(EXEEXT) $(__test_gui___depname) $(__test_gui_bundle___depname) data fr
all: test$(EXEEXT) $(__test_gui___depname) $(__test_gui_bundle___depname) data data-images fr
install:
@@ -406,6 +406,18 @@ data:
esac; \
done
data-images:
@mkdir -p image
@for f in horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp; do \
if test ! -f image/$$f -a ! -d image/$$f ; \
then x=yep ; \
else x=`find $(srcdir)/image/$$f -newer image/$$f -print` ; \
fi; \
case "$$x" in ?*) \
cp -pRf $(srcdir)/image/$$f image ;; \
esac; \
done
fr:
@mkdir -p ./intl/fr
@for f in internat.po internat.mo; do \
@@ -925,4 +937,4 @@ failtest:
# Include dependency info, if present:
@IF_GNU_MAKE@-include ./.deps/*.d
.PHONY: all install uninstall clean distclean test_gui_bundle data fr
.PHONY: all install uninstall clean distclean test_gui_bundle data data-images fr
+32
View File
@@ -73,6 +73,7 @@ private:
CPPUNIT_TEST( CompareLoadedImage );
CPPUNIT_TEST( CompareSavedImage );
CPPUNIT_TEST( SavePNG );
CPPUNIT_TEST( SaveTIFF );
CPPUNIT_TEST( SaveAnimatedGIF );
CPPUNIT_TEST( ReadCorruptedTGA );
CPPUNIT_TEST( GIFComment );
@@ -87,6 +88,7 @@ private:
void CompareLoadedImage();
void CompareSavedImage();
void SavePNG();
void SaveTIFF();
void SaveAnimatedGIF();
void ReadCorruptedTGA();
void GIFComment();
@@ -1088,6 +1090,36 @@ void ImageTestCase::SavePNG()
}
static void TestTIFFImage(const wxString& option, int value)
{
wxImage image("horse.png");
wxMemoryOutputStream memOut;
image.SetOption(option, value);
CPPUNIT_ASSERT(image.SaveFile(memOut, wxBITMAP_TYPE_TIF));
wxMemoryInputStream memIn(memOut);
CPPUNIT_ASSERT(memIn.IsOk());
wxImage savedImage(memIn);
CPPUNIT_ASSERT(savedImage.IsOk());
WX_ASSERT_EQUAL_MESSAGE(("While checking for option %s", option),
true, savedImage.HasOption(option));
WX_ASSERT_EQUAL_MESSAGE(("While testing for %s", option),
value, savedImage.GetOptionInt(option));
}
void ImageTestCase::SaveTIFF()
{
TestTIFFImage(wxIMAGE_OPTION_TIFF_BITSPERSAMPLE, 1);
TestTIFFImage(wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL, 1);
TestTIFFImage(wxIMAGE_OPTION_TIFF_PHOTOMETRIC, 0/*PHOTOMETRIC_MINISWHITE*/);
TestTIFFImage(wxIMAGE_OPTION_TIFF_PHOTOMETRIC, 1/*PHOTOMETRIC_MINISBLACK*/);
}
void ImageTestCase::SaveAnimatedGIF()
{
#if wxUSE_PALETTE
+5 -1
View File
@@ -420,7 +420,7 @@ $(OBJS):
### Targets: ###
all: $(OBJS)\test.exe $(__test_gui___depname) data fr
all: $(OBJS)\test.exe $(__test_gui___depname) data data-images fr
clean:
-if exist $(OBJS)\*.obj del $(OBJS)\*.obj
@@ -455,6 +455,10 @@ data:
if not exist $(OBJS) mkdir $(OBJS)
for %f in (horse.ani horse.bmp horse.cur horse.gif horse.ico horse.jpg horse.pcx horse.png horse.pnm horse.tga horse.tif horse.xpm) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
data-images:
if not exist image mkdir image
for %f in (horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp) do if not exist image\%f copy .\image\%f image
fr:
if not exist $(OBJS)\intl\fr mkdir $(OBJS)\intl\fr
for %f in (internat.po internat.mo) do if not exist $(OBJS)\intl\fr\%f copy .\intl\fr\%f $(OBJS)\intl\fr
+6 -2
View File
@@ -416,7 +416,7 @@ $(OBJS):
### Targets: ###
all: $(OBJS)\test.exe $(__test_gui___depname) data fr
all: $(OBJS)\test.exe $(__test_gui___depname) data data-images fr
clean:
-if exist $(OBJS)\*.o del $(OBJS)\*.o
@@ -436,6 +436,10 @@ data:
if not exist $(OBJS) mkdir $(OBJS)
for %%f in (horse.ani horse.bmp horse.cur horse.gif horse.ico horse.jpg horse.pcx horse.png horse.pnm horse.tga horse.tif horse.xpm) do if not exist $(OBJS)\%%f copy .\%%f $(OBJS)
data-images:
if not exist image mkdir image
for %%f in (horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp) do if not exist image\%%f copy .\image\%%f image
fr:
if not exist $(OBJS)\intl\fr mkdir $(OBJS)\intl\fr
for %%f in (internat.po internat.mo) do if not exist $(OBJS)\intl\fr\%%f copy .\intl\fr\%%f $(OBJS)\intl\fr
@@ -929,7 +933,7 @@ $(OBJS)\test_gui_setsize.o: ./window/setsize.cpp
$(OBJS)\test_gui_xrctest.o: ./xml/xrctest.cpp
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
.PHONY: all clean data fr
.PHONY: all clean data data-images fr
SHELL := $(COMSPEC)
+5 -1
View File
@@ -552,7 +552,7 @@ $(OBJS):
### Targets: ###
all: $(OBJS)\test.exe $(__test_gui___depname) data fr
all: $(OBJS)\test.exe $(__test_gui___depname) data data-images fr
clean:
-if exist $(OBJS)\*.obj del $(OBJS)\*.obj
@@ -581,6 +581,10 @@ data:
if not exist $(OBJS) mkdir $(OBJS)
for %f in (horse.ani horse.bmp horse.cur horse.gif horse.ico horse.jpg horse.pcx horse.png horse.pnm horse.tga horse.tif horse.xpm) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
data-images:
if not exist image mkdir image
for %f in (horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp) do if not exist image\%f copy .\image\%f image
fr:
if not exist $(OBJS)\intl\fr mkdir $(OBJS)\intl\fr
for %f in (internat.po internat.mo) do if not exist $(OBJS)\intl\fr\%f copy .\intl\fr\%f $(OBJS)\intl\fr
+5 -1
View File
@@ -454,7 +454,7 @@ $(OBJS) :
### Targets: ###
all : .SYMBOLIC $(OBJS)\test.exe $(__test_gui___depname) data fr
all : .SYMBOLIC $(OBJS)\test.exe $(__test_gui___depname) data data-images fr
clean : .SYMBOLIC
-if exist $(OBJS)\*.obj del $(OBJS)\*.obj
@@ -495,6 +495,10 @@ data : .SYMBOLIC
if not exist $(OBJS) mkdir $(OBJS)
for %f in (horse.ani horse.bmp horse.cur horse.gif horse.ico horse.jpg horse.pcx horse.png horse.pnm horse.tga horse.tif horse.xpm) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
data-images : .SYMBOLIC
if not exist image mkdir image
for %f in (horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp) do if not exist image\%f copy .\image\%f image
fr : .SYMBOLIC
if not exist $(OBJS)\intl\fr mkdir $(OBJS)\intl\fr
for %f in (internat.po internat.mo) do if not exist $(OBJS)\intl\fr\%f copy .\intl\fr\%f $(OBJS)\intl\fr
+8
View File
@@ -230,6 +230,14 @@
horse.pcx horse.png horse.pnm horse.tga horse.tif horse.xpm</files>
</wx-data>
<wx-data id="data-images">
<srcdir>$(SRCDIR)/image</srcdir>
<dstdir>image</dstdir>
<files>horse_grey.bmp horse_grey_flipped.bmp
horse_rle4.bmp horse_rle4_flipped.bmp
horse_rle8.bmp horse_rle8_flipped.bmp</files>
</wx-data>
<template id="catalog">
<dstdir>$(BUILDDIR)/intl/$(id)</dstdir>
<srcdir>$(SRCDIR)/intl/$(id)</srcdir>