git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9939
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
IMPLEMENT_DYNAMIC_CLASS(wxTIFFHandler,wxImageHandler)
IMPLEMENT_DYNAMIC_CLASS(wxTIFFHandler,wxImageHandler)
+static tsize_t LINKAGEMODE
_tiffNullProc(thandle_t WXUNUSED(handle),
tdata_t WXUNUSED(buf),
tsize_t WXUNUSED(size))
_tiffNullProc(thandle_t WXUNUSED(handle),
tdata_t WXUNUSED(buf),
tsize_t WXUNUSED(size))
+static tsize_t LINKAGEMODE
_tiffReadProc(thandle_t handle, tdata_t buf, tsize_t size)
{
wxInputStream *stream = (wxInputStream*) handle;
_tiffReadProc(thandle_t handle, tdata_t buf, tsize_t size)
{
wxInputStream *stream = (wxInputStream*) handle;
return stream->LastRead();
}
return stream->LastRead();
}
+static tsize_t LINKAGEMODE
_tiffWriteProc(thandle_t handle, tdata_t buf, tsize_t size)
{
wxOutputStream *stream = (wxOutputStream*) handle;
_tiffWriteProc(thandle_t handle, tdata_t buf, tsize_t size)
{
wxOutputStream *stream = (wxOutputStream*) handle;
return stream->LastWrite();
}
return stream->LastWrite();
}
+static toff_t LINKAGEMODE
_tiffSeekIProc(thandle_t handle, toff_t off, int whence)
{
wxInputStream *stream = (wxInputStream*) handle;
_tiffSeekIProc(thandle_t handle, toff_t off, int whence)
{
wxInputStream *stream = (wxInputStream*) handle;
return (toff_t)stream->SeekI( (off_t)off, mode );
}
return (toff_t)stream->SeekI( (off_t)off, mode );
}
+static toff_t LINKAGEMODE
_tiffSeekOProc(thandle_t handle, toff_t off, int whence)
{
wxOutputStream *stream = (wxOutputStream*) handle;
_tiffSeekOProc(thandle_t handle, toff_t off, int whence)
{
wxOutputStream *stream = (wxOutputStream*) handle;
return (toff_t)stream->SeekO( (off_t)off, mode );
}
return (toff_t)stream->SeekO( (off_t)off, mode );
}
_tiffCloseProc(thandle_t WXUNUSED(handle))
{
return 0; // ?
}
_tiffCloseProc(thandle_t WXUNUSED(handle))
{
return 0; // ?
}
+static toff_t LINKAGEMODE
_tiffSizeProc(thandle_t handle)
{
wxStreamBase *stream = (wxStreamBase*) handle;
return (toff_t) stream->GetSize();
}
_tiffSizeProc(thandle_t handle)
{
wxStreamBase *stream = (wxStreamBase*) handle;
return (toff_t) stream->GetSize();
}
_tiffMapProc(thandle_t WXUNUSED(handle),
tdata_t* WXUNUSED(pbase),
toff_t* WXUNUSED(psize))
_tiffMapProc(thandle_t WXUNUSED(handle),
tdata_t* WXUNUSED(pbase),
toff_t* WXUNUSED(psize))
_tiffUnmapProc(thandle_t WXUNUSED(handle),
tdata_t WXUNUSED(base),
toff_t WXUNUSED(size))
_tiffUnmapProc(thandle_t WXUNUSED(handle),
tdata_t WXUNUSED(base),
toff_t WXUNUSED(size))
{
if (verbose)
wxLogError( _("TIFF: Couldn't allocate memory.") );
{
if (verbose)
wxLogError( _("TIFF: Couldn't allocate memory.") );
TIFFClose( tif );
return FALSE;
TIFFClose( tif );
return FALSE;
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
tsize_t linebytes = (tsize_t)image->GetWidth() * 3;
unsigned char *buf;
tsize_t linebytes = (tsize_t)image->GetWidth() * 3;
unsigned char *buf;
-
- if (TIFFScanlineSize(tif) > linebytes)
+
+ if (TIFFScanlineSize(tif) > linebytes)
{
buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(tif));
if (!buf)
{
buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(tif));
if (!buf)
{
buf = NULL;
}
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP,
TIFFDefaultStripSize(tif, (uint32) -1));
{
buf = NULL;
}
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP,
TIFFDefaultStripSize(tif, (uint32) -1));
unsigned char *ptr = image->GetData();
unsigned char *ptr = image->GetData();
- for (int row = 0; row < image->GetHeight(); row++)
+ for (int row = 0; row < image->GetHeight(); row++)
{
if (buf)
memcpy(buf, ptr, image->GetWidth());
{
if (buf)
memcpy(buf, ptr, image->GetWidth());
if (TIFFWriteScanline(tif, buf ? buf : ptr, (uint32)row, 0) < 0)
{
if (verbose)
wxLogError( _("TIFF: Error writing image.") );
if (TIFFWriteScanline(tif, buf ? buf : ptr, (uint32)row, 0) < 0)
{
if (verbose)
wxLogError( _("TIFF: Error writing image.") );
TIFFClose( tif );
if (buf)
_TIFFfree(buf);
TIFFClose( tif );
if (buf)
_TIFFfree(buf);
return FALSE;
}
ptr += image->GetWidth()*3;
return FALSE;
}
ptr += image->GetWidth()*3;
{
size_t length = stream.GetSize();
wxCHECK_MSG(length != 0, wxNullImage, wxT("Cannot read XPM from stream of unknown size"));
{
size_t length = stream.GetSize();
wxCHECK_MSG(length != 0, wxNullImage, wxT("Cannot read XPM from stream of unknown size"));
char *xpm_buffer = new char[length];
char *p, *q;
size_t i;
if ( stream.Read(xpm_buffer, length).LastError() != wxSTREAM_NO_ERROR )
return FALSE;
char *xpm_buffer = new char[length];
char *p, *q;
size_t i;
if ( stream.Read(xpm_buffer, length).LastError() != wxSTREAM_NO_ERROR )
return FALSE;
/*
* Remove comments from the file:
*/
/*
* Remove comments from the file:
*/
i = 0;
for (p = xpm_buffer; *p != '\0'; p++)
{
i = 0;
for (p = xpm_buffer; *p != '\0'; p++)
{
continue;
for (q = p + 1; *q != '\0'; q++)
if (*q == '"')
continue;
for (q = p + 1; *q != '\0'; q++)
if (*q == '"')
p = q + 1;
}
xpm_buffer[i] = '\0';
p = q + 1;
}
xpm_buffer[i] = '\0';
/*
* Create array of lines and convert \n's to \0's:
*/
const char **xpm_lines;
size_t lines_cnt = 0;
size_t line;
/*
* Create array of lines and convert \n's to \0's:
*/
const char **xpm_lines;
size_t lines_cnt = 0;
size_t line;
for (p = xpm_buffer; *p != '\0'; p++)
{
for (p = xpm_buffer; *p != '\0'; p++)
{
xpm_lines = new const char*[lines_cnt];
xpm_lines[0] = xpm_buffer;
line = 1;
for (p = xpm_buffer; (*p != '\0') && (line < lines_cnt); p++)
{
xpm_lines = new const char*[lines_cnt];
xpm_lines[0] = xpm_buffer;
line = 1;
for (p = xpm_buffer; (*p != '\0') && (line < lines_cnt); p++)
{
{
xpm_lines[line] = p + 1;
*p = '\0';
line++;
}
}
{
xpm_lines[line] = p + 1;
*p = '\0';
line++;
}
}
/*
* Read the image:
*/
wxImage img = ReadData(xpm_lines);
/*
* Read the image:
*/
wxImage img = ReadData(xpm_lines);
delete[] xpm_buffer;
delete[] xpm_lines;
return img;
delete[] xpm_buffer;
delete[] xpm_lines;
return img;
\*****************************************************************************/
\*****************************************************************************/
{
char *name;
wxUint32 rgb;
{
char *name;
wxUint32 rgb;
buf[0] = inname[5]; buf[1] = inname[6];
*b = (unsigned char) wxHexToDec(buf);
*isNone = FALSE;
buf[0] = inname[5]; buf[1] = inname[6];
*b = (unsigned char) wxHexToDec(buf);
*isNone = FALSE;
// lot of gray...
// so first extract ' '
// lot of gray...
// so first extract ' '
- while ((p = strchr(name, ' ')))
+ while ((p = strchr(name, ' ')) != NULL)
{
while (*(p)) // till eof of string
{
{
while (*(p)) // till eof of string
{
}
// fold to lower case
p = name;
}
// fold to lower case
p = name;
// substitute Grey with Gray, else rgbtab.h would have more than 100
// 'duplicate' entries
// substitute Grey with Gray, else rgbtab.h would have more than 100
// 'duplicate' entries
- if ( (grey = strstr(name, "grey")) )
+ if ( (grey = strstr(name, "grey")) != NULL )
grey[2] = 'a';
// check for special 'none' colour:
grey[2] = 'a';
// check for special 'none' colour:
// binary search:
left = 0;
right = numTheRGBRecords - 1;
// binary search:
left = 0;
right = numTheRGBRecords - 1;
{
middle = (left + right) / 2;
cmp = strcmp(name, theRGBRecords[middle].name);
{
middle = (left + right) / 2;
cmp = strcmp(name, theRGBRecords[middle].name);
*isNone = FALSE;
free(name);
return TRUE;
*isNone = FALSE;
free(name);
return TRUE;
- }
- else if ( cmp < 0 )
+ }
+ else if ( cmp < 0 )
{ // > 0
left = middle + 1;
}
{ // > 0
left = middle + 1;
}
static const char *ParseColor(const char *data)
{
static const char *ParseColor(const char *data)
{
- static const char *targets[] =
+ static const char *targets[] =
{"c ", "g ", "g4 ", "m ", "b ", "s ", NULL};
const char *p, *r;
{"c ", "g ", "g4 ", "m ", "b ", "s ", NULL};
const char *p, *r;
bool hasMask;
wxXPMColourMapData *clr_data;
wxHashTable clr_tbl(wxKEY_STRING);
bool hasMask;
wxXPMColourMapData *clr_data;
wxHashTable clr_tbl(wxKEY_STRING);
/*
* Read hints and initialize structures:
*/
/*
* Read hints and initialize structures:
*/
- count = sscanf(xpm_data[0], "%u %u %u %u",
+ count = sscanf(xpm_data[0], "%u %u %u %u",
&width, &height, &colors_cnt, &chars_per_pixel);
if ( count != 4 || width * height * colors_cnt == 0 )
{
&width, &height, &colors_cnt, &chars_per_pixel);
if ( count != 4 || width * height * colors_cnt == 0 )
{
// 92 possible values on each position, 92^64 is *way* larger space than
// 8bit RGB...
wxCHECK_MSG(chars_per_pixel < 64, wxNullImage, wxT("XPM colormaps this large not supported."));
// 92 possible values on each position, 92^64 is *way* larger space than
// 8bit RGB...
wxCHECK_MSG(chars_per_pixel < 64, wxNullImage, wxT("XPM colormaps this large not supported."));
img.Create(width, height);
if ( !img.Ok() ) return img;
img.Create(width, height);
if ( !img.Ok() ) return img;
key[chars_per_pixel] = '\0';
hasMask = FALSE;
clr_tbl.DeleteContents(TRUE);
key[chars_per_pixel] = '\0';
hasMask = FALSE;
clr_tbl.DeleteContents(TRUE);
/*
* Create colour map:
*/
/*
* Create colour map:
*/
- if ( !GetRGBFromName(clr_def, &isNone,
+ if ( !GetRGBFromName(clr_def, &isNone,
&clr_data->R, &clr_data->G, &clr_data->B) )
{
wxLogError(_("XPM: malformed colour definition '%s'!"), xpm_data[1+i]);
&clr_data->R, &clr_data->G, &clr_data->B) )
{
wxLogError(_("XPM: malformed colour definition '%s'!"), xpm_data[1+i]);
- if ( hasMask && clr_data->R == 255 &&
+ if ( hasMask && clr_data->R == 255 &&
clr_data->G == 0 && clr_data->B == 255 )
clr_data->B = 254;
}
clr_data->G == 0 && clr_data->B == 255 )
clr_data->B = 254;
}
/*
* Parse image data:
*/
/*
* Parse image data:
*/
unsigned char *img_data = img.GetData();
for (j = 0; j < height; j++)
{
for (i = 0; i < width; i++, img_data += 3)
{
unsigned char *img_data = img.GetData();
for (j = 0; j < height; j++)
{
for (i = 0; i < width; i++, img_data += 3)
{
xpm_data[1 + colors_cnt + j] + chars_per_pixel * i,
chars_per_pixel);
clr_data = (wxXPMColourMapData*) clr_tbl.Get(key);
xpm_data[1 + colors_cnt + j] + chars_per_pixel * i,
chars_per_pixel);
clr_data = (wxXPMColourMapData*) clr_tbl.Get(key);