Initial checkin of v1.04 - KTX file format support, basic ETC1 compression/decompression, Linux makefile with proper gcc options, lots of high-level improvements to get crnlib into a state where I can more easily add additional formats.
This commit is contained in:
+64
-12
@@ -2,6 +2,7 @@
|
||||
// See Copyright Notice and license at the end of inc/crnlib.h
|
||||
#pragma once
|
||||
#include "crn_image.h"
|
||||
#include "crn_data_stream_serializer.h"
|
||||
|
||||
namespace crnlib
|
||||
{
|
||||
@@ -9,23 +10,41 @@ namespace crnlib
|
||||
|
||||
namespace image_utils
|
||||
{
|
||||
bool load_from_file_stb(const char* pFilename, image_u8& img);
|
||||
enum read_flags_t
|
||||
{
|
||||
cReadFlagForceSTB = 1,
|
||||
|
||||
cReadFlagsAllFlags = 1
|
||||
};
|
||||
|
||||
bool read_from_stream_stb(data_stream_serializer& serializer, image_u8& img);
|
||||
bool read_from_stream_jpgd(data_stream_serializer& serializer, image_u8& img);
|
||||
bool read_from_stream(image_u8& dest, data_stream_serializer& serializer, uint read_flags = 0);
|
||||
bool read_from_file(image_u8& dest, const char* pFilename, uint read_flags = 0);
|
||||
|
||||
// Reads texture from memory, results returned stb_image.c style.
|
||||
// *pActual_comps is set to 1, 3, or 4. req_comps must range from 1-4.
|
||||
uint8* read_from_memory(const uint8* pImage, int nSize, int* pWidth, int* pHeight, int* pActualComps, int req_comps, const char* pFilename);
|
||||
|
||||
enum
|
||||
{
|
||||
cSaveIgnoreAlpha = 1,
|
||||
cSaveGrayscale = 2
|
||||
cWriteFlagIgnoreAlpha = 0x00000001,
|
||||
cWriteFlagGrayscale = 0x00000002,
|
||||
|
||||
cWriteFlagJPEGH1V1 = 0x00010000,
|
||||
cWriteFlagJPEGH2V1 = 0x00020000,
|
||||
cWriteFlagJPEGH2V2 = 0x00040000,
|
||||
cWriteFlagJPEGTwoPass = 0x00080000,
|
||||
cWriteFlagJPEGNoChromaDiscrim = 0x00100000,
|
||||
cWriteFlagJPEGQualityLevelMask = 0xFF000000,
|
||||
cWriteFlagJPEGQualityLevelShift = 24,
|
||||
};
|
||||
|
||||
const int cSaveLuma = -1;
|
||||
const int cLumaComponentIndex = -1;
|
||||
|
||||
bool save_to_file_stb(const char* pFilename, const image_u8& img, uint save_flags = 0, int comp_index = cSaveLuma);
|
||||
inline uint create_jpeg_write_flags(uint base_flags, uint quality_level) { CRNLIB_ASSERT(quality_level <= 100); return base_flags | ((quality_level << cWriteFlagJPEGQualityLevelShift) & cWriteFlagJPEGQualityLevelMask); }
|
||||
|
||||
bool load_from_file(image_u8& dest, const char* pFilename, int flags = 0);
|
||||
|
||||
bool save_to_grayscale_file(const char* pFilename, const image_u8& src, int component, int flags = 0);
|
||||
|
||||
bool save_to_file(const char* pFilename, const image_u8& src, int flags = 0, bool ignore_alpha = false);
|
||||
bool write_to_file(const char* pFilename, const image_u8& img, uint write_flags = 0, int grayscale_comp_index = cLumaComponentIndex);
|
||||
|
||||
bool has_alpha(const image_u8& img);
|
||||
bool is_normal_map(const image_u8& img, const char* pFilename = NULL);
|
||||
@@ -127,15 +146,48 @@ namespace crnlib
|
||||
cConversion_A_To_RGBA,
|
||||
cConversion_Y_To_RGB,
|
||||
|
||||
cConversion_To_Y,
|
||||
|
||||
cConversionTotal
|
||||
};
|
||||
|
||||
void convert_image(image_u8& img, conversion_type conv_type);
|
||||
|
||||
template<typename image_type>
|
||||
inline uint8* pack_image(const image_type& img, const pixel_packer& packer, uint& n)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
if (!packer.is_valid())
|
||||
return NULL;
|
||||
|
||||
const uint width = img.get_width(), height = img.get_height();
|
||||
uint dst_pixel_stride = packer.get_pixel_stride();
|
||||
uint dst_pitch = width * dst_pixel_stride;
|
||||
|
||||
n = dst_pitch * height;
|
||||
|
||||
uint8* pImage = static_cast<uint8*>(crnlib_malloc(n));
|
||||
|
||||
uint8* pDst = pImage;
|
||||
for (uint y = 0; y < height; y++)
|
||||
{
|
||||
const typename image_type::color_t* pSrc = img.get_scanline(y);
|
||||
for (uint x = 0; x < width; x++)
|
||||
pDst = (uint8*)packer.pack(*pSrc++, pDst);
|
||||
}
|
||||
|
||||
return pImage;
|
||||
}
|
||||
|
||||
image_utils::conversion_type get_conversion_type(bool cooking, pixel_format fmt);
|
||||
|
||||
image_utils::conversion_type get_image_conversion_type_from_crn_format(crn_format fmt);
|
||||
|
||||
double compute_std_dev(uint n, const color_quad_u8* pPixels, uint first_channel, uint num_channels);
|
||||
}
|
||||
}
|
||||
|
||||
uint8* read_image_from_memory(const uint8* pImage, int nSize, int* pWidth, int* pHeight, int* pActualComps, int req_comps, const char* pFilename);
|
||||
|
||||
} // namespace image_utils
|
||||
|
||||
} // namespace crnlib
|
||||
|
||||
Reference in New Issue
Block a user