Skip to content

Commit dfe30b8

Browse files
committed
decoder: add option to set RLE for TGA file write
also accessible as an option int gpujpegtool GPUJPEG 0.27.2
1 parent 502b136 commit dfe30b8

File tree

8 files changed

+102
-7
lines changed

8 files changed

+102
-7
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.10.0 FATAL_ERROR)
22
# change version also in configure.ac
3-
project(gpujpeg VERSION 0.27.1 LANGUAGES C CUDA)
3+
project(gpujpeg VERSION 0.27.2 LANGUAGES C CUDA)
44

55
# options
66
set(BUILD_OPENGL OFF CACHE STRING "Build with OpenGL support, options are: AUTO ON OFF")

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2025-05-19 - 0.27.2
2+
----------
3+
4+
- gpujpegtool: add -H/--fullhelp for addtional opts
5+
- added gpujpeg_endoder_set_option with GPUJPEG_ENCODER_OPT_TGA_RLE
6+
- added gpujpegtool option -O for the options
7+
18
2025-05-14 - 0.27.1
29
----------
310

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
AC_PREREQ([2.65])
22
# change version also in CMakeLists.txt
3-
AC_INIT([libgpujpeg],[0.27.1],[https://github.com/CESNET/GPUJPEG/issues],[libgpujpeg],[https://github.com/CESNET/GPUJPEG])
3+
AC_INIT([libgpujpeg],[0.27.2],[https://github.com/CESNET/GPUJPEG/issues],[libgpujpeg],[https://github.com/CESNET/GPUJPEG])
44
AC_CONFIG_MACRO_DIR([m4])
55
AC_CONFIG_SRCDIR([src/main.c])
66
AC_CONFIG_AUX_DIR([.])

libgpujpeg/gpujpeg_decoder.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @file
3-
* Copyright (c) 2011-2024, CESNET
3+
* Copyright (c) 2011-2025, CESNET
44
* Copyright (c) 2011, Silicon Genome, LLC.
55
*
66
* All rights reserved.
@@ -267,6 +267,18 @@ gpujpeg_decoder_set_output_format(struct gpujpeg_decoder* decoder,
267267
GPUJPEG_API int
268268
gpujpeg_decoder_get_image_info(uint8_t *image, size_t image_size, struct gpujpeg_image_parameters *param_image, struct gpujpeg_parameters *param, int *segment_count);
269269

270+
/// use RLE when writing TGA with gpujpeg_image_save_to_file (default is true), 0 or 1 please note that the option is
271+
/// global so it affects all decoder instances
272+
#define GPUJPEG_DECODER_OPT_TGA_RLE "dec_tga_rle"
273+
/**
274+
* sets decoder option
275+
* @retval GPUJPEG_NOERR option was sucessfully set
276+
* @retval GPUJPEG_ERROR invalid argument passed
277+
*/
278+
GPUJPEG_API int
279+
gpujpeg_decoder_set_option(struct gpujpeg_decoder* decoder, const char *opt, const char* val);
280+
281+
270282
#ifdef __cplusplus
271283
}
272284
#endif

src/gpujpeg_decoder.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "gpujpeg_postprocessor.h"
4040
#include "gpujpeg_reader.h"
4141
#include "gpujpeg_util.h"
42+
#include "utils/image_delegate.h" // for image_delegate_stbi_tga_set_rle
4243

4344
/* Documented at declaration */
4445
void
@@ -476,6 +477,24 @@ gpujpeg_decoder_set_output_format(struct gpujpeg_decoder* decoder, enum gpujpeg_
476477
decoder->req_pixel_format = pixel_format;
477478
}
478479

480+
GPUJPEG_API int
481+
gpujpeg_decoder_set_option(struct gpujpeg_decoder* decoder, const char *opt, const char* val)
482+
{
483+
if ( decoder == NULL || opt == NULL || val == NULL ) {
484+
return GPUJPEG_ERROR;
485+
}
486+
if ( strcmp(opt, GPUJPEG_DECODER_OPT_TGA_RLE) == 0 ) {
487+
if ( val[0] != '0' && val[0] != '1' ) {
488+
ERROR_MSG("Unexpeceted value %s for " GPUJPEG_DECODER_OPT_TGA_RLE "\n", val);
489+
return GPUJPEG_ERROR;
490+
}
491+
image_delegate_stbi_tga_set_rle(val[0] == '1');
492+
return GPUJPEG_NOERR;
493+
}
494+
ERROR_MSG("Invalid decoder option: %s!\n", opt);
495+
return GPUJPEG_ERROR;
496+
}
497+
479498
/* Documented at declaration */
480499
int
481500
gpujpeg_decoder_destroy(struct gpujpeg_decoder* decoder)

src/main.c

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ print_help(bool full)
8585
" -V --version print GPUJPEG version\n"
8686
);
8787
if ( full ) {
88-
printf(" -b, --debug debug helpers (reset GPU for leakcheck, dump infile if not regular)\n");
88+
printf(" -b, --debug debug helpers (reset GPU for leakcheck, dump infile if not regular)\n"
89+
" -O dec_tga_rle=[0|1] set decoder option\n");
8990
}
9091
else {
9192
printf(" -H, --fullhelp print all options\n");
@@ -275,6 +276,46 @@ debug_dump_infile(const char* filename, const uint8_t* image_data, size_t image_
275276
}
276277
}
277278

279+
enum { CODER_OPTS_COUNT = 10 };
280+
struct coder_opts
281+
{
282+
char* opt;
283+
char* val;
284+
};
285+
static bool
286+
assign_decoder_opt(struct coder_opts* opts, char *optarg)
287+
{
288+
char *opt = optarg;
289+
char *delim = strchr(optarg, '=');
290+
if ( delim == NULL ) {
291+
fprintf(stderr, "No value for %s!\n", optarg);
292+
return false;
293+
}
294+
*delim = '\0';
295+
char *val = delim + 1;
296+
for ( int i = 0; i < CODER_OPTS_COUNT; ++i ) {
297+
if ( opts[i].opt == NULL ) {
298+
opts[i].opt = opt;
299+
opts[i].val = val;
300+
return true;
301+
}
302+
}
303+
fprintf(stderr, "Too much optiosn!\n");
304+
return false;
305+
}
306+
static bool
307+
set_decoder_opts(struct gpujpeg_decoder* decoder, const struct coder_opts* opts)
308+
{
309+
while ( (*opts).opt != NULL ) {
310+
if ( gpujpeg_decoder_set_option(decoder, (*opts).opt, (*opts).val) != 0 ) {
311+
return false;
312+
}
313+
opts++;
314+
}
315+
316+
return true;
317+
}
318+
278319
#ifndef GIT_REV
279320
#define GIT_REV "unknown"
280321
#endif
@@ -308,6 +349,7 @@ main(int argc, char *argv[])
308349
int iterate = 1;
309350
_Bool use_opengl = 0;
310351
bool debug = false;
352+
struct coder_opts decoder_options[CODER_OPTS_COUNT + 1] = {0};
311353

312354
// Flags
313355
struct options opts = {.subsampling = GPUJPEG_SUBSAMPLING_UNKNOWN,
@@ -351,7 +393,7 @@ main(int argc, char *argv[])
351393
int ch = '\0';
352394
int optindex = 0;
353395
char* pos = 0;
354-
while ( (ch = getopt_long(argc, argv, "CD:HI:LNRS::Vabc:edf:ghin:oq:r:s:v", longopts, &optindex)) != -1 ) {
396+
while ( (ch = getopt_long(argc, argv, "CD:HI:LNO:RS::Vabc:edf:ghin:oq:r:s:v", longopts, &optindex)) != -1 ) {
355397
switch (ch) {
356398
case 'a':
357399
opts.keep_alpha = true;
@@ -465,6 +507,11 @@ main(int argc, char *argv[])
465507
case 'b':
466508
debug = true;
467509
break;
510+
case 'O':
511+
if ( !assign_decoder_opt(decoder_options, optarg) ) {
512+
return 1;
513+
}
514+
break;
468515
case '?':
469516
return -1;
470517
default:
@@ -684,7 +731,7 @@ main(int argc, char *argv[])
684731

685732
// Create decoder
686733
struct gpujpeg_decoder* decoder = gpujpeg_decoder_create(NULL);
687-
if ( decoder == NULL ) {
734+
if ( decoder == NULL || !set_decoder_opts(decoder, decoder_options) ) {
688735
fprintf(stderr, "Failed to create decoder!\n");
689736
return -1;
690737
}

src/utils/image_delegate.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,13 @@ tst_image_probe_delegate(const char* filename, enum gpujpeg_image_file_format fo
456456
return tst_image_parse_filename(filename, param_image, &unused);
457457
}
458458

459+
// for stbi_save_delegate
460+
void
461+
image_delegate_stbi_tga_set_rle(bool enabled)
462+
{
463+
stbi_write_tga_with_rle = enabled;
464+
}
465+
459466
static int
460467
stbi_save_delegate(const char* filename, const struct gpujpeg_image_parameters* param_image, const char* data)
461468
{

src/utils/image_delegate.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, CESNET z.s.p.o
2+
* Copyright (c) 2020-2025, CESNET
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -70,6 +70,9 @@ image_load_delegate_t gpujpeg_get_image_load_delegate(enum gpujpeg_image_file_fo
7070
image_probe_delegate_t gpujpeg_get_image_probe_delegate(enum gpujpeg_image_file_format format);
7171
image_save_delegate_t gpujpeg_get_image_save_delegate(enum gpujpeg_image_file_format format);
7272

73+
void
74+
image_delegate_stbi_tga_set_rle(bool enabled);
75+
7376
#ifdef __cplusplus
7477
} // extern "C"
7578
#endif // defined __cplusplus

0 commit comments

Comments
 (0)