2323#include < thread>
2424#include < vector>
2525
26- #include < jxl/decode.h>
27- #include < jxl/decode_cxx.h>
28- #include < jxl/resizable_parallel_runner_cxx.h>
29-
3026#include < gli/gli.hpp>
3127#include < gsl/span>
3228
@@ -113,8 +109,8 @@ image_c* image_c::LoaderForFile(IConsole* conHnd, const char* fileName)
113109 return new dds_c (conHnd);
114110
115111 // Attempt to detect image file type from first 12 bytes of file
116- byte dat[12 ];
117- if (in.Read (dat, 12 )) {
112+ byte dat[4 ];
113+ if (in.Read (dat, 4 )) {
118114 conHnd->Warning (" '%s': cannot read image file (file is corrupt?)" , fileName);
119115 return NULL ;
120116 }
@@ -127,9 +123,6 @@ image_c* image_c::LoaderForFile(IConsole* conHnd, const char* fileName)
127123 } else if (*(dword*)dat == 0x38464947 ) {
128124 // G I F 8
129125 return new gif_c (conHnd);
130- } else if (auto sig = JxlSignatureCheck (dat, 12 ); sig == JXL_SIG_CODESTREAM || sig == JXL_SIG_CONTAINER) {
131- // JPEG XL
132- return new jpeg_xl_c (conHnd);
133126 } else if (*(dword*)dat == 0x20534444 ) {
134127 // D D S 0x20
135128 return new dds_c (conHnd);
@@ -454,96 +447,9 @@ bool gif_c::Save(const char* fileName)
454447}
455448
456449// =========
457- // JPEG XL Image
450+ // DDS Image
458451// =========
459452
460- const std::thread::id g_mainThreadId = std::this_thread::get_id();
461-
462- bool jpeg_xl_c::Load (const char * fileName, std::optional<size_callback_t > sizeCallback)
463- {
464- // Open file
465- fileInputStream_c in;
466- if (in.FileOpen (fileName, true ))
467- return true ;
468-
469- std::vector<byte> fileData (in.GetLen ());
470- if (in.Read (fileData.data (), fileData.size ()))
471- return true ;
472-
473- JxlResizableParallelRunnerPtr runner{};
474- if (g_mainThreadId == std::this_thread::get_id ())
475- runner = JxlResizableParallelRunnerMake (nullptr );
476-
477- auto dec = JxlDecoderMake (nullptr );
478- if (JXL_DEC_SUCCESS != JxlDecoderSubscribeEvents (dec.get (), JXL_DEC_BASIC_INFO | JXL_DEC_FULL_IMAGE))
479- return true ;
480-
481- if (JXL_DEC_SUCCESS != JxlDecoderSetParallelRunner (dec.get (), runner ? JxlResizableParallelRunner : nullptr , runner.get ()))
482- return true ;
483-
484- JxlBasicInfo info{};
485- JxlPixelFormat format = { 4 , JXL_TYPE_UINT8, JXL_NATIVE_ENDIAN, 0 };
486-
487- JxlDecoderSetInput (dec.get (), fileData.data (), fileData.size ());
488- JxlDecoderCloseInput (dec.get ());
489-
490- std::vector<byte> datBuf;
491- int width{};
492- int height{};
493- int comp{};
494-
495- while (true ) {
496- JxlDecoderStatus status = JxlDecoderProcessInput (dec.get ());
497-
498- switch (status) {
499- case JXL_DEC_ERROR:
500- case JXL_DEC_NEED_MORE_INPUT:
501- return true ;
502-
503- case JXL_DEC_BASIC_INFO: {
504- if (JXL_DEC_SUCCESS != JxlDecoderGetBasicInfo (dec.get (), &info))
505- return true ;
506- width = info.xsize ;
507- height = info.ysize ;
508- if (sizeCallback)
509- (*sizeCallback)(width, height);
510- comp = info.num_color_channels + !!info.alpha_bits ;
511- if (comp != 1 && comp != 3 && comp != 4 )
512- return true ;
513-
514- if (runner)
515- JxlResizableParallelRunnerSetThreads (runner.get (), JxlResizableParallelRunnerSuggestThreads (width, height));
516-
517- format.num_channels = comp;
518- } break ;
519-
520- case JXL_DEC_NEED_IMAGE_OUT_BUFFER: {
521- size_t bufferSize{};
522- if (JXL_DEC_SUCCESS != JxlDecoderImageOutBufferSize (dec.get (), &format, &bufferSize))
523- return true ;
524- assert (bufferSize == width * height * comp);
525- datBuf.resize (bufferSize);
526- if (JXL_DEC_SUCCESS != JxlDecoderSetImageOutBuffer (dec.get (), &format, datBuf.data (), bufferSize))
527- return true ;
528- } break ;
529-
530- case JXL_DEC_SUCCESS:
531- case JXL_DEC_FULL_IMAGE: {
532- // We don't care about animations, consider loading completed when a full image has obtained.
533- return !CopyRaw (g_imageTypeFromComp[comp], width, height, datBuf.data ());
534- } break ;
535-
536- default :
537- continue ;
538- }
539- }
540- }
541- bool jpeg_xl_c::Save (const char * fileName)
542- {
543- // Yeah, nah.
544- return false ;
545- }
546-
547453bool dds_c::Load (const char * fileName, std::optional<size_callback_t > sizeCallback)
548454{
549455 auto p = std::filesystem::u8path (fileName);
0 commit comments