pixel.test.cc revision 13465:dee578a46d87
112841Sgabeblack@google.com/* 212841Sgabeblack@google.com * Copyright (c) 2015 ARM Limited 312841Sgabeblack@google.com * All rights reserved 412841Sgabeblack@google.com * 512841Sgabeblack@google.com * The license below extends only to copyright in the software and shall 612841Sgabeblack@google.com * not be construed as granting a license to any other intellectual 712841Sgabeblack@google.com * property including but not limited to intellectual property relating 812841Sgabeblack@google.com * to a hardware implementation of the functionality of the software 912841Sgabeblack@google.com * licensed hereunder. You may use the software subject to the license 1012841Sgabeblack@google.com * terms below provided that you ensure that this notice is replicated 1112841Sgabeblack@google.com * unmodified and in its entirety in all distributions of the software, 1212841Sgabeblack@google.com * modified or unmodified, in source code or in binary form. 1312841Sgabeblack@google.com * 1412841Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 1512841Sgabeblack@google.com * modification, are permitted provided that the following conditions are 1612841Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 1712841Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 1812841Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1912841Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 2012841Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 2112841Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 2212841Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 2312841Sgabeblack@google.com * this software without specific prior written permission. 2412841Sgabeblack@google.com * 2512841Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2612841Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2712841Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2812841Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2912841Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3012841Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3112841Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3212841Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3312841Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3412841Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3513054Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3613269Sgabeblack@google.com * 3712841Sgabeblack@google.com * Authors: Andreas Sandberg 3813245Sgabeblack@google.com */ 3912841Sgabeblack@google.com 4012841Sgabeblack@google.com#include <gtest/gtest.h> 4112841Sgabeblack@google.com 4212841Sgabeblack@google.com#include "base/pixel.hh" 4312841Sgabeblack@google.com 4412841Sgabeblack@google.comstatic Pixel pixel_red(0xff, 0x00, 0x00); 4512841Sgabeblack@google.comstatic Pixel pixel_green(0x00, 0xff, 0x00); 4612841Sgabeblack@google.comstatic Pixel pixel_blue(0x00, 0x00, 0xff); 4712841Sgabeblack@google.com 4812841Sgabeblack@google.comTEST(FBTest, PixelConversionRGBA8888) 4912841Sgabeblack@google.com{ 5012841Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.fromPixel(pixel_red), 5112841Sgabeblack@google.com 0x000000ffU); 5213054Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.fromPixel(pixel_green), 5313054Sgabeblack@google.com 0x0000ff00U); 5413054Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.fromPixel(pixel_blue), 5513054Sgabeblack@google.com 0x00ff0000U); 5613054Sgabeblack@google.com 5713054Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(0x000000ffU), 5812841Sgabeblack@google.com pixel_red); 5912841Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(0x0000ff00U), 6012868Sgabeblack@google.com pixel_green); 6112868Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(0x00ff0000U), 6213054Sgabeblack@google.com pixel_blue); 6313054Sgabeblack@google.com} 6412868Sgabeblack@google.com 6512868Sgabeblack@google.comTEST(FBTest, PixelConversionRGB565) 6613054Sgabeblack@google.com{ 6713054Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgb565_le.fromPixel(pixel_red), 0x001fU); 6812868Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgb565_le.fromPixel(pixel_green), 0x07e0U); 6912868Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgb565_le.fromPixel(pixel_blue), 0xf800U); 7013054Sgabeblack@google.com 7113054Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgb565_le.toPixel(0x001fU), pixel_red); 7212868Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgb565_le.toPixel(0x07e0U), pixel_green); 7312868Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgb565_le.toPixel(0xf800U), pixel_blue); 7413054Sgabeblack@google.com} 7513054Sgabeblack@google.com 7612868Sgabeblack@google.comTEST(FBTest, PixelToMemRGBA8888LE) 7712868Sgabeblack@google.com{ 7813054Sgabeblack@google.com uint8_t data[] = { 0xde, 0xad, 0xbe, 0xef }; 7913054Sgabeblack@google.com PixelConverter::rgba8888_le.fromPixel(data, pixel_red); 8012868Sgabeblack@google.com EXPECT_EQ(data[0], 0xff); 8112868Sgabeblack@google.com EXPECT_EQ(data[1], 0x00); 8213054Sgabeblack@google.com EXPECT_EQ(data[3], 0x00); 8313054Sgabeblack@google.com EXPECT_EQ(data[3], 0x00); 8412868Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(data), pixel_red); 8512868Sgabeblack@google.com 8613498Snikos.nikoleris@arm.com PixelConverter::rgba8888_le.fromPixel(data, pixel_green); 8712841Sgabeblack@google.com EXPECT_EQ(data[0], 0x00); 8813054Sgabeblack@google.com EXPECT_EQ(data[1], 0xff); 8912841Sgabeblack@google.com EXPECT_EQ(data[3], 0x00); 9013054Sgabeblack@google.com EXPECT_EQ(data[3], 0x00); 9113054Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(data), pixel_green); 9213054Sgabeblack@google.com 9313054Sgabeblack@google.com PixelConverter::rgba8888_le.fromPixel(data, pixel_blue); 9413054Sgabeblack@google.com EXPECT_EQ(data[0], 0x00); 9513054Sgabeblack@google.com EXPECT_EQ(data[1], 0x00); 9613054Sgabeblack@google.com EXPECT_EQ(data[2], 0xff); 9713054Sgabeblack@google.com EXPECT_EQ(data[3], 0x00); 9813054Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(data), pixel_blue); 9912841Sgabeblack@google.com} 10012841Sgabeblack@google.com 10113054Sgabeblack@google.comTEST(FBTest, MemToPixelRGBA8888LE) 10212841Sgabeblack@google.com{ 10313054Sgabeblack@google.com uint8_t red[] = { 0xff, 0x00, 0x00, 0x00 }; 10412841Sgabeblack@google.com uint8_t green[] = { 0x00, 0xff, 0x00, 0x00 }; 10512841Sgabeblack@google.com uint8_t blue[] = { 0x00, 0x00, 0xff, 0x00 }; 10612841Sgabeblack@google.com 10713054Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(red), pixel_red); 10812841Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(green), pixel_green); 10913054Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(blue), pixel_blue); 11012841Sgabeblack@google.com} 11112841Sgabeblack@google.com 11213054Sgabeblack@google.comTEST(FBTest, MemToPixelRGBA8888BE) 11312841Sgabeblack@google.com{ 11413054Sgabeblack@google.com uint8_t red[] = { 0x00, 0x00, 0x00, 0xff }; 11512841Sgabeblack@google.com uint8_t green[] = { 0x00, 0x00, 0xff, 0x00 }; 11612841Sgabeblack@google.com uint8_t blue[] = { 0x00, 0xff, 0x00, 0x00 }; 11713245Sgabeblack@google.com 11813245Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_be.toPixel(red), pixel_red); 11913245Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_be.toPixel(green), pixel_green); 12013245Sgabeblack@google.com EXPECT_EQ(PixelConverter::rgba8888_be.toPixel(blue), pixel_blue); 12113245Sgabeblack@google.com} 12213245Sgabeblack@google.com