MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / decode

Method decode

modules/engine/image_coder/src/image_coder_jpeg.cpp:75–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75bool JPEGImageDecoder::decode(EImageCoderColorFormat in_format, uint32_t in_bit_depth) SKR_NOEXCEPT
76{
77 SKR_ASSERT(initialized);
78 int pixel_channels = 0;
79 if ((in_format == IMAGE_CODER_COLOR_FORMAT_RGBA || in_format == IMAGE_CODER_COLOR_FORMAT_BGRA) && in_bit_depth == 8)
80 {
81 pixel_channels = 4;
82 }
83 else if (in_format == IMAGE_CODER_COLOR_FORMAT_Gray && in_bit_depth == 8)
84 {
85 pixel_channels = 1;
86 }
87 else
88 {
89 SKR_ASSERT(false);
90 }
91
92 decoded_size = get_width() * get_height() * pixel_channels;
93 decoded_data = JPEGImageDecoder::Allocate(decoded_size, get_alignment());
94 const int PixelFormat = ConvertTJpegPixelFormat(in_format);
95 const int Flags = TJFLAG_NOREALLOC | TJFLAG_FASTDCT;
96
97 int result = 0;
98 if (result = tjDecompress2(Decompressor,
99 encoded_view.data(), (unsigned long)encoded_view.size(),
100 decoded_data, get_width(), 0, get_height(), PixelFormat, Flags); result == 0)
101 {
102 return true;
103 }
104
105 SKR_LOG_FATAL(u8"TurboJPEG Error %d: %s", result, tjGetErrorStr2(Decompressor));
106 sakura_free(decoded_data);
107 decoded_data = nullptr;
108 return false;
109}
110
111JPEGImageEncoder::JPEGImageEncoder() SKR_NOEXCEPT
112 : BaseImageEncoder()

Callers

nothing calls this directly

Calls 7

get_widthFunction · 0.85
get_heightFunction · 0.85
get_alignmentFunction · 0.85
ConvertTJpegPixelFormatFunction · 0.85
AllocateFunction · 0.50
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected