bug fixes
This commit is contained in:
@@ -17,8 +17,8 @@ VX_LDFLAGS += -lm
|
|||||||
|
|
||||||
VX_SRCS = kernel.c
|
VX_SRCS = kernel.c
|
||||||
|
|
||||||
#CXXFLAGS += -std=c++11 -O2 -Wall -Wextra -pedantic -Wfatal-errors
|
#CXXFLAGS += -std=c++11 -O2 -Wall -Wextra -Wfatal-errors
|
||||||
CXXFLAGS += -std=c++11 -O0 -g -Wall -Wextra -pedantic -Wfatal-errors
|
CXXFLAGS += -std=c++11 -O0 -g -Wall -Wextra -Wfatal-errors
|
||||||
|
|
||||||
CXXFLAGS += -I../../include
|
CXXFLAGS += -I../../include
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
#include "format.h"
|
#include "format.h"
|
||||||
|
|
||||||
struct SurfaceDesc {
|
struct SurfaceDesc {
|
||||||
uint8_t Format;
|
ePixelFormat Format;
|
||||||
uint8_t *pBits;
|
uint8_t *pBits;
|
||||||
int32_t Width;
|
uint32_t Width;
|
||||||
int32_t Height;
|
uint32_t Height;
|
||||||
int32_t Pitch;
|
uint32_t Pitch;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BlitTable {
|
class BlitTable {
|
||||||
public:
|
public:
|
||||||
typedef void (*PfnCopy)(const SurfaceDesc &dstDesc,
|
typedef int (*PfnCopy)(const SurfaceDesc &dstDesc,
|
||||||
uint32_t dstOffsetX,
|
uint32_t dstOffsetX,
|
||||||
uint32_t dstOffsetY,
|
uint32_t dstOffsetY,
|
||||||
uint32_t copyWidth,
|
uint32_t copyWidth,
|
||||||
uint32_t copyHeight,
|
uint32_t copyHeight,
|
||||||
const SurfaceDesc &srcDesc,
|
const SurfaceDesc &srcDesc,
|
||||||
uint32_t srcOffsetX,
|
uint32_t srcOffsetX,
|
||||||
uint32_t srcOffsetY);
|
uint32_t srcOffsetY);
|
||||||
|
|
||||||
BlitTable() {
|
BlitTable() {
|
||||||
for (uint32_t s = 0; s < FORMAT_COLOR_SIZE_; ++s) {
|
for (uint32_t s = 0; s < FORMAT_COLOR_SIZE_; ++s) {
|
||||||
@@ -183,14 +183,14 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
template <ePixelFormat SrcFormat, ePixelFormat DstFormat>
|
template <ePixelFormat SrcFormat, ePixelFormat DstFormat>
|
||||||
static void Copy(const SurfaceDesc &dstDesc,
|
static int Copy(const SurfaceDesc &dstDesc,
|
||||||
uint32_t dstOffsetX,
|
uint32_t dstOffsetX,
|
||||||
uint32_t dstOffsetY,
|
uint32_t dstOffsetY,
|
||||||
uint32_t copyWidth,
|
uint32_t copyWidth,
|
||||||
uint32_t copyHeight,
|
uint32_t copyHeight,
|
||||||
const SurfaceDesc &srcDesc,
|
const SurfaceDesc &srcDesc,
|
||||||
uint32_t srcOffsetX,
|
uint32_t srcOffsetX,
|
||||||
uint32_t srcOffsetY) {
|
uint32_t srcOffsetY) {
|
||||||
auto srcBPP = TFormatInfo<SrcFormat>::CBSIZE;
|
auto srcBPP = TFormatInfo<SrcFormat>::CBSIZE;
|
||||||
auto dstBPP = TFormatInfo<DstFormat>::CBSIZE;
|
auto dstBPP = TFormatInfo<DstFormat>::CBSIZE;
|
||||||
auto srcNextLine = srcDesc.Pitch;
|
auto srcNextLine = srcDesc.Pitch;
|
||||||
@@ -212,13 +212,18 @@ private:
|
|||||||
pbSrc += srcNextLine;
|
pbSrc += srcNextLine;
|
||||||
pbDst += dstNextLine;
|
pbDst += dstNextLine;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
static void CopyFast(const SurfaceDesc &dstDesc, uint32_t dstOffsetX,
|
static int CopyFast(const SurfaceDesc &dstDesc,
|
||||||
uint32_t dstOffsetY, uint32_t copyWidth,
|
uint32_t dstOffsetX,
|
||||||
uint32_t copyHeight, const SurfaceDesc &srcDesc,
|
uint32_t dstOffsetY,
|
||||||
uint32_t srcOffsetX, uint32_t srcOffsetY) {
|
uint32_t copyWidth,
|
||||||
|
uint32_t copyHeight,
|
||||||
|
const SurfaceDesc &srcDesc,
|
||||||
|
uint32_t srcOffsetX,
|
||||||
|
uint32_t srcOffsetY) {
|
||||||
auto nBPP = sizeof(Type);
|
auto nBPP = sizeof(Type);
|
||||||
auto srcNextLine = srcDesc.Pitch;
|
auto srcNextLine = srcDesc.Pitch;
|
||||||
auto dstNextLine = dstDesc.Pitch;
|
auto dstNextLine = dstDesc.Pitch;
|
||||||
@@ -235,18 +240,20 @@ private:
|
|||||||
pbSrc += srcNextLine;
|
pbSrc += srcNextLine;
|
||||||
pbDst += dstNextLine;
|
pbDst += dstNextLine;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CopyInvalid(const SurfaceDesc & /*dstDesc*/,
|
static int CopyInvalid(const SurfaceDesc & /*dstDesc*/,
|
||||||
uint32_t /*dstOffsetX*/,
|
uint32_t /*dstOffsetX*/,
|
||||||
uint32_t /*dstOffsetY*/,
|
uint32_t /*dstOffsetY*/,
|
||||||
uint32_t /*copyWidth*/,
|
uint32_t /*copyWidth*/,
|
||||||
uint32_t /*copyHeight*/,
|
uint32_t /*copyHeight*/,
|
||||||
const SurfaceDesc & /*srcDesc*/,
|
const SurfaceDesc & /*srcDesc*/,
|
||||||
uint32_t /*srcOffsetX*/,
|
uint32_t /*srcOffsetX*/,
|
||||||
uint32_t /*srcOffsetY*/)
|
uint32_t /*srcOffsetY*/)
|
||||||
{
|
{
|
||||||
std::abort();
|
std::cout << "Error: invalid format" << std::endl;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
PfnCopy copyFuncs_[FORMAT_COLOR_SIZE_][FORMAT_COLOR_SIZE_];
|
PfnCopy copyFuncs_[FORMAT_COLOR_SIZE_][FORMAT_COLOR_SIZE_];
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ enum ePixelFormat {
|
|||||||
#define FORMAT_ARGB FORMAT_A8R8G8B8
|
#define FORMAT_ARGB FORMAT_A8R8G8B8
|
||||||
#define FORMAT_ARGB_ FORMAT_A4R4G4B4
|
#define FORMAT_ARGB_ FORMAT_A4R4G4B4
|
||||||
|
|
||||||
template <uint32_t PixelFormat>
|
template <ePixelFormat PixelFormat>
|
||||||
struct TFormatInfo {};
|
struct TFormatInfo {};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
@@ -462,7 +462,7 @@ public:
|
|||||||
|
|
||||||
namespace Format {
|
namespace Format {
|
||||||
|
|
||||||
inline static const FormatInfo &GetInfo(uint32_t pixelFormat) {
|
inline static const FormatInfo &GetInfo(ePixelFormat pixelFormat) {
|
||||||
static const FormatInfo sc_formatInfos[FORMAT_SIZE_] = {
|
static const FormatInfo sc_formatInfos[FORMAT_SIZE_] = {
|
||||||
__formatInfo(FORMAT_UNKNOWN),
|
__formatInfo(FORMAT_UNKNOWN),
|
||||||
__formatInfo(FORMAT_A8),
|
__formatInfo(FORMAT_A8),
|
||||||
@@ -501,26 +501,26 @@ typedef ColorARGB (*pfn_convert_from)(const void *pIn);
|
|||||||
|
|
||||||
typedef void (*pfn_convert_to)(void *pOut, const ColorARGB &in);
|
typedef void (*pfn_convert_to)(void *pOut, const ColorARGB &in);
|
||||||
|
|
||||||
template <uint32_t PixelFormat>
|
template <ePixelFormat PixelFormat>
|
||||||
static uint32_t ConvertTo(const ColorARGB &color);
|
static uint32_t ConvertTo(const ColorARGB &color);
|
||||||
|
|
||||||
template <uint32_t PixelFormat>
|
template <ePixelFormat PixelFormat>
|
||||||
static void ConvertTo(void *pOut, const ColorARGB &in) {
|
static void ConvertTo(void *pOut, const ColorARGB &in) {
|
||||||
*reinterpret_cast<typename TFormatInfo<PixelFormat>::TYPE *>(pOut) =
|
*reinterpret_cast<typename TFormatInfo<PixelFormat>::TYPE *>(pOut) =
|
||||||
static_cast<typename TFormatInfo<PixelFormat>::TYPE>(
|
static_cast<typename TFormatInfo<PixelFormat>::TYPE>(
|
||||||
ConvertTo<PixelFormat>(in));
|
ConvertTo<PixelFormat>(in));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <uint32_t PixelFormat, bool bForceAlpha>
|
template <ePixelFormat PixelFormat, bool bForceAlpha>
|
||||||
static ColorARGB ConvertFrom(uint32_t in);
|
static ColorARGB ConvertFrom(uint32_t in);
|
||||||
|
|
||||||
template <uint32_t PixelFormat, bool bForceAlpha>
|
template <ePixelFormat PixelFormat, bool bForceAlpha>
|
||||||
static ColorARGB ConvertFrom(const void *pIn) {
|
static ColorARGB ConvertFrom(const void *pIn) {
|
||||||
return ConvertFrom<PixelFormat, bForceAlpha>(
|
return ConvertFrom<PixelFormat, bForceAlpha>(
|
||||||
*reinterpret_cast<const typename TFormatInfo<PixelFormat>::TYPE *>(pIn));
|
*reinterpret_cast<const typename TFormatInfo<PixelFormat>::TYPE *>(pIn));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static pfn_convert_to GetConvertTo(uint32_t pixelFormat) {
|
inline static pfn_convert_to GetConvertTo(ePixelFormat pixelFormat) {
|
||||||
switch (pixelFormat) {
|
switch (pixelFormat) {
|
||||||
case FORMAT_A8:
|
case FORMAT_A8:
|
||||||
return &ConvertTo<FORMAT_A8>;
|
return &ConvertTo<FORMAT_A8>;
|
||||||
@@ -550,11 +550,13 @@ inline static pfn_convert_to GetConvertTo(uint32_t pixelFormat) {
|
|||||||
return &ConvertTo<FORMAT_D16>;
|
return &ConvertTo<FORMAT_D16>;
|
||||||
case FORMAT_X8S8D16:
|
case FORMAT_X8S8D16:
|
||||||
return &ConvertTo<FORMAT_X8S8D16>;
|
return &ConvertTo<FORMAT_X8S8D16>;
|
||||||
|
default:
|
||||||
|
return &ConvertTo<FORMAT_UNKNOWN>;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static pfn_convert_from GetConvertFrom(uint32_t pixelFormat,
|
inline static pfn_convert_from GetConvertFrom(ePixelFormat pixelFormat,
|
||||||
bool bForceAlpha) {
|
bool bForceAlpha) {
|
||||||
if (bForceAlpha) {
|
if (bForceAlpha) {
|
||||||
switch (pixelFormat) {
|
switch (pixelFormat) {
|
||||||
@@ -586,6 +588,8 @@ inline static pfn_convert_from GetConvertFrom(uint32_t pixelFormat,
|
|||||||
return &ConvertFrom<FORMAT_D16, false>;
|
return &ConvertFrom<FORMAT_D16, false>;
|
||||||
case FORMAT_X8S8D16:
|
case FORMAT_X8S8D16:
|
||||||
return &ConvertFrom<FORMAT_X8S8D16, false>;
|
return &ConvertFrom<FORMAT_X8S8D16, false>;
|
||||||
|
default:
|
||||||
|
return &ConvertFrom<FORMAT_UNKNOWN, false>;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (pixelFormat) {
|
switch (pixelFormat) {
|
||||||
@@ -617,13 +621,15 @@ inline static pfn_convert_from GetConvertFrom(uint32_t pixelFormat,
|
|||||||
return &ConvertFrom<FORMAT_D16, false>;
|
return &ConvertFrom<FORMAT_D16, false>;
|
||||||
case FORMAT_X8S8D16:
|
case FORMAT_X8S8D16:
|
||||||
return &ConvertFrom<FORMAT_X8S8D16, false>;
|
return &ConvertFrom<FORMAT_X8S8D16, false>;
|
||||||
|
default:
|
||||||
|
return &ConvertFrom<FORMAT_UNKNOWN, false>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static uint32_t GetNativeFormat(uint32_t pixelFormat) {
|
inline static uint32_t GetNativeFormat(ePixelFormat pixelFormat) {
|
||||||
switch (pixelFormat) {
|
switch (pixelFormat) {
|
||||||
case FORMAT_PAL4_B8G8R8:
|
case FORMAT_PAL4_B8G8R8:
|
||||||
case FORMAT_PAL8_B8G8R8:
|
case FORMAT_PAL8_B8G8R8:
|
||||||
@@ -644,8 +650,10 @@ inline static uint32_t GetNativeFormat(uint32_t pixelFormat) {
|
|||||||
case FORMAT_PAL4_R5G5B5A1:
|
case FORMAT_PAL4_R5G5B5A1:
|
||||||
case FORMAT_PAL8_R5G5B5A1:
|
case FORMAT_PAL8_R5G5B5A1:
|
||||||
return FORMAT_R5G5B5A1;
|
return FORMAT_R5G5B5A1;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return pixelFormat;
|
||||||
}
|
}
|
||||||
return pixelFormat;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -22,10 +22,11 @@
|
|||||||
const char* kernel_file = "kernel.bin";
|
const char* kernel_file = "kernel.bin";
|
||||||
const char* input_file = "palette64.tga";
|
const char* input_file = "palette64.tga";
|
||||||
const char* output_file = "output.tga";
|
const char* output_file = "output.tga";
|
||||||
int wrap = 0;
|
int wrap = 0;
|
||||||
int filter = 0;
|
int filter = 0;
|
||||||
float scale = 1.0f;
|
float scale = 1.0f;
|
||||||
int format = 0;
|
int format = 0;
|
||||||
|
ePixelFormat eformat = FORMAT_A8R8G8B8;
|
||||||
|
|
||||||
vx_device_h device = nullptr;
|
vx_device_h device = nullptr;
|
||||||
vx_buffer_h buffer = nullptr;
|
vx_buffer_h buffer = nullptr;
|
||||||
@@ -51,9 +52,19 @@ static void parse_args(int argc, char **argv) {
|
|||||||
case 'w':
|
case 'w':
|
||||||
wrap = std::atoi(optarg);
|
wrap = std::atoi(optarg);
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f': {
|
||||||
format = std::atoi(optarg);
|
format = std::atoi(optarg);
|
||||||
break;
|
switch (format) {
|
||||||
|
case 0: eformat = FORMAT_A8R8G8B8; break;
|
||||||
|
case 1: eformat = FORMAT_R5G6B5; break;
|
||||||
|
case 2: eformat = FORMAT_R4G4B4A4; break;
|
||||||
|
case 3: eformat = FORMAT_L8; break;
|
||||||
|
case 4: eformat = FORMAT_A8; break;
|
||||||
|
default:
|
||||||
|
std::cout << "Error: invalid format: " << format << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
case 'g':
|
case 'g':
|
||||||
filter = std::atoi(optarg);
|
filter = std::atoi(optarg);
|
||||||
break;
|
break;
|
||||||
@@ -81,7 +92,11 @@ void cleanup() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int run_test(const kernel_arg_t& kernel_arg, uint32_t buf_size, uint32_t width, uint32_t height, uint32_t bpp) {
|
int run_test(const kernel_arg_t& kernel_arg,
|
||||||
|
uint32_t buf_size,
|
||||||
|
uint32_t width,
|
||||||
|
uint32_t height,
|
||||||
|
uint32_t bpp) {
|
||||||
// start device
|
// start device
|
||||||
std::cout << "start device" << std::endl;
|
std::cout << "start device" << std::endl;
|
||||||
RT_CHECK(vx_start(device));
|
RT_CHECK(vx_start(device));
|
||||||
@@ -110,7 +125,6 @@ int run_test(const kernel_arg_t& kernel_arg, uint32_t buf_size, uint32_t width,
|
|||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
kernel_arg_t kernel_arg;
|
kernel_arg_t kernel_arg;
|
||||||
std::vector<uint8_t> src_pixels_rgba8;
|
|
||||||
std::vector<uint8_t> src_pixels;
|
std::vector<uint8_t> src_pixels;
|
||||||
uint32_t src_width;
|
uint32_t src_width;
|
||||||
uint32_t src_height;
|
uint32_t src_height;
|
||||||
@@ -119,14 +133,13 @@ int main(int argc, char *argv[]) {
|
|||||||
// parse command arguments
|
// parse command arguments
|
||||||
parse_args(argc, argv);
|
parse_args(argc, argv);
|
||||||
|
|
||||||
// if (format){
|
std::vector<uint8_t> tmp_pixels;
|
||||||
RT_CHECK(LoadTGA(input_file, src_pixels_rgba8, &src_width, &src_height, &src_bpp));
|
RT_CHECK(LoadTGA(input_file, tmp_pixels, &src_width, &src_height));
|
||||||
RT_CHECK(ConvertImage(src_pixels, src_pixels_rgba8, &src_bpp, src_width, src_height, 0, format));
|
RT_CHECK(ConvertImage(src_pixels, tmp_pixels, src_width, src_height, FORMAT_A8R8G8B8, eformat));
|
||||||
// } else {
|
src_bpp = Format::GetInfo(eformat).BytePerPixel;
|
||||||
// RT_CHECK(LoadTGA(input_file, src_pixels, &src_width, &src_height, &src_bpp));
|
|
||||||
// }
|
|
||||||
|
|
||||||
dump_image(src_pixels, src_width, src_height, src_bpp);
|
dump_image(src_pixels, src_width, src_height, src_bpp);
|
||||||
|
|
||||||
uint32_t src_bufsize = src_bpp * src_width * src_height;
|
uint32_t src_bufsize = src_bpp * src_width * src_height;
|
||||||
|
|
||||||
uint32_t dst_width = (uint32_t)(src_width * scale);
|
uint32_t dst_width = (uint32_t)(src_width * scale);
|
||||||
|
|||||||
@@ -3,11 +3,6 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "format.h"
|
#include "format.h"
|
||||||
|
|
||||||
#define TEX_FORMAT(x) (x==0) ? FORMAT_A8R8G8B8 :(x==1) ? FORMAT_R5G6B5 : (x==2) ? FORMAT_R4G4B4A4 :(x==3) ? FORMAT_A8L8 :(x==4) ? FORMAT_L8 : FORMAT_A8
|
|
||||||
|
|
||||||
#define CBSIZE(x) (x==FORMAT_A8R8G8B8) ? 4 : (x==FORMAT_R5G6B5) ? 2 : (x==FORMAT_R4G4B4A4) ? 2 : (x==FORMAT_A8L8) ? 2 : 1
|
|
||||||
|
|
||||||
|
|
||||||
struct __attribute__((__packed__)) tga_header_t {
|
struct __attribute__((__packed__)) tga_header_t {
|
||||||
int8_t idlength;
|
int8_t idlength;
|
||||||
int8_t colormaptype;
|
int8_t colormaptype;
|
||||||
@@ -26,8 +21,7 @@ struct __attribute__((__packed__)) tga_header_t {
|
|||||||
int LoadTGA(const char *filename,
|
int LoadTGA(const char *filename,
|
||||||
std::vector<uint8_t> &pixels,
|
std::vector<uint8_t> &pixels,
|
||||||
uint32_t *width,
|
uint32_t *width,
|
||||||
uint32_t *height,
|
uint32_t *height) {
|
||||||
uint32_t *bpp) {
|
|
||||||
std::ifstream ifs(filename, std::ios::in | std::ios::binary);
|
std::ifstream ifs(filename, std::ios::in | std::ios::binary);
|
||||||
if (!ifs.is_open()) {
|
if (!ifs.is_open()) {
|
||||||
std::cerr << "couldn't open file: " << filename << "!" << std::endl;
|
std::cerr << "couldn't open file: " << filename << "!" << std::endl;
|
||||||
@@ -98,7 +92,6 @@ int LoadTGA(const char *filename,
|
|||||||
|
|
||||||
*width = header.width;
|
*width = header.width;
|
||||||
*height = header.height;
|
*height = header.height;
|
||||||
*bpp = 4;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -168,19 +161,19 @@ void dump_image(const std::vector<uint8_t>& pixels, uint32_t width, uint32_t hei
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int CopyBuffers(const SurfaceDesc &dstDesc,
|
int CopyBuffers(SurfaceDesc &dstDesc,
|
||||||
int32_t dstOffsetX,
|
int32_t dstOffsetX,
|
||||||
int32_t dstOffsetY,
|
int32_t dstOffsetY,
|
||||||
int32_t copyWidth,
|
uint32_t copyWidth,
|
||||||
int32_t copyHeight,
|
uint32_t copyHeight,
|
||||||
const SurfaceDesc &srcDesc,
|
const SurfaceDesc &srcDesc,
|
||||||
int32_t srcOffsetX,
|
int32_t srcOffsetX,
|
||||||
int32_t srcOffsetY) {
|
int32_t srcOffsetY) {
|
||||||
|
|
||||||
static const BlitTable s_blitTable;
|
static const BlitTable s_blitTable;
|
||||||
|
|
||||||
if ((srcOffsetX >= srcDesc.Width) || (srcOffsetY >= srcDesc.Height) ||
|
if ((srcOffsetX >= (int32_t)srcDesc.Width) || (srcOffsetY >= (int32_t)srcDesc.Height) ||
|
||||||
(dstOffsetX >= dstDesc.Width) || (dstOffsetY >= dstDesc.Height)) {
|
(dstOffsetX >= (int32_t)dstDesc.Width) || (dstOffsetY >= (int32_t)dstDesc.Height)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,43 +193,25 @@ int CopyBuffers(const SurfaceDesc &dstDesc,
|
|||||||
copyHeight = srcDesc.Height;
|
copyHeight = srcDesc.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
s_blitTable.get(srcDesc.Format, dstDesc.Format)(
|
return s_blitTable.get(srcDesc.Format, dstDesc.Format)(
|
||||||
dstDesc, dstOffsetX, dstOffsetY, copyWidth, copyHeight, srcDesc,
|
dstDesc, dstOffsetX, dstOffsetY, copyWidth, copyHeight, srcDesc,
|
||||||
srcOffsetX, srcOffsetY);
|
srcOffsetX, srcOffsetY);
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConvertImage(std::vector<uint8_t> &dst_pixels,
|
int ConvertImage(std::vector<uint8_t>& dst_pixels,
|
||||||
std::vector<uint8_t>&src_pixels,
|
const std::vector<uint8_t>& src_pixels,
|
||||||
uint32_t *bpp,
|
|
||||||
uint32_t width,
|
uint32_t width,
|
||||||
uint32_t height,
|
uint32_t height,
|
||||||
uint8_t src_format,
|
ePixelFormat src_format,
|
||||||
uint8_t dst_format) {
|
ePixelFormat dst_format) {
|
||||||
|
|
||||||
ePixelFormat SrcFormat = TEX_FORMAT(src_format);
|
uint32_t src_pitch = Format::GetInfo(src_format).BytePerPixel * width;
|
||||||
ePixelFormat DstFormat = TEX_FORMAT(dst_format);
|
uint32_t dst_pitch = Format::GetInfo(dst_format).BytePerPixel * width;
|
||||||
|
|
||||||
*bpp = CBSIZE(DstFormat);
|
dst_pixels.resize(dst_pitch * height);
|
||||||
|
|
||||||
int32_t src_pitch = CBSIZE(SrcFormat) * width;
|
SurfaceDesc srcDesc{src_format, (uint8_t*)src_pixels.data(), width, height, src_pitch};
|
||||||
int32_t dst_pitch = CBSIZE(DstFormat) * width;
|
SurfaceDesc dstDesc{dst_format, dst_pixels.data(), width, height, dst_pitch};
|
||||||
|
|
||||||
const SurfaceDesc srcDesc = {SrcFormat,
|
return CopyBuffers(dstDesc, 0, 0, width, height, srcDesc, 0, 0);
|
||||||
src_pixels.data(),
|
|
||||||
int32_t(width),
|
|
||||||
int32_t(height),
|
|
||||||
src_pitch} ;
|
|
||||||
|
|
||||||
const SurfaceDesc dstDesc = {DstFormat,
|
|
||||||
dst_pixels.data(),
|
|
||||||
int32_t(width),
|
|
||||||
int32_t(height),
|
|
||||||
dst_pitch};
|
|
||||||
|
|
||||||
CopyBuffers(dstDesc, 0, 0, width, height, srcDesc, 0, 0);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,7 @@
|
|||||||
int LoadTGA(const char *filename,
|
int LoadTGA(const char *filename,
|
||||||
std::vector<uint8_t> &pixels,
|
std::vector<uint8_t> &pixels,
|
||||||
uint32_t *width,
|
uint32_t *width,
|
||||||
uint32_t *height,
|
uint32_t *height);
|
||||||
uint32_t *bpp);
|
|
||||||
|
|
||||||
int SaveTGA(const char *filename,
|
int SaveTGA(const char *filename,
|
||||||
const std::vector<uint8_t> &pixels,
|
const std::vector<uint8_t> &pixels,
|
||||||
@@ -15,21 +14,23 @@ int SaveTGA(const char *filename,
|
|||||||
uint32_t height,
|
uint32_t height,
|
||||||
uint32_t bpp);
|
uint32_t bpp);
|
||||||
|
|
||||||
int CopyBuffers(const SurfaceDesc &dstDesc,
|
int CopyBuffers(SurfaceDesc &dstDesc,
|
||||||
int32_t dstOffsetX,
|
int32_t dstOffsetX,
|
||||||
int32_t dstOffsetY,
|
int32_t dstOffsetY,
|
||||||
int32_t copyWidth,
|
uint32_t copyWidth,
|
||||||
int32_t copyHeight,
|
uint32_t copyHeight,
|
||||||
const SurfaceDesc &srcDesc,
|
const SurfaceDesc &srcDesc,
|
||||||
int32_t srcOffsetX,
|
int32_t srcOffsetX,
|
||||||
int32_t srcOffsetY);
|
int32_t srcOffsetY);
|
||||||
|
|
||||||
int ConvertImage(std::vector<uint8_t> &dst_pixels,
|
int ConvertImage(std::vector<uint8_t>& dst_pixels,
|
||||||
std::vector<uint8_t>&src_pixels,
|
const std::vector<uint8_t>& src_pixels,
|
||||||
uint32_t *bpp,
|
|
||||||
uint32_t width,
|
uint32_t width,
|
||||||
uint32_t height,
|
uint32_t height,
|
||||||
uint8_t src_format,
|
ePixelFormat src_format,
|
||||||
uint8_t dst_format);
|
ePixelFormat dst_format);
|
||||||
|
|
||||||
void dump_image(const std::vector<uint8_t>& pixels, uint32_t width, uint32_t height, uint32_t bpp);
|
void dump_image(const std::vector<uint8_t>& pixels,
|
||||||
|
uint32_t width,
|
||||||
|
uint32_t height,
|
||||||
|
uint32_t bpp);
|
||||||
Reference in New Issue
Block a user