xref: /aosp_15_r20/external/angle/src/image_util/LoadToNative_unittest.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2023 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // LoadToNative_unittest.cpp: Unit tests for pixel loading functions.
7 
8 #include <gmock/gmock.h>
9 #include <vector>
10 #include "common/debug.h"
11 #include "common/mathutil.h"
12 #include "image_util/loadimage.h"
13 
14 using namespace angle;
15 using namespace testing;
16 
17 namespace
18 {
19 
20 template <typename Type>
initializeRGBInput(std::vector<Type> & rgbInput,size_t width,size_t height,size_t depth,size_t inputPixelBytes,size_t inputByteOffset,size_t inputRowPitch,size_t inputDepthPitch)21 void initializeRGBInput(std::vector<Type> &rgbInput,
22                         size_t width,
23                         size_t height,
24                         size_t depth,
25                         size_t inputPixelBytes,
26                         size_t inputByteOffset,
27                         size_t inputRowPitch,
28                         size_t inputDepthPitch)
29 {
30     ASSERT(rgbInput.size() == inputDepthPitch * depth + inputByteOffset);
31     for (size_t z = 0; z < depth; z++)
32     {
33         for (size_t y = 0; y < height; y++)
34         {
35             for (size_t x = 0; x < width; x++)
36             {
37                 size_t inputIndex =
38                     inputByteOffset + z * inputDepthPitch + y * inputRowPitch + x * inputPixelBytes;
39 
40                 rgbInput[inputIndex]     = x % 256;
41                 rgbInput[inputIndex + 1] = y % 256;
42                 rgbInput[inputIndex + 2] = z % 256;
43             }
44         }
45     }
46 }
47 
48 template <typename Type, uint8_t fourthValue>
verifyRGBToRGBAResults(const char * strCase,std::vector<Type> & rgbInput,std::vector<Type> & rgbaOutput,size_t width,size_t height,size_t depth,size_t inputPixelBytes,size_t inputByteOffset,size_t inputRowPitch,size_t inputDepthPitch,size_t outputPixelBytes,size_t outputByteOffset,size_t outputRowPitch,size_t outputDepthPitch)49 void verifyRGBToRGBAResults(const char *strCase,
50                             std::vector<Type> &rgbInput,
51                             std::vector<Type> &rgbaOutput,
52                             size_t width,
53                             size_t height,
54                             size_t depth,
55                             size_t inputPixelBytes,
56                             size_t inputByteOffset,
57                             size_t inputRowPitch,
58                             size_t inputDepthPitch,
59                             size_t outputPixelBytes,
60                             size_t outputByteOffset,
61                             size_t outputRowPitch,
62                             size_t outputDepthPitch)
63 {
64     ASSERT(rgbInput.size() == inputDepthPitch * depth + inputByteOffset);
65     ASSERT(rgbaOutput.size() == outputDepthPitch * depth + outputByteOffset);
66     for (size_t z = 0; z < depth; z++)
67     {
68         for (size_t y = 0; y < height; y++)
69         {
70             for (size_t x = 0; x < width; x++)
71             {
72                 size_t inputIndex =
73                     inputByteOffset + z * inputDepthPitch + y * inputRowPitch + x * inputPixelBytes;
74                 size_t outputIndex = outputByteOffset + z * outputDepthPitch + y * outputRowPitch +
75                                      x * outputPixelBytes;
76 
77                 bool rMatch = rgbInput[inputIndex] == rgbaOutput[outputIndex];
78                 bool gMatch = rgbInput[inputIndex + 1] == rgbaOutput[outputIndex + 1];
79                 bool bMatch = rgbInput[inputIndex + 2] == rgbaOutput[outputIndex + 2];
80                 bool aMatch = rgbaOutput[outputIndex + 3] == fourthValue;
81 
82                 EXPECT_TRUE(rMatch && gMatch && bMatch && aMatch)
83                     << "Case " << strCase << ": Mismatch at Index (" << x << ", " << y << ", " << z
84                     << ")" << std::endl
85                     << "Expected output: (" << static_cast<uint32_t>(rgbInput[inputIndex]) << ", "
86                     << static_cast<uint32_t>(rgbInput[inputIndex + 1]) << ", "
87                     << static_cast<uint32_t>(rgbInput[inputIndex + 2]) << ", "
88                     << static_cast<uint32_t>(fourthValue) << ")" << std::endl
89                     << "Actual output: (" << static_cast<uint32_t>(rgbaOutput[outputIndex]) << ", "
90                     << static_cast<uint32_t>(rgbaOutput[outputIndex + 1]) << ", "
91                     << static_cast<uint32_t>(rgbaOutput[outputIndex + 2]) << ", "
92                     << static_cast<uint32_t>(rgbaOutput[outputIndex + 3]) << ")";
93             }
94         }
95     }
96 }
97 
98 template <uint8_t fourthValue>
TestLoadUbyteRGBToRGBA(ImageLoadContext & context,const char * strCase,size_t width,size_t height,size_t depth,size_t inputByteOffset,size_t outputByteOffset,size_t inputRowAlignment)99 void TestLoadUbyteRGBToRGBA(ImageLoadContext &context,
100                             const char *strCase,
101                             size_t width,
102                             size_t height,
103                             size_t depth,
104                             size_t inputByteOffset,
105                             size_t outputByteOffset,
106                             size_t inputRowAlignment)
107 {
108     constexpr uint8_t kInitialByteValue = 0xAA;
109 
110     size_t inputPixelBytes  = 3;
111     size_t inputRowPitch    = rx::roundUpPow2(width * inputPixelBytes, inputRowAlignment);
112     size_t inputDepthPitch  = height * inputRowPitch;
113     size_t inputActualBytes = depth * inputDepthPitch;
114 
115     size_t outputPixelBytes  = 4;
116     size_t outputRowPitch    = width * outputPixelBytes;
117     size_t outputDepthPitch  = height * outputRowPitch;
118     size_t outputActualBytes = depth * outputDepthPitch;
119 
120     // Prepare the RGB input and RGBA output for copy. The offset values are used to add unused
121     // bytes to the beginning of the input and output data, in order to test address alignments.
122     std::vector<uint8_t> rgbInput(inputByteOffset + inputActualBytes, kInitialByteValue);
123     initializeRGBInput<uint8_t>(rgbInput, width, height, depth, inputPixelBytes, inputByteOffset,
124                                 inputRowPitch, inputDepthPitch);
125 
126     std::vector<uint8_t> rgbaOutput(outputByteOffset + outputActualBytes, kInitialByteValue);
127 
128     // Call loading function.
129     LoadToNative3To4<uint8_t, fourthValue>(
130         context, width, height, depth, rgbInput.data() + inputByteOffset, inputRowPitch,
131         inputDepthPitch, rgbaOutput.data() + outputByteOffset, outputRowPitch, outputDepthPitch);
132 
133     // Compare the input and output data.
134     verifyRGBToRGBAResults<uint8_t, fourthValue>(
135         strCase, rgbInput, rgbaOutput, width, height, depth, inputPixelBytes, inputByteOffset,
136         inputRowPitch, inputDepthPitch, outputPixelBytes, outputByteOffset, outputRowPitch,
137         outputDepthPitch);
138 }
139 
140 template <uint8_t fourthValue>
TestLoadSbyteRGBToRGBA(ImageLoadContext & context,const char * strCase,size_t width,size_t height,size_t depth,size_t inputByteOffset,size_t outputByteOffset,size_t inputRowAlignment)141 void TestLoadSbyteRGBToRGBA(ImageLoadContext &context,
142                             const char *strCase,
143                             size_t width,
144                             size_t height,
145                             size_t depth,
146                             size_t inputByteOffset,
147                             size_t outputByteOffset,
148                             size_t inputRowAlignment)
149 {
150     constexpr int8_t kInitialByteValue = 0xAA;
151 
152     size_t inputPixelBytes  = 3;
153     size_t inputRowPitch    = rx::roundUpPow2(width * inputPixelBytes, inputRowAlignment);
154     size_t inputDepthPitch  = height * inputRowPitch;
155     size_t inputActualBytes = depth * inputDepthPitch;
156 
157     size_t outputPixelBytes  = 4;
158     size_t outputRowPitch    = width * outputPixelBytes;
159     size_t outputDepthPitch  = height * outputRowPitch;
160     size_t outputActualBytes = depth * outputDepthPitch;
161 
162     // Prepare the RGB input and RGBA output for copy. The offset values are used to add unused
163     // bytes to the beginning of the input and output data, in order to test address alignments.
164     std::vector<int8_t> rgbInput(inputByteOffset + inputActualBytes, kInitialByteValue);
165     initializeRGBInput<int8_t>(rgbInput, width, height, depth, inputPixelBytes, inputByteOffset,
166                                inputRowPitch, inputDepthPitch);
167 
168     std::vector<int8_t> rgbaOutput(outputByteOffset + outputActualBytes, kInitialByteValue);
169 
170     // Call loading function.
171     LoadToNative3To4<int8_t, fourthValue>(
172         context, width, height, depth,
173         reinterpret_cast<uint8_t *>(rgbInput.data() + inputByteOffset), inputRowPitch,
174         inputDepthPitch, reinterpret_cast<uint8_t *>(rgbaOutput.data() + outputByteOffset),
175         outputRowPitch, outputDepthPitch);
176 
177     // Compare the input and output data.
178     verifyRGBToRGBAResults<int8_t, fourthValue>(strCase, rgbInput, rgbaOutput, width, height, depth,
179                                                 inputPixelBytes, inputByteOffset, inputRowPitch,
180                                                 inputDepthPitch, outputPixelBytes, outputByteOffset,
181                                                 outputRowPitch, outputDepthPitch);
182 }
183 
TestLoadByteRGBToRGBAForAllCases(ImageLoadContext & context,size_t inputCase,size_t width,size_t height,size_t depth,size_t inputByteOffset,size_t outputByteOffset,size_t inputRowAlignment)184 void TestLoadByteRGBToRGBAForAllCases(ImageLoadContext &context,
185                                       size_t inputCase,
186                                       size_t width,
187                                       size_t height,
188                                       size_t depth,
189                                       size_t inputByteOffset,
190                                       size_t outputByteOffset,
191                                       size_t inputRowAlignment)
192 {
193     std::string strCaseUFF = "UFF_" + std::to_string(inputCase);
194     TestLoadUbyteRGBToRGBA<0xFF>(context, strCaseUFF.c_str(), width, height, depth, inputByteOffset,
195                                  outputByteOffset, inputRowAlignment);
196     std::string strCaseU01 = "U01_" + std::to_string(inputCase);
197     TestLoadUbyteRGBToRGBA<0x01>(context, strCaseU01.c_str(), width, height, depth, inputByteOffset,
198                                  outputByteOffset, inputRowAlignment);
199     std::string strCaseS7F = "S7F_" + std::to_string(inputCase);
200     TestLoadSbyteRGBToRGBA<0x7F>(context, strCaseS7F.c_str(), width, height, depth, inputByteOffset,
201                                  outputByteOffset, inputRowAlignment);
202     std::string strCaseS01 = "S01_" + std::to_string(inputCase);
203     TestLoadSbyteRGBToRGBA<0x01>(context, strCaseS01.c_str(), width, height, depth, inputByteOffset,
204                                  outputByteOffset, inputRowAlignment);
205 }
206 
207 // Tests the ubyte (0xFF) RGB to RGBA loading function for one RGB pixel.
TEST(LoadToNative3To4,LoadUbyteRGBToRGBADataOnePixelWithFourthCompOfFF)208 TEST(LoadToNative3To4, LoadUbyteRGBToRGBADataOnePixelWithFourthCompOfFF)
209 {
210     ImageLoadContext context;
211     uint8_t rgbInput[]             = {1, 2, 3};
212     uint8_t rgbaOutput[]           = {0, 0, 0, 0};
213     constexpr uint8_t kFourthValue = 0xFF;
214 
215     LoadToNative3To4<uint8_t, kFourthValue>(context, 1, 1, 1, rgbInput, 3, 3, rgbaOutput, 4, 4);
216 
217     EXPECT_TRUE(rgbaOutput[0] == rgbInput[0] && rgbaOutput[1] == rgbInput[1] &&
218                 rgbaOutput[2] == rgbInput[2] && rgbaOutput[3] == kFourthValue)
219         << "Pixel mismatch";
220 }
221 
222 // Tests the ubyte (0x01) RGB to RGBA loading function for one RGB pixel.
TEST(LoadToNative3To4,LoadUbyteRGBToRGBADataOnePixelWithFourthCompOf01)223 TEST(LoadToNative3To4, LoadUbyteRGBToRGBADataOnePixelWithFourthCompOf01)
224 {
225     ImageLoadContext context;
226     uint8_t rgbInput[]             = {1, 2, 3};
227     uint8_t rgbaOutput[]           = {0, 0, 0, 0};
228     constexpr uint8_t kFourthValue = 0x01;
229 
230     LoadToNative3To4<uint8_t, kFourthValue>(context, 1, 1, 1, rgbInput, 3, 3, rgbaOutput, 4, 4);
231 
232     EXPECT_TRUE(rgbaOutput[0] == rgbInput[0] && rgbaOutput[1] == rgbInput[1] &&
233                 rgbaOutput[2] == rgbInput[2] && rgbaOutput[3] == kFourthValue)
234         << "Pixel mismatch";
235 }
236 
237 // Tests the sbyte (0x7F) RGB to RGBA loading function for one RGB pixel.
TEST(LoadToNative3To4,LoadSbyteRGBToRGBADataOnePixelWithFourthCompOf7F)238 TEST(LoadToNative3To4, LoadSbyteRGBToRGBADataOnePixelWithFourthCompOf7F)
239 {
240     ImageLoadContext context;
241     int8_t rgbInput[]              = {1, 2, 3};
242     int8_t rgbaOutput[]            = {0, 0, 0, 0};
243     constexpr uint8_t kFourthValue = 0x01;
244 
245     LoadToNative3To4<int8_t, kFourthValue>(context, 1, 1, 1, reinterpret_cast<uint8_t *>(rgbInput),
246                                            3, 3, reinterpret_cast<uint8_t *>(rgbaOutput), 4, 4);
247 
248     EXPECT_TRUE(rgbaOutput[0] == rgbInput[0] && rgbaOutput[1] == rgbInput[1] &&
249                 rgbaOutput[2] == rgbInput[2] && rgbaOutput[3] == static_cast<int8_t>(kFourthValue))
250         << "Pixel mismatch";
251 }
252 
253 // Tests the sbyte (0x01) RGB to RGBA loading function for one RGB pixel.
TEST(LoadToNative3To4,LoadSbyteRGBToRGBADataOnePixelWithFourthCompOf01)254 TEST(LoadToNative3To4, LoadSbyteRGBToRGBADataOnePixelWithFourthCompOf01)
255 {
256     ImageLoadContext context;
257     int8_t rgbInput[]              = {1, 2, 3};
258     int8_t rgbaOutput[]            = {0, 0, 0, 0};
259     constexpr uint8_t kFourthValue = 0x01;
260 
261     LoadToNative3To4<int8_t, kFourthValue>(context, 1, 1, 1, reinterpret_cast<uint8_t *>(rgbInput),
262                                            3, 3, reinterpret_cast<uint8_t *>(rgbaOutput), 4, 4);
263 
264     EXPECT_TRUE(rgbaOutput[0] == rgbInput[0] && rgbaOutput[1] == rgbInput[1] &&
265                 rgbaOutput[2] == rgbInput[2] && rgbaOutput[3] == static_cast<int8_t>(kFourthValue))
266         << "Pixel mismatch";
267 }
268 
269 // Tests the ubyte (0xFF) RGB to RGBA loading function for 4 RGB pixels, which should be read
270 // together.
TEST(LoadToNative3To4,LoadUbyteRGBToRGBADataFourPixelsWithFourthCompOfFF)271 TEST(LoadToNative3To4, LoadUbyteRGBToRGBADataFourPixelsWithFourthCompOfFF)
272 {
273     ImageLoadContext context;
274     constexpr uint8_t kPixelCount = 4;
275     std::vector<uint8_t> rgbInput(kPixelCount * 3);
276     std::vector<uint8_t> rgbaOutput(kPixelCount * 4, 0);
277     size_t index = 0;
278     for (auto &inputComponent : rgbInput)
279     {
280         inputComponent = ++index;
281     }
282     constexpr uint8_t kFourthValue = 0xFF;
283 
284     LoadToNative3To4<uint8_t, kFourthValue>(context, 4, 1, 1, rgbInput.data(), 3, 3,
285                                             rgbaOutput.data(), 4, 4);
286 
287     for (index = 0; index < kPixelCount; index++)
288     {
289         EXPECT_TRUE(rgbaOutput[index * 4] == rgbInput[index * 3] &&
290                     rgbaOutput[index * 4 + 1] == rgbInput[index * 3 + 1] &&
291                     rgbaOutput[index * 4 + 2] == rgbInput[index * 3 + 2] &&
292                     rgbaOutput[index * 4 + 3] == kFourthValue)
293             << "Mismatch at pixel " << index;
294     }
295 }
296 
297 // Tests the ubyte (0x01) RGB to RGBA loading function for 4 RGB pixels, which should be read
298 // together.
TEST(LoadToNative3To4,LoadUbyteRGBToRGBADataFourPixelsWithFourthCompOf01)299 TEST(LoadToNative3To4, LoadUbyteRGBToRGBADataFourPixelsWithFourthCompOf01)
300 {
301     ImageLoadContext context;
302     constexpr uint8_t kPixelCount = 4;
303     std::vector<uint8_t> rgbInput(kPixelCount * 3);
304     std::vector<uint8_t> rgbaOutput(kPixelCount * 4, 0);
305     size_t index = 0;
306     for (auto &inputComponent : rgbInput)
307     {
308         inputComponent = ++index;
309     }
310     constexpr uint8_t kFourthValue = 0x01;
311 
312     LoadToNative3To4<uint8_t, kFourthValue>(context, 4, 1, 1, rgbInput.data(), 3, 3,
313                                             rgbaOutput.data(), 4, 4);
314 
315     for (index = 0; index < kPixelCount; index++)
316     {
317         EXPECT_TRUE(rgbaOutput[index * 4] == rgbInput[index * 3] &&
318                     rgbaOutput[index * 4 + 1] == rgbInput[index * 3 + 1] &&
319                     rgbaOutput[index * 4 + 2] == rgbInput[index * 3 + 2] &&
320                     rgbaOutput[index * 4 + 3] == kFourthValue)
321             << "Mismatch at pixel " << index;
322     }
323 }
324 
325 // Tests the sbyte (0x7F) RGB to RGBA loading function for 4 RGB pixels, which should be read
326 // together.
TEST(LoadToNative3To4,LoadSbyteRGBToRGBADataFourPixelsWithFourthCompOf7F)327 TEST(LoadToNative3To4, LoadSbyteRGBToRGBADataFourPixelsWithFourthCompOf7F)
328 {
329     ImageLoadContext context;
330     constexpr uint8_t kPixelCount = 4;
331     std::vector<int8_t> rgbInput(kPixelCount * 3);
332     std::vector<int8_t> rgbaOutput(kPixelCount * 4, 0);
333     size_t index = 0;
334     for (auto &inputComponent : rgbInput)
335     {
336         inputComponent = ++index;
337     }
338     constexpr uint8_t kFourthValue = 0x01;
339 
340     LoadToNative3To4<int8_t, kFourthValue>(context, 4, 1, 1,
341                                            reinterpret_cast<uint8_t *>(rgbInput.data()), 3, 3,
342                                            reinterpret_cast<uint8_t *>(rgbaOutput.data()), 4, 4);
343 
344     for (index = 0; index < kPixelCount; index++)
345     {
346         EXPECT_TRUE(rgbaOutput[index * 4] == rgbInput[index * 3] &&
347                     rgbaOutput[index * 4 + 1] == rgbInput[index * 3 + 1] &&
348                     rgbaOutput[index * 4 + 2] == rgbInput[index * 3 + 2] &&
349                     rgbaOutput[index * 4 + 3] == static_cast<int8_t>(kFourthValue))
350             << "Mismatch at pixel " << index;
351     }
352 }
353 
354 // Tests the sbyte (0x01) RGB to RGBA loading function for 4 RGB pixels, which should be read
355 // together.
TEST(LoadToNative3To4,LoadSbyteRGBToRGBADataFourPixelsWithFourthCompOf01)356 TEST(LoadToNative3To4, LoadSbyteRGBToRGBADataFourPixelsWithFourthCompOf01)
357 {
358     ImageLoadContext context;
359     constexpr uint8_t kPixelCount = 4;
360     std::vector<int8_t> rgbInput(kPixelCount * 3);
361     std::vector<int8_t> rgbaOutput(kPixelCount * 4, 0);
362     size_t index = 0;
363     for (auto &inputComponent : rgbInput)
364     {
365         inputComponent = ++index;
366     }
367     constexpr uint8_t kFourthValue = 0x01;
368 
369     LoadToNative3To4<int8_t, kFourthValue>(context, 4, 1, 1,
370                                            reinterpret_cast<uint8_t *>(rgbInput.data()), 3, 3,
371                                            reinterpret_cast<uint8_t *>(rgbaOutput.data()), 4, 4);
372 
373     for (index = 0; index < kPixelCount; index++)
374     {
375         EXPECT_TRUE(rgbaOutput[index * 4] == rgbInput[index * 3] &&
376                     rgbaOutput[index * 4 + 1] == rgbInput[index * 3 + 1] &&
377                     rgbaOutput[index * 4 + 2] == rgbInput[index * 3 + 2] &&
378                     rgbaOutput[index * 4 + 3] == static_cast<int8_t>(kFourthValue))
379             << "Mismatch at pixel " << index;
380     }
381 }
382 
383 // Tests the byte RGB to RGBA loading function when the width is 4-byte aligned. This loading
384 // function can copy 4 bytes at a time in a row.
TEST(LoadToNative3To4,LoadByteRGBToRGBADataAlignedWidth)385 TEST(LoadToNative3To4, LoadByteRGBToRGBADataAlignedWidth)
386 {
387     ImageLoadContext context;
388     size_t alignedTestWidths[] = {4, 20, 128, 1000, 4096};
389     for (auto &width : alignedTestWidths)
390     {
391         ASSERT(width % 4 == 0);
392         TestLoadByteRGBToRGBAForAllCases(context, width, width, 3, 1, 0, 0, 1);
393     }
394 }
395 
396 // Tests the byte RGB to RGBA loading function when the width is not 4-byte aligned, which will
397 // cause the loading function to copy some bytes in the beginning and end of some rows individually.
TEST(LoadToNative3To4,LoadByteRGBToRGBADataUnalignedWidth)398 TEST(LoadToNative3To4, LoadByteRGBToRGBADataUnalignedWidth)
399 {
400     ImageLoadContext context;
401     size_t unalignedTestWidths[] = {5, 22, 127, 1022, 4097};
402     for (auto &width : unalignedTestWidths)
403     {
404         ASSERT(width % 4 != 0);
405         TestLoadByteRGBToRGBAForAllCases(context, width, width, 3, 1, 0, 0, 1);
406     }
407 }
408 
409 // Tests the byte RGB to RGBA loading function when there is depth.
TEST(LoadToNative3To4,LoadByteRGBToRGBADataWithDepth)410 TEST(LoadToNative3To4, LoadByteRGBToRGBADataWithDepth)
411 {
412     ImageLoadContext context;
413     size_t unalignedTestDepths[] = {3};
414     for (auto &depth : unalignedTestDepths)
415     {
416         TestLoadByteRGBToRGBAForAllCases(context, depth, 3, 3, depth, 0, 0, 1);
417     }
418 }
419 
420 // Tests the byte RGB to RGBA loading function when the width is less than 4 bytes. Therefore the
421 // loading function will copy data one byte at a time.
TEST(LoadToNative3To4,LoadByteRGBToRGBADataWidthLessThanUint32)422 TEST(LoadToNative3To4, LoadByteRGBToRGBADataWidthLessThanUint32)
423 {
424     ImageLoadContext context;
425     size_t smallTestWidths[] = {1, 2, 3};
426     for (auto &width : smallTestWidths)
427     {
428         TestLoadByteRGBToRGBAForAllCases(context, width, width, 3, 1, 0, 0, 1);
429     }
430 }
431 
432 // Tests the byte RGB to RGBA loading function when when the width is 4-byte-aligned and the input
433 // address has an offset.
TEST(LoadToNative3To4,LoadByteRGBToRGBAWithAlignedWidthAndInputAddressOffset)434 TEST(LoadToNative3To4, LoadByteRGBToRGBAWithAlignedWidthAndInputAddressOffset)
435 {
436     ImageLoadContext context;
437     size_t inputOffsetList[] = {1, 2, 3};
438     for (auto &inputOffset : inputOffsetList)
439     {
440         TestLoadByteRGBToRGBAForAllCases(context, inputOffset, 8, 8, 1, inputOffset, 0, 1);
441     }
442 }
443 
444 // Tests the byte RGB to RGBA loading function when when the width is not 4-byte-aligned and the
445 // input address has an offset.
TEST(LoadToNative3To4,LoadByteRGBToRGBAWithUnalignedWidthAndInputAddressOffset)446 TEST(LoadToNative3To4, LoadByteRGBToRGBAWithUnalignedWidthAndInputAddressOffset)
447 {
448     ImageLoadContext context;
449     size_t inputOffsetList[] = {1, 2, 3};
450     for (auto &inputOffset : inputOffsetList)
451     {
452         TestLoadByteRGBToRGBAForAllCases(context, inputOffset, 7, 7, 1, inputOffset, 0, 1);
453     }
454 }
455 
456 // Tests the byte RGB to RGBA loading function when the width is 4-byte-aligned and the output
457 // address has an offset.
TEST(LoadToNative3To4,LoadByteRGBToRGBAWithAlignedWidthAndOutputAddressOffset)458 TEST(LoadToNative3To4, LoadByteRGBToRGBAWithAlignedWidthAndOutputAddressOffset)
459 {
460     ImageLoadContext context;
461     size_t outputOffsetList[] = {1, 2, 3};
462     for (auto &outputOffset : outputOffsetList)
463     {
464         TestLoadByteRGBToRGBAForAllCases(context, outputOffset, 8, 8, 1, 0, outputOffset, 1);
465     }
466 }
467 
468 // Tests the byte RGB to RGBA loading function when the width is not 4-byte-aligned and the output
469 // address has an offset.
TEST(LoadToNative3To4,LoadByteRGBToRGBAWithUnalignedWidthAndOutputAddressOffset)470 TEST(LoadToNative3To4, LoadByteRGBToRGBAWithUnalignedWidthAndOutputAddressOffset)
471 {
472     ImageLoadContext context;
473     size_t outputOffsetList[] = {1, 2, 3};
474     for (auto &outputOffset : outputOffsetList)
475     {
476         TestLoadByteRGBToRGBAForAllCases(context, outputOffset, 7, 7, 1, 0, outputOffset, 1);
477     }
478 }
479 
480 // Tests the byte RGB to RGBA loading function when the width is 4-byte-aligned and the input row
481 // alignment is 4.
TEST(LoadToNative3To4,LoadByteRGBToRGBAWithAlignedWidthAndAlignment4)482 TEST(LoadToNative3To4, LoadByteRGBToRGBAWithAlignedWidthAndAlignment4)
483 {
484     ImageLoadContext context;
485     size_t inputRowAlignmentList[] = {4};
486     for (auto &alignment : inputRowAlignmentList)
487     {
488         TestLoadByteRGBToRGBAForAllCases(context, alignment, 4, 4, 1, 0, 0, alignment);
489     }
490 }
491 
492 // Tests the byte RGB to RGBA loading function when the width is not 4-byte-aligned and the input
493 // row alignment is 4.
TEST(LoadToNative3To4,LoadByteRGBToRGBAWithUnalignedWidthAndAlignment4)494 TEST(LoadToNative3To4, LoadByteRGBToRGBAWithUnalignedWidthAndAlignment4)
495 {
496     ImageLoadContext context;
497     size_t inputRowAlignmentList[] = {4};
498     for (auto &alignment : inputRowAlignmentList)
499     {
500         TestLoadByteRGBToRGBAForAllCases(context, alignment, 5, 5, 1, 0, 0, alignment);
501     }
502 }
503 }  // namespace