10 #include "../stdafx.h"
11 #include "../zoom_func.h"
12 #include "../settings_type.h"
15 #include "../safeguards.h"
27 template <BlitterMode mode,
bool Tpal_to_rgb>
38 const uint16 *src_n = (
const uint16 *)(src->
data + src->
offset[zoom][1]);
41 for (uint i = bp->
skip_top; i != 0; i--) {
42 src_px = (
const Colour *)((
const byte *)src_px + *(
const uint32 *)src_px);
43 src_n = (
const uint16 *)((
const byte *)src_n + *(
const uint32 *)src_n);
50 const byte *remap = bp->
remap;
52 for (
int y = 0; y < bp->
height; y++) {
57 const Colour *src_px_ln = (
const Colour *)((
const byte *)src_px + *(
const uint32 *)src_px);
61 const uint16 *src_n_ln = (
const uint16 *)((
const byte *)src_n + *(
const uint32 *)src_n);
70 while (dst < dst_end) {
78 if (dst + n > dst_end) {
79 uint d = dst_end - dst;
84 dst_end = dst + bp->
width;
86 n = std::min(n - d, (uint)bp->
width);
100 while (dst < dst_end) {
101 n = std::min<uint>(*src_n++, dst_end - dst);
103 if (src_px->a == 0) {
114 if (src_px->a == 255) {
121 uint r = remap[
GB(m, 0, 8)];
134 uint r = remap[
GB(m, 0, 8)];
145 if (src_px->a == 255) {
149 uint8 g =
MakeDark(src_px->r, src_px->g, src_px->b);
152 uint r = remap[
GB(m, 0, 8)];
163 if (src_px->a != 0) {
164 uint8 g =
MakeDark(src_px->r, src_px->g, src_px->b);
168 uint r = remap[
GB(m, 0, 8)];
194 if (src_px->a == 255) {
210 if (src_px->a == 255) {
213 if (Tpal_to_rgb && *src_n != 0) {
225 if (Tpal_to_rgb && *src_n != 0) {
247 template <
bool Tpal_to_rgb>
251 default: NOT_REACHED();
252 case BM_NORMAL: Draw<BM_NORMAL, Tpal_to_rgb>(bp, zoom);
return;
253 case BM_COLOUR_REMAP: Draw<BM_COLOUR_REMAP, Tpal_to_rgb>(bp, zoom);
return;
254 case BM_TRANSPARENT: Draw<BM_TRANSPARENT, Tpal_to_rgb>(bp, zoom);
return;
255 case BM_CRASH_REMAP: Draw<BM_CRASH_REMAP, Tpal_to_rgb>(bp, zoom);
return;
256 case BM_BLACK_REMAP: Draw<BM_BLACK_REMAP, Tpal_to_rgb>(bp, zoom);
return;
272 this->Draw<false>(bp, mode, zoom);
275 template <
bool Tpal_to_rgb>
Sprite *Blitter_32bppOptimized::EncodeInternal(
const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
305 for (
ZoomLevel z = zoom_min; z <= zoom_max; z++) {
310 dst_px_orig[z] = CallocT<Colour>(size + src_orig->
height * 2);
311 dst_n_orig[z] = CallocT<uint16>(size * 2 + src_orig->
height * 4 * 2);
313 uint32 *dst_px_ln = (uint32 *)dst_px_orig[z];
314 uint32 *dst_n_ln = (uint32 *)dst_n_orig[z];
318 for (uint y = src_orig->
height; y > 0; y--) {
320 uint16 *dst_n = (uint16 *)(dst_n_ln + 1);
322 uint16 *dst_len = dst_n++;
327 for (uint x = src_orig->
width; x > 0; x--) {
329 uint t = a > 0 && a < 255 ? 1 : a;
331 if (last != t || len == 65535) {
347 uint8 rgb_max = std::max({ src->
r, src->
g, src->
b });
350 if (rgb_max == 0) rgb_max = DEFAULT_BRIGHTNESS;
351 *dst_n |= rgb_max << 8;
356 dst_px->r = colour.r;
357 dst_px->g = colour.g;
358 dst_px->b = colour.b;
371 }
else if (len == 1) {
385 dst_n = (uint16 *)
AlignPtr(dst_n, 4);
387 *dst_px_ln = (uint8 *)dst_px - (uint8 *)dst_px_ln;
388 *dst_n_ln = (uint8 *)dst_n - (uint8 *)dst_n_ln;
390 dst_px_ln = (uint32 *)dst_px;
391 dst_n_ln = (uint32 *)dst_n;
394 lengths[z][0] = (
byte *)dst_px_ln - (
byte *)dst_px_orig[z];
395 lengths[z][1] = (
byte *)dst_n_ln - (
byte *)dst_n_orig[z];
399 for (
ZoomLevel z = zoom_min; z <= zoom_max; z++) {
400 len += lengths[z][0] + lengths[z][1];
403 Sprite *dest_sprite = (
Sprite *)allocator(
sizeof(*dest_sprite) +
sizeof(SpriteData) + len);
410 SpriteData *dst = (SpriteData *)dest_sprite->
data;
411 memset(dst, 0,
sizeof(*dst));
413 for (
ZoomLevel z = zoom_min; z <= zoom_max; z++) {
414 dst->offset[z][0] = z == zoom_min ? 0 : lengths[z - 1][1] + dst->offset[z - 1][1];
415 dst->offset[z][1] = lengths[z][0] + dst->offset[z][0];
417 memcpy(dst->data + dst->offset[z][0], dst_px_orig[z], lengths[z][0]);
418 memcpy(dst->data + dst->offset[z][1], dst_n_orig[z], lengths[z][1]);
420 free(dst_px_orig[z]);
432 return this->EncodeInternal<true>(sprite, allocator);