git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13594
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
#if wxUSE_PALETTE
if (pal && colors > 0)
{
#if wxUSE_PALETTE
if (pal && colors > 0)
{
- unsigned char r[colors];
- unsigned char g[colors];
- unsigned char b[colors];
+ unsigned char* r = new unsigned char[colors];
+ unsigned char* g = new unsigned char[colors];
+ unsigned char* b = new unsigned char[colors];
for (i = 0; i < colors; i++)
{
for (i = 0; i < colors; i++)
{
}
image->SetPalette(wxPalette(colors, r, g, b));
}
image->SetPalette(wxPalette(colors, r, g, b));
+
+ delete [] r;
+ delete [] g;
+ delete [] b;
}
#endif // wxUSE_PALETTE
}
#endif // wxUSE_PALETTE
/*************************************************************************
void decomprle(source, destination, source length, buffer size)
/*************************************************************************
void decomprle(source, destination, source length, buffer size)
Decompress run-length encoded data from source to destination. Terminates
when source is decoded completely or destination buffer is full.
Decompress run-length encoded data from source to destination. Terminates
when source is decoded completely or destination buffer is full.
The decruncher is as optimized as I could make it, without risking
safety in case of corrupt BODY chunks.
**************************************************************************/
The decruncher is as optimized as I could make it, without risking
safety in case of corrupt BODY chunks.
**************************************************************************/
static void decomprle(const byte *sptr, byte *dptr, long slen, long dlen)
{
byte codeByte, dataByte;
static void decomprle(const byte *sptr, byte *dptr, long slen, long dlen)
{
byte codeByte, dataByte;
while ((slen > 0) && (dlen > 0)) {
// read control byte
codeByte = *sptr++;
while ((slen > 0) && (dlen > 0)) {
// read control byte
codeByte = *sptr++;
if (codeByte < 0x80) {
codeByte++;
if ((slen > (long) codeByte) && (dlen >= (long) codeByte)) {
if (codeByte < 0x80) {
codeByte++;
if ((slen > (long) codeByte) && (dlen >= (long) codeByte)) {
dataptr = dataptr + 4; // skip ID
dataptr = dataptr + 4; // skip ID
- //
- // main decoding loop. searches IFF chunks and handles them.
- // terminates when BODY chunk was found or dataptr ran over end of file
+ //
+ // main decoding loop. searches IFF chunks and handles them.
+ // terminates when BODY chunk was found or dataptr ran over end of file
//
bool BMHDok = false, CMAPok = false, CAMGok = false;
int bmhd_width = 0, bmhd_height = 0, bmhd_bitplanes = 0, bmhd_transcol = -1;
//
bool BMHDok = false, CMAPok = false, CAMGok = false;
int bmhd_width = 0, bmhd_height = 0, bmhd_bitplanes = 0, bmhd_transcol = -1;
int colors = 0;
while (dataptr + 8 <= dataend) {
// get chunk length and make even
int colors = 0;
while (dataptr + 8 <= dataend) {
// get chunk length and make even
- size_t chunkLen = (iff_getlong(dataptr + 4) + 1) & 0xfffffffe;
+ size_t chunkLen = (iff_getlong(dataptr + 4) + 1) & 0xfffffffe;
if (chunkLen < 0) { // format error?
break;
}
if (chunkLen < 0) { // format error?
break;
}
}
const byte *cmapptr = dataptr + 8;
colors = chunkLen / 3; // calc no of colors
}
const byte *cmapptr = dataptr + 8;
colors = chunkLen / 3; // calc no of colors
delete m_image->pal;
m_image->pal = 0;
m_image->colors = colors;
delete m_image->pal;
m_image->pal = 0;
m_image->colors = colors;
Destroy();
return wxIFF_MEMERR;
}
Destroy();
return wxIFF_MEMERR;
}
// copy colors to color map
for (int i=0; i < colors; i++) {
m_image->pal[3*i + 0] = *cmapptr++;
// copy colors to color map
for (int i=0; i < colors; i++) {
m_image->pal[3*i + 0] = *cmapptr++;
wxLogTrace(_T("iff"), _T("Read %d colors from IFF file."),
colors);
wxLogTrace(_T("iff"), _T("Read %d colors from IFF file."),
colors);
CMAPok = true; // got CMAP
dataptr += 8 + chunkLen; // to next chunk
} else if (strncmp((char *)dataptr, "CAMG", 4) == 0) { // CAMG ?
CMAPok = true; // got CMAP
dataptr += 8 + chunkLen; // to next chunk
} else if (strncmp((char *)dataptr, "CAMG", 4) == 0) { // CAMG ?
if (truncated) {
chunkLen = dataend - dataptr;
}
if (truncated) {
chunkLen = dataend - dataptr;
}
//
// if BODY is compressed, allocate buffer for decrunched BODY
// and decompress it (run length encoding)
//
if (bmhd_compression == 1) {
//
// if BODY is compressed, allocate buffer for decrunched BODY
// and decompress it (run length encoding)
//
if (bmhd_compression == 1) {
- // calc size of decrunch buffer - (size of the actual pic.
+ // calc size of decrunch buffer - (size of the actual pic.
// decompressed in interleaved Amiga bitplane format)
// decompressed in interleaved Amiga bitplane format)
- size_t decomp_bufsize = (((bmhd_width + 15) >> 4) << 1)
+ size_t decomp_bufsize = (((bmhd_width + 15) >> 4) << 1)
* bmhd_height * bmhd_bitplanes;
* bmhd_height * bmhd_bitplanes;
if ((decomp_mem = new byte[decomp_bufsize]) == 0) {
Destroy();
return wxIFF_MEMERR;
}
if ((decomp_mem = new byte[decomp_bufsize]) == 0) {
Destroy();
return wxIFF_MEMERR;
}
decomprle(bodyptr, decomp_mem, chunkLen, decomp_bufsize);
bodyptr = decomp_mem; // -> uncompressed BODY
chunkLen = decomp_bufsize;
decomprle(bodyptr, decomp_mem, chunkLen, decomp_bufsize);
bodyptr = decomp_mem; // -> uncompressed BODY
chunkLen = decomp_bufsize;
// the following determines the type of the ILBM file.
// it's either NORMAL, EHB, HAM, HAM8 or 24BIT
// the following determines the type of the ILBM file.
// it's either NORMAL, EHB, HAM, HAM8 or 24BIT
int fmt = ILBM_NORMAL; // assume normal ILBM
if (bmhd_bitplanes == 24) {
fmt = ILBM_24BIT;
int fmt = ILBM_NORMAL; // assume normal ILBM
if (bmhd_bitplanes == 24) {
fmt = ILBM_24BIT;
_T("LoadIFF: %s %dx%d, planes=%d (%d cols), comp=%d"),
(fmt==ILBM_NORMAL) ? "Normal ILBM" :
(fmt==ILBM_HAM) ? "HAM ILBM" :
(fmt==ILBM_HAM8) ? "HAM8 ILBM" :
(fmt==ILBM_EHB) ? "EHB ILBM" :
(fmt==ILBM_24BIT) ? "24BIT ILBM" : "unknown ILBM",
_T("LoadIFF: %s %dx%d, planes=%d (%d cols), comp=%d"),
(fmt==ILBM_NORMAL) ? "Normal ILBM" :
(fmt==ILBM_HAM) ? "HAM ILBM" :
(fmt==ILBM_HAM8) ? "HAM8 ILBM" :
(fmt==ILBM_EHB) ? "EHB ILBM" :
(fmt==ILBM_24BIT) ? "24BIT ILBM" : "unknown ILBM",
- bmhd_width, bmhd_height, bmhd_bitplanes,
+ bmhd_width, bmhd_height, bmhd_bitplanes,
1<<bmhd_bitplanes, bmhd_compression);
if ((fmt==ILBM_NORMAL) || (fmt==ILBM_EHB) || (fmt==ILBM_HAM)) {
1<<bmhd_bitplanes, bmhd_compression);
if ((fmt==ILBM_NORMAL) || (fmt==ILBM_EHB) || (fmt==ILBM_HAM)) {
_T("Converting CMAP from normal ILBM CMAP"));
switch(fmt) {
_T("Converting CMAP from normal ILBM CMAP"));
switch(fmt) {
} else if ((fmt == ILBM_NORMAL) || (fmt == ILBM_EHB)) {
if (fmt == ILBM_EHB) {
wxLogTrace(_T("iff"), _T("Doubling CMAP for EHB mode"));
} else if ((fmt == ILBM_NORMAL) || (fmt == ILBM_EHB)) {
if (fmt == ILBM_EHB) {
wxLogTrace(_T("iff"), _T("Doubling CMAP for EHB mode"));
for (int i=0; i<32; i++) {
pal[3*(i + 32) + 0] = pal[3*i + 0] >> 1;
pal[3*(i + 32) + 1] = pal[3*i + 1] >> 1;
pal[3*(i + 32) + 2] = pal[3*i + 2] >> 1;
}
}
for (int i=0; i<32; i++) {
pal[3*(i + 32) + 0] = pal[3*i + 0] >> 1;
pal[3*(i + 32) + 1] = pal[3*i + 1] >> 1;
pal[3*(i + 32) + 2] = pal[3*i + 2] >> 1;
}
}
byte *pic = picptr; // ptr to buffer
const byte *workptr = bodyptr; // ptr to pic, planar format
if (bmhd_height < height) {
height = bmhd_height;
}
byte *pic = picptr; // ptr to buffer
const byte *workptr = bodyptr; // ptr to pic, planar format
if (bmhd_height < height) {
height = bmhd_height;
}
for (int i=0; i < height; i++) {
byte bitmsk = 0x80; // left most bit (mask)
const byte *workptr2 = workptr; // work ptr to source
for (int i=0; i < height; i++) {
byte bitmsk = 0x80; // left most bit (mask)
const byte *workptr2 = workptr; // work ptr to source
long col = 0;
long colbit = 1;
const byte *workptr3 = workptr2; // 1st byte in 1st pln
long col = 0;
long colbit = 1;
const byte *workptr3 = workptr2; // 1st byte in 1st pln
for (int k=0; k < bmhd_bitplanes; k++) {
if (*workptr3 & bitmsk) { // if bit set in this pln
col = col + colbit; // add bit to chunky byte
for (int k=0; k < bmhd_bitplanes; k++) {
if (*workptr3 & bitmsk) { // if bit set in this pln
col = col + colbit; // add bit to chunky byte
workptr3 += lineskip; // go to next line
colbit <<= 1; // shift color bit
}
workptr3 += lineskip; // go to next line
colbit <<= 1; // shift color bit
}
if (col >= 0 && col < colors) {
pic[0] = pal[3*col + 0];
pic[1] = pal[3*col + 1];
if (col >= 0 && col < colors) {
pic[0] = pal[3*col + 0];
pic[1] = pal[3*col + 1];
workptr2++; // mv ptr to next byte
}
}
workptr2++; // mv ptr to next byte
}
}
workptr += lineskip * bmhd_bitplanes; // to next line
}
} else {
workptr += lineskip * bmhd_bitplanes; // to next line
}
} else {
m_image->w = bmhd_width;
m_image->h = height;
m_image->transparent = bmhd_transcol;
m_image->w = bmhd_width;
m_image->h = height;
m_image->transparent = bmhd_transcol;
wxLogTrace(_T("iff"), _T("Loaded IFF picture %s"),
truncated? "truncated" : "completely");
wxLogTrace(_T("iff"), _T("Loaded IFF picture %s"),
truncated? "truncated" : "completely");