- if (FS_Read(s->file, &frameHead, 16))
- {
- compsize = LittleLong(*(frameHead + 8)) - 16;
- outsize = LittleLong(*(frameHead + 12));
- if (compsize > s->framesize || outsize > s->framesize)
- s->error = JAMDECODEERROR_BAD_FRAME_HEADER;
- else if (FS_Read(s->file, s->compressed, compsize))
- {
- // palette goes interleaved with special flag
- if (frameHead[0] == 2)
- {
- if (compsize == 768)
- {
- memcpy(s->colormap, s->compressed, 768);
- for(i = 0; i < 768; i++)
- s->colormap[i] = (unsigned char)(bound(0, (s->colormap[i] * s->colorscale) - s->colorsub, 255));
- goto readframe;
- }
- //else
- // s->error = JAMDECODEERROR_BAD_COLORMAP;
- }
- else
- {
- // decode frame
- // shift buffers to provide current and previous one, decode
- b = s->prevframedata;
- s->prevframedata = s->framedata;
- s->framedata = b;
- jam_decodeframe(s->compressed, s->framedata, s->prevframedata, outsize, frameHead[4]);
- // make 32bit imagepixels from 8bit palettized frame
- if (s->doubleres)
- b = s->videopixels;
- else
- b = (unsigned char *)imagedata;
- for(i = 0; i < s->framesize; i++)
- {
- // bgra
- *b++ = s->colormap[s->framedata[i]*3 + 2];
- *b++ = s->colormap[s->framedata[i]*3 + 1];
- *b++ = s->colormap[s->framedata[i]*3];
- *b++ = 255;
- }
- // nearest 2x
- if (s->doubleres)
- {
- for (i = 0; i < s->info_imageheight; i++)
- {
- b = (unsigned char *)imagedata + (s->info_imagewidth*2*4)*(i*2);
- for (j = 0; j < s->info_imagewidth; j++)
- {
- *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4];
- *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 1];
- *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 2];
- *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 3];
- //
- *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4];
- *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 1];
- *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 2];
- *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 3];
- }
- b = (unsigned char *)imagedata + (s->info_imagewidth*2*4)*(i*2 + 1);
- for (j = 0; j < s->info_imagewidth; j++)
- {
- *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4];
- *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 1];
- *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 2];
- *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 3];
- //
- *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4];
- *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 1];
- *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 2];
- *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 3];
- }
- }
- // do stippling
- if (s->stipple)
- {
- for (i = 0; i < s->info_imageheight; i++)
- {
- b = (unsigned char *)imagedata + (s->info_imagewidth * 4 * 2 * 2 * i);
- for (j = 0; j < s->info_imagewidth; j++)
- {
- b[0] = b[0] * s->stipple;
- b[1] = b[1] * s->stipple;
- b[2] = b[2] * s->stipple;
- b += 4;
- b[0] = b[0] * s->stipple;
- b[1] = b[1] * s->stipple;
- b[2] = b[2] * s->stipple;
- b += 4;
- }
- }
- }
- }