mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-01-22 01:11:49 +00:00
- moved some utility code out of FTexture.
This commit is contained in:
parent
03626107eb
commit
e35d88e039
15 changed files with 210 additions and 217 deletions
|
@ -39,6 +39,7 @@
|
||||||
#include "files.h"
|
#include "files.h"
|
||||||
#include "w_wad.h"
|
#include "w_wad.h"
|
||||||
#include "textures/textures.h"
|
#include "textures/textures.h"
|
||||||
|
#include "imagehelpers.h"
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
|
@ -96,7 +97,7 @@ TArray<uint8_t> FAutomapTexture::Get8BitPixels(bool alphatex)
|
||||||
|
|
||||||
TArray<uint8_t> Pixels(Width * Height, true);
|
TArray<uint8_t> Pixels(Width * Height, true);
|
||||||
|
|
||||||
const uint8_t *remap = GetRemap(alphatex);
|
const uint8_t *remap = ImageHelpers::GetRemap(alphatex);
|
||||||
for (x = 0; x < Width; ++x)
|
for (x = 0; x < Width; ++x)
|
||||||
{
|
{
|
||||||
for (y = 0; y < Height; ++y)
|
for (y = 0; y < Height; ++y)
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
#include "w_wad.h"
|
#include "w_wad.h"
|
||||||
#include "bitmap.h"
|
#include "bitmap.h"
|
||||||
#include "v_video.h"
|
#include "v_video.h"
|
||||||
|
#include "imagehelpers.h"
|
||||||
|
|
||||||
// Since we want this to compile under Linux too, we need to define this
|
// Since we want this to compile under Linux too, we need to define this
|
||||||
// stuff ourselves instead of including a DirectX header.
|
// stuff ourselves instead of including a DirectX header.
|
||||||
|
@ -470,7 +471,7 @@ void FDDSTexture::ReadRGB (FileReader &lump, uint8_t *buffer, int pixelmode)
|
||||||
uint32_t g = (c & GMask) << GShiftL; g |= g >> GShiftR;
|
uint32_t g = (c & GMask) << GShiftL; g |= g >> GShiftR;
|
||||||
uint32_t b = (c & BMask) << BShiftL; b |= b >> BShiftR;
|
uint32_t b = (c & BMask) << BShiftL; b |= b >> BShiftR;
|
||||||
uint32_t a = (c & AMask) << AShiftL; a |= a >> AShiftR;
|
uint32_t a = (c & AMask) << AShiftL; a |= a >> AShiftR;
|
||||||
*pixelp = RGBToPalette(pixelmode == PIX_Alphatex, r >> 24, g >> 24, b >> 24, a >> 24);
|
*pixelp = ImageHelpers::RGBToPalette(pixelmode == PIX_Alphatex, r >> 24, g >> 24, b >> 24, a >> 24);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -556,7 +557,7 @@ void FDDSTexture::DecompressDXT1 (FileReader &lump, uint8_t *buffer, int pixelmo
|
||||||
// Pick colors from the palette for each of the four colors.
|
// Pick colors from the palette for each of the four colors.
|
||||||
if (pixelmode != PIX_ARGB) for (i = 3; i >= 0; --i)
|
if (pixelmode != PIX_ARGB) for (i = 3; i >= 0; --i)
|
||||||
{
|
{
|
||||||
palcol[i] = RGBToPalette(pixelmode == PIX_Alphatex, color[i]);
|
palcol[i] = ImageHelpers::RGBToPalette(pixelmode == PIX_Alphatex, color[i]);
|
||||||
}
|
}
|
||||||
// Now decode this 4x4 block to the pixel buffer.
|
// Now decode this 4x4 block to the pixel buffer.
|
||||||
for (y = 0; y < 4; ++y)
|
for (y = 0; y < 4; ++y)
|
||||||
|
@ -636,7 +637,7 @@ void FDDSTexture::DecompressDXT3 (FileReader &lump, bool premultiplied, uint8_t
|
||||||
// Pick colors from the palette for each of the four colors.
|
// Pick colors from the palette for each of the four colors.
|
||||||
if (pixelmode != PIX_ARGB) for (i = 3; i >= 0; --i)
|
if (pixelmode != PIX_ARGB) for (i = 3; i >= 0; --i)
|
||||||
{
|
{
|
||||||
palcol[i] = RGBToPalette(pixelmode == PIX_Alphatex, color[i], false);
|
palcol[i] = ImageHelpers::RGBToPalette(pixelmode == PIX_Alphatex, color[i], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now decode this 4x4 block to the pixel buffer.
|
// Now decode this 4x4 block to the pixel buffer.
|
||||||
|
@ -748,7 +749,7 @@ void FDDSTexture::DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t
|
||||||
// Pick colors from the palette for each of the four colors.
|
// Pick colors from the palette for each of the four colors.
|
||||||
if (pixelmode != PIX_ARGB) for (i = 3; i >= 0; --i)
|
if (pixelmode != PIX_ARGB) for (i = 3; i >= 0; --i)
|
||||||
{
|
{
|
||||||
palcol[i] = RGBToPalette(pixelmode == PIX_Alphatex, color[i], false);
|
palcol[i] = ImageHelpers::RGBToPalette(pixelmode == PIX_Alphatex, color[i], false);
|
||||||
}
|
}
|
||||||
// Now decode this 4x4 block to the pixel buffer.
|
// Now decode this 4x4 block to the pixel buffer.
|
||||||
for (y = 0; y < 4; ++y)
|
for (y = 0; y < 4; ++y)
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include "files.h"
|
#include "files.h"
|
||||||
#include "w_wad.h"
|
#include "w_wad.h"
|
||||||
#include "textures/textures.h"
|
#include "textures/textures.h"
|
||||||
|
#include "imagehelpers.h"
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
|
@ -110,7 +111,7 @@ TArray<uint8_t> FFlatTexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
memset (Pixels.Data() + numread, 0xBB, Width*Height - numread);
|
memset (Pixels.Data() + numread, 0xBB, Width*Height - numread);
|
||||||
}
|
}
|
||||||
FTexture::FlipSquareBlockRemap(Pixels.Data(), Width, Height, GetRemap(alphatex));
|
ImageHelpers::FlipSquareBlockRemap(Pixels.Data(), Width, ImageHelpers::GetRemap(alphatex));
|
||||||
return Pixels;
|
return Pixels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include "w_wad.h"
|
#include "w_wad.h"
|
||||||
#include "v_video.h"
|
#include "v_video.h"
|
||||||
#include "bitmap.h"
|
#include "bitmap.h"
|
||||||
|
#include "imagehelpers.h"
|
||||||
|
|
||||||
bool checkIMGZPalette(FileReader &file);
|
bool checkIMGZPalette(FileReader &file);
|
||||||
|
|
||||||
|
@ -134,7 +135,7 @@ TArray<uint8_t> FIMGZTexture::Get8BitPixels(bool alphatex)
|
||||||
TArray<uint8_t> Pixels(Width*Height, true);
|
TArray<uint8_t> Pixels(Width*Height, true);
|
||||||
dest_p = Pixels.Data();
|
dest_p = Pixels.Data();
|
||||||
|
|
||||||
const uint8_t *remap = GetRemap(alphatex, isalpha);
|
const uint8_t *remap = ImageHelpers::GetRemap(alphatex, isalpha);
|
||||||
|
|
||||||
// Convert the source image from row-major to column-major format and remap it
|
// Convert the source image from row-major to column-major format and remap it
|
||||||
if (!imgz->Compression)
|
if (!imgz->Compression)
|
||||||
|
|
|
@ -45,6 +45,7 @@ extern "C"
|
||||||
#include "v_text.h"
|
#include "v_text.h"
|
||||||
#include "bitmap.h"
|
#include "bitmap.h"
|
||||||
#include "v_video.h"
|
#include "v_video.h"
|
||||||
|
#include "imagehelpers.h"
|
||||||
|
|
||||||
|
|
||||||
struct FLumpSourceMgr : public jpeg_source_mgr
|
struct FLumpSourceMgr : public jpeg_source_mgr
|
||||||
|
@ -316,7 +317,7 @@ TArray<uint8_t> FJPEGTexture::Get8BitPixels(bool doalpha)
|
||||||
case JCS_RGB:
|
case JCS_RGB:
|
||||||
for (int x = Width; x > 0; --x)
|
for (int x = Width; x > 0; --x)
|
||||||
{
|
{
|
||||||
*out = RGBToPalette(doalpha, in[0], in[1], in[2]);
|
*out = ImageHelpers::RGBToPalette(doalpha, in[0], in[1], in[2]);
|
||||||
out += Height;
|
out += Height;
|
||||||
in += 3;
|
in += 3;
|
||||||
}
|
}
|
||||||
|
@ -324,7 +325,7 @@ TArray<uint8_t> FJPEGTexture::Get8BitPixels(bool doalpha)
|
||||||
|
|
||||||
case JCS_GRAYSCALE:
|
case JCS_GRAYSCALE:
|
||||||
{
|
{
|
||||||
auto remap = GetRemap(doalpha, true);
|
auto remap = ImageHelpers::GetRemap(doalpha, true);
|
||||||
for (int x = Width; x > 0; --x)
|
for (int x = Width; x > 0; --x)
|
||||||
{
|
{
|
||||||
*out = remap[in[0]];
|
*out = remap[in[0]];
|
||||||
|
@ -342,7 +343,7 @@ TArray<uint8_t> FJPEGTexture::Get8BitPixels(bool doalpha)
|
||||||
int r = in[3] - (((256 - in[0])*in[3]) >> 8);
|
int r = in[3] - (((256 - in[0])*in[3]) >> 8);
|
||||||
int g = in[3] - (((256 - in[1])*in[3]) >> 8);
|
int g = in[3] - (((256 - in[1])*in[3]) >> 8);
|
||||||
int b = in[3] - (((256 - in[2])*in[3]) >> 8);
|
int b = in[3] - (((256 - in[2])*in[3]) >> 8);
|
||||||
*out = RGBToPalette(doalpha, r, g, b);
|
*out = ImageHelpers::RGBToPalette(doalpha, r, g, b);
|
||||||
out += Height;
|
out += Height;
|
||||||
in += 4;
|
in += 4;
|
||||||
}
|
}
|
||||||
|
@ -356,7 +357,7 @@ TArray<uint8_t> FJPEGTexture::Get8BitPixels(bool doalpha)
|
||||||
int r = clamp((int)(Y + 1.40200 * (Cr - 0x80)), 0, 255);
|
int r = clamp((int)(Y + 1.40200 * (Cr - 0x80)), 0, 255);
|
||||||
int g = clamp((int)(Y - 0.34414 * (Cb - 0x80) - 0.71414 * (Cr - 0x80)), 0, 255);
|
int g = clamp((int)(Y - 0.34414 * (Cb - 0x80) - 0.71414 * (Cr - 0x80)), 0, 255);
|
||||||
int b = clamp((int)(Y + 1.77200 * (Cb - 0x80)), 0, 255);
|
int b = clamp((int)(Y + 1.77200 * (Cb - 0x80)), 0, 255);
|
||||||
*out = RGBToPalette(doalpha, r, g, b);
|
*out = ImageHelpers::RGBToPalette(doalpha, r, g, b);
|
||||||
out += Height;
|
out += Height;
|
||||||
in += 4;
|
in += 4;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
#include "v_video.h"
|
#include "v_video.h"
|
||||||
#include "v_text.h"
|
#include "v_text.h"
|
||||||
#include "cmdlib.h"
|
#include "cmdlib.h"
|
||||||
|
#include "imagehelpers.h"
|
||||||
|
|
||||||
// On the Alpha, accessing the shorts directly if they aren't aligned on a
|
// On the Alpha, accessing the shorts directly if they aren't aligned on a
|
||||||
// 4-byte boundary causes unaligned access warnings. Why it does this at
|
// 4-byte boundary causes unaligned access warnings. Why it does this at
|
||||||
|
@ -450,7 +451,7 @@ TArray<uint8_t> FMultiPatchTexture::MakeTexture (bool alphatex)
|
||||||
{
|
{
|
||||||
if (*out == 0 && in[3] != 0)
|
if (*out == 0 && in[3] != 0)
|
||||||
{
|
{
|
||||||
*out = RGBToPalette(alphatex, in[2], in[1], in[0]);
|
*out = ImageHelpers::RGBToPalette(alphatex, in[2], in[1], in[0]);
|
||||||
}
|
}
|
||||||
out += Height;
|
out += Height;
|
||||||
in += 4;
|
in += 4;
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "v_palette.h"
|
#include "v_palette.h"
|
||||||
#include "v_video.h"
|
#include "v_video.h"
|
||||||
#include "bitmap.h"
|
#include "bitmap.h"
|
||||||
|
#include "imagehelpers.h"
|
||||||
|
|
||||||
|
|
||||||
// posts are runs of non masked source pixels
|
// posts are runs of non masked source pixels
|
||||||
|
@ -179,7 +180,7 @@ TArray<uint8_t> FPatchTexture::Get8BitPixels(bool alphatex)
|
||||||
|
|
||||||
maxcol = (const column_t *)((const uint8_t *)patch + Wads.LumpLength (SourceLump) - 3);
|
maxcol = (const column_t *)((const uint8_t *)patch + Wads.LumpLength (SourceLump) - 3);
|
||||||
|
|
||||||
remap = GetRemap(alphatex, isalpha);
|
remap = ImageHelpers::GetRemap(alphatex, isalpha);
|
||||||
// Special case for skies
|
// Special case for skies
|
||||||
if (bNoRemap0 && remap == GPalette.Remap)
|
if (bNoRemap0 && remap == GPalette.Remap)
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "w_wad.h"
|
#include "w_wad.h"
|
||||||
#include "bitmap.h"
|
#include "bitmap.h"
|
||||||
#include "v_video.h"
|
#include "v_video.h"
|
||||||
|
#include "imagehelpers.h"
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
|
@ -391,15 +392,15 @@ TArray<uint8_t> FPCXTexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
case 1:
|
case 1:
|
||||||
PaletteMap[0] = alphatex? 0 : GrayMap[0];
|
PaletteMap[0] = alphatex? 0 : ImageHelpers::GrayMap[0];
|
||||||
PaletteMap[1] = alphatex? 255 : GrayMap[255];
|
PaletteMap[1] = alphatex? 255 : ImageHelpers::GrayMap[255];
|
||||||
ReadPCX1bit (Pixels.Data(), lump, &header);
|
ReadPCX1bit (Pixels.Data(), lump, &header);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
for (int i = 0; i < 16; i++)
|
for (int i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
PaletteMap[i] = RGBToPalettePrecise(alphatex, header.palette[i * 3], header.palette[i * 3 + 1], header.palette[i * 3 + 2]);
|
PaletteMap[i] = ImageHelpers::RGBToPalettePrecise(alphatex, header.palette[i * 3], header.palette[i * 3 + 1], header.palette[i * 3 + 2]);
|
||||||
}
|
}
|
||||||
ReadPCX4bits (Pixels.Data(), lump, &header);
|
ReadPCX4bits (Pixels.Data(), lump, &header);
|
||||||
break;
|
break;
|
||||||
|
@ -416,19 +417,19 @@ TArray<uint8_t> FPCXTexture::Get8BitPixels(bool alphatex)
|
||||||
uint8_t r = lump.ReadUInt8();
|
uint8_t r = lump.ReadUInt8();
|
||||||
uint8_t g = lump.ReadUInt8();
|
uint8_t g = lump.ReadUInt8();
|
||||||
uint8_t b = lump.ReadUInt8();
|
uint8_t b = lump.ReadUInt8();
|
||||||
PaletteMap[i] = RGBToPalettePrecise(alphatex, r, g, b);
|
PaletteMap[i] = ImageHelpers::RGBToPalettePrecise(alphatex, r, g, b);
|
||||||
}
|
}
|
||||||
lump.Seek(sizeof(header), FileReader::SeekSet);
|
lump.Seek(sizeof(header), FileReader::SeekSet);
|
||||||
ReadPCX8bits (Pixels.Data(), lump, &header);
|
ReadPCX8bits (Pixels.Data(), lump, &header);
|
||||||
}
|
}
|
||||||
if (Width == Height)
|
if (Width == Height)
|
||||||
{
|
{
|
||||||
FlipSquareBlockRemap(Pixels.Data(), Width, Height, PaletteMap);
|
ImageHelpers::FlipSquareBlockRemap(Pixels.Data(), Width, PaletteMap);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TArray<uint8_t> newpix(Width*Height, true);
|
TArray<uint8_t> newpix(Width*Height, true);
|
||||||
FlipNonSquareBlockRemap (newpix.Data(), Pixels.Data(), Width, Height, Width, PaletteMap);
|
ImageHelpers::FlipNonSquareBlockRemap (newpix.Data(), Pixels.Data(), Width, Height, Width, PaletteMap);
|
||||||
return newpix;
|
return newpix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -441,7 +442,7 @@ TArray<uint8_t> FPCXTexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
for(int x=0; x < Width; x++)
|
for(int x=0; x < Width; x++)
|
||||||
{
|
{
|
||||||
Pixels[y + Height * x] = RGBToPalette(alphatex, row[0], row[1], row[2]);
|
Pixels[y + Height * x] = ImageHelpers::RGBToPalette(alphatex, row[0], row[1], row[2]);
|
||||||
row+=3;
|
row+=3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "templates.h"
|
#include "templates.h"
|
||||||
#include "m_png.h"
|
#include "m_png.h"
|
||||||
#include "bitmap.h"
|
#include "bitmap.h"
|
||||||
|
#include "imagehelpers.h"
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
|
@ -293,12 +294,12 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename
|
||||||
bMasked = true;
|
bMasked = true;
|
||||||
PaletteSize = 256;
|
PaletteSize = 256;
|
||||||
PaletteMap = new uint8_t[256];
|
PaletteMap = new uint8_t[256];
|
||||||
memcpy (PaletteMap, GrayMap, 256);
|
memcpy (PaletteMap, ImageHelpers::GrayMap, 256);
|
||||||
PaletteMap[NonPaletteTrans[0]] = 0;
|
PaletteMap[NonPaletteTrans[0]] = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PaletteMap = GrayMap;
|
PaletteMap = ImageHelpers::GrayMap;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -335,7 +336,7 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename
|
||||||
|
|
||||||
FPNGTexture::~FPNGTexture ()
|
FPNGTexture::~FPNGTexture ()
|
||||||
{
|
{
|
||||||
if (PaletteMap != nullptr && PaletteMap != FTexture::GrayMap)
|
if (PaletteMap != nullptr && PaletteMap != ImageHelpers::GrayMap)
|
||||||
{
|
{
|
||||||
delete[] PaletteMap;
|
delete[] PaletteMap;
|
||||||
PaletteMap = nullptr;
|
PaletteMap = nullptr;
|
||||||
|
@ -424,17 +425,17 @@ TArray<uint8_t> FPNGTexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
if (!alphatex)
|
if (!alphatex)
|
||||||
{
|
{
|
||||||
FTexture::FlipSquareBlockRemap (Pixels.Data(), Width, Height, PaletteMap);
|
ImageHelpers::FlipSquareBlockRemap (Pixels.Data(), Width, PaletteMap);
|
||||||
}
|
}
|
||||||
else if (ColorType == 0)
|
else if (ColorType == 0)
|
||||||
{
|
{
|
||||||
FTexture::FlipSquareBlock (Pixels.Data(), Width, Height);
|
ImageHelpers::FlipSquareBlock (Pixels.Data(), Width);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint8_t alpharemap[256];
|
uint8_t alpharemap[256];
|
||||||
ReadAlphaRemap(lump, alpharemap);
|
ReadAlphaRemap(lump, alpharemap);
|
||||||
FTexture::FlipSquareBlockRemap(Pixels.Data(), Width, Height, alpharemap);
|
ImageHelpers::FlipSquareBlockRemap(Pixels.Data(), Width, alpharemap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -442,17 +443,17 @@ TArray<uint8_t> FPNGTexture::Get8BitPixels(bool alphatex)
|
||||||
TArray<uint8_t> newpix(Width*Height, true);
|
TArray<uint8_t> newpix(Width*Height, true);
|
||||||
if (!alphatex)
|
if (!alphatex)
|
||||||
{
|
{
|
||||||
FTexture::FlipNonSquareBlockRemap (newpix.Data(), Pixels.Data(), Width, Height, Width, PaletteMap);
|
ImageHelpers::FlipNonSquareBlockRemap (newpix.Data(), Pixels.Data(), Width, Height, Width, PaletteMap);
|
||||||
}
|
}
|
||||||
else if (ColorType == 0)
|
else if (ColorType == 0)
|
||||||
{
|
{
|
||||||
FTexture::FlipNonSquareBlock (newpix.Data(), Pixels.Data(), Width, Height, Width);
|
ImageHelpers::FlipNonSquareBlock (newpix.Data(), Pixels.Data(), Width, Height, Width);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint8_t alpharemap[256];
|
uint8_t alpharemap[256];
|
||||||
ReadAlphaRemap(lump, alpharemap);
|
ReadAlphaRemap(lump, alpharemap);
|
||||||
FTexture::FlipNonSquareBlockRemap(newpix.Data(), Pixels.Data(), Width, Height, Width, alpharemap);
|
ImageHelpers::FlipNonSquareBlockRemap(newpix.Data(), Pixels.Data(), Width, Height, Width, alpharemap);
|
||||||
}
|
}
|
||||||
return newpix;
|
return newpix;
|
||||||
}
|
}
|
||||||
|
@ -485,7 +486,7 @@ TArray<uint8_t> FPNGTexture::Get8BitPixels(bool alphatex)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*out++ = RGBToPalette(alphatex, in[0], in[1], in[2]);
|
*out++ = ImageHelpers::RGBToPalette(alphatex, in[0], in[1], in[2]);
|
||||||
}
|
}
|
||||||
in += pitch;
|
in += pitch;
|
||||||
}
|
}
|
||||||
|
@ -514,7 +515,7 @@ TArray<uint8_t> FPNGTexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
for (y = Height; y > 0; --y)
|
for (y = Height; y > 0; --y)
|
||||||
{
|
{
|
||||||
*out++ = RGBToPalette(alphatex, in[0], in[1], in[2], in[3]);
|
*out++ = ImageHelpers::RGBToPalette(alphatex, in[0], in[1], in[2], in[3]);
|
||||||
in += pitch;
|
in += pitch;
|
||||||
}
|
}
|
||||||
in -= backstep;
|
in -= backstep;
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "gi.h"
|
#include "gi.h"
|
||||||
#include "bitmap.h"
|
#include "bitmap.h"
|
||||||
#include "textures/textures.h"
|
#include "textures/textures.h"
|
||||||
|
#include "imagehelpers.h"
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -184,7 +185,7 @@ TArray<uint8_t> FRawPageTexture::Get8BitPixels(bool alphatex)
|
||||||
TArray<uint8_t> Pixels(Width*Height, true);
|
TArray<uint8_t> Pixels(Width*Height, true);
|
||||||
dest_p = Pixels.Data();
|
dest_p = Pixels.Data();
|
||||||
|
|
||||||
const uint8_t *remap = GetRemap(alphatex);
|
const uint8_t *remap = ImageHelpers::GetRemap(alphatex);
|
||||||
|
|
||||||
// This does not handle the custom palette.
|
// This does not handle the custom palette.
|
||||||
// User maps are encouraged to use a real image format when replacing E2END and the original could never be used anywhere else.
|
// User maps are encouraged to use a real image format when replacing E2END and the original could never be used anywhere else.
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "menu/menu.h"
|
#include "menu/menu.h"
|
||||||
#include "w_wad.h"
|
#include "w_wad.h"
|
||||||
#include "bitmap.h"
|
#include "bitmap.h"
|
||||||
|
#include "imagehelpers.h"
|
||||||
|
|
||||||
|
|
||||||
class FBarShader : public FWorldTexture
|
class FBarShader : public FWorldTexture
|
||||||
|
@ -113,7 +114,7 @@ public:
|
||||||
// even if it makes little sense.
|
// even if it makes little sense.
|
||||||
for (int i = 0; i < 512; i++)
|
for (int i = 0; i < 512; i++)
|
||||||
{
|
{
|
||||||
Pix[i] = GrayMap[Pixels[i]];
|
Pix[i] = ImageHelpers::GrayMap[Pixels[i]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Pix;
|
return Pix;
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "templates.h"
|
#include "templates.h"
|
||||||
#include "bitmap.h"
|
#include "bitmap.h"
|
||||||
#include "v_video.h"
|
#include "v_video.h"
|
||||||
|
#include "imagehelpers.h"
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -244,7 +245,7 @@ TArray<uint8_t> FTGATexture::Get8BitPixels(bool alphatex)
|
||||||
r=g=b=a=0;
|
r=g=b=a=0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
PaletteMap[i] = RGBToPalettePrecise(alphatex, r, g, b, a);
|
PaletteMap[i] = ImageHelpers::RGBToPalettePrecise(alphatex, r, g, b, a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +304,7 @@ TArray<uint8_t> FTGATexture::Get8BitPixels(bool alphatex)
|
||||||
for(int x=0;x<Width;x++)
|
for(int x=0;x<Width;x++)
|
||||||
{
|
{
|
||||||
int v = LittleShort(*p);
|
int v = LittleShort(*p);
|
||||||
Pixels[x*Height + y] = RGBToPalette(alphatex, ((v >> 10) & 0x1f) * 8, ((v >> 5) & 0x1f) * 8, (v & 0x1f) * 8);
|
Pixels[x*Height + y] = ImageHelpers::RGBToPalette(alphatex, ((v >> 10) & 0x1f) * 8, ((v >> 5) & 0x1f) * 8, (v & 0x1f) * 8);
|
||||||
p+=step_x;
|
p+=step_x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -315,7 +316,7 @@ TArray<uint8_t> FTGATexture::Get8BitPixels(bool alphatex)
|
||||||
uint8_t * p = ptr + y * Pitch;
|
uint8_t * p = ptr + y * Pitch;
|
||||||
for(int x=0;x<Width;x++)
|
for(int x=0;x<Width;x++)
|
||||||
{
|
{
|
||||||
Pixels[x*Height + y] = RGBToPalette(alphatex, p[2], p[1], p[0]);
|
Pixels[x*Height + y] = ImageHelpers::RGBToPalette(alphatex, p[2], p[1], p[0]);
|
||||||
p+=step_x;
|
p+=step_x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,7 +330,7 @@ TArray<uint8_t> FTGATexture::Get8BitPixels(bool alphatex)
|
||||||
uint8_t * p = ptr + y * Pitch;
|
uint8_t * p = ptr + y * Pitch;
|
||||||
for(int x=0;x<Width;x++)
|
for(int x=0;x<Width;x++)
|
||||||
{
|
{
|
||||||
Pixels[x*Height + y] = RGBToPalette(alphatex, p[2], p[1], p[0]);
|
Pixels[x*Height + y] = ImageHelpers::RGBToPalette(alphatex, p[2], p[1], p[0]);
|
||||||
p+=step_x;
|
p+=step_x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -341,7 +342,7 @@ TArray<uint8_t> FTGATexture::Get8BitPixels(bool alphatex)
|
||||||
uint8_t * p = ptr + y * Pitch;
|
uint8_t * p = ptr + y * Pitch;
|
||||||
for(int x=0;x<Width;x++)
|
for(int x=0;x<Width;x++)
|
||||||
{
|
{
|
||||||
Pixels[x*Height + y] = RGBToPalette(alphatex, p[2], p[1], p[0], p[3]);
|
Pixels[x*Height + y] = ImageHelpers::RGBToPalette(alphatex, p[2], p[1], p[0], p[3]);
|
||||||
p+=step_x;
|
p+=step_x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -355,7 +356,7 @@ TArray<uint8_t> FTGATexture::Get8BitPixels(bool alphatex)
|
||||||
|
|
||||||
case 3: // Grayscale
|
case 3: // Grayscale
|
||||||
{
|
{
|
||||||
auto remap = GetRemap(alphatex, true);
|
auto remap = ImageHelpers::GetRemap(alphatex, true);
|
||||||
switch (hdr.bpp)
|
switch (hdr.bpp)
|
||||||
{
|
{
|
||||||
case 8:
|
case 8:
|
||||||
|
|
154
src/textures/imagehelpers.h
Normal file
154
src/textures/imagehelpers.h
Normal file
|
@ -0,0 +1,154 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
** imagehelpers.h
|
||||||
|
** Utilities for image conversion - mostly 8 bit paletted baggage
|
||||||
|
**
|
||||||
|
**---------------------------------------------------------------------------
|
||||||
|
** Copyright 2004-2007 Randy Heit
|
||||||
|
** Copyright 2006-2018 Christoph Oelckers
|
||||||
|
** All rights reserved.
|
||||||
|
**
|
||||||
|
** Redistribution and use in source and binary forms, with or without
|
||||||
|
** modification, are permitted provided that the following conditions
|
||||||
|
** are met:
|
||||||
|
**
|
||||||
|
** 1. Redistributions of source code must retain the above copyright
|
||||||
|
** notice, this list of conditions and the following disclaimer.
|
||||||
|
** 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
** notice, this list of conditions and the following disclaimer in the
|
||||||
|
** documentation and/or other materials provided with the distribution.
|
||||||
|
** 3. The name of the author may not be used to endorse or promote products
|
||||||
|
** derived from this software without specific prior written permission.
|
||||||
|
**
|
||||||
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
**---------------------------------------------------------------------------
|
||||||
|
**
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "tarray.h"
|
||||||
|
#include "colormatcher.h"
|
||||||
|
#include "v_palette.h"
|
||||||
|
#include "textures/bitmap.h"
|
||||||
|
#include "r_data/renderstyle.h"
|
||||||
|
#include "r_data/r_translate.h"
|
||||||
|
|
||||||
|
namespace ImageHelpers
|
||||||
|
{
|
||||||
|
extern uint8_t GrayMap[256];
|
||||||
|
|
||||||
|
// Helpers for creating paletted images.
|
||||||
|
inline uint8_t *GetRemap(bool wantluminance, bool srcisgrayscale = false)
|
||||||
|
{
|
||||||
|
if (wantluminance)
|
||||||
|
{
|
||||||
|
return translationtables[TRANSLATION_Standard][srcisgrayscale ? STD_Gray : STD_Grayscale]->Remap;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return srcisgrayscale ? GrayMap : GPalette.Remap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint8_t RGBToPalettePrecise(bool wantluminance, int r, int g, int b, int a = 255)
|
||||||
|
{
|
||||||
|
if (wantluminance)
|
||||||
|
{
|
||||||
|
return (uint8_t)Luminance(r, g, b) * a / 255;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return ColorMatcher.Pick(r, g, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint8_t RGBToPalette(bool wantluminance, int r, int g, int b, int a = 255)
|
||||||
|
{
|
||||||
|
if (wantluminance)
|
||||||
|
{
|
||||||
|
// This is the same formula the OpenGL renderer uses for grayscale textures with an alpha channel.
|
||||||
|
return (uint8_t)(Luminance(r, g, b) * a / 255);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return a < 128? 0 : RGB256k.RGB[r >> 2][g >> 2][b >> 2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint8_t RGBToPalette(bool wantluminance, PalEntry pe, bool hasalpha = true)
|
||||||
|
{
|
||||||
|
return RGBToPalette(wantluminance, pe.r, pe.g, pe.b, hasalpha? pe.a : 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// Converts a texture between row-major and column-major format
|
||||||
|
// by flipping it about the X=Y axis.
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void FlipSquareBlock (T *block, int x)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < x; ++i)
|
||||||
|
{
|
||||||
|
uint8_t *corner = block + x*i + i;
|
||||||
|
int count = x - i;
|
||||||
|
for (int j = 0; j < count; j++)
|
||||||
|
{
|
||||||
|
std::swap(corner[j], corner[j*x]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void FlipSquareBlockRemap (uint8_t *block, int x, const uint8_t *remap)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < x; ++i)
|
||||||
|
{
|
||||||
|
uint8_t *corner = block + x*i + i;
|
||||||
|
int count = x - i;
|
||||||
|
for (int j = 0; j < count; j++)
|
||||||
|
{
|
||||||
|
auto t = remap[corner[j]];
|
||||||
|
corner[j] = remap[corner[j*x]];
|
||||||
|
corner[j*x] = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void FlipNonSquareBlock (T *dst, const T *src, int x, int y, int srcpitch)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < x; ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < y; ++j)
|
||||||
|
{
|
||||||
|
dst[i*y+j] = src[i+j*srcpitch];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void FlipNonSquareBlockRemap (uint8_t *dst, const uint8_t *src, int x, int y, int srcpitch, const uint8_t *remap)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < x; ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < y; ++j)
|
||||||
|
{
|
||||||
|
dst[i*y+j] = remap[src[i+j*srcpitch]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -48,6 +48,7 @@
|
||||||
#include "hwrenderer/textures/hw_material.h"
|
#include "hwrenderer/textures/hw_material.h"
|
||||||
#include "hwrenderer/textures/hw_ihwtexture.h"
|
#include "hwrenderer/textures/hw_ihwtexture.h"
|
||||||
#include "swrenderer/textures/r_swtexture.h"
|
#include "swrenderer/textures/r_swtexture.h"
|
||||||
|
#include "imagehelpers.h"
|
||||||
|
|
||||||
FTexture *CreateBrightmapTexture(FTexture*);
|
FTexture *CreateBrightmapTexture(FTexture*);
|
||||||
|
|
||||||
|
@ -66,13 +67,13 @@ CUSTOM_CVAR(Int, r_spriteadjust, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
uint8_t FTexture::GrayMap[256];
|
uint8_t ImageHelpers::GrayMap[256];
|
||||||
|
|
||||||
void FTexture::InitGrayMap()
|
void FTexture::InitGrayMap()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 256; ++i)
|
for (int i = 0; i < 256; ++i)
|
||||||
{
|
{
|
||||||
GrayMap[i] = ColorMatcher.Pick(i, i, i);
|
ImageHelpers::GrayMap[i] = ColorMatcher.Pick(i, i, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,128 +298,6 @@ void FTexture::CopyToBlock (uint8_t *dest, int dwidth, int dheight, int xpos, in
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
|
||||||
//
|
|
||||||
// Converts a texture between row-major and column-major format
|
|
||||||
// by flipping it about the X=Y axis.
|
|
||||||
//
|
|
||||||
//==========================================================================
|
|
||||||
|
|
||||||
void FTexture::FlipSquareBlock (uint8_t *block, int x, int y)
|
|
||||||
{
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
if (x != y) return;
|
|
||||||
|
|
||||||
for (i = 0; i < x; ++i)
|
|
||||||
{
|
|
||||||
uint8_t *corner = block + x*i + i;
|
|
||||||
int count = x - i;
|
|
||||||
if (count & 1)
|
|
||||||
{
|
|
||||||
count--;
|
|
||||||
swapvalues<uint8_t> (corner[count], corner[count*x]);
|
|
||||||
}
|
|
||||||
for (j = 0; j < count; j += 2)
|
|
||||||
{
|
|
||||||
swapvalues<uint8_t> (corner[j], corner[j*x]);
|
|
||||||
swapvalues<uint8_t> (corner[j+1], corner[(j+1)*x]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FTexture::FlipSquareBlockBgra(uint32_t *block, int x, int y)
|
|
||||||
{
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
if (x != y) return;
|
|
||||||
|
|
||||||
for (i = 0; i < x; ++i)
|
|
||||||
{
|
|
||||||
uint32_t *corner = block + x*i + i;
|
|
||||||
int count = x - i;
|
|
||||||
if (count & 1)
|
|
||||||
{
|
|
||||||
count--;
|
|
||||||
swapvalues<uint32_t>(corner[count], corner[count*x]);
|
|
||||||
}
|
|
||||||
for (j = 0; j < count; j += 2)
|
|
||||||
{
|
|
||||||
swapvalues<uint32_t>(corner[j], corner[j*x]);
|
|
||||||
swapvalues<uint32_t>(corner[j + 1], corner[(j + 1)*x]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FTexture::FlipSquareBlockRemap (uint8_t *block, int x, int y, const uint8_t *remap)
|
|
||||||
{
|
|
||||||
int i, j;
|
|
||||||
uint8_t t;
|
|
||||||
|
|
||||||
if (x != y) return;
|
|
||||||
|
|
||||||
for (i = 0; i < x; ++i)
|
|
||||||
{
|
|
||||||
uint8_t *corner = block + x*i + i;
|
|
||||||
int count = x - i;
|
|
||||||
if (count & 1)
|
|
||||||
{
|
|
||||||
count--;
|
|
||||||
t = remap[corner[count]];
|
|
||||||
corner[count] = remap[corner[count*x]];
|
|
||||||
corner[count*x] = t;
|
|
||||||
}
|
|
||||||
for (j = 0; j < count; j += 2)
|
|
||||||
{
|
|
||||||
t = remap[corner[j]];
|
|
||||||
corner[j] = remap[corner[j*x]];
|
|
||||||
corner[j*x] = t;
|
|
||||||
t = remap[corner[j+1]];
|
|
||||||
corner[j+1] = remap[corner[(j+1)*x]];
|
|
||||||
corner[(j+1)*x] = t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FTexture::FlipNonSquareBlock (uint8_t *dst, const uint8_t *src, int x, int y, int srcpitch)
|
|
||||||
{
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
for (i = 0; i < x; ++i)
|
|
||||||
{
|
|
||||||
for (j = 0; j < y; ++j)
|
|
||||||
{
|
|
||||||
dst[i*y+j] = src[i+j*srcpitch];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FTexture::FlipNonSquareBlockBgra(uint32_t *dst, const uint32_t *src, int x, int y, int srcpitch)
|
|
||||||
{
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
for (i = 0; i < x; ++i)
|
|
||||||
{
|
|
||||||
for (j = 0; j < y; ++j)
|
|
||||||
{
|
|
||||||
dst[i*y + j] = src[i + j*srcpitch];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FTexture::FlipNonSquareBlockRemap (uint8_t *dst, const uint8_t *src, int x, int y, int srcpitch, const uint8_t *remap)
|
|
||||||
{
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
for (i = 0; i < x; ++i)
|
|
||||||
{
|
|
||||||
for (j = 0; j < y; ++j)
|
|
||||||
{
|
|
||||||
dst[i*y+j] = remap[src[i+j*srcpitch]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
//
|
//
|
||||||
// FTexture::CopyPixels
|
// FTexture::CopyPixels
|
||||||
|
|
|
@ -304,12 +304,14 @@ public:
|
||||||
/*virtual*/ FBitmap GetBgraBitmap(PalEntry *remap, int *trans = nullptr);
|
/*virtual*/ FBitmap GetBgraBitmap(PalEntry *remap, int *trans = nullptr);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/*
|
||||||
static void FlipSquareBlock (uint8_t *block, int x, int y);
|
static void FlipSquareBlock (uint8_t *block, int x, int y);
|
||||||
static void FlipSquareBlockBgra (uint32_t *block, int x, int y);
|
static void FlipSquareBlockBgra (uint32_t *block, int x, int y);
|
||||||
static void FlipSquareBlockRemap (uint8_t *block, int x, int y, const uint8_t *remap);
|
static void FlipSquareBlockRemap (uint8_t *block, int x, int y, const uint8_t *remap);
|
||||||
static void FlipNonSquareBlock (uint8_t *blockto, const uint8_t *blockfrom, int x, int y, int srcpitch);
|
static void FlipNonSquareBlock (uint8_t *blockto, const uint8_t *blockfrom, int x, int y, int srcpitch);
|
||||||
static void FlipNonSquareBlockBgra (uint32_t *blockto, const uint32_t *blockfrom, int x, int y, int srcpitch);
|
static void FlipNonSquareBlockBgra (uint32_t *blockto, const uint32_t *blockfrom, int x, int y, int srcpitch);
|
||||||
static void FlipNonSquareBlockRemap (uint8_t *blockto, const uint8_t *blockfrom, int x, int y, int srcpitch, const uint8_t *remap);
|
static void FlipNonSquareBlockRemap (uint8_t *blockto, const uint8_t *blockfrom, int x, int y, int srcpitch, const uint8_t *remap);
|
||||||
|
*/
|
||||||
static bool SmoothEdges(unsigned char * buffer,int w, int h);
|
static bool SmoothEdges(unsigned char * buffer,int w, int h);
|
||||||
static PalEntry averageColor(const uint32_t *data, int size, int maxout);
|
static PalEntry averageColor(const uint32_t *data, int size, int maxout);
|
||||||
|
|
||||||
|
@ -459,53 +461,6 @@ protected:
|
||||||
protected:
|
protected:
|
||||||
uint16_t Width, Height;
|
uint16_t Width, Height;
|
||||||
int16_t _LeftOffset[2], _TopOffset[2];
|
int16_t _LeftOffset[2], _TopOffset[2];
|
||||||
static uint8_t GrayMap[256];
|
|
||||||
uint8_t *GetRemap(bool wantluminance, bool srcisgrayscale = false)
|
|
||||||
{
|
|
||||||
if (wantluminance)
|
|
||||||
{
|
|
||||||
return translationtables[TRANSLATION_Standard][srcisgrayscale ? STD_Gray : STD_Grayscale]->Remap;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return srcisgrayscale ? GrayMap : GPalette.Remap;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t RGBToPalettePrecise(bool wantluminance, int r, int g, int b, int a = 255)
|
|
||||||
{
|
|
||||||
if (wantluminance)
|
|
||||||
{
|
|
||||||
return (uint8_t)Luminance(r, g, b) * a / 255;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return ColorMatcher.Pick(r, g, b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t RGBToPalette(bool wantluminance, int r, int g, int b, int a = 255)
|
|
||||||
{
|
|
||||||
if (wantluminance)
|
|
||||||
{
|
|
||||||
// This is the same formula the OpenGL renderer uses for grayscale textures with an alpha channel.
|
|
||||||
return (uint8_t)(Luminance(r, g, b) * a / 255);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return a < 128? 0 : RGB256k.RGB[r >> 2][g >> 2][b >> 2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t RGBToPalette(bool wantluminance, PalEntry pe, bool hasalpha = true)
|
|
||||||
{
|
|
||||||
return RGBToPalette(wantluminance, pe.r, pe.g, pe.b, hasalpha? pe.a : 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t RGBToPalette(FRenderStyle style, int r, int g, int b, int a = 255)
|
|
||||||
{
|
|
||||||
return RGBToPalette(!!(style.Flags & STYLEF_RedIsAlpha), r, g, b, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
FTexture (const char *name = NULL, int lumpnum = -1);
|
FTexture (const char *name = NULL, int lumpnum = -1);
|
||||||
|
|
||||||
|
@ -635,13 +590,6 @@ public:
|
||||||
void DeleteAll();
|
void DeleteAll();
|
||||||
void SpriteAdjustChanged();
|
void SpriteAdjustChanged();
|
||||||
|
|
||||||
// Replaces one texture with another. The new texture will be assigned
|
|
||||||
// the same name, slot, and use type as the texture it is replacing.
|
|
||||||
// The old texture will no longer be managed. Set free true if you want
|
|
||||||
// the old texture to be deleted or set it false if you want it to
|
|
||||||
// be left alone in memory. You will still need to delete it at some
|
|
||||||
// point, because the texture manager no longer knows about it.
|
|
||||||
// This function can be used for such things as warping textures.
|
|
||||||
void ReplaceTexture (FTextureID picnum, FTexture *newtexture, bool free);
|
void ReplaceTexture (FTextureID picnum, FTexture *newtexture, bool free);
|
||||||
|
|
||||||
int NumTextures () const { return (int)Textures.Size(); }
|
int NumTextures () const { return (int)Textures.Size(); }
|
||||||
|
|
Loading…
Reference in a new issue