Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Unified Diff: include/codec/SkCodec.h

Issue 1549473003: Add getYUV8Planes() API to SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add a test to DM Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: include/codec/SkCodec.h
diff --git a/include/codec/SkCodec.h b/include/codec/SkCodec.h
index 597ebd039e8a806bc09cf4c6f7eb0d1b8746ded8..5a57fd54cdbde4eed5920867f6703e3977f965aa 100644
--- a/include/codec/SkCodec.h
+++ b/include/codec/SkCodec.h
@@ -277,6 +277,85 @@ public:
*/
Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes);
+ struct YUVPlanesSizes {
+ SkISize YSize;
+ SkISize USize;
+ SkISize VSize;
+ };
+
+ /**
+ * While the widths of the Y, U, and V planes are not restricted, the
+ * implementation requires that the width of the memory allocated for
+ * each plane be a multiple of DCTSIZE (which is always 8).
+ *
+ * This struct allows us to inform the client how many "widthBytes"
+ * that we need. Note that we use the new idea of "widthBytes" because
+ * this idea is distinct from "rowBytes" (used elsewhere in Skia).
+ * "rowBytes" allow the last row of the allocation to not include any
+ * extra padding, while, in this case, every single row of the allocation
+ * must be at least "widthBytes".
+ */
+ struct YUVPlanesWidthBytes {
+ size_t YWidthBytes;
+ size_t UWidthBytes;
+ size_t VWidthBytes;
+ };
+
+ /**
+ * If decoding to YUV is supported, this returns true. Otherwise, this
+ * returns false and does not modify any of the parameters.
+ *
+ * @param sizes Output parameter indicating the sizes of the Y, U,
+ * and V planes.
+ * @param widthBytes Output parameter indicating the required allocation
+ * width in bytes for each of the Y, U, and V planes.
+ * @param colorSpace Output parameter. If non-NULL this is set to kJPEG,
+ * otherwise this is ignored.
+ */
+ bool queryYUV8(YUVPlanesSizes* sizes, YUVPlanesWidthBytes* widthBytes,
+ SkYUVColorSpace* colorSpace) const {
+ if (nullptr == sizes || nullptr == widthBytes) {
+ return false;
+ }
+
+ return this->onQueryYUV8(sizes, widthBytes, colorSpace);
+ }
+
+ /**
+ * Returns kSuccess, or another value explaining the type of failure.
+ * This always attempts to perform a full decode. If the client only
+ * wants size, it should call queryYUV8().
+ *
+ * @param sizes Sizes of each of the Y, U, and V planes. The size
+ * of the Y plane will be the same size as the image.
+ * The size of the U and V planes may be the same size
+ * as the image, or they may be a fraction of the size
+ * of the image (due to sampling). It is quite common
+ * for the width to be sampled at a different rate than
+ * the height. 2 and 4 are common sampling rates. The
+ * U and V planes are often the same size.
+ * @param planes Memory for each of the Y, U, and V planes.
+ * @param widthBytes Width in bytes of each row of the Y, U, and V planes.
+ * Each Y, U, or V "sample" is a single byte. Also,
+ * the implementation requires that the width of the
+ * memory allocated be padded to a multiple of 8. So
+ * the widthBytes should at least equal the Y, U, and V
+ * widths rounded up to the nearest multiples of 8.
+ */
+ Result getYUV8Planes(const YUVPlanesSizes* sizes, void* planes[3],
+ const YUVPlanesWidthBytes* widthBytes) {
+ if (nullptr == sizes || nullptr == planes || nullptr == planes[0] ||
+ nullptr == planes[1] || nullptr == planes[2] || nullptr == widthBytes) {
+ return kInvalidInput;
+ }
+
+ if (!this->rewindIfNeeded()) {
+ return kCouldNotRewind;
+ }
+
+ return this->onGetYUV8Planes(sizes, planes, widthBytes);
+ }
+
/**
* The remaining functions revolve around decoding scanlines.
*/
@@ -442,7 +521,7 @@ public:
protected:
SkCodec(const SkImageInfo&, SkStream*);
- virtual SkISize onGetScaledDimensions(float /* desiredScale */) const {
+ virtual SkISize onGetScaledDimensions(float /*desiredScale*/) const {
// By default, scaling is not supported.
return this->getInfo().dimensions();
}
@@ -469,7 +548,16 @@ protected:
SkPMColor ctable[], int* ctableCount,
int* rowsDecoded) = 0;
- virtual bool onGetValidSubset(SkIRect* /* desiredSubset */) const {
+ virtual bool onQueryYUV8(YUVPlanesSizes*, YUVPlanesWidthBytes*, SkYUVColorSpace*) const {
+ return false;
+ }
+
+ virtual Result onGetYUV8Planes(const YUVPlanesSizes*, void*[3] /*planes*/,
+ const YUVPlanesWidthBytes*) {
+ return kUnimplemented;
+ }
+
+ virtual bool onGetValidSubset(SkIRect* /*desiredSubset*/) const {
// By default, subsets are not supported.
return false;
}

Powered by Google App Engine
This is Rietveld 408576698