Commit c8965196 authored by Andrew Osmond's avatar Andrew Osmond
Browse files

Bug 1594425 - Part 3. Make image decoder gtests use SurfaceFormat::OS_RGBA. r=tnikkel

Differential Revision: https://phabricator.services.mozilla.com/D52009

--HG--
extra : moz-landing-system : lando
parent 877d22c3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -56,8 +56,8 @@ class DecodeToSurfaceRunnableFuzzing : public Runnable {
    if (!mSurface) return;

    if (mSurface->GetType() == SurfaceType::DATA) {
      if (mSurface->GetFormat() == SurfaceFormat::B8G8R8X8 ||
          mSurface->GetFormat() == SurfaceFormat::B8G8R8A8) {
      if (mSurface->GetFormat() == SurfaceFormat::OS_RGBX ||
          mSurface->GetFormat() == SurfaceFormat::OS_RGBA) {
        DUMMY_IF(IntSize(1, 1) == mSurface->GetSize());
        DUMMY_IF(IsSolidColor(mSurface, BGRAColor::Green(), 1));
      }
+22 −15
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ namespace image {

using namespace gfx;

using std::abs;
using std::vector;

static bool sImageLibInitialized = false;
@@ -193,20 +192,25 @@ bool RectIsSolidColor(SourceSurface* aSurface, const IntRect& aRect,
  ASSERT_TRUE_OR_RETURN(data != nullptr, false);

  BGRAColor pmColor = aColor.Premultiply();
  uint32_t expectedPixel = pmColor.AsPixel();

  int32_t rowLength = mapping.GetStride();
  for (int32_t row = rect.Y(); row < rect.YMost(); ++row) {
    for (int32_t col = rect.X(); col < rect.XMost(); ++col) {
      int32_t i = row * rowLength + col * 4;
      if (aFuzz != 0) {
        ASSERT_LE_OR_RETURN(abs(pmColor.mBlue - data[i + 0]), aFuzz, false);
        ASSERT_LE_OR_RETURN(abs(pmColor.mGreen - data[i + 1]), aFuzz, false);
        ASSERT_LE_OR_RETURN(abs(pmColor.mRed - data[i + 2]), aFuzz, false);
        ASSERT_LE_OR_RETURN(abs(pmColor.mAlpha - data[i + 3]), aFuzz, false);
      } else {
        ASSERT_EQ_OR_RETURN(pmColor.mBlue, data[i + 0], false);
        ASSERT_EQ_OR_RETURN(pmColor.mGreen, data[i + 1], false);
        ASSERT_EQ_OR_RETURN(pmColor.mRed, data[i + 2], false);
        ASSERT_EQ_OR_RETURN(pmColor.mAlpha, data[i + 3], false);
      uint32_t gotPixel = *reinterpret_cast<uint32_t*>(data + i);
      if (expectedPixel != gotPixel) {
        BGRAColor gotColor = BGRAColor::FromPixel(gotPixel);
        if (abs(pmColor.mBlue - gotColor.mBlue) > aFuzz ||
            abs(pmColor.mGreen - gotColor.mGreen) > aFuzz ||
            abs(pmColor.mRed - gotColor.mRed) > aFuzz ||
            abs(pmColor.mAlpha - gotColor.mAlpha) > aFuzz) {
          EXPECT_EQ(pmColor.mBlue, gotColor.mBlue);
          EXPECT_EQ(pmColor.mGreen, gotColor.mGreen);
          EXPECT_EQ(pmColor.mRed, gotColor.mRed);
          EXPECT_EQ(pmColor.mAlpha, gotColor.mAlpha);
          ASSERT_EQ_OR_RETURN(expectedPixel, gotPixel, false);
        }
      }
    }
  }
@@ -236,10 +240,13 @@ bool RowHasPixels(SourceSurface* aSurface, int32_t aRow,
  int32_t rowLength = mapping.GetStride();
  for (int32_t col = 0; col < surfaceSize.width; ++col) {
    int32_t i = aRow * rowLength + col * 4;
    ASSERT_EQ_OR_RETURN(aPixels[col].mBlue, data[i + 0], false);
    ASSERT_EQ_OR_RETURN(aPixels[col].mGreen, data[i + 1], false);
    ASSERT_EQ_OR_RETURN(aPixels[col].mRed, data[i + 2], false);
    ASSERT_EQ_OR_RETURN(aPixels[col].mAlpha, data[i + 3], false);
    uint32_t gotPixelData = *reinterpret_cast<uint32_t*>(data + i);
    BGRAColor gotPixel = BGRAColor::FromPixel(gotPixelData);
    EXPECT_EQ(aPixels[col].mBlue, gotPixel.mBlue);
    EXPECT_EQ(aPixels[col].mGreen, gotPixel.mGreen);
    EXPECT_EQ(aPixels[col].mRed, gotPixel.mRed);
    EXPECT_EQ(aPixels[col].mAlpha, gotPixel.mAlpha);
    ASSERT_EQ_OR_RETURN(aPixels[col].AsPixel(), gotPixelData, false);
  }

  return true;
+9 −0
Original line number Diff line number Diff line
@@ -47,6 +47,15 @@ struct BGRAColor {
  static BGRAColor Blue() { return BGRAColor(0xFF, 0x00, 0x00, 0xFF); }
  static BGRAColor Transparent() { return BGRAColor(0x00, 0x00, 0x00, 0x00); }

  static BGRAColor FromPixel(uint32_t aPixel) {
    uint8_t r, g, b, a;
    r = (aPixel >> gfx::SurfaceFormatBit::OS_R) & 0xFF;
    g = (aPixel >> gfx::SurfaceFormatBit::OS_G) & 0xFF;
    b = (aPixel >> gfx::SurfaceFormatBit::OS_B) & 0xFF;
    a = (aPixel >> gfx::SurfaceFormatBit::OS_A) & 0xFF;
    return BGRAColor(b, g, r, a, true);
  }

  BGRAColor Premultiply() const {
    if (!mPremultiplied) {
      return BGRAColor(gfxPreMultiply(mBlue, mAlpha),
+2 −2
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ void WithADAM7InterpolatingFilter(const IntSize& aSize, Func aFunc) {

  WithFilterPipeline(
      decoder, std::forward<Func>(aFunc), ADAM7InterpolatingConfig{},
      SurfaceConfig{decoder, aSize, SurfaceFormat::B8G8R8A8, false});
      SurfaceConfig{decoder, aSize, SurfaceFormat::OS_RGBA, false});
}

void AssertConfiguringADAM7InterpolatingFilterFails(const IntSize& aSize) {
@@ -41,7 +41,7 @@ void AssertConfiguringADAM7InterpolatingFilterFails(const IntSize& aSize) {

  AssertConfiguringPipelineFails(
      decoder, ADAM7InterpolatingConfig{},
      SurfaceConfig{decoder, aSize, SurfaceFormat::B8G8R8A8, false});
      SurfaceConfig{decoder, aSize, SurfaceFormat::OS_RGBA, false});
}

uint8_t InterpolateByte(uint8_t aByteA, uint8_t aByteB, float aWeight) {
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ static already_AddRefed<imgFrame> CreateEmptyFrame(
  AnimationParams animParams{aFrameRect, FrameTimeout::Forever(),
                             /* aFrameNum */ 1, BlendMethod::OVER,
                             DisposalMethod::NOT_SPECIFIED};
  nsresult rv = frame->InitForDecoder(aSize, SurfaceFormat::B8G8R8A8, false,
  nsresult rv = frame->InitForDecoder(aSize, SurfaceFormat::OS_RGBA, false,
                                      Some(animParams), aCanRecycle);
  EXPECT_TRUE(NS_SUCCEEDED(rv));
  RawAccessFrameRef frameRef = frame->RawAccessRef();
Loading