Skip to content

Commit

Permalink
Create build.yml, CMakeLists and fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
KaperD authored and Danil Bubnov committed Jan 29, 2024
1 parent 14a64d9 commit ca2ed1b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 34 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
on: [ push, pull_request ]
name: Build
jobs:
build:
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Build
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --config Release
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: etcpack-${{ matrix.os }}
path: build
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.25)
project(etcpack)

set(CMAKE_CXX_STANDARD 20)

add_executable(etcpack source/image.cxx source/etcpack.cxx source/etcdec.cxx)
33 changes: 11 additions & 22 deletions source/etcpack.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,14 @@ void setupAlphaTable();
#define TABLE_BITS_58H 3

// Global tables
static uint8 table59T[8] = {3,6,11,16,23,32,41,64}; // 3-bit table for the 59 bit T-mode
static uint8 table58H[8] = {3,6,11,16,23,32,41,64}; // 3-bit table for the 58 bit H-mode
constexpr uint8 table59T[8] = {3,6,11,16,23,32,41,64}; // 3-bit table for the 59 bit T-mode
constexpr uint8 table58H[8] = {3,6,11,16,23,32,41,64}; // 3-bit table for the 58 bit H-mode
uint8 weight[3] = {1,1,1}; // Color weight

// Enums
static enum{PATTERN_H = 0,
PATTERN_T = 1};
constexpr uint8 PATTERN_H = 0, PATTERN_T = 1;

static enum{MODE_ETC1, MODE_THUMB_T, MODE_THUMB_H, MODE_PLANAR};
constexpr int MODE_ETC1 = 0, MODE_THUMB_T = 1, MODE_THUMB_H = 2, MODE_PLANAR = 3;
// The ETC2 package of codecs includes the following codecs:
//
// codec enum
Expand Down Expand Up @@ -202,11 +201,11 @@ static enum{MODE_ETC1, MODE_THUMB_T, MODE_THUMB_H, MODE_PLANAR};
// (GL_COMPRESSED_R11_EAC) and signed (GL_COMPRESSED_SIGNED_R11_EAC) version of
// the codec.
//
static enum{ETC1_RGB_NO_MIPMAPS,ETC2PACKAGE_RGB_NO_MIPMAPS,ETC2PACKAGE_RGBA_NO_MIPMAPS_OLD,ETC2PACKAGE_RGBA_NO_MIPMAPS,ETC2PACKAGE_RGBA1_NO_MIPMAPS,ETC2PACKAGE_R_NO_MIPMAPS,ETC2PACKAGE_RG_NO_MIPMAPS,ETC2PACKAGE_R_SIGNED_NO_MIPMAPS,ETC2PACKAGE_RG_SIGNED_NO_MIPMAPS,ETC2PACKAGE_sRGB_NO_MIPMAPS,ETC2PACKAGE_sRGBA_NO_MIPMAPS,ETC2PACKAGE_sRGBA1_NO_MIPMAPS};
static enum {MODE_COMPRESS, MODE_UNCOMPRESS, MODE_PSNR};
static enum {SPEED_SLOW, SPEED_FAST, SPEED_MEDIUM};
static enum {METRIC_PERCEPTUAL, METRIC_NONPERCEPTUAL};
static enum {CODEC_ETC, CODEC_ETC2};
constexpr short ETC1_RGB_NO_MIPMAPS = 0, ETC2PACKAGE_RGB_NO_MIPMAPS = 1, ETC2PACKAGE_RGBA_NO_MIPMAPS_OLD = 2,ETC2PACKAGE_RGBA_NO_MIPMAPS = 3,ETC2PACKAGE_RGBA1_NO_MIPMAPS = 4,ETC2PACKAGE_R_NO_MIPMAPS = 5,ETC2PACKAGE_RG_NO_MIPMAPS = 6,ETC2PACKAGE_R_SIGNED_NO_MIPMAPS = 7,ETC2PACKAGE_RG_SIGNED_NO_MIPMAPS = 8,ETC2PACKAGE_sRGB_NO_MIPMAPS = 9,ETC2PACKAGE_sRGBA_NO_MIPMAPS = 10,ETC2PACKAGE_sRGBA1_NO_MIPMAPS = 11;
constexpr int MODE_COMPRESS = 0, MODE_UNCOMPRESS = 1, MODE_PSNR = 2;
constexpr int SPEED_SLOW = 0, SPEED_FAST = 1, SPEED_MEDIUM = 2;
constexpr int METRIC_PERCEPTUAL = 0, METRIC_NONPERCEPTUAL = 1;
constexpr int CODEC_ETC = 0, CODEC_ETC2 = 1;

int mode = MODE_COMPRESS;
int speed = SPEED_FAST;
Expand Down Expand Up @@ -244,7 +243,7 @@ KTX_header;
#define KTX_ENDIAN_REF (0x04030201)
#define KTX_ENDIAN_REF_REV (0x01020304)

static enum {GL_R=0x1903,GL_RG=0x8227,GL_RGB=0x1907,GL_RGBA=0x1908};
static int GL_R=0x1903,GL_RG=0x8227,GL_RGB=0x1907,GL_RGBA=0x1908;
#define GL_SRGB 0x8C40
#define GL_SRGB8 0x8C41
#define GL_SRGB8_ALPHA8 0x8C43
Expand Down Expand Up @@ -298,7 +297,7 @@ int indexConversion(int pixelIndices)

// Tests if a file exists.
// NO WARRANTY --- SEE STATEMENT IN TOP OF FILE (C) Ericsson AB 2005-2013. All Rights Reserved.
bool fileExist(char *filename)
bool fileExist(const char *filename)
{
FILE *f=NULL;
if((f=fopen(filename,"rb"))!=NULL)
Expand Down Expand Up @@ -15882,9 +15881,6 @@ void compressFile(char *srcfile,char *dstfile)
uint8 *srcimg;
int width,height;
int extendedwidth, extendedheight;
struct _timeb tstruct;
int tstart;
int tstop;
// 0: compress from .any to .pkm with SPEED_FAST, METRIC_NONPERCEPTUAL, ETC
// 1: compress from .any to .pkm with SPEED_MEDIUM, METRIC_NONPERCEPTUAL, ETC
// 2: compress from .any to .pkm with SPEED_SLOW, METRIC_NONPERCEPTUAL, ETC
Expand Down Expand Up @@ -15959,14 +15955,7 @@ void compressFile(char *srcfile,char *dstfile)
}
printf("Compressing...\n");

tstart=time(NULL);
_ftime( &tstruct );
tstart=tstart*1000+tstruct.millitm;
compressImageFile(srcimg,alphaimg,width,height,dstfile,extendedwidth, extendedheight);
tstop = time(NULL);
_ftime( &tstruct );
tstop = tstop*1000+tstruct.millitm;
printf( "It took %u milliseconds to compress:\n", tstop - tstart);
calculatePSNRfile(dstfile,srcimg,alphaimg);
}
}
Expand Down
10 changes: 5 additions & 5 deletions source/image.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void removeSpaces(FILE *f1)
// after that follows RGBRGBRGB...
//
// NO WARRANTY --- SEE STATEMENT IN TOP OF FILE (C) Ericsson AB 2005-2013. All Rights Reserved.
bool fReadPPM(char *filename, int &width, int &height, unsigned char *&pixels, int targetbitrate)
bool fReadPPM(const char *filename, int &width, int &height, unsigned char *&pixels, int targetbitrate)
{
FILE *f1;
int maximum;
Expand Down Expand Up @@ -226,7 +226,7 @@ bool fReadPPM(char *filename, int &width, int &height, unsigned char *&pixels, i

// Write PPM
// NO WARRANTY --- SEE STATEMENT IN TOP OF FILE (C) Ericsson AB 2005-2013. All Rights Reserved.
bool fWritePPM(char *filename, int width, int height, unsigned char *pixels, int bitrate, bool reverse_y)
bool fWritePPM(const char *filename, int width, int height, unsigned char *pixels, int bitrate, bool reverse_y)
{
FILE *fsave;
fsave = fopen(filename, "wb");
Expand Down Expand Up @@ -257,7 +257,7 @@ bool fWritePPM(char *filename, int width, int height, unsigned char *pixels, int

// WritePGM
// NO WARRANTY --- SEE STATEMENT IN TOP OF FILE (C) Ericsson AB 2005-2013. All Rights Reserved.
bool fWritePGM(char *filename, int width, int height, unsigned char *pixels,bool reverse_y, int bitdepth)
bool fWritePGM(const char *filename, int width, int height, unsigned char *pixels,bool reverse_y, int bitdepth)
{
FILE *f;
f=fopen(filename,"wb");
Expand Down Expand Up @@ -296,7 +296,7 @@ bool fWritePGM(char *filename, int width, int height, unsigned char *pixels,bool
* then follows RGBRGBRGBRGBRGB...
*/
// NO WARRANTY --- SEE STATEMENT IN TOP OF FILE (C) Ericsson AB 2005-2013. All Rights Reserved.
int fReadPGM(char *filename, int &width, int &height, unsigned char *&pixels, int wantedBitDepth)
int fReadPGM(const char *filename, int &width, int &height, unsigned char *&pixels, int wantedBitDepth)
{
FILE *f;
int colres;
Expand Down Expand Up @@ -396,7 +396,7 @@ int fReadPGM(char *filename, int &width, int &height, unsigned char *&pixels, in
/* writes a .tga file from two arrays --- one RGB array and one alpha-array */
/* */
// NO WARRANTY --- SEE STATEMENT IN TOP OF FILE (C) Ericsson AB 2012. All Rights Reserved.
bool fWriteTGAfromRGBandA(char *filename, int width, int height, unsigned char *pixelsRGB, unsigned char *pixelsA, bool reverse_y)
bool fWriteTGAfromRGBandA(const char *filename, int width, int height, unsigned char *pixelsRGB, unsigned char *pixelsA, bool reverse_y)
{
FILE *f1;

Expand Down
14 changes: 7 additions & 7 deletions source/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@
#ifndef IMAGE_H
#define IMAGE_H

bool fReadPPM(char *filename, int &width, int &height, unsigned char *&pixels, int targetbitrate);
bool fWritePPM(char *filename, int width, int height, unsigned char *pixels, int bitrate, bool reverse_y);
bool fReadPPM(const char *filename, int &width, int &height, unsigned char *&pixels, int targetbitrate);
bool fWritePPM(const char *filename, int width, int height, unsigned char *pixels, int bitrate, bool reverse_y);

bool fReadPFM(char *filename, int &width, int &height, float *&pixels);
bool fWritePFM(char *filename, int width, int height, float *pixels,bool reverse_y);
bool fReadPFM(const char *filename, int &width, int &height, float *&pixels);
bool fWritePFM(const char *filename, int width, int height, float *pixels,bool reverse_y);
// write a grey scale image
bool fWritePGM(char *filename, int width, int height, unsigned char *pixels,bool reverse_y, int bitdepth);
int fReadPGM(char *filename, int &width, int &height, unsigned char *&pixels, int wantedBitDepth);
bool fWritePGM(const char *filename, int width, int height, unsigned char *pixels,bool reverse_y, int bitdepth);
int fReadPGM(const char *filename, int &width, int &height, unsigned char *&pixels, int wantedBitDepth);
// write a TGA image with both RGB and alpha
bool fWriteTGAfromRGBandA(char *filename, int width, int height, unsigned char *pixelsRGB, unsigned char *pixelsA, bool reverse_y);
bool fWriteTGAfromRGBandA(const char *filename, int width, int height, unsigned char *pixelsRGB, unsigned char *pixelsA, bool reverse_y);

#endif

Expand Down

0 comments on commit ca2ed1b

Please sign in to comment.