aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/codec
diff options
context:
space:
mode:
authorGravatar msarett <msarett@google.com>2016-03-07 09:16:52 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-07 09:16:52 -0800
commit1590f3b32890f6455b30494308633177b54db347 (patch)
tree5fabc87ced4a0c49bc304d87306068647e8123c2 /src/codec
parent54887a6a2e12b0f2c93e039b00678732b6518826 (diff)
Revert of Update Skia's YUV API (patchset #5 id:160001 of https://codereview.chromium.org/1716523002/ )
Reason for revert: Blimp failures with manual roll in Chrome. Original issue's description: > Update Skia's YUV API > > We should match the recently designed API in SkCodec. > https://codereview.chromium.org/1549473003/ > > This requires changes in Chromium as well. > > BUG=skia: > GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1716523002 > > Committed: https://skia.googlesource.com/skia/+/095d31c8a0eeb5d491febf064bc3c8a44e22b94f TBR=scroggo@google.com,reed@google.com,bsalomon@google.com # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review URL: https://codereview.chromium.org/1775493002
Diffstat (limited to 'src/codec')
-rw-r--r--src/codec/SkCodecImageGenerator.cpp47
-rw-r--r--src/codec/SkCodecImageGenerator.h11
-rw-r--r--src/codec/SkJpegCodec.cpp60
-rw-r--r--src/codec/SkJpegCodec.h4
4 files changed, 80 insertions, 42 deletions
diff --git a/src/codec/SkCodecImageGenerator.cpp b/src/codec/SkCodecImageGenerator.cpp
index e579da92f6..e6e164ef61 100644
--- a/src/codec/SkCodecImageGenerator.cpp
+++ b/src/codec/SkCodecImageGenerator.cpp
@@ -28,6 +28,9 @@ SkCodecImageGenerator::SkCodecImageGenerator(SkCodec* codec, SkData* data)
: INHERITED(make_premul(codec->getInfo()))
, fCodec(codec)
, fData(SkRef(data))
+ , fYWidth(0)
+ , fUWidth(0)
+ , fVWidth(0)
{}
SkData* SkCodecImageGenerator::onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) {
@@ -48,13 +51,47 @@ bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, s
}
}
-bool SkCodecImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const
-{
- return fCodec->queryYUV8(sizeInfo, colorSpace);
-}
+bool SkCodecImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
+ SkYUVColorSpace* colorSpace) {
+ // TODO (msarett): Change the YUV API in ImageGenerator to match SkCodec.
+ // This function is currently a hack to match the implementation
+ // in SkCodec with the old API.
+ SkCodec::YUVSizeInfo sizeInfo;
+
+ // If planes is NULL, we just need to return the size.
+ if (nullptr == planes) {
+ bool result = fCodec->queryYUV8(&sizeInfo, colorSpace);
+ if (result) {
+ // Save the true widths
+ fYWidth = sizeInfo.fYSize.width();
+ fUWidth = sizeInfo.fUSize.width();
+ fVWidth = sizeInfo.fVSize.width();
+
+ // Set the sizes so that the client allocates enough memory
+ sizes[0].fWidth = (int) sizeInfo.fYWidthBytes;
+ sizes[0].fHeight = sizeInfo.fYSize.height();
+ sizes[1].fWidth = (int) sizeInfo.fUWidthBytes;
+ sizes[1].fHeight = sizeInfo.fUSize.height();
+ sizes[2].fWidth = (int) sizeInfo.fVWidthBytes;
+ sizes[2].fHeight = sizeInfo.fVSize.height();
+ }
+ return result;
+ }
+
+ // Set the sizeInfo with the true widths and heights
+ SkASSERT(fYWidth != 0 && fUWidth != 0 && fVWidth != 0);
+ sizeInfo.fYSize.set(fYWidth, sizes[0].height());
+ sizeInfo.fUSize.set(fUWidth, sizes[1].height());
+ sizeInfo.fVSize.set(fVWidth, sizes[2].height());
-bool SkCodecImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) {
+ // Set the sizeInfo with the allocated widths
+ sizeInfo.fYWidthBytes = sizes[0].width();
+ sizeInfo.fUWidthBytes = sizes[1].width();
+ sizeInfo.fVWidthBytes = sizes[2].width();
SkCodec::Result result = fCodec->getYUV8Planes(sizeInfo, planes);
+ if ((result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput) && colorSpace) {
+ *colorSpace = kJPEG_SkYUVColorSpace;
+ }
switch (result) {
case SkCodec::kSuccess:
diff --git a/src/codec/SkCodecImageGenerator.h b/src/codec/SkCodecImageGenerator.h
index 6d34223110..d2c74ab482 100644
--- a/src/codec/SkCodecImageGenerator.h
+++ b/src/codec/SkCodecImageGenerator.h
@@ -26,9 +26,8 @@ protected:
bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[],
int* ctableCount) override;
- bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const override;
-
- bool onGetYUV8Planes(const SkYUVSizeInfo&, void* planes[3]) override;
+ bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
+ SkYUVColorSpace* colorSpace) override;
private:
/*
@@ -40,5 +39,11 @@ private:
SkAutoTDelete<SkCodec> fCodec;
SkAutoTUnref<SkData> fData;
+ // FIXME: These fields are necessary only until we change the API of SkImageGenerator
+ // to match SkCodec. Once the API is changed, they should be removed.
+ int fYWidth;
+ int fUWidth;
+ int fVWidth;
+
typedef SkImageGenerator INHERITED;
};
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp
index f1b55df06e..b5780c5581 100644
--- a/src/codec/SkJpegCodec.cpp
+++ b/src/codec/SkJpegCodec.cpp
@@ -594,21 +594,21 @@ static bool is_yuv_supported(jpeg_decompress_struct* dinfo) {
(4 == hSampY && 2 == vSampY);
}
-bool SkJpegCodec::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const {
+bool SkJpegCodec::onQueryYUV8(YUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const {
jpeg_decompress_struct* dinfo = fDecoderMgr->dinfo();
if (!is_yuv_supported(dinfo)) {
return false;
}
- sizeInfo->fSizes[SkYUVSizeInfo::kY].set(dinfo->comp_info[0].downsampled_width,
- dinfo->comp_info[0].downsampled_height);
- sizeInfo->fSizes[SkYUVSizeInfo::kU].set(dinfo->comp_info[1].downsampled_width,
- dinfo->comp_info[1].downsampled_height);
- sizeInfo->fSizes[SkYUVSizeInfo::kV].set(dinfo->comp_info[2].downsampled_width,
- dinfo->comp_info[2].downsampled_height);
- sizeInfo->fWidthBytes[SkYUVSizeInfo::kY] = dinfo->comp_info[0].width_in_blocks * DCTSIZE;
- sizeInfo->fWidthBytes[SkYUVSizeInfo::kU] = dinfo->comp_info[1].width_in_blocks * DCTSIZE;
- sizeInfo->fWidthBytes[SkYUVSizeInfo::kV] = dinfo->comp_info[2].width_in_blocks * DCTSIZE;
+ sizeInfo->fYSize.set(dinfo->comp_info[0].downsampled_width,
+ dinfo->comp_info[0].downsampled_height);
+ sizeInfo->fUSize.set(dinfo->comp_info[1].downsampled_width,
+ dinfo->comp_info[1].downsampled_height);
+ sizeInfo->fVSize.set(dinfo->comp_info[2].downsampled_width,
+ dinfo->comp_info[2].downsampled_height);
+ sizeInfo->fYWidthBytes = dinfo->comp_info[0].width_in_blocks * DCTSIZE;
+ sizeInfo->fUWidthBytes = dinfo->comp_info[1].width_in_blocks * DCTSIZE;
+ sizeInfo->fVWidthBytes = dinfo->comp_info[2].width_in_blocks * DCTSIZE;
if (colorSpace) {
*colorSpace = kJPEG_SkYUVColorSpace;
@@ -617,18 +617,17 @@ bool SkJpegCodec::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpa
return true;
}
-SkCodec::Result SkJpegCodec::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) {
- SkYUVSizeInfo defaultInfo;
+SkCodec::Result SkJpegCodec::onGetYUV8Planes(const YUVSizeInfo& sizeInfo, void* pixels[3]) {
+ YUVSizeInfo defaultInfo;
// This will check is_yuv_supported(), so we don't need to here.
bool supportsYUV = this->onQueryYUV8(&defaultInfo, nullptr);
- if (!supportsYUV ||
- sizeInfo.fSizes[SkYUVSizeInfo::kY] != defaultInfo.fSizes[SkYUVSizeInfo::kY] ||
- sizeInfo.fSizes[SkYUVSizeInfo::kU] != defaultInfo.fSizes[SkYUVSizeInfo::kU] ||
- sizeInfo.fSizes[SkYUVSizeInfo::kV] != defaultInfo.fSizes[SkYUVSizeInfo::kV] ||
- sizeInfo.fWidthBytes[SkYUVSizeInfo::kY] < defaultInfo.fWidthBytes[SkYUVSizeInfo::kY] ||
- sizeInfo.fWidthBytes[SkYUVSizeInfo::kU] < defaultInfo.fWidthBytes[SkYUVSizeInfo::kU] ||
- sizeInfo.fWidthBytes[SkYUVSizeInfo::kV] < defaultInfo.fWidthBytes[SkYUVSizeInfo::kV]) {
+ if (!supportsYUV || sizeInfo.fYSize != defaultInfo.fYSize ||
+ sizeInfo.fUSize != defaultInfo.fUSize ||
+ sizeInfo.fVSize != defaultInfo.fVSize ||
+ sizeInfo.fYWidthBytes < defaultInfo.fYWidthBytes ||
+ sizeInfo.fUWidthBytes < defaultInfo.fUWidthBytes ||
+ sizeInfo.fVWidthBytes < defaultInfo.fVWidthBytes) {
return fDecoderMgr->returnFailure("onGetYUV8Planes", kInvalidInput);
}
@@ -652,9 +651,9 @@ SkCodec::Result SkJpegCodec::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void
// Currently, we require that the Y plane dimensions match the image dimensions
// and that the U and V planes are the same dimensions.
- SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kU] == sizeInfo.fSizes[SkYUVSizeInfo::kV]);
- SkASSERT((uint32_t) sizeInfo.fSizes[SkYUVSizeInfo::kY].width() == dinfo->output_width &&
- (uint32_t) sizeInfo.fSizes[SkYUVSizeInfo::kY].height() == dinfo->output_height);
+ SkASSERT(sizeInfo.fUSize == sizeInfo.fVSize);
+ SkASSERT((uint32_t) sizeInfo.fYSize.width() == dinfo->output_width &&
+ (uint32_t) sizeInfo.fYSize.height() == dinfo->output_height);
// Build a JSAMPIMAGE to handle output from libjpeg-turbo. A JSAMPIMAGE has
// a 2-D array of pixels for each of the components (Y, U, V) in the image.
@@ -671,20 +670,17 @@ SkCodec::Result SkJpegCodec::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void
// Initialize rowptrs.
int numYRowsPerBlock = DCTSIZE * dinfo->comp_info[0].v_samp_factor;
for (int i = 0; i < numYRowsPerBlock; i++) {
- rowptrs[i] = SkTAddOffset<JSAMPLE>(planes[SkYUVSizeInfo::kY],
- i * sizeInfo.fWidthBytes[SkYUVSizeInfo::kY]);
+ rowptrs[i] = SkTAddOffset<JSAMPLE>(pixels[0], i * sizeInfo.fYWidthBytes);
}
for (int i = 0; i < DCTSIZE; i++) {
- rowptrs[i + 2 * DCTSIZE] = SkTAddOffset<JSAMPLE>(planes[SkYUVSizeInfo::kU],
- i * sizeInfo.fWidthBytes[SkYUVSizeInfo::kU]);
- rowptrs[i + 3 * DCTSIZE] = SkTAddOffset<JSAMPLE>(planes[SkYUVSizeInfo::kV],
- i * sizeInfo.fWidthBytes[SkYUVSizeInfo::kV]);
+ rowptrs[i + 2 * DCTSIZE] = SkTAddOffset<JSAMPLE>(pixels[1], i * sizeInfo.fUWidthBytes);
+ rowptrs[i + 3 * DCTSIZE] = SkTAddOffset<JSAMPLE>(pixels[2], i * sizeInfo.fVWidthBytes);
}
// After each loop iteration, we will increment pointers to Y, U, and V.
- size_t blockIncrementY = numYRowsPerBlock * sizeInfo.fWidthBytes[SkYUVSizeInfo::kY];
- size_t blockIncrementU = DCTSIZE * sizeInfo.fWidthBytes[SkYUVSizeInfo::kU];
- size_t blockIncrementV = DCTSIZE * sizeInfo.fWidthBytes[SkYUVSizeInfo::kV];
+ size_t blockIncrementY = numYRowsPerBlock * sizeInfo.fYWidthBytes;
+ size_t blockIncrementU = DCTSIZE * sizeInfo.fUWidthBytes;
+ size_t blockIncrementV = DCTSIZE * sizeInfo.fVWidthBytes;
uint32_t numRowsPerBlock = numYRowsPerBlock;
@@ -717,7 +713,7 @@ SkCodec::Result SkJpegCodec::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void
// this requirement using a dummy row buffer.
// FIXME: Should SkCodec have an extra memory buffer that can be shared among
// all of the implementations that use temporary/garbage memory?
- SkAutoTMalloc<JSAMPLE> dummyRow(sizeInfo.fWidthBytes[SkYUVSizeInfo::kY]);
+ SkAutoTMalloc<JSAMPLE> dummyRow(sizeInfo.fYWidthBytes);
for (int i = remainingRows; i < numYRowsPerBlock; i++) {
rowptrs[i] = dummyRow.get();
}
diff --git a/src/codec/SkJpegCodec.h b/src/codec/SkJpegCodec.h
index 049c3c956a..e3448e9dd1 100644
--- a/src/codec/SkJpegCodec.h
+++ b/src/codec/SkJpegCodec.h
@@ -46,9 +46,9 @@ protected:
Result onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, const Options&,
SkPMColor*, int*, int*) override;
- bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override;
+ bool onQueryYUV8(YUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override;
- Result onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) override;
+ Result onGetYUV8Planes(const YUVSizeInfo& sizeInfo, void* pixels[3]) override;
SkEncodedFormat onGetEncodedFormat() const override {
return kJPEG_SkEncodedFormat;