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

Unified Diff: src/opts/SkColorXform_opts.h

Issue 2081933005: Do loads and math in parallel in SkColorXform_opts (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Don't close over rgba Created 4 years, 6 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/opts/SkColorXform_opts.h
diff --git a/src/opts/SkColorXform_opts.h b/src/opts/SkColorXform_opts.h
index 2c14c802831e51950b799054ee73e67b5021a3a0..52e37e599e3ed4dcb86ef7cd38c3205cd0e2b4f7 100644
--- a/src/opts/SkColorXform_opts.h
+++ b/src/opts/SkColorXform_opts.h
@@ -186,51 +186,64 @@ static Sk4f clamp_0_to_255(const Sk4f& x) {
template <const float (&linear_from_curve)[256], Sk4f (*linear_to_curve)(const Sk4f&)>
static void color_xform_RGB1(uint32_t* dst, const uint32_t* src, int len,
const float matrix[16]) {
- // Load transformation matrix.
- auto rXgXbX = Sk4f::Load(matrix + 0),
+ Sk4f rXgXbX = Sk4f::Load(matrix + 0),
rYgYbY = Sk4f::Load(matrix + 4),
rZgZbZ = Sk4f::Load(matrix + 8);
- while (len >= 4) {
- // Convert to linear. The look-up table has perfect accuracy.
- auto reds = Sk4f{linear_from_curve[(src[0] >> 0) & 0xFF],
- linear_from_curve[(src[1] >> 0) & 0xFF],
- linear_from_curve[(src[2] >> 0) & 0xFF],
- linear_from_curve[(src[3] >> 0) & 0xFF]};
- auto greens = Sk4f{linear_from_curve[(src[0] >> 8) & 0xFF],
- linear_from_curve[(src[1] >> 8) & 0xFF],
- linear_from_curve[(src[2] >> 8) & 0xFF],
- linear_from_curve[(src[3] >> 8) & 0xFF]};
- auto blues = Sk4f{linear_from_curve[(src[0] >> 16) & 0xFF],
- linear_from_curve[(src[1] >> 16) & 0xFF],
- linear_from_curve[(src[2] >> 16) & 0xFF],
- linear_from_curve[(src[3] >> 16) & 0xFF]};
-
- // Apply the transformation matrix to dst gamut.
- auto dstReds = rXgXbX[0]*reds + rYgYbY[0]*greens + rZgZbZ[0]*blues,
- dstGreens = rXgXbX[1]*reds + rYgYbY[1]*greens + rZgZbZ[1]*blues,
- dstBlues = rXgXbX[2]*reds + rYgYbY[2]*greens + rZgZbZ[2]*blues;
+ if (len >= 4) {
+ Sk4f reds, greens, blues;
+ auto load_next_4 = [&reds, &greens, &blues, &src, &len] {
+ reds = Sk4f{linear_from_curve[(src[0] >> 0) & 0xFF],
+ linear_from_curve[(src[1] >> 0) & 0xFF],
+ linear_from_curve[(src[2] >> 0) & 0xFF],
+ linear_from_curve[(src[3] >> 0) & 0xFF]};
+ greens = Sk4f{linear_from_curve[(src[0] >> 8) & 0xFF],
+ linear_from_curve[(src[1] >> 8) & 0xFF],
+ linear_from_curve[(src[2] >> 8) & 0xFF],
+ linear_from_curve[(src[3] >> 8) & 0xFF]};
+ blues = Sk4f{linear_from_curve[(src[0] >> 16) & 0xFF],
+ linear_from_curve[(src[1] >> 16) & 0xFF],
+ linear_from_curve[(src[2] >> 16) & 0xFF],
+ linear_from_curve[(src[3] >> 16) & 0xFF]};
+ src += 4;
+ len -= 4;
+ };
- // Convert to dst gamma.
- dstReds = linear_to_curve(dstReds);
- dstGreens = linear_to_curve(dstGreens);
- dstBlues = linear_to_curve(dstBlues);
+ Sk4f dstReds, dstGreens, dstBlues;
+ auto transform_4 = [&reds, &greens, &blues, &dstReds, &dstGreens, &dstBlues, &rXgXbX,
+ &rYgYbY, &rZgZbZ] {
+ dstReds = rXgXbX[0]*reds + rYgYbY[0]*greens + rZgZbZ[0]*blues;
+ dstGreens = rXgXbX[1]*reds + rYgYbY[1]*greens + rZgZbZ[1]*blues;
+ dstBlues = rXgXbX[2]*reds + rYgYbY[2]*greens + rZgZbZ[2]*blues;
+ };
- // Clamp floats to byte range.
- dstReds = clamp_0_to_255(dstReds);
- dstGreens = clamp_0_to_255(dstGreens);
- dstBlues = clamp_0_to_255(dstBlues);
+ auto store_4 = [&dstReds, &dstGreens, &dstBlues, &dst] {
+ dstReds = linear_to_curve(dstReds);
+ dstGreens = linear_to_curve(dstGreens);
+ dstBlues = linear_to_curve(dstBlues);
- // Convert to bytes and store to memory.
- auto rgba = (Sk4i{(int)0xFF000000} )
- | (SkNx_cast<int>(dstReds) )
- | (SkNx_cast<int>(dstGreens) << 8)
- | (SkNx_cast<int>(dstBlues) << 16);
- rgba.store(dst);
-
- dst += 4;
- src += 4;
- len -= 4;
+ dstReds = clamp_0_to_255(dstReds);
+ dstGreens = clamp_0_to_255(dstGreens);
+ dstBlues = clamp_0_to_255(dstBlues);
+
+ auto rgba = (Sk4i{(int)0xFF000000} )
+ | (SkNx_cast<int>(dstReds) )
+ | (SkNx_cast<int>(dstGreens) << 8)
+ | (SkNx_cast<int>(dstBlues) << 16);
+ rgba.store(dst);
+ dst += 4;
+ };
+
+ load_next_4();
+
+ while (len >= 4) {
+ transform_4();
+ load_next_4();
+ store_4();
+ }
+
+ transform_4();
+ store_4();
}
while (len > 0) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698