Skip to content

Commit ec2b40e

Browse files
committed
Exif writer: pass parameters to fn call
Do not pass gpujpeg_encoder (using the parameters from this struct) and rather pass them explictly. The gpujpeg_writer_write_exif() prototype looked weird when not taking the custom_tags parameter (which is stored in encoder->writer->custom_tags and were accesed implicitly).
1 parent 18e551b commit ec2b40e

File tree

3 files changed

+34
-29
lines changed

3 files changed

+34
-29
lines changed

src/gpujpeg_exif.c

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
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

319318
static 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
368359
void
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;

src/gpujpeg_exif.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@
3737

3838
struct gpujpeg_exif_tags;
3939

40-
struct gpujpeg_encoder;
40+
struct gpujpeg_writer;
41+
struct gpujpeg_image_parameters;
42+
struct gpujpeg_parameters;
43+
4144
void
42-
gpujpeg_writer_write_exif(struct gpujpeg_encoder* encoder);
45+
gpujpeg_writer_write_exif(struct gpujpeg_writer* writer, const struct gpujpeg_parameters* param,
46+
const struct gpujpeg_image_parameters* param_image,
47+
const struct gpujpeg_exif_tags* custom_tags);
4348

4449
bool
4550
gpujpeg_exif_add_tag(struct gpujpeg_exif_tags** exif_tags, const char *cfg);

src/gpujpeg_writer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,8 @@ gpujpeg_writer_write_header(struct gpujpeg_encoder* encoder)
468468
gpujpeg_writer_write_app0(encoder->writer);
469469
break;
470470
case GPUJPEG_HEADER_EXIF:
471-
gpujpeg_writer_write_exif(encoder);
471+
gpujpeg_writer_write_exif(encoder->writer, &encoder->coder.param, &encoder->coder.param_image,
472+
encoder->writer->exif_tags);
472473
break;
473474
case GPUJPEG_HEADER_SPIFF:
474475
gpujpeg_writer_write_spiff(encoder);

0 commit comments

Comments
 (0)