IMPLEMENT_DYNAMIC_CLASS(wxTIFFHandler,wxImageHandler)
-static tsize_t
+static tsize_t LINKAGEMODE
_tiffNullProc(thandle_t WXUNUSED(handle),
tdata_t WXUNUSED(buf),
tsize_t WXUNUSED(size))
return (tsize_t) -1;
}
-static tsize_t
+static tsize_t LINKAGEMODE
_tiffReadProc(thandle_t handle, tdata_t buf, tsize_t size)
{
wxInputStream *stream = (wxInputStream*) handle;
return stream->LastRead();
}
-static tsize_t
+static tsize_t LINKAGEMODE
_tiffWriteProc(thandle_t handle, tdata_t buf, tsize_t size)
{
wxOutputStream *stream = (wxOutputStream*) handle;
return stream->LastWrite();
}
-static toff_t
+static toff_t LINKAGEMODE
_tiffSeekIProc(thandle_t handle, toff_t off, int whence)
{
wxInputStream *stream = (wxInputStream*) handle;
return (toff_t)stream->SeekI( (off_t)off, mode );
}
-static toff_t
+static toff_t LINKAGEMODE
_tiffSeekOProc(thandle_t handle, toff_t off, int whence)
{
wxOutputStream *stream = (wxOutputStream*) handle;
return (toff_t)stream->SeekO( (off_t)off, mode );
}
-static int
+static int LINKAGEMODE
_tiffCloseProc(thandle_t WXUNUSED(handle))
{
return 0; // ?
}
-static toff_t
+static toff_t LINKAGEMODE
_tiffSizeProc(thandle_t handle)
{
wxStreamBase *stream = (wxStreamBase*) handle;
return (toff_t) stream->GetSize();
}
-static int
+static int LINKAGEMODE
_tiffMapProc(thandle_t WXUNUSED(handle),
tdata_t* WXUNUSED(pbase),
toff_t* WXUNUSED(psize))
return 0;
}
-static void
+static void LINKAGEMODE
_tiffUnmapProc(thandle_t WXUNUSED(handle),
tdata_t WXUNUSED(base),
toff_t WXUNUSED(size))
{
if (verbose)
wxLogError( _("TIFF: Couldn't allocate memory.") );
-
+
TIFFClose( tif );
return FALSE;
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;
-
- if (TIFFScanlineSize(tif) > linebytes)
+
+ if (TIFFScanlineSize(tif) > linebytes)
{
buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(tif));
if (!buf)
return FALSE;
}
- }
- else
+ }
+ else
{
buf = NULL;
}
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP,
TIFFDefaultStripSize(tif, (uint32) -1));
-
+
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 (TIFFWriteScanline(tif, buf ? buf : ptr, (uint32)row, 0) < 0)
{
if (verbose)
wxLogError( _("TIFF: Error writing image.") );
-
+
TIFFClose( tif );
if (buf)
_TIFFfree(buf);
-
+
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"));
-
+
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:
*/
i = 0;
for (p = xpm_buffer; *p != '\0'; p++)
{
- if ( *p != '"' )
+ if ( *p != '"' )
continue;
for (q = p + 1; *q != '\0'; q++)
if (*q == '"')
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;
-
+
for (p = xpm_buffer; *p != '\0'; p++)
{
- if ( *p == '\n' )
+ if ( *p == '\n' )
lines_cnt++;
}
-
+
xpm_lines = new const char*[lines_cnt];
xpm_lines[0] = xpm_buffer;
line = 1;
for (p = xpm_buffer; (*p != '\0') && (line < lines_cnt); p++)
{
- if ( *p == '\n' )
+ if ( *p == '\n' )
{
xpm_lines[line] = p + 1;
*p = '\0';
line++;
}
}
-
+
/*
* Read the image:
*/
wxImage img = ReadData(xpm_lines);
-
+
delete[] xpm_buffer;
delete[] xpm_lines;
return img;
\*****************************************************************************/
-typedef struct
+typedef struct
{
char *name;
wxUint32 rgb;
buf[0] = inname[5]; buf[1] = inname[6];
*b = (unsigned char) wxHexToDec(buf);
*isNone = FALSE;
-
+
return TRUE;
}
// lot of gray...
// so first extract ' '
- while ((p = strchr(name, ' ')))
+ while ((p = strchr(name, ' ')) != NULL)
{
while (*(p)) // till eof of string
{
}
// fold to lower case
p = name;
- while (*p)
+ while (*p)
{
*p = tolower(*p);
p++;
// 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:
// binary search:
left = 0;
right = numTheRGBRecords - 1;
- do
+ do
{
middle = (left + right) / 2;
cmp = strcmp(name, theRGBRecords[middle].name);
*isNone = FALSE;
free(name);
return TRUE;
- }
- else if ( cmp < 0 )
+ }
+ else if ( cmp < 0 )
{
right = middle - 1;
- }
- else
+ }
+ else
{ // > 0
left = middle + 1;
}
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;
bool hasMask;
wxXPMColourMapData *clr_data;
wxHashTable clr_tbl(wxKEY_STRING);
-
+
/*
* 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 )
{
// 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;
key[chars_per_pixel] = '\0';
hasMask = FALSE;
clr_tbl.DeleteContents(TRUE);
-
+
/*
* Create colour map:
*/
else
{
bool isNone;
- 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]);
}
else
{
- if ( hasMask && clr_data->R == 255 &&
+ if ( hasMask && clr_data->R == 255 &&
clr_data->G == 0 && clr_data->B == 255 )
clr_data->B = 254;
}
/*
* Parse image data:
*/
-
+
unsigned char *img_data = img.GetData();
for (j = 0; j < height; j++)
{
for (i = 0; i < width; i++, img_data += 3)
{
- memcpy(key,
+ memcpy(key,
xpm_data[1 + colors_cnt + j] + chars_per_pixel * i,
chars_per_pixel);
clr_data = (wxXPMColourMapData*) clr_tbl.Get(key);