Skip to content

Commit 13601ed

Browse files
committed
tst_image params to struct
1 parent 959bab5 commit 13601ed

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/utils/image_delegate.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,15 @@ enum tst_pattern {
347347
TST_RANDOM,
348348
};
349349

350+
struct tst_image_parameters
351+
{
352+
enum tst_pattern pattern;
353+
int random_seed;
354+
};
355+
350356
static int
351-
tst_image_parse_filename(const char* filename, struct gpujpeg_image_parameters* param_image, enum tst_pattern* pattern,
352-
int* seed)
357+
tst_image_parse_filename(const char* filename, struct gpujpeg_image_parameters* param_image,
358+
struct tst_image_parameters* tst_params)
353359
{
354360
char fname[PATH_MAX];
355361
snprintf(fname, sizeof fname, "%s", filename);
@@ -374,7 +380,7 @@ tst_image_parse_filename(const char* filename, struct gpujpeg_image_parameters*
374380
// defaults
375381
param_image->color_space = GPUJPEG_RGB;
376382
param_image->pixel_format = GPUJPEG_444_U8_P012;
377-
*pattern = TST_GRADIENT;
383+
tst_params->pattern = TST_GRADIENT;
378384

379385
char *item = NULL;
380386
char *saveptr = NULL;
@@ -395,19 +401,19 @@ tst_image_parse_filename(const char* filename, struct gpujpeg_image_parameters*
395401
}
396402
}
397403
else if ( strcmp(item, "noise") == 0) {
398-
*pattern = TST_NOISE;
404+
tst_params->pattern = TST_NOISE;
399405
}
400406
else if ( strstr(item, "random") == item ) {
401-
*pattern = TST_RANDOM;
407+
tst_params->pattern = TST_RANDOM;
402408
if ( strstr(item, "random_") == item ) {
403-
*seed = atoi(strchr(item, '_') + 1);
409+
tst_params->random_seed = atoi(strchr(item, '_') + 1);
404410
}
405411
}
406412
else if ( strcmp(item, "blank") == 0) {
407-
*pattern = TST_BLANK;
413+
tst_params->pattern = TST_BLANK;
408414
}
409415
else if ( strcmp(item, "gradient") == 0) {
410-
*pattern = TST_GRADIENT;
416+
tst_params->pattern = TST_GRADIENT;
411417
}
412418
else {
413419
fprintf(stderr, "unknown test image option: %s!\n", item);
@@ -425,10 +431,9 @@ tst_image_probe_delegate(const char* filename, enum gpujpeg_image_file_format fo
425431
{
426432
(void)format;
427433
(void)file_exists;
428-
enum tst_pattern unused_pattern = {0};
429-
int unused_seed = 0;
434+
struct tst_image_parameters unused = {0};
430435

431-
return tst_image_parse_filename(filename, param_image, &unused_pattern, &unused_seed);
436+
return tst_image_parse_filename(filename, param_image, &unused);
432437
}
433438

434439
static int
@@ -543,16 +548,15 @@ static int
543548
tst_image_load_delegate(const char* filename, size_t* image_size, void** image_data, allocator_t alloc)
544549
{
545550
struct gpujpeg_image_parameters param_image;
546-
enum tst_pattern pattern = {0};
547-
int random_seed = 12345;
548-
if ( tst_image_parse_filename(filename, &param_image, &pattern, &random_seed) != 0 ) {
551+
struct tst_image_parameters tst_params = {.random_seed = 12345};
552+
if ( tst_image_parse_filename(filename, &param_image, &tst_params) != 0 ) {
549553
return -1;
550554
}
551555
*image_size = gpujpeg_image_calculate_size(&param_image);
552556
*image_data = alloc(*image_size);
553557

554558
// fill some data
555-
switch (pattern) {
559+
switch (tst_params.pattern) {
556560
case TST_GRADIENT: {
557561
struct gpujpeg_image_parameters param_oneline = param_image;
558562
param_oneline.height = 1;
@@ -570,7 +574,7 @@ tst_image_load_delegate(const char* filename, size_t* image_size, void** image_d
570574
break;
571575
}
572576
case TST_RANDOM: {
573-
gen_pseudorandom((unsigned char*)*image_data, *image_size, random_seed);
577+
gen_pseudorandom((unsigned char*)*image_data, *image_size, tst_params.random_seed);
574578
break;
575579
}
576580
case TST_BLANK: {

0 commit comments

Comments
 (0)