int loadppm(int *fd, unsigned char **buf, int *w, int *h, enum BMPPIXELFORMAT f, int align, int dstbottomup, int ascii) { FILE *fs=NULL; int retcode=0, scalefactor, dstpitch; unsigned char *tempbuf=NULL; char temps[255], temps2[255]; int numread=0, totalread=0, pixel[3], i, j; if((fs=fdopen(*fd, "r"))==NULL) _throw(strerror(errno)); do { if(!fgets(temps, 255, fs)) _throw("Read error"); if(strlen(temps)==0 || temps[0]=='\n') continue; if(sscanf(temps, "%s", temps2)==1 && temps2[1]=='#') continue; switch(totalread) { case 0: if((numread=sscanf(temps, "%d %d %d", w, h, &scalefactor))==EOF) _throw("Read error"); break; case 1: if((numread=sscanf(temps, "%d %d", h, &scalefactor))==EOF) _throw("Read error"); break; case 2: if((numread=sscanf(temps, "%d", &scalefactor))==EOF) _throw("Read error"); break; } totalread+=numread; } while(totalread<3); if((*w)<1 || (*h)<1 || scalefactor<1) _throw("Corrupt PPM header"); dstpitch=(((*w)*ps[f])+(align-1))&(~(align-1)); if((*buf=(unsigned char *)malloc(dstpitch*(*h)))==NULL) _throw("Memory allocation error"); if(ascii) { for(j=0; j<*h; j++) { for(i=0; i<*w; i++) { if(fscanf(fs, "%d%d%d", &pixel[0], &pixel[1], &pixel[2])!=3) _throw("Read error"); (*buf)[j*dstpitch+i*ps[f]+roffset[f]]=(unsigned char)(pixel[0]*255/scalefactor); (*buf)[j*dstpitch+i*ps[f]+goffset[f]]=(unsigned char)(pixel[1]*255/scalefactor); (*buf)[j*dstpitch+i*ps[f]+boffset[f]]=(unsigned char)(pixel[2]*255/scalefactor); } } } else { if(scalefactor!=255) _throw("Binary PPMs must have 8-bit components"); if((tempbuf=(unsigned char *)malloc((*w)*(*h)*3))==NULL) _throw("Memory allocation error"); if(fread(tempbuf, (*w)*(*h)*3, 1, fs)!=1) _throw("Read error"); pixelconvert(tempbuf, BMP_RGB, (*w)*3, *buf, f, dstpitch, *w, *h, dstbottomup); } finally: if(fs) {fclose(fs); *fd=-1;} if(tempbuf) free(tempbuf); return retcode; }
JNIEXPORT void JNICALL Java_com_turbovnc_vncviewer_Viewport_grabKeyboard (JNIEnv *env, jobject obj, jboolean on, jboolean pointer) { JAWT awt; JAWT_DrawingSurface *ds = NULL; JAWT_DrawingSurfaceInfo *dsi = NULL; JAWT_X11DrawingSurfaceInfo *x11dsi = NULL; int ret; awt.version = JAWT_VERSION_1_3; if (!handle) { if ((handle = dlopen("libjawt.so", RTLD_LAZY)) == NULL) _throw(dlerror()); if ((__JAWT_GetAWT = (__JAWT_GetAWT_type)dlsym(handle, "JAWT_GetAWT")) == NULL) _throw(dlerror()); } if (__JAWT_GetAWT(env, &awt) == JNI_FALSE) _throw("Could not initialize AWT native interface"); if ((ds = awt.GetDrawingSurface(env, obj)) == NULL) _throw("Could not get drawing surface"); if ((ds->Lock(ds) & JAWT_LOCK_ERROR) != 0) _throw("Could not lock surface"); if ((dsi = ds->GetDrawingSurfaceInfo(ds)) == NULL) _throw("Could not get drawing surface info"); if ((x11dsi = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo) == NULL) _throw("Could not get X11 drawing surface info"); XSync(x11dsi->display, False); if (on) { int count = 5; while ((ret = XGrabKeyboard(x11dsi->display, x11dsi->drawable, True, GrabModeAsync, GrabModeAsync, CurrentTime)) != GrabSuccess) { switch (ret) { case AlreadyGrabbed: _throw("Could not grab keyboard: already grabbed by another application"); case GrabInvalidTime: _throw("Could not grab keyboard: invalid time"); case GrabNotViewable: /* The window should theoretically be viewable by now, but in practice, sometimes a race condition occurs with Swing. It is unclear why, since everything should be happening in the EDT. */ if (count == 0) _throw("Could not grab keyboard: window not viewable"); usleep(100000); count--; continue; case GrabFrozen: _throw("Could not grab keyboard: keyboard frozen by another application"); } } if (pointer) { ret = XGrabPointer(x11dsi->display, x11dsi->drawable, True, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); switch (ret) { case AlreadyGrabbed: _throw("Could not grab pointer: already grabbed by another application"); case GrabInvalidTime: _throw("Could not grab pointer: invalid time"); case GrabNotViewable: _throw("Could not grab pointer: window not viewable"); case GrabFrozen: _throw("Could not grab pointer: pointer frozen by another application"); } } printf("TurboVNC Helper: Grabbed keyboard%s for window 0x%.8lx\n", pointer? " & pointer" : "", x11dsi->drawable); } else { XUngrabKeyboard(x11dsi->display, CurrentTime); if (pointer) XUngrabPointer(x11dsi->display, CurrentTime); printf("TurboVNC Helper: Ungrabbed keyboard%s\n", pointer ? " & pointer" : ""); } XSync(x11dsi->display, False); bailout: if (ds) { if (dsi) ds->FreeDrawingSurfaceInfo(dsi); ds->Unlock(ds); awt.FreeDrawingSurface(ds); } }
DLLEXPORT int DLLCALL tjCompress(tjhandle h, unsigned char *srcbuf, int width, int pitch, int height, int ps, unsigned char *dstbuf, unsigned long *size, int jpegsub, int qual, int flags) { int i, retval=0; JSAMPROW *row_pointer=NULL; JSAMPLE *_tmpbuf[MAX_COMPONENTS], *_tmpbuf2[MAX_COMPONENTS]; JSAMPROW *tmpbuf[MAX_COMPONENTS], *tmpbuf2[MAX_COMPONENTS]; JSAMPROW *outbuf[MAX_COMPONENTS]; checkhandle(h); for(i=0; i<MAX_COMPONENTS; i++) { tmpbuf[i]=NULL; _tmpbuf[i]=NULL; tmpbuf2[i]=NULL; _tmpbuf2[i]=NULL; outbuf[i]=NULL; } if(srcbuf==NULL || width<=0 || pitch<0 || height<=0 || dstbuf==NULL || size==NULL || jpegsub<0 || jpegsub>=NUMSUBOPT || qual<0 || qual>100) _throw("Invalid argument in tjCompress()"); if(ps!=3 && ps!=4 && ps!=1) _throw("This compressor can only handle 24-bit and 32-bit RGB or 8-bit grayscale input"); if(!j->initc) _throw("Instance has not been initialized for compression"); if(pitch==0) pitch=width*ps; j->cinfo.image_width = width; j->cinfo.image_height = height; j->cinfo.input_components = ps; if(ps==1) j->cinfo.in_color_space = JCS_GRAYSCALE; #if JCS_EXTENSIONS==1 else j->cinfo.in_color_space = JCS_EXT_RGB; if(ps==3 && (flags&TJ_BGR)) j->cinfo.in_color_space = JCS_EXT_BGR; else if(ps==4 && !(flags&TJ_BGR) && !(flags&TJ_ALPHAFIRST)) j->cinfo.in_color_space = JCS_EXT_RGBX; else if(ps==4 && (flags&TJ_BGR) && !(flags&TJ_ALPHAFIRST)) j->cinfo.in_color_space = JCS_EXT_BGRX; else if(ps==4 && (flags&TJ_BGR) && (flags&TJ_ALPHAFIRST)) j->cinfo.in_color_space = JCS_EXT_XBGR; else if(ps==4 && !(flags&TJ_BGR) && (flags&TJ_ALPHAFIRST)) j->cinfo.in_color_space = JCS_EXT_XRGB; #else #error "TurboJPEG requires JPEG colorspace extensions" #endif if(flags&TJ_FORCEMMX) putenv("JSIMD_FORCEMMX=1"); else if(flags&TJ_FORCESSE) putenv("JSIMD_FORCESSE=1"); else if(flags&TJ_FORCESSE2) putenv("JSIMD_FORCESSE2=1"); if(setjmp(j->jerr.jb)) { // this will execute if LIBJPEG has an error retval=-1; goto bailout; } jpeg_set_defaults(&j->cinfo); jpeg_set_quality(&j->cinfo, qual, TRUE); if(jpegsub==TJ_GRAYSCALE) jpeg_set_colorspace(&j->cinfo, JCS_GRAYSCALE); else jpeg_set_colorspace(&j->cinfo, JCS_YCbCr); if(qual>=96) j->cinfo.dct_method=JDCT_ISLOW; else j->cinfo.dct_method=JDCT_FASTEST; j->cinfo.comp_info[0].h_samp_factor=hsampfactor[jpegsub]; j->cinfo.comp_info[1].h_samp_factor=1; j->cinfo.comp_info[2].h_samp_factor=1; j->cinfo.comp_info[0].v_samp_factor=vsampfactor[jpegsub]; j->cinfo.comp_info[1].v_samp_factor=1; j->cinfo.comp_info[2].v_samp_factor=1; j->jdms.next_output_byte = dstbuf; j->jdms.free_in_buffer = TJBUFSIZE(j->cinfo.image_width, j->cinfo.image_height); jpeg_start_compress(&j->cinfo, TRUE); if(flags&TJ_YUV) { j_compress_ptr cinfo=&j->cinfo; int row; int pw=PAD(width, cinfo->max_h_samp_factor); int ph=PAD(height, cinfo->max_v_samp_factor); int cw[MAX_COMPONENTS], ch[MAX_COMPONENTS]; jpeg_component_info *compptr; JSAMPLE *ptr=dstbuf; unsigned long yuvsize=0; if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph))==NULL) _throw("Memory allocation failed in tjCompress()"); for(i=0; i<height; i++) { if(flags&TJ_BOTTOMUP) row_pointer[i]= &srcbuf[(height-i-1)*pitch]; else row_pointer[i]= &srcbuf[i*pitch]; } if(height<ph) for(i=height; i<ph; i++) row_pointer[i]=row_pointer[height-1]; for(i=0; i<cinfo->num_components; i++) { compptr=&cinfo->comp_info[i]; _tmpbuf[i]=(JSAMPLE *)malloc( PAD((compptr->width_in_blocks*cinfo->max_h_samp_factor*DCTSIZE) /compptr->h_samp_factor, 16) * cinfo->max_v_samp_factor + 16); if(!_tmpbuf[i]) _throw("Memory allocation failure"); tmpbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*cinfo->max_v_samp_factor); if(!tmpbuf[i]) _throw("Memory allocation failure"); for(row=0; row<cinfo->max_v_samp_factor; row++) { unsigned char *_tmpbuf_aligned= (unsigned char *)PAD((size_t)_tmpbuf[i], 16); tmpbuf[i][row]=&_tmpbuf_aligned[ PAD((compptr->width_in_blocks*cinfo->max_h_samp_factor*DCTSIZE) /compptr->h_samp_factor, 16) * row]; } _tmpbuf2[i]=(JSAMPLE *)malloc(PAD(compptr->width_in_blocks*DCTSIZE, 16) * compptr->v_samp_factor + 16); if(!_tmpbuf2[i]) _throw("Memory allocation failure"); tmpbuf2[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*compptr->v_samp_factor); if(!tmpbuf2[i]) _throw("Memory allocation failure"); for(row=0; row<compptr->v_samp_factor; row++) { unsigned char *_tmpbuf2_aligned= (unsigned char *)PAD((size_t)_tmpbuf2[i], 16); tmpbuf2[i][row]=&_tmpbuf2_aligned[ PAD(compptr->width_in_blocks*DCTSIZE, 16) * row]; } cw[i]=pw*compptr->h_samp_factor/cinfo->max_h_samp_factor; ch[i]=ph*compptr->v_samp_factor/cinfo->max_v_samp_factor; outbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ch[i]); if(!outbuf[i]) _throw("Memory allocation failure"); for(row=0; row<ch[i]; row++) { outbuf[i][row]=ptr; ptr+=PAD(cw[i], 4); } } yuvsize=(unsigned long)(ptr-dstbuf); for(row=0; row<ph; row+=cinfo->max_v_samp_factor) { (*cinfo->cconvert->color_convert)(cinfo, &row_pointer[row], tmpbuf, 0, cinfo->max_v_samp_factor); (cinfo->downsample->downsample)(cinfo, tmpbuf, 0, tmpbuf2, 0); for(i=0, compptr=cinfo->comp_info; i<cinfo->num_components; i++, compptr++) jcopy_sample_rows(tmpbuf2[i], 0, outbuf[i], row*compptr->v_samp_factor/cinfo->max_v_samp_factor, compptr->v_samp_factor, cw[i]); } *size=yuvsize; cinfo->next_scanline+=height; } else { if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*height))==NULL) _throw("Memory allocation failed in tjCompress()"); for(i=0; i<height; i++) { if(flags&TJ_BOTTOMUP) row_pointer[i]= &srcbuf[(height-i-1)*pitch]; else row_pointer[i]= &srcbuf[i*pitch]; } while(j->cinfo.next_scanline<j->cinfo.image_height) { jpeg_write_scanlines(&j->cinfo, &row_pointer[j->cinfo.next_scanline], j->cinfo.image_height-j->cinfo.next_scanline); } } jpeg_finish_compress(&j->cinfo); if(!(flags&TJ_YUV)) *size=TJBUFSIZE(j->cinfo.image_width, j->cinfo.image_height) -(unsigned long)(j->jdms.free_in_buffer); bailout: if(j->cinfo.global_state>CSTATE_START) jpeg_abort_compress(&j->cinfo); if(row_pointer) free(row_pointer); for(i=0; i<MAX_COMPONENTS; i++) { if(tmpbuf[i]!=NULL) free(tmpbuf[i]); if(_tmpbuf[i]!=NULL) free(_tmpbuf[i]); if(tmpbuf2[i]!=NULL) free(tmpbuf2[i]); if(_tmpbuf2[i]!=NULL) free(_tmpbuf2[i]); if(outbuf[i]!=NULL) free(outbuf[i]); } return retval; }
struct Cyc_APQ_T*Cyc_APQ_div(struct Cyc_APQ_T*p,struct Cyc_APQ_T*q){struct Cyc_APQ_T*_T0;struct Cyc_AP_T*_T1;struct Cyc_AP_T*_T2;int _T3;struct Cyc_Invalid_argument_exn_struct*_T4;void*_T5;struct Cyc_APQ_T*_T6;struct Cyc_AP_T*_T7;struct Cyc_APQ_T*_T8;struct Cyc_AP_T*_T9;struct Cyc_AP_T*_TA;struct Cyc_APQ_T*_TB;struct Cyc_AP_T*_TC;struct Cyc_APQ_T*_TD;struct Cyc_AP_T*_TE;struct Cyc_AP_T*_TF;struct Cyc_APQ_T*_T10;_T0= _check_null(q);_T1=_T0->n;_T2=Cyc_AP_zero;_T3=Cyc_AP_cmp(_T1,_T2);if(_T3!=0)goto _TL10;{struct Cyc_Invalid_argument_exn_struct*_T11=_cycalloc(sizeof(struct Cyc_Invalid_argument_exn_struct));_T11->tag=Cyc_Invalid_argument;_T11->f1=_tag_fat("APQ_div: divide by zero",sizeof(char),24U);_T4=(struct Cyc_Invalid_argument_exn_struct*)_T11;}_T5=(void*)_T4;_throw(_T5);goto _TL11;_TL10: _TL11: _T6= _check_null(p);_T7=_T6->n;_T8=q;_T9=_T8->d;_TA=Cyc_AP_mul(_T7,_T9);_TB=p;_TC=_TB->d;_TD=q;_TE=_TD->n;_TF=Cyc_AP_mul(_TC,_TE);_T10=Cyc_APQ_fromAP(_TA,_TF);return _T10;}
void Cyc_Lineno_poss_of_abss(struct _fat_ptr filename,struct Cyc_List_List * places) { struct Cyc_List_List * (* _T0)(int (*)(struct _tuple1 *,struct _tuple1 *), struct Cyc_List_List *); struct Cyc_List_List * (* _T1)(int (*)(void *,void *),struct Cyc_List_List *); struct Cyc_List_List * _T2; struct _fat_ptr _T3; struct _fat_ptr _T4; struct _handler_cons * _T5; int _T6; enum Cyc_Lineno_token_val _T7; int _T8; int _T9; struct Cyc_List_List * _TA; void * _TB; struct _tuple1 * _TC; struct _tuple1 _TD; int _TE; enum Cyc_Lineno_token_val _TF; int _T10; struct _tuple0 * _T11; struct _tuple0 _T12; struct _tuple0 * _T13; struct _tuple0 _T14; enum Cyc_Lineno_token_val _T15; int _T16; int _T17; struct Cyc_List_List * _T18; void * _T19; struct _tuple1 * _T1A; struct _tuple1 _T1B; int _T1C; struct Cyc_List_List * _T1D; void * _T1E; struct _tuple1 * _T1F; struct _tuple1 _T20; struct Cyc_Lineno_Pos * _T21; struct Cyc_Lineno_Pos * _T22; struct Cyc_Lineno_Pos * _T23; struct Cyc_Lineno_Pos * _T24; unsigned long _T25; int _T26; struct Cyc_List_List * _T27; void * _T28; struct _tuple1 * _T29; struct _tuple1 _T2A; int _T2B; int _T2C; unsigned long _T2D; unsigned long _T2E; struct Cyc_Lineno_Pos * _T2F; int _T30; struct Cyc_Lineno_Pos * _T31; struct Cyc_List_List * _T32; void * _T33; _T1 = Cyc_List_merge_sort; { struct Cyc_List_List * (* _T34)(int (*)(struct _tuple1 *,struct _tuple1 *), struct Cyc_List_List *) = (struct Cyc_List_List * (*)(int (*)(struct _tuple1 *, struct _tuple1 *), struct Cyc_List_List *))_T1; _T0 = _T34; }_T2 = places; places = _T0(Cyc_Lineno_place_cmp,_T2); _T3 = filename; _T4 = _tag_fat("r",sizeof(char),2U); { struct Cyc___cycFILE * f = Cyc_file_open(_T3,_T4); { struct _handler_cons _T34; _T5 = &_T34; _push_handler(_T5); { int _T35 = 0; _T6 = setjmp(_T34.handler); if (! _T6) { goto _TL3A; } _T35 = 1; goto _TL3B; _TL3A: _TL3B: if (_T35) { goto _TL3C; }else { goto _TL3E; } _TL3E: { struct Cyc_Lexing_lexbuf * lbuf = Cyc_Lexing_from_file(f); struct _fat_ptr source_file = filename; int line = 1; struct _fat_ptr this_line; int eol; enum Cyc_Lineno_token_val next; _TL3F: if (places != 0) { goto _TL40; }else { goto _TL41; } _TL40: _TL42: if (1) { goto _TL43; }else { goto _TL44; } _TL43: next = Cyc_Lineno_token(lbuf); eol = Cyc_Lexing_lexeme_end(lbuf); this_line = Cyc_Lexing_lexeme(lbuf); _T7 = next; _T8 = (int)_T7; if (_T8 == 2) { goto _TL47; }else { goto _TL48; } _TL48: _T9 = eol; _TA = places; _TB = _TA->hd; _TC = (struct _tuple1 *)_TB; _TD = *_TC; _TE = _TD.f0; if (_T9 > _TE) { goto _TL47; }else { goto _TL45; } _TL47: goto _TL44; _TL45: _TF = next; _T10 = (int)_TF; if (_T10 != 0) { goto _TL49; } line = line + 1; goto _TL4A; _TL49: { struct _tuple0 * fno = Cyc_Lineno_parse_linedef(this_line); if (fno != 0) { goto _TL4B; } line = line + 1; goto _TL4C; _TL4B: _T11 = fno; _T12 = *_T11; source_file = _T12.f0; _T13 = fno; _T14 = *_T13; line = _T14.f1; _TL4C: ; }_TL4A: goto _TL42; _TL44: _TL4D: if (places != 0) { goto _TL50; }else { goto _TL4F; } _TL50: _T15 = next; _T16 = (int)_T15; if (_T16 == 2) { goto _TL4E; }else { goto _TL51; } _TL51: _T17 = eol; _T18 = places; _T19 = _T18->hd; _T1A = (struct _tuple1 *)_T19; _T1B = *_T1A; _T1C = _T1B.f0; if (_T17 > _T1C) { goto _TL4E; }else { goto _TL4F; } _TL4E: _T1D = places; _T1E = _T1D->hd; _T1F = (struct _tuple1 *)_T1E; _T20 = *_T1F; { struct Cyc_Lineno_Pos * p = _T20.f1; _T21 = p; _T21->logical_file = Cyc_strdup(source_file); _T22 = p; _T22->line = this_line; _T23 = p; _T23->line_no = line; _T24 = p; _T25 = Cyc_strlen(this_line); _T26 = eol; _T27 = places; _T28 = _T27->hd; _T29 = (struct _tuple1 *)_T28; _T2A = *_T29; _T2B = _T2A.f0; _T2C = _T26 - _T2B; _T2D = (unsigned long)_T2C; _T2E = _T25 - _T2D; _T24->col = (int)_T2E; _T2F = p; _T30 = _T2F->col; if (_T30 >= 0) { goto _TL52; } _T31 = p; _T31->col = 0; goto _TL53; _TL52: _TL53: _T32 = places; places = _T32->tl; }goto _TL4D; _TL4F: line = line + 1; goto _TL3F; _TL41: ; }_pop_handler(); goto _TL3D; _TL3C: _T33 = Cyc_Core_get_exn_thrown(); { void * _T36 = (void *)_T33; void * _T37; _T37 = _T36; { void * y = _T37; Cyc_file_close(f); _throw(y); }; }_TL3D: ; } }Cyc_file_close(f); return; } }
/* TurboJPEG 1.2.x: TJTransformer::transform() */ JNIEXPORT jintArray JNICALL Java_org_libjpegturbo_turbojpeg_TJTransformer_transform (JNIEnv *env, jobject obj, jbyteArray jsrcBuf, jint jpegSize, jobjectArray dstobjs, jobjectArray tobjs, jint flags) { tjhandle handle=0; int i; unsigned char *jpegBuf=NULL, **dstBufs=NULL; jsize n=0; unsigned long *dstSizes=NULL; tjtransform *t=NULL; jbyteArray *jdstBufs=NULL; int jpegWidth=0, jpegHeight=0, jpegSubsamp; jintArray jdstSizes=0; jint *dstSizesi=NULL; JNICustomFilterParams *params=NULL; gethandle(); if((*env)->GetArrayLength(env, jsrcBuf)<jpegSize) _throw("Source buffer is not large enough"); bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegWidth", "I")); jpegWidth=(int)(*env)->GetIntField(env, obj, _fid); bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegHeight", "I")); jpegHeight=(int)(*env)->GetIntField(env, obj, _fid); bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegSubsamp", "I")); jpegSubsamp=(int)(*env)->GetIntField(env, obj, _fid); n=(*env)->GetArrayLength(env, dstobjs); if(n!=(*env)->GetArrayLength(env, tobjs)) _throw("Mismatch between size of transforms array and destination buffers array"); if((dstBufs=(unsigned char **)malloc(sizeof(unsigned char *)*n))==NULL) _throw("Memory allocation failure"); if((jdstBufs=(jbyteArray *)malloc(sizeof(jbyteArray)*n))==NULL) _throw("Memory allocation failure"); if((dstSizes=(unsigned long *)malloc(sizeof(unsigned long)*n))==NULL) _throw("Memory allocation failure"); if((t=(tjtransform *)malloc(sizeof(tjtransform)*n))==NULL) _throw("Memory allocation failure"); if((params=(JNICustomFilterParams *)malloc(sizeof(JNICustomFilterParams)*n)) ==NULL) _throw("Memory allocation failure"); for(i=0; i<n; i++) { dstBufs[i]=NULL; jdstBufs[i]=NULL; dstSizes[i]=0; memset(&t[i], 0, sizeof(tjtransform)); memset(¶ms[i], 0, sizeof(JNICustomFilterParams)); } for(i=0; i<n; i++) { jobject tobj, cfobj; bailif0(tobj=(*env)->GetObjectArrayElement(env, tobjs, i)); bailif0(_cls=(*env)->GetObjectClass(env, tobj)); bailif0(_fid=(*env)->GetFieldID(env, _cls, "op", "I")); t[i].op=(*env)->GetIntField(env, tobj, _fid); bailif0(_fid=(*env)->GetFieldID(env, _cls, "options", "I")); t[i].options=(*env)->GetIntField(env, tobj, _fid); bailif0(_fid=(*env)->GetFieldID(env, _cls, "x", "I")); t[i].r.x=(*env)->GetIntField(env, tobj, _fid); bailif0(_fid=(*env)->GetFieldID(env, _cls, "y", "I")); t[i].r.y=(*env)->GetIntField(env, tobj, _fid); bailif0(_fid=(*env)->GetFieldID(env, _cls, "width", "I")); t[i].r.w=(*env)->GetIntField(env, tobj, _fid); bailif0(_fid=(*env)->GetFieldID(env, _cls, "height", "I")); t[i].r.h=(*env)->GetIntField(env, tobj, _fid); bailif0(_fid=(*env)->GetFieldID(env, _cls, "cf", "Lorg/libjpegturbo/turbojpeg/TJCustomFilter;")); cfobj=(*env)->GetObjectField(env, tobj, _fid); if(cfobj) { params[i].env=env; params[i].tobj=tobj; params[i].cfobj=cfobj; t[i].customFilter=JNICustomFilter; t[i].data=(void *)¶ms[i]; } } for(i=0; i<n; i++) { int w=jpegWidth, h=jpegHeight; if(t[i].r.w!=0) w=t[i].r.w; if(t[i].r.h!=0) h=t[i].r.h; bailif0(jdstBufs[i]=(*env)->GetObjectArrayElement(env, dstobjs, i)); if((unsigned long)(*env)->GetArrayLength(env, jdstBufs[i]) <tjBufSize(w, h, jpegSubsamp)) _throw("Destination buffer is not large enough"); } bailif0(jpegBuf=(*env)->GetPrimitiveArrayCritical(env, jsrcBuf, 0)); for(i=0; i<n; i++) bailif0(dstBufs[i]=(*env)->GetPrimitiveArrayCritical(env, jdstBufs[i], 0)); if(tjTransform(handle, jpegBuf, jpegSize, n, dstBufs, dstSizes, t, flags|TJFLAG_NOREALLOC)==-1) _throw(tjGetErrorStr()); for(i=0; i<n; i++) { (*env)->ReleasePrimitiveArrayCritical(env, jdstBufs[i], dstBufs[i], 0); dstBufs[i]=NULL; } (*env)->ReleasePrimitiveArrayCritical(env, jsrcBuf, jpegBuf, 0); jpegBuf=NULL; jdstSizes=(*env)->NewIntArray(env, n); bailif0(dstSizesi=(*env)->GetIntArrayElements(env, jdstSizes, 0)); for(i=0; i<n; i++) dstSizesi[i]=(int)dstSizes[i]; bailout: if(dstSizesi) (*env)->ReleaseIntArrayElements(env, jdstSizes, dstSizesi, 0); if(dstBufs) { for(i=0; i<n; i++) { if(dstBufs[i] && jdstBufs && jdstBufs[i]) (*env)->ReleasePrimitiveArrayCritical(env, jdstBufs[i], dstBufs[i], 0); } free(dstBufs); } if(jpegBuf) (*env)->ReleasePrimitiveArrayCritical(env, jsrcBuf, jpegBuf, 0); if(jdstBufs) free(jdstBufs); if(dstSizes) free(dstSizes); if(t) free(t); return jdstSizes; }
struct Cyc_APQ_T*Cyc_APQ_fromAP(struct Cyc_AP_T*n,struct Cyc_AP_T*d){int _T0;struct Cyc_Invalid_argument_exn_struct*_T1;void*_T2;void*_T3;struct Cyc_APQ_T*_T4;struct Cyc_APQ_T*_T5;struct Cyc_APQ_T*_T6;_T0= Cyc_AP_cmp(d,Cyc_AP_zero);if(_T0!=0)goto _TL4;{struct Cyc_Invalid_argument_exn_struct*_T7=_cycalloc(sizeof(struct Cyc_Invalid_argument_exn_struct));_T7->tag=Cyc_Invalid_argument;_T7->f1=_tag_fat("APQ_fromAP: divide by zero",sizeof(char),27U);_T1=(struct Cyc_Invalid_argument_exn_struct*)_T7;}_T2=(void*)_T1;_throw(_T2);goto _TL5;_TL4: _TL5: _T3=_cycalloc(sizeof(struct Cyc_APQ_T));{ struct Cyc_APQ_T*q=(struct Cyc_APQ_T*)_T3;_T4=q; _T4->n=n;_T5=q; _T5->d=d;_T6= Cyc_reduce(q);return _T6;}}
int Cyc_main(int argc,struct _fat_ptr argv) { struct Cyc___cycFILE * _T0; struct _fat_ptr _T1; struct _fat_ptr _T2; struct _fat_ptr _T3; unsigned char * _T4; struct _fat_ptr * _T5; struct _fat_ptr _T6; unsigned char * _T7; struct _fat_ptr * _T8; struct _fat_ptr _T9; struct _fat_ptr _TA; long _TB; struct _fat_ptr _TC; struct _fat_ptr _TD; struct _fat_ptr _TE; struct _fat_ptr _TF; struct _handler_cons * _T10; int _T11; struct _fat_ptr _T12; struct _fat_ptr _T13; struct _fat_ptr _T14; struct _fat_ptr _T15; void * _T16; struct Cyc___cycFILE * _T17; struct _fat_ptr _T18; struct _fat_ptr _T19; struct _fat_ptr _T1A; unsigned char * _T1B; unsigned char * _T1C; const char * _T1D; struct _handler_cons * _T1E; int _T1F; struct _fat_ptr _T20; struct Cyc___cycFILE * _T21; struct Cyc___cycFILE * _T22; struct Cyc_Syntax_Lexer_definition * _T23; struct Cyc_Syntax_Location * _T24; struct Cyc_Compact_Lex_tables * _T25; struct Cyc_List_List * _T26; struct Cyc_Syntax_Lexer_definition * _T27; struct Cyc_Syntax_Location * _T28; void * _T29; struct Cyc_Parser_Parser_error_exn_struct * _T2A; char * _T2B; char * _T2C; struct Cyc_String_pa_PrintArg_struct _T2D; struct Cyc_Int_pa_PrintArg_struct _T2E; int _T2F; struct Cyc___cycFILE * _T30; struct _fat_ptr _T31; struct _fat_ptr _T32; struct Cyc_Lexer_Lexical_error_exn_struct * _T33; char * _T34; char * _T35; struct Cyc_String_pa_PrintArg_struct _T36; struct Cyc_Int_pa_PrintArg_struct _T37; int _T38; struct Cyc_Int_pa_PrintArg_struct _T39; int _T3A; struct Cyc_String_pa_PrintArg_struct _T3B; struct Cyc___cycFILE * _T3C; struct _fat_ptr _T3D; struct _fat_ptr _T3E; struct Cyc_Output_Table_overflow_exn_struct * _T3F; char * _T40; char * _T41; struct Cyc_String_pa_PrintArg_struct _T42; struct Cyc___cycFILE * _T43; struct _fat_ptr _T44; struct _fat_ptr _T45; struct Cyc___cycFILE * _T46; struct _fat_ptr _T47; struct _fat_ptr _T48; struct _fat_ptr _T49; unsigned char * _T4A; unsigned char * _T4B; const char * _T4C; GC_blacklist_warn_clear(); if (argc < 2) { goto _TL2; }else { goto _TL3; } _TL3: if (argc > 3) { goto _TL2; }else { goto _TL0; } _TL2: _T0 = Cyc_stderr; _T1 = _tag_fat("Usage: cyclex <input file> [<output file>]",sizeof(char), 43U); _T2 = _tag_fat(0U,sizeof(void *),0); Cyc_fprintf(_T0,_T1,_T2); return 1; _TL0: _T3 = argv; _T4 = _check_fat_subscript(_T3,sizeof(struct _fat_ptr),1); _T5 = (struct _fat_ptr *)_T4; { struct _fat_ptr source_name = *_T5; struct _fat_ptr dest_name; if (argc != 3) { goto _TL4; } _T6 = argv; _T7 = _check_fat_subscript(_T6,sizeof(struct _fat_ptr),2); _T8 = (struct _fat_ptr *)_T7; dest_name = *_T8; goto _TL5; _TL4: _T9 = source_name; _TA = _tag_fat(".cyl",sizeof(char),5U); _TB = Cyc_Filename_check_suffix(_T9,_TA); if (! _TB) { goto _TL6; } _TC = Cyc_Filename_chop_extension(source_name); _TD = _tag_fat(".cyc",sizeof(char),5U); dest_name = Cyc_strconcat(_TC,_TD); goto _TL7; _TL6: _TE = source_name; _TF = _tag_fat(".cyc",sizeof(char),5U); dest_name = Cyc_strconcat(_TE,_TF); _TL7: _TL5: { struct Cyc___cycFILE * ic; struct Cyc___cycFILE * oc; { struct _handler_cons _T4D; _T10 = &_T4D; _push_handler(_T10); { int _T4E = 0; _T11 = setjmp(_T4D.handler); if (! _T11) { goto _TL8; } _T4E = 1; goto _TL9; _TL8: _TL9: if (_T4E) { goto _TLA; }else { goto _TLC; } _TLC: _T12 = source_name; _T13 = _tag_fat("rb",sizeof(char),3U); ic = Cyc_file_open(_T12,_T13); _T14 = dest_name; _T15 = _tag_fat("w",sizeof(char),2U); oc = Cyc_file_open(_T14,_T15); _pop_handler(); goto _TLB; _TLA: _T16 = Cyc_Core_get_exn_thrown(); { void * _T4F = (void *)_T16; _T17 = Cyc_stderr; _T18 = _tag_fat("trouble opening files",sizeof(char),22U); _T19 = _tag_fat(0U,sizeof(void *),0); Cyc_fprintf(_T17,_T18,_T19); _T1A = dest_name; _T1B = _untag_fat_ptr_check_bound(_T1A,sizeof(char),1U); _T1C = _check_null(_T1B); _T1D = (const char *)_T1C; remove(_T1D); return 1; ; }_TLB: ; } }{ struct _handler_cons _T4D; _T1E = &_T4D; _push_handler(_T1E); { int _T4E = 0; _T1F = setjmp(_T4D.handler); if (! _T1F) { goto _TLD; } _T4E = 1; goto _TLE; _TLD: _TLE: if (_T4E) { goto _TLF; }else { goto _TL11; } _TL11: { struct Cyc_Syntax_Lexer_definition * def = Cyc_Parser_parse_file(ic); struct _tuple6 * _T4F = Cyc_Lexgen_make_dfa(def); struct _fat_ptr _T50; struct Cyc_List_List * _T51; { struct _tuple6 _T52 = *_T4F; _T51 = _T52.f0; _T50 = _T52.f1; }{ struct Cyc_List_List * entries = _T51; struct _fat_ptr transitions = _T50; struct Cyc_Compact_Lex_tables * tables = Cyc_Compact_compact_tables(transitions); _T20 = source_name; _T21 = ic; _T22 = oc; _T23 = _check_null(def); _T24 = _T23->header; _T25 = tables; _T26 = entries; _T27 = def; _T28 = _T27->trailer; Cyc_Output_output_lexdef(_T20,_T21,_T22,_T24,_T25,_T26,_T28); } }_pop_handler(); goto _TL10; _TLF: _T29 = Cyc_Core_get_exn_thrown(); { void * _T4F = (void *)_T29; void * _T50; int _T51; int _T52; struct _fat_ptr _T53; _T2A = (struct Cyc_Parser_Parser_error_exn_struct *)_T4F; _T2B = _T2A->tag; _T2C = Cyc_Parser_Parser_error; if (_T2B != _T2C) { goto _TL12; } { struct Cyc_Parser_Parser_error_exn_struct * _T54 = (struct Cyc_Parser_Parser_error_exn_struct *)_T4F; _T53 = _T54->f1; }{ struct _fat_ptr s = _T53; { struct Cyc_String_pa_PrintArg_struct _T54; _T54.tag = 0; _T54.f1 = source_name; _T2D = _T54; }{ struct Cyc_String_pa_PrintArg_struct _T54 = _T2D; { struct Cyc_Int_pa_PrintArg_struct _T55; _T55.tag = 1; _T2F = Cyc_Lexer_line_num; _T55.f1 = (unsigned long)_T2F; _T2E = _T55; }{ struct Cyc_Int_pa_PrintArg_struct _T55 = _T2E; void * _T56[2]; _T56[0] = &_T54; _T56[1] = &_T55; _T30 = Cyc_stderr; _T31 = _tag_fat("File \"%s\", line %d: syntax error.\n", sizeof(char),35U); _T32 = _tag_fat(_T56,sizeof(void *),2); Cyc_fprintf(_T30,_T31,_T32); } }goto _LL6; }_TL12: _T33 = (struct Cyc_Lexer_Lexical_error_exn_struct *)_T4F; _T34 = _T33->tag; _T35 = Cyc_Lexer_Lexical_error; if (_T34 != _T35) { goto _TL14; } { struct Cyc_Lexer_Lexical_error_exn_struct * _T54 = (struct Cyc_Lexer_Lexical_error_exn_struct *)_T4F; _T53 = _T54->f1; _T52 = _T54->f2; _T51 = _T54->f3; }{ struct _fat_ptr msg = _T53; int line = _T52; int col = _T51; { struct Cyc_String_pa_PrintArg_struct _T54; _T54.tag = 0; _T54.f1 = source_name; _T36 = _T54; }{ struct Cyc_String_pa_PrintArg_struct _T54 = _T36; { struct Cyc_Int_pa_PrintArg_struct _T55; _T55.tag = 1; _T38 = line; _T55.f1 = (unsigned long)_T38; _T37 = _T55; }{ struct Cyc_Int_pa_PrintArg_struct _T55 = _T37; { struct Cyc_Int_pa_PrintArg_struct _T56; _T56.tag = 1; _T3A = col; _T56.f1 = (unsigned long)_T3A; _T39 = _T56; }{ struct Cyc_Int_pa_PrintArg_struct _T56 = _T39; { struct Cyc_String_pa_PrintArg_struct _T57; _T57.tag = 0; _T57.f1 = msg; _T3B = _T57; }{ struct Cyc_String_pa_PrintArg_struct _T57 = _T3B; void * _T58[4]; _T58[0] = &_T54; _T58[1] = &_T55; _T58[2] = &_T56; _T58[3] = &_T57; _T3C = Cyc_stderr; _T3D = _tag_fat("File \"%s\", line %d, character %d: %s.\n", sizeof(char),39U); _T3E = _tag_fat(_T58,sizeof(void *),4); Cyc_fprintf(_T3C,_T3D,_T3E); } } } }goto _LL6; }_TL14: _T3F = (struct Cyc_Output_Table_overflow_exn_struct *)_T4F; _T40 = _T3F->tag; _T41 = Cyc_Output_Table_overflow; if (_T40 != _T41) { goto _TL16; } { struct Cyc_String_pa_PrintArg_struct _T54; _T54.tag = 0; _T54.f1 = source_name; _T42 = _T54; }{ struct Cyc_String_pa_PrintArg_struct _T54 = _T42; void * _T55[1]; _T55[0] = &_T54; _T43 = Cyc_stderr; _T44 = _tag_fat("File \"%s\":\ntransition table overflow, automaton is too big\n", sizeof(char),60U); _T45 = _tag_fat(_T55,sizeof(void *),1); Cyc_fprintf(_T43,_T44,_T45); }goto _LL6; _TL16: _T50 = _T4F; { void * exn = _T50; _T46 = Cyc_stderr; _T47 = _tag_fat("error in parsing, generation, compaction, or output", sizeof(char),52U); _T48 = _tag_fat(0U,sizeof(void *),0); Cyc_fprintf(_T46,_T47,_T48); _T49 = dest_name; _T4A = _untag_fat_ptr_check_bound(_T49,sizeof(char),1U); _T4B = _check_null(_T4A); _T4C = (const char *)_T4B; remove(_T4C); _throw(exn); return 1; }_LL6: ; }_TL10: ; } }return 0; } } }
struct _fat_ptr Cyc_Array_map2(void * (* f)(void *,void *),struct _fat_ptr x, struct _fat_ptr y) { struct _fat_ptr _T0; unsigned int _T1; int _T2; unsigned int _T3; struct _fat_ptr _T4; unsigned int _T5; struct Cyc_Array_Array_mismatch_exn_struct * _T6; struct Cyc_Array_Array_mismatch_exn_struct * _T7; struct _fat_ptr _T8; int _T9; void * * _TA; unsigned int _TB; unsigned int _TC; struct _fat_ptr _TD; unsigned char * _TE; void * * _TF; void * * _T10; unsigned int _T11; int _T12; void * _T13; struct _fat_ptr _T14; unsigned char * _T15; void * * _T16; void * * _T17; unsigned int _T18; int _T19; void * _T1A; _T0 = x; _T1 = _get_fat_size(_T0,sizeof(void *)); { int sx = (int)_T1; _T2 = sx; _T3 = (unsigned int)_T2; _T4 = y; _T5 = _get_fat_size(_T4,sizeof(void *)); if (_T3 == _T5) { goto _TL63; } _T6 = &Cyc_Array_Array_mismatch_val; _T7 = (struct Cyc_Array_Array_mismatch_exn_struct *)_T6; _throw(_T7); goto _TL64; _TL63: _TL64: _T9 = sx; { unsigned int _T1B = (unsigned int)_T9; _TB = _check_times(_T1B,sizeof(void *)); { void * * _T1C = _cycalloc(_TB); { unsigned int _T1D = _T1B; unsigned int i; i = 0; _TL68: if (i < _T1D) { goto _TL66; }else { goto _TL67; } _TL66: _TC = i; _TD = x; _TE = _TD.curr; _TF = (void * *)_TE; _T10 = _check_null(_TF); _T11 = i; _T12 = (int)_T11; _T13 = _T10[_T12]; _T14 = y; _T15 = _T14.curr; _T16 = (void * *)_T15; _T17 = _check_null(_T16); _T18 = i; _T19 = (int)_T18; _T1A = _T17[_T19]; _T1C[_TC] = f(_T13,_T1A); i = i + 1; goto _TL68; _TL67: ; }_TA = (void * *)_T1C; }_T8 = _tag_fat(_TA,sizeof(void *),_T1B); }return _T8; } }
// Platform-specific write test void nativewrite(int useshm) { fbx_struct s; int n, i; double rbtime; memset(&s, 0, sizeof(s)); try { fbx(fbx_init(&s, wh, 0, 0, useshm)); if(useshm && !s.shm) _throw("MIT-SHM not available"); fprintf(stderr, "Native Pixel Format: %s", fbx_formatname(s.format)); fprintf(stderr, "\n"); if(s.width!=width || s.height!=height) _throw("The benchmark window lost input focus or was obscured.\nSkipping native write test\n"); clearfb(); initbuf(0, 0, width, s.pitch, height, s.format, (unsigned char *)s.bits); if(useshm) fprintf(stderr, "FBX bottom-up write [SHM]: "); else fprintf(stderr, "FBX bottom-up write: "); n=N; do { n+=n; timer.start(); for (i=0; i<n; i++) { if(checkdb) { memset(s.bits, 255, s.pitch*s.height); fbx(fbx_awrite(&s, 0, 0, 0, 0, 0, 0)); initbuf(0, 0, width, s.pitch, height, s.format, (unsigned char *)s.bits); } fbx(fbx_flip(&s, 0, 0, 0, 0)); fbx(fbx_write(&s, 0, 0, 0, 0, 0, 0)); } rbtime=timer.elapsed(); } while(rbtime<1.); fprintf(stderr, "%f Mpixels/sec\n", (double)n*(double)(width*height)/((double)1000000.*rbtime)); clearfb(); if(useshm) fprintf(stderr, "FBX top-down write [SHM]: "); else fprintf(stderr, "FBX top-down write: "); n=N; do { n+=n; timer.start(); for (i=0; i<n; i++) { if(checkdb) { memset(s.bits, 255, s.pitch*s.height); fbx(fbx_awrite(&s, 0, 0, 0, 0, 0, 0)); initbuf(0, 0, width, s.pitch, height, s.format, (unsigned char *)s.bits); } fbx(fbx_write(&s, 0, 0, 0, 0, 0, 0)); } rbtime=timer.elapsed(); } while(rbtime<1.); fprintf(stderr, "%f Mpixels/sec\n", (double)n*(double)(width*height)/((double)1000000.*rbtime)); } catch(rrerror &e) {fprintf(stderr, "%s\n", e.getMessage());} fbx_term(&s); }
// This method should only be called from generated code, // therefore the exception oop should be in the oopmap. void Exceptions::_throw_oop(Thread* thread, const char* file, int line, oop exception) { assert(exception != NULL, "exception should not be NULL"); Handle h_exception = Handle(thread, exception); _throw(thread, file, line, h_exception); }
void Cyc_Xarray_remove(struct Cyc_Xarray_Xarray * xarr,int i) { int _T0; struct Cyc_Xarray_Xarray * _T1; int _T2; int _T3; struct Cyc_Core_Invalid_argument_exn_struct * _T4; void * _T5; int _T6; struct Cyc_Xarray_Xarray * _T7; int _T8; int _T9; struct Cyc_Xarray_Xarray * _TA; struct _fat_ptr _TB; int _TC; unsigned char * _TD; void * * _TE; struct Cyc_Xarray_Xarray * _TF; struct _fat_ptr _T10; int _T11; unsigned char * _T12; void * * _T13; struct Cyc_Xarray_Xarray * _T14; if (i < 0) { goto _TL64; }else { goto _TL65; } _TL65: _T0 = i; _T1 = xarr; _T2 = _T1->num_elmts; _T3 = _T2 - 1; if (_T0 > _T3) { goto _TL64; }else { goto _TL62; } _TL64: { struct Cyc_Core_Invalid_argument_exn_struct * _T15 = _cycalloc(sizeof(struct Cyc_Core_Invalid_argument_exn_struct)); _T15->tag = Cyc_Core_Invalid_argument; _T15->f1 = _tag_fat("xarray index out of bounds",sizeof(char),27U); _T4 = (struct Cyc_Core_Invalid_argument_exn_struct *)_T15; }_T5 = (void *)_T4; _throw(_T5); goto _TL63; _TL62: _TL63: { int j = i; _TL69: _T6 = j; _T7 = xarr; _T8 = _T7->num_elmts; _T9 = _T8 - 1; if (_T6 < _T9) { goto _TL67; }else { goto _TL68; } _TL67: _TA = xarr; _TB = _TA->elmts; _TC = j; _TD = _check_fat_subscript(_TB,sizeof(void *),_TC); _TE = (void * *)_TD; _TF = xarr; _T10 = _TF->elmts; _T11 = j + 1; _T12 = _check_fat_subscript(_T10,sizeof(void *),_T11); _T13 = (void * *)_T12; *_TE = *_T13; j = j + 1; goto _TL69; _TL68: ; }_T14 = xarr; _T14->num_elmts = _T14->num_elmts + -1; }
static int setDecompDefaults(struct jpeg_decompress_struct *dinfo, int pixelFormat) { int retval=0; switch(pixelFormat) { case TJPF_GRAY: dinfo->out_color_space=JCS_GRAYSCALE; break; #if JCS_EXTENSIONS==1 case TJPF_RGB: dinfo->out_color_space=JCS_EXT_RGB; break; case TJPF_BGR: dinfo->out_color_space=JCS_EXT_BGR; break; case TJPF_RGBX: dinfo->out_color_space=JCS_EXT_RGBX; break; case TJPF_BGRX: dinfo->out_color_space=JCS_EXT_BGRX; break; case TJPF_XRGB: dinfo->out_color_space=JCS_EXT_XRGB; break; case TJPF_XBGR: dinfo->out_color_space=JCS_EXT_XBGR; break; #if JCS_ALPHA_EXTENSIONS==1 case TJPF_RGBA: dinfo->out_color_space=JCS_EXT_RGBA; break; case TJPF_BGRA: dinfo->out_color_space=JCS_EXT_BGRA; break; case TJPF_ARGB: dinfo->out_color_space=JCS_EXT_ARGB; break; case TJPF_ABGR: dinfo->out_color_space=JCS_EXT_ABGR; break; #endif #else case TJPF_RGB: case TJPF_BGR: case TJPF_RGBX: case TJPF_BGRX: case TJPF_XRGB: case TJPF_XBGR: case TJPF_RGBA: case TJPF_BGRA: case TJPF_ARGB: case TJPF_ABGR: dinfo->out_color_space=JCS_RGB; break; #endif default: _throw("Unsupported pixel format"); } bailout: return retval; }
DLLEXPORT int DLLCALL tjDecompress(tjhandle h, unsigned char *srcbuf, unsigned long size, unsigned char *dstbuf, int width, int pitch, int height, int ps, int flags) { int i, row, retval=0; JSAMPROW *row_pointer=NULL, *outbuf[MAX_COMPONENTS]; int cw[MAX_COMPONENTS], ch[MAX_COMPONENTS], iw[MAX_COMPONENTS], tmpbufsize=0, usetmpbuf=0, th[MAX_COMPONENTS]; JSAMPLE *_tmpbuf=NULL; JSAMPROW *tmpbuf[MAX_COMPONENTS]; checkhandle(h); for(i=0; i<MAX_COMPONENTS; i++) { tmpbuf[i]=NULL; outbuf[i]=NULL; } if(srcbuf==NULL || size<=0 || dstbuf==NULL || width<=0 || pitch<0 || height<=0) _throw("Invalid argument in tjDecompress()"); if(ps!=3 && ps!=4 && ps!=1) _throw("This decompressor can only handle 24-bit and 32-bit RGB or 8-bit grayscale output"); if(!j->initd) _throw("Instance has not been initialized for decompression"); if(pitch==0) pitch=width*ps; if(flags&TJ_FORCEMMX) putenv("JSIMD_FORCEMMX=1"); else if(flags&TJ_FORCESSE) putenv("JSIMD_FORCESSE=1"); else if(flags&TJ_FORCESSE2) putenv("JSIMD_FORCESSE2=1"); if(setjmp(j->jerr.jb)) { // this will execute if LIBJPEG has an error retval=-1; goto bailout; } j->jsms.bytes_in_buffer = size; j->jsms.next_input_byte = srcbuf; jpeg_read_header(&j->dinfo, TRUE); if(flags&TJ_YUV) { j_decompress_ptr dinfo=&j->dinfo; JSAMPLE *ptr=dstbuf; for(i=0; i<dinfo->num_components; i++) { jpeg_component_info *compptr=&dinfo->comp_info[i]; int ih; iw[i]=compptr->width_in_blocks*DCTSIZE; ih=compptr->height_in_blocks*DCTSIZE; cw[i]=PAD(dinfo->image_width, dinfo->max_h_samp_factor) *compptr->h_samp_factor/dinfo->max_h_samp_factor; ch[i]=PAD(dinfo->image_height, dinfo->max_v_samp_factor) *compptr->v_samp_factor/dinfo->max_v_samp_factor; if(iw[i]!=cw[i] || ih!=ch[i]) usetmpbuf=1; th[i]=compptr->v_samp_factor*DCTSIZE; tmpbufsize+=iw[i]*th[i]; if((outbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ch[i]))==NULL) _throw("Memory allocation failed in tjDecompress()"); for(row=0; row<ch[i]; row++) { outbuf[i][row]=ptr; ptr+=PAD(cw[i], 4); } } if(usetmpbuf) { if((_tmpbuf=(JSAMPLE *)malloc(sizeof(JSAMPLE)*tmpbufsize))==NULL) _throw("Memory allocation failed in tjDecompress()"); ptr=_tmpbuf; for(i=0; i<dinfo->num_components; i++) { if((tmpbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*th[i]))==NULL) _throw("Memory allocation failed in tjDecompress()"); for(row=0; row<th[i]; row++) { tmpbuf[i][row]=ptr; ptr+=iw[i]; } } } } else { if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*height))==NULL) _throw("Memory allocation failed in tjDecompress()"); for(i=0; i<height; i++) { if(flags&TJ_BOTTOMUP) row_pointer[i]= &dstbuf[(height-i-1)*pitch]; else row_pointer[i]= &dstbuf[i*pitch]; } } if(ps==1) j->dinfo.out_color_space = JCS_GRAYSCALE; #if JCS_EXTENSIONS==1 else j->dinfo.out_color_space = JCS_EXT_RGB; if(ps==3 && (flags&TJ_BGR)) j->dinfo.out_color_space = JCS_EXT_BGR; else if(ps==4 && !(flags&TJ_BGR) && !(flags&TJ_ALPHAFIRST)) j->dinfo.out_color_space = JCS_EXT_RGBX; else if(ps==4 && (flags&TJ_BGR) && !(flags&TJ_ALPHAFIRST)) j->dinfo.out_color_space = JCS_EXT_BGRX; else if(ps==4 && (flags&TJ_BGR) && (flags&TJ_ALPHAFIRST)) j->dinfo.out_color_space = JCS_EXT_XBGR; else if(ps==4 && !(flags&TJ_BGR) && (flags&TJ_ALPHAFIRST)) j->dinfo.out_color_space = JCS_EXT_XRGB; #else #error "TurboJPEG requires JPEG colorspace extensions" #endif if(flags&TJ_FASTUPSAMPLE) j->dinfo.do_fancy_upsampling=FALSE; if(flags&TJ_YUV) j->dinfo.raw_data_out=TRUE; jpeg_start_decompress(&j->dinfo); if(flags&TJ_YUV) { j_decompress_ptr dinfo=&j->dinfo; for(row=0; row<dinfo->output_height; row+=dinfo->max_v_samp_factor*DCTSIZE) { JSAMPARRAY yuvptr[MAX_COMPONENTS]; int crow[MAX_COMPONENTS]; for(i=0; i<dinfo->num_components; i++) { jpeg_component_info *compptr=&dinfo->comp_info[i]; crow[i]=row*compptr->v_samp_factor/dinfo->max_v_samp_factor; if(usetmpbuf) yuvptr[i]=tmpbuf[i]; else yuvptr[i]=&outbuf[i][crow[i]]; } jpeg_read_raw_data(dinfo, yuvptr, dinfo->max_v_samp_factor*DCTSIZE); if(usetmpbuf) { int j; for(i=0; i<dinfo->num_components; i++) { for(j=0; j<min(th[i], ch[i]-crow[i]); j++) { memcpy(outbuf[i][crow[i]+j], tmpbuf[i][j], cw[i]); } } } } } else { while(j->dinfo.output_scanline<j->dinfo.output_height) { jpeg_read_scanlines(&j->dinfo, &row_pointer[j->dinfo.output_scanline], j->dinfo.output_height-j->dinfo.output_scanline); } } jpeg_finish_decompress(&j->dinfo); bailout: if(j->dinfo.global_state>DSTATE_START) jpeg_abort_decompress(&j->dinfo); for(i=0; i<MAX_COMPONENTS; i++) { if(tmpbuf[i]) free(tmpbuf[i]); if(outbuf[i]) free(outbuf[i]); } if(_tmpbuf) free(_tmpbuf); if(row_pointer) free(row_pointer); return retval; }
int loadbmp(char *filename, unsigned char **buf, int *w, int *h, int dstpf, int bottomup) { int retval=0, dstps, srcpf, tempc; struct jpeg_compress_struct cinfo; struct my_error_mgr jerr; cjpeg_source_ptr src; FILE *file=NULL; if(!filename || !buf || !w || !h || dstpf<0 || dstpf>=TJ_NUMPF) _throw("loadbmp(): Invalid argument"); if((file=fopen(filename, "rb"))==NULL) _throwunix("loadbmp(): Cannot open input file"); cinfo.err=jpeg_std_error(&jerr.pub); jerr.pub.error_exit=my_error_exit; jerr.pub.output_message=my_output_message; if(setjmp(jerr.setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error. */ retval=-1; goto bailout; } jpeg_create_compress(&cinfo); if((tempc=getc(file))<0 || ungetc(tempc, file)==EOF) _throwunix("loadbmp(): Could not read input file") else if(tempc==EOF) _throw("loadbmp(): Input file contains no data"); if(tempc=='B') { if((src=jinit_read_bmp(&cinfo))==NULL) _throw("loadbmp(): Could not initialize bitmap loader"); } else if(tempc=='P') { if((src=jinit_read_ppm(&cinfo))==NULL) _throw("loadbmp(): Could not initialize bitmap loader"); } else _throw("loadbmp(): Unsupported file type"); src->input_file=file; (*src->start_input)(&cinfo, src); (*cinfo.mem->realize_virt_arrays)((j_common_ptr)&cinfo); *w=cinfo.image_width; *h=cinfo.image_height; if(cinfo.input_components==1 && cinfo.in_color_space==JCS_RGB) srcpf=TJPF_GRAY; else srcpf=TJPF_RGB; dstps=tjPixelSize[dstpf]; if((*buf=(unsigned char *)malloc((*w)*(*h)*dstps))==NULL) _throw("loadbmp(): Memory allocation failure"); while(cinfo.next_scanline<cinfo.image_height) { int i, nlines=(*src->get_pixel_rows)(&cinfo, src); for(i=0; i<nlines; i++) { unsigned char *outbuf; int row; row=cinfo.next_scanline+i; if(bottomup) outbuf=&(*buf)[((*h)-row-1)*(*w)*dstps]; else outbuf=&(*buf)[row*(*w)*dstps]; pixelconvert(src->buffer[i], srcpf, 0, outbuf, dstpf, bottomup, *w, nlines); } cinfo.next_scanline+=nlines; } (*src->finish_input)(&cinfo, src); bailout: jpeg_destroy_compress(&cinfo); if(file) fclose(file); if(retval<0 && buf && *buf) {free(*buf); *buf=NULL;} return retval; }
void Cyc_Array_qsort(int (* less_eq)(void * *,void * *),struct _fat_ptr arr, int len) { int _T0; unsigned int _T1; struct _fat_ptr _T2; unsigned int _T3; struct Cyc_Core_Invalid_argument_exn_struct * _T4; void * _T5; int _T6; struct _fat_ptr _T7; int _T8; int _T9; int _TA; int _TB; unsigned char * _TC; void * * _TD; struct _fat_ptr _TE; unsigned char * _TF; void * * _T10; int _T11; int _T12; int _T13; int _T14; struct _fat_ptr _T15; int _T16; unsigned char * _T17; void * * _T18; struct _fat_ptr _T19; unsigned char * _T1A; void * * _T1B; int _T1C; struct _fat_ptr _T1D; int _T1E; struct _fat_ptr _T1F; unsigned char * _T20; unsigned char * _T21; void * * _T22; struct _fat_ptr _T23; int _T24; struct _fat_ptr _T25; unsigned char * _T26; unsigned char * _T27; void * * _T28; int _T29; struct _fat_ptr _T2A; int _T2B; unsigned char * _T2C; void * * _T2D; struct _fat_ptr _T2E; unsigned char * _T2F; void * * _T30; int _T31; struct _fat_ptr _T32; int _T33; unsigned char * _T34; void * * _T35; struct _fat_ptr _T36; unsigned char * _T37; void * * _T38; int _T39; struct _fat_ptr _T3A; int _T3B; struct _fat_ptr _T3C; unsigned char * _T3D; unsigned char * _T3E; void * * _T3F; struct _fat_ptr _T40; int _T41; struct _fat_ptr _T42; unsigned char * _T43; unsigned char * _T44; void * * _T45; int _T46; struct _fat_ptr _T47; unsigned char * _T48; void * * _T49; int _T4A; struct _fat_ptr _T4B; unsigned char * _T4C; void * * _T4D; int _T4E; struct _fat_ptr _T4F; int _T50; unsigned char * _T51; void * * _T52; struct _fat_ptr _T53; unsigned char * _T54; void * * _T55; int _T56; struct _fat_ptr _T57; int _T58; struct _fat_ptr _T59; unsigned char * _T5A; unsigned char * _T5B; void * * _T5C; struct _fat_ptr _T5D; int _T5E; struct _fat_ptr _T5F; unsigned char * _T60; unsigned char * _T61; void * * _T62; int _T63; struct _fat_ptr _T64; int _T65; unsigned char * _T66; void * * _T67; struct _fat_ptr _T68; unsigned char * _T69; void * * _T6A; int _T6B; struct _fat_ptr _T6C; unsigned char * _T6D; void * * _T6E; int _T6F; struct _fat_ptr _T70; unsigned char * _T71; void * * _T72; int _T73; struct _fat_ptr _T74; int _T75; struct _fat_ptr _T76; unsigned char * _T77; unsigned char * _T78; void * * _T79; struct _fat_ptr _T7A; int _T7B; struct _fat_ptr _T7C; unsigned char * _T7D; unsigned char * _T7E; void * * _T7F; int _T80; struct _fat_ptr _T81; int _T82; struct _fat_ptr _T83; unsigned char * _T84; unsigned char * _T85; void * * _T86; struct _fat_ptr _T87; int _T88; struct _fat_ptr _T89; unsigned char * _T8A; unsigned char * _T8B; void * * _T8C; int _T8D; struct _fat_ptr _T8E; int _T8F; unsigned char * _T90; void * * _T91; struct _fat_ptr _T92; unsigned char * _T93; void * * _T94; int _T95; struct _fat_ptr _T96; int _T97; unsigned char * _T98; void * * _T99; struct _fat_ptr _T9A; unsigned char * _T9B; void * * _T9C; int _T9D; struct _fat_ptr _T9E; unsigned char * _T9F; void * * _TA0; int _TA1; struct _fat_ptr _TA2; unsigned char * _TA3; void * * _TA4; int _TA5; struct _fat_ptr _TA6; int _TA7; unsigned char * _TA8; void * * _TA9; struct _fat_ptr _TAA; unsigned char * _TAB; void * * _TAC; int _TAD; int _TAE; int _TAF; int * _TB0; int _TB1; char * _TB2; int * _TB3; int * _TB4; int _TB5; char * _TB6; int * _TB7; int * _TB8; int _TB9; char * _TBA; int * _TBB; int * _TBC; int _TBD; char * _TBE; int * _TBF; struct _fat_ptr _TC0; int _TC1; struct _fat_ptr _TC2; unsigned char * _TC3; unsigned char * _TC4; void * * _TC5; struct _fat_ptr _TC6; int _TC7; struct _fat_ptr _TC8; struct _fat_ptr _TC9; unsigned char * _TCA; unsigned char * _TCB; void * * _TCC; int _TCD; struct _fat_ptr _TCE; int _TCF; unsigned char * _TD0; void * * _TD1; struct _fat_ptr _TD2; unsigned char * _TD3; void * * _TD4; int _TD5; struct _fat_ptr _TD6; int _TD7; unsigned char * _TD8; void * * _TD9; struct _fat_ptr _TDA; unsigned char * _TDB; void * * _TDC; int _TDD; int * _TDE; int _TDF; char * _TE0; int * _TE1; int * _TE2; int _TE3; char * _TE4; int * _TE5; int base_ofs = 0; void * temp; int sp[40U]; int sp_ofs; int i; int j; int limit_ofs; if (base_ofs < 0) { goto _TL2; }else { goto _TL4; } _TL4: _T0 = base_ofs + len; _T1 = (unsigned int)_T0; _T2 = arr; _T3 = _get_fat_size(_T2,sizeof(void *)); if (_T1 > _T3) { goto _TL2; }else { goto _TL3; } _TL3: if (len < 0) { goto _TL2; }else { goto _TL0; } _TL2: { struct Cyc_Core_Invalid_argument_exn_struct * _TE6 = _cycalloc(sizeof(struct Cyc_Core_Invalid_argument_exn_struct)); _TE6->tag = Cyc_Core_Invalid_argument; _TE6->f1 = _tag_fat("Array::qsort",sizeof(char),13U); _T4 = (struct Cyc_Core_Invalid_argument_exn_struct *)_TE6; }_T5 = (void *)_T4; _throw(_T5); goto _TL1; _TL0: _TL1: limit_ofs = base_ofs + len; sp_ofs = 0; _TL8: if (1) { goto _TL6; }else { goto _TL7; } _TL6: _T6 = limit_ofs - base_ofs; if (_T6 <= 3) { goto _TL9; } _T7 = arr; _T8 = limit_ofs - base_ofs; _T9 = _T8 / 2; _TA = base_ofs; _TB = _T9 + _TA; _TC = _check_fat_subscript(_T7,sizeof(void *),_TB); _TD = (void * *)_TC; temp = *_TD; _TE = arr; _TF = _TE.curr; _T10 = (void * *)_TF; _T11 = limit_ofs - base_ofs; _T12 = _T11 / 2; _T13 = base_ofs; _T14 = _T12 + _T13; _T15 = arr; _T16 = base_ofs; _T17 = _check_fat_subscript(_T15,sizeof(void *),_T16); _T18 = (void * *)_T17; _T10[_T14] = *_T18; _T19 = arr; _T1A = _T19.curr; _T1B = (void * *)_T1A; _T1C = base_ofs; _T1B[_T1C] = temp; i = base_ofs + 1; j = limit_ofs - 1; _T1D = arr; _T1E = i; _T1F = _fat_ptr_plus(_T1D,sizeof(void *),_T1E); _T20 = _untag_fat_ptr_check_bound(_T1F,sizeof(void *),1U); _T21 = _check_null(_T20); _T22 = (void * *)_T21; _T23 = arr; _T24 = j; _T25 = _fat_ptr_plus(_T23,sizeof(void *),_T24); _T26 = _untag_fat_ptr_check_bound(_T25,sizeof(void *),1U); _T27 = _check_null(_T26); _T28 = (void * *)_T27; _T29 = less_eq(_T22,_T28); if (_T29 <= 0) { goto _TLB; } _T2A = arr; _T2B = i; _T2C = _check_fat_subscript(_T2A,sizeof(void *),_T2B); _T2D = (void * *)_T2C; temp = *_T2D; _T2E = arr; _T2F = _T2E.curr; _T30 = (void * *)_T2F; _T31 = i; _T32 = arr; _T33 = j; _T34 = _check_fat_subscript(_T32,sizeof(void *),_T33); _T35 = (void * *)_T34; _T30[_T31] = *_T35; _T36 = arr; _T37 = _T36.curr; _T38 = (void * *)_T37; _T39 = j; _T38[_T39] = temp; goto _TLC; _TLB: _TLC: _T3A = arr; _T3B = base_ofs; _T3C = _fat_ptr_plus(_T3A,sizeof(void *),_T3B); _T3D = _untag_fat_ptr_check_bound(_T3C,sizeof(void *),1U); _T3E = _check_null(_T3D); _T3F = (void * *)_T3E; _T40 = arr; _T41 = j; _T42 = _fat_ptr_plus(_T40,sizeof(void *),_T41); _T43 = _untag_fat_ptr(_T42,sizeof(void *),1U); _T44 = _check_null(_T43); _T45 = (void * *)_T44; _T46 = less_eq(_T3F,_T45); if (_T46 <= 0) { goto _TLD; } _T47 = arr; _T48 = _T47.curr; _T49 = (void * *)_T48; _T4A = base_ofs; temp = _T49[_T4A]; _T4B = arr; _T4C = _T4B.curr; _T4D = (void * *)_T4C; _T4E = base_ofs; _T4F = arr; _T50 = j; _T51 = _check_fat_subscript(_T4F,sizeof(void *),_T50); _T52 = (void * *)_T51; _T4D[_T4E] = *_T52; _T53 = arr; _T54 = _T53.curr; _T55 = (void * *)_T54; _T56 = j; _T55[_T56] = temp; goto _TLE; _TLD: _TLE: _T57 = arr; _T58 = i; _T59 = _fat_ptr_plus(_T57,sizeof(void *),_T58); _T5A = _untag_fat_ptr(_T59,sizeof(void *),1U); _T5B = _check_null(_T5A); _T5C = (void * *)_T5B; _T5D = arr; _T5E = base_ofs; _T5F = _fat_ptr_plus(_T5D,sizeof(void *),_T5E); _T60 = _untag_fat_ptr(_T5F,sizeof(void *),1U); _T61 = _check_null(_T60); _T62 = (void * *)_T61; _T63 = less_eq(_T5C,_T62); if (_T63 <= 0) { goto _TLF; } _T64 = arr; _T65 = i; _T66 = _check_fat_subscript(_T64,sizeof(void *),_T65); _T67 = (void * *)_T66; temp = *_T67; _T68 = arr; _T69 = _T68.curr; _T6A = (void * *)_T69; _T6B = i; _T6C = arr; _T6D = _T6C.curr; _T6E = (void * *)_T6D; _T6F = base_ofs; _T6A[_T6B] = _T6E[_T6F]; _T70 = arr; _T71 = _T70.curr; _T72 = (void * *)_T71; _T73 = base_ofs; _T72[_T73] = temp; goto _TL10; _TLF: _TL10: _TL14: if (1) { goto _TL12; }else { goto _TL13; } _TL12: _TL15: i = i + 1; _T74 = arr; _T75 = i; _T76 = _fat_ptr_plus(_T74,sizeof(void *),_T75); _T77 = _untag_fat_ptr_check_bound(_T76,sizeof(void *),1U); _T78 = _check_null(_T77); _T79 = (void * *)_T78; _T7A = arr; _T7B = base_ofs; _T7C = _fat_ptr_plus(_T7A,sizeof(void *),_T7B); _T7D = _untag_fat_ptr(_T7C,sizeof(void *),1U); _T7E = _check_null(_T7D); _T7F = (void * *)_T7E; _T80 = less_eq(_T79,_T7F); if (_T80 < 0) { goto _TL15; }else { goto _TL16; } _TL16: _TL17: j = j + -1; _T81 = arr; _T82 = j; _T83 = _fat_ptr_plus(_T81,sizeof(void *),_T82); _T84 = _untag_fat_ptr_check_bound(_T83,sizeof(void *),1U); _T85 = _check_null(_T84); _T86 = (void * *)_T85; _T87 = arr; _T88 = base_ofs; _T89 = _fat_ptr_plus(_T87,sizeof(void *),_T88); _T8A = _untag_fat_ptr(_T89,sizeof(void *),1U); _T8B = _check_null(_T8A); _T8C = (void * *)_T8B; _T8D = less_eq(_T86,_T8C); if (_T8D > 0) { goto _TL17; }else { goto _TL18; } _TL18: if (i <= j) { goto _TL19; } goto _TL13; _TL19: _T8E = arr; _T8F = i; _T90 = _check_fat_subscript(_T8E,sizeof(void *),_T8F); _T91 = (void * *)_T90; temp = *_T91; _T92 = arr; _T93 = _T92.curr; _T94 = (void * *)_T93; _T95 = i; _T96 = arr; _T97 = j; _T98 = _check_fat_subscript(_T96,sizeof(void *),_T97); _T99 = (void * *)_T98; _T94[_T95] = *_T99; _T9A = arr; _T9B = _T9A.curr; _T9C = (void * *)_T9B; _T9D = j; _T9C[_T9D] = temp; goto _TL14; _TL13: _T9E = arr; _T9F = _T9E.curr; _TA0 = (void * *)_T9F; _TA1 = base_ofs; temp = _TA0[_TA1]; _TA2 = arr; _TA3 = _TA2.curr; _TA4 = (void * *)_TA3; _TA5 = base_ofs; _TA6 = arr; _TA7 = j; _TA8 = _check_fat_subscript(_TA6,sizeof(void *),_TA7); _TA9 = (void * *)_TA8; _TA4[_TA5] = *_TA9; _TAA = arr; _TAB = _TAA.curr; _TAC = (void * *)_TAB; _TAD = j; _TAC[_TAD] = temp; _TAE = j - base_ofs; _TAF = limit_ofs - i; if (_TAE <= _TAF) { goto _TL1B; } _TB0 = sp; _TB1 = sp_ofs; _TB2 = _check_known_subscript_notnull(_TB0,40U,sizeof(int),_TB1); _TB3 = (int *)_TB2; *_TB3 = base_ofs; _TB4 = sp; _TB5 = sp_ofs + 1; _TB6 = _check_known_subscript_notnull(_TB4,40U,sizeof(int),_TB5); _TB7 = (int *)_TB6; *_TB7 = j; base_ofs = i; goto _TL1C; _TL1B: _TB8 = sp; _TB9 = sp_ofs; _TBA = _check_known_subscript_notnull(_TB8,40U,sizeof(int),_TB9); _TBB = (int *)_TBA; *_TBB = i; _TBC = sp; _TBD = sp_ofs + 1; _TBE = _check_known_subscript_notnull(_TBC,40U,sizeof(int),_TBD); _TBF = (int *)_TBE; *_TBF = limit_ofs; limit_ofs = j; _TL1C: sp_ofs = sp_ofs + 2; goto _TLA; _TL9: j = base_ofs; i = j + 1; _TL20: if (i < limit_ofs) { goto _TL1E; }else { goto _TL1F; } _TL1E: _TL24: _TC0 = arr; _TC1 = j; _TC2 = _fat_ptr_plus(_TC0,sizeof(void *),_TC1); _TC3 = _untag_fat_ptr_check_bound(_TC2,sizeof(void *),1U); _TC4 = _check_null(_TC3); _TC5 = (void * *)_TC4; _TC6 = arr; _TC7 = j; _TC8 = _fat_ptr_plus(_TC6,sizeof(void *),_TC7); _TC9 = _fat_ptr_plus(_TC8,sizeof(void *),1); _TCA = _untag_fat_ptr_check_bound(_TC9,sizeof(void *),1U); _TCB = _check_null(_TCA); _TCC = (void * *)_TCB; _TCD = less_eq(_TC5,_TCC); if (_TCD > 0) { goto _TL22; }else { goto _TL23; } _TL22: _TCE = arr; _TCF = j; _TD0 = _check_fat_subscript(_TCE,sizeof(void *),_TCF); _TD1 = (void * *)_TD0; temp = *_TD1; _TD2 = arr; _TD3 = _TD2.curr; _TD4 = (void * *)_TD3; _TD5 = j; _TD6 = arr; _TD7 = j + 1; _TD8 = _check_fat_subscript(_TD6,sizeof(void *),_TD7); _TD9 = (void * *)_TD8; _TD4[_TD5] = *_TD9; _TDA = arr; _TDB = _TDA.curr; _TDC = (void * *)_TDB; _TDD = j + 1; _TDC[_TDD] = temp; if (j != base_ofs) { goto _TL25; } goto _TL23; _TL25: j = j + -1; goto _TL24; _TL23: j = i; i = i + 1; goto _TL20; _TL1F: if (sp_ofs == 0) { goto _TL27; } sp_ofs = sp_ofs - 2; _TDE = sp; _TDF = sp_ofs; _TE0 = _check_known_subscript_notnull(_TDE,40U,sizeof(int),_TDF); _TE1 = (int *)_TE0; base_ofs = *_TE1; _TE2 = sp; _TE3 = sp_ofs + 1; _TE4 = _check_known_subscript_notnull(_TE2,40U,sizeof(int),_TE3); _TE5 = (int *)_TE4; limit_ofs = *_TE5; goto _TL28; _TL27: goto _TL7; _TL28: _TLA: goto _TL8; _TL7: ; }
int savebmp(char *filename, unsigned char *buf, int w, int h, int srcpf, int bottomup) { int retval=0, srcps, dstpf; struct jpeg_decompress_struct dinfo; struct my_error_mgr jerr; djpeg_dest_ptr dst; FILE *file=NULL; char *ptr=NULL; if(!filename || !buf || w<1 || h<1 || srcpf<0 || srcpf>=TJ_NUMPF) _throw("savebmp(): Invalid argument"); if((file=fopen(filename, "wb"))==NULL) _throwunix("savebmp(): Cannot open output file"); dinfo.err=jpeg_std_error(&jerr.pub); jerr.pub.error_exit=my_error_exit; jerr.pub.output_message=my_output_message; if(setjmp(jerr.setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error. */ retval=-1; goto bailout; } jpeg_create_decompress(&dinfo); if(srcpf==TJPF_GRAY) { dinfo.out_color_components=dinfo.output_components=1; dinfo.out_color_space=JCS_GRAYSCALE; } else { dinfo.out_color_components=dinfo.output_components=3; dinfo.out_color_space=JCS_RGB; } dinfo.image_width=w; dinfo.image_height=h; dinfo.global_state=DSTATE_READY; dinfo.scale_num=dinfo.scale_denom=1; ptr=strrchr(filename, '.'); if(ptr && !strcasecmp(ptr, ".bmp")) { if((dst=jinit_write_bmp(&dinfo, 0))==NULL) _throw("savebmp(): Could not initialize bitmap writer"); } else { if((dst=jinit_write_ppm(&dinfo))==NULL) _throw("savebmp(): Could not initialize PPM writer"); } dst->output_file=file; (*dst->start_output)(&dinfo, dst); (*dinfo.mem->realize_virt_arrays)((j_common_ptr)&dinfo); if(srcpf==TJPF_GRAY) dstpf=srcpf; else dstpf=TJPF_RGB; srcps=tjPixelSize[srcpf]; while(dinfo.output_scanline<dinfo.output_height) { int i, nlines=dst->buffer_height; for(i=0; i<nlines; i++) { unsigned char *inbuf; int row; row=dinfo.output_scanline+i; if(bottomup) inbuf=&buf[(h-row-1)*w*srcps]; else inbuf=&buf[row*w*srcps]; pixelconvert(inbuf, srcpf, bottomup, dst->buffer[i], dstpf, 0, w, nlines); } (*dst->put_pixel_rows)(&dinfo, dst, nlines); dinfo.output_scanline+=nlines; } (*dst->finish_output)(&dinfo, dst); bailout: jpeg_destroy_decompress(&dinfo); if(file) fclose(file); return retval; }
struct _fat_ptr Cyc_Array_zip(struct _fat_ptr x,struct _fat_ptr y) { struct _fat_ptr _T0; unsigned int _T1; int _T2; unsigned int _T3; struct _fat_ptr _T4; unsigned int _T5; struct Cyc_Array_Array_mismatch_exn_struct * _T6; struct Cyc_Array_Array_mismatch_exn_struct * _T7; struct _fat_ptr _T8; int _T9; struct _tuple0 * _TA; unsigned int _TB; unsigned int _TC; struct _fat_ptr _TD; unsigned char * _TE; void * * _TF; void * * _T10; unsigned int _T11; int _T12; unsigned int _T13; struct _fat_ptr _T14; unsigned char * _T15; void * * _T16; void * * _T17; unsigned int _T18; int _T19; _T0 = x; _T1 = _get_fat_size(_T0,sizeof(void *)); { int sx = (int)_T1; _T2 = sx; _T3 = (unsigned int)_T2; _T4 = y; _T5 = _get_fat_size(_T4,sizeof(void *)); if (_T3 == _T5) { goto _TLC2; } _T6 = &Cyc_Array_Array_mismatch_val; _T7 = (struct Cyc_Array_Array_mismatch_exn_struct *)_T6; _throw(_T7); goto _TLC3; _TLC2: _TLC3: _T9 = sx; { unsigned int _T1A = (unsigned int)_T9; _TB = _check_times(_T1A,sizeof(struct _tuple0)); { struct _tuple0 * _T1B = _cycalloc(_TB); { unsigned int _T1C = _T1A; unsigned int i; i = 0; _TLC7: if (i < _T1C) { goto _TLC5; }else { goto _TLC6; } _TLC5: _TC = i; _TD = x; _TE = _TD.curr; _TF = (void * *)_TE; _T10 = _check_null(_TF); _T11 = i; _T12 = (int)_T11; (_T1B[_TC]).f0 = _T10[_T12]; _T13 = i; _T14 = y; _T15 = _T14.curr; _T16 = (void * *)_T15; _T17 = _check_null(_T16); _T18 = i; _T19 = (int)_T18; (_T1B[_T13]).f1 = _T17[_T19]; i = i + 1; goto _TLC7; _TLC6: ; }_TA = (struct _tuple0 *)_T1B; }_T8 = _tag_fat(_TA,sizeof(struct _tuple0),_T1A); }return _T8; } }
static int setCompDefaults(struct jpeg_compress_struct *cinfo, int pixelFormat, int subsamp, int jpegQual) { int retval=0; switch(pixelFormat) { case TJPF_GRAY: cinfo->in_color_space=JCS_GRAYSCALE; break; #if JCS_EXTENSIONS==1 case TJPF_RGB: cinfo->in_color_space=JCS_EXT_RGB; break; case TJPF_BGR: cinfo->in_color_space=JCS_EXT_BGR; break; case TJPF_RGBX: case TJPF_RGBA: cinfo->in_color_space=JCS_EXT_RGBX; break; case TJPF_BGRX: case TJPF_BGRA: cinfo->in_color_space=JCS_EXT_BGRX; break; case TJPF_XRGB: case TJPF_ARGB: cinfo->in_color_space=JCS_EXT_XRGB; break; case TJPF_XBGR: case TJPF_ABGR: cinfo->in_color_space=JCS_EXT_XBGR; break; #else case TJPF_RGB: if(RGB_RED==0 && RGB_GREEN==1 && RGB_BLUE==2 && RGB_PIXELSIZE==3) { cinfo->in_color_space=JCS_RGB; break; } default: _throw("Unsupported pixel format"); #endif } cinfo->input_components=tjPixelSize[pixelFormat]; jpeg_set_defaults(cinfo); if(jpegQual>=0) { jpeg_set_quality(cinfo, jpegQual, TRUE); if(jpegQual>=96) cinfo->dct_method=JDCT_ISLOW; else cinfo->dct_method=JDCT_FASTEST; } if(subsamp==TJSAMP_GRAY) jpeg_set_colorspace(cinfo, JCS_GRAYSCALE); else jpeg_set_colorspace(cinfo, JCS_YCbCr); cinfo->comp_info[0].h_samp_factor=tjMCUWidth[subsamp]/8; cinfo->comp_info[1].h_samp_factor=1; cinfo->comp_info[2].h_samp_factor=1; cinfo->comp_info[0].v_samp_factor=tjMCUHeight[subsamp]/8; cinfo->comp_info[1].v_samp_factor=1; cinfo->comp_info[2].v_samp_factor=1; #if JCS_EXTENSIONS!=1 bailout: #endif return retval; }
struct _fat_ptr Cyc_Array_extract(struct _fat_ptr x,int start,int * n_opt) { struct _fat_ptr _T0; unsigned int _T1; int _T2; int * _T3; int _T4; int _T5; int _T6; int _T7; struct Cyc_Core_Invalid_argument_exn_struct * _T8; void * _T9; struct _fat_ptr _TA; int _TB; void * * _TC; unsigned int _TD; unsigned int _TE; struct _fat_ptr _TF; int _T10; unsigned int _T11; unsigned int _T12; unsigned int _T13; int _T14; unsigned char * _T15; void * * _T16; _T0 = x; _T1 = _get_fat_size(_T0,sizeof(void *)); { int sx = (int)_T1; if (n_opt != 0) { goto _TLDC; } _T2 = sx - start; goto _TLDD; _TLDC: _T3 = n_opt; _T2 = *_T3; _TLDD: { int n = _T2; if (start < 0) { goto _TLE0; }else { goto _TLE2; } _TLE2: if (n <= 0) { goto _TLE0; }else { goto _TLE1; } _TLE1: _T4 = start; if (n_opt != 0) { goto _TLE3; } _T5 = 0; goto _TLE4; _TLE3: _T5 = n; _TLE4: _T6 = _T4 + _T5; _T7 = sx; if (_T6 > _T7) { goto _TLE0; }else { goto _TLDE; } _TLE0: { struct Cyc_Core_Invalid_argument_exn_struct * _T17 = _cycalloc(sizeof(struct Cyc_Core_Invalid_argument_exn_struct)); _T17->tag = Cyc_Core_Invalid_argument; _T17->f1 = _tag_fat("Array::extract",sizeof(char),15U); _T8 = (struct Cyc_Core_Invalid_argument_exn_struct *)_T17; }_T9 = (void *)_T8; _throw(_T9); goto _TLDF; _TLDE: _TLDF: _TB = n; { unsigned int _T17 = (unsigned int)_TB; _TD = _check_times(_T17,sizeof(void *)); { void * * _T18 = _cycalloc(_TD); { unsigned int _T19 = _T17; unsigned int i; i = 0; _TLE8: if (i < _T19) { goto _TLE6; }else { goto _TLE7; } _TLE6: _TE = i; _TF = x; _T10 = start; _T11 = (unsigned int)_T10; _T12 = i; _T13 = _T11 + _T12; _T14 = (int)_T13; _T15 = _check_fat_subscript(_TF,sizeof(void *),_T14); _T16 = (void * *)_T15; _T18[_TE] = *_T16; i = i + 1; goto _TLE8; _TLE7: ; }_TC = (void * *)_T18; }_TA = _tag_fat(_TC,sizeof(void *),_T17); }return _TA; } } }
struct Cyc_APQ_T*Cyc_APQ_fromstr(struct _fat_ptr str,int base){void*_T0;struct _fat_ptr _T1;unsigned char*_T2;const char*_T3;char _T4;int _T5;struct _fat_ptr _T6;unsigned char*_T7;const char*_T8;char _T9;int _TA;struct _fat_ptr*_TB;struct Cyc_APQ_T*_TC;struct _fat_ptr _TD;unsigned char*_TE;const char*_TF;int _T10;struct _fat_ptr _T11;unsigned char*_T12;const char*_T13;char _T14;int _T15;struct _fat_ptr _T16;struct _fat_ptr _T17;unsigned char*_T18;const char*_T19;int _T1A;int _T1B;struct Cyc_APQ_T*_T1C;struct Cyc_Invalid_argument_exn_struct*_T1D;void*_T1E;struct Cyc_APQ_T*_T1F;struct Cyc_APQ_T*_T20;_T0=_cycalloc(sizeof(struct Cyc_APQ_T));{ struct Cyc_APQ_T*q=(struct Cyc_APQ_T*)_T0; struct _fat_ptr s=str; _TL6: _T1=s;_T2=_check_fat_subscript(_T1,sizeof(char),0U);_T3=(const char*)_T2;_T4=*_T3;_T5=(int)_T4;if(_T5)goto _TL9;else{goto _TL8;}_TL9: _T6=s;_T7=_T6.curr;_T8=(const char*)_T7;_T9=*_T8;_TA=(int)_T9;if(_TA!=47)goto _TL7;else{goto _TL8;}_TL7: _TB=& s;_fat_ptr_inplace_plus(_TB,sizeof(char),1);goto _TL6;_TL8: _TC=q;_TD=str;_TE=_untag_fat_ptr_check_bound(_TD,sizeof(char),1U);_TF=(const char*)_TE;_T10=base; _TC->n=Cyc_AP_fromstr(_TF,_T10);_T11=s;_T12=_T11.curr;_T13=(const char*)_T12;_T14=*_T13;_T15=(int)_T14; if(!_T15)goto _TLA;_T16=s;_T17= _fat_ptr_plus(_T16,sizeof(char),1);_T18=_untag_fat_ptr_check_bound(_T17,sizeof(char),1U);_T19=(const char*)_T18;_T1A=base;{struct Cyc_AP_T*d=Cyc_AP_fromstr(_T19,_T1A);_T1B= Cyc_AP_cmp(d,Cyc_AP_zero);if(!_T1B)goto _TLC;_T1C=q; _T1C->d=d;goto _TLD; _TLC:{struct Cyc_Invalid_argument_exn_struct*_T21=_cycalloc(sizeof(struct Cyc_Invalid_argument_exn_struct));_T21->tag=Cyc_Invalid_argument;_T21->f1=_tag_fat("APQ_fromstr: malformed string",sizeof(char),30U);_T1D=(struct Cyc_Invalid_argument_exn_struct*)_T21;}_T1E=(void*)_T1D;_throw(_T1E);_TLD:;}goto _TLB; # 54 _TLA: _T1F=q;_T1F->d=Cyc_AP_one;_TLB: _T20= Cyc_reduce(q);return _T20;}}
void Cyc_Array_msort(int (* less_eq)(void * *,void * *),struct _fat_ptr arr, int len) { int _T0; unsigned int _T1; struct _fat_ptr _T2; unsigned int _T3; struct Cyc_Core_Invalid_argument_exn_struct * _T4; void * _T5; struct _fat_ptr _T6; int _T7; void * * _T8; unsigned int _T9; unsigned int _TA; struct _fat_ptr _TB; unsigned char * _TC; void * * _TD; void * * _TE; int _TF; int _T10; int _T11; int _T12; int _T13; int _T14; int _T15; int _T16; int _T17; int _T18; struct _fat_ptr _T19; int _T1A; struct _fat_ptr _T1B; unsigned char * _T1C; unsigned char * _T1D; void * * _T1E; struct _fat_ptr _T1F; int _T20; struct _fat_ptr _T21; unsigned char * _T22; unsigned char * _T23; void * * _T24; int _T25; struct _fat_ptr _T26; int _T27; int _T28; unsigned char * _T29; void * * _T2A; struct _fat_ptr _T2B; int _T2C; int _T2D; unsigned char * _T2E; void * * _T2F; struct _fat_ptr _T30; int _T31; int _T32; unsigned char * _T33; void * * _T34; struct _fat_ptr _T35; int _T36; int _T37; unsigned char * _T38; void * * _T39; struct _fat_ptr _T3A; int _T3B; int _T3C; unsigned char * _T3D; void * * _T3E; struct _fat_ptr _T3F; int _T40; int _T41; unsigned char * _T42; void * * _T43; struct _fat_ptr _T44; int _T45; int _T46; unsigned char * _T47; void * * _T48; struct _fat_ptr _T49; int _T4A; int _T4B; unsigned char * _T4C; void * * _T4D; int _T4E; int _T4F; long _T50; struct _fat_ptr _T51; unsigned char * _T52; void * * _T53; int _T54; struct _fat_ptr _T55; unsigned char * _T56; void * * _T57; int _T58; _T0 = len; _T1 = (unsigned int)_T0; _T2 = arr; _T3 = _get_fat_size(_T2,sizeof(void *)); if (_T1 > _T3) { goto _TL2B; }else { goto _TL2C; } _TL2C: if (len < 0) { goto _TL2B; }else { goto _TL29; } _TL2B: { struct Cyc_Core_Invalid_argument_exn_struct * _T59 = _cycalloc(sizeof(struct Cyc_Core_Invalid_argument_exn_struct)); _T59->tag = Cyc_Core_Invalid_argument; _T59->f1 = _tag_fat("Array::msort",sizeof(char),13U); _T4 = (struct Cyc_Core_Invalid_argument_exn_struct *)_T59; }_T5 = (void *)_T4; _throw(_T5); goto _TL2A; _TL29: _TL2A: _T7 = len; { unsigned int _T59 = (unsigned int)_T7; _T9 = _check_times(_T59,sizeof(void *)); { void * * _T5A = _cycalloc(_T9); { unsigned int _T5B = _T59; unsigned int i; i = 0; _TL30: if (i < _T5B) { goto _TL2E; }else { goto _TL2F; } _TL2E: _TA = i; _TB = arr; _TC = _TB.curr; _TD = (void * *)_TC; _TE = _check_null(_TD); _T5A[_TA] = _TE[0]; i = i + 1; goto _TL30; _TL2F: ; }_T8 = (void * *)_T5A; }_T6 = _tag_fat(_T8,sizeof(void *),_T59); }{ struct _fat_ptr from = _T6; struct _fat_ptr to = arr; struct _fat_ptr swap; long swapped = 0; int stepsize; int start; int lstart; int lend; int rstart; int rend; int dest; stepsize = 1; _TL34: if (stepsize < len) { goto _TL32; }else { goto _TL33; } _TL32: swap = from; from = to; to = swap; dest = 0; start = 0; _TL38: if (start < len) { goto _TL36; }else { goto _TL37; } _TL36: lstart = start; _T10 = start + stepsize; _T11 = len; if (_T10 >= _T11) { goto _TL39; } _TF = start + stepsize; goto _TL3A; _TL39: _TF = len; _TL3A: rstart = _TF; lend = rstart; _T13 = start; _T14 = stepsize * 2; _T15 = _T13 + _T14; _T16 = len; if (_T15 >= _T16) { goto _TL3B; } _T17 = start; _T18 = stepsize * 2; _T12 = _T17 + _T18; goto _TL3C; _TL3B: _T12 = len; _TL3C: rend = _T12; _TL3D: if (lstart < lend) { goto _TL40; }else { goto _TL3F; } _TL40: if (rstart < rend) { goto _TL3E; }else { goto _TL3F; } _TL3E: _T19 = from; _T1A = lstart; _T1B = _fat_ptr_plus(_T19,sizeof(void *),_T1A); _T1C = _untag_fat_ptr_check_bound(_T1B,sizeof(void *),1U); _T1D = _check_null(_T1C); _T1E = (void * *)_T1D; _T1F = from; _T20 = rstart; _T21 = _fat_ptr_plus(_T1F,sizeof(void *),_T20); _T22 = _untag_fat_ptr_check_bound(_T21,sizeof(void *),1U); _T23 = _check_null(_T22); _T24 = (void * *)_T23; _T25 = less_eq(_T1E,_T24); if (_T25 > 0) { goto _TL41; } _T26 = to; _T27 = dest; dest = _T27 + 1; _T28 = _T27; _T29 = _check_fat_subscript(_T26,sizeof(void *),_T28); _T2A = (void * *)_T29; _T2B = from; _T2C = lstart; lstart = _T2C + 1; _T2D = _T2C; _T2E = _check_fat_subscript(_T2B,sizeof(void *),_T2D); _T2F = (void * *)_T2E; *_T2A = *_T2F; goto _TL42; _TL41: _T30 = to; _T31 = dest; dest = _T31 + 1; _T32 = _T31; _T33 = _check_fat_subscript(_T30,sizeof(void *),_T32); _T34 = (void * *)_T33; _T35 = from; _T36 = rstart; rstart = _T36 + 1; _T37 = _T36; _T38 = _check_fat_subscript(_T35,sizeof(void *),_T37); _T39 = (void * *)_T38; *_T34 = *_T39; _TL42: goto _TL3D; _TL3F: _TL43: if (lstart < lend) { goto _TL44; }else { goto _TL45; } _TL44: _T3A = to; _T3B = dest; dest = _T3B + 1; _T3C = _T3B; _T3D = _check_fat_subscript(_T3A,sizeof(void *),_T3C); _T3E = (void * *)_T3D; _T3F = from; _T40 = lstart; lstart = _T40 + 1; _T41 = _T40; _T42 = _check_fat_subscript(_T3F,sizeof(void *),_T41); _T43 = (void * *)_T42; *_T3E = *_T43; goto _TL43; _TL45: _TL46: if (rstart < rend) { goto _TL47; }else { goto _TL48; } _TL47: _T44 = to; _T45 = dest; dest = _T45 + 1; _T46 = _T45; _T47 = _check_fat_subscript(_T44,sizeof(void *),_T46); _T48 = (void * *)_T47; _T49 = from; _T4A = rstart; rstart = _T4A + 1; _T4B = _T4A; _T4C = _check_fat_subscript(_T49,sizeof(void *),_T4B); _T4D = (void * *)_T4C; *_T48 = *_T4D; goto _TL46; _TL48: _T4E = start; _T4F = stepsize * 2; start = _T4E + _T4F; goto _TL38; _TL37: stepsize = stepsize * 2; goto _TL34; _TL33: _T50 = swapped; if (! _T50) { goto _TL49; } { int i = 0; _TL4E: if (i < len) { goto _TL4C; }else { goto _TL4D; } _TL4C: _T51 = from; _T52 = _T51.curr; _T53 = (void * *)_T52; _T54 = i; _T55 = to; _T56 = _T55.curr; _T57 = (void * *)_T56; _T58 = i; _T53[_T54] = _T57[_T58]; i = i + 1; goto _TL4E; _TL4D: ; }goto _TL4A; _TL49: _TL4A: ; } }
DLLEXPORT int DLLCALL tjCompress(tjhandle h, unsigned char *srcbuf, int width, int pitch, int height, int ps, unsigned char *dstbuf, unsigned long *size, int jpegsub, int qual, int flags) { int i; JSAMPROW *row_pointer=NULL; checkhandle(h); if(srcbuf==NULL || width<=0 || pitch<0 || height<=0 || dstbuf==NULL || size==NULL || jpegsub<0 || jpegsub>=NUMSUBOPT || qual<0 || qual>100) _throw("Invalid argument in tjCompress()"); if(ps!=3 && ps!=4) _throw("This compressor can only take 24-bit or 32-bit RGB input"); if(!j->initc) _throw("Instance has not been initialized for compression"); if(pitch==0) pitch=width*ps; j->cinfo.rgb_pixelsize = ps; j->cinfo.rgb_green = 1; if(flags&TJ_BGR) {j->cinfo.rgb_red = 2; j->cinfo.rgb_blue = 0;} else {j->cinfo.rgb_red = 0; j->cinfo.rgb_blue = 2;} if(flags&TJ_ALPHAFIRST) { j->cinfo.rgb_red++; j->cinfo.rgb_green++; j->cinfo.rgb_blue++; } j->cinfo.image_width = width; j->cinfo.image_height = height; j->cinfo.input_components = ps; j->cinfo.in_color_space = JCS_RGB; if(setjmp(j->jerr.jb)) { // this will execute if LIBJPEG has an error if(row_pointer) free(row_pointer); return -1; } jpeg_set_defaults(&j->cinfo); jpeg_set_quality(&j->cinfo, qual, TRUE); if(jpegsub==TJ_GRAYSCALE) jpeg_set_colorspace(&j->cinfo, JCS_GRAYSCALE); else jpeg_set_colorspace(&j->cinfo, JCS_YCbCr); j->cinfo.dct_method = JDCT_FASTEST; j->cinfo.comp_info[0].h_samp_factor=hsampfactor[jpegsub]; j->cinfo.comp_info[1].h_samp_factor=1; j->cinfo.comp_info[2].h_samp_factor=1; j->cinfo.comp_info[0].v_samp_factor=vsampfactor[jpegsub]; j->cinfo.comp_info[1].v_samp_factor=1; j->cinfo.comp_info[2].v_samp_factor=1; j->jdms.next_output_byte = dstbuf; j->jdms.free_in_buffer = TJBUFSIZE(j->cinfo.image_width, j->cinfo.image_height); if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*height))==NULL) _throw("Memory allocation failed in tjInitCompress()"); for(i=0; i<height; i++) { if(flags&TJ_BOTTOMUP) row_pointer[i]= &srcbuf[(height-i-1)*pitch]; else row_pointer[i]= &srcbuf[i*pitch]; } jpeg_start_compress(&j->cinfo, TRUE); while(j->cinfo.next_scanline<j->cinfo.image_height) { jpeg_write_scanlines(&j->cinfo, &row_pointer[j->cinfo.next_scanline], j->cinfo.image_height-j->cinfo.next_scanline); } jpeg_finish_compress(&j->cinfo); *size=TJBUFSIZE(j->cinfo.image_width, j->cinfo.image_height)-(j->jdms.free_in_buffer); if(row_pointer) free(row_pointer); return 0; }
int loadbmp(char *filename, unsigned char **buf, int *w, int *h, enum BMPPIXELFORMAT f, int align, int dstbottomup) { int fd=-1, bytesread, srcpitch, srcbottomup=1, srcps, dstpitch, retcode=0; unsigned char *tempbuf=NULL; bmphdr bh; int flags=O_RDONLY; dstbottomup=dstbottomup? 1:0; #ifdef _WIN32 flags|=O_BINARY; #endif if(!filename || !buf || !w || !h || f<0 || f>BMPPIXELFORMATS-1 || align<1) _throw("invalid argument to loadbmp()"); if((align&(align-1))!=0) _throw("Alignment must be a power of 2"); _unix(fd=open(filename, flags)); readme(fd, &bh.bfType, sizeof(unsigned short)); if(!littleendian()) bh.bfType=byteswap16(bh.bfType); if(bh.bfType==0x3650) { _catch(loadppm(&fd, buf, w, h, f, align, dstbottomup, 0)); goto finally; } if(bh.bfType==0x3350) { _catch(loadppm(&fd, buf, w, h, f, align, dstbottomup, 1)); goto finally; } readme(fd, &bh.bfSize, sizeof(unsigned int)); readme(fd, &bh.bfReserved1, sizeof(unsigned short)); readme(fd, &bh.bfReserved2, sizeof(unsigned short)); readme(fd, &bh.bfOffBits, sizeof(unsigned int)); readme(fd, &bh.biSize, sizeof(unsigned int)); readme(fd, &bh.biWidth, sizeof(int)); readme(fd, &bh.biHeight, sizeof(int)); readme(fd, &bh.biPlanes, sizeof(unsigned short)); readme(fd, &bh.biBitCount, sizeof(unsigned short)); readme(fd, &bh.biCompression, sizeof(unsigned int)); readme(fd, &bh.biSizeImage, sizeof(unsigned int)); readme(fd, &bh.biXPelsPerMeter, sizeof(int)); readme(fd, &bh.biYPelsPerMeter, sizeof(int)); readme(fd, &bh.biClrUsed, sizeof(unsigned int)); readme(fd, &bh.biClrImportant, sizeof(unsigned int)); if(!littleendian()) { bh.bfSize=byteswap(bh.bfSize); bh.bfOffBits=byteswap(bh.bfOffBits); bh.biSize=byteswap(bh.biSize); bh.biWidth=byteswap(bh.biWidth); bh.biHeight=byteswap(bh.biHeight); bh.biPlanes=byteswap16(bh.biPlanes); bh.biBitCount=byteswap16(bh.biBitCount); bh.biCompression=byteswap(bh.biCompression); bh.biSizeImage=byteswap(bh.biSizeImage); bh.biXPelsPerMeter=byteswap(bh.biXPelsPerMeter); bh.biYPelsPerMeter=byteswap(bh.biYPelsPerMeter); bh.biClrUsed=byteswap(bh.biClrUsed); bh.biClrImportant=byteswap(bh.biClrImportant); } if(bh.bfType!=0x4d42 || bh.bfOffBits<BMPHDRSIZE || bh.biWidth<1 || bh.biHeight==0) _throw("Corrupt bitmap header"); if((bh.biBitCount!=24 && bh.biBitCount!=32) || bh.biCompression!=BI_RGB) _throw("Only uncompessed RGB bitmaps are supported"); *w=bh.biWidth; *h=bh.biHeight; srcps=bh.biBitCount/8; if(*h<0) {*h=-(*h); srcbottomup=0;} srcpitch=(((*w)*srcps)+3)&(~3); dstpitch=(((*w)*ps[f])+(align-1))&(~(align-1)); if(srcpitch*(*h)+bh.bfOffBits!=bh.bfSize) _throw("Corrupt bitmap header"); if((tempbuf=(unsigned char *)malloc(srcpitch*(*h)))==NULL || (*buf=(unsigned char *)malloc(dstpitch*(*h)))==NULL) _throw("Memory allocation error"); if(lseek(fd, (long)bh.bfOffBits, SEEK_SET)!=(long)bh.bfOffBits) _throw(strerror(errno)); _unix(bytesread=read(fd, tempbuf, srcpitch*(*h))); if(bytesread!=srcpitch*(*h)) _throw("Read error"); pixelconvert(tempbuf, BMP_BGR, srcpitch, *buf, f, dstpitch, *w, *h, srcbottomup!=dstbottomup); finally: if(tempbuf) free(tempbuf); if(fd!=-1) close(fd); return retcode; }
int Cyc_Lineno_lex_engine(int start_state,struct Cyc_Lexing_lexbuf * lbuf) { struct Cyc_Lexing_lexbuf * _T0; struct Cyc_Lexing_lexbuf * _T1; struct Cyc_Lexing_lexbuf * _T2; struct Cyc_Lexing_lexbuf * _T3; int _T4; const int * _T5; int _T6; const char * _T7; const int * _T8; int _T9; int _TA; const int * _TB; int _TC; struct Cyc_Lexing_lexbuf * _TD; struct Cyc_Lexing_lexbuf * _TE; struct Cyc_Lexing_lexbuf * _TF; struct Cyc_Lexing_lexbuf * _T10; int _T11; struct Cyc_Lexing_lexbuf * _T12; int _T13; struct Cyc_Lexing_lexbuf * _T14; long _T15; int _T16; int _T17; struct Cyc_Lexing_lexbuf * _T18; struct _fat_ptr _T19; struct Cyc_Lexing_lexbuf * _T1A; int _T1B; int _T1C; unsigned char * _T1D; char * _T1E; char _T1F; int _T20; int _T21; const int * _T22; int _T23; const char * _T24; const int * _T25; int _T26; int _T27; const int * _T28; int _T29; const int * _T2A; int _T2B; struct Cyc_Lexing_lexbuf * _T2C; struct Cyc_Lexing_lexbuf * _T2D; struct Cyc_Lexing_lexbuf * _T2E; int _T2F; int _T30; struct Cyc_Lexing_Error_exn_struct * _T31; void * _T32; struct Cyc_Lexing_lexbuf * _T33; int _T34; struct Cyc_Lexing_lexbuf * _T35; int state; int base; int backtrk; int c; state = start_state; if (state < 0) { goto _TL0; } _T0 = lbuf; _T1 = lbuf; _T2 = lbuf; _T1->lex_start_pos = _T2->lex_curr_pos; _T0->lex_last_pos = _T1->lex_start_pos; _T3 = lbuf; _T3->lex_last_action = - 1; goto _TL1; _TL0: _T4 = - state; state = _T4 - 1; _TL1: _TL2: if (1) { goto _TL3; }else { goto _TL4; } _TL3: _T5 = Cyc_Lineno_lex_base; _T6 = state; _T7 = _check_known_subscript_notnull(_T5,10U,sizeof(int),_T6); _T8 = (const int *)_T7; base = *_T8; if (base >= 0) { goto _TL5; } _T9 = - base; _TA = _T9 - 1; return _TA; _TL5: _TB = Cyc_Lineno_lex_backtrk; _TC = state; backtrk = _TB[_TC]; if (backtrk < 0) { goto _TL7; } _TD = lbuf; _TE = lbuf; _TD->lex_last_pos = _TE->lex_curr_pos; _TF = lbuf; _TF->lex_last_action = backtrk; goto _TL8; _TL7: _TL8: _T10 = lbuf; _T11 = _T10->lex_curr_pos; _T12 = lbuf; _T13 = _T12->lex_buffer_len; if (_T11 < _T13) { goto _TL9; } _T14 = lbuf; _T15 = _T14->lex_eof_reached; if (_T15) { goto _TLB; }else { goto _TLD; } _TLD: _T16 = - state; _T17 = _T16 - 1; return _T17; _TLB: c = 256; goto _TLA; _TL9: _T18 = lbuf; _T19 = _T18->lex_buffer; _T1A = lbuf; _T1B = _T1A->lex_curr_pos; _T1A->lex_curr_pos = _T1B + 1; _T1C = _T1B; _T1D = _check_fat_subscript(_T19,sizeof(char),_T1C); _T1E = (char *)_T1D; _T1F = *_T1E; c = (int)_T1F; _T20 = c; _T21 = - 1; if (_T20 != _T21) { goto _TLE; } c = 256; goto _TLF; _TLE: if (c >= 0) { goto _TL10; } c = 256 + c; goto _TL11; _TL10: _TL11: _TLF: _TLA: _T22 = Cyc_Lineno_lex_check; _T23 = base + c; _T24 = _check_known_subscript_notnull(_T22,273U,sizeof(int),_T23); _T25 = (const int *)_T24; _T26 = *_T25; _T27 = state; if (_T26 != _T27) { goto _TL12; } _T28 = Cyc_Lineno_lex_trans; _T29 = base + c; state = _T28[_T29]; goto _TL13; _TL12: _T2A = Cyc_Lineno_lex_default; _T2B = state; state = _T2A[_T2B]; _TL13: if (state >= 0) { goto _TL14; } _T2C = lbuf; _T2D = lbuf; _T2C->lex_curr_pos = _T2D->lex_last_pos; _T2E = lbuf; _T2F = _T2E->lex_last_action; _T30 = - 1; if (_T2F != _T30) { goto _TL16; } { struct Cyc_Lexing_Error_exn_struct * _T36 = _cycalloc(sizeof(struct Cyc_Lexing_Error_exn_struct)); _T36->tag = Cyc_Lexing_Error; _T36->f1 = _tag_fat("empty token",sizeof(char),12U); _T31 = (struct Cyc_Lexing_Error_exn_struct *)_T36; }_T32 = (void *)_T31; _throw(_T32); goto _TL17; _TL16: _T33 = lbuf; _T34 = _T33->lex_last_action; return _T34; _TL17: goto _TL15; _TL14: if (c != 256) { goto _TL18; } _T35 = lbuf; _T35->lex_eof_reached = 0; goto _TL19; _TL18: _TL19: _TL15: goto _TL2; _TL4: ; }
int savebmp(char *filename, unsigned char *buf, int w, int h, enum BMPPIXELFORMAT f, int srcpitch, int srcbottomup) { int fd=-1, byteswritten, dstpitch, retcode=0; int flags=O_RDWR|O_CREAT|O_TRUNC; unsigned char *tempbuf=NULL; char *temp; bmphdr bh; int mode; #ifdef _WIN32 flags|=O_BINARY; mode=_S_IREAD|_S_IWRITE; #else mode=S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH; #endif if(!filename || !buf || w<1 || h<1 || f<0 || f>BMPPIXELFORMATS-1 || srcpitch<0) _throw("bad argument to savebmp()"); if(srcpitch==0) srcpitch=w*ps[f]; if((temp=strrchr(filename, '.'))!=NULL) { if(!stricmp(temp, ".ppm")) return saveppm(filename, buf, w, h, f, srcpitch, srcbottomup); } _unix(fd=open(filename, flags, mode)); dstpitch=((w*3)+3)&(~3); bh.bfType=0x4d42; bh.bfSize=BMPHDRSIZE+dstpitch*h; bh.bfReserved1=0; bh.bfReserved2=0; bh.bfOffBits=BMPHDRSIZE; bh.biSize=40; bh.biWidth=w; bh.biHeight=h; bh.biPlanes=0; bh.biBitCount=24; bh.biCompression=BI_RGB; bh.biSizeImage=0; bh.biXPelsPerMeter=0; bh.biYPelsPerMeter=0; bh.biClrUsed=0; bh.biClrImportant=0; if(!littleendian()) { bh.bfType=byteswap16(bh.bfType); bh.bfSize=byteswap(bh.bfSize); bh.bfOffBits=byteswap(bh.bfOffBits); bh.biSize=byteswap(bh.biSize); bh.biWidth=byteswap(bh.biWidth); bh.biHeight=byteswap(bh.biHeight); bh.biPlanes=byteswap16(bh.biPlanes); bh.biBitCount=byteswap16(bh.biBitCount); bh.biCompression=byteswap(bh.biCompression); bh.biSizeImage=byteswap(bh.biSizeImage); bh.biXPelsPerMeter=byteswap(bh.biXPelsPerMeter); bh.biYPelsPerMeter=byteswap(bh.biYPelsPerMeter); bh.biClrUsed=byteswap(bh.biClrUsed); bh.biClrImportant=byteswap(bh.biClrImportant); } writeme(fd, &bh.bfType, sizeof(unsigned short)); writeme(fd, &bh.bfSize, sizeof(unsigned int)); writeme(fd, &bh.bfReserved1, sizeof(unsigned short)); writeme(fd, &bh.bfReserved2, sizeof(unsigned short)); writeme(fd, &bh.bfOffBits, sizeof(unsigned int)); writeme(fd, &bh.biSize, sizeof(unsigned int)); writeme(fd, &bh.biWidth, sizeof(int)); writeme(fd, &bh.biHeight, sizeof(int)); writeme(fd, &bh.biPlanes, sizeof(unsigned short)); writeme(fd, &bh.biBitCount, sizeof(unsigned short)); writeme(fd, &bh.biCompression, sizeof(unsigned int)); writeme(fd, &bh.biSizeImage, sizeof(unsigned int)); writeme(fd, &bh.biXPelsPerMeter, sizeof(int)); writeme(fd, &bh.biYPelsPerMeter, sizeof(int)); writeme(fd, &bh.biClrUsed, sizeof(unsigned int)); writeme(fd, &bh.biClrImportant, sizeof(unsigned int)); if((tempbuf=(unsigned char *)malloc(dstpitch*h))==NULL) _throw("Memory allocation error"); pixelconvert(buf, f, srcpitch, tempbuf, BMP_BGR, dstpitch, w, h, !srcbottomup); if((byteswritten=write(fd, tempbuf, dstpitch*h))!=dstpitch*h) _throw(strerror(errno)); finally: if(tempbuf) free(tempbuf); if(fd!=-1) close(fd); return retcode; }
JNIEXPORT void JNICALL Java_com_turbovnc_vncviewer_Viewport_setupExtInput (JNIEnv *env, jobject obj) { jclass cls, eidcls; jfieldID fid; jmethodID mid; Display *dpy = NULL; Window win = 0; XDeviceInfo *devInfo = NULL; XDevice *device = NULL; int nDevices = 0, i, ci, ai, nEvents = 0; int buttonPressType = -1, buttonReleaseType = -1, motionType = -1; XEventClass events[100] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; jobject extInputDevice; if ((dpy = XOpenDisplay(NULL)) == NULL) _throw("Could not open X display"); bailif0(cls = (*env)->GetObjectClass(env, obj)); bailif0(fid = (*env)->GetFieldID(env, cls, "x11win", "J")); if ((win = (Window)(*env)->GetLongField(env, obj, fid)) == 0) _throw("X window handle has not been initialized"); if ((devInfo = XListInputDevices(dpy, &nDevices)) == NULL) _throw("Could not list XI devices"); for (i = 0; i < nDevices; i++) { char *type; XAnyClassPtr classInfo = devInfo[i].inputclassinfo; CARD32 canGenerate = 0, productID = 0; if (devInfo[i].use != IsXExtensionPointer) continue; if (devInfo[i].type == None) continue; type = XGetAtomName(dpy, devInfo[i].type); if (!strcmp(type, "MOUSE")) { XFree(type); continue; } /* TurboVNC-specific: we use productID to represent the device type, so we can recreate it on the server */ if (!strcmp(type, "CURSOR")) productID = rfbGIIDevTypeCursor; else if (!strcmp(type, "STYLUS")) productID = rfbGIIDevTypeStylus; else if (!strcmp(type, "ERASER")) productID = rfbGIIDevTypeEraser; else if (!strcmp(type, "TOUCH")) productID = rfbGIIDevTypeTouch; else if (!strcmp(type, "PAD")) productID = rfbGIIDevTypePad; XFree(type); bailif0(eidcls = (*env)->FindClass(env, "com/turbovnc/rfb/ExtInputDevice")); bailif0(extInputDevice = (*env)->AllocObject(env, eidcls)); SET_STRING(eidcls, extInputDevice, name, devInfo[i].name); SET_LONG(eidcls, extInputDevice, vendorID, 4242); SET_LONG(eidcls, extInputDevice, productID, productID); SET_LONG(eidcls, extInputDevice, id, devInfo[i].id); for (ci = 0; ci < devInfo[i].num_classes; ci++) { switch (classInfo->class) { case ButtonClass: { XButtonInfoPtr b = (XButtonInfoPtr)classInfo; SET_INT(eidcls, extInputDevice, numButtons, b->num_buttons); canGenerate |= rfbGIIButtonPressMask | rfbGIIButtonReleaseMask; break; } case ValuatorClass: { XValuatorInfoPtr v = (XValuatorInfoPtr)classInfo; jclass valcls; bailif0(valcls = (*env)->FindClass(env, "com/turbovnc/rfb/ExtInputDevice$Valuator")); if (v->mode == Absolute) canGenerate |= rfbGIIValuatorAbsoluteMask; else if (v->mode == Relative) canGenerate |= rfbGIIValuatorRelativeMask; for (ai = 0; ai < v->num_axes; ai++) { jobject valuator; XAxisInfoPtr a = &v->axes[ai]; char longName[75], shortName[5]; bailif0(valuator = (*env)->AllocObject(env, valcls)); SET_INT(valcls, valuator, index, ai); snprintf(longName, 75, "Valuator %d", ai); SET_STRING(valcls, valuator, longName, longName); snprintf(shortName, 5, "%d", ai); SET_STRING(valcls, valuator, shortName, shortName); SET_INT(valcls, valuator, rangeMin, a->min_value); SET_INT(valcls, valuator, rangeCenter, (a->min_value + a->max_value) / 2); SET_INT(valcls, valuator, rangeMax, a->max_value); SET_INT(valcls, valuator, siUnit, rfbGIIUnitLength); SET_INT(valcls, valuator, siDiv, a->resolution); bailif0(mid = (*env)->GetMethodID(env, eidcls, "addValuator", "(Lcom/turbovnc/rfb/ExtInputDevice$Valuator;)V")); (*env)->CallVoidMethod(env, extInputDevice, mid, valuator); } break; } } classInfo = (XAnyClassPtr)((char *)classInfo + classInfo->length); } SET_LONG(eidcls, extInputDevice, canGenerate, canGenerate); if (canGenerate & rfbGIIValuatorAbsoluteMask) SET_BOOL(eidcls, extInputDevice, absolute, 1); if ((device = XOpenDevice(dpy, devInfo[i].id)) == NULL) _throw("Could not open XI device"); for (ci = 0; ci < device->num_classes; ci++) { if (device->classes[ci].input_class == ButtonClass) { DeviceButtonPress(device, buttonPressType, events[nEvents]); nEvents++; DeviceButtonRelease(device, buttonReleaseType, events[nEvents]); nEvents++; } else if (device->classes[ci].input_class == ValuatorClass) { DeviceMotionNotify(device, motionType, events[nEvents]); nEvents++; } } XCloseDevice(dpy, device); device=NULL; bailif0(mid = (*env)->GetMethodID(env, cls, "addInputDevice", "(Lcom/turbovnc/rfb/ExtInputDevice;)V")); (*env)->CallVoidMethod(env, obj, mid, extInputDevice); } XFreeDeviceList(devInfo); devInfo = NULL; if (nEvents == 0) { printf("No extended input devices.\n"); goto bailout; } if (XSelectExtensionEvent(dpy, win, events, nEvents)) _throw("Could not select XI events"); SET_INT(cls, obj, buttonPressType, buttonPressType); SET_INT(cls, obj, buttonReleaseType, buttonReleaseType); SET_INT(cls, obj, motionType, motionType); SET_LONG(cls, obj, x11dpy, (jlong)dpy); printf("TurboVNC Helper: Listening for XInput events on %s (window 0x%.8x)\n", DisplayString(dpy), (unsigned int)win); bailout: if (dpy && device) XCloseDevice(dpy, device); if (devInfo) XFreeDeviceList(devInfo); }
int main(int argc, char *argv[]) { unsigned char *srcBuf = NULL; int w = 0, h = 0, i, j, minQual = -1, maxQual = -1; char *temp; int minArg = 2, retval = 0, subsamp = -1; if ((scalingFactors = tjGetScalingFactors(&nsf)) == NULL || nsf == 0) _throw("executing tjGetScalingFactors()", tjGetErrorStr()); if (argc < minArg) usage(argv[0]); temp = strrchr(argv[1], '.'); if (temp != NULL) { if (!strcasecmp(temp, ".bmp")) ext = "bmp"; if (!strcasecmp(temp, ".jpg") || !strcasecmp(temp, ".jpeg")) decompOnly = 1; } printf("\n"); if (!decompOnly) { minArg = 3; if (argc < minArg) usage(argv[0]); if ((minQual = atoi(argv[2])) < 1 || minQual > 100) { puts("ERROR: Quality must be between 1 and 100."); exit(1); } if ((temp = strchr(argv[2], '-')) != NULL && strlen(temp) > 1 && sscanf(&temp[1], "%d", &maxQual) == 1 && maxQual > minQual && maxQual >= 1 && maxQual <= 100) {} else maxQual = minQual; } if (argc > minArg) { for (i = minArg; i < argc; i++) { if (!strcasecmp(argv[i], "-tile")) { doTile = 1; xformOpt |= TJXOPT_CROP; } else if (!strcasecmp(argv[i], "-fastupsample")) { printf("Using fast upsampling code\n\n"); flags |= TJFLAG_FASTUPSAMPLE; } else if (!strcasecmp(argv[i], "-fastdct")) { printf("Using fastest DCT/IDCT algorithm\n\n"); flags |= TJFLAG_FASTDCT; } else if (!strcasecmp(argv[i], "-accuratedct")) { printf("Using most accurate DCT/IDCT algorithm\n\n"); flags |= TJFLAG_ACCURATEDCT; } else if (!strcasecmp(argv[i], "-progressive")) { printf("Using progressive entropy coding\n\n"); flags |= TJFLAG_PROGRESSIVE; } else if (!strcasecmp(argv[i], "-rgb")) pf = TJPF_RGB; else if (!strcasecmp(argv[i], "-rgbx")) pf = TJPF_RGBX; else if (!strcasecmp(argv[i], "-bgr")) pf = TJPF_BGR; else if (!strcasecmp(argv[i], "-bgrx")) pf = TJPF_BGRX; else if (!strcasecmp(argv[i], "-xbgr")) pf = TJPF_XBGR; else if (!strcasecmp(argv[i], "-xrgb")) pf = TJPF_XRGB; else if (!strcasecmp(argv[i], "-cmyk")) pf = TJPF_CMYK; else if (!strcasecmp(argv[i], "-bottomup")) flags |= TJFLAG_BOTTOMUP; else if (!strcasecmp(argv[i], "-quiet")) quiet = 1; else if (!strcasecmp(argv[i], "-qq")) quiet = 2; else if (!strcasecmp(argv[i], "-scale") && i < argc - 1) { int temp1 = 0, temp2 = 0, match = 0; if (sscanf(argv[++i], "%d/%d", &temp1, &temp2) == 2) { for (j = 0; j < nsf; j++) { if ((double)temp1 / (double)temp2 == (double)scalingFactors[j].num / (double)scalingFactors[j].denom) { sf = scalingFactors[j]; match = 1; break; } } if (!match) usage(argv[0]); } else usage(argv[0]); } else if (!strcasecmp(argv[i], "-hflip")) xformOp = TJXOP_HFLIP; else if (!strcasecmp(argv[i], "-vflip")) xformOp = TJXOP_VFLIP; else if (!strcasecmp(argv[i], "-transpose")) xformOp = TJXOP_TRANSPOSE; else if (!strcasecmp(argv[i], "-transverse")) xformOp = TJXOP_TRANSVERSE; else if (!strcasecmp(argv[i], "-rot90")) xformOp = TJXOP_ROT90; else if (!strcasecmp(argv[i], "-rot180")) xformOp = TJXOP_ROT180; else if (!strcasecmp(argv[i], "-rot270")) xformOp = TJXOP_ROT270; else if (!strcasecmp(argv[i], "-grayscale")) xformOpt |= TJXOPT_GRAY; else if (!strcasecmp(argv[i], "-custom")) customFilter = dummyDCTFilter; else if (!strcasecmp(argv[i], "-nooutput")) xformOpt |= TJXOPT_NOOUTPUT; else if (!strcasecmp(argv[i], "-copynone")) xformOpt |= TJXOPT_COPYNONE; else if (!strcasecmp(argv[i], "-benchtime") && i < argc - 1) { double temp = atof(argv[++i]); if (temp > 0.0) benchTime = temp; else usage(argv[0]); } else if (!strcasecmp(argv[i], "-warmup") && i < argc - 1) { double temp = atof(argv[++i]); if (temp >= 0.0) warmup = temp; else usage(argv[0]); printf("Warmup time = %.1f seconds\n\n", warmup); } else if (!strcasecmp(argv[i], "-alloc")) flags &= (~TJFLAG_NOREALLOC); else if (!strcasecmp(argv[i], "-bmp")) ext = "bmp"; else if (!strcasecmp(argv[i], "-yuv")) { printf("Testing YUV planar encoding/decoding\n\n"); doYUV = 1; } else if (!strcasecmp(argv[i], "-yuvpad") && i < argc - 1) { int temp = atoi(argv[++i]); if (temp >= 1) yuvPad = temp; } else if (!strcasecmp(argv[i], "-subsamp") && i < argc - 1) { i++; if (toupper(argv[i][0]) == 'G') subsamp = TJSAMP_GRAY; else { int temp = atoi(argv[i]); switch (temp) { case 444: subsamp = TJSAMP_444; break; case 422: subsamp = TJSAMP_422; break; case 440: subsamp = TJSAMP_440; break; case 420: subsamp = TJSAMP_420; break; case 411: subsamp = TJSAMP_411; break; } } } else if (!strcasecmp(argv[i], "-componly")) compOnly = 1; else if (!strcasecmp(argv[i], "-nowrite")) doWrite = 0; else if (!strcasecmp(argv[i], "-stoponwarning")) flags |= TJFLAG_STOPONWARNING; else usage(argv[0]); } } if ((sf.num != 1 || sf.denom != 1) && doTile) { printf("Disabling tiled compression/decompression tests, because those tests do not\n"); printf("work when scaled decompression is enabled.\n"); doTile = 0; } if ((flags & TJFLAG_NOREALLOC) == 0 && doTile) { printf("Disabling tiled compression/decompression tests, because those tests do not\n"); printf("work when dynamic JPEG buffer allocation is enabled.\n\n"); doTile = 0; } if (!decompOnly) { if ((srcBuf = tjLoadImage(argv[1], &w, 1, &h, &pf, flags)) == NULL) _throwtjg("loading bitmap"); temp = strrchr(argv[1], '.'); if (temp != NULL) *temp = '\0'; } if (quiet == 1 && !decompOnly) { printf("All performance values in Mpixels/sec\n\n"); printf("Bitmap JPEG JPEG %s %s ", doTile ? "Tile " : "Image", doTile ? "Tile " : "Image"); if (doYUV) printf("Encode "); printf("Comp Comp Decomp "); if (doYUV) printf("Decode"); printf("\n"); printf("Format Subsamp Qual Width Height "); if (doYUV) printf("Perf "); printf("Perf Ratio Perf "); if (doYUV) printf("Perf"); printf("\n\n"); } if (decompOnly) { decompTest(argv[1]); printf("\n"); goto bailout; } if (subsamp >= 0 && subsamp < TJ_NUMSAMP) { for (i = maxQual; i >= minQual; i--) fullTest(srcBuf, w, h, subsamp, i, argv[1]); printf("\n"); } else { if (pf != TJPF_CMYK) { for (i = maxQual; i >= minQual; i--) fullTest(srcBuf, w, h, TJSAMP_GRAY, i, argv[1]); printf("\n"); } for (i = maxQual; i >= minQual; i--) fullTest(srcBuf, w, h, TJSAMP_420, i, argv[1]); printf("\n"); for (i = maxQual; i >= minQual; i--) fullTest(srcBuf, w, h, TJSAMP_422, i, argv[1]); printf("\n"); for (i = maxQual; i >= minQual; i--) fullTest(srcBuf, w, h, TJSAMP_444, i, argv[1]); printf("\n"); } bailout: if (srcBuf) tjFree(srcBuf); return retval; }