11/*
2- * Copyright (c) 2020-2024 , 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
4646#include "../../libgpujpeg/gpujpeg_decoder.h" // ddecoder placeholders
4747#include "image_delegate.h"
4848#include "pam.h"
49+ #define STB_IMAGE_WRITE_IMPLEMENTATION
50+ #include "stb_image_write.h"
4951#include "y4m.h"
5052
5153enum {
@@ -363,6 +365,31 @@ tst_image_probe_delegate(const char* filename, enum gpujpeg_image_file_format fo
363365 return tst_image_parse_filename (filename , param_image , & unused_pattern , & unused_seed );
364366}
365367
368+ static int
369+ bmp_save_delegate (const char * filename , const struct gpujpeg_image_parameters * param_image , const char * data )
370+ {
371+ if ( stbi_write_bmp (filename , param_image -> width , param_image -> height ,
372+ gpujpeg_pixel_format_get_comp_count (param_image -> pixel_format ), data ) ) {
373+ return 0 ;
374+ }
375+ ERROR_MSG ("[stbi] Cannot write output file %s: %s\n" , filename , stbi_failure_reason ());
376+ return -1 ;
377+ }
378+
379+ static int
380+ bmp_image_probe_delegate (const char * filename , enum gpujpeg_image_file_format format ,
381+ struct gpujpeg_image_parameters * param_image , bool file_exists )
382+ {
383+ (void )filename ;
384+ (void )format ;
385+ if ( !file_exists ) {
386+ param_image -> pixel_format = GPUJPEG_PIXFMT_AUTODETECT ;
387+ param_image -> color_space = GPUJPEG_CS_DEFAULT ;
388+ return true;
389+ }
390+ abort (); ///< @todo implement
391+ }
392+
366393/// generates deterministic random pattern
367394static void
368395gen_pseudorandom (unsigned char * data , size_t len , int seed )
@@ -440,6 +467,7 @@ image_load_delegate_t gpujpeg_get_image_load_delegate(enum gpujpeg_image_file_fo
440467 return y4m_load_delegate ;
441468 case GPUJPEG_IMAGE_FILE_TST :
442469 return tst_image_load_delegate ;
470+ case GPUJPEG_IMAGE_FILE_BMP : ///< @todo implement
443471 case GPUJPEG_IMAGE_FILE_UNKNOWN :
444472 case GPUJPEG_IMAGE_FILE_JPEG :
445473 case GPUJPEG_IMAGE_FILE_RAW :
@@ -457,6 +485,8 @@ image_load_delegate_t gpujpeg_get_image_load_delegate(enum gpujpeg_image_file_fo
457485image_probe_delegate_t gpujpeg_get_image_probe_delegate (enum gpujpeg_image_file_format format )
458486{
459487 switch (format ) {
488+ case GPUJPEG_IMAGE_FILE_BMP :
489+ return bmp_image_probe_delegate ;
460490 case GPUJPEG_IMAGE_FILE_PGM :
461491 case GPUJPEG_IMAGE_FILE_PPM :
462492 case GPUJPEG_IMAGE_FILE_PNM :
@@ -483,6 +513,8 @@ image_probe_delegate_t gpujpeg_get_image_probe_delegate(enum gpujpeg_image_file_
483513image_save_delegate_t gpujpeg_get_image_save_delegate (enum gpujpeg_image_file_format format )
484514{
485515 switch (format ) {
516+ case GPUJPEG_IMAGE_FILE_BMP :
517+ return bmp_save_delegate ;
486518 case GPUJPEG_IMAGE_FILE_PAM :
487519 return pam_save_delegate ;
488520 case GPUJPEG_IMAGE_FILE_PGM :
0 commit comments