Skip to content

Commit bc41d4a

Browse files
committed
gpujpeg_metadata: more generic
allow more metadata items + add flag if it is set or not gpujpegtool: if orientation not set, do not print its value
1 parent e921116 commit bc41d4a

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

libgpujpeg/gpujpeg_type.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,24 @@ struct gpujpeg_component_sampling_factor
142142
uint8_t vertical;
143143
};
144144

145+
enum {
146+
GPUJPEG_METADATA_ORIENTATION,
147+
GPUJPEG_METADATA_COUNT,
148+
};
145149
struct gpujpeg_orientation /// as defined in SPIFF
146150
{
147151
unsigned rotation : 2; ///< in multiples of 90° clock-wise
148152
unsigned flip : 1; ///< 1 - left-to-right orientation flipped after rotation applied
149153
};
150-
151154
struct gpujpeg_image_metadata
152155
{
153-
struct gpujpeg_orientation orientation;
156+
struct
157+
{
158+
union {
159+
struct gpujpeg_orientation orient;
160+
};
161+
unsigned set : 1; ///< item is set, otherwise the union value is undefined
162+
} vals[GPUJPEG_METADATA_COUNT];
154163
};
155164

156165
#ifdef __cplusplus

src/gpujpeg_exif.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,8 @@ exif_orieintation_to_metadata(unsigned val, struct gpujpeg_image_metadata* parse
630630
{3, 0}, // 8 = The 0th row is the visual left-hand side of the image, and the 0th column is the visual bottom.
631631
};
632632
// clang-format on
633-
parsed->orientation = map[val - 1];
633+
parsed->vals[GPUJPEG_METADATA_ORIENTATION].orient = map[val - 1];
634+
parsed->vals[GPUJPEG_METADATA_ORIENTATION].set = 1;
634635
}
635636

636637
static void

src/gpujpeg_reader.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,8 +1638,12 @@ gpujpeg_reader_read_image(struct gpujpeg_decoder* decoder, uint8_t* image, size_
16381638
return -1;
16391639
}
16401640

1641-
if ( reader.metadata.orientation.rotation != 0 || reader.metadata.orientation.flip != 0 ) {
1642-
WARN_MSG("Orientation %s not handled!\n", gpujpeg_orientation_get_name(reader.metadata.orientation));
1641+
if ( reader.metadata.vals[GPUJPEG_METADATA_ORIENTATION].set ) {
1642+
if ( reader.metadata.vals[GPUJPEG_METADATA_ORIENTATION].orient.rotation != 0 ||
1643+
reader.metadata.vals[GPUJPEG_METADATA_ORIENTATION].orient.flip != 0 ) {
1644+
WARN_MSG("Orientation %s not handled!\n",
1645+
gpujpeg_orientation_get_name(reader.metadata.vals[GPUJPEG_METADATA_ORIENTATION].orient));
1646+
}
16431647
}
16441648

16451649
return 0;

src/main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,10 @@ static int print_image_info_jpeg(const char *filename, int verbose) {
206206
gpujpeg_subsampling_get_name(info.param.comp_count, info.param.sampling_factor));
207207
printf("interleaved: %s\n", info.param.interleaved ? "yes" : "no");
208208
printf("header type: %s\n", gpujpeg_header_type_get_name(info.header_type));
209-
printf("orientation: %s\n", gpujpeg_orientation_get_name(info.metadata.orientation));
209+
if ( info.metadata.vals[GPUJPEG_METADATA_ORIENTATION].set ) {
210+
printf("orientation: %s\n",
211+
gpujpeg_orientation_get_name(info.metadata.vals[GPUJPEG_METADATA_ORIENTATION].orient));
212+
}
210213
if ( info.segment_count ) {
211214
printf("segment count: %d (DRI = %d)\n", info.segment_count, info.param.restart_interval);
212215
}

0 commit comments

Comments
 (0)