• Home
  • Raw
  • Download

Lines Matching +full:libjpeg +full:- +full:turbo

4  * Use of this source code is governed by a BSD-style license that can be
20 // stdio is needed for libjpeg-turbo
26 #pragma GCC diagnostic ignored "-Wclobbered"
56 if (kExifMarker != marker->marker || marker->data_length < kExifHeaderSize) { in is_orientation_marker()
61 if (0 != memcmp(marker->data, kExifSig, sizeof(kExifSig))) { in is_orientation_marker()
67 return SkParseEncodedOrigin(marker->data + kOffset, marker->data_length - kOffset, in is_orientation_marker()
73 for (jpeg_marker_struct* marker = dinfo->marker_list; marker; marker = marker->next) { in get_exif_orientation()
83 if (kICCMarker != marker->marker || marker->data_length < kICCMarkerHeaderSize) { in is_icc_marker()
87 return !memcmp(marker->data, kICCSig, sizeof(kICCSig)); in is_icc_marker()
98 // Note that 256 will be enough storage space since each markerIndex is stored in 8-bits. in read_color_profile()
105 for (jpeg_marker_struct* marker = dinfo->marker_list; marker; marker = marker->next) { in read_color_profile()
109 numMarkers = marker->data[13]; in read_color_profile()
114 } else if (numMarkers != marker->data[13]) { in read_color_profile()
121 uint8_t markerIndex = marker->data[12]; in read_color_profile()
131 SkASSERT(marker->data_length >= kICCMarkerHeaderSize); in read_color_profile()
132 totalBytes += marker->data_length - kICCMarkerHeaderSize; in read_color_profile()
137 // No non-empty ICC profile markers were found. in read_color_profile()
143 void* dst = iccData->writable_data(); in read_color_profile()
151 void* src = SkTAddOffset<void>(marker->data, kICCMarkerHeaderSize); in read_color_profile()
152 size_t bytes = marker->data_length - kICCMarkerHeaderSize; in read_color_profile()
167 // libjpeg errors will be caught and reported here in ReadHeader()
168 skjpeg_error_mgr::AutoPushJmpBuf jmp(decoderMgr->errorMgr()); in ReadHeader()
170 return decoderMgr->returnFailure("ReadHeader", kInvalidInput); in ReadHeader()
174 decoderMgr->init(); in ReadHeader()
175 auto* dinfo = decoderMgr->dinfo(); in ReadHeader()
204 return decoderMgr->returnFailure("ReadHeader", kIncompleteInput); in ReadHeader()
206 return decoderMgr->returnFailure("ReadHeader", kInvalidInput); in ReadHeader()
212 if (!decoderMgr->getEncodedColor(&color)) { in ReadHeader()
219 auto type = profile->profile()->data_color_space; in ReadHeader()
220 switch (decoderMgr->dinfo()->jpeg_color_space) { in ReadHeader()
245 SkEncodedInfo info = SkEncodedInfo::Make(dinfo->image_width, dinfo->image_height, in ReadHeader()
281 , fReadyState(decoderMgr->dinfo()->global_state) in SkJpegCodec()
291 const size_t colorBytes = (dinfo->out_color_space == JCS_RGB565) ? 2 : in get_row_bytes()
292 dinfo->out_color_components; in get_row_bytes()
293 return dinfo->output_width * colorBytes; in get_row_bytes()
304 dinfo->num_components = 0; in calc_output_dimensions()
305 dinfo->scale_num = num; in calc_output_dimensions()
306 dinfo->scale_denom = denom; in calc_output_dimensions()
314 // libjpeg-turbo supports scaling by 1/8, 1/4, 3/8, 1/2, 5/8, 3/4, 7/8, and 1/1, so we will in onGetScaledDimensions()
336 // Set up a fake decompress struct in order to use libjpeg to calculate output dimensions in onGetScaledDimensions()
339 dinfo.image_width = this->dimensions().width(); in onGetScaledDimensions()
340 dinfo.image_height = this->dimensions().height(); in onGetScaledDimensions()
350 if (kSuccess != ReadHeader(this->stream(), nullptr, &decoderMgr, nullptr)) { in onRewind()
351 return fDecoderMgr->returnFalse("onRewind"); in onRewind()
374 "- it is being decoded as non-opaque, which will draw slower\n"); in conversionSupported()
377 J_COLOR_SPACE encodedColorType = fDecoderMgr->dinfo()->jpeg_color_space; in conversionSupported()
382 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_RGBA; in conversionSupported()
388 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_RGBA; in conversionSupported()
390 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_BGRA; in conversionSupported()
395 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_RGBA; in conversionSupported()
397 fDecoderMgr->dinfo()->dither_mode = JDITHER_NONE; in conversionSupported()
398 fDecoderMgr->dinfo()->out_color_space = JCS_RGB565; in conversionSupported()
407 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_RGBA; in conversionSupported()
409 fDecoderMgr->dinfo()->out_color_space = JCS_GRAYSCALE; in conversionSupported()
414 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_RGBA; in conversionSupported()
420 // Check if we will decode to CMYK. libjpeg-turbo does not convert CMYK to RGBA, so in conversionSupported()
423 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; in conversionSupported()
434 skjpeg_error_mgr::AutoPushJmpBuf jmp(fDecoderMgr->errorMgr()); in onDimensionsSupported()
436 return fDecoderMgr->returnFalse("onDimensionsSupported"); in onDimensionsSupported()
442 // Set up a fake decompress struct in order to use libjpeg to calculate output dimensions in onDimensionsSupported()
446 dinfo.image_width = this->dimensions().width(); in onDimensionsSupported()
447 dinfo.image_height = this->dimensions().height(); in onDimensionsSupported()
450 // libjpeg-turbo can scale to 1/8, 1/4, 3/8, 1/2, 5/8, 3/4, 7/8, and 1/1 in onDimensionsSupported()
462 num -= 1; in onDimensionsSupported()
466 fDecoderMgr->dinfo()->scale_num = num; in onDimensionsSupported()
467 fDecoderMgr->dinfo()->scale_denom = denom; in onDimensionsSupported()
473 // Set the jump location for libjpeg-turbo errors in readRows()
474 skjpeg_error_mgr::AutoPushJmpBuf jmp(fDecoderMgr->errorMgr()); in readRows()
479 // When fSwizzleSrcRow is non-null, it means that we need to swizzle. In this case, in readRows()
483 // When fColorXformSrcRow is non-null, it means that we need to color xform and that in readRows()
491 int dstWidth = opts.fSubset ? opts.fSubset->width() : dstInfo.width(); in readRows()
497 dstWidth = fSwizzler->swizzleWidth(); in readRows()
506 dstWidth = fSwizzler->swizzleWidth(); in readRows()
510 uint32_t lines = jpeg_read_scanlines(fDecoderMgr->dinfo(), &decodeDst, 1); in readRows()
516 fSwizzler->swizzle(swizzleDst, decodeDst); in readRows()
519 if (this->colorXform()) { in readRows()
520 this->applyColorXform(dst, swizzleDst, dstWidth); in readRows()
535 * xform, the color xform will handle the CMYK->RGB conversion.
544 bool hasCMYKColorSpace = srcProfile && srcProfile->data_color_space == skcms_Signature_CMYK; in needs_swizzler_to_convert_from_cmyk()
561 jpeg_decompress_struct* dinfo = fDecoderMgr->dinfo(); in onGetPixels()
563 // Set the jump location for libjpeg errors in onGetPixels()
564 skjpeg_error_mgr::AutoPushJmpBuf jmp(fDecoderMgr->errorMgr()); in onGetPixels()
566 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); in onGetPixels()
570 return fDecoderMgr->returnFailure("startDecompress", kInvalidInput); in onGetPixels()
575 SkASSERT(1 == dinfo->rec_outbuf_height); in onGetPixels()
577 if (needs_swizzler_to_convert_from_cmyk(dinfo->out_color_space, in onGetPixels()
578 this->getEncodedInfo().profile(), this->colorXform())) { in onGetPixels()
579 this->initializeSwizzler(dstInfo, options, true); in onGetPixels()
582 if (!this->allocateStorage(dstInfo)) { in onGetPixels()
586 int rows = this->readRows(dstInfo, dst, dstRowBytes, dstInfo.height(), options); in onGetPixels()
589 return fDecoderMgr->returnFailure("Incomplete image data", kIncompleteInput); in onGetPixels()
600 swizzleBytes = get_row_bytes(fDecoderMgr->dinfo()); in allocateStorage()
601 dstWidth = fSwizzler->swizzleWidth(); in allocateStorage()
602 SkASSERT(!this->colorXform() || SkIsAlign4(swizzleBytes)); in allocateStorage()
607 if (this->colorXform() && sizeof(uint32_t) != dstInfo.bytesPerPixel()) { in allocateStorage()
628 // where libjpeg-turbo provides a subset and then we need to subset it further. in initializeSwizzler()
630 SkASSERT(!fSwizzlerSubset.isEmpty() && fSwizzlerSubset.x() <= options.fSubset->x() && in initializeSwizzler()
631 fSwizzlerSubset.width() == options.fSubset->width()); in initializeSwizzler()
636 if (this->colorXform()) { in initializeSwizzler()
649 switch (fDecoderMgr->dinfo()->out_color_space) { in initializeSwizzler()
677 fDecoderMgr->dinfo()->out_color_space, this->getEncodedInfo().profile(), in getSampler()
678 this->colorXform()); in getSampler()
679 this->initializeSwizzler(this->dstInfo(), this->options(), needsCMYKToRGB); in getSampler()
680 if (!this->allocateStorage(this->dstInfo())) { in getSampler()
688 // Set the jump location for libjpeg errors in onStartScanlineDecode()
689 skjpeg_error_mgr::AutoPushJmpBuf jmp(fDecoderMgr->errorMgr()); in onStartScanlineDecode()
691 SkCodecPrintf("setjmp: Error from libjpeg\n"); in onStartScanlineDecode()
695 if (!jpeg_start_decompress(fDecoderMgr->dinfo())) { in onStartScanlineDecode()
701 fDecoderMgr->dinfo()->out_color_space, this->getEncodedInfo().profile(), in onStartScanlineDecode()
702 this->colorXform()); in onStartScanlineDecode()
704 uint32_t startX = options.fSubset->x(); in onStartScanlineDecode()
705 uint32_t width = options.fSubset->width(); in onStartScanlineDecode()
707 // libjpeg-turbo may need to align startX to a multiple of the IDCT in onStartScanlineDecode()
712 jpeg_crop_scanline(fDecoderMgr->dinfo(), &startX, &width); in onStartScanlineDecode()
714 SkASSERT(startX <= (uint32_t) options.fSubset->x()); in onStartScanlineDecode()
715 SkASSERT(width >= (uint32_t) options.fSubset->width()); in onStartScanlineDecode()
716 SkASSERT(startX + width >= (uint32_t) options.fSubset->right()); in onStartScanlineDecode()
719 // output provided by libjpeg-turbo. in onStartScanlineDecode()
728 // one row at a time, only the subsetting in the x-dimension matters. in onStartScanlineDecode()
729 fSwizzlerSubset.setXYWH(options.fSubset->x() - startX, 0, in onStartScanlineDecode()
730 options.fSubset->width(), options.fSubset->height()); in onStartScanlineDecode()
732 // We will need a swizzler if libjpeg-turbo cannot provide the exact in onStartScanlineDecode()
734 if (startX != (uint32_t) options.fSubset->x() || in onStartScanlineDecode()
735 width != (uint32_t) options.fSubset->width()) { in onStartScanlineDecode()
736 this->initializeSwizzler(dstInfo, options, needsCMYKToRGB); in onStartScanlineDecode()
742 this->initializeSwizzler(dstInfo, options, true); in onStartScanlineDecode()
745 if (!this->allocateStorage(dstInfo)) { in onStartScanlineDecode()
753 int rows = this->readRows(this->dstInfo(), dst, dstRowBytes, count, this->options()); in onGetScanlines()
756 fDecoderMgr->dinfo()->output_scanline = this->dstInfo().height(); in onGetScanlines()
763 // Set the jump location for libjpeg errors in onSkipScanlines()
764 skjpeg_error_mgr::AutoPushJmpBuf jmp(fDecoderMgr->errorMgr()); in onSkipScanlines()
766 return fDecoderMgr->returnFalse("onSkipScanlines"); in onSkipScanlines()
769 return (uint32_t) count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); in onSkipScanlines()
777 SkASSERT(dinfo->scale_num == dinfo->scale_denom); in is_yuv_supported()
782 if (JCS_YCbCr != dinfo->jpeg_color_space) { in is_yuv_supported()
786 SkASSERT(3 == dinfo->num_components); in is_yuv_supported()
787 SkASSERT(dinfo->comp_info); in is_yuv_supported()
791 // libjpeg/libjpeg-turbo. However, we will start by supporting only the in is_yuv_supported()
804 if ((1 != dinfo->comp_info[1].h_samp_factor) || in is_yuv_supported()
805 (1 != dinfo->comp_info[1].v_samp_factor) || in is_yuv_supported()
806 (1 != dinfo->comp_info[2].h_samp_factor) || in is_yuv_supported()
807 (1 != dinfo->comp_info[2].v_samp_factor)) in is_yuv_supported()
820 int hSampY = dinfo->comp_info[0].h_samp_factor; in is_yuv_supported()
821 int vSampY = dinfo->comp_info[0].v_samp_factor; in is_yuv_supported()
822 SkASSERT(hSampY == dinfo->max_h_samp_factor); in is_yuv_supported()
823 SkASSERT(vSampY == dinfo->max_v_samp_factor); in is_yuv_supported()
842 !supportedDataTypes->supported(SkYUVAInfo::PlaneConfig::kY_U_V, in is_yuv_supported()
851 rowBytes[i] = dinfo->comp_info[i].width_in_blocks * DCTSIZE; in is_yuv_supported()
867 jpeg_decompress_struct* dinfo = fDecoderMgr->dinfo(); in onQueryYUVAInfo()
873 jpeg_decompress_struct* dinfo = fDecoderMgr->dinfo(); in onGetYUVAPlanes()
875 return fDecoderMgr->returnFailure("onGetYUVAPlanes", kInvalidInput); in onGetYUVAPlanes()
877 // Set the jump location for libjpeg errors in onGetYUVAPlanes()
878 skjpeg_error_mgr::AutoPushJmpBuf jmp(fDecoderMgr->errorMgr()); in onGetYUVAPlanes()
880 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); in onGetYUVAPlanes()
883 dinfo->raw_data_out = TRUE; in onGetYUVAPlanes()
885 return fDecoderMgr->returnFailure("startDecompress", kInvalidInput); in onGetYUVAPlanes()
906 // Build a JSAMPIMAGE to handle output from libjpeg-turbo. A JSAMPIMAGE has in onGetYUVAPlanes()
907 // a 2-D array of pixels for each of the components (Y, U, V) in the image. in onGetYUVAPlanes()
919 int numYRowsPerBlock = DCTSIZE * dinfo->comp_info[0].v_samp_factor; in onGetYUVAPlanes()
941 const int numIters = dinfo->output_height / numRowsPerBlock; in onGetYUVAPlanes()
959 uint32_t remainingRows = dinfo->output_height - dinfo->output_scanline; in onGetYUVAPlanes()
960 SkASSERT(remainingRows == dinfo->output_height % numRowsPerBlock); in onGetYUVAPlanes()
961 SkASSERT(dinfo->output_scanline == numIters * numRowsPerBlock); in onGetYUVAPlanes()
963 // libjpeg-turbo needs memory to be padded by the block sizes. We will fulfill in onGetYUVAPlanes()
971 int remainingUVRows = dinfo->comp_info[1].downsampled_height - DCTSIZE * numIters; in onGetYUVAPlanes()
998 // libjpeg errors will be caught and reported here in SkGetJpegInfo()
1021 *size = {SkToS32(dinfo->image_width), SkToS32(dinfo->image_height)}; in SkGetJpegInfo()