10 #include "../stdafx.h"
11 #include "../zoom_func.h"
12 #include "../settings_type.h"
13 #include "../palette_func.h"
16 #include "../safeguards.h"
28 template <BlitterMode mode,
bool Tpal_to_rgb>
39 const uint16_t *src_n = (
const uint16_t *)(src->
data + src->
offset[zoom][1]);
42 for (uint i = bp->
skip_top; i != 0; i--) {
43 src_px = (
const Colour *)((
const uint8_t *)src_px + *(
const uint32_t *)src_px);
44 src_n = (
const uint16_t *)((
const uint8_t *)src_n + *(
const uint32_t *)src_n);
51 const uint8_t *remap = bp->
remap;
53 for (
int y = 0; y < bp->
height; y++) {
58 const Colour *src_px_ln = (
const Colour *)((
const uint8_t *)src_px + *(
const uint32_t *)src_px);
62 const uint16_t *src_n_ln = (
const uint16_t *)((
const uint8_t *)src_n + *(
const uint32_t *)src_n);
71 while (dst < dst_end) {
79 if (dst + n > dst_end) {
80 uint d = dst_end - dst;
85 dst_end = dst + bp->
width;
87 n = std::min(n - d, (uint)bp->
width);
101 while (dst < dst_end) {
102 n = std::min<uint>(*src_n++, dst_end - dst);
104 if (src_px->a == 0) {
115 if (src_px->a == 255) {
122 uint r = remap[
GB(m, 0, 8)];
135 uint r = remap[
GB(m, 0, 8)];
146 if (src_px->a == 255) {
150 uint8_t g =
MakeDark(src_px->r, src_px->g, src_px->b);
153 uint r = remap[
GB(m, 0, 8)];
164 if (src_px->a != 0) {
165 uint8_t g =
MakeDark(src_px->r, src_px->g, src_px->b);
169 uint r = remap[
GB(m, 0, 8)];
191 if (src_px->a == 255) {
209 if (src_px->a != 0) {
222 if (src_px->a == 255) {
225 if (Tpal_to_rgb && *src_n != 0) {
237 if (Tpal_to_rgb && *src_n != 0) {
259 template <
bool Tpal_to_rgb>
263 default: NOT_REACHED();
264 case BM_NORMAL: Draw<BM_NORMAL, Tpal_to_rgb>(bp, zoom);
return;
265 case BM_COLOUR_REMAP: Draw<BM_COLOUR_REMAP, Tpal_to_rgb>(bp, zoom);
return;
266 case BM_TRANSPARENT: Draw<BM_TRANSPARENT, Tpal_to_rgb>(bp, zoom);
return;
268 case BM_CRASH_REMAP: Draw<BM_CRASH_REMAP, Tpal_to_rgb>(bp, zoom);
return;
269 case BM_BLACK_REMAP: Draw<BM_BLACK_REMAP, Tpal_to_rgb>(bp, zoom);
return;
285 this->Draw<false>(bp, mode, zoom);
318 for (
ZoomLevel z = zoom_min; z <= zoom_max; z++) {
323 dst_px_orig[z] = CallocT<Colour>(size + src_orig->
height * 2);
324 dst_n_orig[z] = CallocT<uint16_t>(size * 2 + src_orig->
height * 4 * 2);
326 uint32_t *dst_px_ln = (uint32_t *)dst_px_orig[z];
327 uint32_t *dst_n_ln = (uint32_t *)dst_n_orig[z];
331 for (uint y = src_orig->
height; y > 0; y--) {
334 uint16_t *dst_n = (uint16_t *)&dst_n_ln[1];
336 uint16_t *dst_len = dst_n++;
341 for (uint x = src_orig->
width; x > 0; x--) {
343 uint t = a > 0 && a < 255 ? 1 : a;
345 if (last != t || len == 65535) {
361 uint8_t rgb_max = std::max({ src->
r, src->
g, src->
b });
364 if (rgb_max == 0) rgb_max = DEFAULT_BRIGHTNESS;
365 *dst_n |= rgb_max << 8;
370 dst_px->r = colour.r;
371 dst_px->g = colour.g;
372 dst_px->b = colour.b;
385 }
else if (len == 1) {
399 dst_n = (uint16_t *)
AlignPtr(dst_n, 4);
401 *dst_px_ln = (uint8_t *)dst_px - (uint8_t *)dst_px_ln;
402 *dst_n_ln = (uint8_t *)dst_n - (uint8_t *)dst_n_ln;
404 dst_px_ln = (uint32_t *)dst_px;
405 dst_n_ln = (uint32_t *)dst_n;
408 lengths[z][0] = (uint8_t *)dst_px_ln - (uint8_t *)dst_px_orig[z];
409 lengths[z][1] = (uint8_t *)dst_n_ln - (uint8_t *)dst_n_orig[z];
413 for (
ZoomLevel z = zoom_min; z <= zoom_max; z++) {
414 len += lengths[z][0] + lengths[z][1];
417 Sprite *dest_sprite = allocator.
Allocate<
Sprite>(
sizeof(*dest_sprite) +
sizeof(SpriteData) + len);
424 SpriteData *dst = (SpriteData *)dest_sprite->data;
425 memset(dst, 0,
sizeof(*dst));
427 for (
ZoomLevel z = zoom_min; z <= zoom_max; z++) {
428 dst->offset[z][0] = z == zoom_min ? 0 : lengths[z - 1][1] + dst->offset[z - 1][1];
429 dst->offset[z][1] = lengths[z][0] + dst->offset[z][0];
431 memcpy(dst->data + dst->offset[z][0], dst_px_orig[z], lengths[z][0]);
432 memcpy(dst->data + dst->offset[z][1], dst_n_orig[z], lengths[z][1]);
434 free(dst_px_orig[z]);
446 return this->EncodeInternal<true>(sprite, allocator);