-
- if(alphapalette >= 0)
- t = swf_InsertTag(t, ST_DEFINEBITSLOSSLESS2);
- else
- t = swf_InsertTag(t, ST_DEFINEBITSLOSSLESS);
-
- swf_SetU16(t, id); // id
-
- // Ah! The Flash specs says scanlines must be DWORD ALIGNED!
- // (but image width is the correct number of pixels)
- swf_width = BYTES_PER_SCANLINE(header.width);
-
- if ((imagedata = (U8 *)malloc(swf_width*header.height)) == NULL) {
- fprintf(stderr, "Failed to allocate memory required, aborted.");
- exit(2);
- }
- to = imagedata;
- from = (U8 *)gft->SavedImages[0].RasterBits;
-
- if (swf_width == header.width) {
- // we are all nicely aligned and don't need to move the bitmap around.
- // Just copy the bits into the image buffer.*/
- if (!gft->Image.Interlace)
- memcpy(to, from, header.width*header.height);
- else // Need to perform 4 passes on the interlaced images
- for (i = 0; i < 4; i++)
- for (j = interlacedOffset[i]; j < header.height;
- j += interlacedJumps[i], from += header.width)
- memcpy(to + header.width*j, from, header.width);
- } else {
- padlen = swf_width - header.width;
-
- // here we need to pad the scanline
- if (!gft->Image.Interlace) {
- for (i=0; i < header.height; i++, from+=header.width, to+=swf_width) {
- memcpy(to, from, header.width);
- memset(to + header.width, bgcolor, padlen);
- }
- } else { // Need to perform 4 passes on the interlaced images
- for (i = 0; i < 4; i++)
- for (j = interlacedOffset[i]; j < header.height;
- j += interlacedJumps[i], from += header.width) {
- memcpy(to + swf_width*j, from, header.width);
- memset(to + swf_width*j, bgcolor, padlen);
- }
+
+ t = swf_InsertTag(t, bpp == 4 ? ST_DEFINEBITSLOSSLESS2 : ST_DEFINEBITSLOSSLESS);
+ swf_SetU16(t, id); // id
+
+ // Ah! The Flash specs says scanlines must be DWORD ALIGNED!
+ // (but image width is the correct number of pixels)
+ swf_width = BYTES_PER_SCANLINE(header.width);
+
+ if ((imagedata = (U8 *) malloc(swf_width * header.height)) == NULL) {
+ fprintf(stderr, "Failed to allocate memory required, aborted.");
+ exit(2);
+ }
+
+ to = imagedata;
+ from = (U8 *) gft->SavedImages[imgidx].RasterBits;
+
+ if (swf_width == header.width) {
+ // we are all nicely aligned and don't need to move the bitmap around.
+ // Just copy the bits into the image buffer.
+ if (!gft->Image.Interlace)
+ if (header.width == img->Width && header.height == img->Height)
+ memcpy(to, from, header.width * header.height);
+ else { //small screen
+ for (i = 0; i < header.height; i++, to += header.width) {
+ memset(to, bgcolor, header.width);
+ if (i >= img->Top && i < img->Top + img->Height) {
+ memcpy(to + img->Left, from, img->Width);
+ from += img->Width;
+ }
+ }
+ }
+
+ else // Need to perform 4 passes on the interlaced images
+ for (i = 0; i < 4; i++)
+ for (j = interlacedOffset[i]; j < header.height;
+ j += interlacedJumps[i], from += header.width)
+ memcpy(to + header.width * j, from, header.width);
+ } else {
+ padlen = swf_width - header.width;
+
+ // here we need to pad the scanline
+ if (!gft->Image.Interlace) {
+ if (header.width == img->Width && header.height == img->Height) {
+ for (i = 0; i < header.height; i++, from += header.width, to += swf_width) {
+ memcpy(to, from, header.width);
+ memset(to + header.width, bgcolor, padlen);
+ }
+ } else { //small screen
+ for (i = 0; i < header.height; i++, to += swf_width) {
+ memset(to, bgcolor, swf_width);
+ if (i >= img->Top && i < img->Top + img->Height) {
+ memcpy(to + img->Left, from, img->Width);
+ from += img->Width;
+ }
+ }
+ }
+ } else { // Need to perform 4 passes on the interlaced images
+ for (i = 0; i < 4; i++)
+ for (j = interlacedOffset[i]; j < header.height;
+ j += interlacedJumps[i], from += header.width) {
+ memcpy(to + swf_width * j, from, header.width);
+ memset(to + swf_width * j, bgcolor, padlen);
+ }
+ }