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