当前位置: 首页>>代码示例>>C++>>正文


C++ Sk4f函数代码示例

本文整理汇总了C++中Sk4f函数的典型用法代码示例。如果您正苦于以下问题:C++ Sk4f函数的具体用法?C++ Sk4f怎么用?C++ Sk4f使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Sk4f函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Sk4f

bool SkPixmap::erase(const SkColor4f& origColor, const SkIRect* subset) const {
    SkPixmap pm;
    if (subset) {
        if (!this->extractSubset(&pm, *subset)) {
            return false;
        }
    } else {
        pm = *this;
    }

    const SkColor4f color = origColor.pin();

    if (kRGBA_F16_SkColorType != pm.colorType()) {
        Sk4f c4 = Sk4f::Load(color.vec());
        SkColor c;
        (c4 * Sk4f(255) + Sk4f(0.5f)).store(&c);
        return pm.erase(c);
    }

    const uint64_t half4 = color.premul().toF16();
    for (int y = 0; y < pm.height(); ++y) {
        sk_memset64(pm.writable_addr64(0, y), half4, pm.width());
    }
    return true;
}
开发者ID:fluxxion82,项目名称:skia,代码行数:25,代码来源:SkPixmap.cpp

示例2: set_argb

static Sk4f set_argb(float a, float r, float g, float b) {
    if (0 == SkPM4f::R) {
        return Sk4f(r, g, b, a);
    } else {
        return Sk4f(b, g, r, a);
    }
}
开发者ID:kekekeks,项目名称:skia,代码行数:7,代码来源:SkXfermode.cpp

示例3: srcover_1

template <DstType D> void srcover_1(const SkXfermode::PM4fState& state, uint32_t dst[],
                                    const SkPM4f& src, int count, const SkAlpha aa[]) {
    Sk4f s4 = Sk4f::Load(src.fVec);
    Sk4f scale = Sk4f(1 - get_alpha(s4));

    if (aa) {
        for (int i = 0; i < count; ++i) {
            unsigned a = aa[i];
            if (0 == a) {
                continue;
            }
            Sk4f d4 = load_dst<D>(dst[i]);
            Sk4f r4;
            if (a != 0xFF) {
                s4 = scale_by_coverage(s4, a);
                r4 = s4 + d4 * Sk4f(1 - get_alpha(s4));
            } else {
                r4 = s4 + d4 * scale;
            }
            dst[i] = store_dst<D>(r4);
        }
    } else {
        for (int i = 0; i < count; ++i) {
            Sk4f d4 = load_dst<D>(dst[i]);
            Sk4f r4 = s4 + d4 * scale;
            dst[i] = store_dst<D>(r4);
        }
    }
}
开发者ID:rohitkawale,项目名称:skia,代码行数:29,代码来源:SkXfermode4f.cpp

示例4: compute_interval_props

 void compute_interval_props(SkScalar t) {
     fDc   = dst_swizzle<DstType>(fInterval->fDc);
     fCc   = dst_swizzle<DstType>(fInterval->fC0);
     fCc   = fCc + fDc * Sk4f(t);
     fCc   = scale_for_dest<DstType, profile>(fCc);
     fDcDx = scale_for_dest<DstType, profile>(fDc * Sk4f(fDx));
     fZeroRamp = fIsVertical || fInterval->isZeroRamp();
 }
开发者ID:nicholas-yangding,项目名称:skia,代码行数:8,代码来源:Sk4fLinearGradient.cpp

示例5: encode_bitmap_for_png

    sk_sp<SkData> encode_bitmap_for_png(SkBitmap bitmap) {
        const int w = bitmap.width(),
                h = bitmap.height();
        // PNG wants unpremultiplied 8-bit RGBA pixels (16-bit could work fine too).
        // We leave the gamma of these bytes unspecified, to continue the status quo,
        // which we think generally is to interpret them as sRGB.

        SkAutoTMalloc<uint32_t> rgba(w*h);

        auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
        if (bitmap. colorType() ==  kN32_SkColorType &&
            bitmap.colorSpace() == srgbColorSpace.get()) {
            // These are premul sRGB 8-bit pixels in SkPMColor order.
            // We want unpremul sRGB 8-bit pixels in RGBA order.  We'll get there via floats.
            bitmap.lockPixels();
            auto px = (const uint32_t*)bitmap.getPixels();
            if (!px) {
                return nullptr;
            }
            for (int i = 0; i < w*h; i++) {
                Sk4f fs = Sk4f_fromS32(px[i]);         // Convert up to linear floats.
#if defined(SK_PMCOLOR_IS_BGRA)
                fs = SkNx_shuffle<2,1,0,3>(fs);        // Shuffle to RGBA, if not there already.
#endif
                float invA = 1.0f / fs[3];
                fs = fs * Sk4f(invA, invA, invA, 1);   // Unpremultiply.
                rgba[i] = Sk4f_toS32(fs);              // Pack down to sRGB bytes.
            }

        } else if (bitmap.colorType() == kRGBA_F16_SkColorType) {
            // These are premul linear half-float pixels in RGBA order.
            // We want unpremul sRGB 8-bit pixels in RGBA order.  We'll get there via floats.
            bitmap.lockPixels();
            auto px = (const uint64_t*)bitmap.getPixels();
            if (!px) {
                return nullptr;
            }
            for (int i = 0; i < w*h; i++) {
                // Convert up to linear floats.
                Sk4f fs(SkHalfToFloat(static_cast<SkHalf>(px[i] >> (0 * 16))),
                        SkHalfToFloat(static_cast<SkHalf>(px[i] >> (1 * 16))),
                        SkHalfToFloat(static_cast<SkHalf>(px[i] >> (2 * 16))),
                        SkHalfToFloat(static_cast<SkHalf>(px[i] >> (3 * 16))));
                fs = Sk4f::Max(0.0f, Sk4f::Min(fs, 1.0f));  // Clamp
                float invA = 1.0f / fs[3];
                fs = fs * Sk4f(invA, invA, invA, 1);  // Unpremultiply.
                rgba[i] = Sk4f_toS32(fs);             // Pack down to sRGB bytes.
            }

        } else {
开发者ID:OwenTan,项目名称:skia,代码行数:50,代码来源:picture_utils.cpp

示例6: DEF_TEST

DEF_TEST(Sk4x_Swizzle, r) {
    ASSERT_EQ(Sk4f(3,4,1,2), Sk4f(1,2,3,4).zwxy());
    ASSERT_EQ(Sk4f(1,2,5,6), Sk4f::XYAB(Sk4f(1,2,3,4), Sk4f(5,6,7,8)));
    ASSERT_EQ(Sk4f(3,4,7,8), Sk4f::ZWCD(Sk4f(1,2,3,4), Sk4f(5,6,7,8)));
    ASSERT_EQ(Sk4i(3,4,1,2), Sk4i(1,2,3,4).zwxy());
    ASSERT_EQ(Sk4i(1,2,5,6), Sk4i::XYAB(Sk4i(1,2,3,4), Sk4i(5,6,7,8)));
    ASSERT_EQ(Sk4i(3,4,7,8), Sk4i::ZWCD(Sk4i(1,2,3,4), Sk4i(5,6,7,8)));
}
开发者ID:OS-Corp,项目名称:skia,代码行数:8,代码来源:Sk4xTest.cpp

示例7: SkASSERT

void GrCCFillGeometry::conicTo(const SkPoint P[3], float w) {
    SkASSERT(fBuildingContour);
    SkASSERT(P[0] == fPoints.back());
    Sk2f p0 = Sk2f::Load(P);
    Sk2f p1 = Sk2f::Load(P+1);
    Sk2f p2 = Sk2f::Load(P+2);

    Sk2f tan0 = p1 - p0;
    Sk2f tan1 = p2 - p1;

    if (!is_convex_curve_monotonic(p0, tan0, p2, tan1)) {
        // The derivative of a conic has a cumbersome order-4 denominator. However, this isn't
        // necessary if we are only interested in a vector in the same *direction* as a given
        // tangent line. Since the denominator scales dx and dy uniformly, we can throw it out
        // completely after evaluating the derivative with the standard quotient rule. This leaves
        // us with a simpler quadratic function that we use to find the midtangent.
        float midT = find_midtangent(tan0, tan1, (w - 1) * (p2 - p0),
                                                 (p2 - p0) - 2*w*(p1 - p0),
                                                 w*(p1 - p0));
        // Use positive logic since NaN fails comparisons. (However midT should not be NaN since we
        // cull near-linear conics above. And while w=0 is flat, it's not a line and has valid
        // midtangents.)
        if (!(midT > 0 && midT < 1)) {
            // The conic is flat. Otherwise there would be a real midtangent inside T=0..1.
            this->appendLine(p0, p2);
            return;
        }

        // Chop the conic at midtangent to produce two monotonic segments.
        Sk4f p3d0 = Sk4f(p0[0], p0[1], 1, 0);
        Sk4f p3d1 = Sk4f(p1[0], p1[1], 1, 0) * w;
        Sk4f p3d2 = Sk4f(p2[0], p2[1], 1, 0);
        Sk4f midT4 = midT;

        Sk4f p3d01 = lerp(p3d0, p3d1, midT4);
        Sk4f p3d12 = lerp(p3d1, p3d2, midT4);
        Sk4f p3d012 = lerp(p3d01, p3d12, midT4);

        Sk2f midpoint = Sk2f(p3d012[0], p3d012[1]) / p3d012[2];
        Sk2f ww = Sk2f(p3d01[2], p3d12[2]) * Sk2f(p3d012[2]).rsqrt();

        this->appendMonotonicConic(p0, Sk2f(p3d01[0], p3d01[1]) / p3d01[2], midpoint, ww[0]);
        this->appendMonotonicConic(midpoint, Sk2f(p3d12[0], p3d12[1]) / p3d12[2], p2, ww[1]);
        return;
    }

    this->appendMonotonicConic(p0, p1, p2, w);
}
开发者ID:jasonLaster,项目名称:gecko-dev,代码行数:48,代码来源:GrCCFillGeometry.cpp

示例8: Sk4f

SkPM4f SkColor4f::premul() const {
    auto src = Sk4f::Load(this->pin().vec());
    float srcAlpha = src[3];  // need the pinned version of our alpha
    src = src * Sk4f(srcAlpha, srcAlpha, srcAlpha, 1);

    return SkPM4f::From4f(src);
}
开发者ID:android,项目名称:platform_external_skia,代码行数:7,代码来源:SkColor.cpp

示例9: filter_span

void filter_span(const float array[], const T src[], int count, T dst[]) {
    // c0-c3 are already in [0,1].
    const Sk4f c0 = Sk4f::Load(array + 0);
    const Sk4f c1 = Sk4f::Load(array + 4);
    const Sk4f c2 = Sk4f::Load(array + 8);
    const Sk4f c3 = Sk4f::Load(array + 12);
    // c4 (the translate vector) is in [0, 255].  Bring it back to [0,1].
    const Sk4f c4 = Sk4f::Load(array + 16)*Sk4f(1.0f/255);

    // todo: we could cache this in the constructor...
    T matrix_translate_pmcolor = Adaptor::From4f(premul(clamp_0_1(c4)));

    for (int i = 0; i < count; i++) {
        Sk4f srcf = Adaptor::To4f(src[i]);
        float srcA = srcf.kth<SkPM4f::A>();

        if (0 == srcA) {
            dst[i] = matrix_translate_pmcolor;
            continue;
        }
        if (1 != srcA) {
            srcf = unpremul(srcf);
        }

        Sk4f r4 = SkNx_dup<SK_R32_SHIFT/8>(srcf);
        Sk4f g4 = SkNx_dup<SK_G32_SHIFT/8>(srcf);
        Sk4f b4 = SkNx_dup<SK_B32_SHIFT/8>(srcf);
        Sk4f a4 = SkNx_dup<SK_A32_SHIFT/8>(srcf);

        // apply matrix
        Sk4f dst4 = c0 * r4 + c1 * g4 + c2 * b4 + c3 * a4 + c4;

        dst[i] = Adaptor::From4f(premul(clamp_0_1(dst4)));
    }
}
开发者ID:mokacao,项目名称:skia,代码行数:35,代码来源:SkColorMatrixFilterRowMajor255.cpp

示例10: compute_interval_props

 void compute_interval_props(SkScalar t) {
     const Sk4f dC = DstTraits<dstType>::load(fInterval->fDc);
     fCc           = DstTraits<dstType>::load(fInterval->fC0);
     fCc           = fCc + dC * Sk4f(t);
     fDcDx         = dC * fDx;
     fZeroRamp     = fIsVertical || fInterval->isZeroRamp();
 }
开发者ID:03050903,项目名称:skia,代码行数:7,代码来源:Sk4fLinearGradient.cpp

示例11: while

void SkColorFilter::filterSpan4f(const SkPM4f[], int count, SkPM4f span[]) const {
    const int N = 128;
    SkPMColor tmp[N];
    while (count > 0) {
        int n = SkTMin(count, N);
        for (int i = 0; i < n; ++i) {
            SkNx_cast<uint8_t>(Sk4f::Load(span[i].fVec) * Sk4f(255) + Sk4f(0.5f)).store(&tmp[i]);
        }
        this->filterSpan(tmp, n, tmp);
        for (int i = 0; i < n; ++i) {
            span[i] = SkPM4f::FromPMColor(tmp[i]);
        }
        span += n;
        count -= n;
    }
}
开发者ID:leaf0793,项目名称:skia,代码行数:16,代码来源:SkColorFilter.cpp

示例12: src_1_lcd

void src_1_lcd(uint32_t dst[], const SkPM4f* src, int count, const uint16_t lcd[]) {
    const Sk4f s4 = Sk4f::Load(src->fVec);

    if (D == kLinear_Dst) {
        // operate in bias-255 space for src and dst
        const Sk4f s4bias = s4 * Sk4f(255);
        for (int i = 0; i < count; ++i) {
            uint16_t rgb = lcd[i];
            if (0 == rgb) {
                continue;
            }
            Sk4f d4bias = to_4f(dst[i]);
            dst[i] = to_4b(lerp(s4bias, d4bias, lcd16_to_unit_4f(rgb))) | (SK_A32_MASK << SK_A32_SHIFT);
        }
    } else {    // kSRGB
        for (int i = 0; i < count; ++i) {
            uint16_t rgb = lcd[i];
            if (0 == rgb) {
                continue;
            }
            Sk4f d4 = load_dst<D>(dst[i]);
            dst[i] = store_dst<D>(lerp(s4, d4, lcd16_to_unit_4f(rgb))) | (SK_A32_MASK << SK_A32_SHIFT);
        }
    }
}
开发者ID:BertiKarsunke,项目名称:skia,代码行数:25,代码来源:SkXfermode4f.cpp

示例13: colorburn_4f

static Sk4f colorburn_4f(const Sk4f& s, const Sk4f& d) {
    Sk4f sa  = alpha(s);
    Sk4f da  = alpha(d);
    Sk4f isa = Sk4f(1) - sa;
    Sk4f ida = Sk4f(1) - da;

    Sk4f srcover = s + d * isa;
    Sk4f dstover = d + s * ida;
    Sk4f otherwise = sa * (da - Sk4f::Min(da, (da - d) * sa / s)) + s * ida + d * isa;

    // Order matters here, preferring d==da over s==0.
    auto colors = (d == da).thenElse(dstover,
                                     (s == Sk4f(0)).thenElse(srcover,
                                                             otherwise));
    return color_alpha(colors, srcover);
}
开发者ID:kekekeks,项目名称:skia,代码行数:16,代码来源:SkXfermode.cpp

示例14: lcd16_to_unit_4f

static Sk4f lcd16_to_unit_4f(uint16_t rgb) {
#ifdef SK_PMCOLOR_IS_RGBA
    Sk4i rgbi = Sk4i(SkGetPackedR16(rgb), SkGetPackedG16(rgb), SkGetPackedB16(rgb), 0);
#else
    Sk4i rgbi = Sk4i(SkGetPackedB16(rgb), SkGetPackedG16(rgb), SkGetPackedR16(rgb), 0);
#endif
    return SkNx_cast<float>(rgbi) * Sk4f(1.0f/31, 1.0f/63, 1.0f/31, 0);
}
开发者ID:BertiKarsunke,项目名称:skia,代码行数:8,代码来源:SkXfermode4f.cpp

示例15: srcover_srgb_dst_1

static void srcover_srgb_dst_1(const SkXfermode*, uint32_t dst[],
                               const SkPM4f* src, int count, const SkAlpha aa[]) {
    Sk4f s4 = src->to4f_pmorder();
    Sk4f dst_scale = Sk4f(1 - get_alpha(s4));

    if (aa) {
        for (int i = 0; i < count; ++i) {
            unsigned a = aa[i];
            if (0 == a) {
                continue;
            }
            Sk4f d4 = srgb_4b_to_linear_unit(dst[i]);
            Sk4f r4;
            if (a != 0xFF) {
                const Sk4f s4_aa = scale_by_coverage(s4, a);
                r4 = s4_aa + d4 * Sk4f(1 - get_alpha(s4_aa));
            } else {
                r4 = s4 + d4 * dst_scale;
            }
            dst[i] = to_4b(linear_unit_to_srgb_255f(r4));
        }
    } else {
        while (count >= 4) {
            auto d = load_4_srgb(dst);

            auto s = Sk4x4f{{ src->r() }, { src->g() }, { src->b() }, { src->a() }};
        #if defined(SK_PMCOLOR_IS_BGRA)
            SkTSwap(s.r, s.b);
        #endif

            auto invSA = 1.0f - s.a;
            auto r = s.r + d.r * invSA,
                 g = s.g + d.g * invSA,
                 b = s.b + d.b * invSA,
                 a = s.a + d.a * invSA;

            store_4_srgb(dst, Sk4x4f{r,g,b,a});
            count -= 4;
            dst += 4;
        }
        for (int i = 0; i < count; ++i) {
            Sk4f d4 = srgb_4b_to_linear_unit(dst[i]);
            dst[i] = to_4b(linear_unit_to_srgb_255f(s4 + d4 * dst_scale));
        }
    }
}
开发者ID:BertiKarsunke,项目名称:skia,代码行数:46,代码来源:SkXfermode4f.cpp


注:本文中的Sk4f函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。