Project

General

Profile

« Previous | Next » 

Revision 8fb99bf0

Added by David Sorber about 8 years ago

WIP for libpackjpg reorganization: moved all global variables to be
instance variables and converted a couple of trivial functions.

View differences:

software/packJPG_library/lib_src/packjpg.cpp
inline float median_float(float* values, int size);
/* -----------------------------------------------
function declarations: miscelaneous helpers
----------------------------------------------- */
inline bool file_exists(const char* filename);
/* -----------------------------------------------
function declarations: developers functions
......
/* -----------------------------------------------
global variables: info about image
----------------------------------------------- */
// seperate info for each color component
componentInfo cmpnfo[ 4 ];
int cmpc = 0; // component count
int imgwidth = 0; // width of image
int imgheight = 0; // height of image
int sfhm = 0; // max horizontal sample factor
int sfvm = 0; // max verical sample factor
int mcuv = 0; // mcus per line
int mcuh = 0; // mcus per collumn
int mcuc = 0; // count of mcus
/* -----------------------------------------------
global variables: info about current scan
----------------------------------------------- */
int cs_cmpc = 0 ; // component count in current scan
int cs_cmp[ 4 ] = { 0 }; // component numbers in current scan
int cs_from = 0 ; // begin - band of current scan ( inclusive )
int cs_to = 0 ; // end - band of current scan ( inclusive )
int cs_sah = 0 ; // successive approximation bit pos high
int cs_sal = 0 ; // successive approximation bit pos low
/* -----------------------------------------------
global variables: info about files
----------------------------------------------- */
char* jpgfilename = NULL; // name of JPEG file
char* pjgfilename = NULL; // name of PJG file
int jpgfilesize; // size of JPEG file
int pjgfilesize; // size of PJG file
int jpegtype = 0; // type of JPEG coding: 0->unknown, 1->sequential, 2->progressive
int filetype; // type of current file
std::unique_ptr<Reader> str_in; // input stream
std::unique_ptr<Writer> str_out; // output stream
#if defined(DEV_INFOS)
int dev_size_hdr = 0;
int dev_size_cmp[ 4 ] = { 0 };
......
#endif
/* -----------------------------------------------
global variables: messages
----------------------------------------------- */
char errormessage [ MSG_SIZE ];
bool (*errorfunction)();
int errorlevel;
// meaning of errorlevel:
// -1 -> wrong input
// 0 -> no error
// 1 -> warning
// 2 -> fatal error
/* -----------------------------------------------
global variables: settings
----------------------------------------------- */
int err_tol = 1; // error threshold ( proceed on warnings yes (2) / no (1) )
bool disc_meta = false; // discard meta-info yes / no
bool auto_set = true; // automatic find best settings yes/no
int action = A_COMPRESS;// what to do with JPEG/PJG files
unsigned char nois_trs[ 4 ] = {6,6,6,6}; // bit pattern noise threshold
unsigned char segm_cnt[ 4 ] = {10,10,10,10}; // number of segments
/* -----------------------------------------------
global variables: info about program
----------------------------------------------- */
const unsigned char appversion = 25;
const char* subversion = "k";
const char* apptitle = "packJPG";
const char* appname = "packjpg";
const char* versiondate = "01/22/2016";
const char* author = "Matthias Stirner / Se";
const char pjg_magic[] = { 'J', 'S' };
// Initialize static members
const unsigned char packJPG::appversion = 25;
const char* packJPG::subversion = "k";
const char* packJPG::apptitle = "packJPG";
const char* packJPG::appname = "packjpg";
const char* packJPG::versiondate = "01/22/2016";
const char* packJPG::author = "Matthias Stirner / Se";
const char packJPG::pjg_magic[] = { 'J', 'S' };
packJPG::packJPG()
: lib_in_type(-1),
: lib_in_type(-1),
lib_out_type(-1),
grbgdata(nullptr),
hdrdata(nullptr),
......
padbit(-1),
rst_err(nullptr),
zdstdata(),
eobxhigh(),
eobyhigh(),
zdstxlow(),
zdstylow(),
colldata(),
freqscan(),
zsrtscan()
eobxhigh(),
eobyhigh(),
zdstxlow(),
zdstylow(),
colldata(),
freqscan(),
zsrtscan(),
adpt_idct_8x8(),
adpt_idct_1x8(),
adpt_idct_8x1(),
cmpnfo(),
cmpc(0),
imgwidth(0),
imgheight(0),
sfhm(0),
sfvm(0),
mcuv(0),
mcuh(0),
mcuc(0),
cs_cmpc(0),
cs_cmp(),
cs_from(0),
cs_to(0),
cs_sah(0),
cs_sal(0),
jpgfilename(nullptr),
pjgfilename(nullptr),
jpgfilesize(0),
pjgfilesize(0),
jpegtype(0),
filetype(0),
//~ str_in, // input stream
//~ str_out, // output stream
errormessage(),
errorfunction(nullptr),
errorlevel(0),
err_tol(1),
disc_meta(false),
auto_set(true),
action(A_COMPRESS),
nois_trs{6, 6, 6, 6},
segm_cnt{10, 10, 10, 10}
{
}
......
{
}
const char* packJPG::pjglib_version_info(void)
{
static char v_info[256];
// copy version info to string
sprintf(v_info, "--> %s library v%i.%i%s (%s) by %s <--",
apptitle, appversion / 10, appversion % 10, subversion,
versiondate, author);
return (const char*) v_info;
}
const char* packJPG::pjglib_short_name(void)
{
static char v_name[256];
// copy version info to string
sprintf(v_name, "%s v%i.%i%s",
apptitle, appversion / 10, appversion % 10, subversion);
return (const char*) v_name;
}
#if 0
......
}
/* -----------------------------------------------
DLL export version information
----------------------------------------------- */
const char* pjglib_version_info(void)
{
static char v_info[ 256 ];
// copy version info to string
sprintf(v_info, "--> %s library v%i.%i%s (%s) by %s <--",
apptitle, appversion / 10, appversion % 10, subversion, versiondate, author);
return (const char*) v_info;
}
/* -----------------------------------------------
DLL export version information
----------------------------------------------- */
const char* pjglib_short_name(void)
{
static char v_name[ 256 ];
// copy version info to string
sprintf(v_name, "%s v%i.%i%s",
apptitle, appversion / 10, appversion % 10, subversion);
return (const char*) v_name;
}
/* ----------------------- End of libary only functions -------------------------- */
/* ----------------------- Begin of main interface functions -------------------------- */
......
adds underscore after filename
----------------------------------------------- */
/* -----------------------------------------------
checks if a file exists
----------------------------------------------- */
inline bool file_exists(const char* filename)
{
// needed for both, executable and library
FILE* fp = fopen(filename, "rb");
if (fp == NULL)
{
return false;
}
else
{
fclose(fp);
return true;
}
}
/* ----------------------- End of miscellaneous helper functions -------------------------- */
/* ----------------------- Begin of developers functions -------------------------- */
software/packJPG_library/lib_src/packjpg.h
~packJPG();
static const char* pjglib_version_info(void);
static const char* pjglib_short_name(void);
/* -----------------------------------------------
checks if a file exists
----------------------------------------------- */
inline bool file_exists(const char* filename)
{
// needed for both, executable and library
FILE* fp = fopen(filename, "rb");
if (fp == NULL)
{
return false;
}
else
{
fclose(fp);
return true;
}
}
private:
/* -----------------------------------------------
......
/* -----------------------------------------------
global variables: data storage
----------------------------------------------- */
unsigned short qtables[4][64]; // quantization tables
huffCodes hcodes[2][4]; // huffman codes
huffTree htrees[2][4]; // huffman decoding trees
unsigned char htset[2][4]; // 1 if huffman table is set
unsigned short qtables[4][64]; // quantization tables
huffCodes hcodes[2][4]; // huffman codes
huffTree htrees[2][4]; // huffman decoding trees
unsigned char htset[2][4]; // 1 if huffman table is set
unsigned char* grbgdata; // garbage data
unsigned char* hdrdata ; // header data
......
int adpt_idct_8x8[4][8 * 8 * 8 * 8]; // precalculated/adapted values for idct (8x8)
int adpt_idct_1x8[4][1 * 1 * 8 * 8]; // precalculated/adapted values for idct (1x8)
int adpt_idct_8x1[4][8 * 8 * 1 * 1]; // precalculated/adapted values for idct (8x1)
/* -----------------------------------------------
global variables: info about image
----------------------------------------------- */
componentInfo cmpnfo[4]; // seperate info for each color component
int cmpc; // component count
int imgwidth; // width of image
int imgheight; // height of image
int sfhm; // max horizontal sample factor
int sfvm; // max verical sample factor
int mcuv; // mcus per line
int mcuh; // mcus per collumn
int mcuc; // count of mcus
/* -----------------------------------------------
global variables: info about current scan
----------------------------------------------- */
int cs_cmpc; // component count in current scan
int cs_cmp[4]; // component numbers in current scan
int cs_from; // begin - band of current scan ( inclusive )
int cs_to; // end - band of current scan ( inclusive )
int cs_sah; // successive approximation bit pos high
int cs_sal; // successive approximation bit pos low
/* -----------------------------------------------
global variables: info about files
----------------------------------------------- */
char* jpgfilename; // name of JPEG file
char* pjgfilename; // name of PJG file
int jpgfilesize; // size of JPEG file
int pjgfilesize; // size of PJG file
int jpegtype; // type of JPEG coding: 0->unknown, 1->sequential, 2->progressive
int filetype; // type of current file
std::unique_ptr<Reader> str_in; // input stream
std::unique_ptr<Writer> str_out; // output stream
/* -----------------------------------------------
global variables: messages
----------------------------------------------- */
char errormessage[MSG_SIZE];
bool (*errorfunction)();
// meaning of errorlevel:
// -1 -> wrong input
// 0 -> no error
// 1 -> warning
// 2 -> fatal error
int errorlevel;
/* -----------------------------------------------
global variables: settings
----------------------------------------------- */
int err_tol; // error threshold ( proceed on warnings yes (2) / no (1) )
bool disc_meta; // discard meta-info yes / no
bool auto_set; // automatic find best settings yes/no
int action; // what to do with JPEG/PJG files
unsigned char nois_trs[4]; // bit pattern noise threshold
unsigned char segm_cnt[4]; // number of segments
/* -----------------------------------------------
global variables: info about program
----------------------------------------------- */
static const unsigned char appversion;
static const char* subversion;
static const char* apptitle;
static const char* appname;
static const char* versiondate;
static const char* author;
static const char pjg_magic[2];
};

Also available in: Unified diff