//=========================================================================== // // True Color texture copy function // This excludes all the cases that force downconversion to the // base palette because they wouldn't be used anyway. // //=========================================================================== void FGLBitmap::CopyPixelDataRGB(int originx, int originy, const uint8_t * patch, int srcwidth, int srcheight, int step_x, int step_y, int rotate, int ct, FCopyInfo *inf, int r, int g, int b) { if (ClipCopyPixelRect(&ClipRect, originx, originy, patch, srcwidth, srcheight, step_x, step_y, rotate)) { uint8_t *buffer = GetPixels() + 4*originx + Pitch*originy; for (int y=0;y<srcheight;y++) { copyfuncs[ct](&buffer[y*Pitch], &patch[y*step_y], srcwidth, step_x, (uint8_t)r, (uint8_t)g, (uint8_t)b); } } }
//=========================================================================== // // Paletted to True Color texture copy function // //=========================================================================== void FGLBitmap::CopyPixelData(int originx, int originy, const uint8_t * patch, int srcwidth, int srcheight, int step_x, int step_y, int rotate, PalEntry * palette, FCopyInfo *inf) { PalEntry penew[256]; int x,y,pos,i; if (ClipCopyPixelRect(&ClipRect, originx, originy, patch, srcwidth, srcheight, step_x, step_y, rotate)) { uint8_t *buffer = GetPixels() + 4*originx + Pitch*originy; if (translation > 0) { PalEntry *ptrans = GLTranslationPalette::GetPalette(translation); if (ptrans && !alphatrans) { for (i = 0; i < 256; i++) { penew[i] = (ptrans[i] & 0xffffff) | (palette[i] & 0xff000000); } } else if (ptrans) { memcpy(penew, ptrans, 256 * sizeof(PalEntry)); } } else { memcpy(penew, palette, 256*sizeof(PalEntry)); } // convert the image according to the translated palette. for (y=0;y<srcheight;y++) { pos=(y*Pitch); for (x=0;x<srcwidth;x++,pos+=4) { int v=(unsigned char)patch[y*step_y+x*step_x]; if (penew[v].a!=0) { buffer[pos] = penew[v].r; buffer[pos+1] = penew[v].g; buffer[pos+2] = penew[v].b; buffer[pos+3] = penew[v].a; } } } } }
void FMultiPatchTexture::CopyToBlock(uint8_t *dest, int dwidth, int dheight, FImageSource *source, int xpos, int ypos, int rotate, const uint8_t *translation, int style) { auto cimage = source->GetCachedPalettedPixels(style); // should use composition cache auto &image = cimage.Pixels; const uint8_t *pixels = image.Data(); int srcwidth = source->GetWidth(); int srcheight = source->GetHeight(); int step_x = source->GetHeight(); int step_y = 1; FClipRect cr = { 0, 0, dwidth, dheight }; if (style) translation = nullptr; // do not apply translations to alpha textures. if (ClipCopyPixelRect(&cr, xpos, ypos, pixels, srcwidth, srcheight, step_x, step_y, rotate)) { dest += ypos + dheight * xpos; if (translation == NULL) { for (int x = 0; x < srcwidth; x++) { int pos = x * dheight; for (int y = 0; y < srcheight; y++, pos++) { // the optimizer is doing a good enough job here so there's no need to optimize this by hand uint8_t v = pixels[y * step_y + x * step_x]; if (v != 0) dest[pos] = v; } } } else { for (int x = 0; x < srcwidth; x++) { int pos = x * dheight; for (int y = 0; y < srcheight; y++, pos++) { uint8_t v = pixels[y * step_y + x * step_x]; if (v != 0) dest[pos] = translation[v]; } } } } }
void FTexture::CopyToBlock (BYTE *dest, int dwidth, int dheight, int xpos, int ypos, int rotate, const BYTE *translation) { const BYTE *pixels = GetPixels(); int srcwidth = Width; int srcheight = Height; int step_x = Height; int step_y = 1; FClipRect cr = {0, 0, dwidth, dheight}; if (ClipCopyPixelRect(&cr, xpos, ypos, pixels, srcwidth, srcheight, step_x, step_y, rotate)) { dest += ypos + dheight * xpos; if (translation == NULL) { for (int x = 0; x < srcwidth; x++) { int pos = x * dheight; for (int y = 0; y < srcheight; y++, pos++) { // the optimizer is doing a good enough job here so there's no need to optimize this by hand BYTE v = pixels[y * step_y + x * step_x]; if (v != 0) dest[pos] = v; } } } else { for (int x = 0; x < srcwidth; x++) { int pos = x * dheight; for (int y = 0; y < srcheight; y++, pos++) { BYTE v = pixels[y * step_y + x * step_x]; if (v != 0) dest[pos] = translation[v]; } } } } }