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

Unified Diff: src/utils/SkRGBAToYUV.cpp

Issue 1513393002: Add ability to extract YUV planes from SkImage (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: gm cleanup 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
« no previous file with comments | « src/utils/SkRGBAToYUV.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkRGBAToYUV.cpp
diff --git a/src/utils/SkRGBAToYUV.cpp b/src/utils/SkRGBAToYUV.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..b7f78bac14c08cc8110b0ca2935156d77b7ca2a1
--- /dev/null
+++ b/src/utils/SkRGBAToYUV.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkRGBAToYUV.h"
+#include "SkCanvas.h"
+#include "SkColorMatrixFilterRowMajor255.h"
+#include "SkImage.h"
+#include "SkPaint.h"
+#include "SkSurface.h"
+
+bool SkRGBAToYUV(const SkImage* image, const SkISize sizes[3], void* const planes[3],
+ const size_t rowBytes[3], SkYUVColorSpace colorSpace) {
+ // Matrices that go from RGBA to YUV.
+ static const SkScalar kYUVColorSpaceInvMatrices[][15] = {
+ // kJPEG_SkYUVColorSpace
+ { 0.299001f, 0.586998f, 0.114001f, 0.f, 0.0000821798f * 255.f,
+ -0.168736f, -0.331263f, 0.499999f, 0.f, 0.499954f * 255.f,
+ 0.499999f, -0.418686f, -0.0813131f, 0.f, 0.499941f * 255.f},
+
+ // kRec601_SkYUVColorSpace
+ { 0.256951f, 0.504421f, 0.0977346f, 0.f, 0.0625f * 255.f,
+ -0.148212f, -0.290954f, 0.439166f, 0.f, 0.5f * 255.f,
+ 0.439166f, -0.367886f, -0.0712802f, 0.f, 0.5f * 255.f},
+
+ // kRec709_SkYUVColorSpace
+ { 0.182663f, 0.614473f, 0.061971f, 0.f, 0.0625f * 255.f,
+ -0.100672f, -0.338658f, 0.43933f, 0.f, 0.5f * 255.f,
+ 0.439142f, -0.39891f, -0.040231f, 0.f, 0.5f * 255.f},
+ };
+ static_assert(kLastEnum_SkYUVColorSpace == 2, "yuv color matrix array problem");
+ static_assert(kJPEG_SkYUVColorSpace == 0, "yuv color matrix array problem");
+ static_assert(kRec601_SkYUVColorSpace == 1, "yuv color matrix array problem");
+ static_assert(kRec709_SkYUVColorSpace == 2, "yuv color matrix array problem");
+
+ for (int i = 0; i < 3; ++i) {
+ size_t rb = rowBytes[i] ? rowBytes[i] : sizes[i].fWidth;
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterDirect(
+ SkImageInfo::MakeA8(sizes[i].fWidth, sizes[i].fHeight), planes[i], rb));
+ if (!surface) {
+ return false;
+ }
+ SkPaint paint;
+ paint.setFilterQuality(kLow_SkFilterQuality);
+ paint.setXfermodeMode(SkXfermode::kSrc_Mode);
+ int rowStartIdx = 5 * i;
+ const SkScalar* row = kYUVColorSpaceInvMatrices[colorSpace] + rowStartIdx;
+ paint.setColorFilter(
+ SkColorMatrixFilterRowMajor255::CreateSingleChannelOutput(row))->unref();
+ surface->getCanvas()->drawImageRect(image, SkIRect::MakeWH(image->width(), image->height()),
+ SkRect::MakeIWH(surface->width(), surface->height()),
+ &paint);
+ }
+ return true;
+}
« no previous file with comments | « src/utils/SkRGBAToYUV.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698