src/spritecache.cpp
changeset 10062 8ec5e3f048b7
parent 10056 48659f7d4fa5
child 10236 50afe9dd466e
equal deleted inserted replaced
10061:6a7bce2eca5c 10062:8ec5e3f048b7
     9 #include "spritecache.h"
     9 #include "spritecache.h"
    10 #include "fileio_func.h"
    10 #include "fileio_func.h"
    11 #include "spriteloader/grf.hpp"
    11 #include "spriteloader/grf.hpp"
    12 #include "core/alloc_func.hpp"
    12 #include "core/alloc_func.hpp"
    13 #include "core/math_func.hpp"
    13 #include "core/math_func.hpp"
       
    14 #include "gfx_func.h"
    14 #ifdef WITH_PNG
    15 #ifdef WITH_PNG
    15 #include "spriteloader/png.hpp"
    16 #include "spriteloader/png.hpp"
    16 #endif /* WITH_PNG */
    17 #endif /* WITH_PNG */
    17 #include "blitter/factory.hpp"
    18 #include "blitter/factory.hpp"
    18 
    19 
   186 			warning_level = 6;
   187 			warning_level = 6;
   187 			if (id == SPR_IMG_QUERY) usererror("Uhm, would you be so kind not to load a NewGRF that makes the 'query' sprite a recolour-sprite?");
   188 			if (id == SPR_IMG_QUERY) usererror("Uhm, would you be so kind not to load a NewGRF that makes the 'query' sprite a recolour-sprite?");
   188 			return (void*)GetRawSprite(SPR_IMG_QUERY, ST_NORMAL);
   189 			return (void*)GetRawSprite(SPR_IMG_QUERY, ST_NORMAL);
   189 		}
   190 		}
   190 
   191 
   191 		byte *dest = (byte *)AllocSprite(num);
   192 		/* "Normal" recolour sprites are ALWAYS 257 bytes. Then there is a small
       
   193 		 * number of recolour sprites that are 17 bytes that only exist in DOS
       
   194 		 * GRFs which are the same as 257 byte recolour sprites, but with the last
       
   195 		 * 240 bytes zeroed.  */
       
   196 		static const int RECOLOUR_SPRITE_SIZE = 257;
       
   197 		byte *dest = (byte *)AllocSprite(max(RECOLOUR_SPRITE_SIZE, num));
   192 
   198 
   193 		sc->ptr = dest;
   199 		sc->ptr = dest;
   194 		sc->type = sprite_type;
   200 		sc->type = sprite_type;
   195 		FioReadBlock(dest, num);
   201 
       
   202 		if (_palette_remap_grf[sc->file_slot]) {
       
   203 			byte *dest_tmp = AllocaM(byte, max(RECOLOUR_SPRITE_SIZE, num));
       
   204 
       
   205 			/* Only a few recolour sprites are less than 257 bytes */
       
   206 			if (num < RECOLOUR_SPRITE_SIZE) memset(dest_tmp, 0, RECOLOUR_SPRITE_SIZE);
       
   207 			FioReadBlock(dest_tmp, num);
       
   208 
       
   209 			/* The data of index 0 is never used; "literal 00" according to the (New)GRF specs. */
       
   210 			for (int i = 1; i < RECOLOUR_SPRITE_SIZE; i++) {
       
   211 				dest[i] = _palette_remap[dest_tmp[_palette_reverse_remap[i - 1] + 1]];
       
   212 			}
       
   213 		} else {
       
   214 			FioReadBlock(dest, num);
       
   215 		}
   196 
   216 
   197 		return sc->ptr;
   217 		return sc->ptr;
   198 	}
   218 	}
   199 	/* Ugly hack to work around the problem that the old landscape
   219 	/* Ugly hack to work around the problem that the old landscape
   200 	 *  generator assumes that those sprites are stored uncompressed in
   220 	 *  generator assumes that those sprites are stored uncompressed in