- type = (unsigned char)m_f->GetC();
-
- /* end of data? */
- if (type == 0x3B)
- break;
-
- /* extension block? */
- if (type == 0x21)
- {
- if (((unsigned char)m_f->GetC()) == 0xF9)
- /* graphics control extension, parse it */
- {
- m_f->Read(buf, 6);
-
- /* read delay and convert from 1/100 of a second to ms */
- delay = 10 * (buf[2] + 256 * buf[3]);
-
- /* read transparent colour index, if used */
- if (buf[1] & 0x01)
- transparent = buf[4];
-
- /* read disposal method */
- disposal = (buf[1] & 0x1C) - 1;
- }
- else
- /* other extension, skip */
- {
- while ((i = (unsigned char)m_f->GetC()) != 0)
- {
- /* This line should not be neccessary!
- * Some images are not loaded correctly
- * without it. A bug in wxStream?
- */
- // m_f->SeekI(m_f->TellI(), wxFromStart);
- m_f->SeekI(i, wxFromCurrent);
- }
- }
- }
-
- /* image descriptor block? */
- if (type == 0x2C)
- {
- /* allocate memory for IMAGEN struct */
- pimg = (*ppimg) = (IMAGEN *) malloc(sizeof(IMAGEN));
-
- if (pimg == NULL)
- {
- Destroy();
- return E_MEMORIA;
- }
-
- /* fill in the data */
- m_f->Read(buf, 9);
- pimg->left = buf[4] + 256 * buf[5];
- pimg->top = buf[4] + 256 * buf[5];
- pimg->w = buf[4] + 256 * buf[5];
- pimg->h = buf[6] + 256 * buf[7];
- interl = ((buf[8] & 0x40)? 1 : 0);
- size = pimg->w * pimg->h;
-
- pimg->transparent = transparent;
- pimg->disposal = disposal;
- pimg->delay = delay;
- pimg->next = NULL;
- pimg->prev = pprev;
- pprev = pimg;
- ppimg = &pimg->next;
-
- /* allocate memory for image and palette */
- pimg->p = (unsigned char *) malloc(size);
- pimg->pal = (unsigned char *) malloc(768);
-
- if ((!pimg->p) || (!pimg->pal))
- {
- Destroy();
- return E_MEMORIA;
- }
-
- /* load local color map if available, else use global map */
- if ((buf[8] & 0x80) == 0x80)
- {
- ncolors = 2 << (buf[8] & 0x07);
- m_f->Read(pimg->pal, 3 * ncolors);
- }
- else
- memcpy(pimg->pal, pal, 768);
-
- /* get initial code size from first byte in raster data */
- bits = (unsigned char)m_f->GetC();
-
- /* decode image */
- dgif(pimg, interl, bits);
-
- m_nimages++;
- }
-
- /* if we have one image and no animated GIF support, exit */
- if (m_nimages == 1 && !m_anim)
- break;
+ type = (unsigned char)m_f->GetC();
+
+ /* end of data? */
+ if (type == 0x3B)
+ {
+ done = TRUE;
+ }
+ else
+ /* extension block? */
+ if (type == 0x21)
+ {
+ if (((unsigned char)m_f->GetC()) == 0xF9)
+ /* graphics control extension, parse it */
+ {
+ m_f->Read(buf, 6);
+
+ /* read delay and convert from 1/100 of a second to ms */
+ delay = 10 * (buf[2] + 256 * buf[3]);
+
+ /* read transparent colour index, if used */
+ if (buf[1] & 0x01)
+ transparent = buf[4];
+
+ /* read disposal method */
+ disposal = (buf[1] & 0x1C) - 1;
+ }
+ else
+ /* other extension, skip */
+ {
+ while ((i = (unsigned char)m_f->GetC()) != 0)
+ {
+ m_f->SeekI(i, wxFromCurrent);
+ }
+ }
+ }
+ else
+ /* image descriptor block? */
+ if (type == 0x2C)
+ {
+ /* allocate memory for IMAGEN struct */
+ pimg = (*ppimg) = new GIFImage();
+
+ if (pimg == NULL)
+ {
+ Destroy();
+ return wxGIF_MEMERR;
+ }
+
+ /* fill in the data */
+ m_f->Read(buf, 9);
+ pimg->left = buf[0] + 256 * buf[1];
+ pimg->top = buf[2] + 256 * buf[3];
+/*
+ pimg->left = buf[4] + 256 * buf[5];
+ pimg->top = buf[4] + 256 * buf[5];
+*/
+ pimg->w = buf[4] + 256 * buf[5];
+ pimg->h = buf[6] + 256 * buf[7];
+ interl = ((buf[8] & 0x40)? 1 : 0);
+ size = pimg->w * pimg->h;
+
+ pimg->transparent = transparent;
+ pimg->disposal = disposal;
+ pimg->delay = delay;
+ pimg->next = NULL;
+ pimg->prev = pprev;
+ pprev = pimg;
+ ppimg = &pimg->next;
+
+ /* allocate memory for image and palette */
+ pimg->p = (unsigned char *) malloc((size_t)size);
+ pimg->pal = (unsigned char *) malloc(768);
+
+ if ((!pimg->p) || (!pimg->pal))
+ {
+ Destroy();
+ return wxGIF_MEMERR;
+ }
+
+ /* load local color map if available, else use global map */
+ if ((buf[8] & 0x80) == 0x80)
+ {
+ ncolors = 2 << (buf[8] & 0x07);
+ m_f->Read(pimg->pal, 3 * ncolors);
+ }
+ else
+ memcpy(pimg->pal, pal, 768);
+
+ /* get initial code size from first byte in raster data */
+ bits = (unsigned char)m_f->GetC();
+
+ /* decode image */
+ dgif(pimg, interl, bits);
+ m_nimages++;
+
+ /* if this is not an animated GIF, exit after first image */
+ if (!m_anim)
+ done = TRUE;
+ }