Skip to content

Commit fac6d8e

Browse files
committed
initial support for Exif writer
Is not much powerful right now - nothing interesting so far but it will allow eventually adding some metadata not available in other formats (SPIFF is effectively dead, JFIF and Adobe contains almost nothing).
1 parent e399687 commit fac6d8e

File tree

6 files changed

+468
-2
lines changed

6 files changed

+468
-2
lines changed

libgpujpeg/gpujpeg_encoder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ enum gpujpeg_header_type {
195195
GPUJPEG_HEADER_JFIF = 1<<0,
196196
GPUJPEG_HEADER_SPIFF = 1<<1,
197197
GPUJPEG_HEADER_ADOBE = 1<<2, ///< Adobe APP8 header
198+
GPUJPEG_HEADER_EXIF = 1<<3,
198199
};
199200

200201
/**
@@ -227,6 +228,7 @@ gpujpeg_encoder_suggest_restart_interval(const struct gpujpeg_image_parameters*
227228
/// @defgroup enc_hdr_types
228229
/// @{
229230
#define GPUJPEG_ENC_HDR_VAL_JFIF "JFIF"
231+
#define GPUJPEG_ENC_HDR_VAL_EXIF "Exif"
230232
#define GPUJPEG_ENC_HDR_VAL_ADOBE "Adobe"
231233
#define GPUJPEG_ENC_HDR_VAL_SPIFF "SPIFF"
232234
/// @}

src/compat/endian.h

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**
2+
* @file compat/endian.h
3+
* @author Martin Pulec <[email protected]>
4+
*
5+
* endian.h compat macro for macOS, Windows
6+
*
7+
* It will be likely possible to remove later, at least for macOS, because it is
8+
* required by POSIX 2024.
9+
*/
10+
/*
11+
* Copyright (c) 2025 CESNET, zájmové sdružení právnických osob
12+
* All rights reserved.
13+
*
14+
* Redistribution and use in source and binary forms, with or without
15+
* modification, is permitted provided that the following conditions
16+
* are met:
17+
*
18+
* 1. Redistributions of source code must retain the above copyright
19+
* notice, this list of conditions and the following disclaimer.
20+
*
21+
* 2. Redistributions in binary form must reproduce the above copyright
22+
* notice, this list of conditions and the following disclaimer in the
23+
* documentation and/or other materials provided with the distribution.
24+
*
25+
* 3. Neither the name of CESNET nor the names of its contributors may be
26+
* used to endorse or promote products derived from this software without
27+
* specific prior written permission.
28+
*
29+
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
30+
* "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
31+
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
32+
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
33+
* EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
34+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
36+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
39+
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
40+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41+
*/
42+
43+
#ifndef COMPAT_ENDIAN_H_A5D7C443_895D_465E_A46D_BF5E6DAA833F
44+
#define COMPAT_ENDIAN_H_A5D7C443_895D_465E_A46D_BF5E6DAA833F
45+
46+
#ifdef __APPLE__
47+
// https://github.com/zeromq/zmqpp/issues/164#issuecomment-246346344
48+
#include <libkern/OSByteOrder.h>
49+
#ifndef be16toh
50+
#define be16toh(x) OSSwapBigToHostInt16(x)
51+
#define be32toh(x) OSSwapBigToHostInt32(x)
52+
#define be64toh(x) OSSwapBigToHostInt64(x)
53+
54+
#define htobe16(x) OSSwapHostToBigInt16(x)
55+
#define htobe32(x) OSSwapHostToBigInt32(x)
56+
#define htobe64(x) OSSwapHostToBigInt64(x)
57+
58+
#define htole16(x) OSSwapHostToLittleInt16(x)
59+
#define htole32(x) OSSwapHostToLittleInt32(x)
60+
#define htole64(x) OSSwapHostToLittleInt64(x)
61+
62+
#define le16toh(x) OSSwapLittleToHostInt16(x)
63+
#define le32toh(x) OSSwapLittleToHostInt32(x)
64+
#define le64toh(x) OSSwapLittleToHostInt64(x)
65+
#endif
66+
// BYTE_ORDER, LITTLE_ENDIAN, BIG_ENDIAN
67+
#include <machine/endian.h>
68+
69+
#elif defined _WIN32
70+
// little endian archs
71+
#if defined(_M_AMD64) || defined(_M_IX86) || defined(_M_ARM) || \
72+
defined(_M_ARM64) || \
73+
(defined(__BYTE_ORDER__) && \
74+
__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
75+
#include <stdlib.h>
76+
#ifndef be16toh
77+
#define be16toh(x) _byteswap_ushort(x)
78+
#define be32toh(x) _byteswap_ulong(x)
79+
#define be64toh(x) _byteswap_uint64(x)
80+
81+
#define htobe16(x) _byteswap_ushort(x)
82+
#define htobe32(x) _byteswap_ulong(x)
83+
#define htobe64(x) _byteswap_uint64(x)
84+
85+
#define htole16(x) (x)
86+
#define htole32(x) (x)
87+
#define htole64(x) (x)
88+
89+
#define le16toh(x) (x)
90+
#define le32toh(x) (x)
91+
#define le64toh(x) (x)
92+
#endif
93+
#ifndef BYTE_ORDER
94+
#define LITTLE_ENDIAN 1234
95+
#define BIG_ENDIAN 4321
96+
#define BYTE_ORDER LITTLE_ENDIAN
97+
#endif
98+
#else
99+
#error "Unrecognized Win32 configuration (big-endian or unhandled)"
100+
#endif
101+
102+
#else
103+
#include <endian.h>
104+
#endif
105+
106+
#endif // defined COMPAT_ENDIAN_H_A5D7C443_895D_465E_A46D_BF5E6DAA833F

src/gpujpeg_encoder.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,8 @@ gpujpeg_encoder_set_option(struct gpujpeg_encoder* encoder, const char *opt, con
723723
if ( strcmp(opt, GPUJPEG_ENC_OPT_HDR) == 0 ) {
724724
if (strcasecmp(val, GPUJPEG_ENC_HDR_VAL_JFIF) == 0) {
725725
encoder->header_type = GPUJPEG_HEADER_JFIF;
726+
} else if (strcasecmp(val, GPUJPEG_ENC_HDR_VAL_EXIF) == 0) {
727+
encoder->header_type = GPUJPEG_HEADER_EXIF;
726728
} else if (strcasecmp(val, GPUJPEG_ENC_HDR_VAL_ADOBE) == 0) {
727729
encoder->header_type = GPUJPEG_HEADER_ADOBE;
728730
} else if (strcasecmp(val, GPUJPEG_ENC_HDR_VAL_SPIFF) == 0) {
@@ -746,8 +748,8 @@ GPUJPEG_API void
746748
gpujpeg_encoder_print_options() {
747749
printf("\t" GPUJPEG_ENC_OPT_OUT "=[" GPUJPEG_ENC_OUT_VAL_PAGEABLE "|" GPUJPEG_ENC_OUT_VAL_PINNED
748750
"] - compressed data buffer allocation property\n");
749-
printf("\t" GPUJPEG_ENC_OPT_HDR "=[" GPUJPEG_ENC_HDR_VAL_JFIF "|" GPUJPEG_ENC_HDR_VAL_ADOBE "|" GPUJPEG_ENC_HDR_VAL_SPIFF
750-
"] - output JPEG header\n");
751+
printf("\t" GPUJPEG_ENC_OPT_HDR "=[" GPUJPEG_ENC_HDR_VAL_JFIF "|" GPUJPEG_ENC_HDR_VAL_ADOBE
752+
"|" GPUJPEG_ENC_HDR_VAL_EXIF "|" GPUJPEG_ENC_HDR_VAL_SPIFF "] - output JPEG header\n");
751753
printf("\t" GPUJPEG_ENC_OPT_FLIPPED_BOOL "=[" GPUJPEG_VAL_FALSE "|" GPUJPEG_VAL_TRUE
752754
"] - whether is the input image should be vertically flipped (prior encode)\n");
753755
printf("\t" GPUJPEG_ENC_OPT_CHANNEL_REMAP "=XYZ[W] - input channel mapping, eg. '210F' for GBRX,\n"

0 commit comments

Comments
 (0)