5252#include "compat/endian.h" // IWYU pragma: keep for htobe32
5353#include "compat/time.h" // IWYU pragma: keep for localtime_s
5454#include "gpujpeg_common_internal.h" // for gpujpeg_coder, ERROR_MSG, WARN...
55- #include "gpujpeg_encoder_internal.h" // for gpujpeg_encoder
5655#include "gpujpeg_marker.h" // for gpujpeg_marker_code
5756#include "gpujpeg_util.h" // for ARR_SIZE
5857#include "gpujpeg_writer.h" // for gpujpeg_writer, gpujpeg_writer...
@@ -317,7 +316,8 @@ remove_overriden(size_t count, struct tag_value tags[static count], const struct
317316}
318317
319318static void
320- gpujpeg_write_0th (struct gpujpeg_encoder * encoder , const uint8_t * start )
319+ gpujpeg_write_0th (struct gpujpeg_writer * writer , const uint8_t * start ,
320+ const struct custom_exif_tags * custom_tags )
321321{
322322 char date_time [] = " : : : : " ; // unknown val by Exif 2.3
323323 time_t now = time (NULL );
@@ -334,46 +334,38 @@ gpujpeg_write_0th(struct gpujpeg_encoder* encoder, const uint8_t* start)
334334 {ETIFF_EXIF_IFD_POINTER , {0 } }, // value will be set later
335335 };
336336 size_t tag_count = ARR_SIZE (tags );
337- const struct custom_exif_tags * custom_tags = & (struct custom_exif_tags ){0 };
338- if (encoder -> writer -> exif_tags != NULL ) {
339- custom_tags = & encoder -> writer -> exif_tags -> tags [CT_TIFF ];
340- tag_count = remove_overriden (tag_count , tags , custom_tags );
341- }
342-
343- gpujpeg_write_ifd (encoder -> writer , start , tag_count , tags , custom_tags );
337+ tag_count = remove_overriden (tag_count , tags , custom_tags );
338+ gpujpeg_write_ifd (writer , start , tag_count , tags , custom_tags );
344339}
345340
346- static void gpujpeg_write_exif_ifd (struct gpujpeg_encoder * encoder , const uint8_t * start )
341+ static void
342+ gpujpeg_write_exif_ifd (struct gpujpeg_writer * writer , const uint8_t * start ,
343+ const struct gpujpeg_image_parameters * param_image , const struct custom_exif_tags * custom_tags )
347344{
348345 struct tag_value tags [] = {
349346 {EEXIF_EXIF_VERSION , {.csvalue = "0230" } }, // 2.30
350347 {EEXIF_COMPONENTS_CONFIGURATION , {.csvalue = "\1\2\3\0" } }, // YCbCr
351348 {EEXIF_FLASHPIX_VERSION , {.csvalue = "0100" } },
352349 {EEXIF_COLOR_SPACE , {.uvalue = (uint32_t []){ETIFF_SRGB }} },
353- {EEXIF_PIXEL_X_DIMENSION , {.uvalue = (uint32_t []){encoder -> coder . param_image . width }} },
354- {EEXIF_PIXEL_Y_DIMENSION , {.uvalue = (uint32_t []){encoder -> coder . param_image . height }}},
350+ {EEXIF_PIXEL_X_DIMENSION , {.uvalue = (uint32_t []){param_image -> width }} },
351+ {EEXIF_PIXEL_Y_DIMENSION , {.uvalue = (uint32_t []){param_image -> height }}},
355352 };
356353 size_t tag_count = ARR_SIZE (tags );
357- const struct custom_exif_tags * custom_tags = & (struct custom_exif_tags ){0 };
358- if (encoder -> writer -> exif_tags != NULL ) {
359- custom_tags = & encoder -> writer -> exif_tags -> tags [CT_EXIF ];
360- tag_count = remove_overriden (tag_count , tags , custom_tags );
361- }
362-
363- gpujpeg_write_ifd (encoder -> writer , start , ARR_SIZE (tags ), tags , custom_tags );
354+ tag_count = remove_overriden (tag_count , tags , custom_tags );
355+ gpujpeg_write_ifd (writer , start , ARR_SIZE (tags ), tags , custom_tags );
364356}
365357
366-
367358/// writes EXIF APP1 marker
368359void
369- gpujpeg_writer_write_exif (struct gpujpeg_encoder * encoder )
360+ gpujpeg_writer_write_exif (struct gpujpeg_writer * writer , const struct gpujpeg_parameters * param ,
361+ const struct gpujpeg_image_parameters * param_image ,
362+ const struct gpujpeg_exif_tags * custom_tags )
370363{
371- if ( encoder -> coder . param . color_space_internal != GPUJPEG_YCBCR_BT601_256LVLS ) {
364+ if ( param -> color_space_internal != GPUJPEG_YCBCR_BT601_256LVLS ) {
372365 WARN_MSG ("[Exif] Color space %s currently not recorded, assumed %s (report)\n" ,
373- gpujpeg_color_space_get_name (encoder -> coder . param . color_space_internal ),
366+ gpujpeg_color_space_get_name (param -> color_space_internal ),
374367 gpujpeg_color_space_get_name (GPUJPEG_YCBCR_BT601_256LVLS ));
375368 }
376- struct gpujpeg_writer * writer = encoder -> writer ;
377369 gpujpeg_writer_emit_marker (writer , GPUJPEG_MARKER_APP1 );
378370
379371 // Length - will be written later
@@ -398,8 +390,15 @@ gpujpeg_writer_write_exif(struct gpujpeg_encoder* encoder)
398390 gpujpeg_writer_emit_2byte (writer , TIFF_HDR_TAG ); // TIFF header
399391 gpujpeg_writer_emit_4byte (writer , 0x08 ); // IFD offset - follows immediately
400392
401- gpujpeg_write_0th (encoder , start );
402- gpujpeg_write_exif_ifd (encoder , start );
393+ const struct custom_exif_tags * tiff_tags = & (const struct custom_exif_tags ){.count = 0 };
394+ const struct custom_exif_tags * exif_tags = & (const struct custom_exif_tags ){.count = 0 };
395+ if ( custom_tags != NULL ) {
396+ tiff_tags = & custom_tags -> tags [CT_TIFF ];
397+ exif_tags = & custom_tags -> tags [CT_EXIF ];
398+ }
399+
400+ gpujpeg_write_0th (writer , start , tiff_tags );
401+ gpujpeg_write_exif_ifd (writer , start , param_image , exif_tags );
403402
404403 // set the marker length
405404 size_t length = writer -> buffer_current - length_p ;
0 commit comments