| 197 | } |
| 198 | |
| 199 | bool JpegCodec::readScaledPixels(ColorType colorType, AlphaType alphaType, size_t dstRowBytes, |
| 200 | void* dstPixels, uint32_t scaleNum) const { |
| 201 | if (dstPixels == nullptr) { |
| 202 | return false; |
| 203 | } |
| 204 | if (colorType == ColorType::ALPHA_8) { |
| 205 | memset(dstPixels, 255, dstRowBytes * static_cast<size_t>(height())); |
| 206 | return true; |
| 207 | } |
| 208 | auto dstInfo = ImageInfo::Make(width(), height(), colorType, alphaType, dstRowBytes); |
| 209 | Bitmap bitmap = {}; |
| 210 | auto outPixels = dstPixels; |
| 211 | auto outRowBytes = dstRowBytes; |
| 212 | J_COLOR_SPACE out_color_space; |
| 213 | switch (colorType) { |
| 214 | case ColorType::RGBA_8888: |
| 215 | out_color_space = JCS_EXT_RGBA; |
| 216 | break; |
| 217 | case ColorType::BGRA_8888: |
| 218 | out_color_space = JCS_EXT_BGRA; |
| 219 | break; |
| 220 | case ColorType::Gray_8: |
| 221 | out_color_space = JCS_GRAYSCALE; |
| 222 | break; |
| 223 | case ColorType::RGB_565: |
| 224 | out_color_space = JCS_RGB565; |
| 225 | break; |
| 226 | default: |
| 227 | auto success = bitmap.allocPixels(width(), height(), false, false); |
| 228 | if (!success) { |
| 229 | return false; |
| 230 | } |
| 231 | out_color_space = JCS_EXT_RGBA; |
| 232 | break; |
| 233 | } |
| 234 | Pixmap pixmap(bitmap); |
| 235 | if (!pixmap.isEmpty()) { |
| 236 | outPixels = pixmap.writablePixels(); |
| 237 | outRowBytes = pixmap.rowBytes(); |
| 238 | } |
| 239 | FILE* infile = nullptr; |
| 240 | if (fileData == nullptr && (infile = fopen(filePath.c_str(), "rb")) == nullptr) { |
| 241 | return false; |
| 242 | } |
| 243 | jpeg_decompress_struct cinfo = {}; |
| 244 | my_error_mgr jerr = {}; |
| 245 | cinfo.err = jpeg_std_error(&jerr.pub); |
| 246 | bool result = false; |
| 247 | do { |
| 248 | if (setjmp(jerr.setjmp_buffer)) break; |
| 249 | jpeg_create_decompress(&cinfo); |
| 250 | if (infile) { |
| 251 | jpeg_stdio_src(&cinfo, infile); |
| 252 | } else { |
| 253 | jpeg_mem_src(&cinfo, fileData->bytes(), fileData->size()); |
| 254 | } |
| 255 | jpeg_save_markers(&cinfo, JPEG_APP0 + 1, 0xFFFF); |
| 256 | jpeg_save_markers(&cinfo, JPEG_APP0 + 2, 0xFFFF); |
nothing calls this directly
no test coverage detected