Flutter Engine
The Flutter Engine
Namespaces | Functions
SkJpegCodec.cpp File Reference
#include "src/codec/SkJpegCodec.h"
#include "include/codec/SkCodec.h"
#include "include/codec/SkJpegDecoder.h"
#include "include/core/SkAlphaType.h"
#include "include/core/SkColorType.h"
#include "include/core/SkData.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkStream.h"
#include "include/core/SkTypes.h"
#include "include/core/SkYUVAInfo.h"
#include "include/private/base/SkAlign.h"
#include "include/private/base/SkMalloc.h"
#include "include/private/base/SkTemplates.h"
#include "modules/skcms/skcms.h"
#include "src/codec/SkCodecPriv.h"
#include "src/codec/SkJpegConstants.h"
#include "src/codec/SkJpegDecoderMgr.h"
#include "src/codec/SkJpegMetadataDecoderImpl.h"
#include "src/codec/SkJpegPriv.h"
#include "src/codec/SkParseEncodedOrigin.h"
#include "src/codec/SkSwizzler.h"
#include <array>
#include <csetjmp>
#include <cstring>
#include <utility>
#include "jpeglib.h"

Go to the source code of this file.

Namespaces

namespace  SkJpegDecoder
 

Functions

SkJpegMarkerList get_sk_marker_list (jpeg_decompress_struct *dinfo)
 
static SkEncodedOrigin get_exif_orientation (sk_sp< SkData > exifData)
 
static size_t get_row_bytes (const j_decompress_ptr dinfo)
 
void calc_output_dimensions (jpeg_decompress_struct *dinfo, unsigned int num, unsigned int denom)
 
static bool needs_swizzler_to_convert_from_cmyk (J_COLOR_SPACE jpegColorType, const skcms_ICCProfile *srcProfile, bool hasColorSpaceXform)
 
static bool is_yuv_supported (const jpeg_decompress_struct *dinfo, const SkJpegCodec &codec, const SkYUVAPixmapInfo::SupportedDataTypes *supportedDataTypes, SkYUVAPixmapInfo *yuvaPixmapInfo)
 
SK_API bool SkJpegDecoder::IsJpeg (const void *, size_t)
 
SK_API std::unique_ptr< SkCodecSkJpegDecoder::Decode (std::unique_ptr< SkStream >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
 
SK_API std::unique_ptr< SkCodecSkJpegDecoder::Decode (sk_sp< SkData >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
 

Function Documentation

◆ calc_output_dimensions()

void calc_output_dimensions ( jpeg_decompress_struct *  dinfo,
unsigned int  num,
unsigned int  denom 
)

Definition at line 222 of file SkJpegCodec.cpp.

222 {
223 dinfo->num_components = 0;
224 dinfo->scale_num = num;
225 dinfo->scale_denom = denom;
226 jpeg_calc_output_dimensions(dinfo);
227}

◆ get_exif_orientation()

static SkEncodedOrigin get_exif_orientation ( sk_sp< SkData exifData)
static

Definition at line 69 of file SkJpegCodec.cpp.

69 {
71 if (exifData && SkParseEncodedOrigin(exifData->bytes(), exifData->size(), &origin)) {
72 return origin;
73 }
75}
SkEncodedOrigin
@ kDefault_SkEncodedOrigin
bool SkParseEncodedOrigin(const void *data, size_t data_length, SkEncodedOrigin *orientation)
const uint8_t * bytes() const
Definition: SkData.h:43
size_t size() const
Definition: SkData.h:30

◆ get_row_bytes()

static size_t get_row_bytes ( const j_decompress_ptr  dinfo)
static

Definition at line 209 of file SkJpegCodec.cpp.

209 {
210 const size_t colorBytes = (dinfo->out_color_space == JCS_RGB565) ? 2 :
211 dinfo->out_color_components;
212 return dinfo->output_width * colorBytes;
213
214}

◆ get_sk_marker_list()

SkJpegMarkerList get_sk_marker_list ( jpeg_decompress_struct *  dinfo)

Definition at line 60 of file SkJpegCodec.cpp.

60 {
61 SkJpegMarkerList markerList;
62 for (auto* marker = dinfo->marker_list; marker; marker = marker->next) {
63 markerList.emplace_back(marker->marker,
64 SkData::MakeWithoutCopy(marker->data, marker->data_length));
65 }
66 return markerList;
67}
static const char marker[]
std::vector< SkJpegMarker > SkJpegMarkerList
static sk_sp< SkData > MakeWithoutCopy(const void *data, size_t length)
Definition: SkData.h:116

◆ is_yuv_supported()

static bool is_yuv_supported ( const jpeg_decompress_struct *  dinfo,
const SkJpegCodec codec,
const SkYUVAPixmapInfo::SupportedDataTypes supportedDataTypes,
SkYUVAPixmapInfo yuvaPixmapInfo 
)
static

Definition at line 693 of file SkJpegCodec.cpp.

696 {
697 // Scaling is not supported in raw data mode.
698 SkASSERT(dinfo->scale_num == dinfo->scale_denom);
699
700 // I can't imagine that this would ever change, but we do depend on it.
701 static_assert(8 == DCTSIZE, "DCTSIZE (defined in jpeg library) should always be 8.");
702
703 if (JCS_YCbCr != dinfo->jpeg_color_space) {
704 return false;
705 }
706
707 SkASSERT(3 == dinfo->num_components);
708 SkASSERT(dinfo->comp_info);
709
710 // It is possible to perform a YUV decode for any combination of
711 // horizontal and vertical sampling that is supported by
712 // libjpeg/libjpeg-turbo. However, we will start by supporting only the
713 // common cases (where U and V have samp_factors of one).
714 //
715 // The definition of samp_factor is kind of the opposite of what SkCodec
716 // thinks of as a sampling factor. samp_factor is essentially a
717 // multiplier, and the larger the samp_factor is, the more samples that
718 // there will be. Ex:
719 // U_plane_width = image_width * (U_h_samp_factor / max_h_samp_factor)
720 //
721 // Supporting cases where the samp_factors for U or V were larger than
722 // that of Y would be an extremely difficult change, given that clients
723 // allocate memory as if the size of the Y plane is always the size of the
724 // image. However, this case is very, very rare.
725 if ((1 != dinfo->comp_info[1].h_samp_factor) ||
726 (1 != dinfo->comp_info[1].v_samp_factor) ||
727 (1 != dinfo->comp_info[2].h_samp_factor) ||
728 (1 != dinfo->comp_info[2].v_samp_factor))
729 {
730 return false;
731 }
732
733 // Support all common cases of Y samp_factors.
734 // TODO (msarett): As mentioned above, it would be possible to support
735 // more combinations of samp_factors. The issues are:
736 // (1) Are there actually any images that are not covered
737 // by these cases?
738 // (2) How much complexity would be added to the
739 // implementation in order to support these rare
740 // cases?
741 int hSampY = dinfo->comp_info[0].h_samp_factor;
742 int vSampY = dinfo->comp_info[0].v_samp_factor;
743 SkASSERT(hSampY == dinfo->max_h_samp_factor);
744 SkASSERT(vSampY == dinfo->max_v_samp_factor);
745
746 SkYUVAInfo::Subsampling tempSubsampling;
747 if (1 == hSampY && 1 == vSampY) {
748 tempSubsampling = SkYUVAInfo::Subsampling::k444;
749 } else if (2 == hSampY && 1 == vSampY) {
750 tempSubsampling = SkYUVAInfo::Subsampling::k422;
751 } else if (2 == hSampY && 2 == vSampY) {
752 tempSubsampling = SkYUVAInfo::Subsampling::k420;
753 } else if (1 == hSampY && 2 == vSampY) {
754 tempSubsampling = SkYUVAInfo::Subsampling::k440;
755 } else if (4 == hSampY && 1 == vSampY) {
756 tempSubsampling = SkYUVAInfo::Subsampling::k411;
757 } else if (4 == hSampY && 2 == vSampY) {
758 tempSubsampling = SkYUVAInfo::Subsampling::k410;
759 } else {
760 return false;
761 }
762 if (supportedDataTypes &&
763 !supportedDataTypes->supported(SkYUVAInfo::PlaneConfig::kY_U_V,
765 return false;
766 }
767 if (yuvaPixmapInfo) {
769 size_t rowBytes[SkYUVAPixmapInfo::kMaxPlanes];
770 for (int i = 0; i < 3; ++i) {
771 colorTypes[i] = kAlpha_8_SkColorType;
772 rowBytes[i] = dinfo->comp_info[i].width_in_blocks * DCTSIZE;
773 }
774 SkYUVAInfo yuvaInfo(codec.dimensions(),
776 tempSubsampling,
778 codec.getOrigin(),
781 *yuvaPixmapInfo = SkYUVAPixmapInfo(yuvaInfo, colorTypes, rowBytes);
782 }
783 return true;
784}
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkColorType
Definition: SkColorType.h:19
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
Definition: SkColorType.h:21
@ kJPEG_Full_SkYUVColorSpace
describes full range
Definition: SkImageInfo.h:69
SkISize dimensions() const
Definition: SkCodec.h:230
SkEncodedOrigin getOrigin() const
Definition: SkCodec.h:246
@ kY_U_V
Plane 0: Y, Plane 1: U, Plane 2: V.
@ k440
1 set of UV values for each 1x2 block of Y values.
@ k420
1 set of UV values for each 2x2 block of Y values.
@ k410
1 set of UV values for each 4x2 block of Y values.
@ k411
1 set of UV values for each 4x1 block of Y values.
@ k422
1 set of UV values for each 2x1 block of Y values.
@ k444
No subsampling. UV values for each Y.
constexpr bool supported(PlaneConfig, DataType) const
@ kUnorm8
8 bit unsigned normalized
static constexpr auto kMaxPlanes
Definition: SkYUVAPixmaps.h:32

◆ needs_swizzler_to_convert_from_cmyk()

static bool needs_swizzler_to_convert_from_cmyk ( J_COLOR_SPACE  jpegColorType,
const skcms_ICCProfile srcProfile,
bool  hasColorSpaceXform 
)
inlinestatic

Definition at line 458 of file SkJpegCodec.cpp.

460 {
461 if (JCS_CMYK != jpegColorType) {
462 return false;
463 }
464
465 bool hasCMYKColorSpace = srcProfile && srcProfile->data_color_space == skcms_Signature_CMYK;
466 return !hasCMYKColorSpace || !hasColorSpaceXform;
467}
@ skcms_Signature_CMYK
Definition: skcms_public.h:264
uint32_t data_color_space
Definition: skcms_public.h:177