minor update
This commit is contained in:
@@ -2,7 +2,7 @@ RISCV_TOOLCHAIN_PATH ?= /opt/riscv-gnu-toolchain
|
||||
VORTEX_DRV_PATH ?= $(realpath ../../../driver)
|
||||
VORTEX_RT_PATH ?= $(wildcard ../../../runtime)
|
||||
|
||||
OPTS ?= -f1
|
||||
OPTS ?= -g1
|
||||
|
||||
VX_CC = $(RISCV_TOOLCHAIN_PATH)/bin/riscv32-unknown-elf-gcc
|
||||
VX_CXX = $(RISCV_TOOLCHAIN_PATH)/bin/riscv32-unknown-elf-g++
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
#include "format.h"
|
||||
//
|
||||
// Copyright (c) Blaise Tine. All rights reserved.
|
||||
//
|
||||
//
|
||||
// Use of this sample source code is subject to the terms of the Microsoft
|
||||
// license agreement under which you licensed this sample source code. If
|
||||
// you did not accept the terms of the license agreement, you are not
|
||||
// authorized to use this sample source code. For the terms of the license,
|
||||
// please see the license agreement between you and Microsoft or, if applicable,
|
||||
// see the LICENSE.RTF on your install media or the root of your tools
|
||||
// installation.
|
||||
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR
|
||||
// INDEMNITIES.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
struct SurfaceDesc {
|
||||
ePixelFormat Format;
|
||||
uint8_t *pBits;
|
||||
uint32_t Width;
|
||||
uint32_t Height;
|
||||
uint32_t Pitch;
|
||||
};
|
||||
#include "surfacedesc.h"
|
||||
|
||||
class BlitTable {
|
||||
public:
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
1313
tests/regression/tex/lupng.c
Normal file
1313
tests/regression/tex/lupng.c
Normal file
File diff suppressed because it is too large
Load Diff
186
tests/regression/tex/lupng.h
Normal file
186
tests/regression/tex/lupng.h
Normal file
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 Jan Solanti
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1600)
|
||||
typedef __int8 int8_t;
|
||||
typedef __int16 int16_t;
|
||||
typedef __int32 int32_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
uint8_t channels;
|
||||
uint8_t depth; /* must be 8 or 16 */
|
||||
size_t dataSize;
|
||||
uint8_t *data;
|
||||
} LuImage;
|
||||
|
||||
typedef size_t (*PngReadProc)(void *outPtr, size_t size, size_t count, void *userPtr);
|
||||
typedef size_t (*PngWriteProc)(const void *inPtr, size_t size, size_t count, void *userPtr);
|
||||
typedef void* (*PngAllocProc)(size_t size, void *userPtr);
|
||||
typedef void (*PngFreeProc)(void *ptr, void *userPtr);
|
||||
typedef void (*PngWarnProc)(void *userPtr, const char *fmt, ...);
|
||||
|
||||
typedef struct {
|
||||
/* loader */
|
||||
PngReadProc readProc;
|
||||
void *readProcUserPtr;
|
||||
int skipSig;
|
||||
|
||||
/* writer */
|
||||
PngWriteProc writeProc;
|
||||
void *writeProcUserPtr;
|
||||
int compressionLevel;
|
||||
|
||||
/* memory allocation */
|
||||
PngAllocProc allocProc;
|
||||
void *allocProcUserPtr;
|
||||
PngFreeProc freeProc;
|
||||
void *freeProcUserPtr;
|
||||
|
||||
/* warnings/error output */
|
||||
PngWarnProc warnProc; /* set to NULL to disable output altogether */
|
||||
void *warnProcUserPtr;
|
||||
|
||||
/* special case: avoid allocating a LuImage when loading or creating
|
||||
* an image, just use this one */
|
||||
LuImage *overrideImage;
|
||||
} LuUserContext;
|
||||
|
||||
/**
|
||||
* Initializes a LuUserContext to use the defaul malloc implementation.
|
||||
*
|
||||
* @param userCtx the LuUserContext to initialize
|
||||
*/
|
||||
void luUserContextInitDefault(LuUserContext *userCtx);
|
||||
|
||||
/**
|
||||
* Creates a new Image object with the specified attributes.
|
||||
* The data store of the Image is allocated but its contents are undefined.
|
||||
* Only 8 and 16 bits deep images with 1-4 channels are supported.
|
||||
*
|
||||
* @param buffer pointer to an existing buffer (which may already contain the
|
||||
* image data), or NULL to internally allocate a new buffer
|
||||
* @param userCtx the user context (with the memory allocator function
|
||||
* pointers to use), or NULL to use the default allocator
|
||||
* (malloc).
|
||||
*/
|
||||
LuImage *luImageCreate(size_t width, size_t height, uint8_t channels, uint8_t depth,
|
||||
uint8_t *buffer, const LuUserContext *usrCtx);
|
||||
|
||||
/**
|
||||
* Releases the memory associated with the given Image object.
|
||||
*
|
||||
* @param userCtx the user context (with the memory deallocator function
|
||||
* pointers to use), or NULL to use the default deallocator
|
||||
* (free). The deallocator should match the ones used for
|
||||
* allocation.
|
||||
*/
|
||||
void luImageRelease(LuImage *img, const LuUserContext *usrCtx);
|
||||
|
||||
/**
|
||||
* Extracts the raw image buffer form a LuImage and releases the
|
||||
* then-orphaned LuImage object. This can be used if you want to use
|
||||
* the image data in your own structures.
|
||||
*
|
||||
* @param userCtx the user context (with the memory deallocator function
|
||||
* pointers to use), or NULL to use the default deallocator
|
||||
* (free). The deallocator should match the ones used for
|
||||
* allocation.
|
||||
*/
|
||||
uint8_t *luImageExtractBufAndRelease(LuImage *img, const LuUserContext *userCtx);
|
||||
|
||||
/**
|
||||
* Decodes a PNG image from a file
|
||||
*
|
||||
* @param filename the file name (optionally with full path) to read from.
|
||||
* @param userCtx the user context (with the memory allocator function
|
||||
* pointers to use), or NULL to use the default allocator
|
||||
* (malloc).
|
||||
*/
|
||||
LuImage *luPngReadFile(const char *filename, LuUserContext *userCtx);
|
||||
|
||||
/**
|
||||
* Decodes a PNG image with the provided read function into a LuImage struct
|
||||
*
|
||||
* @param readProc a function pointer to a user-defined function to use for
|
||||
* reading the PNG data.
|
||||
* @param userPtr an opaque pointer provided as an argument to readProc
|
||||
* @param skipSig don't verify PNG signature - the bytes have already been
|
||||
* removed from the input stream
|
||||
*/
|
||||
LuImage *luPngRead(PngReadProc readProc, void *userPtr, int skipSig);
|
||||
|
||||
/**
|
||||
* Decodes a PNG image with the provided user context into a LuImage struct
|
||||
*
|
||||
* @param userCtx the LuUserContext to use
|
||||
*/
|
||||
LuImage *luPngReadUC(const LuUserContext *userCtx);
|
||||
|
||||
/**
|
||||
* Encodes a LuImage struct to PNG and writes it out to a file.
|
||||
*
|
||||
* @param filename the file name (optionally with full path) to write to.
|
||||
* Existing files will be overwritten!
|
||||
* @param img the LuImage to encode
|
||||
*/
|
||||
int luPngWriteFile(const char *filename, const LuImage *img);
|
||||
|
||||
/**
|
||||
* Encodes a LuImage struct to PNG and writes it out using a user-defined write
|
||||
* function.
|
||||
*
|
||||
* @param writeProc a function pointer to a user-defined function that will be
|
||||
* used for writing the final PNG data.
|
||||
* @param userPtr an opaque pointer provided as an argument to writeProc
|
||||
* @param img the LuImage to encode
|
||||
*/
|
||||
int luPngWrite(PngWriteProc writeProc, void *userPtr, const LuImage *img);
|
||||
|
||||
/**
|
||||
* Encodes a LuImage struct to PNG and writes it out with the provided user
|
||||
* context.
|
||||
*
|
||||
* @param userCtx the LuUserContext to use
|
||||
* @param img the LuImage to encode
|
||||
*/
|
||||
int luPngWriteUC(const LuUserContext *userCtx, const LuImage *img);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
25
tests/regression/tex/surfacedesc.h
Normal file
25
tests/regression/tex/surfacedesc.h
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// Copyright (c) Blaise Tine. All rights reserved.
|
||||
//
|
||||
//
|
||||
// Use of this sample source code is subject to the terms of the Microsoft
|
||||
// license agreement under which you licensed this sample source code. If
|
||||
// you did not accept the terms of the license agreement, you are not
|
||||
// authorized to use this sample source code. For the terms of the license,
|
||||
// please see the license agreement between you and Microsoft or, if applicable,
|
||||
// see the LICENSE.RTF on your install media or the root of your tools
|
||||
// installation.
|
||||
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR
|
||||
// INDEMNITIES.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "format.h"
|
||||
|
||||
struct SurfaceDesc {
|
||||
ePixelFormat Format;
|
||||
uint8_t *pBits;
|
||||
uint32_t Width;
|
||||
uint32_t Height;
|
||||
uint32_t Pitch;
|
||||
};
|
||||
122
tests/regression/tex/tga.cpp
Normal file
122
tests/regression/tex/tga.cpp
Normal file
@@ -0,0 +1,122 @@
|
||||
#include "tga.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "format.h"
|
||||
|
||||
struct __attribute__((__packed__)) tga_header_t {
|
||||
int8_t idlength;
|
||||
int8_t colormaptype;
|
||||
int8_t imagetype;
|
||||
int16_t colormaporigin;
|
||||
int16_t colormaplength;
|
||||
int8_t colormapdepth;
|
||||
int16_t xoffset;
|
||||
int16_t yoffset;
|
||||
int16_t width;
|
||||
int16_t height;
|
||||
int8_t bitsperpixel;
|
||||
int8_t imagedescriptor;
|
||||
};
|
||||
|
||||
int LoadTGA(const char *filename,
|
||||
std::vector<uint8_t> &pixels,
|
||||
uint32_t *width,
|
||||
uint32_t *height,
|
||||
uint32_t *bpp) {
|
||||
std::ifstream ifs(filename, std::ios::in | std::ios::binary);
|
||||
if (!ifs.is_open()) {
|
||||
std::cerr << "couldn't open file: " << filename << "!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tga_header_t header;
|
||||
ifs.read(reinterpret_cast<char *>(&header), sizeof(tga_header_t));
|
||||
if (ifs.fail()) {
|
||||
std::cerr << "invalid TGA file header!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (header.imagetype != 2) {
|
||||
std::cerr << "unsupported TGA encoding format!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ifs.seekg(header.idlength, std::ios::cur); // skip string
|
||||
if (ifs.fail()) {
|
||||
std::cerr << "invalid TGA file!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (header.bitsperpixel) {
|
||||
case 16:
|
||||
case 24:
|
||||
case 32: {
|
||||
// Read pixels data
|
||||
auto stride = header.bitsperpixel / 8;
|
||||
pixels.resize(stride * header.width * header.height);
|
||||
ifs.read((char*)pixels.data(), pixels.size());
|
||||
if (ifs.fail()) {
|
||||
std::cerr << "invalid TGA file!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
*bpp = stride;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
std::cerr << "unsupported TGA bitsperpixel!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*width = header.width;
|
||||
*height = header.height;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SaveTGA(const char *filename,
|
||||
const std::vector<uint8_t> &pixels,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t bpp) {
|
||||
std::ofstream ofs(filename, std::ios::out | std::ios::binary);
|
||||
if (!ofs.is_open()) {
|
||||
std::cerr << "couldn't create file: " << filename << "!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (bpp < 2 || bpp > 4) {
|
||||
std::cerr << "unsupported pixel stride: " << bpp << "!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tga_header_t header;
|
||||
header.idlength = 0;
|
||||
header.colormaptype = 0; // no palette
|
||||
header.imagetype = 2; // color mapped data
|
||||
header.colormaporigin = 0;
|
||||
header.colormaplength = 0;
|
||||
header.colormapdepth = 0;
|
||||
header.xoffset = 0;
|
||||
header.yoffset = 0;
|
||||
header.width = width;
|
||||
header.height = height;
|
||||
header.bitsperpixel = bpp * 8;
|
||||
header.imagedescriptor = 0;
|
||||
|
||||
// write header
|
||||
ofs.write(reinterpret_cast<char *>(&header), sizeof(tga_header_t));
|
||||
|
||||
// write pixel data
|
||||
uint32_t pitch = bpp * width;
|
||||
const uint8_t* pixel_bytes = pixels.data() + (height - 1) * pitch;
|
||||
for (uint32_t y = 0; y < height; ++y) {
|
||||
const uint8_t* pixel_row = pixel_bytes;
|
||||
for (uint32_t x = 0; x < width; ++x) {
|
||||
ofs.write((const char*)pixel_row, bpp);
|
||||
pixel_row += bpp;
|
||||
}
|
||||
pixel_bytes -= pitch;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
14
tests/regression/tex/tga.h
Normal file
14
tests/regression/tex/tga.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
int LoadTGA(const char *filename,
|
||||
std::vector<uint8_t> &pixels,
|
||||
uint32_t *width,
|
||||
uint32_t *height,
|
||||
uint32_t *bpp);
|
||||
|
||||
int SaveTGA(const char *filename,
|
||||
const std::vector<uint8_t> &pixels,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t bpp);
|
||||
Reference in New Issue
Block a user