Fix generic color space xform, ColorSpaceXformTest
BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2275563002 Review-Url: https://codereview.chromium.org/2275563002
This commit is contained in:
parent
ae6377c08e
commit
9dc6cf6b88
@ -950,13 +950,21 @@ static inline void store_generic(void* dst, const uint32_t* src,
|
||||
static inline void store_generic_1(void* dst, const uint32_t* src,
|
||||
Sk4f& rgba, const Sk4f&,
|
||||
const uint8_t* const dstTables[3], SwapRB kSwapRB) {
|
||||
int kRShift = 0;
|
||||
int kGShift = 8;
|
||||
int kBShift = 16;
|
||||
if (kYes_SwapRB == kSwapRB) {
|
||||
kBShift = 0;
|
||||
kRShift = 16;
|
||||
}
|
||||
|
||||
rgba = Sk4f::Min(Sk4f::Max(1023.0f * rgba, 0.0f), 1023.0f);
|
||||
|
||||
Sk4i indices = Sk4f_round(rgba);
|
||||
|
||||
*((uint32_t*) dst) = dstTables[0][indices[0]] << 0
|
||||
| dstTables[1][indices[1]] << 8
|
||||
| dstTables[2][indices[2]] << 16
|
||||
*((uint32_t*) dst) = dstTables[0][indices[0]] << kRShift
|
||||
| dstTables[1][indices[1]] << kGShift
|
||||
| dstTables[2][indices[2]] << kBShift
|
||||
| (*src & 0xFF000000);
|
||||
}
|
||||
|
||||
@ -1197,3 +1205,9 @@ const
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkColorSpace>& space) {
|
||||
return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
|
||||
<SkColorSpace::kNonStandard_GammaNamed, kNone_ColorSpaceMatch>
|
||||
(space, SkMatrix::I(), space));
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
* |dstColorType| and is premultiplied by alpha if |premul| is set.
|
||||
*/
|
||||
virtual void apply(void* dst, const uint32_t* src, int len, SkColorType dstColorType,
|
||||
SkAlphaType dstAlphaType) const = 0;
|
||||
SkAlphaType dstAlphaType) const = 0;
|
||||
|
||||
virtual ~SkColorSpaceXform() {}
|
||||
};
|
||||
@ -68,6 +68,10 @@ private:
|
||||
uint8_t fDstGammaTableStorage[3 * kDstGammaTableSize];
|
||||
|
||||
friend class SkColorSpaceXform;
|
||||
friend std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkColorSpace>& space);
|
||||
};
|
||||
|
||||
// For testing. Bypasses opts for when src and dst color spaces are equal.
|
||||
std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkColorSpace>& space);
|
||||
|
||||
#endif
|
||||
|
@ -19,7 +19,9 @@ public:
|
||||
// Logically we can pass any matrix here. For simplicty, pass I(), i.e. D50 XYZ gamut.
|
||||
sk_sp<SkColorSpace> space(new SkColorSpace_Base(
|
||||
nullptr, SkColorSpace::kNonStandard_GammaNamed, gammas, SkMatrix::I(), nullptr));
|
||||
return SkColorSpaceXform::New(space, space);
|
||||
|
||||
// Use special testing entry point, so we don't skip the xform, even though src == dst.
|
||||
return SlowIdentityXform(space);
|
||||
}
|
||||
};
|
||||
|
||||
@ -37,19 +39,19 @@ static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& ga
|
||||
|
||||
// Create and perform an identity xform.
|
||||
std::unique_ptr<SkColorSpaceXform> xform = ColorSpaceXformTest::CreateIdentityXform(gammas);
|
||||
xform->apply(dstPixels, srcPixels, width, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
|
||||
xform->apply(dstPixels, srcPixels, width, kN32_SkColorType, kOpaque_SkAlphaType);
|
||||
|
||||
// Since the src->dst matrix is the identity, and the gamma curves match,
|
||||
// the pixels should be unchanged.
|
||||
for (int i = 0; i < width; i++) {
|
||||
REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 0) & 0xFF),
|
||||
((dstPixels[i] >> 0) & 0xFF)));
|
||||
SkGetPackedR32(dstPixels[i])));
|
||||
REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 8) & 0xFF),
|
||||
((dstPixels[i] >> 8) & 0xFF)));
|
||||
SkGetPackedG32(dstPixels[i])));
|
||||
REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF),
|
||||
((dstPixels[i] >> 16) & 0xFF)));
|
||||
SkGetPackedB32(dstPixels[i])));
|
||||
REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 24) & 0xFF),
|
||||
((dstPixels[i] >> 24) & 0xFF)));
|
||||
SkGetPackedA32(dstPixels[i])));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user