-
- /* 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) */
- fread(buf, 1, 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);
- fread(pal, 1, 3 * ncolors);
- }
-
- /* skip extensions */
- while (fgetc() == 0x21) /* separator */
- {
- fgetc(); /* function code */
-
- while ((i = fgetc()) != 0) /* byte count */
- fseekcur(i);
- }
-
- /* read image descriptor block (IDB) */
- fread(buf, 1, 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);
- fread(pal, 1, 3 * ncolors);
- }
-
- /* get initial code size from first byte in raster data */
- bits = fgetc();
-
- /* 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;
- int file_size;
- unsigned char* file_con;
- IMAGEN igif;
- int i;
- gifDecoder *decod;
-
- image->Destroy();
-
- file_size = stream.StreamSize();
- file_con = (unsigned char*) malloc(file_size);
- stream.Read(file_con, file_size);
- decod = new gifDecoder(file_con, file_size);
-
- if (decod -> readgif(&igif) != E_OK) {
- wxLogDebug("Error reading GIF");
- free(file_con);