tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TestSwizzleFilter.cpp (4590B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "gtest/gtest.h"
      8 
      9 #include "mozilla/gfx/2D.h"
     10 #include "Common.h"
     11 #include "Decoder.h"
     12 #include "DecoderFactory.h"
     13 #include "SurfaceFilters.h"
     14 #include "SurfacePipe.h"
     15 
     16 using namespace mozilla;
     17 using namespace mozilla::gfx;
     18 using namespace mozilla::image;
     19 
     20 template <typename Func>
     21 void WithSwizzleFilter(const IntSize& aSize, SurfaceFormat aInputFormat,
     22                       SurfaceFormat aOutputFormat, bool aPremultiplyAlpha,
     23                       Func aFunc) {
     24  RefPtr<image::Decoder> decoder = CreateTrivialDecoder();
     25  ASSERT_TRUE(decoder != nullptr);
     26 
     27  WithFilterPipeline(
     28      decoder, std::forward<Func>(aFunc),
     29      SwizzleConfig{aInputFormat, aOutputFormat, aPremultiplyAlpha},
     30      SurfaceConfig{decoder, aSize, aOutputFormat, false});
     31 }
     32 
     33 TEST(ImageSwizzleFilter, WritePixels_RGBA_to_BGRA)
     34 {
     35  WithSwizzleFilter(
     36      IntSize(100, 100), SurfaceFormat::R8G8B8A8, SurfaceFormat::B8G8R8A8,
     37      false, [](image::Decoder* aDecoder, SurfaceFilter* aFilter) {
     38        CheckTransformedWritePixels(aDecoder, aFilter, BGRAColor::Blue(),
     39                                    BGRAColor::Red());
     40      });
     41 }
     42 
     43 TEST(ImageSwizzleFilter, WritePixels_RGBA_to_Premultiplied_BGRA)
     44 {
     45  WithSwizzleFilter(
     46      IntSize(100, 100), SurfaceFormat::R8G8B8A8, SurfaceFormat::B8G8R8A8, true,
     47      [](image::Decoder* aDecoder, SurfaceFilter* aFilter) {
     48        CheckTransformedWritePixels(
     49            aDecoder, aFilter, BGRAColor(0x26, 0x00, 0x00, 0x7F, true),
     50            BGRAColor(0x00, 0x00, 0x26, 0x7F), Nothing(), Nothing(), Nothing(),
     51            Nothing(), /* aFuzz */ 1);
     52      });
     53 }
     54 
     55 TEST(ImageSwizzleFilter, WritePixels_RGBA_to_BGRX)
     56 {
     57  WithSwizzleFilter(
     58      IntSize(100, 100), SurfaceFormat::R8G8B8A8, SurfaceFormat::B8G8R8X8,
     59      false, [](image::Decoder* aDecoder, SurfaceFilter* aFilter) {
     60        CheckTransformedWritePixels(aDecoder, aFilter,
     61                                    BGRAColor(0x26, 0x00, 0x00, 0x7F, true),
     62                                    BGRAColor(0x00, 0x00, 0x26, 0xFF));
     63      });
     64 }
     65 
     66 TEST(ImageSwizzleFilter, WritePixels_RGBA_to_Premultiplied_BGRX)
     67 {
     68  WithSwizzleFilter(
     69      IntSize(100, 100), SurfaceFormat::R8G8B8A8, SurfaceFormat::B8G8R8X8, true,
     70      [](image::Decoder* aDecoder, SurfaceFilter* aFilter) {
     71        CheckTransformedWritePixels(aDecoder, aFilter,
     72                                    BGRAColor(0x26, 0x00, 0x00, 0x7F, true),
     73                                    BGRAColor(0x00, 0x00, 0x13, 0xFF));
     74      });
     75 }
     76 
     77 TEST(ImageSwizzleFilter, WritePixels_RGBA_to_RGBX)
     78 {
     79  WithSwizzleFilter(
     80      IntSize(100, 100), SurfaceFormat::R8G8B8A8, SurfaceFormat::R8G8B8X8,
     81      false, [](image::Decoder* aDecoder, SurfaceFilter* aFilter) {
     82        CheckTransformedWritePixels(aDecoder, aFilter,
     83                                    BGRAColor(0x00, 0x00, 0x26, 0x7F, true),
     84                                    BGRAColor(0x00, 0x00, 0x26, 0xFF));
     85      });
     86 }
     87 
     88 TEST(ImageSwizzleFilter, WritePixels_RGBA_to_Premultiplied_RGRX)
     89 {
     90  WithSwizzleFilter(
     91      IntSize(100, 100), SurfaceFormat::R8G8B8A8, SurfaceFormat::R8G8B8X8, true,
     92      [](image::Decoder* aDecoder, SurfaceFilter* aFilter) {
     93        CheckTransformedWritePixels(aDecoder, aFilter,
     94                                    BGRAColor(0x00, 0x00, 0x26, 0x7F, true),
     95                                    BGRAColor(0x00, 0x00, 0x13, 0xFF));
     96      });
     97 }
     98 
     99 TEST(ImageSwizzleFilter, WritePixels_BGRA_to_BGRX)
    100 {
    101  WithSwizzleFilter(
    102      IntSize(100, 100), SurfaceFormat::B8G8R8A8, SurfaceFormat::B8G8R8X8,
    103      false, [](image::Decoder* aDecoder, SurfaceFilter* aFilter) {
    104        CheckTransformedWritePixels(aDecoder, aFilter,
    105                                    BGRAColor(0x10, 0x26, 0x00, 0x7F, true),
    106                                    BGRAColor(0x10, 0x26, 0x00, 0xFF));
    107      });
    108 }
    109 
    110 TEST(ImageSwizzleFilter, WritePixels_BGRA_to_Premultiplied_BGRA)
    111 {
    112  WithSwizzleFilter(
    113      IntSize(100, 100), SurfaceFormat::B8G8R8A8, SurfaceFormat::B8G8R8A8, true,
    114      [](image::Decoder* aDecoder, SurfaceFilter* aFilter) {
    115        CheckTransformedWritePixels(
    116            aDecoder, aFilter, BGRAColor(0x10, 0x26, 0x00, 0x7F, true),
    117            BGRAColor(0x10, 0x26, 0x00, 0x7F), Nothing(), Nothing(), Nothing(),
    118            Nothing(), /* aFuzz */ 1);
    119      });
    120 }