src/blitter/8bpp_optimized.cpp
changeset 9542 bc9789270025
parent 9437 d822addc9d2a
child 9573 5f9fa05daadf
equal deleted inserted replaced
9541:a5e34830f00d 9542:bc9789270025
    12 static FBlitter_8bppOptimized iFBlitter_8bppOptimized;
    12 static FBlitter_8bppOptimized iFBlitter_8bppOptimized;
    13 
    13 
    14 void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
    14 void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
    15 {
    15 {
    16 	/* Find the offset of this zoom-level */
    16 	/* Find the offset of this zoom-level */
    17 	uint offset = ((const uint8 *)bp->sprite)[(int)(zoom - ZOOM_LVL_BEGIN) * 2] | ((const byte *)bp->sprite)[(int)(zoom - ZOOM_LVL_BEGIN) * 2 + 1] << 8;
    17 	const SpriteData *sprite_src = (const SpriteData *)bp->sprite;
       
    18 	uint offset = sprite_src->offset[zoom];
    18 
    19 
    19 	/* Find where to start reading in the source sprite */
    20 	/* Find where to start reading in the source sprite */
    20 	const uint8 *src = (const uint8 *)bp->sprite + offset;
    21 	const uint8 *src = sprite_src->data + offset;
    21 	uint8 *dst_line = (uint8 *)bp->dst + bp->top * bp->pitch + bp->left;
    22 	uint8 *dst_line = (uint8 *)bp->dst + bp->top * bp->pitch + bp->left;
    22 
    23 
    23 	/* Skip over the top lines in the source image */
    24 	/* Skip over the top lines in the source image */
    24 	for (int y = 0; y < bp->skip_top; y++) {
    25 	for (int y = 0; y < bp->skip_top; y++) {
    25 		for (;;) {
    26 		for (;;) {
    99 }
   100 }
   100 
   101 
   101 Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
   102 Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
   102 {
   103 {
   103 	/* Make memory for all zoom-levels */
   104 	/* Make memory for all zoom-levels */
   104 	uint memory = (int)(ZOOM_LVL_END - ZOOM_LVL_BEGIN) * sizeof(uint16);
   105 	uint memory = sizeof(SpriteData);
   105 
   106 
   106 	for (ZoomLevel i = ZOOM_LVL_BEGIN; i < ZOOM_LVL_END; i++) {
   107 	for (ZoomLevel i = ZOOM_LVL_BEGIN; i < ZOOM_LVL_END; i++) {
   107 		memory += UnScaleByZoom(sprite->height, i) * UnScaleByZoom(sprite->width, i);
   108 		memory += UnScaleByZoom(sprite->height, i) * UnScaleByZoom(sprite->width, i);
   108 	}
   109 	}
   109 
   110 
   110 	/* We have no idea how much memory we really need, so just guess something */
   111 	/* We have no idea how much memory we really need, so just guess something */
   111 	memory *= 5;
   112 	memory *= 5;
   112 	byte *temp_dst = MallocT<byte>(memory);
   113 	SpriteData *temp_dst = (SpriteData *)MallocT<byte>(memory);
   113 	byte *dst = &temp_dst[(ZOOM_LVL_END - ZOOM_LVL_BEGIN) * 2];
   114 	byte *dst = temp_dst->data;
   114 
   115 
   115 	/* Make the sprites per zoom-level */
   116 	/* Make the sprites per zoom-level */
   116 	for (ZoomLevel i = ZOOM_LVL_BEGIN; i < ZOOM_LVL_END; i++) {
   117 	for (ZoomLevel i = ZOOM_LVL_BEGIN; i < ZOOM_LVL_END; i++) {
   117 		/* Store the index table */
   118 		/* Store the index table */
   118 		uint index = dst - temp_dst;
   119 		uint offset = dst - temp_dst->data;
   119 		temp_dst[i * 2] = index & 0xFF;
   120 		temp_dst->offset[i] = offset;
   120 		temp_dst[i * 2 + 1] = (index >> 8) & 0xFF;
       
   121 
   121 
   122 		/* cache values, because compiler can't cache it */
   122 		/* cache values, because compiler can't cache it */
   123 		int scaled_height = UnScaleByZoom(sprite->height, i);
   123 		int scaled_height = UnScaleByZoom(sprite->height, i);
   124 		int scaled_width  = UnScaleByZoom(sprite->width,  i);
   124 		int scaled_width  = UnScaleByZoom(sprite->width,  i);
   125 		int scaled_1      =   ScaleByZoom(1,              i);
   125 		int scaled_1      =   ScaleByZoom(1,              i);
   177 			*dst = 0; dst++;
   177 			*dst = 0; dst++;
   178 			*dst = 0; dst++;
   178 			*dst = 0; dst++;
   179 		}
   179 		}
   180 	}
   180 	}
   181 
   181 
   182 	uint size = dst - temp_dst;
   182 	uint size = dst - (byte *)temp_dst;
   183 
   183 
   184 	/* Safety check, to make sure we guessed the size correctly */
   184 	/* Safety check, to make sure we guessed the size correctly */
   185 	assert(size < memory);
   185 	assert(size < memory);
   186 
   186 
   187 	/* Allocate the exact amount of memory we need */
   187 	/* Allocate the exact amount of memory we need */