@@ -167,11 +167,6 @@ bool IsSolidColor(SourceSurface* aSurface, BGRAColor aColor,
167167 aColor, aFuzz);
168168}
169169
170- bool IsSolidPalettedColor (Decoder* aDecoder, uint8_t aColor) {
171- RawAccessFrameRef currentFrame = aDecoder->GetCurrentFrameRef ();
172- return PalettedRectIsSolidColor (aDecoder, currentFrame->GetRect (), aColor);
173- }
174-
175170bool RowsAreSolidColor (SourceSurface* aSurface, int32_t aStartRow,
176171 int32_t aRowCount, BGRAColor aColor,
177172 uint8_t aFuzz /* = 0 */ ) {
@@ -180,15 +175,6 @@ bool RowsAreSolidColor(SourceSurface* aSurface, int32_t aStartRow,
180175 aSurface, IntRect (0 , aStartRow, size.width , aRowCount), aColor, aFuzz);
181176}
182177
183- bool PalettedRowsAreSolidColor (Decoder* aDecoder, int32_t aStartRow,
184- int32_t aRowCount, uint8_t aColor) {
185- RawAccessFrameRef currentFrame = aDecoder->GetCurrentFrameRef ();
186- IntRect frameRect = currentFrame->GetRect ();
187- IntRect solidColorRect (frameRect.X (), aStartRow, frameRect.Width (),
188- aRowCount);
189- return PalettedRectIsSolidColor (aDecoder, solidColorRect, aColor);
190- }
191-
192178bool RectIsSolidColor (SourceSurface* aSurface, const IntRect& aRect,
193179 BGRAColor aColor, uint8_t aFuzz /* = 0 */ ) {
194180 IntSize surfaceSize = aSurface->GetSize ();
@@ -228,42 +214,6 @@ bool RectIsSolidColor(SourceSurface* aSurface, const IntRect& aRect,
228214 return true ;
229215}
230216
231- bool PalettedRectIsSolidColor (Decoder* aDecoder, const IntRect& aRect,
232- uint8_t aColor) {
233- RawAccessFrameRef currentFrame = aDecoder->GetCurrentFrameRef ();
234- uint8_t * imageData;
235- uint32_t imageLength;
236- currentFrame->GetImageData (&imageData, &imageLength);
237- ASSERT_TRUE_OR_RETURN (imageData, false );
238-
239- // Clamp to the frame rect. If any pixels outside the frame rect are included,
240- // we immediately fail, because such pixels don't have any "color" in the
241- // sense this function measures - they're transparent, and that doesn't
242- // necessarily correspond to any color palette index at all.
243- IntRect frameRect = currentFrame->GetRect ();
244- ASSERT_EQ_OR_RETURN (imageLength, uint32_t (frameRect.Area ()), false );
245- IntRect rect = aRect.Intersect (frameRect);
246- ASSERT_EQ_OR_RETURN (rect.Area (), aRect.Area (), false );
247-
248- // Translate |rect| by |frameRect.TopLeft()| to reflect the fact that the
249- // frame rect's offset doesn't actually mean anything in terms of the
250- // in-memory representation of the surface. The image data starts at the upper
251- // left corner of the frame rect, in other words.
252- rect -= frameRect.TopLeft ();
253-
254- // Walk through the image data and make sure that the entire rect has the
255- // palette index |aColor|.
256- int32_t rowLength = frameRect.Width ();
257- for (int32_t row = rect.Y (); row < rect.YMost (); ++row) {
258- for (int32_t col = rect.X (); col < rect.XMost (); ++col) {
259- int32_t i = row * rowLength + col;
260- ASSERT_EQ_OR_RETURN (aColor, imageData[i], false );
261- }
262- }
263-
264- return true ;
265- }
266-
267217bool RowHasPixels (SourceSurface* aSurface, int32_t aRow,
268218 const vector<BGRAColor>& aPixels) {
269219 ASSERT_GE_OR_RETURN (aRow, 0 , false );
@@ -372,93 +322,20 @@ void CheckGeneratedSurface(SourceSurface* aSurface, const IntRect& aRect,
372322 aOuterColor, aFuzz));
373323}
374324
375- void CheckGeneratedPalettedImage (Decoder* aDecoder, const IntRect& aRect) {
376- RawAccessFrameRef currentFrame = aDecoder->GetCurrentFrameRef ();
377- IntSize imageSize = currentFrame->GetSize ();
378-
379- // This diagram shows how the surface is divided into regions that the code
380- // below tests for the correct content. The output rect is the bounds of the
381- // region labeled 'C'.
382- //
383- // +---------------------------+
384- // | A |
385- // +---------+--------+--------+
386- // | B | C | D |
387- // +---------+--------+--------+
388- // | E |
389- // +---------------------------+
390-
391- // Check that the output rect itself is all 255's. (Region 'C'.)
392- EXPECT_TRUE (PalettedRectIsSolidColor (aDecoder, aRect, 255 ));
393-
394- // Check that the area above the output rect is all 0's. (Region 'A'.)
395- EXPECT_TRUE (PalettedRectIsSolidColor (
396- aDecoder, IntRect (0 , 0 , imageSize.width , aRect.Y ()), 0 ));
397-
398- // Check that the area to the left of the output rect is all 0's. (Region
399- // 'B'.)
400- EXPECT_TRUE (PalettedRectIsSolidColor (
401- aDecoder, IntRect (0 , aRect.Y (), aRect.X (), aRect.YMost ()), 0 ));
402-
403- // Check that the area to the right of the output rect is all 0's. (Region
404- // 'D'.)
405- const int32_t widthOnRight = imageSize.width - aRect.XMost ();
406- EXPECT_TRUE (PalettedRectIsSolidColor (
407- aDecoder, IntRect (aRect.XMost (), aRect.Y (), widthOnRight, aRect.YMost ()),
408- 0 ));
409-
410- // Check that the area below the output rect is transparent. (Region 'E'.)
411- const int32_t heightBelow = imageSize.height - aRect.YMost ();
412- EXPECT_TRUE (PalettedRectIsSolidColor (
413- aDecoder, IntRect (0 , aRect.YMost (), imageSize.width , heightBelow), 0 ));
414- }
415-
416325void CheckWritePixels (Decoder* aDecoder, SurfaceFilter* aFilter,
417326 const Maybe<IntRect>& aOutputRect /* = Nothing() */ ,
418327 const Maybe<IntRect>& aInputRect /* = Nothing() */ ,
419328 const Maybe<IntRect>& aInputWriteRect /* = Nothing() */ ,
420329 const Maybe<IntRect>& aOutputWriteRect /* = Nothing() */ ,
421330 uint8_t aFuzz /* = 0 */ ) {
422- IntRect outputRect = aOutputRect.valueOr (IntRect (0 , 0 , 100 , 100 ));
423- IntRect inputRect = aInputRect.valueOr (IntRect (0 , 0 , 100 , 100 ));
424- IntRect inputWriteRect = aInputWriteRect.valueOr (inputRect);
425- IntRect outputWriteRect = aOutputWriteRect.valueOr (outputRect);
426-
427- // Fill the image.
428- int32_t count = 0 ;
429- auto result = aFilter->WritePixels <uint32_t >([&] {
430- ++count;
431- return AsVariant (BGRAColor::Green ().AsPixel ());
432- });
433- EXPECT_EQ (WriteState::FINISHED , result);
434- EXPECT_EQ (inputWriteRect.Width () * inputWriteRect.Height (), count);
435-
436- AssertCorrectPipelineFinalState (aFilter, inputRect, outputRect);
437-
438- // Attempt to write more data and make sure nothing changes.
439- const int32_t oldCount = count;
440- result = aFilter->WritePixels <uint32_t >([&] {
441- ++count;
442- return AsVariant (BGRAColor::Green ().AsPixel ());
443- });
444- EXPECT_EQ (oldCount, count);
445- EXPECT_EQ (WriteState::FINISHED , result);
446- EXPECT_TRUE (aFilter->IsSurfaceFinished ());
447- Maybe<SurfaceInvalidRect> invalidRect = aFilter->TakeInvalidRect ();
448- EXPECT_TRUE (invalidRect.isNothing ());
449-
450- // Attempt to advance to the next row and make sure nothing changes.
451- aFilter->AdvanceRow ();
452- EXPECT_TRUE (aFilter->IsSurfaceFinished ());
453- invalidRect = aFilter->TakeInvalidRect ();
454- EXPECT_TRUE (invalidRect.isNothing ());
455-
456- // Check that the generated image is correct.
457- CheckGeneratedImage (aDecoder, outputWriteRect, aFuzz);
331+ CheckTransformedWritePixels (aDecoder, aFilter, BGRAColor::Green (),
332+ BGRAColor::Green (), aOutputRect, aInputRect,
333+ aInputWriteRect, aOutputWriteRect, aFuzz);
458334}
459335
460- void CheckPalettedWritePixels (
461- Decoder* aDecoder, SurfaceFilter* aFilter,
336+ void CheckTransformedWritePixels (
337+ Decoder* aDecoder, SurfaceFilter* aFilter, const BGRAColor& aInputColor,
338+ const BGRAColor& aOutputColor,
462339 const Maybe<IntRect>& aOutputRect /* = Nothing() */ ,
463340 const Maybe<IntRect>& aInputRect /* = Nothing() */ ,
464341 const Maybe<IntRect>& aInputWriteRect /* = Nothing() */ ,
@@ -471,9 +348,9 @@ void CheckPalettedWritePixels(
471348
472349 // Fill the image.
473350 int32_t count = 0 ;
474- auto result = aFilter->WritePixels <uint8_t >([&] {
351+ auto result = aFilter->WritePixels <uint32_t >([&] {
475352 ++count;
476- return AsVariant (uint8_t ( 255 ));
353+ return AsVariant (aInputColor. AsPixel ( ));
477354 });
478355 EXPECT_EQ (WriteState::FINISHED , result);
479356 EXPECT_EQ (inputWriteRect.Width () * inputWriteRect.Height (), count);
@@ -482,9 +359,9 @@ void CheckPalettedWritePixels(
482359
483360 // Attempt to write more data and make sure nothing changes.
484361 const int32_t oldCount = count;
485- result = aFilter->WritePixels <uint8_t >([&] {
362+ result = aFilter->WritePixels <uint32_t >([&] {
486363 ++count;
487- return AsVariant (uint8_t ( 255 ));
364+ return AsVariant (aInputColor. AsPixel ( ));
488365 });
489366 EXPECT_EQ (oldCount, count);
490367 EXPECT_EQ (WriteState::FINISHED , result);
@@ -500,15 +377,9 @@ void CheckPalettedWritePixels(
500377
501378 // Check that the generated image is correct.
502379 RawAccessFrameRef currentFrame = aDecoder->GetCurrentFrameRef ();
503- uint8_t * imageData;
504- uint32_t imageLength;
505- currentFrame->GetImageData (&imageData, &imageLength);
506- ASSERT_TRUE (imageData != nullptr );
507- ASSERT_EQ (outputWriteRect.Width () * outputWriteRect.Height (),
508- int32_t (imageLength));
509- for (uint32_t i = 0 ; i < imageLength; ++i) {
510- ASSERT_EQ (uint8_t (255 ), imageData[i]);
511- }
380+ RefPtr<SourceSurface> surface = currentFrame->GetSourceSurface ();
381+ CheckGeneratedSurface (surface, outputWriteRect, aOutputColor,
382+ BGRAColor::Transparent (), aFuzz);
512383}
513384
514385// /////////////////////////////////////////////////////////////////////////////
0 commit comments