4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file 8bpp_simple.cpp Implementation of the simple 8 bpp blitter. */
12 #include "../stdafx.h"
13 #include "../zoom_func.h"
14 #include "8bpp_simple.hpp"
16 #include "../safeguards.h"
18 /** Instantiation of the simple 8bpp blitter factory. */
19 static FBlitter_8bppSimple iFBlitter_8bppSimple
;
21 void Blitter_8bppSimple::Draw(Blitter::BlitterParams
*bp
, BlitterMode mode
, ZoomLevel zoom
)
23 const uint8
*src
, *src_line
;
24 uint8
*dst
, *dst_line
;
26 /* Find where to start reading in the source sprite */
27 src_line
= (const uint8
*)bp
->sprite
+ (bp
->skip_top
* bp
->sprite_width
+ bp
->skip_left
) * ScaleByZoom(1, zoom
);
28 dst_line
= (uint8
*)bp
->dst
+ bp
->top
* bp
->pitch
+ bp
->left
;
30 for (int y
= 0; y
< bp
->height
; y
++) {
32 dst_line
+= bp
->pitch
;
35 src_line
+= bp
->sprite_width
* ScaleByZoom(1, zoom
);
37 for (int x
= 0; x
< bp
->width
; x
++) {
43 colour
= bp
->remap
[*src
];
47 if (*src
!= 0) colour
= bp
->remap
[*dst
];
51 if (*src
!= 0) *dst
= 0;
58 if (colour
!= 0) *dst
= colour
;
60 src
+= ScaleByZoom(1, zoom
);
65 Sprite
*Blitter_8bppSimple::Encode(const SpriteLoader::Sprite
*sprite
, AllocatorProc
*allocator
)
68 dest_sprite
= (Sprite
*)allocator(sizeof(*dest_sprite
) + (size_t)sprite
->height
* (size_t)sprite
->width
);
70 dest_sprite
->height
= sprite
->height
;
71 dest_sprite
->width
= sprite
->width
;
72 dest_sprite
->x_offs
= sprite
->x_offs
;
73 dest_sprite
->y_offs
= sprite
->y_offs
;
75 /* Copy over only the 'remap' channel, as that is what we care about in 8bpp */
76 for (int i
= 0; i
< sprite
->height
* sprite
->width
; i
++) {
77 dest_sprite
->data
[i
] = sprite
->data
[i
].m
;