Skip to content

Commit

Permalink
created gpujpeg_color_space_by_name
Browse files Browse the repository at this point in the history
Moved the color space name parsing from gpujpegtool to the library -
it is generally usable.
  • Loading branch information
MartinPulec committed Jun 5, 2024
1 parent 06e1791 commit f3451e1
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 31 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR)
# change version also in configure.ac
project(gpujpeg VERSION 0.25.2 LANGUAGES C CUDA)
project(gpujpeg VERSION 0.25.3 LANGUAGES C CUDA)

# options
set(BUILD_OPENGL OFF CACHE STRING "Build with OpenGL support, options are: AUTO ON OFF")
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2024-06- - 0.25.3
----------
- added gpujpeg_color_space_by_name

2024-04-09 - 0.25.2
----------
- allowed setting subsampling 4:0:0 for color input image
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AC_PREREQ([2.65])
# change version also in CMakeLists.txt
AC_INIT([libgpujpeg],[0.25.2],[https://github.com/CESNET/GPUJPEG/issues],[libgpujpeg],[https://github.com/CESNET/GPUJPEG])
AC_INIT([libgpujpeg],[0.25.3],[https://github.com/CESNET/GPUJPEG/issues],[libgpujpeg],[https://github.com/CESNET/GPUJPEG])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_AUX_DIR([.])
Expand Down
4 changes: 4 additions & 0 deletions libgpujpeg/gpujpeg_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,10 @@ gpujpeg_color_space_get_name(enum gpujpeg_color_space color_space);
GPUJPEG_API enum gpujpeg_pixel_format
gpujpeg_pixel_format_by_name(const char *name);

/** Returns color space by string name */
GPUJPEG_API enum gpujpeg_color_space
gpujpeg_color_space_by_name(const char *name);

/** Returns number of color components in pixel format */
GPUJPEG_API int
gpujpeg_pixel_format_get_comp_count(enum gpujpeg_pixel_format pixel_format);
Expand Down
33 changes: 33 additions & 0 deletions src/gpujpeg_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,39 @@ gpujpeg_pixel_format_by_name(const char *name)
return GPUJPEG_PIXFMT_NONE;
}

enum gpujpeg_color_space
gpujpeg_color_space_by_name(const char* name)
{
if ( strcmp(name, "rgb") == 0 ) {
return GPUJPEG_RGB;
}
if ( strcmp(name, "yuv") == 0 ) {
return GPUJPEG_YUV;
}
if ( strcmp(name, "ycbcr") == 0 ) {
return GPUJPEG_YCBCR;
}
if ( strcmp(name, "ycbcr-jpeg") == 0 ) {
return GPUJPEG_YCBCR_BT601_256LVLS;
}
if ( strcmp(name, "ycbcr-bt601") == 0 ) {
return GPUJPEG_YCBCR_BT601;
}
if ( strcmp(name, "ycbcr-bt709") == 0 ) {
return GPUJPEG_YCBCR_BT709;
}
if ( strcmp(name, "help") == 0 ) {
printf("Available color spaces:\n"
"- rgb\n"
"- yuv (deprecated)\n"
"- ycbcr - same as ycbcr-bt709\n"
"- ycbcr-jpeg - BT.601 full range\n"
"- ycbcr-bt601 - limitted range\n"
"- ycbcr-bt709 - limitted range\n");
}
return GPUJPEG_NONE;
}

int
gpujpeg_pixel_format_get_comp_count(enum gpujpeg_pixel_format pixel_format)
{
Expand Down
34 changes: 5 additions & 29 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,6 @@ print_pixel_formats(void)
" 4444-u8-p0123 (RGBA)\n");
}

static void
print_color_spaces(void)
{
printf("Available color spaces:\n"
"- rgb\n"
"- yuv (deprecated)\n"
"- ycbcr - same as ycbcr-bt709\n"
"- ycbcr-jpeg - BT.601 full range\n"
"- ycbcr-bt601 - limitted range\n"
"- ycbcr-bt709 - limitted range\n");
}

static void
print_help(void)
{
Expand Down Expand Up @@ -335,23 +323,11 @@ main(int argc, char *argv[])
param_image.height = atoi(pos + 1);
break;
case 'c':
if ( strcmp(optarg, "rgb") == 0 )
param_image.color_space = GPUJPEG_RGB;
else if ( strcmp(optarg, "yuv") == 0 )
param_image.color_space = GPUJPEG_YUV;
else if ( strcmp(optarg, "ycbcr") == 0 )
param_image.color_space = GPUJPEG_YCBCR;
else if ( strcmp(optarg, "ycbcr-jpeg") == 0 )
param_image.color_space = GPUJPEG_YCBCR_BT601_256LVLS;
else if ( strcmp(optarg, "ycbcr-bt601") == 0 )
param_image.color_space = GPUJPEG_YCBCR_BT601;
else if ( strcmp(optarg, "ycbcr-bt709") == 0 )
param_image.color_space = GPUJPEG_YCBCR_BT709;
else if ( strcmp(optarg, "help") == 0 ) {
print_color_spaces();
return EXIT_SUCCESS;
}
else {
param_image.color_space = gpujpeg_color_space_by_name(optarg);
if ( param_image.color_space == GPUJPEG_NONE ) {
if ( strcmp(optarg, "help") == 0 ) {
return EXIT_SUCCESS;
}
fprintf(stderr, "Colorspace '%s' is not available!\n", optarg);
return EXIT_FAILURE;
}
Expand Down

0 comments on commit f3451e1

Please sign in to comment.