Skip to content

Commit

Permalink
added testing input
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPulec committed Jun 5, 2024
1 parent 1da700b commit d5436b0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
2 changes: 2 additions & 0 deletions libgpujpeg/gpujpeg_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ enum gpujpeg_image_file_format {
GPUJPEG_IMAGE_FILE_YUVA,
/// i420 file format
GPUJPEG_IMAGE_FILE_I420,
/// testing (empty) image, that is SW generated
GPUJPEG_IMAGE_FILE_TST,
};

/**
Expand Down
7 changes: 4 additions & 3 deletions src/gpujpeg_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ gpujpeg_image_get_file_format(const char* filename)
{ "ppm", GPUJPEG_IMAGE_FILE_PPM},
{ "pam", GPUJPEG_IMAGE_FILE_PAM},
{ "y4m", GPUJPEG_IMAGE_FILE_Y4M},
{ "tst", GPUJPEG_IMAGE_FILE_TST},
};

const char * ext = strrchr(filename, '.');
Expand All @@ -407,6 +408,7 @@ static enum { FF_CS_NONE, FF_CS_RGB, FF_CS_YCBCR } get_file_type_cs(enum gpujpeg
case GPUJPEG_IMAGE_FILE_UNKNOWN:
case GPUJPEG_IMAGE_FILE_JPEG:
case GPUJPEG_IMAGE_FILE_RAW:
case GPUJPEG_IMAGE_FILE_TST:
return FF_CS_NONE;
case GPUJPEG_IMAGE_FILE_GRAY:
case GPUJPEG_IMAGE_FILE_Y4M:
Expand Down Expand Up @@ -1186,9 +1188,8 @@ int
gpujpeg_image_get_properties(const char *filename, struct gpujpeg_image_parameters *param_image, int file_exists)
{
const enum gpujpeg_image_file_format format = gpujpeg_image_get_file_format(filename);
image_probe_delegate_t image_probe_delegate =
gpujpeg_get_image_probe_delegate(gpujpeg_image_get_file_format(filename));
if (image_probe_delegate) {
image_probe_delegate_t image_probe_delegate = gpujpeg_get_image_probe_delegate(format);
if ( image_probe_delegate ) {
return image_probe_delegate(filename, format, param_image, file_exists);
}

Expand Down
55 changes: 55 additions & 0 deletions src/utils/image_delegate.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,57 @@ int y4m_save_delegate(const char *filename, const struct gpujpeg_image_parameter
return y4m_write(filename, &info, (const unsigned char *) data) ? 0 : -1;
}

static int
tst_image_probe_delegate(const char* filename, enum gpujpeg_image_file_format format,
struct gpujpeg_image_parameters* param_image, bool file_exists)
{
(void) format;
(void) file_exists;

char color_space[21];
char pixel_format[21];
const int nelem = sscanf(filename, "%dx%d_%20[^_.]_%20[^_.]s", &param_image->width, &param_image->height,
color_space, pixel_format);
if ( nelem < 2 ) {
printf("Usage:\n\t<W>x<H>[_<CS>[_<PF>]]\n");
return -1;
}
if ( nelem >= 3 ) {
param_image->color_space = gpujpeg_color_space_by_name(color_space);
if ( param_image->color_space == GPUJPEG_NONE ) {
fprintf(stderr, "Unknown color space: %s\n", color_space);
return -1;
}
}
else {
param_image->color_space = GPUJPEG_RGB;
}
if ( nelem >= 4 ) {
param_image->pixel_format = gpujpeg_pixel_format_by_name(pixel_format);
if ( param_image->pixel_format == GPUJPEG_PIXFMT_NONE ) {
fprintf(stderr, "Unknown pixel format: %s\n", pixel_format);
return -1;
}
}
else {
param_image->pixel_format = GPUJPEG_444_U8_P012;
}
return 0;
}

static int
tst_image_load_delegate(const char* filename, size_t* image_size, void** image_data, allocator_t alloc)
{
struct gpujpeg_image_parameters param_image;
if (tst_image_probe_delegate(filename, GPUJPEG_IMAGE_FILE_TST, &param_image, false) != 0) {
return -1;
}
*image_size = gpujpeg_image_calculate_size(&param_image);
*image_data = alloc(*image_size);
memset(*image_data, 0, *image_size);
return 0;
}

image_load_delegate_t gpujpeg_get_image_load_delegate(enum gpujpeg_image_file_format format) {
switch (format) {
case GPUJPEG_IMAGE_FILE_PGM:
Expand All @@ -245,6 +296,8 @@ image_load_delegate_t gpujpeg_get_image_load_delegate(enum gpujpeg_image_file_fo
return pam_load_delegate;
case GPUJPEG_IMAGE_FILE_Y4M:
return y4m_load_delegate;
case GPUJPEG_IMAGE_FILE_TST:
return tst_image_load_delegate;
default:
return NULL;
}
Expand All @@ -260,6 +313,8 @@ image_probe_delegate_t gpujpeg_get_image_probe_delegate(enum gpujpeg_image_file_
return pampnm_probe_delegate;
case GPUJPEG_IMAGE_FILE_Y4M:
return y4m_probe_delegate;
case GPUJPEG_IMAGE_FILE_TST:
return tst_image_probe_delegate;
default:
return NULL;
}
Expand Down

0 comments on commit d5436b0

Please sign in to comment.