| 73 | } |
| 74 | |
| 75 | bool 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 | |
| 111 | JPEGImageEncoder::JPEGImageEncoder() SKR_NOEXCEPT |
| 112 | : BaseImageEncoder() |
nothing calls this directly
no test coverage detected