Home | History | Annotate | Download | only in opts
      1 /*
      2  * Copyright 2015 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #ifndef SkBlitRow_opts_DEFINED
      9 #define SkBlitRow_opts_DEFINED
     10 
     11 #include "Sk4px.h"
     12 
     13 namespace SK_OPTS_NS {
     14 
     15 // Color32 uses the blend_256_round_alt algorithm from tests/BlendTest.cpp.
     16 // It's not quite perfect, but it's never wrong in the interesting edge cases,
     17 // and it's quite a bit faster than blend_perfect.
     18 //
     19 // blend_256_round_alt is our currently blessed algorithm.  Please use it or an analogous one.
     20 static void blit_row_color32(SkPMColor* dst, const SkPMColor* src, int count, SkPMColor color) {
     21     unsigned invA = 255 - SkGetPackedA32(color);
     22     invA += invA >> 7;
     23     SkASSERT(invA < 256);  // We've should have already handled alpha == 0 externally.
     24 
     25     Sk16h colorHighAndRound = Sk4px::DupPMColor(color).widenHi() + Sk16h(128);
     26     Sk16b invA_16x(invA);
     27 
     28     Sk4px::MapSrc(count, dst, src, [&](const Sk4px& src4) -> Sk4px {
     29         return (src4 * invA_16x).addNarrowHi(colorHighAndRound);
     30     });
     31 }
     32 
     33 }  // SK_OPTS_NS
     34 
     35 #endif//SkBlitRow_opts_DEFINED
     36