113465Sgabeblack@google.com/* 213465Sgabeblack@google.com * Copyright (c) 2015 ARM Limited 313465Sgabeblack@google.com * All rights reserved 413465Sgabeblack@google.com * 513465Sgabeblack@google.com * The license below extends only to copyright in the software and shall 613465Sgabeblack@google.com * not be construed as granting a license to any other intellectual 713465Sgabeblack@google.com * property including but not limited to intellectual property relating 813465Sgabeblack@google.com * to a hardware implementation of the functionality of the software 913465Sgabeblack@google.com * licensed hereunder. You may use the software subject to the license 1013465Sgabeblack@google.com * terms below provided that you ensure that this notice is replicated 1113465Sgabeblack@google.com * unmodified and in its entirety in all distributions of the software, 1213465Sgabeblack@google.com * modified or unmodified, in source code or in binary form. 1313465Sgabeblack@google.com * 1413465Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 1513465Sgabeblack@google.com * modification, are permitted provided that the following conditions are 1613465Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 1713465Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 1813465Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1913465Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 2013465Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 2113465Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 2213465Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 2313465Sgabeblack@google.com * this software without specific prior written permission. 2413465Sgabeblack@google.com * 2513465Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2613465Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2713465Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2813465Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2913465Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3013465Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3113465Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3213465Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3313465Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3413465Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3513465Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3613465Sgabeblack@google.com * 3713465Sgabeblack@google.com * Authors: Andreas Sandberg 3813465Sgabeblack@google.com */ 3913465Sgabeblack@google.com 4013465Sgabeblack@google.com#include <gtest/gtest.h> 4113465Sgabeblack@google.com 4213465Sgabeblack@google.com#include "base/pixel.hh" 4313465Sgabeblack@google.com 4413465Sgabeblack@google.comstatic Pixel pixel_red(0xff, 0x00, 0x00); 4513465Sgabeblack@google.comstatic Pixel pixel_green(0x00, 0xff, 0x00); 4613465Sgabeblack@google.comstatic Pixel pixel_blue(0x00, 0x00, 0xff); 4713465Sgabeblack@google.com 4813465Sgabeblack@google.comTEST(FBTest, PixelConversionRGBA8888) 4913465Sgabeblack@google.com{ 5013465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.fromPixel(pixel_red), 5113465Sgabeblack@google.com 0x000000ffU); 5213465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.fromPixel(pixel_green), 5313465Sgabeblack@google.com 0x0000ff00U); 5413465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.fromPixel(pixel_blue), 5513465Sgabeblack@google.com 0x00ff0000U); 5613465Sgabeblack@google.com 5713465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(0x000000ffU), 5813465Sgabeblack@google.com pixel_red); 5913465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(0x0000ff00U), 6013465Sgabeblack@google.com pixel_green); 6113465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(0x00ff0000U), 6213465Sgabeblack@google.com pixel_blue); 6313465Sgabeblack@google.com} 6413465Sgabeblack@google.com 6513465Sgabeblack@google.comTEST(FBTest, PixelConversionRGB565) 6613465Sgabeblack@google.com{ 6713465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgb565_le.fromPixel(pixel_red), 0x001fU); 6813465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgb565_le.fromPixel(pixel_green), 0x07e0U); 6913465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgb565_le.fromPixel(pixel_blue), 0xf800U); 7013465Sgabeblack@google.com 7113465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgb565_le.toPixel(0x001fU), pixel_red); 7213465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgb565_le.toPixel(0x07e0U), pixel_green); 7313465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgb565_le.toPixel(0xf800U), pixel_blue); 7413465Sgabeblack@google.com} 7513465Sgabeblack@google.com 7613465Sgabeblack@google.comTEST(FBTest, PixelToMemRGBA8888LE) 7713465Sgabeblack@google.com{ 7813465Sgabeblack@google.com uint8_t data[] = { 0xde, 0xad, 0xbe, 0xef }; 7913465Sgabeblack@google.com PixelConverter::rgba8888_le.fromPixel(data, pixel_red); 8013465Sgabeblack@google.com EXPECT_EQ(data[0], 0xff); 8113465Sgabeblack@google.com EXPECT_EQ(data[1], 0x00); 8213465Sgabeblack@google.com EXPECT_EQ(data[3], 0x00); 8313465Sgabeblack@google.com EXPECT_EQ(data[3], 0x00); 8413465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(data), pixel_red); 8513465Sgabeblack@google.com 8613465Sgabeblack@google.com PixelConverter::rgba8888_le.fromPixel(data, pixel_green); 8713465Sgabeblack@google.com EXPECT_EQ(data[0], 0x00); 8813465Sgabeblack@google.com EXPECT_EQ(data[1], 0xff); 8913465Sgabeblack@google.com EXPECT_EQ(data[3], 0x00); 9013465Sgabeblack@google.com EXPECT_EQ(data[3], 0x00); 9113465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(data), pixel_green); 9213465Sgabeblack@google.com 9313465Sgabeblack@google.com PixelConverter::rgba8888_le.fromPixel(data, pixel_blue); 9413465Sgabeblack@google.com EXPECT_EQ(data[0], 0x00); 9513465Sgabeblack@google.com EXPECT_EQ(data[1], 0x00); 9613465Sgabeblack@google.com EXPECT_EQ(data[2], 0xff); 9713465Sgabeblack@google.com EXPECT_EQ(data[3], 0x00); 9813465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(data), pixel_blue); 9913465Sgabeblack@google.com} 10013465Sgabeblack@google.com 10113465Sgabeblack@google.comTEST(FBTest, MemToPixelRGBA8888LE) 10213465Sgabeblack@google.com{ 10313465Sgabeblack@google.com uint8_t red[] = { 0xff, 0x00, 0x00, 0x00 }; 10413465Sgabeblack@google.com uint8_t green[] = { 0x00, 0xff, 0x00, 0x00 }; 10513465Sgabeblack@google.com uint8_t blue[] = { 0x00, 0x00, 0xff, 0x00 }; 10613465Sgabeblack@google.com 10713465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(red), pixel_red); 10813465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(green), pixel_green); 10913465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(blue), pixel_blue); 11013465Sgabeblack@google.com} 11113465Sgabeblack@google.com 11213465Sgabeblack@google.comTEST(FBTest, MemToPixelRGBA8888BE) 11313465Sgabeblack@google.com{ 11413465Sgabeblack@google.com uint8_t red[] = { 0x00, 0x00, 0x00, 0xff }; 11513465Sgabeblack@google.com uint8_t green[] = { 0x00, 0x00, 0xff, 0x00 }; 11613465Sgabeblack@google.com uint8_t blue[] = { 0x00, 0xff, 0x00, 0x00 }; 11713465Sgabeblack@google.com 11813465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_be.toPixel(red), pixel_red); 11913465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_be.toPixel(green), pixel_green); 12013465Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_be.toPixel(blue), pixel_blue); 12113465Sgabeblack@google.com} 122