Skip to content

Commit 514eb21

Browse files
committed
decoder: add alignment option
refers to <#107>
1 parent 7a41d59 commit 514eb21

File tree

7 files changed

+36
-9
lines changed

7 files changed

+36
-9
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.12 LANGUAGES C CUDA)
3+
project(gpujpeg VERSION 0.27.13 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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2026-03-19 - 0.27.13
2+
----------
3+
4+
- add decoder option GPUJPEG_DEC_OPT_ALIGNMENT_BYTES_INT (GH-107)
5+
16
2026-02-18 - 0.27.12
27
----------
38

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.12],[https://github.com/CESNET/GPUJPEG/issues],[libgpujpeg],[https://github.com/CESNET/GPUJPEG])
3+
AC_INIT([libgpujpeg],[0.27.13],[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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ gpujpeg_decoder_get_image_info(uint8_t *image, size_t image_size, struct gpujpeg
300300
/// @copydoc GPUJPEG_ENC_OPT_CHANNEL_REMAP
301301
#define GPUJPEG_DEC_OPT_CHANNEL_REMAP "dec_opt_channel_remap"
302302

303+
/// required line padding in bytes
304+
#define GPUJPEG_DEC_OPT_ALIGNMENT_BYTES_INT "dec_opt_alignment_bytes"
305+
303306
/**
304307
* sets decoder option
305308
* @retval GPUJPEG_NOERR option was sucessfully set

src/gpujpeg_decoder.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @file
3-
* Copyright (c) 2011-2025, CESNET
3+
* Copyright (c) 2011-2026, CESNET
44
* Copyright (c) 2011, Silicon Genome, LLC.
55
*
66
* All rights reserved.
@@ -502,6 +502,10 @@ gpujpeg_decoder_set_option(struct gpujpeg_decoder* decoder, const char *opt, con
502502
if ( strcmp(opt, GPUJPEG_DEC_OPT_CHANNEL_REMAP) == 0 ) {
503503
return gpujpeg_opt_set_channel_remap(&decoder->coder, val, GPUJPEG_DEC_OPT_CHANNEL_REMAP);
504504
}
505+
if ( strcmp(opt, GPUJPEG_DEC_OPT_ALIGNMENT_BYTES_INT) == 0 ) {
506+
decoder->req_alignment = atoi(val);
507+
return GPUJPEG_NOERR;
508+
}
505509
ERROR_MSG("Invalid decoder option: %s!\n", opt);
506510
return GPUJPEG_ERROR;
507511
}
@@ -513,8 +517,10 @@ gpujpeg_decoder_print_options()
513517
"] - set decoder option (not) to output RLE TGA\n");
514518
printf("\t" GPUJPEG_DEC_OPT_FLIPPED_BOOL "=[" GPUJPEG_VAL_FALSE "|" GPUJPEG_VAL_TRUE
515519
"] - vertically flip the output image\n");
516-
printf("\t" GPUJPEG_DEC_OPT_CHANNEL_REMAP "=XYZ[W] - input channel mapping, eg. '210F' for GBRX,\n"
520+
printf("\t" GPUJPEG_DEC_OPT_CHANNEL_REMAP "=XYZ[W] - ouput channel mapping, eg. '210F' for GBRX,\n"
517521
"\t\t'210' for GBR; special placeholders 'F' and 'Z' to set a channel to all-ones or all-zeros\n");
522+
printf("\t" GPUJPEG_DEC_OPT_ALIGNMENT_BYTES_INT "=<num> - output alignment in bytes,\n"
523+
"\t\tshould not be used for gpujpegtool (cannot process)\n");
518524
}
519525

520526
/* Documented at declaration */

src/gpujpeg_decoder_internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @file
3-
* Copyright (c) 2011-2025, CESNET
3+
* Copyright (c) 2011-2026, CESNET
44
* Copyright (c) 2011, Silicon Genome, LLC.
55
*
66
* All rights reserved.
@@ -69,6 +69,7 @@ struct gpujpeg_decoder
6969
enum gpujpeg_color_space req_color_space;
7070
bool ff_cs_itu601_is_709; ///< if FFmpeg specific COM marker "CS=ITU601" present, interpret the data as
7171
///< limited-range BT.709 not BT.601
72+
int req_alignment; ///< required output alignment in bytes
7273

7374
/// metadata associated with last decoded image
7475
struct gpujpeg_image_metadata metadata;

src/gpujpeg_reader.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,9 +1581,15 @@ adjust_pixel_format(struct gpujpeg_parameters * param, struct gpujpeg_image_para
15811581
return param_image->pixel_format == GPUJPEG_PIXFMT_NO_ALPHA ? GPUJPEG_444_U8_P012 : GPUJPEG_4444_U8_P0123;
15821582
}
15831583

1584+
/**
1585+
* Adjust the unbound/unset parameters to match JPEG image properties.
1586+
*
1587+
* The main reason is to adnust the @ref gpujpeg_parameters and @ref gpujpeg_image_parameters
1588+
* to be consistend and/or match user requirements.
1589+
*/
15841590
static void
1585-
adjust_format(struct gpujpeg_parameters* param, struct gpujpeg_image_parameters* param_image,
1586-
enum gpujpeg_color_space color_space_internal)
1591+
adjust_params(struct gpujpeg_parameters* param, struct gpujpeg_image_parameters* param_image,
1592+
enum gpujpeg_color_space color_space_internal, unsigned req_alignment_b)
15871593
{
15881594
static_assert(GPUJPEG_PIXFMT_AUTODETECT < 0, "enum gpujpeg_pixel_format type should be signed");
15891595
if ( param_image->color_space == GPUJPEG_NONE) {
@@ -1602,6 +1608,11 @@ adjust_format(struct gpujpeg_parameters* param, struct gpujpeg_image_parameters*
16021608
if ( param_image->pixel_format <= GPUJPEG_PIXFMT_AUTODETECT ) {
16031609
param_image->pixel_format = adjust_pixel_format(param, param_image);
16041610
}
1611+
if (req_alignment_b != 0) {
1612+
const unsigned linesize_b = gpujpeg_pixel_format_get_unit_size(param_image->pixel_format) * param_image->width;
1613+
const unsigned aligned_linesize_b = (linesize_b + req_alignment_b - 1) / req_alignment_b * req_alignment_b;
1614+
param_image->width_padding = (int) (aligned_linesize_b - linesize_b);
1615+
}
16051616
}
16061617

16071618
/* Documented at declaration */
@@ -1669,7 +1680,8 @@ gpujpeg_reader_read_image(struct gpujpeg_decoder* decoder, uint8_t* image, size_
16691680
reader.image_end) != 0 ) {
16701681
return -1;
16711682
}
1672-
adjust_format(&reader.param, &reader.param_image, reader.param.color_space_internal);
1683+
adjust_params(&reader.param, &reader.param_image, reader.param.color_space_internal,
1684+
decoder->req_alignment);
16731685
break;
16741686

16751687
case GPUJPEG_MARKER_DHT:
@@ -1774,7 +1786,7 @@ gpujpeg_reader_get_image_info(uint8_t *image, size_t image_size, struct gpujpeg_
17741786
reader.image_end) != 0 ) {
17751787
return -1;
17761788
}
1777-
adjust_format(&reader.param, &reader.param_image, reader.param.color_space_internal);
1789+
adjust_params(&reader.param, &reader.param_image, reader.param.color_space_internal, 0);
17781790
break;
17791791
}
17801792
case GPUJPEG_MARKER_RST0:

0 commit comments

Comments
 (0)