src/blitter/8bpp_optimized.cpp
changeset 8095 f834186120af
parent 7088 70852959cb77
child 8123 ce31d2843a95
equal deleted inserted replaced
8094:7b8304f4d617 8095:f834186120af
    15 	const uint8 *src, *src_next;
    15 	const uint8 *src, *src_next;
    16 	uint8 *dst, *dst_line;
    16 	uint8 *dst, *dst_line;
    17 	uint offset = 0;
    17 	uint offset = 0;
    18 
    18 
    19 	/* Find the offset of this zoom-level */
    19 	/* Find the offset of this zoom-level */
    20 	offset = ((const uint8 *)bp->sprite)[(int)zoom * 2] | ((const byte *)bp->sprite)[(int)zoom * 2 + 1] << 8;
    20 	offset = ((const uint8 *)bp->sprite)[(int)(zoom - ZOOM_LVL_BEGIN) * 2] | ((const byte *)bp->sprite)[(int)(zoom - ZOOM_LVL_BEGIN) * 2 + 1] << 8;
    21 
    21 
    22 	/* Find where to start reading in the source sprite */
    22 	/* Find where to start reading in the source sprite */
    23 	src = (const uint8 *)bp->sprite + offset;
    23 	src = (const uint8 *)bp->sprite + offset;
    24 	dst_line = (uint8 *)bp->dst + bp->top * bp->pitch + bp->left;
    24 	dst_line = (uint8 *)bp->dst + bp->top * bp->pitch + bp->left;
    25 
    25 
   108 	byte *temp_dst;
   108 	byte *temp_dst;
   109 	uint memory = 0;
   109 	uint memory = 0;
   110 	uint index = 0;
   110 	uint index = 0;
   111 
   111 
   112 	/* Make memory for all zoom-levels */
   112 	/* Make memory for all zoom-levels */
   113 	memory += (int)ZOOM_LVL_END * sizeof(uint16);
   113 	memory += (int)(ZOOM_LVL_END - ZOOM_LVL_BEGIN) * sizeof(uint16);
   114 	for (int i = 0; i < (int)ZOOM_LVL_END; i++) {
   114 	for (ZoomLevel i = ZOOM_LVL_BEGIN; i < ZOOM_LVL_END; i++) {
   115 		memory += UnScaleByZoom(sprite->height, (ZoomLevel)i) * UnScaleByZoom(sprite->width, (ZoomLevel)i);
   115 		memory += UnScaleByZoom(sprite->height, i) * UnScaleByZoom(sprite->width, i);
   116 		index += 2;
   116 		index += 2;
   117 	}
   117 	}
   118 
   118 
   119 	/* We have no idea how much memory we really need, so just guess something */
   119 	/* We have no idea how much memory we really need, so just guess something */
   120 	memory *= 5;
   120 	memory *= 5;
   121 	temp_dst = MallocT<byte>(memory);
   121 	temp_dst = MallocT<byte>(memory);
   122 
   122 
   123 	/* Make the sprites per zoom-level */
   123 	/* Make the sprites per zoom-level */
   124 	for (int i = 0; i < (int)ZOOM_LVL_END; i++) {
   124 	for (ZoomLevel i = ZOOM_LVL_BEGIN; i < ZOOM_LVL_END; i++) {
   125 		/* Store the scaled image */
   125 		/* Store the scaled image */
   126 		const SpriteLoader::CommonPixel *src;
   126 		const SpriteLoader::CommonPixel *src;
   127 
   127 
   128 		/* Store the index table */
   128 		/* Store the index table */
   129 		temp_dst[i * 2] = index & 0xFF;
   129 		temp_dst[i * 2] = index & 0xFF;
   130 		temp_dst[i * 2 + 1] = (index >> 8) & 0xFF;
   130 		temp_dst[i * 2 + 1] = (index >> 8) & 0xFF;
   131 
   131 
   132 		byte *dst = &temp_dst[index];
   132 		byte *dst = &temp_dst[index];
   133 
   133 
   134 		for (int y = 0; y < UnScaleByZoom(sprite->height, (ZoomLevel)i); y++) {
   134 		for (int y = 0; y < UnScaleByZoom(sprite->height, i); y++) {
   135 			uint trans = 0;
   135 			uint trans = 0;
   136 			uint pixels = 0;
   136 			uint pixels = 0;
   137 			uint last_color = 0;
   137 			uint last_color = 0;
   138 			uint count_index = 0;
   138 			uint count_index = 0;
   139 			uint rx = 0;
   139 			uint rx = 0;
   140 			src = &sprite->data[ScaleByZoom(y, (ZoomLevel)i) * sprite->width];
   140 			src = &sprite->data[ScaleByZoom(y, i) * sprite->width];
   141 
   141 
   142 			for (int x = 0; x < UnScaleByZoom(sprite->width, (ZoomLevel)i); x++) {
   142 			for (int x = 0; x < UnScaleByZoom(sprite->width, i); x++) {
   143 				uint color = 0;
   143 				uint color = 0;
   144 
   144 
   145 				/* Get the color keeping in mind the zoom-level */
   145 				/* Get the color keeping in mind the zoom-level */
   146 				for (int j = 0; j < ScaleByZoom(1, (ZoomLevel)i); j++) {
   146 				for (int j = 0; j < ScaleByZoom(1, i); j++) {
   147 					if (src->m != 0) color = src->m;
   147 					if (src->m != 0) color = src->m;
   148 					src++;
   148 					src++;
   149 					rx++;
   149 					rx++;
   150 					/* Because of the scaling it might happen we read outside the buffer. Avoid that. */
   150 					/* Because of the scaling it might happen we read outside the buffer. Avoid that. */
   151 					if (rx == sprite->width) break;
   151 					if (rx == sprite->width) break;