📄 wrsprite.c
字号:
pix = layers_fb_PACKYUV422( GETJSAMPLE( ptr1[0] ), /* Y from first pixel */ GETJSAMPLE( ptr1[1] ), /* U from first pixel */ GETJSAMPLE( ptr2[0] ), /* Y from second pixel */ GETJSAMPLE( ptr1[2] ) ); /* V from first pixel */ *--bufferptr = pix; } ASSERT((unsigned char*)bufferptr==(unsigned char *)dest->iobuffer); } else { start = ((unsigned int *)dest->iobuffer)+((rows_supplied+2)/2); bufferptr = start; y = rows_supplied; if (cinfo->output_scanline == rows_supplied) { /* rhs of image, duplication required */ register const JSAMPLE FAR * ptr1 = dest->pub.buffer[rows_supplied-y]+3*x; /* ptr to 2nd of pair of values to write */ unsigned int pix; /* pack YUV, ignoring every other thing's UV */ pix = layers_fb_PACKYUV422( GETJSAMPLE( ptr1[0] ), /* Y from first pixel */ GETJSAMPLE( ptr1[1] ), /* U from first pixel */ GETJSAMPLE( ptr1[0] ), /* Y from first pixel */ GETJSAMPLE( ptr1[2] ) ); /* V from first pixel */ *--bufferptr = pix; --y; } else { /* rhs of image, duplication required */ register const JSAMPLE FAR * ptr1 = dest->pub.buffer[rows_supplied-y]+3*x; /* ptr to 2nd of pair of values to write */ unsigned int pix; unsigned int Y1, Y2, U, V; /* for this to work, it needs getdst */ ASSERT(dest->getdst); ASSERT(dest->outfile); if (dest->outfile) { /* seek: start at botoom, left and work up in each row. */ dest->seekdst(offset, dest->outfile); dest->getdst((unsigned char *)dest->iobuffer, (unsigned char*)start-(unsigned char*)dest->iobuffer, dest->outfile); } /* pack YUV, ignoring every other thing's UV */ layers_fb_UNPACKYUV422(*(bufferptr-1), Y1, U, Y2, V); /* replace Y, U, V with real values */ Y1 = GETJSAMPLE(ptr1[0]); U = GETJSAMPLE(ptr1[1]); V = GETJSAMPLE(ptr1[2]); pix = layers_fb_PACKYUV422( Y1, /* Y from first pixel */ U, /* U from first pixel */ Y2, /* Y from first pixel */ V ); /* V from first pixel */ *--bufferptr = pix; --y; } /* now deal with middle rows */ for (; y>=2; y-=2) { register const JSAMPLE FAR * ptr1 = dest->pub.buffer[rows_supplied-y+1]+3*x; /* ptr to 1st of pair of values to write */ register const JSAMPLE FAR * ptr2 = dest->pub.buffer[rows_supplied-y]+3*x; /* ptr to 2nd of pair of values to write */ unsigned int pix; /* pack YUV, ignoring every other thing's UV */ pix = layers_fb_PACKYUV422( GETJSAMPLE( ptr1[0] ), /* Y from first pixel */ GETJSAMPLE( ptr1[1] ), /* U from first pixel */ GETJSAMPLE( ptr2[0] ), /* Y from second pixel */ GETJSAMPLE( ptr1[2] ) ); /* V from first pixel */ *--bufferptr = pix; } if (y==1) { /* final value which is a duplicate which will be updated later */ register const JSAMPLE FAR * ptr1 = dest->pub.buffer[rows_supplied-y]+3*x; /* ptr to 1st of pair of values to write */ unsigned int pix; /* pack YUV, ignoring every other thing's UV */ pix = layers_fb_PACKYUV422( GETJSAMPLE( ptr1[0] ), /* Y from first pixel */ GETJSAMPLE( ptr1[1] ), /* U from first pixel */ GETJSAMPLE( ptr1[0] ), /* Y from second pixel */ GETJSAMPLE( ptr1[2] ) ); /* V from first pixel */ *--bufferptr = pix; } /* seek: start at botoom, left and work up in each row. */ ASSERT((unsigned char*)bufferptr==(unsigned char *)dest->iobuffer); } if (dest->outfile) { dest->seekdst(offset, dest->outfile); dest->putdst((unsigned char *)dest->iobuffer, (unsigned char *)start-(unsigned char *)dest->iobuffer, dest->outfile); } else { ASSERT(0); (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); } offset += dest->stride; } }}#endif/* * Write some pixel data. * In this module rows_supplied will always be 1. * * put_pixel4bpp_rows handles the "normal" 4-bit case. */static voidput_pixel4bpp_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, JDIMENSION rows_supplied){ sprite_dest_ptr dest = (sprite_dest_ptr) dinfo; register char *bufferptr; register JSAMPROW ptr; register JDIMENSION col; ptr = dest->pub.buffer[0]; bufferptr = dest->iobuffer; /* fprintf(stderr, "put_pixel4bpp_rows: ptr %x buf %x samples %x bufwidth %x\n", (int) ptr, (int) bufferptr, dest->samples_per_row, dest->buffer_width); */ for (col = dest->samples_per_row; (col > 0) && (col < JPEG_MAX_DIMENSION); col-=2) { /* fprintf(stderr, "col %x bufferptr %x ptr %x\n", col, bufferptr, ptr); */ PUTSPRITESAMPLE4BPP(bufferptr, GETJSAMPLE(ptr[0]), GETJSAMPLE(ptr[1])); ptr+=2; } /* fprintf(stderr, "put_pixel4bpp_rows: out %x io %x len %x\n", (int) dest->pub.output_file, (int) dest->iobuffer, dest->buffer_width); */ if (dest->outfile) { dest->putdst((unsigned char *)dest->iobuffer, dest->buffer_width, dest->outfile); } else { (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); } NOT_USED(cinfo); NOT_USED(rows_supplied);}/* * Startup: write the file header. */static voidstart_output_sprite (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo){ sprite_dest_ptr dest = (sprite_dest_ptr) dinfo; int spritehdr[sizeof(sprite_header)/sizeof(int)+3+512]; int width, mode, size, end_bits, height; int palette = 0; int greyscale = 0; sprite_header *sph = (sprite_header *)(spritehdr+3); ASSERT(sizeof(sprite_header) == 11*sizeof(int)); /* Set unused fields of header to 0 */ memset((void *) spritehdr, 0, sizeof(spritehdr)); /* Copy in application description */ switch (dest->rotate) { case webimage_rotate_LEFT_90: case webimage_rotate_LEFT_270: width = (int) cinfo->output_height; height = (int) cinfo->output_width; break; default: ASSERT(0); case webimage_rotate_LEFT_180: case webimage_rotate_NONE: width = (int) cinfo->output_width; height = (int) cinfo->output_height; break; } end_bits = 0x1f; /* If quantising image, then output an old fixed palette 8bpp */ if (cinfo->quantize_colors) { if (cinfo->out_color_space == JCS_GRAYSCALE) { greyscale = 1; if (cinfo->actual_number_of_colors == 16) { /* 4bpp, 16 colour fixed greyscale palette */ mode = 20; if ((width % 8) != 0) { end_bits = ((width % 8) * 4) - 1; width += (8 - (width % 8)); } width = width / 2; palette = 128; } else { /* 8bpp, 256 colour greyscale palette */ mode = 21; if ((width % 4) != 0) { end_bits = ((width % 4) * 8) - 1; width += (4 - (width % 4)); } palette = 2048; } } else { /* 8bpp, 256 colour fixed palette */ mode = 21; if ((width % 4) != 0) { end_bits = ((width % 4) * 8) - 1; width += (4 - (width % 4)); }#if RISCOS palette = 0;#else palette = 2048;#endif } } else if (!dest->yuv_out) {#if LAYERS_FB_32BITS if ( !dest->use_16bpp ) { /* 32bpp, 90x90dpi */ mode = (6<<27) + (90<<14) + (90<<1) + 1; width *= 4; } else#endif { /* 16bpp, 90x90dpi */ mode = (5<<27) + (90<<14) + (90<<1) + 1; if ((width % 2) != 0) { end_bits = ((width % 2) * 16) - 1; width += (2 - (width % 2)); } width *= 2; } } else { mode = 422; if ((width % 2) != 0) { end_bits = ((width % 2) * 16) - 1; width += (2 - (width % 2)); } width *= 2; } size = 60 + palette + (width * height); /* 3 + sizeof(sprite_header) (shoud be 14) word sprite header block */ spritehdr[0] = ENDIAN_MODIFY(1); /* # Sprite in area */ spritehdr[1] = 0x10; /* Byte offset to 1st sprite */ spritehdr[2] = size; /* Byte offset to end of block */ /* No extension words */ size -= 0x10; sph->next = ENDIAN_MODIFY(size); /* Byte offset to next sprite */ /* pdh 16-Aug-99: *must* 0-pad name */ memset( &sph->name, 0, sizeof(sph->name) ); layers_packedchar_pack_n(sph->name, "i", 12); /* 12 chars of sprite name (this won't work for lounge) */ sph->width = ENDIAN_MODIFY((width / 4) - 1); /* Width in words - 1 */ dest->stride = width; sph->height = ENDIAN_MODIFY(height - 1); /* Height in scan lines - 1 */ sph->lbit = 0; /* First bit used */ sph->rbit = ENDIAN_MODIFY(end_bits); /* Last bit used */ sph->image = ENDIAN_MODIFY(0x2C+palette); /* Offset to sprite image */ sph->mask = sph->image; /* Offset to transparency mask */ sph->mode = ENDIAN_MODIFY(mode); /* Mode sprite was defined in */ /* If grayscale, then write header + palette */ if (palette) { int *palhdr = spritehdr+14; int maxloop = palette/8; int loop; if (greyscale) { if (palette == 128) { for (loop = 0; loop < maxloop; loop++) { palhdr[loop*2] = ENDIAN_MODIFY((loop << 28) + (loop << 24)+ (loop << 20)+ (loop << 16) + (loop << 12) + (loop << 8)); palhdr[(loop*2) + 1] = palhdr[loop*2]; } } else { for (loop = 0; loop < maxloop; loop++) { palhdr[loop*2] = ENDIAN_MODIFY((loop << 8) + (loop << 16) + (loop << 24)); palhdr[(loop*2) + 1] = palhdr[loop*2]; } } }#if !RISCOS else { /* 256 colour palettised colour version */ unsigned int *pal = win32_palette(); for (loop = 0; loop < maxloop; loop++) { palhdr[(loop*2) + 1] = palhdr[loop*2] = ENDIAN_MODIFY(*pal++); } }#endif if (dest->outfile) { dest->putdst((unsigned char *) sph, 44+palette, dest->outfile); dest->image_offset = 44+palette; } else { (void) JFWRITE(dest->pub.output_file, spritehdr, 56+palette); dest->image_offset = 56+palette; } } else { /* Write header */ if (dest->outfile) { dest->putdst((unsigned char *) &spritehdr[3], 56-12, dest->outfile); dest->image_offset = 56-12; } else { (void) JFWRITE(dest->pub.output_file, spritehdr, 56); dest->image_offset = 56; } }}/* Build color map for an 8bpp Sprite file. * See PRM 3-385 "ColourTrans" for details of 8bpp 'colour numbers' * when PALETTE_VIDC is set */static voidread_sprite_map (j_decompress_ptr cinfo)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -