1 #ifndef _TCUSURFACE_HPP
2 #define _TCUSURFACE_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
5 * ----------------------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief RGBA8888 surface class.
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
27 #include "tcuRGBA.hpp"
28 #include "tcuTexture.hpp"
30 #include "deArrayBuffer.hpp"
35 /*--------------------------------------------------------------------*//*!
36 * \brief RGBA8888 surface
38 * Surface provides basic pixel storage functionality. Only single format
39 * (RGBA8888) is supported.
41 * PixelBufferAccess (see tcuTexture.h) provides much more flexible API
42 * for handling various pixel formats. This is mainly a convinience class.
43 *//*--------------------------------------------------------------------*/
48 Surface (int width, int height);
51 void setSize (int width, int height);
53 int getWidth (void) const { return m_width; }
54 int getHeight (void) const { return m_height; }
56 void setPixel (int x, int y, RGBA col);
57 RGBA getPixel (int x, int y) const;
59 ConstPixelBufferAccess getAccess (void) const;
60 PixelBufferAccess getAccess (void);
63 // \note Copy constructor and assignment operators are public and auto-generated
67 de::ArrayBuffer<deUint32> m_pixels;
68 } DE_WARN_UNUSED_TYPE;
70 inline void Surface::setPixel (int x, int y, RGBA col)
72 DE_ASSERT(de::inBounds(x, 0, m_width) && de::inBounds(y, 0, m_height));
74 const int pixOffset = y*m_width + x;
75 deUint32* pixAddr = m_pixels.getElementPtr(pixOffset);
77 #if (DE_ENDIANNESS == DE_LITTLE_ENDIAN)
78 *pixAddr = col.getPacked();
80 *((deUint8*)pixAddr + 0) = (deUint8)col.getRed();
81 *((deUint8*)pixAddr + 1) = (deUint8)col.getGreen();
82 *((deUint8*)pixAddr + 2) = (deUint8)col.getBlue();
83 *((deUint8*)pixAddr + 3) = (deUint8)col.getAlpha();
87 inline RGBA Surface::getPixel (int x, int y) const
89 DE_ASSERT(de::inBounds(x, 0, m_width) && de::inBounds(y, 0, m_height));
91 const int pixOffset = y*m_width + x;
92 const deUint32* pixAddr = m_pixels.getElementPtr(pixOffset);
94 DE_STATIC_ASSERT(RGBA::RED_SHIFT == 0 && RGBA::GREEN_SHIFT == 8 && RGBA::BLUE_SHIFT == 16 && RGBA::ALPHA_SHIFT == 24);
96 #if (DE_ENDIANNESS == DE_LITTLE_ENDIAN)
97 return RGBA(*pixAddr);
99 const deUint8* byteAddr = (const deUint8*)pixAddr;
100 return RGBA(byteAddr[0], byteAddr[1], byteAddr[2], byteAddr[3]);
104 /** Get pixel buffer access from surface. */
105 inline ConstPixelBufferAccess Surface::getAccess (void) const
107 return ConstPixelBufferAccess(TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8), m_width, m_height, 1, m_pixels.empty() ? DE_NULL : m_pixels.getPtr());
110 /** Get pixel buffer access from surface. */
111 inline PixelBufferAccess Surface::getAccess (void)
113 return PixelBufferAccess(TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8), m_width, m_height, 1, m_pixels.empty() ? DE_NULL : m_pixels.getPtr());
118 #endif // _TCUSURFACE_HPP