Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added data/images/orient_0.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/orient_1.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/orient_2.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/orient_3.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/orient_4.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/orient_5.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/orient_6.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/orient_7.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/orient_8.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ endif()

if(XV_ENABLE_WEBP)
add_compile_definitions(DOWEBP)
set(xv_libs ${xv_libs} WebP::libwebp)
set(xv_libs ${xv_libs} WebP::libwebp -lwebpdemux)
endif()

if(XV_ENABLE_JPEG)
Expand Down Expand Up @@ -93,6 +93,7 @@ set(xv_sources
xvmgcsfx.c
xvmisc.c
xvml.c
xvorient.c
xvpbm.c
xvpcd.c
xvpcx.c
Expand Down
4 changes: 3 additions & 1 deletion src/xv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2311,7 +2311,7 @@ static int openPic(int filenum)
pinfo.exifInfo = (byte *) NULL;
pinfo.numpages = 1;
pinfo.pagebname[0] = '\0';

pinfo.orientation = ORIENT_NONE;

normaspect = defaspect;
freename = dfltkludge = frompipe = frompoll = fromint = wascropped = 0;
Expand Down Expand Up @@ -3552,6 +3552,8 @@ int ReadPicFile(char *fname, int ftype, PICINFO *pinfo, int quick)
#endif

}

reorient_image(pinfo);
return rv;
}

Expand Down
24 changes: 21 additions & 3 deletions src/xv.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,10 @@

#ifdef DOJPEG
# define HAVE_JPEG
# ifdef DOEXIF
# define HAVE_EXIF
# endif
#endif

#ifdef DOEXIF
# define HAVE_EXIF
#endif

#ifdef DOJP2K
Expand Down Expand Up @@ -1130,6 +1131,7 @@ typedef struct { byte *pic; /* image data */
byte *exifInfo; /* image info from digicam */
int exifInfoSize; /* size of image info */

int orientation; /* Which way up is the image? */
int numpages; /* # of page files, if >1 */
char pagebname[64]; /* basename of page files */
} PICINFO;
Expand Down Expand Up @@ -1179,6 +1181,18 @@ typedef struct { int n;
unsigned short int r;
} MKT;

typedef enum orientation {
ORIENT_NONE = 0,
ORIENT_NORMAL = 1,
ORIENT_HFLIP = 2,
ORIENT_ROT180 = 3,
ORIENT_VFLIP = 4,
ORIENT_TRANSPOSE = 5,
ORIENT_ROT90 = 6,
ORIENT_TRANSVERSE = 7,
ORIENT_ROT270 = 8,
} orientation_t;


/* MACROS */
#define CENTERX(f,x,str) ((x)-XTextWidth(f,str, (int) strlen(str))/2)
Expand Down Expand Up @@ -2162,6 +2176,10 @@ int MGCSFXSaveParams PARM((char *, int));
int getInputCom PARM((void));
int getOutputCom PARM((void));

/*************************** XVORIENT.C *************************/
unsigned int get_exif_orientation PARM((byte *buf, unsigned int bufsize));
void reorient_image PARM((PICINFO *pinfo));

/**************************** XVPBM.C ***************************/
#ifdef HAVE_MGCSFX
int LoadPBM PARM((char *, PICINFO *, int));
Expand Down
136 changes: 4 additions & 132 deletions src/xvjpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,6 @@ struct my_error_mgr {

typedef struct my_error_mgr *my_error_ptr;

typedef enum orient {
ORIENT_NONE = 0,
ORIENT_NORMAL = 1,
ORIENT_HFLIP = 2,
ORIENT_ROT180 = 3,
ORIENT_VFLIP = 4,
ORIENT_TRANSPOSE = 5,
ORIENT_ROT90 = 6,
ORIENT_TRANSVERSE = 7,
ORIENT_ROT270 = 8,
} exif_orient_t;

/*** local functions ***/
static void drawJD PARM((int, int, int, int));
static void clickJD PARM((int, int));
Expand Down Expand Up @@ -97,7 +85,6 @@ static const char *fbasename = NULL;
static char *comment = NULL;
static byte *exifInfo = NULL;
static int exifInfoSize = 0; /* not a string => must track size explicitly */
static exif_orient_t exifOrientation = ORIENT_NONE;

static int colorType;

Expand All @@ -106,12 +93,6 @@ static BUTT jbut[J_NBUTTS];

char errbuffer[JMSG_LENGTH_MAX];

#ifdef HAVE_EXIF
static ExifData *exif_data;
static ExifByteOrder exif_byte_order;
static ExifEntry *exif_entry;
#endif /* HAVE_EXIF */


/***************************************************************************/
/* JPEG SAVE DIALOG ROUTINES ***********************************************/
Expand Down Expand Up @@ -530,7 +511,7 @@ int LoadJFIF(char *fname, PICINFO *pinfo, int quick)
const char *colorspace_name;
byte *pic;
long filesize;
int i,w,h,bperpix,bperline,count,swap_xy=0;
int i,w,h,bperpix,bperline,count;


/* Initialize variables below instead of in the declarations above to avoid the warning */
Expand Down Expand Up @@ -690,20 +671,7 @@ int LoadJFIF(char *fname, PICINFO *pinfo, int quick)

jpeg_start_decompress(&cinfo);

#ifdef HAVE_EXIF
exif_data = exif_data_new_from_data(exifInfo, exifInfoSize);
exif_entry = exif_data_get_entry(exif_data, EXIF_TAG_ORIENTATION);
exif_byte_order = exif_data_get_byte_order(exif_data);

/* If the EXIF IFD is as expected, get the orientation from it */
if (exif_entry != NULL &&
exif_entry->components == 1 &&
exif_entry->size == 2 &&
exif_entry->format == EXIF_FORMAT_SHORT)
{
exifOrientation = exif_get_short(exif_entry->data, exif_byte_order);
}
#endif
pinfo->orientation = get_exif_orientation(exifInfo, exifInfoSize);

while (cinfo.output_scanline < cinfo.output_height) {
#if 0
Expand Down Expand Up @@ -758,107 +726,11 @@ int LoadJFIF(char *fname, PICINFO *pinfo, int quick)
pic = realloc(pic,p-pic); /* Release extra storage */
}

/* If we need to transform the image, allocate a new image and populate
** it with the correct pixel values. Then swap the two images.
*/
if (exifOrientation != ORIENT_NONE && exifOrientation != ORIENT_NORMAL)
{
byte *tmppic;
byte *orientpic = (byte *) malloc((size_t) count);
int dst_row, dst_col, dst_row_width;

if (!orientpic) {
SetISTR(ISTR_WARNING, "%s: can't transform JPEG file - out of memory",
fbasename);
goto L1;
}

if (exifOrientation == ORIENT_VFLIP)
{
/* We can copy entire lines for VFLIP images, which will
** be quicker than doing it pixel by pixel, so special
** case this one.
*/
for (int row=0; row < h; row++)
{
memcpy(&orientpic[(h-row-1) * w * bperpix],
&pic[row * w * bperpix],
w * bperpix);
}
} else
{
int src_offset, dst_offset;


for (int row=0; row < h; row++)
{
for (int col=0; col < w; col++)
{
switch(exifOrientation)
{
case ORIENT_ROT90:
dst_col = h-row-1;
dst_row = col;
swap_xy = 1;
break;
case ORIENT_ROT180:
dst_col = w-col-1;
dst_row = h-row-1;
break;
case ORIENT_ROT270:
dst_col = row;
dst_row = w-col-1;
swap_xy = 1;
break;
case ORIENT_HFLIP:
dst_col = w-col-1;
dst_row = row;
break;
case ORIENT_TRANSPOSE:
dst_col = row;
dst_row = col;
swap_xy = 1;
break;
case ORIENT_TRANSVERSE:
dst_col = h-row-1;
dst_row = w-col-1;
swap_xy = 1;
break;
default:
dst_offset = src_offset;
break;
}

dst_row_width = swap_xy ? h : w;

src_offset = (row * w) + col;
dst_offset = (dst_row * dst_row_width) + dst_col;

memcpy(&orientpic[dst_offset * bperpix],
&pic[src_offset * bperpix],
bperpix);
}
}
}

tmppic = pic;
pic = orientpic;
free(tmppic);
}


/* return 'PICINFO' structure to XV */

pinfo->pic = pic;
if (swap_xy)
{
pinfo->w = h;
pinfo->h = w;
} else
{
pinfo->w = w;
pinfo->h = h;
}
pinfo->w = w;
pinfo->h = h;
pinfo->frmType = F_JPEG;

if (cinfo.out_color_space == JCS_GRAYSCALE) {
Expand Down
Loading