@@ -144,6 +144,7 @@ const struct exif_tiff_tag_info_t {
144144// misc constants
145145enum {
146146 ETIFF_CENTER = 1 ,
147+ ETIFF_ORIENTATION_VERTICAL = 1 ,
147148 ETIFF_SRGB = 1 ,
148149 ETIFF_INCHES = 2 ,
149150 NEXT_IFD_PTR_SZ = 4 ,
@@ -324,7 +325,7 @@ gpujpeg_write_0th(struct gpujpeg_writer* writer, const uint8_t* start,
324325 struct tm buf ;
325326 (void ) strftime (date_time , sizeof date_time , "%Y:%m:%d %H:%M:%S" , localtime_s (& now , & buf ));
326327 struct tag_value tags [] = {
327- {ETIFF_ORIENTATION , {.uvalue = (uint32_t []){EXIF_ORIENTATION_HORIZONTAL }}},
328+ {ETIFF_ORIENTATION , {.uvalue = (uint32_t []){ETIFF_ORIENTATION_VERTICAL }}},
328329 {ETIFF_XRESOLUTION , {.uvalue = (uint32_t []){DPI_DEFAULT , 1 }} },
329330 {ETIFF_YRESOLUTION , {.uvalue = (uint32_t []){DPI_DEFAULT , 1 }} },
330331 {ETIFF_RESOLUTION_UNIT , {.uvalue = (uint32_t []){ETIFF_INCHES }} },
@@ -611,9 +612,31 @@ read_4byte_le(uint8_t** image) {
611612 return ret ;
612613}
613614
615+ static void
616+ exif_orieintation_to_metadata (unsigned val , struct gpujpeg_image_metadata * parsed )
617+ {
618+ if (val == 0 || val > 8 ) {
619+ WARN_MSG (MOD_NAME "Flawed orientation value %d! Should be 1-8...\n" , val );
620+ return ;
621+ }
622+ // clang-format off
623+ struct gpujpeg_orientation map [] = {
624+ {0 , 0 }, // 1 = The 0th row is at the visual top of the image, and the 0th column is the visual left-hand side.
625+ {0 , 1 }, // 2 = The 0th row is at the visual top of the image, and the 0th column is the visual right-hand side.
626+ {2 , 0 }, // 3 = The 0th row is at the visual bottom of the image, and the 0th column is the visual right-hand side.
627+ {2 , 1 }, // 4 = The 0th row is at the visual bottom of the image, and the 0th column is the visual left-hand side.
628+ {1 , 1 }, // 5 = The 0th row is the visual left-hand side of the image, and the 0th column is the visual top.
629+ {1 , 0 }, // 6 = The 0th row is the visual right-hand side of the image, and the 0th column is the visual top.
630+ {3 , 1 }, // 7 = The 0th row is the visual right-hand side of the image, and the 0th column is the visual bottom.
631+ {3 , 0 }, // 8 = The 0th row is the visual left-hand side of the image, and the 0th column is the visual bottom.
632+ };
633+ // clang-format on
634+ parsed -> orientation = map [val - 1 ];
635+ }
636+
614637static void
615638read_0th_ifd (uint8_t * * image , const uint8_t * image_end , int verbose , uint16_t (* read_2byte )(uint8_t * * ),
616- uint32_t (* read_4byte )(uint8_t * * ), struct gpujpeg_exif_parameters * parsed )
639+ uint32_t (* read_4byte )(uint8_t * * ), struct gpujpeg_image_metadata * parsed )
617640{
618641 if ( * image + 2 > image_end ) {
619642 WARN_MSG ("Unexpected end of file!\n" );
@@ -646,7 +669,7 @@ read_0th_ifd(uint8_t** image, const uint8_t* image_end, int verbose, uint16_t (*
646669 DEBUG_MSG (verbose , MOD_NAME "Found IFD0 tag %s (%#x) type %s: count=%u, %s=%#x\n" , exif_tiff_tag_info [tag ].name ,
647670 tag_id , type_name , count , count * size <= 4 ? "value" : "offset" , val );
648671 if ( tag == ETIFF_ORIENTATION ) {
649- parsed -> orientation = val ;
672+ exif_orieintation_to_metadata ( val , parsed ) ;
650673 }
651674 }
652675
@@ -663,7 +686,7 @@ read_0th_ifd(uint8_t** image, const uint8_t* image_end, int verbose, uint16_t (*
663686 * JPEG Orientation is checked and of not horizontal, warning is issued.
664687 */
665688void
666- gpujpeg_exif_parse (uint8_t * * image , const uint8_t * image_end , int verbose , struct gpujpeg_exif_parameters * parsed )
689+ gpujpeg_exif_parse (uint8_t * * image , const uint8_t * image_end , int verbose , struct gpujpeg_image_metadata * metadata )
667690{
668691#define HANDLE_ERROR (...) \
669692 WARN_MSG(__VA_ARGS__); \
@@ -713,7 +736,7 @@ gpujpeg_exif_parse(uint8_t** image, const uint8_t* image_end, int verbose, struc
713736
714737 uint32_t offset = read_4byte (image ); // 0th IFD offset
715738 * image = base + offset ;
716- read_0th_ifd (image , image_end , verbose , read_2byte , read_4byte , parsed );
739+ read_0th_ifd (image , image_end , verbose , read_2byte , read_4byte , metadata );
717740
718741 * image = image_start + length ;
719742#undef HANDLE_ERROR
0 commit comments