-
- /* dump stack data to the buffer */
- while (pos >= 0)
- {
- (img->p)[x + (y * (img->w))] = (char)stack[pos--];
-
- if (++x >= (img->w))
- {
- x = 0;
-
- if (interl)
- {
- /* support for interlaced images */
- switch (pass)
- {
- case 1: y += 8; break;
- case 2: y += 8; break;
- case 3: y += 4; break;
- case 4: y += 2; break;
- }
- if (y >= (img->h))
- {
- switch (++pass)
- {
- case 2: y = 4; break;
- case 3: y = 2; break;
- case 4: y = 1; break;
- }
- }
- }
- else
- {
- /* non-interlaced */
- y++;
- }
- }
- }
-
- pos = 0;
- lastcode = readcode;
- }
- while (code != ab_fin);
-
- return 0;
-}
-
-/* readgif:
- * Reads a GIF image from the file with filename 'nombre' in the
- * IMAGEN structure pointed by 'img'. Can read GIFs with any bit
- * size (color depth), but the output image is always expanded
- * to 8 bits per pixel. Also, the image palette always contains
- * 256 colors, although some of them may be unused. Returns E_OK
- * (== 0) on success, or an error code if something fails. Error
- * codes are E_ARCHIVO, E_FORMATO, E_MEMORIA (see above).
- */
-int gifDecoder::readgif(IMAGEN *img)
-{
- int size, ncolors, bits, interl, i;
- unsigned char pal[768];
- unsigned char buf[16];
-
- /* read header and logical screen descriptor block (LSDB) */
- f -> Read(buf, 13);
-
- /* check GIF signature */
- if (memcmp(buf, "GIF", 3) != 0) return E_FORMATO;
-
- /* load global color map if available */
- if ((buf[10] & 0x80) == 0x80)
- {
- ncolors = 2 << (buf[10] & 0x07);
- f -> Read(pal, 3 * ncolors);
- }
-
- /* assume no transparent color */
- img->transparent = -1;
-
- /* skip most extensions */
- while (mygetc() == 0x21) /* separator */
- {
- wxLogDebug("ugh");
- if (mygetc() == 0xF9) /* graphic control ext. */
- {
- wxLogDebug("...");
- f->Read(buf, 6);
- wxLogDebug("buf[1] is %i (%i)", buf[1], buf[1] & 0x01);
- if (buf[1] & 0x01) {
- wxLogDebug("setting transparen %i", buf[4]);
- img->transparent = buf[4];
- }
- }
- else
- while ((i = mygetc()) != 0) /* byte count */
- f->SeekI(i, wxFromCurrent);
- }
-
- /* read image descriptor block (IDB) */
- f -> Read(buf, 9);
- img->w = buf[4] + 256 * buf[5];
-
- img->h = buf[6] + 256 * buf[7];
- size = img->w * img->h;
- interl = ((buf[8] & 0x40)? 1 : 0);
-
- /* load local color map if available */
- if ((buf[8] & 0x80) == 0x80)
- {
- ncolors = 2 << (buf[8] & 0x07);
- f -> Read(pal, 3 * ncolors);
- }
-
- /* get initial code size from first byte in raster data */
- bits = mygetc();
-
- /* allocate memory for image and palette */
- if ((img->p = (unsigned char*) malloc(size)) == NULL) return E_MEMORIA;
- if ((img->pal = (unsigned char*) malloc(768)) == NULL) return E_MEMORIA;
-
- /* shift palette to fit VGA 6-bit format */
- for (i = 0; i < 768; i++)
- (img->pal)[i] = (unsigned char)pal[i] /* >> 2 not needed under wxWin */;
-
- /* decode GIF */
- dgif(img, interl, bits);
-
- /* finish successfully :-) */
- return E_OK;
-}
-
-/*
-
-FOLLOWING CODE IS BY V.S. :
-
-*/
-
-//-----------------------------------------------------------------------------
-// wxGIFHandler
-//-----------------------------------------------------------------------------
-
-IMPLEMENT_DYNAMIC_CLASS(wxGIFHandler,wxImageHandler)
-
-bool wxGIFHandler::LoadFile( wxImage *image, wxInputStream& stream )
-{
- unsigned char *ptr, *src, *pal;
- IMAGEN igif;
- int i;
- gifDecoder *decod;
-
- image->Destroy();
-
- decod = new gifDecoder(&stream);
-
- if (decod -> readgif(&igif) != E_OK) {
- wxLogDebug(_T("Error reading GIF"));