"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "f.pixmap.cc" between
fotoxx-22.30.tar.gz and fotoxx-22.35.tar.gz

About: fotoxx is a program for photo editing and collection management.

f.pixmap.cc  (fotoxx-22.30):f.pixmap.cc  (fotoxx-22.35)
skipping to change at line 49 skipping to change at line 49
PXB_make create PXB pixmap RGB[A] uint8 PXB_make create PXB pixmap RGB[A] uint8
PXB_free free PXB pixmap memory PXB_free free PXB pixmap memory
PXB_clear clear PXB pixmap to zeros PXB_clear clear PXB pixmap to zeros
PXB_addalpha add alhpa channel to PXB pixmap PXB_addalpha add alhpa channel to PXB pixmap
PXB_subalpha remove alpha channel from PXB pixmap PXB_subalpha remove alpha channel from PXB pixmap
PXB_copy copy (duplicate) PXB pixmap PXB_copy copy (duplicate) PXB pixmap
PXB_copy_area copy area from one PXB into another PXB_copy_area copy area from one PXB into another
PXB_subpxb create new PXB from section of existing PXB PXB_subpxb create new PXB from section of existing PXB
PXB_half rescale PXB pixmap to 1/2 size PXB_half rescale PXB pixmap to 1/2 size
PXB_rescale rescale PXB pixmap - ww/hh independent PXB_rescale rescale PXB pixmap - ww/hh independent
PXB_resize resize PXB pixmap - max. ww/hh, preserve ratio
PXB_rescale_fast fast rescale PXB pixmap - ww/hh independent PXB_rescale_fast fast rescale PXB pixmap - ww/hh independent
PXB_resize resize PXB pixmap - max. ww/hh, preserve ratio
PXB_resize_fast fast resize PXB pixmap - max. ww/hh, preserve ratio PXB_resize_fast fast resize PXB pixmap - max. ww/hh, preserve ratio
PXB_rotate rotate PXB pixmap, any angle PXB_rotate rotate PXB pixmap, any angle
vpixel get virtual pixel at any PXM or PXB image location (f loat) vpixel get virtual pixel at any PXM or PXB image location (f loat)
PXM_PXB_copy copy PXM pixmap to PXB pixmap PXM_PXB_copy copy PXM pixmap to PXB pixmap
PXM_PXB_update copy/convert PXM pixmap area to PXB pixmap area PXM_PXB_update copy/convert PXM pixmap area to PXB pixmap area
PXB_PXB_update copy/rescale input PXB pixmap area to output PXB area PXB_PXB_update copy/rescale input PXB pixmap area to output PXB area
PXB_load load an image file into a PXB pixmap (8-bit RGB) PXB_load load an image file into a PXB pixmap (8-bit RGB)
skipping to change at line 229 skipping to change at line 229
} }
if (pix[ii] >= 256.0) { if (pix[ii] >= 256.0) {
err3++; err3++;
pix[ii] = 255.9; pix[ii] = 255.9;
continue; continue;
} }
} }
} }
if (err1) Plog(1,"PXM_audit(): corrected %d RGB = NAN \n",err1); if (err1) Plog(0,"PXM_audit(): corrected %d RGB = NAN \n",err1);
if (err2) Plog(1,"PXM_audit(): corrected %d RGB < 0 \n",err2); if (err2) Plog(0,"PXM_audit(): corrected %d RGB < 0 \n",err2);
if (err3) Plog(1,"PXM_audit(): corrected %d RGB >= 256.0 \n",err3); if (err3) Plog(0,"PXM_audit(): corrected %d RGB >= 256.0 \n",err3);
return; return;
} }
// clear a PXM pixmap to white/opaque or black/transparent // clear a PXM pixmap to white/opaque or black/transparent
void PXM_clear(PXM *pxm, int BW) void PXM_clear(PXM *pxm, int BW)
{ {
int px, py, ii; int px, py, ii;
float *pix, rgba; float *pix, rgba;
skipping to change at line 1395 skipping to change at line 1395
if (P->nc2 == 4) pix2[3] = alpha; if (P->nc2 == 4) pix2[3] = alpha;
} }
} }
} }
return 0; return 0;
} }
/******************************************************************************* */ /******************************************************************************* */
// resize PXB to given max. width or height, preserving aspect ratio
// same as PXB_rescale() but one size argument instead of width and height
PXB * PXB_resize(PXB *pxb1, int size)
{
int ww1, hh1, ww2, hh2;
PXB *pxb2;
ww1 = pxb1->ww;
hh1 = pxb1->hh;
if (ww1 >= hh1) {
ww2 = size;
hh2 = 1.0 * size * hh1 / ww1 + 0.5;
}
else {
hh2 = size;
ww2 = 1.0 * size * ww1 / hh1 + 0.5;
}
pxb2 = PXB_rescale(pxb1,ww2,hh2);
return pxb2;
}
/*******************************************************************************
*/
// fast PXB pixmap rescale using 'half binomial' interpolation // fast PXB pixmap rescale using 'half binomial' interpolation
// works best when the rescale ratio is between 0.5 and 2.0 // works best when the rescale ratio is between 0.5 and 2.0
typedef struct { typedef struct {
int ww1, hh1, ww2, hh2, rs1, rs2, nc1, nc2; int ww1, hh1, ww2, hh2, rs1, rs2, nc1, nc2;
uint8 *pixels1, *pixels2; uint8 *pixels1, *pixels2;
float xscale, yscale; float xscale, yscale;
int nwt; int nwt;
} }
pxb_rescale_fast_data_t; pxb_rescale_fast_data_t;
skipping to change at line 1508 skipping to change at line 1482
pix2[0] = (pix10[0] + pix11[0]) / 2; pix2[0] = (pix10[0] + pix11[0]) / 2;
pix2[1] = (pix10[1] + pix11[1]) / 2; pix2[1] = (pix10[1] + pix11[1]) / 2;
pix2[2] = (pix10[2] + pix11[2]) / 2; pix2[2] = (pix10[2] + pix11[2]) / 2;
} }
return 0; return 0;
} }
/******************************************************************************* */ /******************************************************************************* */
// resize PXB to given max. width or height, preserving aspect ratio
// same as PXB_rescale() but one size argument instead of width and height
PXB * PXB_resize(PXB *pxb1, int size)
{
int ww1, hh1, ww2, hh2;
PXB *pxb2;
ww1 = pxb1->ww;
hh1 = pxb1->hh;
if (ww1 >= hh1) {
ww2 = size;
hh2 = 1.0 * size * hh1 / ww1 + 0.5;
}
else {
hh2 = size;
ww2 = 1.0 * size * ww1 / hh1 + 0.5;
}
pxb2 = PXB_rescale(pxb1,ww2,hh2);
return pxb2;
}
/*******************************************************************************
*/
// fast resize PXB to given max. width or height, preserving aspect ratio // fast resize PXB to given max. width or height, preserving aspect ratio
// same as PXB_rescale_fast() but one size argument instead of width and height // same as PXB_rescale_fast() but one size argument instead of width and height
PXB * PXB_resize_fast(PXB *pxb1, int size) PXB * PXB_resize_fast(PXB *pxb1, int size)
{ {
int ww1, hh1, ww2, hh2; int ww1, hh1, ww2, hh2;
PXB *pxb2; PXB *pxb2;
ww1 = pxb1->ww; ww1 = pxb1->ww;
hh1 = pxb1->hh; hh1 = pxb1->hh;
skipping to change at line 1803 skipping to change at line 1803
void PXM_PXB_update(PXM *pxm1, PXB *pxb2, int px3, int py3, int ww3, int hh3) void PXM_PXB_update(PXM *pxm1, PXB *pxb2, int px3, int py3, int ww3, int hh3)
{ {
float *pix1; float *pix1;
uint8 *pix2; uint8 *pix2;
int px, py; int px, py;
int lox, hix, loy, hiy; int lox, hix, loy, hiy;
int nc1, nc2, ac; int nc1, nc2, ac;
if (pxm1->ww + pxm1->hh != pxb2->ww + pxb2->hh) { if (pxm1->ww + pxm1->hh != pxb2->ww + pxb2->hh) {
Plog(1,"PXM_PXB_update() call error %d %d %d %d \n", Plog(0,"PXM_PXB_update() call error %d %d %d %d \n",
pxm1->ww, pxm1->hh, pxb2->ww, pxb2->hh); pxm1->ww, pxm1->hh, pxb2->ww, pxb2->hh);
return; return;
} }
lox = px3; lox = px3;
hix = px3 + ww3; hix = px3 + ww3;
if (lox < 0) lox = 0; if (lox < 0) lox = 0;
if (hix > pxb2->ww) hix = pxb2->ww; if (hix > pxb2->ww) hix = pxb2->ww;
loy = py3; loy = py3;
skipping to change at line 2053 skipping to change at line 2053
PXB *pxb = 0; PXB *pxb = 0;
STATB statB; STATB statB;
pthread_t tid; pthread_t tid;
cchar *key = "bitspersample"; cchar *key = "bitspersample";
char *kdata[1]; char *kdata[1];
static int Vftf = 1; static int Vftf = 1;
cchar *ffmpegmess = "video files not supported (install ffmpeg)"; cchar *ffmpegmess = "video files not supported (install ffmpeg)";
if (! regfile(file,&statB)) { if (! regfile(file,&statB)) {
Plog(1,"%s %s \n","file not found",file); Plog(0,"%s %s \n","file not found",file);
goto errret; goto errret;
} }
f_load_size = statB.st_size; f_load_size = statB.st_size;
f_load_bpc = 8; // default f_load_bpc = 8; // default
ftype = image_file_type(file); ftype = image_file_type(file);
if (ftype != IMAGE && ftype != RAW && ftype != VIDEO) { if (ftype != IMAGE && ftype != RAW && ftype != VIDEO) {
Plog(1,"file type not supported: %s \n",file); Plog(0,"file type not supported: %s \n",file);
goto errret; goto errret;
} }
pext = strrchr(file,'.'); // file .ext pext = strrchr(file,'.'); // file .ext
if (! pext) pext = ""; if (! pext) pext = "";
if (ftype == VIDEO) // video file - extract frame 1 if (ftype == VIDEO) // video file - extract frame 1
{ {
if (! Ffmpeg) { if (! Ffmpeg) {
if (Vftf) { Vftf = 0; zmessageACK(Mwin,ffmpegmess); } if (Vftf) { Vftf = 0; zmessageACK(Mwin,ffmpegmess); }
goto errret; goto errret;
} }
tid = pthread_self(); tid = pthread_self();
snprintf(framefile,200,"%s/framefile-%ld.jpg",temp_folder,tid); // unique frame file per thread snprintf(framefile,200,"%s/framefile-%ld.jpg",temp_folder,tid); // unique frame file per thread
// (index function, thumbnail creation) // (index function, thumbnail creation)
file2 = zescape_quotes(file); // escape embedded quotes file2 = zescape_quotes(file); // escape embedded quotes
err = zshell(0,"ffmpeg -ss 1 -i \"%s\" -v 8 -frames 1 -y %s", // ffmpeg command to get frame file err = zshell("log","ffmpeg -ss 1 -i \"%s\" -v 8 -frames 1 -y %s", // ffmpeg command to get frame file
file2, framefile); file2, framefile);
zfree(file2); zfree(file2);
if (err && err != 69) { // srmount error, ignore if (err && err != 69) { // srmount error, ignore
Plog(1,"cannot get video frame 1: %s %s \n",file,strerror(err)); Plog(0,"cannot get video frame 1: %s %s \n",file,strerror(err));
goto errret; goto errret;
} }
pxb = ANY_PXB_load(framefile); pxb = ANY_PXB_load(framefile);
if (! pxb) goto errret; if (! pxb) goto errret;
remove(framefile); remove(framefile);
strcpy(f_load_type,"video"); strcpy(f_load_type,"video");
f_load_bpc_raw = 0; f_load_bpc_raw = 0;
} }
skipping to change at line 2188 skipping to change at line 2188
PXM *pxm = 0; PXM *pxm = 0;
STATB statB; STATB statB;
cchar *key = "bitspersample"; cchar *key = "bitspersample";
char *kdata[1]; char *kdata[1];
zadd_locked(Ffuncbusy,+1); zadd_locked(Ffuncbusy,+1);
update_Fpanel(); update_Fpanel();
zmainloop(); zmainloop();
if (! regfile(file,&statB)) { if (! regfile(file,&statB)) {
Plog(1,"%s %s \n","file not found",file); Plog(0,"%s %s \n","file not found",file);
goto errret; goto errret;
} }
f_load_size = statB.st_size; f_load_size = statB.st_size;
f_load_bpc = 8; // default f_load_bpc = 8; // default
ftype = image_file_type(file); ftype = image_file_type(file);
if (ftype != IMAGE && ftype != RAW) { if (ftype != IMAGE && ftype != RAW) {
Plog(1,"file type not supported: %s \n",file); Plog(0,"file type not supported: %s \n",file);
goto errret; goto errret;
} }
pext = strrchr(file,'.'); // file .ext pext = strrchr(file,'.'); // file .ext
if (! pext) pext = ""; if (! pext) pext = "";
if (ftype == IMAGE) if (ftype == IMAGE)
{ {
if (strcasestr(".jpg .jpeg",pext)) { if (strcasestr(".jpg .jpeg",pext)) {
pxm = JPG_PXM_load(file); pxm = JPG_PXM_load(file);
skipping to change at line 2457 skipping to change at line 2457
if (num < 16) { if (num < 16) {
cinfo.scale_num = num; // target size = num/16 * full size cinfo.scale_num = num; // target size = num/16 * full size
cinfo.scale_denom = 16; cinfo.scale_denom = 16;
} }
} }
jpeg_start_decompress(&cinfo); jpeg_start_decompress(&cinfo);
nb = cinfo.rec_outbuf_height; // rows per read nb = cinfo.rec_outbuf_height; // rows per read
nc1 = cinfo.output_components; // color channels nc1 = cinfo.output_components; // color channels
if (nc1 != 3) Plog(1,"JPEG file has %d channels: %s \n",nc1,file); // try anyway 22.18 if (nc1 != 3) Plog(0,"JPEG file has %d channels: %s \n",nc1,file); // try anyway 22.18
ww = cinfo.output_width; // actual output dimensions ww = cinfo.output_width; // actual output dimensions
hh = cinfo.output_height; hh = cinfo.output_height;
cc = imagesize(ww,hh,nc1,1); cc = imagesize(ww,hh,nc1,1);
if (! cc) goto errret; if (! cc) goto errret;
pixels = (uint8 *) zmalloc(cc,"JPG_PXB_load"); // allocate memory for RGB image pixels = (uint8 *) zmalloc(cc,"JPG_PXB_load"); // allocate memory for RGB image
cc = hh * sizeof(void *); // allocate row pointers cc = hh * sizeof(void *); // allocate row pointers
skipping to change at line 2515 skipping to change at line 2515
pxb2 = PXB_rescale(pxb,ww,hh); pxb2 = PXB_rescale(pxb,ww,hh);
PXB_free(pxb); PXB_free(pxb);
pxb = pxb2; pxb = pxb2;
} }
f_load_bpc = 8; f_load_bpc = 8;
return pxb; return pxb;
errret: errret:
if (errno) Plog(1,"error: %s \n",strerror(errno)); if (errno) Plog(0,"error: %s \n",strerror(errno));
Plog(1,"jpeg file error: %s \n",file); Plog(0,"jpeg file error: %s \n",file);
if (fid && fileno(fid) != -1) fclose(fid); if (fid && fileno(fid) != -1) fclose(fid);
if (row_pointers) zfree(row_pointers); if (row_pointers) zfree(row_pointers);
if (pixels) zfree(pixels); if (pixels) zfree(pixels);
return 0; return 0;
} }
// Load PXM pixmap from JPG file using JPG library. // Load PXM pixmap from JPG file using JPG library.
PXM * JPG_PXM_load(cchar *file) PXM * JPG_PXM_load(cchar *file)
{ {
skipping to change at line 2562 skipping to change at line 2562
jpeg_stdio_src(&cinfo,fid); jpeg_stdio_src(&cinfo,fid);
jpeg_read_header(&cinfo,TRUE); jpeg_read_header(&cinfo,TRUE);
ww = cinfo.image_width; // image size ww = cinfo.image_width; // image size
hh = cinfo.image_height; hh = cinfo.image_height;
jpeg_start_decompress(&cinfo); jpeg_start_decompress(&cinfo);
nb = cinfo.rec_outbuf_height; // rows per read nb = cinfo.rec_outbuf_height; // rows per read
nc1 = cinfo.output_components; // color channels nc1 = cinfo.output_components; // color channels
if (nc1 != 3) Plog(1,"JPEG file has %d channels: %s \n",nc1,file); // try anyway 22.18 if (nc1 != 3) Plog(0,"JPEG file has %d channels: %s \n",nc1,file); // try anyway 22.18
ww = cinfo.output_width; // actual output dimensions ww = cinfo.output_width; // actual output dimensions
hh = cinfo.output_height; hh = cinfo.output_height;
cc = imagesize(ww,hh,nc1,1); cc = imagesize(ww,hh,nc1,1);
if (! cc) goto errret; if (! cc) goto errret;
pixels = (uint8 *) zmalloc(cc,"JPG_PXM_load"); // allocate memory for RGB image pixels = (uint8 *) zmalloc(cc,"JPG_PXM_load"); // allocate memory for RGB image
cc = hh * sizeof(void *); // allocate row pointers cc = hh * sizeof(void *); // allocate row pointers
skipping to change at line 2605 skipping to change at line 2605
PXM_audit(pxm); // audit/repair PXM_audit(pxm); // audit/repair
zfree(pixels); zfree(pixels);
pixels = 0; pixels = 0;
f_load_bpc = 8; f_load_bpc = 8;
return pxm; return pxm;
errret: errret:
if (errno) Plog(1,"error: %s \n",strerror(errno)); if (errno) Plog(0,"error: %s \n",strerror(errno));
Plog(1,"jpeg file error: %s \n",file); Plog(0,"jpeg file error: %s \n",file);
if (fid && fileno(fid) != -1) fclose(fid); if (fid && fileno(fid) != -1) fclose(fid);
if (row_pointers) zfree(row_pointers); if (row_pointers) zfree(row_pointers);
if (pixels) zfree(pixels); if (pixels) zfree(pixels);
return 0; return 0;
} }
// Write PXB pixmap to JPG file using JPG library. // Write PXB pixmap to JPG file using JPG library.
// quality is compression quality 0-100 // quality is compression quality 0-100
// returns 0 if OK, +N if error. // returns 0 if OK, +N if error.
skipping to change at line 2684 skipping to change at line 2684
jpeg_finish_compress(&cinfo); // wrap-up jpeg_finish_compress(&cinfo); // wrap-up
jpeg_destroy_compress(&cinfo); jpeg_destroy_compress(&cinfo);
fclose(fid); fclose(fid);
zfree(row_pointers); zfree(row_pointers);
zfree(pixels2); zfree(pixels2);
row_pointers = 0; row_pointers = 0;
pixels2 = 0; pixels2 = 0;
return 0; return 0;
errret: errret:
if (errno) Plog(1,"error: %s \n",strerror(errno)); if (errno) Plog(0,"error: %s \n",strerror(errno));
Plog(1,"jpeg file error: %s \n",file); Plog(0,"jpeg file error: %s \n",file);
if (fid && fileno(fid) != -1) fclose(fid); if (fid && fileno(fid) != -1) fclose(fid);
if (row_pointers) zfree(row_pointers); if (row_pointers) zfree(row_pointers);
if (pixels2) zfree(pixels2); if (pixels2) zfree(pixels2);
return 3; return 3;
} }
// Write PXM pixmap to JPG file using JPG library. // Write PXM pixmap to JPG file using JPG library.
// quality is compression quality 0-100 // quality is compression quality 0-100
// returns 0 if OK, +N if error. // returns 0 if OK, +N if error.
skipping to change at line 2766 skipping to change at line 2766
jpeg_destroy_compress(&cinfo); jpeg_destroy_compress(&cinfo);
fclose(fid); fclose(fid);
zfree(row_pointers); zfree(row_pointers);
zfree(pixels2); zfree(pixels2);
row_pointers = 0; row_pointers = 0;
pixels2 = 0; pixels2 = 0;
return 0; return 0;
errret: errret:
if (errno) Plog(1,"error: %s \n",strerror(errno)); if (errno) Plog(0,"error: %s \n",strerror(errno));
Plog(1,"jpeg file error: %s \n",file); Plog(0,"jpeg file error: %s \n",file);
if (fid && fileno(fid) != -1) fclose(fid); if (fid && fileno(fid) != -1) fclose(fid);
if (row_pointers) zfree(row_pointers); if (row_pointers) zfree(row_pointers);
if (pixels2) zfree(pixels2); if (pixels2) zfree(pixels2);
return 2; return 2;
} }
/******************************************************************************* */ /******************************************************************************* */
#pragma GCC pop_options // revert to normal optimization #pragma GCC pop_options // revert to normal optimization
skipping to change at line 2789 skipping to change at line 2789
TIFF file read and write functions TIFF file read and write functions
******************************************************************************** */ ******************************************************************************** */
// Intercept TIFF warning messages (many) // Intercept TIFF warning messages (many)
void tiffwarninghandler(cchar *module, cchar *format, va_list ap) void tiffwarninghandler(cchar *module, cchar *format, va_list ap)
{ {
return; // stop flood of crap return; // stop flood of crap
char message[200]; char message[200];
vsnprintf(message,199,format,ap); vsnprintf(message,199,format,ap);
Plog(1,"TIFF warning: %s %s \n",module,message); Plog(0,"TIFF warning: %s %s \n",module,message);
return; return;
} }
// Load PXB pixmap from TIFF file using TIFF library. // Load PXB pixmap from TIFF file using TIFF library.
// Native TIFF file bits/color >> f_load_bpc // Native TIFF file bits/color >> f_load_bpc
PXB * TIFF_PXB_load(cchar *file) PXB * TIFF_PXB_load(cchar *file)
{ {
static int ftf = 1; static int ftf = 1;
TIFF *tiff; TIFF *tiff;
skipping to change at line 2817 skipping to change at line 2817
if (! regfile(file)) goto errret; // no print error if (! regfile(file)) goto errret; // no print error
if (ftf) { if (ftf) {
TIFFSetWarningHandler(tiffwarninghandler); // intercept TIFF warning messages TIFFSetWarningHandler(tiffwarninghandler); // intercept TIFF warning messages
ftf = 0; ftf = 0;
} }
tiff = TIFFOpen(file,"r"); tiff = TIFFOpen(file,"r");
if (! tiff) { if (! tiff) {
Plog(1,"tiff file error: %s %s \n",file,strerror(errno)); Plog(0,"tiff file error: %s %s \n",file,strerror(errno));
goto errret; goto errret;
} }
TIFFGetFieldDefaulted(tiff, TIFFTAG_IMAGEWIDTH, &ww); // width TIFFGetFieldDefaulted(tiff, TIFFTAG_IMAGEWIDTH, &ww); // width
TIFFGetFieldDefaulted(tiff, TIFFTAG_IMAGELENGTH, &hh); // height TIFFGetFieldDefaulted(tiff, TIFFTAG_IMAGELENGTH, &hh); // height
TIFFGetFieldDefaulted(tiff, TIFFTAG_BITSPERSAMPLE, &bpc); // bits per color, 1/8/16 TIFFGetFieldDefaulted(tiff, TIFFTAG_BITSPERSAMPLE, &bpc); // bits per color, 1/8/16
TIFFGetFieldDefaulted(tiff, TIFFTAG_SAMPLESPERPIXEL, &nc1); // no. channels (colors), 1/2/3/4 TIFFGetFieldDefaulted(tiff, TIFFTAG_SAMPLESPERPIXEL, &nc1); // no. channels (colors), 1/2/3/4
TIFFGetFieldDefaulted(tiff, TIFFTAG_ROWSPERSTRIP, &rps); // rows per strip TIFFGetFieldDefaulted(tiff, TIFFTAG_ROWSPERSTRIP, &rps); // rows per strip
TIFFGetFieldDefaulted(tiff, TIFFTAG_PLANARCONFIG, &pcfg); // 1 = contiguous, 2 = planes TIFFGetFieldDefaulted(tiff, TIFFTAG_PLANARCONFIG, &pcfg); // 1 = contiguous, 2 = planes
rwb = TIFFScanlineSize(tiff); // scanline size rwb = TIFFScanlineSize(tiff); // scanline size
stb = TIFFStripSize(tiff); // strip size stb = TIFFStripSize(tiff); // strip size
nst = TIFFNumberOfStrips(tiff); // number of strips nst = TIFFNumberOfStrips(tiff); // number of strips
if (pcfg != 1 || nc1 > 4) { if (pcfg != 1 || nc1 > 4) {
Plog(1,"tiff format not supported: %s pcfg: %d nc1: %d \n",file,pcfg,nc1); Plog(0,"tiff format not supported: %s pcfg: %d nc1: %d \n",file,pcfg,nc1);
TIFFClose(tiff); TIFFClose(tiff);
goto errret; goto errret;
} }
if (bpc != 8 && bpc != 16) { // bits/color if (bpc != 8 && bpc != 16) { // bits/color
Plog(1,"tiff format not supported: %s bpc: %d \n",file,bpc); Plog(0,"tiff format not supported: %s bpc: %d \n",file,bpc);
TIFFClose(tiff); TIFFClose(tiff);
goto errret; goto errret;
} }
if (nst == 0 || stb == 0) { // R.Nolde tiff integrity checks if (nst == 0 || stb == 0) { // R.Nolde tiff integrity checks
Plog(1,"tiff format not supported: %s nst: %d stb: %d \n",file,nst,stb); Plog(0,"tiff format not supported: %s nst: %d stb: %d \n",file,nst,stb);
TIFFClose(tiff); TIFFClose(tiff);
goto errret; goto errret;
} }
buffbytes = ((uint64)(stb)) * nst; buffbytes = ((uint64)(stb)) * nst;
if (stb != buffbytes / nst) { if (stb != buffbytes / nst) {
Plog(1,"tiff buffer check fail: %s %d %d \n",file,stb,nst); Plog(0,"tiff buffer check fail: %s %d %d \n",file,stb,nst);
TIFFClose(tiff); TIFFClose(tiff);
goto errret; goto errret;
} }
buffbits = ((uint64)(ww)) * hh * nc1 * bpc; buffbits = ((uint64)(ww)) * hh * nc1 * bpc;
if (hh != buffbits / ww / nc1 / bpc) { if (hh != buffbits / ww / nc1 / bpc) {
Plog(1,"tiff buffer check fail: %s %d %d %d %d \n",file,ww,hh,nc1,bpc); Plog(0,"tiff buffer check fail: %s %d %d %d %d \n",file,ww,hh,nc1,bpc);
TIFFClose(tiff); TIFFClose(tiff);
goto errret; goto errret;
} }
rs1 = ww * nc1; // row stride rs1 = ww * nc1; // row stride
if (bpc == 16) rs1 = rs1 * 2; if (bpc == 16) rs1 = rs1 * 2;
buffsz1 = imagesize(stb,nst,1,1); // alternate size calculations buffsz1 = imagesize(stb,nst,1,1); // alternate size calculations
buffsz2 = imagesize(hh,rs1,1,1); buffsz2 = imagesize(hh,rs1,1,1);
buffsz = buffsz1; buffsz = buffsz1;
skipping to change at line 2931 skipping to change at line 2931
if (! regfile(file)) goto errret; // no print error if (! regfile(file)) goto errret; // no print error
if (ftf) { if (ftf) {
TIFFSetWarningHandler(tiffwarninghandler); // intercept TIFF warning messages TIFFSetWarningHandler(tiffwarninghandler); // intercept TIFF warning messages
ftf = 0; ftf = 0;
} }
tiff = TIFFOpen(file,"r"); tiff = TIFFOpen(file,"r");
if (! tiff) { if (! tiff) {
Plog(1,"tiff file error: %s %s \n",file,strerror(errno)); Plog(0,"tiff file error: %s %s \n",file,strerror(errno));
goto errret; goto errret;
} }
TIFFGetFieldDefaulted(tiff, TIFFTAG_IMAGEWIDTH, &ww); // width TIFFGetFieldDefaulted(tiff, TIFFTAG_IMAGEWIDTH, &ww); // width
TIFFGetFieldDefaulted(tiff, TIFFTAG_IMAGELENGTH, &hh); // height TIFFGetFieldDefaulted(tiff, TIFFTAG_IMAGELENGTH, &hh); // height
TIFFGetFieldDefaulted(tiff, TIFFTAG_BITSPERSAMPLE, &bpc); // bits per color, 1/8/16 TIFFGetFieldDefaulted(tiff, TIFFTAG_BITSPERSAMPLE, &bpc); // bits per color, 1/8/16
TIFFGetFieldDefaulted(tiff, TIFFTAG_SAMPLESPERPIXEL, &nc1); // no. channels (colors), 1/2/3/4 TIFFGetFieldDefaulted(tiff, TIFFTAG_SAMPLESPERPIXEL, &nc1); // no. channels (colors), 1/2/3/4
TIFFGetFieldDefaulted(tiff, TIFFTAG_ROWSPERSTRIP, &rps); // rows per strip TIFFGetFieldDefaulted(tiff, TIFFTAG_ROWSPERSTRIP, &rps); // rows per strip
TIFFGetFieldDefaulted(tiff, TIFFTAG_PLANARCONFIG, &pcfg); // 1 = contiguous, 2 = planes TIFFGetFieldDefaulted(tiff, TIFFTAG_PLANARCONFIG, &pcfg); // 1 = contiguous, 2 = planes
rwb = TIFFScanlineSize(tiff); // scanline size rwb = TIFFScanlineSize(tiff); // scanline size
stb = TIFFStripSize(tiff); // strip size stb = TIFFStripSize(tiff); // strip size
nst = TIFFNumberOfStrips(tiff); // number of strips nst = TIFFNumberOfStrips(tiff); // number of strips
if (pcfg != 1 || nc1 > 4) { if (pcfg != 1 || nc1 > 4) {
Plog(1,"tiff format not supported: %s pcfg: %d nc1: %d \n",file,pcfg,nc1); Plog(0,"tiff format not supported: %s pcfg: %d nc1: %d \n",file,pcfg,nc1);
TIFFClose(tiff); TIFFClose(tiff);
goto errret; goto errret;
} }
if (bpc != 8 && bpc != 16) { // bits/color if (bpc != 8 && bpc != 16) { // bits/color
Plog(1,"tiff format not supported: %s bpc: %d \n",file,bpc); Plog(0,"tiff format not supported: %s bpc: %d \n",file,bpc);
TIFFClose(tiff); TIFFClose(tiff);
goto errret; goto errret;
} }
if (nst == 0 || stb == 0) { // R.Nolde tiff integrity checks if (nst == 0 || stb == 0) { // R.Nolde tiff integrity checks
Plog(1,"tiff format not supported: %s nst: %d stb: %d \n",file,nst,stb); Plog(0,"tiff format not supported: %s nst: %d stb: %d \n",file,nst,stb);
TIFFClose(tiff); TIFFClose(tiff);
goto errret; goto errret;
} }
buffbytes = ((uint64)(stb)) * nst; buffbytes = ((uint64)(stb)) * nst;
if (stb != buffbytes / nst) { if (stb != buffbytes / nst) {
Plog(1,"tiff buffer check fail: %s %d %d \n",file,stb,nst); Plog(0,"tiff buffer check fail: %s %d %d \n",file,stb,nst);
TIFFClose(tiff); TIFFClose(tiff);
goto errret; goto errret;
} }
buffbits = ((uint64)(ww)) * hh * nc1 * bpc; buffbits = ((uint64)(ww)) * hh * nc1 * bpc;
if (hh != buffbits / ww / nc1 / bpc) { if (hh != buffbits / ww / nc1 / bpc) {
Plog(1,"tiff buffer check fail: %s %d %d %d %d \n",file,ww,hh,nc1,bpc); Plog(0,"tiff buffer check fail: %s %d %d %d %d \n",file,ww,hh,nc1,bpc);
TIFFClose(tiff); TIFFClose(tiff);
goto errret; goto errret;
} }
rs1 = ww * nc1; // row stride rs1 = ww * nc1; // row stride
if (bpc == 16) rs1 = rs1 * 2; if (bpc == 16) rs1 = rs1 * 2;
buffsz1 = imagesize(stb,nst,1,1); // alternate size calculations buffsz1 = imagesize(stb,nst,1,1); // alternate size calculations
buffsz2 = imagesize(hh,rs1,1,1); buffsz2 = imagesize(hh,rs1,1,1);
buffsz = buffsz1; buffsz = buffsz1;
skipping to change at line 3046 skipping to change at line 3046
uint cc; uint cc;
uint16 es[1]; uint16 es[1];
if (ftf) { if (ftf) {
TIFFSetWarningHandler(tiffwarninghandler); // intercept TIFF warning messages TIFFSetWarningHandler(tiffwarninghandler); // intercept TIFF warning messages
ftf = 0; ftf = 0;
} }
tiff = TIFFOpen(file,"w"); tiff = TIFFOpen(file,"w");
if (! tiff) { if (! tiff) {
Plog(1,"file error: %s %s \n",file,strerror(errno)); Plog(0,"file error: %s %s \n",file,strerror(errno));
goto errret; goto errret;
} }
ww = pxb->ww; ww = pxb->ww;
hh = pxb->hh; hh = pxb->hh;
nc1 = pxb->nc; nc1 = pxb->nc;
nc2 = nc1; nc2 = nc1;
rs2 = ww * nc2; // output row stride rs2 = ww * nc2; // output row stride
skipping to change at line 3121 skipping to change at line 3121
uint cc; uint cc;
uint16 es[1]; uint16 es[1];
if (ftf) { if (ftf) {
TIFFSetWarningHandler(tiffwarninghandler); // intercept TIFF warning messages TIFFSetWarningHandler(tiffwarninghandler); // intercept TIFF warning messages
ftf = 0; ftf = 0;
} }
tiff = TIFFOpen(file,"w"); tiff = TIFFOpen(file,"w");
if (! tiff) { if (! tiff) {
Plog(1,"file error: %s %s \n",file,strerror(errno)); Plog(0,"file error: %s %s \n",file,strerror(errno));
goto errret; goto errret;
} }
ww = pxm->ww; ww = pxm->ww;
hh = pxm->hh; hh = pxm->hh;
nc1 = pxm->nc; nc1 = pxm->nc;
nc2 = nc1; nc2 = nc1;
rs2 = ww * nc2; // output row stride rs2 = ww * nc2; // output row stride
skipping to change at line 3194 skipping to change at line 3194
FILE *fid = 0; FILE *fid = 0;
int ww, hh, bpc, nc1, nc2, rs1, row, colortype; int ww, hh, bpc, nc1, nc2, rs1, row, colortype;
uchar *pngbuff, **pngrows; uchar *pngbuff, **pngrows;
PXB *pxb; PXB *pxb;
uint cc; uint cc;
if (! regfile(file)) goto errret; // no print error if (! regfile(file)) goto errret; // no print error
fid = fopen(file,"r"); // open file fid = fopen(file,"r"); // open file
if (! fid) { if (! fid) {
Plog(1,"file error: %s %s \n",file,strerror(errno)); Plog(0,"file error: %s %s \n",file,strerror(errno));
goto errret; goto errret;
} }
pngstruct = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0); // create png structs pngstruct = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0); // create png structs
if (! pngstruct) goto errret; if (! pngstruct) goto errret;
pnginfo = png_create_info_struct(pngstruct); pnginfo = png_create_info_struct(pngstruct);
if (! pnginfo) goto errret; if (! pnginfo) goto errret;
if (setjmp(png_jmpbuf(pngstruct))) goto errret; // setup error handling if (setjmp(png_jmpbuf(pngstruct))) goto errret; // setup error handling
png_init_io(pngstruct,fid); // read png file png_init_io(pngstruct,fid); // read png file
skipping to change at line 3283 skipping to change at line 3283
FILE *fid = 0; FILE *fid = 0;
int ww, hh, bpc, nc1, nc2, rs1, row, colortype; int ww, hh, bpc, nc1, nc2, rs1, row, colortype;
uchar *pngbuff, **pngrows; uchar *pngbuff, **pngrows;
PXM *pxm; PXM *pxm;
uint cc; uint cc;
if (! regfile(file)) goto errret; // no print error if (! regfile(file)) goto errret; // no print error
fid = fopen(file,"r"); // open file fid = fopen(file,"r"); // open file
if (! fid) { if (! fid) {
Plog(1,"file error: %s %s \n",file,strerror(errno)); Plog(0,"file error: %s %s \n",file,strerror(errno));
goto errret; goto errret;
} }
pngstruct = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0); // create png structs pngstruct = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0); // create png structs
if (! pngstruct) goto errret; if (! pngstruct) goto errret;
pnginfo = png_create_info_struct(pngstruct); pnginfo = png_create_info_struct(pngstruct);
if (! pnginfo) goto errret; if (! pnginfo) goto errret;
if (setjmp(png_jmpbuf(pngstruct))) goto errret; // setup error handling if (setjmp(png_jmpbuf(pngstruct))) goto errret; // setup error handling
png_init_io(pngstruct,fid); // read png file png_init_io(pngstruct,fid); // read png file
skipping to change at line 3371 skipping to change at line 3371
int PXB_PNG_save(PXB *pxb, cchar *file, int bpc) int PXB_PNG_save(PXB *pxb, cchar *file, int bpc)
{ {
png_structp pngstruct; png_structp pngstruct;
png_infop pnginfo; png_infop pnginfo;
FILE *fid = 0; FILE *fid = 0;
uchar *pngbuff, **pngrows; uchar *pngbuff, **pngrows;
int ww, hh, nc1, nc2, rs2, row; int ww, hh, nc1, nc2, rs2, row;
uint cc; uint cc;
if (bpc != 8 && bpc != 16) { if (bpc != 8 && bpc != 16) {
Plog(1,"PNG BPC not 8/16: %s",file); Plog(0,"PNG BPC not 8/16: %s",file);
goto errret; goto errret;
} }
fid = fopen(file,"w"); // open output file fid = fopen(file,"w"); // open output file
if (! fid) { if (! fid) {
Plog(1,"file error: %s %s \n",file,strerror(errno)); Plog(0,"file error: %s %s \n",file,strerror(errno));
goto errret; goto errret;
} }
ww = pxb->ww; ww = pxb->ww;
hh = pxb->hh; hh = pxb->hh;
nc1 = pxb->nc; nc1 = pxb->nc;
nc2 = nc1; nc2 = nc1;
pngstruct = png_create_write_struct(PNG_LIBPNG_VER_STRING,0,0,0); // create png structs pngstruct = png_create_write_struct(PNG_LIBPNG_VER_STRING,0,0,0); // create png structs
if (! pngstruct) goto errret; if (! pngstruct) goto errret;
skipping to change at line 3447 skipping to change at line 3447
int PXM_PNG_save(PXM *pxm, cchar *file, int bpc) int PXM_PNG_save(PXM *pxm, cchar *file, int bpc)
{ {
png_structp pngstruct; png_structp pngstruct;
png_infop pnginfo; png_infop pnginfo;
FILE *fid = 0; FILE *fid = 0;
uchar *pngbuff, **pngrows; uchar *pngbuff, **pngrows;
int ww, hh, nc1, nc2, rs2, row; int ww, hh, nc1, nc2, rs2, row;
uint cc; uint cc;
if (bpc != 8 && bpc != 16) { if (bpc != 8 && bpc != 16) {
Plog(1,"PNG BPC not 8/16: %s",file); Plog(0,"PNG BPC not 8/16: %s",file);
goto errret; goto errret;
} }
fid = fopen(file,"w"); // open output file fid = fopen(file,"w"); // open output file
if (! fid) { if (! fid) {
Plog(1,"file error: %s %s \n",file,strerror(errno)); Plog(0,"file error: %s %s \n",file,strerror(errno));
goto errret; goto errret;
} }
ww = pxm->ww; ww = pxm->ww;
hh = pxm->hh; hh = pxm->hh;
nc1 = pxm->nc; nc1 = pxm->nc;
nc2 = nc1; nc2 = nc1;
pngstruct = png_create_write_struct(PNG_LIBPNG_VER_STRING,0,0,0); // create png structs pngstruct = png_create_write_struct(PNG_LIBPNG_VER_STRING,0,0,0); // create png structs
if (! pngstruct) goto errret; if (! pngstruct) goto errret;
skipping to change at line 3539 skipping to change at line 3539
return 0; return 0;
} }
if (! regfile(file)) return 0; // no print error if (! regfile(file)) return 0; // no print error
jpegfile = zstrdup(file,"HEIC_PXB_load",8); // file.heic >> file.jpg jpegfile = zstrdup(file,"HEIC_PXB_load",8); // file.heic >> file.jpg
pp = strrchr(jpegfile,'.'); pp = strrchr(jpegfile,'.');
if (! pp) goto errret; if (! pp) goto errret;
strcpy(pp,".jpg"); strcpy(pp,".jpg");
zshell(0,"heif-convert -q %d \"%s\" \"%s\" >/dev/null ", // convert to .jpg zshell("log","heif-convert -q %d \"%s\" \"%s\" >/dev/null ", // convert to .jpg
jpeg_def_quality, file, jpegfile); jpeg_def_quality, file, jpegfile);
if (! regfile(jpegfile)) { if (! regfile(jpegfile)) {
jpegfix = zstrdup(jpegfile,"HEIC_PXB_load",8); // failed, may have multiple output files jpegfix = zstrdup(jpegfile,"HEIC_PXB_load",8); // failed, may have multiple output files
pp = strrchr(jpegfix,'.'); // file-1.jpg, file-2.jpg, etc. pp = strrchr(jpegfix,'.'); // file-1.jpg, file-2.jpg, etc.
strcpy(pp,"-1.jpg"); strcpy(pp,"-1.jpg");
if (! regfile(jpegfix)) goto errret; if (! regfile(jpegfix)) goto errret;
rename(jpegfix,jpegfile); // if file-1.jpg, rename to file.jpg rename(jpegfix,jpegfile); // if file-1.jpg, rename to file.jpg
zfree(jpegfix); // (file-2.jpg etc. remain) zfree(jpegfix); // (file-2.jpg etc. remain)
} }
skipping to change at line 3589 skipping to change at line 3589
return 0; return 0;
} }
if (! regfile(file)) return 0; // no print error if (! regfile(file)) return 0; // no print error
jpegfile = zstrdup(file,"HEIC_PXM_load",8); jpegfile = zstrdup(file,"HEIC_PXM_load",8);
pp = strrchr(jpegfile,'.'); pp = strrchr(jpegfile,'.');
if (! pp) goto errret; if (! pp) goto errret;
strcpy(pp,".jpg"); strcpy(pp,".jpg");
zshell(0,"heif-convert -q %d \"%s\" \"%s\" >/dev/null ", zshell("log","heif-convert -q %d \"%s\" \"%s\" >/dev/null ",
jpeg_def_quality, file, jpegfile); jpeg_def_quality, file, jpegfile);
if (! regfile(jpegfile)) { if (! regfile(jpegfile)) {
jpegfix = zstrdup(jpegfile,"HEIC_PXM_load",8); jpegfix = zstrdup(jpegfile,"HEIC_PXM_load",8);
pp = strrchr(jpegfix,'.'); pp = strrchr(jpegfix,'.');
strcpy(pp,"-1.jpg"); strcpy(pp,"-1.jpg");
if (! regfile(jpegfix)) goto errret; if (! regfile(jpegfix)) goto errret;
rename(jpegfix,jpegfile); rename(jpegfix,jpegfile);
zfree(jpegfix); zfree(jpegfix);
} }
skipping to change at line 3661 skipping to change at line 3661
return 0; return 0;
} }
if (! regfile(file)) return 0; // no print error if (! regfile(file)) return 0; // no print error
tiffile = zstrdup(file,"JP2_PXB_load",8); // file.jp2 >> file.tif tiffile = zstrdup(file,"JP2_PXB_load",8); // file.jp2 >> file.tif
pp = strrchr(tiffile,'.'); pp = strrchr(tiffile,'.');
if (! pp) goto errret; if (! pp) goto errret;
strcpy(pp,".tif"); strcpy(pp,".tif");
err = zshell(0,"opj_decompress -i \"%s\" -o \"%s\" >/dev/null 2>1",file,tiffi le); err = zshell("log","opj_decompress -i \"%s\" -o \"%s\" >/dev/null 2>1",file,t iffile);
if (err) goto errret; if (err) goto errret;
if (! regfile(tiffile)) goto errret; if (! regfile(tiffile)) goto errret;
pxb = TIFF_PXB_load(tiffile); // make PXB from tif file pxb = TIFF_PXB_load(tiffile); // make PXB from tif file
remove(tiffile); remove(tiffile);
zfree(tiffile); zfree(tiffile);
return pxb; return pxb;
skipping to change at line 3704 skipping to change at line 3704
return 0; return 0;
} }
if (! regfile(file)) return 0; // no print error if (! regfile(file)) return 0; // no print error
tiffile = zstrdup(file,"JP2_PXM_load",8); // file.jp2 >> file.tif tiffile = zstrdup(file,"JP2_PXM_load",8); // file.jp2 >> file.tif
pp = strrchr(tiffile,'.'); pp = strrchr(tiffile,'.');
if (! pp) goto errret; if (! pp) goto errret;
strcpy(pp,".tif"); strcpy(pp,".tif");
err = zshell(0,"opj_decompress -i \"%s\" -o \"%s\" >/dev/null 2>1",file,tiffi le); err = zshell("log","opj_decompress -i \"%s\" -o \"%s\" >/dev/null 2>1",file,t iffile);
if (err) goto errret; if (err) goto errret;
if (! regfile(tiffile)) goto errret; if (! regfile(tiffile)) goto errret;
pxm = TIFF_PXM_load(tiffile); // make PXM from tif file pxm = TIFF_PXM_load(tiffile); // make PXM from tif file
remove(tiffile); remove(tiffile);
zfree(tiffile); zfree(tiffile);
return pxm; return pxm;
skipping to change at line 3764 skipping to change at line 3764
return 0; return 0;
} }
if (! regfile(file)) return 0; // no print error if (! regfile(file)) return 0; // no print error
tiffile = zstrdup(file,"WEBP_PXB_load",8); // file.webp >> file.tif tiffile = zstrdup(file,"WEBP_PXB_load",8); // file.webp >> file.tif
pp = strrchr(tiffile,'.'); pp = strrchr(tiffile,'.');
if (! pp) goto errret; if (! pp) goto errret;
strcpy(pp,".tif"); strcpy(pp,".tif");
err = zshell(0,"dwebp -quiet -tiff \"%s\" -o \"%s\" ",file,tiffile); err = zshell("log","dwebp -quiet -tiff \"%s\" -o \"%s\" ",file,tiffile);
if (err) goto errret; if (err) goto errret;
if (! regfile(tiffile)) goto errret; if (! regfile(tiffile)) goto errret;
pxb = TIFF_PXB_load(tiffile); // make PXB from tif file pxb = TIFF_PXB_load(tiffile); // make PXB from tif file
remove(tiffile); remove(tiffile);
zfree(tiffile); zfree(tiffile);
return pxb; return pxb;
skipping to change at line 3807 skipping to change at line 3807
return 0; return 0;
} }
if (! regfile(file)) return 0; // no print error if (! regfile(file)) return 0; // no print error
tiffile = zstrdup(file,"WEBP_PXM_load",8); // file.webp >> file.tif tiffile = zstrdup(file,"WEBP_PXM_load",8); // file.webp >> file.tif
pp = strrchr(tiffile,'.'); pp = strrchr(tiffile,'.');
if (! pp) goto errret; if (! pp) goto errret;
strcpy(pp,".tif"); strcpy(pp,".tif");
err = zshell(0,"dwebp -quiet -tiff \"%s\" -o \"%s\" ",file,tiffile); err = zshell("log","dwebp -quiet -tiff \"%s\" -o \"%s\" ",file,tiffile);
if (err) goto errret; if (err) goto errret;
if (! regfile(tiffile)) goto errret; if (! regfile(tiffile)) goto errret;
pxm = TIFF_PXM_load(tiffile); // make PXM from tif file pxm = TIFF_PXM_load(tiffile); // make PXM from tif file
remove(tiffile); remove(tiffile);
zfree(tiffile); zfree(tiffile);
return pxm; return pxm;
skipping to change at line 3858 skipping to change at line 3858
char *pp; char *pp;
PXB *pxb = 0; PXB *pxb = 0;
if (! regfile(file)) return 0; // no print error if (! regfile(file)) return 0; // no print error
jpegfile = zstrdup(file,"MPO_PXB_load",8); // construct filename.jpg jpegfile = zstrdup(file,"MPO_PXB_load",8); // construct filename.jpg
pp = strrchr(jpegfile,'.'); pp = strrchr(jpegfile,'.');
if (! pp) goto errret; if (! pp) goto errret;
strcpy(pp,".jpg"); strcpy(pp,".jpg");
zshell(0,"exiftool \"%s\" -mpimage2 -b > \"%s\" ",file,jpegfile); // left image (default) zshell("log","exiftool \"%s\" -mpimage2 -b > \"%s\" ",file,jpegfile); // left image (default)
if (! regfile(jpegfile)) goto errret; if (! regfile(jpegfile)) goto errret;
pxb = JPG_PXB_load(jpegfile,size); // make PXB pxb = JPG_PXB_load(jpegfile,size); // make PXB
errret: errret:
if (jpegfile) remove(jpegfile); // remove jpeg file if (jpegfile) remove(jpegfile); // remove jpeg file
if (jpegfile) zfree(jpegfile); if (jpegfile) zfree(jpegfile);
return pxb; return pxb;
} }
skipping to change at line 3886 skipping to change at line 3886
char *pp; char *pp;
PXM *pxm = 0; PXM *pxm = 0;
if (! regfile(file)) return 0; // no print error if (! regfile(file)) return 0; // no print error
jpegfile = zstrdup(file,"MPO_PXM_load",8); // construct filename.jpg jpegfile = zstrdup(file,"MPO_PXM_load",8); // construct filename.jpg
pp = strrchr(jpegfile,'.'); pp = strrchr(jpegfile,'.');
if (! pp) goto errret; if (! pp) goto errret;
strcpy(pp,".jpg"); strcpy(pp,".jpg");
zshell(0,"exiftool \"%s\" -mpimage2 -b > \"%s\" ",file,jpegfile); // left image (default) zshell("log","exiftool \"%s\" -mpimage2 -b > \"%s\" ",file,jpegfile); // left image (default)
if (! regfile(jpegfile)) goto errret; if (! regfile(jpegfile)) goto errret;
pxm = JPG_PXM_load(jpegfile); // make PXM pxm = JPG_PXM_load(jpegfile); // make PXM
errret: errret:
if (jpegfile) remove(jpegfile); // remove jpeg file if (jpegfile) remove(jpegfile); // remove jpeg file
if (jpegfile) zfree(jpegfile); if (jpegfile) zfree(jpegfile);
return pxm; return pxm;
} }
skipping to change at line 3981 skipping to change at line 3981
pix1 += nc1; pix1 += nc1;
pix2 += nc2; pix2 += nc2;
} }
} }
} }
g_object_unref(pixbuf); g_object_unref(pixbuf);
return pxb; return pxb;
errret: errret:
Plog(1,"pixbuf read error: %s \n",file); Plog(0,"pixbuf read error: %s \n",file);
if (gerror) Plog(1,"%s \n",gerror->message); if (gerror) Plog(0,"%s \n",gerror->message);
return 0; return 0;
} }
// Load PXM pixmap from other file types using the pixbuf library. // Load PXM pixmap from other file types using the pixbuf library.
// bpc = 8. // bpc = 8.
PXM * ANY_PXM_load(cchar *file) PXM * ANY_PXM_load(cchar *file)
{ {
GError *gerror = 0; GError *gerror = 0;
PXM *pxm; PXM *pxm;
skipping to change at line 4055 skipping to change at line 4055
} }
} }
} }
g_object_unref(pixbuf); g_object_unref(pixbuf);
PXM_audit(pxm); // audit/repair PXM_audit(pxm); // audit/repair
return pxm; return pxm;
errret: errret:
Plog(1,"pixbuf read error: %s \n",file); Plog(0,"pixbuf read error: %s \n",file);
if (gerror) Plog(1,"%s \n",gerror->message); if (gerror) Plog(0,"%s \n",gerror->message);
return 0; return 0;
} }
/******************************************************************************* * /******************************************************************************* *
RAW file read functions. RAW file read functions.
There are no write functions. There are no write functions.
******************************************************************************** */ ******************************************************************************** */
int raw_match_thumb_color(cchar *rawfile, PXM *pxm); int raw_match_thumb_color(cchar *rawfile, PXM *pxm);
int raw_match_thumb_color(cchar *rawfile, PXB *pxb); int raw_match_thumb_color(cchar *rawfile, PXB *pxb);
// RAW file to PXB pixmap (pixbuf, 8-bit color) // RAW file to PXB pixmap (pixbuf, 8-bit color)
PXB * RAW_PXB_load(cchar *rawfile, int autobright, int matchthumb) PXB * RAW_PXB_load(cchar *rawfile, int autobright, int matchthumb)
{ {
PXB *pxb = 0; PXB *pxb = 0;
if (Frawloader == 1) pxb = RAW_PXB_load_dcraw(rawfile,autobright); if (Frawloader == 1) pxb = RAW_PXB_load_dcraw(rawfile,autobright);
if (Frawloader == 2) pxb = RAW_PXB_load_RT(rawfile,autobright); if (Frawloader == 2) pxb = RAW_PXB_load_RT(rawfile,autobright);
if (Frawloader == 3) pxb = RAW_PXB_load_DT(rawfile,autobright); if (Frawloader == 3) pxb = RAW_PXB_load_DT(rawfile,autobright);
if (Frawloader == 4) pxb = RAW_PXB_load_custom(rawfile,autobright);
if (! pxb) return 0; if (! pxb) return 0;
if (matchthumb) raw_match_thumb_color(rawfile,pxb); if (matchthumb) raw_match_thumb_color(rawfile,pxb);
return pxb; return pxb;
} }
// RAW file to PXM pixmap (float color) // RAW file to PXM pixmap (float color)
PXM * RAW_PXM_load(cchar *rawfile, int autobright, int matchthumb) PXM * RAW_PXM_load(cchar *rawfile, int autobright, int matchthumb)
{ {
PXM *pxm = 0; PXM *pxm = 0;
if (Frawloader == 1) pxm = RAW_PXM_load_dcraw(rawfile,autobright); if (Frawloader == 1) pxm = RAW_PXM_load_dcraw(rawfile,autobright);
if (Frawloader == 2) pxm = RAW_PXM_load_RT(rawfile,autobright); if (Frawloader == 2) pxm = RAW_PXM_load_RT(rawfile,autobright);
if (Frawloader == 3) pxm = RAW_PXM_load_DT(rawfile,autobright); if (Frawloader == 3) pxm = RAW_PXM_load_DT(rawfile,autobright);
if (Frawloader == 4) pxm = RAW_PXM_load_custom(rawfile,autobright);
if (! pxm) return 0; if (! pxm) return 0;
if (matchthumb) raw_match_thumb_color(rawfile,pxm); if (matchthumb) raw_match_thumb_color(rawfile,pxm);
return pxm; return pxm;
} }
// RAW file to PXB pixmap (pixbuf, 8-bit color, dcraw) // RAW file to PXB pixmap (pixbuf, 8-bit color, dcraw)
PXB * RAW_PXB_load_dcraw(cchar *rawfile, int autobright) PXB * RAW_PXB_load_dcraw(cchar *rawfile, int autobright)
{ {
skipping to change at line 4216 skipping to change at line 4218
cchar *command; cchar *command;
cchar *command1 = "rawtherapee-cli -q -d -t -b16 -Y -c \"%s\" >/dev/null"; cchar *command1 = "rawtherapee-cli -q -d -t -b16 -Y -c \"%s\" >/dev/null";
cchar *command2 = "rawtherapee-cli -q -t -b16 -Y -c \"%s\" >/dev/null"; cchar *command2 = "rawtherapee-cli -q -t -b16 -Y -c \"%s\" >/dev/null";
if (autobright) command = command1; if (autobright) command = command1;
else command = command2; else command = command2;
pp = zescape_quotes(rawfile); // use rawtherapee pp = zescape_quotes(rawfile); // use rawtherapee
err = zshell("log",command,pp); // convert to rawfile.tif err = zshell("log",command,pp); // convert to rawfile.tif
zfree(pp); zfree(pp);
if (err) { if (err) return 0;
Plog(1,"RAW conversion failed: %s \n",rawfile);
return 0;
}
tiffile = zstrdup(rawfile,"RAW_PXB_load",8); // tiff file name = rawfile.tiff tiffile = zstrdup(rawfile,"RAW_PXB_load",8); // tiff file name = rawfile.tif
pp = strrchr(tiffile,'/'); pp = strrchr(tiffile,'/');
pp = strrchr(pp,'.'); pp = strrchr(pp,'.');
if (! pp) pp = tiffile + strlen(tiffile); if (! pp) pp = tiffile + strlen(tiffile);
strcpy(pp,".tif"); strcpy(pp,".tif");
pxb = TIFF_PXB_load(tiffile); pxb = TIFF_PXB_load(tiffile);
remove(tiffile); remove(tiffile);
zfree(tiffile); zfree(tiffile);
skipping to change at line 4252 skipping to change at line 4251
cchar *command; cchar *command;
cchar *command1 = "rawtherapee-cli -q -d -t -b16 -Y -c \"%s\" >/dev/null"; cchar *command1 = "rawtherapee-cli -q -d -t -b16 -Y -c \"%s\" >/dev/null";
cchar *command2 = "rawtherapee-cli -q -t -b16 -Y -c \"%s\" >/dev/null"; cchar *command2 = "rawtherapee-cli -q -t -b16 -Y -c \"%s\" >/dev/null";
if (autobright) command = command1; if (autobright) command = command1;
else command = command2; else command = command2;
pp = zescape_quotes(rawfile); // use rawtherapee pp = zescape_quotes(rawfile); // use rawtherapee
err = zshell("log",command,pp); // convert to rawfile.tif err = zshell("log",command,pp); // convert to rawfile.tif
zfree(pp); zfree(pp);
if (err) { if (err) return 0;
Plog(1,"RAW conversion failed: %s \n",rawfile);
return 0;
}
tiffile = zstrdup(rawfile,"RAW_PXM_load",8); // tiff file name = rawfile.tiff tiffile = zstrdup(rawfile,"RAW_PXM_load",8); // tiff file name = rawfile.tif
pp = strrchr(tiffile,'/'); pp = strrchr(tiffile,'/');
pp = strrchr(pp,'.'); pp = strrchr(pp,'.');
if (! pp) pp = tiffile + strlen(tiffile); if (! pp) pp = tiffile + strlen(tiffile);
strcpy(pp,".tif"); strcpy(pp,".tif");
pxm = TIFF_PXM_load(tiffile); pxm = TIFF_PXM_load(tiffile);
remove(tiffile); remove(tiffile);
zfree(tiffile); zfree(tiffile);
skipping to change at line 4292 skipping to change at line 4288
if (autobright) command = command1; if (autobright) command = command1;
else command = command2; else command = command2;
pp1 = zescape_quotes(rawfile); // construct <rawfile>.jpg pp1 = zescape_quotes(rawfile); // construct <rawfile>.jpg
pp2 = zstrdup(pp1,"RAW_PXB_load",8); pp2 = zstrdup(pp1,"RAW_PXB_load",8);
pp = strrchr(pp2,'.'); pp = strrchr(pp2,'.');
if (! pp) pp = pp2 + strlen(pp2); if (! pp) pp = pp2 + strlen(pp2);
strcpy(pp,".jpg"); strcpy(pp,".jpg");
err = zshell("log",command,pp1,pp2); // convert to rawfile.jpg err = zshell("log",command,pp1,pp2); // convert to rawfile.jpg
if (err) Plog(1,"RAW conversion failed: %s \n",rawfile); if (err) Plog(0,"RAW conversion failed: %s \n",rawfile);
else pxb = JPG_PXB_load(pp2); // load file to PXB else pxb = JPG_PXB_load(pp2); // load file to PXB
remove(pp2); remove(pp2);
zfree(pp1); zfree(pp1);
zfree(pp2); zfree(pp2);
return pxb; return pxb;
} }
// RAW file to PXM pixmap (float color, darktable) // RAW file to PXM pixmap (float color, darktable)
skipping to change at line 4324 skipping to change at line 4320
if (autobright) command = command1; if (autobright) command = command1;
else command = command2; else command = command2;
pp1 = zescape_quotes(rawfile); // construct <rawfile>.jpg pp1 = zescape_quotes(rawfile); // construct <rawfile>.jpg
pp2 = zstrdup(pp1,"RAW_PXM_load",8); pp2 = zstrdup(pp1,"RAW_PXM_load",8);
pp = strrchr(pp2,'.'); pp = strrchr(pp2,'.');
if (! pp) pp = pp2 + strlen(pp2); if (! pp) pp = pp2 + strlen(pp2);
strcpy(pp,".jpg"); strcpy(pp,".jpg");
err = zshell("log",command,pp1,pp2); // convert to rawfile.jpg err = zshell("log",command,pp1,pp2); // convert to rawfile.jpg
if (err) Plog(1,"RAW conversion failed: %s \n",rawfile); if (err) Plog(0,"RAW conversion failed: %s \n",rawfile);
else pxm = JPG_PXM_load(pp2); // load file to PXM else pxm = JPG_PXM_load(pp2); // load file to PXM
remove(pp2); remove(pp2);
zfree(pp1); zfree(pp1);
zfree(pp2); zfree(pp2);
return pxm; return pxm;
} }
// RAW file to PXB pixmap (pixbuf, 8-bit color, custom loader)
PXB * RAW_PXB_load_custom(cchar *rawfile, int autobright)
// 22.35
{
PXB *pxb = 0;
PXM *pxm = 0;
pxm = RAW_PXM_load_custom(rawfile,autobright);
if (! pxm) return 0;
pxb = PXM_PXB_copy(pxm);
PXM_free(pxm);
return pxb;
}
// RAW file to PXM pixmap (float color, custom loader)
PXM * RAW_PXM_load_custom(cchar *rawfile, int autobright)
// 22.35
{
int err;
PXM *pxm = 0;
char *pp, *tiffile;
pp = zescape_quotes(rawfile);
// use custom RAW loader command
err = zshell("log",rawcommand,pp);
// convert to rawfile.tif
zfree(pp);
if (err) return 0;
tiffile = zstrdup(rawfile,"RAW_PXM_load",8);
// tiff file name = rawfile.tif
pp = strrchr(tiffile,'/');
pp = strrchr(pp,'.');
if (! pp) pp = tiffile + strlen(tiffile);
strcpy(pp,".tif");
pxm = TIFF_PXM_load(tiffile);
remove(tiffile);
zfree(tiffile);
return pxm;
}
// Create 512x512 PXB for thumbnail from the embedded image in a RAW file // Create 512x512 PXB for thumbnail from the embedded image in a RAW file
PXB * RAW_thumb_pxb(cchar *rawfile) // 22.1 PXB * RAW_thumb_pxb(cchar *rawfile) // 22.1
{ {
char *thumbfile = 0, *pp; char *thumbfile = 0, *pp;
int err, ww, hh, angle = 0; int err, ww, hh, angle = 0;
PXB *Tpxb = 0, *Rpxb = 0; PXB *Tpxb = 0, *Rpxb = 0;
cchar *exifkey[1] = { exif_orientation_key }; cchar *exifkey[1] = { exif_orientation_key };
char *exifdata[1] = { 0 }, orientation = 0; char *exifdata[1] = { 0 }, orientation = 0;
pp = zescape_quotes(rawfile); pp = zescape_quotes(rawfile);
err = zshell(0,"dcraw -e \"%s\" ",pp); // get .jpg or .ppm embedded image err = zshell(0,"dcraw -e \"%s\" ",pp); // get .jpg or .ppm embedded image
zfree(pp); zfree(pp);
if (err) goto getraw; if (err) goto getraw; // none there
thumbfile = zstrdup(rawfile,"RAW_thumb_pxb",12); // rawfile.thumb.jpg (or .ppm) thumbfile = zstrdup(rawfile,"RAW_thumb_pxb",12); // rawfile.thumb.jpg (or .ppm)
pp = strrchr(thumbfile,'/'); pp = strrchr(thumbfile,'/');
pp = strrchr(pp,'.'); pp = strrchr(pp,'.');
if (! pp) pp = thumbfile + strlen(thumbfile); if (! pp) pp = thumbfile + strlen(thumbfile);
strcpy(pp,".thumb.jpg"); strcpy(pp,".thumb.jpg");
if (regfile(thumbfile)) // make thumb PXB if (regfile(thumbfile)) // make thumb PXB
Tpxb = JPG_PXB_load(thumbfile); Tpxb = JPG_PXB_load(thumbfile);
else { else {
skipping to change at line 4428 skipping to change at line 4465
PXB *Tpxb; PXB *Tpxb;
char *thumbfile, *pp; char *thumbfile, *pp;
int ii, jj, kk, err, rgb, step; int ii, jj, kk, err, rgb, step;
int Tpix, Rpix, Tpix3[3], Rpix3[3]; int Tpix, Rpix, Tpix3[3], Rpix3[3];
int Tdist[3][1024], Rdist[3][1024], Rval[3][1024]; int Tdist[3][1024], Rdist[3][1024], Rval[3][1024];
int Rsum, Tsum, Rbin, Tbin; int Rsum, Tsum, Rbin, Tbin;
uint8 *Tpixel; uint8 *Tpixel;
float *Rpixel; float *Rpixel;
pp = zescape_quotes(rawfile); // get embedded thumbnail file pp = zescape_quotes(rawfile); // get embedded thumbnail file
err = zshell(0,"dcraw -e \"%s\" ",pp); // from raw file err = zshell("log","dcraw -e \"%s\" ",pp); // from raw file
zfree(pp); zfree(pp);
if (err) return 1; if (err) return 1;
thumbfile = zstrdup(rawfile,"raw_match_thumb",12); // rawfile.thumb.jpg thumbfile = zstrdup(rawfile,"raw_match_thumb",12); // rawfile.thumb.jpg
pp = strrchr(thumbfile,'/'); pp = strrchr(thumbfile,'/');
pp = strrchr(pp,'.'); pp = strrchr(pp,'.');
if (! pp) pp = thumbfile + strlen(thumbfile); if (! pp) pp = thumbfile + strlen(thumbfile);
strcpy(pp,".thumb.jpg"); strcpy(pp,".thumb.jpg");
if (regfile(thumbfile)) Tpxb = JPG_PXB_load(thumbfile); // make thumb PXB if (regfile(thumbfile)) Tpxb = JPG_PXB_load(thumbfile); // make thumb PXB
skipping to change at line 4558 skipping to change at line 4595
{ {
PXB *Tpxb; PXB *Tpxb;
char *thumbfile, *pp; char *thumbfile, *pp;
int ii, jj, kk, err, rgb, step; int ii, jj, kk, err, rgb, step;
int Tpix, Rpix, Tpix3[3], Rpix3[3]; int Tpix, Rpix, Tpix3[3], Rpix3[3];
int Tdist[3][1024], Rdist[3][1024], Rval[3][1024]; int Tdist[3][1024], Rdist[3][1024], Rval[3][1024];
int Rsum, Tsum, Rbin, Tbin; int Rsum, Tsum, Rbin, Tbin;
uint8 *Tpixel, *Rpixel; uint8 *Tpixel, *Rpixel;
pp = zescape_quotes(rawfile); // get embedded thumbnail file pp = zescape_quotes(rawfile); // get embedded thumbnail file
err = zshell(0,"dcraw -e \"%s\" ",pp); // from raw file err = zshell("log","dcraw -e \"%s\" ",pp); // from raw file
zfree(pp); zfree(pp);
if (err) return 1; if (err) return 1;
thumbfile = zstrdup(rawfile,"raw_match_thumb",12); // rawfile.thumb.jpg thumbfile = zstrdup(rawfile,"raw_match_thumb",12); // rawfile.thumb.jpg
pp = strrchr(thumbfile,'/'); pp = strrchr(thumbfile,'/');
pp = strrchr(pp,'.'); pp = strrchr(pp,'.');
if (! pp) pp = thumbfile + strlen(thumbfile); if (! pp) pp = thumbfile + strlen(thumbfile);
strcpy(pp,".thumb.jpg"); strcpy(pp,".thumb.jpg");
if (regfile(thumbfile)) Tpxb = JPG_PXB_load(thumbfile); // make thumb PXB if (regfile(thumbfile)) Tpxb = JPG_PXB_load(thumbfile); // make thumb PXB
 End of changes. 61 change blocks. 
96 lines changed or deleted 138 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)