aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2018-07-12 11:38:10 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-07-12 19:19:28 +0000
commit9e229233a67b36a508d3c753a5b93a022369c5f7 (patch)
tree25f86e467bc48d5dff3276427f3f1772e8f89352 /src
parentd46f0091afdc2563ec50319c4f93d110e0868fb9 (diff)
update SkColor4f::FromColor() to preserve transfer function
This kills off some sRGB tables, and lots of call sites can now use SkColor4f::FromColor(). It doesn't seem important to keep this test. Change-Id: Ia79ec8ace45e80bbc7a1e33f560f59289e61b2fb Reviewed-on: https://skia-review.googlesource.com/141046 Commit-Queue: Mike Klein <mtklein@chromium.org> Reviewed-by: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/SkBlitter_Sprite.cpp2
-rw-r--r--src/core/SkColor.cpp2
-rw-r--r--src/core/SkDraw_vertices.cpp4
-rw-r--r--src/core/SkPM4fPriv.h15
-rw-r--r--src/core/SkSRGB.cpp67
-rw-r--r--src/core/SkSRGB.h2
-rw-r--r--src/shaders/SkImageShader.cpp4
7 files changed, 8 insertions, 88 deletions
diff --git a/src/core/SkBlitter_Sprite.cpp b/src/core/SkBlitter_Sprite.cpp
index b26b712d93..5cd96fa8cf 100644
--- a/src/core/SkBlitter_Sprite.cpp
+++ b/src/core/SkBlitter_Sprite.cpp
@@ -112,7 +112,7 @@ public:
fTop = top;
// Just like in SkImageShader, we'll keep the paint color as floats in sRGB.
- swizzle_rb(Sk4f_fromL32(paint.getColor())).store(fPaintColor.vec());
+ fPaintColor = SkColor4f::FromColor(paint.getColor());
SkRasterPipeline p(fAlloc);
void* ctx = &fSrcPtr;
diff --git a/src/core/SkColor.cpp b/src/core/SkColor.cpp
index 6c9f0093d0..9c02378f59 100644
--- a/src/core/SkColor.cpp
+++ b/src/core/SkColor.cpp
@@ -153,7 +153,7 @@ void SkPM4f::assertIsUnit() const {
SkColor4f SkColor4f::FromColor(SkColor bgra) {
SkColor4f rgba;
- swizzle_rb(Sk4f_fromS32(bgra)).store(rgba.vec());
+ swizzle_rb(Sk4f_fromL32(bgra)).store(rgba.vec());
return rgba;
}
diff --git a/src/core/SkDraw_vertices.cpp b/src/core/SkDraw_vertices.cpp
index 4d1ccea496..f9d48a79da 100644
--- a/src/core/SkDraw_vertices.cpp
+++ b/src/core/SkDraw_vertices.cpp
@@ -141,9 +141,7 @@ static SkPM4f* convert_colors(const SkColor src[], int count, SkColorSpace* devi
SkPM4f* dst = alloc->makeArray<SkPM4f>(count);
if (!deviceCS) {
for (int i = 0; i < count; ++i) {
- SkColor4f color4f;
- swizzle_rb(Sk4f_fromL32(src[i])).store(&color4f);
- dst[i] = color4f.premul();
+ dst[i] = SkColor4f::FromColor(src[i]).premul();
}
} else {
auto srcCS = SkColorSpace::MakeSRGB();
diff --git a/src/core/SkPM4fPriv.h b/src/core/SkPM4fPriv.h
index f5e9aa02e6..4a288feb98 100644
--- a/src/core/SkPM4fPriv.h
+++ b/src/core/SkPM4fPriv.h
@@ -53,25 +53,16 @@ static inline SkPM4f premul_in_dst_colorspace(SkColor4f color4f,
return {{color4f.fR, color4f.fG, color4f.fB, color4f.fA}};
}
-static inline SkPM4f premul_in_dst_colorspace(SkColor c, SkColorSpace* dstCS) {
- SkColor4f color4f;
- swizzle_rb(Sk4f_fromL32(c)).store(color4f.vec());
-
+static inline SkPM4f premul_in_dst_colorspace(SkColor color, SkColorSpace* dstCS) {
// SkColors are always sRGB.
- return premul_in_dst_colorspace(color4f, SkColorSpace::MakeSRGB().get(), dstCS);
+ return premul_in_dst_colorspace(SkColor4f::FromColor(color),
+ SkColorSpace::MakeSRGB().get(), dstCS);
}
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Functions below this line are probably totally broken as far as color space management goes.
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-static inline Sk4f Sk4f_fromS32(uint32_t px) {
- return { sk_linear_from_srgb[(px >> 0) & 0xff],
- sk_linear_from_srgb[(px >> 8) & 0xff],
- sk_linear_from_srgb[(px >> 16) & 0xff],
- (1/255.0f) * (px >> 24) };
-}
-
static inline uint32_t Sk4f_toS32(const Sk4f& px) {
Sk4i rgb = sk_linear_to_srgb(px),
srgb = { rgb[0], rgb[1], rgb[2], (int)(255.0f * px[3] + 0.5f) };
diff --git a/src/core/SkSRGB.cpp b/src/core/SkSRGB.cpp
index 327c7d809d..f32f854d6f 100644
--- a/src/core/SkSRGB.cpp
+++ b/src/core/SkSRGB.cpp
@@ -7,73 +7,6 @@
#include "SkSRGB.h"
-const float sk_linear_from_srgb[256] = {
- 0.000000000000000000f, 0.000303526983548838f, 0.000607053967097675f, 0.000910580950646513f,
- 0.001214107934195350f, 0.001517634917744190f, 0.001821161901293030f, 0.002124688884841860f,
- 0.002428215868390700f, 0.002731742851939540f, 0.003034518678424960f, 0.003346535763899160f,
- 0.003676507324047440f, 0.004024717018496310f, 0.004391442037410290f, 0.004776953480693730f,
- 0.005181516702338390f, 0.005605391624202720f, 0.006048833022857060f, 0.006512090792594470f,
- 0.006995410187265390f, 0.007499032043226180f, 0.008023192985384990f, 0.008568125618069310f,
- 0.009134058702220790f, 0.009721217320237850f, 0.010329823029626900f, 0.010960094006488200f,
- 0.011612245179743900f, 0.012286488356915900f, 0.012983032342173000f, 0.013702083047289700f,
- 0.014443843596092500f, 0.015208514422912700f, 0.015996293365509600f, 0.016807375752887400f,
- 0.017641954488384100f, 0.018500220128379700f, 0.019382360956935700f, 0.020288563056652400f,
- 0.021219010376003600f, 0.022173884793387400f, 0.023153366178110400f, 0.024157632448504800f,
- 0.025186859627361600f, 0.026241221894849900f, 0.027320891639074900f, 0.028426039504420800f,
- 0.029556834437808800f, 0.030713443732993600f, 0.031896033073011500f, 0.033104766570885100f,
- 0.034339806808682200f, 0.035601314875020300f, 0.036889450401100000f, 0.038204371595346500f,
- 0.039546235276732800f, 0.040915196906853200f, 0.042311410620809700f, 0.043735029256973500f,
- 0.045186204385675500f, 0.046665086336880100f, 0.048171824226889400f, 0.049706565984127200f,
- 0.051269458374043200f, 0.052860647023180200f, 0.054480276442442400f, 0.056128490049600100f,
- 0.057805430191067200f, 0.059511238162981200f, 0.061246054231617600f, 0.063010017653167700f,
- 0.064803266692905800f, 0.066625938643772900f, 0.068478169844400200f, 0.070360095696595900f,
- 0.072271850682317500f, 0.074213568380149600f, 0.076185381481307900f, 0.078187421805186300f,
- 0.080219820314468300f, 0.082282707129814800f, 0.084376211544148800f, 0.086500462036549800f,
- 0.088655586285772900f, 0.090841711183407700f, 0.093058962846687500f, 0.095307466630964700f,
- 0.097587347141862500f, 0.099898728247113900f, 0.102241733088101000f, 0.104616484091104000f,
- 0.107023102978268000f, 0.109461710778299000f, 0.111932427836906000f, 0.114435373826974000f,
- 0.116970667758511000f, 0.119538427988346000f, 0.122138772229602000f, 0.124771817560950000f,
- 0.127437680435647000f, 0.130136476690364000f, 0.132868321553818000f, 0.135633329655206000f,
- 0.138431615032452000f, 0.141263291140272000f, 0.144128470858058000f, 0.147027266497595000f,
- 0.149959789810609000f, 0.152926151996150000f, 0.155926463707827000f, 0.158960835060880000f,
- 0.162029375639111000f, 0.165132194501668000f, 0.168269400189691000f, 0.171441100732823000f,
- 0.174647403655585000f, 0.177888415983629000f, 0.181164244249860000f, 0.184474994500441000f,
- 0.187820772300678000f, 0.191201682740791000f, 0.194617830441576000f, 0.198069319559949000f,
- 0.201556253794397000f, 0.205078736390317000f, 0.208636870145256000f, 0.212230757414055000f,
- 0.215860500113899000f, 0.219526199729269000f, 0.223227957316809000f, 0.226965873510098000f,
- 0.230740048524349000f, 0.234550582161005000f, 0.238397573812271000f, 0.242281122465555000f,
- 0.246201326707835000f, 0.250158284729953000f, 0.254152094330827000f, 0.258182852921596000f,
- 0.262250657529696000f, 0.266355604802862000f, 0.270497791013066000f, 0.274677312060385000f,
- 0.278894263476810000f, 0.283148740429992000f, 0.287440837726918000f, 0.291770649817536000f,
- 0.296138270798321000f, 0.300543794415777000f, 0.304987314069886000f, 0.309468922817509000f,
- 0.313988713375718000f, 0.318546778125092000f, 0.323143209112951000f, 0.327778098056542000f,
- 0.332451536346179000f, 0.337163615048330000f, 0.341914424908661000f, 0.346704056355030000f,
- 0.351532599500439000f, 0.356400144145944000f, 0.361306779783510000f, 0.366252595598840000f,
- 0.371237680474149000f, 0.376262122990906000f, 0.381326011432530000f, 0.386429433787049000f,
- 0.391572477749723000f, 0.396755230725627000f, 0.401977779832196000f, 0.407240211901737000f,
- 0.412542613483904000f, 0.417885070848138000f, 0.423267669986072000f, 0.428690496613907000f,
- 0.434153636174749000f, 0.439657173840919000f, 0.445201194516228000f, 0.450785782838223000f,
- 0.456411023180405000f, 0.462076999654407000f, 0.467783796112159000f, 0.473531496148010000f,
- 0.479320183100827000f, 0.485149940056070000f, 0.491020849847836000f, 0.496932995060870000f,
- 0.502886458032569000f, 0.508881320854934000f, 0.514917665376521000f, 0.520995573204354000f,
- 0.527115125705813000f, 0.533276404010505000f, 0.539479489012107000f, 0.545724461370187000f,
- 0.552011401512000000f, 0.558340389634268000f, 0.564711505704929000f, 0.571124829464873000f,
- 0.577580440429651000f, 0.584078417891164000f, 0.590618840919337000f, 0.597201788363763000f,
- 0.603827338855338000f, 0.610495570807865000f, 0.617206562419651000f, 0.623960391675076000f,
- 0.630757136346147000f, 0.637596873994033000f, 0.644479681970582000f, 0.651405637419824000f,
- 0.658374817279448000f, 0.665387298282272000f, 0.672443156957688000f, 0.679542469633094000f,
- 0.686685312435314000f, 0.693871761291990000f, 0.701101891932973000f, 0.708375779891687000f,
- 0.715693500506481000f, 0.723055128921969000f, 0.730460740090354000f, 0.737910408772731000f,
- 0.745404209540387000f, 0.752942216776078000f, 0.760524504675292000f, 0.768151147247507000f,
- 0.775822218317423000f, 0.783537791526194000f, 0.791297940332630000f, 0.799102738014409000f,
- 0.806952257669252000f, 0.814846572216101000f, 0.822785754396284000f, 0.830769876774655000f,
- 0.838799011740740000f, 0.846873231509858000f, 0.854992608124234000f, 0.863157213454102000f,
- 0.871367119198797000f, 0.879622396887832000f, 0.887923117881966000f, 0.896269353374266000f,
- 0.904661174391149000f, 0.913098651793419000f, 0.921581856277295000f, 0.930110858375424000f,
- 0.938685728457888000f, 0.947306536733200000f, 0.955973353249286000f, 0.964686247894465000f,
- 0.973445290398413000f, 0.982250550333117000f, 0.991102097113830000f, 1.000000000000000000f,
-};
-
/*
* Converts sRGB encoded bytes to a 12-bit linear representation.
*/
diff --git a/src/core/SkSRGB.h b/src/core/SkSRGB.h
index de078a5528..e0052b99ea 100644
--- a/src/core/SkSRGB.h
+++ b/src/core/SkSRGB.h
@@ -13,14 +13,12 @@
/** Components for building our canonical sRGB -> linear and linear -> sRGB transformations.
*
* Current best practices:
- * - for sRGB -> linear, lookup R,G,B in sk_linear_from_srgb;
* - for linear -> sRGB, call sk_linear_to_srgb() for R,G,B;
* - the alpha channel is linear in both formats, needing at most *(1/255.0f) or *255.0f.
*
* sk_linear_to_srgb() will run a little faster than usual when compiled with SSE4.1+.
*/
-extern const float sk_linear_from_srgb[256];
extern const uint16_t sk_linear12_from_srgb[256];
extern const uint8_t sk_linear12_to_srgb[4096];
diff --git a/src/shaders/SkImageShader.cpp b/src/shaders/SkImageShader.cpp
index 22c3f95c04..b770d64c5f 100644
--- a/src/shaders/SkImageShader.cpp
+++ b/src/shaders/SkImageShader.cpp
@@ -315,8 +315,8 @@ bool SkImageShader::onAppendStages(const StageRec& rec) const {
SkColor4f paint_color;
};
auto misc = alloc->make<MiscCtx>();
- misc->state = std::move(state); // Extend lifetime to match the pipeline's.
- swizzle_rb(Sk4f_fromL32(rec.fPaint.getColor())).store(misc->paint_color.vec()); // sRGBA floats
+ misc->state = std::move(state); // Extend lifetime to match the pipeline's.
+ misc->paint_color = SkColor4f::FromColor(rec.fPaint.getColor());
p->append_matrix(alloc, matrix);
auto gather = alloc->make<SkJumper_GatherCtx>();