28 #include "../../../idlib/precompiled.h"
186 stream->
Write( &a, 1 );
187 stream->
Write( &b, 1 );
195 b = (*aWord >> 8) & 0xff;
196 c = (*aWord >> 16) & 0xff;
197 d = (*aWord >> 24) & 0xff;
199 stream->
Write( &a, 1 );
200 stream->
Write( &b, 1 );
201 stream->
Write( &c, 1 );
202 stream->
Write( &d, 1 );
280 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
282 if (write_all_tables)
287 (*cinfo->
dest->init_destination) (cinfo);
291 (*cinfo->
master->prepare_for_pass) (cinfo);
319 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
321 WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
324 if (cinfo->progress !=
NULL) {
326 cinfo->progress->pass_limit = (
long) cinfo->
image_height;
327 (*cinfo->progress->progress_monitor) ((
j_common_ptr) cinfo);
336 (*cinfo->
master->pass_startup) (cinfo);
340 if (num_lines > rows_left)
341 num_lines = rows_left;
344 (*cinfo->
main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
363 hackSize = datacount;
485 row_stride =
image->pixelsWide() * 4;
503 common->
Printf(
"writeLossless: writing %d bytes to RoQ_QUAD_JPEG\n", hackSize);
523 static int finit = 0;
531 common->
Error(
"Unable to open output file %s.\n", RoQFilename);
562 common->
Printf(
"initRoQPatterns: outputting %d bytes to RoQ_INFO\n", j);
563 direct =
image->hasAlpha();
568 direct =
image->pixelsWide();
570 direct =
image->pixelsHigh();
588 common->
Printf(
"*******************************************************************\n");
614 common->
Printf(
"writeCodeBook: outputting %d bytes to RoQ_QUAD_CODEBOOK\n", j);
624 memcpy(
codes, codebook, 4096 );
630 int onCCC, onAction,
i, code;
634 int dx,dy,dxMean,dyMean,index2[256],index4[256], dimension;
637 use2 = (
bool *)
Mem_Alloc(256*
sizeof(
bool));
638 use4 = (
bool *)
Mem_Alloc(256*
sizeof(
bool));
652 if (
image->hasAlpha()) dimension = 10;
else dimension = 6;
655 if ( pquad[i].
size && pquad[i].
size < 16 ) {
656 switch( pquad[i].status ) {
658 use4[pquad[
i].
patten[0]] =
true;
659 use2[
codes[dimension*256+(pquad[
i].
patten[0]*4)+0]] =
true;
660 use2[
codes[dimension*256+(pquad[
i].
patten[0]*4)+1]] =
true;
661 use2[
codes[dimension*256+(pquad[
i].
patten[0]*4)+2]] =
true;
662 use2[
codes[dimension*256+(pquad[
i].
patten[0]*4)+3]] =
true;
665 use4[pquad[
i].
patten[0]] =
true;
666 use2[
codes[dimension*256+(pquad[
i].
patten[0]*4)+0]] =
true;
667 use2[
codes[dimension*256+(pquad[
i].
patten[0]*4)+1]] =
true;
668 use2[
codes[dimension*256+(pquad[
i].
patten[0]*4)+2]] =
true;
669 use2[
codes[dimension*256+(pquad[
i].
patten[0]*4)+3]] =
true;
672 use2[pquad[
i].
patten[1]] =
true;
673 use2[pquad[
i].
patten[2]] =
true;
674 use2[pquad[
i].
patten[3]] =
true;
675 use2[pquad[
i].
patten[4]] =
true;
683 if (
image->hasAlpha()) i = 3584;
else i = 2560;
694 for(dx=0;dx<dimension;dx++) cccList[j*dimension+dx] =
codes[i*dimension+dx];
700 common->
Printf(
"writeFrame: really used %d 2x2 cels\n", j);
705 for(dx=0;dx<4;dx++) cccList[j*4+code+dx] = index2[
codes[i*4+(dimension*256)+dx]];
710 direct = (direct<<8) + j;
711 common->
Printf(
"writeFrame: really used %d 4x4 cels\n", j);
712 if (
image->hasAlpha()) i = 3584;
else i = 2560;
713 if ( code == i || j == 256) {
724 if ( pquad[i].
size && pquad[i].
size < 16 ) {
726 switch( pquad[i].status ) {
732 cccList[onCCC++] = index4[pquad[
i].
patten[0]];
739 dx = ((pquad[
i].
domain >> 8 )) - 128 - dxMean + 8;
740 dy = ((pquad[
i].
domain & 0xff)) - 128 - dyMean + 8;
741 if (dx>15 || dx<0 || dy>15 || dy<0 ) {
742 common->
Error(
"writeFrame: FCC error %d,%d mean %d,%d at %d,%d,%d rmse %f\n", dx,dy, dxMean, dyMean,pquad[i].xat,pquad[i].yat,pquad[i].
size, pquad[i].snr[
FCC] );
744 cccList[onCCC++] = (dx<<4)+dy;
748 cccList[onCCC++] = index4[pquad[
i].
patten[0]];
752 cccList[onCCC++] = index2[pquad[
i].
patten[1]];
753 cccList[onCCC++] = index2[pquad[
i].
patten[2]];
754 cccList[onCCC++] = index2[pquad[
i].
patten[3]];
755 cccList[onCCC++] = index2[pquad[
i].
patten[4]];
762 common->
Error(
"writeFrame: an error occurred writing the frame\n");
765 action = (action<<2)|code;
769 cccList[onAction+0] = (action & 0xff);
770 cccList[onAction+1] = ((action >> 8) & 0xff);
778 action <<= ((8-
j)*2);
779 cccList[onAction+0] = (action & 0xff);
780 cccList[onAction+1] = ((action >> 8) & 0xff);
792 direct += (dxMean<<8);
796 common->
Printf(
"writeFrame: outputting %d bytes to RoQ_QUAD_VQ\n", j);
845 if ( args.
Argc() != 2 ) {
853 common->
Printf(
"total encoding time: %i second\n", ( stopMsec - startMsec ) / 1000 );
void SetPreviousImage(const char *filename, NSBitmapImageRep *timage)
void InitRoQFile(const char *roqFilename)
struct jpeg_common_struct * j_common_ptr
void Write32Word(unsigned int *aWord, idFile *stream)
int Sys_Milliseconds(void)
idFileSystem * fileSystem
void WriteCodeBookToStream(byte *codebook, int csize, word cflags)
void JPEGDest(j_compress_ptr cinfo, byte *outfile, int size)
GLenum GLsizei GLenum GLenum const GLvoid * image
GLOBAL void jpeg_suppress_tables(j_compress_ptr cinfo, boolean suppress)
void WriteCodeBook(byte *codebook)
static void JPEGInitDestination(j_compress_ptr cinfo)
void InitRoQPatterns(void)
void JPEGStartCompress(j_compress_ptr cinfo, bool write_all_tables)
void LoadAndDisplayImage(const char *filename)
boolean call_pass_startup
J_COLOR_SPACE in_color_space
GLOBAL void jinit_compress_master(j_compress_ptr cinfo)
void RoQFileEncode_f(const idCmdArgs &args)
struct jpeg_destination_mgr pub
JDIMENSION JPEGWriteScanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION num_lines)
static void JPEGTermDestination(j_compress_ptr cinfo)
static boolean JPEGEmptyOutputBuffer(j_compress_ptr cinfo)
const char * CurrentFilename(void)
GLOBAL void jpeg_finish_compress(j_compress_ptr cinfo)
void InitFromFile(const char *fileName)
struct jpeg_destination_mgr * dest
virtual idFile * OpenFileWrite(const char *relativePath, const char *basePath="fs_savepath")=0
const char * GetNextImageFilename(void)
struct jpeg_c_main_controller * main
#define WARNMS(cinfo, code)
#define RoQ_QUAD_CODEBOOK
GLOBAL void jpeg_set_quality(j_compress_ptr cinfo, int quality, boolean force_baseline)
GLubyte GLubyte GLubyte a
virtual void UpdateScreen(bool outOfSequence=true)=0
virtual void Printf(const char *fmt,...) id_attribute((format(printf
#define ERREXIT1(cinfo, code, p1)
int NormalFrameSize(void)
NSBitmapImageRep * CurrentImage(void)
int SizeFile(idFile *ftosize)
void EncodeQuietly(bool which)
void Write16Word(word *aWord, idFile *stream)
void MarkQuadx(int xat, int yat, int size, float cerror, int choice)
GLOBAL void jpeg_create_compress(j_compress_ptr cinfo)
void EncodeStream(const char *paramInputFile)
virtual int Write(const void *buffer, int len)
int PreviousFrameSize(void)
int NormalFrameSize(void)
GLOBAL struct jpeg_error_mgr * jpeg_std_error(struct jpeg_error_mgr *err)
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
const char * c_str(void) const
const char * Argv(int arg) const
GLOBAL void jpeg_destroy_compress(j_compress_ptr cinfo)
void * Mem_Alloc(const int size)
void WriteHangFrame(void)
void WriteFrame(quadcel *pquad)
GLOBAL void jpeg_set_defaults(j_compress_ptr cinfo)
virtual void CloseFile(idFile *f)=0
my_destination_mgr * my_dest_ptr
virtual void Error(const char *fmt,...) id_attribute((format(printf
JOCTET * next_output_byte
struct jpeg_comp_master * master