Bugzilla – Attachment 408518 Details for
Bug 150534
xzgv --exif-orient doesn't work
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
IDP Log In
|
Forgot Password
[patch]
patch to read exif data (again)
xzgv-exif-orient.diff (text/plain), 2.45 KB, created by
Harald Koenig
on 2011-01-15 11:32:21 UTC
(
hide
)
Description:
patch to read exif data (again)
Filename:
MIME Type:
Creator:
Harald Koenig
Created:
2011-01-15 11:32:21 UTC
Size:
2.45 KB
patch
obsolete
>--- src/main.c~ 2009-02-22 22:17:57.000000000 +0100 >+++ src/main.c 2011-01-15 12:23:25.000000000 +0100 >@@ -342,6 +342,118 @@ > } > > >+static unsigned long read_tiff_long(FILE *in,int little_endian) >+{ >+unsigned long ret; >+ >+if(little_endian) >+ { >+ ret=fgetc(in); >+ ret|=(fgetc(in)<<8); >+ ret|=(fgetc(in)<<16); >+ ret|=(fgetc(in)<<24); >+ } >+else >+ { >+ ret=(fgetc(in)<<24); >+ ret|=(fgetc(in)<<16); >+ ret|=(fgetc(in)<<8); >+ ret|=fgetc(in); >+ } >+ >+return(ret); >+} >+ >+ >+static unsigned int read_tiff_short(FILE *in,int little_endian) >+{ >+unsigned int ret; >+ >+if(little_endian) >+ { >+ ret=fgetc(in); >+ ret|=(fgetc(in)<<8); >+ } >+else >+ { >+ ret=(fgetc(in)<<8); >+ ret|=fgetc(in); >+ } >+ >+return(ret); >+} >+ >+ >+int get_exif_orientation(char *filename) >+{ >+static int xzgv_orient_lookup[]={0,1,3,2,7,4,6,5}; >+FILE *in; >+unsigned char buf[4]; >+long ifd0_ofs; >+int little_endian,f,num_ents; >+int exif_orient; >+ >+if((in=fopen(filename,"rb"))==NULL) >+ return(0); >+ >+fread(buf,1,4,in); >+if(memcmp(buf,"\xff\xd8\xff\xe1",4)!=0) >+ { >+ fclose(in); >+ return(0); >+ } >+ >+/* we can ignore data size */ >+fgetc(in); >+fgetc(in); >+ >+fread(buf,1,4,in); >+if(memcmp(buf,"Exif",4)!=0 || fgetc(in) || fgetc(in)) >+ { >+ fclose(in); >+ return(0); >+ } >+ >+/* now at tiff header */ >+fread(buf,1,4,in); >+if(memcmp(buf,"II*\0",4)!=0 && memcmp(buf,"MM\0*",4)!=0) >+ { >+ fclose(in); >+ return(0); >+ } >+ >+little_endian=(memcmp(buf,"II*\0",4)==0); >+ >+/* orientation is an IFD0 tag, so read IFD0 offset and seek */ >+ifd0_ofs=12+read_tiff_long(in,little_endian); >+fseek(in,ifd0_ofs,SEEK_SET); >+ >+/* search IFD0 for Orientation (0x112) */ >+exif_orient=-1; >+num_ents=read_tiff_short(in,little_endian); >+for(f=0;f<num_ents;f++) >+ { >+ fseek(in,ifd0_ofs+2+12*f,SEEK_SET); >+ if(read_tiff_short(in,little_endian)==0x112 && >+ read_tiff_short(in,little_endian)==3 && >+ read_tiff_long(in,little_endian)==1) >+ { >+ exif_orient=read_tiff_short(in,little_endian); >+ break; >+ } >+ } >+ >+fclose(in); >+ >+if(exif_orient<1 || exif_orient>8) >+ return(0); >+ >+/* return, converting Exif orientation to xzgv format */ >+ >+return(xzgv_orient_lookup[exif_orient-1]); >+} >+ >+ > /* small wrapper function for backend_create_image_from_file() which > * deals with mrf files and other oddities (currently GIF/PNG). > * >@@ -359,6 +471,10 @@ > jpeg_exif_orient=0; > > ret=backend_create_image_from_file(file); /* use backend's loader */ >+ >+if(use_exif_orient) >+ jpeg_exif_orient=get_exif_orientation(file); >+ > origw=0; origh=0; > if(ret) > {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
Actions:
View
|
Diff
Attachments on
bug 150534
:
68395
|
408518
|
425443