xref: /aosp_15_r20/external/deqp/modules/internal/ditImageIOTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Internal Test Module
3  * ---------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Image IO tests.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "ditImageIOTests.hpp"
25 #include "tcuResource.hpp"
26 #include "tcuImageIO.hpp"
27 #include "tcuTexture.hpp"
28 #include "tcuTestLog.hpp"
29 #include "tcuFormatUtil.hpp"
30 #include "deUniquePtr.hpp"
31 #include "deString.h"
32 
33 namespace dit
34 {
35 
36 using tcu::TestLog;
37 
38 // \todo [2013-05-28 pyry] Image output cases!
39 
40 class ImageReadCase : public tcu::TestCase
41 {
42 public:
ImageReadCase(tcu::TestContext & testCtx,const char * name,const char * filename,uint32_t expectedHash)43     ImageReadCase(tcu::TestContext &testCtx, const char *name, const char *filename, uint32_t expectedHash)
44         : TestCase(testCtx, name, filename)
45         , m_filename(filename)
46         , m_expectedHash(expectedHash)
47     {
48     }
49 
iterate(void)50     IterateResult iterate(void)
51     {
52         m_testCtx.getLog() << TestLog::Message << "Loading image from file '" << m_filename << "'"
53                            << TestLog::EndMessage;
54 
55         tcu::TextureLevel texture;
56         tcu::ImageIO::loadImage(texture, m_testCtx.getArchive(), m_filename.c_str());
57 
58         m_testCtx.getLog() << TestLog::Message << "Loaded " << texture.getWidth() << "x" << texture.getHeight() << "x"
59                            << texture.getDepth() << " image with format " << texture.getFormat() << TestLog::EndMessage;
60 
61         // Check that layout is as expected
62         TCU_CHECK(texture.getAccess().getRowPitch() == texture.getWidth() * texture.getFormat().getPixelSize());
63         TCU_CHECK(texture.getAccess().getSlicePitch() ==
64                   texture.getAccess().getRowPitch() * texture.getAccess().getHeight());
65 
66         const int imageSize = texture.getAccess().getSlicePitch() * texture.getDepth();
67         const uint32_t hash = deMemoryHash(texture.getAccess().getDataPtr(), imageSize);
68 
69         if (hash != m_expectedHash)
70         {
71             m_testCtx.getLog() << TestLog::Message << "ERROR: expected hash " << tcu::toHex(m_expectedHash) << ", got "
72                                << tcu::toHex(hash) << TestLog::EndMessage;
73             m_testCtx.getLog() << TestLog::Image("Image", "Loaded image", texture.getAccess());
74             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Hash check failed");
75         }
76         else
77             m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
78 
79         return STOP;
80     }
81 
82 private:
83     const std::string m_filename;
84     const uint32_t m_expectedHash;
85 };
86 
87 class ImageReadTests : public tcu::TestCaseGroup
88 {
89 public:
ImageReadTests(tcu::TestContext & testCtx)90     ImageReadTests(tcu::TestContext &testCtx) : TestCaseGroup(testCtx, "read", "Image read tests")
91     {
92     }
93 
init(void)94     void init(void)
95     {
96         addChild(new ImageReadCase(m_testCtx, "rgb24_256x256", "internal/data/imageio/rgb24_256x256.png", 0x6efad777));
97         addChild(new ImageReadCase(m_testCtx, "rgb24_209x181", "internal/data/imageio/rgb24_209x181.png", 0xfd6ea668));
98         addChild(
99             new ImageReadCase(m_testCtx, "rgba32_256x256", "internal/data/imageio/rgba32_256x256.png", 0xcf4883da));
100         addChild(
101             new ImageReadCase(m_testCtx, "rgba32_207x219", "internal/data/imageio/rgba32_207x219.png", 0x404ba06b));
102     }
103 };
104 
ImageIOTests(tcu::TestContext & testCtx)105 ImageIOTests::ImageIOTests(tcu::TestContext &testCtx) : TestCaseGroup(testCtx, "image_io", "Image read and write tests")
106 {
107 }
108 
~ImageIOTests(void)109 ImageIOTests::~ImageIOTests(void)
110 {
111 }
112 
init(void)113 void ImageIOTests::init(void)
114 {
115     addChild(new ImageReadTests(m_testCtx));
116 }
117 
118 } // namespace dit
119