Sprite *Blitter_16bppSimple::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) { Pixel *dst; Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + (size_t)sprite->height * (size_t)sprite->width * sizeof(Pixel)); dest_sprite->height = sprite->height; dest_sprite->width = sprite->width; dest_sprite->x_offs = sprite->x_offs; dest_sprite->y_offs = sprite->y_offs; dst = (Pixel *)dest_sprite->data; SpriteLoader::CommonPixel *src = (SpriteLoader::CommonPixel *)sprite->data; for (int i = 0; i < sprite->height * sprite->width; i++) { if (src->m == 0) { dst[i].c = To16(src->r, src->g, src->b); dst[i].a = src->a / 16; dst[i].m = 0; dst[i].v = 0; } else { /* Get brightest value */ uint8 rgb_max = max(src->r, max(src->g, src->b)); #if 0 /* Pre-convert the mapping channel to a RGB value, use 32bpp AdjustBrightness() variant for better colors, because this function is not called each frame */ if (rgb_max == 0) rgb_max = Blitter_32bppBase::DEFAULT_BRIGHTNESS; dst[i].c = To16(Blitter_32bppBase::AdjustBrightness(LookupColourInPalette32(src->m), rgb_max)); dst[i].v = rgb_max / 16; #endif rgb_max /= 16; /* Black pixel (8bpp or old 32bpp image), so use default value */ if (rgb_max == 0) rgb_max = DEFAULT_BRIGHTNESS; /* Pre-convert the mapping channel to a RGB value, use 32bpp AdjustBrightness() variant for better colors, because this function is not called each frame */ dst[i].c = AdjustBrightness(LookupColourInPalette(src->m), rgb_max); dst[i].v = rgb_max; dst[i].a = src->a / 16; dst[i].m = src->m; } src++; } return dest_sprite; }
Coord DrawLab::fromMilli(MCoord x) const { return To16( IntRShift<MCoord>(x+MPoint::Half,MPoint::Precision-cfg.zoom_deg) ); }