1 /*
2  * Copyright (C) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include <fstream>
18 #include <fcntl.h>
19 #include <string>
20 #include <chrono>
21 #include "buffer_packer_stream.h"
22 #include "color_space.h"
23 #include "image_type.h"
24 #include "image_utils.h"
25 #include "image_source.h"
26 #include "image_source_util.h"
27 #include "media_errors.h"
28 #include "pixel_map.h"
29 #include "pixel_yuv.h"
30 
31 using namespace testing::ext;
32 using namespace OHOS::Media;
33 using namespace OHOS::ImageSourceUtil;
34 
35 namespace OHOS {
36 namespace Multimedia {
37 static const std::string IMAGE_INPUT_JPG_PATH = "/data/local/tmp/image/";
38 static const std::string IMAGE_OUTPUT_JPG_PATH = "/data/local/tmp/";
39 static const std::string IMAGE_INPUT_YUV_PATH3 = "/data/local/tmp/image/P010.yuv";
40 static const std::string IMAGE_INPUT_YUV_PATH4 = "/data/local/tmp/image/RGBA1010102.rgba";
41 static constexpr uint32_t MAXSIZE = 10000;
42 #define TREE_ORIGINAL_WIDTH 480
43 #define TREE_ORIGINAL_HEIGHT 360
44 #define ODDTREE_ORIGINAL_WIDTH 481
45 #define ODDTREE_ORIGINAL_HEIGHT 361
46 #define P101TREE_ORIGINAL_WIDTH 1920
47 #define P101TREE_ORIGINAL_HEIGHT 1080
48 static const uint8_t NUM_2 = 2;
49 static const uint8_t NUM_3 = 3;
50 static const uint8_t NUM_4 = 4;
51 
52 struct ImageSize {
53     int32_t width = 0;
54     int32_t height = 0;
55     float dstWidth = 0;
56     float dstHeight = 0;
57     const uint32_t color = 0;
58     uint32_t dst = 0;
59 };
60 
61 struct Coordinate {
62     float xAxis = 0;
63     float yAxis = 0;
64 };
65 
66 class JpgYuvTest : public testing::Test {
67 public:
JpgYuvTest()68     JpgYuvTest() {}
~JpgYuvTest()69     ~JpgYuvTest() {}
70 
71     void TestDecodeToSize(int width, int height);
72     uint64_t GetNowTimeMicroSeconds();
73     void DoTimeTest(std::string jpgname);
74     bool ReadFile(void *chOrg, std::string path, int32_t totalsize, int32_t srcNum);
75     void DecodeToFormat(std::string srcjpg, PixelFormat outfmt, int width, int height);
76     void DecodeToYuv(std::string srcjpg, PixelFormat outfmt, std::string outname, int &width, int &height);
77     void YuvWriteToFile(std::string outpath, ImageSize &imageSize, std::string outname, uint8_t *data, uint32_t &size);
78     void YuvCrop(std::string srcjpg, PixelFormat outfmt, std::string outname, ImageSize &imageSize);
79     void YuvP010Crop(PixelFormat outfmt, std::string outname, ImageSize &imageSize);
80     void YuvRotate(std::string srcjpg, PixelFormat outfmt, std::string outname, ImageSize &imageSize, float degrees);
81     void YuvP010Rotate(PixelFormat outfmt, std::string outname, ImageSize &imageSize, float degrees);
82     void YuvWriteConvert(std::string srcjpg, PixelFormat outfmt, std::string outname, ImageSize &imageSize);
83     void ScaleYuv420(std::string &srcjpg, PixelFormat outfmt, std::string &outname,
84         ImageSize &imageSize, AntiAliasingOption option);
85     void ScaleYuv420P010(PixelFormat outfmt, std::string &outname, ImageSize &imageSize, AntiAliasingOption option);
86     void ResizeYuv420(std::string &srcjpg, PixelFormat outfmt, std::string &outname, ImageSize &imageSize);
87     void ResizeYuv420P010(PixelFormat outfmt, std::string &outname, ImageSize &imageSize);
88     void GetFlipAxis(size_t i, bool &xAxis, bool &yAxis);
89     void FlipYuv420(std::string &srcjpg, PixelFormat outfmt, std::string &outname,
90         ImageSize &imageSize, size_t i);
91     void FlipYuv420P010(PixelFormat outfmt, std::string &outname, ImageSize &imageSize, size_t i);
92     void ApplyColorSpaceYuv420(std::string &srcjpg, PixelFormat outfmt, std::string &outname,
93         ImageSize &imageSize, const OHOS::ColorManager::ColorSpace &grColorSpace);
94     void TranslateYuv420(std::string &srcjpg, PixelFormat outfmt, std::string &outname,
95         ImageSize &imageSize, Coordinate &coordinate);
96     void TranslateYuv420P010(PixelFormat outfmt, std::string &outname,
97         ImageSize &imageSize, Coordinate &coordinate);
98     void ReadYuv420(std::string &srcjpg, PixelFormat outfmt, std::string &outname,
99         Position &pos, ImageSize &imageSize);
100     void WriteYuv420(std::string &srcjpg, PixelFormat outfmt, std::string &outname,
101         Position &pos, ImageSize &imageSize);
102     void WritesYuv420(std::string &srcjpg, PixelFormat outfmt, std::string &outname, ImageSize &imageSize);
103     void RGBA1010102Crop(PixelFormat outfmt, std::string outname, ImageSize &imageSize);
104     void RGBA1010102Rotate(PixelFormat outfmt, std::string outname, ImageSize &imageSize, float degrees);
105     void RGBA1010102Scale(PixelFormat outfmt, std::string &outname, ImageSize &imageSize, AntiAliasingOption option);
106     void RGBA1010102Resize(PixelFormat outfmt, std::string &outname, ImageSize &imageSize);
107     void RGBA1010102Flip(PixelFormat outfmt, std::string &outname, ImageSize &imageSize, size_t size);
108     void RGBA1010102Translate(PixelFormat outfmt, std::string &outname, ImageSize &imageSize, Coordinate &coordinate);
109 };
110 
TestDecodeToSize(int width,int height)111 void JpgYuvTest::TestDecodeToSize(int width, int height)
112 {
113     const char* srcjpg[] = { "test-tree-444.jpg", "test-tree-422.jpg", "test-tree-420.jpg",
114         "test-tree-400.jpg", "test-tree-440.jpg", "test-tree-411.jpg"};
115     const char* outNamePart1[] = { "tree-444", "tree-422", "tree-420", "tree-400", "tree-440", "tree-411"};
116     const char* outNamePart2[] = { "-nv12.yuv", "-nv21.yuv"};
117     PixelFormat outfmt[] = { PixelFormat::NV12, PixelFormat::NV21};
118     for (uint32_t k = 0; k < sizeof(srcjpg) / sizeof(char*); k++) {
119         for (uint32_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
120             std::string jpgpath = IMAGE_INPUT_JPG_PATH;
121             jpgpath.append(srcjpg[k]);
122             std::string outname;
123             outname.append(outNamePart1[k]);
124             outname.append(outNamePart2[j]);
125             int outWidth = width;
126             int outHeight = height;
127             DecodeToYuv(jpgpath, outfmt[j], outname, outWidth, outHeight);
128         }
129     }
130 }
131 
GetNowTimeMicroSeconds()132 uint64_t JpgYuvTest::GetNowTimeMicroSeconds()
133 {
134     auto now = std::chrono::system_clock::now();
135     return std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
136 }
137 
DecodeToFormat(std::string srcjpg,PixelFormat outfmt,int width,int height)138 void JpgYuvTest::DecodeToFormat(std::string srcjpg, PixelFormat outfmt, int width, int height)
139 {
140     uint32_t errorCode = 0;
141     SourceOptions opts;
142     opts.formatHint = "image/jpeg";
143     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(srcjpg, opts, errorCode);
144     ASSERT_EQ(errorCode, SUCCESS);
145     ASSERT_NE(imageSource.get(), nullptr);
146     DecodeOptions decodeOpts;
147     decodeOpts.desiredPixelFormat = outfmt;
148     decodeOpts.desiredSize.width = width;
149     decodeOpts.desiredSize.height = height;
150     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
151     ASSERT_EQ(errorCode, SUCCESS);
152     ASSERT_NE(pixelMap.get(), nullptr);
153     ASSERT_EQ(pixelMap->GetPixelFormat(), outfmt);
154 }
155 
DoTimeTest(std::string jpgname)156 void JpgYuvTest::DoTimeTest(std::string jpgname)
157 {
158     const int testCount = 100;
159     for (uint32_t k = 0; k < testCount; k++) {
160         std::string jpgpath = IMAGE_INPUT_JPG_PATH;
161         jpgpath.append(jpgname);
162         DecodeToFormat(jpgpath, PixelFormat::RGBA_8888, 0, 0);
163     }
164 
165     for (uint32_t k = 0; k < testCount; k++) {
166         std::string jpgpath = IMAGE_INPUT_JPG_PATH;
167         jpgpath.append(jpgname);
168         DecodeToFormat(jpgpath, PixelFormat::NV12, 0, 0);
169     }
170 }
171 
DecodeToYuv(std::string srcjpg,PixelFormat outfmt,std::string outname,int & width,int & height)172 void JpgYuvTest::DecodeToYuv(std::string srcjpg, PixelFormat outfmt, std::string outname, int& width, int& height)
173 {
174     uint32_t errorCode = 0;
175     SourceOptions opts;
176     opts.formatHint = "image/jpeg";
177     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(srcjpg, opts, errorCode);
178     ASSERT_EQ(errorCode, SUCCESS);
179     ASSERT_NE(imageSource.get(), nullptr);
180 
181     DecodeOptions decodeOpts;
182     decodeOpts.desiredPixelFormat = outfmt;
183     decodeOpts.desiredSize.width = width;
184     decodeOpts.desiredSize.height = height;
185     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
186     ASSERT_EQ(errorCode, SUCCESS);
187     ASSERT_NE(pixelMap.get(), nullptr);
188     uint8_t *data = const_cast<uint8_t *>(pixelMap->GetPixels());
189     const uint8_t *buffer = nullptr;
190     uint32_t size = pixelMap->GetCapacity();
191     uint32_t maxSize = MAXSIZE;
192     BufferPackerStream bufferPackerStream(data, maxSize);
193     bool ret = bufferPackerStream.Write(buffer, size);
194     ASSERT_EQ(pixelMap->GetPixelFormat(), outfmt);
195     ASSERT_EQ(ret, false);
196     width = pixelMap->GetWidth();
197     height = pixelMap->GetHeight();
198     std::string outpath = "/tmp/";
199     outpath.append(std::to_string(width));
200     outpath.append("-");
201     outpath.append(std::to_string(height));
202     outpath.append("-");
203     outpath.append(outname);
204     FILE* outfile = fopen(outpath.c_str(), "wb");
205     if (outfile) {
206         fwrite(data, 1, size, outfile);
207         int fret = fclose(outfile);
208         if (fret != 0) {
209             ASSERT_TRUE(false);
210         }
211     }
212 }
213 
YuvWriteToFile(std::string outpath,ImageSize & imageSize,std::string outname,uint8_t * data,uint32_t & size)214 void JpgYuvTest::YuvWriteToFile(std::string outpath, ImageSize &imageSize, std::string outname,
215     uint8_t *data, uint32_t &size)
216 {
217     std::filesystem::path dir(outpath);
218     std::filesystem::create_directory(dir);
219     outpath.append(std::to_string(imageSize.width));
220     outpath.append("-");
221     outpath.append(std::to_string(imageSize.height));
222     outpath.append("-");
223     outpath.append(outname);
224     FILE *outfile = fopen(outpath.c_str(), "wb");
225     if (outfile) {
226         fwrite(data, 1, size, outfile);
227         int32_t fret = fclose(outfile);
228         if (fret != 0) {
229             ASSERT_TRUE(false);
230         }
231     }
232 }
233 
YuvRotate(std::string srcjpg,PixelFormat outfmt,std::string outname,ImageSize & imageSize,float degrees)234 void JpgYuvTest::YuvRotate(std::string srcjpg, PixelFormat outfmt, std::string outname,
235     ImageSize &imageSize, float degrees)
236 {
237     uint32_t errorCode = 0;
238     SourceOptions opts;
239     opts.formatHint = "image/jpeg";
240     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(srcjpg, opts, errorCode);
241     ASSERT_EQ(errorCode, SUCCESS);
242     ASSERT_NE(imageSource.get(), nullptr);
243     DecodeOptions decodeOpts;
244     decodeOpts.desiredPixelFormat = outfmt;
245     decodeOpts.desiredSize.width = imageSize.width;
246     decodeOpts.desiredSize.height = imageSize.height;
247     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
248     ASSERT_EQ(errorCode, SUCCESS);
249     ASSERT_NE(pixelMap.get(), nullptr);
250 
251     pixelMap->rotate(degrees);
252 
253     uint8_t *data = const_cast<uint8_t *>(pixelMap->GetPixels());
254     const uint8_t *buffer = nullptr;
255     uint32_t size = pixelMap->GetWidth() * pixelMap->GetHeight() + ((pixelMap->GetWidth() + 1) / NUM_2) *
256         ((pixelMap->GetHeight() + 1) / NUM_2) * NUM_2;
257     uint32_t maxSize = MAXSIZE;
258     BufferPackerStream bufferPackerStream(data, maxSize);
259     bool ret = bufferPackerStream.Write(buffer, size);
260     ASSERT_EQ(pixelMap->GetPixelFormat(), outfmt);
261     ASSERT_EQ(ret, false);
262     imageSize.width = pixelMap->GetWidth();
263     imageSize.height = pixelMap->GetHeight();
264     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "YuvRotate/";
265     YuvWriteToFile(outpath, imageSize, outname, data, size);
266 }
267 
YuvCrop(std::string srcjpg,PixelFormat outfmt,std::string outname,ImageSize & imageSize)268 void JpgYuvTest::YuvCrop(std::string srcjpg, PixelFormat outfmt, std::string outname, ImageSize &imageSize)
269 {
270     uint32_t errorCode = 0;
271     SourceOptions opts;
272     opts.formatHint = "image/jpeg";
273     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(srcjpg, opts, errorCode);
274     ASSERT_EQ(errorCode, SUCCESS);
275     ASSERT_NE(imageSource.get(), nullptr);
276     DecodeOptions decodeOpts;
277     decodeOpts.desiredPixelFormat = outfmt;
278     decodeOpts.desiredSize.width = imageSize.width;
279     decodeOpts.desiredSize.height = imageSize.height;
280     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
281     ASSERT_EQ(errorCode, SUCCESS);
282     ASSERT_NE(pixelMap.get(), nullptr);
283     Rect rect = {0, 0, 100, 100};
284     ASSERT_EQ(pixelMap->GetPixelFormat(), outfmt);
285     ASSERT_EQ(pixelMap->crop(rect), SUCCESS);
286     ASSERT_EQ(pixelMap->GetPixelFormat(), outfmt);
287 
288     uint8_t *data = const_cast<uint8_t *>(pixelMap->GetPixels());
289     const uint8_t *buffer = nullptr;
290     uint32_t size = pixelMap->GetWidth() * pixelMap->GetHeight() + ((pixelMap->GetWidth() + 1) / NUM_2) *
291         ((pixelMap->GetHeight() + 1) / NUM_2) * NUM_2;
292     uint32_t maxSize = MAXSIZE;
293     BufferPackerStream bufferPackerStream(data, maxSize);
294     bool ret = bufferPackerStream.Write(buffer, size);
295     ASSERT_EQ(pixelMap->GetPixelFormat(), outfmt);
296     ASSERT_EQ(ret, false);
297     imageSize.width = pixelMap->GetWidth();
298     imageSize.height = pixelMap->GetHeight();
299     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "YuvCrop/";
300     YuvWriteToFile(outpath, imageSize, outname, data, size);
301 }
302 
YuvWriteConvert(std::string srcjpg,PixelFormat outfmt,std::string outname,ImageSize & imageSize)303 void JpgYuvTest::YuvWriteConvert(std::string srcjpg, PixelFormat outfmt, std::string outname, ImageSize &imageSize)
304 {
305     uint32_t errorCode = 0;
306     SourceOptions opts;
307     opts.formatHint = "image/jpeg";
308     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(srcjpg, opts, errorCode);
309     ASSERT_EQ(errorCode, SUCCESS);
310     ASSERT_NE(imageSource.get(), nullptr);
311     DecodeOptions decodeOpts;
312     decodeOpts.editable = true;
313     decodeOpts.desiredPixelFormat = outfmt;
314     decodeOpts.desiredSize.width = imageSize.width;
315     decodeOpts.desiredSize.height = imageSize.height;
316     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
317     ASSERT_EQ(errorCode, SUCCESS);
318     ASSERT_NE(pixelMap.get(), nullptr);
319 
320     ASSERT_EQ(pixelMap->GetPixelFormat(), outfmt);
321     Rect region = {10, 10, 100, 100}; // The size of the crop
322     size_t bufferSize = (region.width * region.height + ((region.width + 1) / NUM_2) *
323         ((region.height + 1) / NUM_2) * NUM_2);
324     std::unique_ptr<uint8_t[]> dst = std::make_unique<uint8_t[]>(bufferSize);
325     int stride = static_cast<uint32_t>(region.width) * NUM_3 / NUM_2;
326     ASSERT_EQ(pixelMap->ReadPixels(bufferSize, 0, stride, region, dst.get()), SUCCESS);
327 
328     Rect rect = {50, 50, 100, 100}; // The location and size of the write
329     stride = static_cast<uint32_t>(rect.width) * NUM_3 / NUM_2;
330     ASSERT_EQ(pixelMap->WritePixels(dst.get(), bufferSize, 0, stride, rect), SUCCESS);
331     ASSERT_EQ(pixelMap->GetPixelFormat(), outfmt);
332 
333     uint8_t *data = const_cast<uint8_t *>(pixelMap->GetPixels());
334     const uint8_t *buffer = nullptr;
335     uint32_t size = pixelMap->GetWidth() * pixelMap->GetHeight() + ((pixelMap->GetWidth() + 1) / NUM_2) *
336         ((pixelMap->GetHeight() + 1) / NUM_2) * NUM_2;
337     uint32_t maxSize = MAXSIZE;
338     BufferPackerStream bufferPackerStream(data, maxSize);
339     bool ret = bufferPackerStream.Write(buffer, size);
340     ASSERT_EQ(pixelMap->GetPixelFormat(), outfmt);
341     ASSERT_EQ(ret, false);
342     imageSize.width = pixelMap->GetWidth();
343     imageSize.height = pixelMap->GetHeight();
344     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "WriteConvert/";
345     YuvWriteToFile(outpath, imageSize, outname, data, size);
346 }
347 
ScaleYuv420(std::string & srcjpg,PixelFormat outfmt,std::string & outname,ImageSize & imageSize,AntiAliasingOption option)348 void JpgYuvTest::ScaleYuv420(std::string &srcjpg, PixelFormat outfmt, std::string &outname,
349     ImageSize &imageSize, AntiAliasingOption option)
350 {
351     uint32_t errorCode = 0;
352     SourceOptions opts;
353     opts.formatHint = "image/jpeg";
354     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(srcjpg, opts, errorCode);
355     ASSERT_EQ(errorCode, SUCCESS);
356     ASSERT_NE(imageSource.get(), nullptr);
357     DecodeOptions decodeOpts;
358     decodeOpts.desiredPixelFormat = outfmt;
359     decodeOpts.desiredSize.width = imageSize.width;
360     decodeOpts.desiredSize.height = imageSize.height;
361     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
362     ASSERT_EQ(errorCode, SUCCESS);
363     ASSERT_NE(pixelMap.get(), nullptr);
364 
365     pixelMap->scale(imageSize.dstWidth, imageSize.dstHeight, option);
366 
367     uint8_t *data = const_cast<uint8_t *>(pixelMap->GetPixels());
368     const uint8_t *buffer = nullptr;
369     uint32_t size = pixelMap->GetCapacity();
370     uint32_t maxSize = MAXSIZE;
371     BufferPackerStream bufferPackerStream(data, maxSize);
372     bool ret = bufferPackerStream.Write(buffer, size);
373     ASSERT_EQ(pixelMap->GetPixelFormat(), outfmt);
374     ASSERT_EQ(ret, false);
375     imageSize.width = pixelMap->GetWidth();
376     imageSize.height = pixelMap->GetHeight();
377     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "scale/";
378     YuvWriteToFile(outpath, imageSize, outname, data, size);
379 }
380 
ResizeYuv420(std::string & srcjpg,PixelFormat outfmt,std::string & outname,ImageSize & imageSize)381 void JpgYuvTest::ResizeYuv420(std::string &srcjpg, PixelFormat outfmt, std::string &outname, ImageSize &imageSize)
382 {
383     uint32_t errorCode = 0;
384     SourceOptions opts;
385     opts.formatHint = "image/jpeg";
386     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(srcjpg, opts, errorCode);
387     ASSERT_EQ(errorCode, SUCCESS);
388     ASSERT_NE(imageSource.get(), nullptr);
389     DecodeOptions decodeOpts;
390     decodeOpts.desiredPixelFormat = outfmt;
391     decodeOpts.desiredSize.width = imageSize.width;
392     decodeOpts.desiredSize.height = imageSize.height;
393     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
394     ASSERT_EQ(errorCode, SUCCESS);
395     ASSERT_NE(pixelMap.get(), nullptr);
396 
397     pixelMap->resize(imageSize.dstWidth, imageSize.dstHeight);
398 
399     uint8_t *data = const_cast<uint8_t *>(pixelMap->GetPixels());
400     const uint8_t *buffer = nullptr;
401     uint32_t size = pixelMap->GetCapacity();
402     uint32_t maxSize = MAXSIZE;
403     BufferPackerStream bufferPackerStream(data, maxSize);
404     bool ret = bufferPackerStream.Write(buffer, size);
405     ASSERT_EQ(pixelMap->GetPixelFormat(), outfmt);
406     ASSERT_EQ(ret, false);
407     imageSize.width = pixelMap->GetWidth();
408     imageSize.height = pixelMap->GetHeight();
409     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "resize/";
410     YuvWriteToFile(outpath, imageSize, outname, data, size);
411 }
412 
GetFlipAxis(size_t i,bool & xAxis,bool & yAxis)413 void JpgYuvTest::GetFlipAxis(size_t i, bool &xAxis, bool &yAxis)
414 {
415     if (i & 1) {
416         yAxis = false;
417     } else {
418         yAxis = true;
419     }
420     if ((i >> 1) & 1) {
421         xAxis = false;
422     } else {
423         xAxis = true;
424     }
425 }
426 
FlipYuv420(std::string & srcjpg,PixelFormat outfmt,std::string & outname,ImageSize & imageSize,size_t i)427 void JpgYuvTest::FlipYuv420(std::string &srcjpg, PixelFormat outfmt, std::string &outname,
428     ImageSize &imageSize, size_t i)
429 {
430     uint32_t errorCode = 0;
431     SourceOptions opts;
432     opts.formatHint = "image/jpeg";
433     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(srcjpg, opts, errorCode);
434     ASSERT_EQ(errorCode, SUCCESS);
435     ASSERT_NE(imageSource.get(), nullptr);
436     DecodeOptions decodeOpts;
437     decodeOpts.desiredPixelFormat = outfmt;
438     decodeOpts.desiredSize.width = imageSize.width;
439     decodeOpts.desiredSize.height = imageSize.height;
440     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
441     ASSERT_EQ(errorCode, SUCCESS);
442     ASSERT_NE(pixelMap.get(), nullptr);
443 
444     bool xAxis;
445     bool yAxis;
446     GetFlipAxis(i, xAxis, yAxis);
447     pixelMap->flip(xAxis, yAxis);
448 
449     uint8_t *data = const_cast<uint8_t *>(pixelMap->GetPixels());
450     const uint8_t *buffer = nullptr;
451     uint32_t size = pixelMap->GetCapacity();
452     uint32_t maxSize = MAXSIZE;
453     BufferPackerStream bufferPackerStream(data, maxSize);
454     bool ret = bufferPackerStream.Write(buffer, size);
455     ASSERT_EQ(pixelMap->GetPixelFormat(), outfmt);
456     ASSERT_EQ(ret, false);
457     imageSize.width = pixelMap->GetWidth();
458     imageSize.height = pixelMap->GetHeight();
459     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "flip/";
460     YuvWriteToFile(outpath, imageSize, outname, data, size);
461 }
462 
TranslateYuv420(std::string & srcjpg,PixelFormat outfmt,std::string & outname,ImageSize & imageSize,Coordinate & coordinate)463 void JpgYuvTest::TranslateYuv420(std::string &srcjpg, PixelFormat outfmt, std::string &outname,
464     ImageSize &imageSize, Coordinate &coordinate)
465 {
466     uint32_t errorCode = 0;
467     SourceOptions opts;
468     opts.formatHint = "image/jpeg";
469     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(srcjpg, opts, errorCode);
470     ASSERT_EQ(errorCode, SUCCESS);
471     ASSERT_NE(imageSource.get(), nullptr);
472     DecodeOptions decodeOpts;
473     decodeOpts.desiredPixelFormat = outfmt;
474     decodeOpts.desiredSize.width = imageSize.width;
475     decodeOpts.desiredSize.height = imageSize.height;
476     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
477     ASSERT_EQ(errorCode, SUCCESS);
478     ASSERT_NE(pixelMap.get(), nullptr);
479 
480     pixelMap->translate(coordinate.xAxis, coordinate.yAxis);
481 
482     uint8_t *data = const_cast<uint8_t *>(pixelMap->GetPixels());
483     const uint8_t *buffer = nullptr;
484     uint32_t size = pixelMap->GetCapacity();
485     uint32_t maxSize = MAXSIZE;
486     BufferPackerStream bufferPackerStream(data, maxSize);
487     bool ret = bufferPackerStream.Write(buffer, size);
488     ASSERT_EQ(pixelMap->GetPixelFormat(), outfmt);
489     ASSERT_EQ(ret, false);
490     imageSize.width = pixelMap->GetWidth();
491     imageSize.height = pixelMap->GetHeight();
492     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "translate/";
493     YuvWriteToFile(outpath, imageSize, outname, data, size);
494 }
495 
ReadYuv420(std::string & srcjpg,PixelFormat outfmt,std::string & outname,Position & pos,ImageSize & imageSize)496 void JpgYuvTest::ReadYuv420(std::string &srcjpg, PixelFormat outfmt, std::string &outname,
497     Position &pos, ImageSize &imageSize)
498 {
499     uint32_t errorCode = 0;
500     SourceOptions opts;
501     opts.formatHint = "image/jpeg";
502     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(srcjpg, opts, errorCode);
503     ASSERT_EQ(errorCode, SUCCESS);
504     ASSERT_NE(imageSource.get(), nullptr);
505     DecodeOptions decodeOpts;
506     decodeOpts.desiredPixelFormat = outfmt;
507     decodeOpts.desiredSize.width = imageSize.width;
508     decodeOpts.desiredSize.height = imageSize.height;
509     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
510     ASSERT_EQ(errorCode, SUCCESS);
511     ASSERT_NE(pixelMap.get(), nullptr);
512 
513     pixelMap->ReadPixel(pos, imageSize.dst);
514 
515     uint8_t *data = const_cast<uint8_t *>(pixelMap->GetPixels());
516     const uint8_t *buffer = nullptr;
517     uint32_t size = pixelMap->GetCapacity();
518     uint32_t maxSize = MAXSIZE;
519     BufferPackerStream bufferPackerStream(data, maxSize);
520     bool ret = bufferPackerStream.Write(buffer, size);
521     ASSERT_EQ(pixelMap->GetPixelFormat(), outfmt);
522     ASSERT_EQ(ret, false);
523     imageSize.width = pixelMap->GetWidth();
524     imageSize.height = pixelMap->GetHeight();
525     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "read/";
526     YuvWriteToFile(outpath, imageSize, outname, data, size);
527 }
528 
WriteYuv420(std::string & srcjpg,PixelFormat outfmt,std::string & outname,Position & pos,ImageSize & imageSize)529 void JpgYuvTest::WriteYuv420(std::string &srcjpg, PixelFormat outfmt, std::string &outname,
530     Position &pos, ImageSize &imageSize)
531 {
532     uint32_t errorCode = 0;
533     SourceOptions opts;
534     opts.formatHint = "image/jpeg";
535     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(srcjpg, opts, errorCode);
536     ASSERT_EQ(errorCode, SUCCESS);
537     ASSERT_NE(imageSource.get(), nullptr);
538     DecodeOptions decodeOpts;
539     decodeOpts.desiredPixelFormat = outfmt;
540     decodeOpts.desiredSize.width = imageSize.width;
541     decodeOpts.desiredSize.height = imageSize.height;
542     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
543     ASSERT_EQ(errorCode, SUCCESS);
544     ASSERT_NE(pixelMap.get(), nullptr);
545 
546     pixelMap->WritePixel(pos, imageSize.color);
547 
548     pixelMap->ReadPixel(pos, imageSize.dst);
549 
550     uint8_t *data = const_cast<uint8_t *>(pixelMap->GetPixels());
551     const uint8_t *buffer = nullptr;
552     uint32_t size = pixelMap->GetCapacity();
553     uint32_t maxSize = MAXSIZE;
554     BufferPackerStream bufferPackerStream(data, maxSize);
555     bool ret = bufferPackerStream.Write(buffer, size);
556     ASSERT_EQ(pixelMap->GetPixelFormat(), outfmt);
557     ASSERT_EQ(ret, false);
558     imageSize.width = pixelMap->GetWidth();
559     imageSize.height = pixelMap->GetHeight();
560     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "write/";
561     YuvWriteToFile(outpath, imageSize, outname, data, size);
562 }
563 
WritesYuv420(std::string & srcjpg,PixelFormat outfmt,std::string & outname,ImageSize & imageSize)564 void JpgYuvTest::WritesYuv420(std::string &srcjpg, PixelFormat outfmt, std::string &outname, ImageSize &imageSize)
565 {
566     uint32_t errorCode = 0;
567     SourceOptions opts;
568     opts.formatHint = "image/jpeg";
569     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(srcjpg, opts, errorCode);
570     ASSERT_EQ(errorCode, SUCCESS);
571     ASSERT_NE(imageSource.get(), nullptr);
572     DecodeOptions decodeOpts;
573     decodeOpts.desiredPixelFormat = outfmt;
574     decodeOpts.desiredSize.width = imageSize.width;
575     decodeOpts.desiredSize.height = imageSize.height;
576     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
577     ASSERT_EQ(errorCode, SUCCESS);
578     ASSERT_NE(pixelMap.get(), nullptr);
579 
580     uint32_t res = pixelMap->WritePixels(imageSize.color);
581     ASSERT_EQ(res, 1);
582 
583     uint8_t *data = const_cast<uint8_t *>(pixelMap->GetPixels());
584     const uint8_t *buffer = nullptr;
585     uint32_t size = pixelMap->GetCapacity();
586     uint32_t maxSize = MAXSIZE;
587     BufferPackerStream bufferPackerStream(data, maxSize);
588     bool ret = bufferPackerStream.Write(buffer, size);
589     ASSERT_EQ(pixelMap->GetPixelFormat(), outfmt);
590     ASSERT_EQ(ret, false);
591     imageSize.width = pixelMap->GetWidth();
592     imageSize.height = pixelMap->GetHeight();
593     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "Writes";
594     YuvWriteToFile(outpath, imageSize, outname, data, size);
595 }
596 
ReadFile(void * chOrg,std::string path,int32_t totalsize,int32_t srcNum)597 bool JpgYuvTest::ReadFile(void *chOrg, std::string path, int32_t totalsize, int32_t srcNum)
598 {
599     FILE* const fileOrg = fopen(path.c_str(), "rb");
600     if (fileOrg == nullptr) {
601         GTEST_LOG_(INFO) << "Cannot open" << path.c_str();
602         return false;
603     }
604     if (srcNum == 0) {
605         size_t bytesOrg = fread(chOrg, sizeof(uint8_t), static_cast<size_t>(totalsize), fileOrg);
606         if (bytesOrg < static_cast<size_t>(totalsize)) {
607             GTEST_LOG_(INFO) << "Read fail";
608             return false;
609         }
610     } else {
611         size_t bytesOrg = fread(chOrg, sizeof(uint16_t), static_cast<size_t>(totalsize), fileOrg);
612         if (bytesOrg < static_cast<size_t>(totalsize)) {
613             GTEST_LOG_(INFO) << "Read fail " << bytesOrg << " totalsize" << totalsize;
614             return false;
615         }
616     }
617     return true;
618 }
619 
YuvP010Crop(PixelFormat outfmt,std::string outname,ImageSize & imageSize)620 void JpgYuvTest::YuvP010Crop(PixelFormat outfmt, std::string outname, ImageSize &imageSize)
621 {
622     GTEST_LOG_(INFO) << "JpgYuvTest: request size(" << imageSize.width << ", " << imageSize.height << ")";
623     int32_t ySize = imageSize.width * imageSize.height;
624     int32_t uvSize = ((imageSize.width + 1) / 2) * ((imageSize.height + 1) / 2);
625     const size_t totalSize = (ySize + 2 * uvSize);
626     uint16_t* const chOrg = new uint16_t[totalSize];
627     bool result = ReadFile(chOrg, IMAGE_INPUT_YUV_PATH3, totalSize, 1);
628     ASSERT_EQ(result, true);
629     const uint32_t dataLength = totalSize * 2;
630     uint32_t *data = reinterpret_cast<uint32_t *>(chOrg);
631     InitializationOptions opts;
632     opts.srcPixelFormat =outfmt;
633     opts.pixelFormat = outfmt;
634     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
635     opts.size.width = imageSize.width;
636     opts.size.height = imageSize.height;
637     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(data, dataLength, opts);
638     ASSERT_NE(pixelMap.get(), nullptr);
639 
640     std::shared_ptr<PixelMap> srcPixelMap = std::move(pixelMap);
641 
642     Rect rect = {0, 0, 100, 100};
643     ASSERT_EQ(srcPixelMap->GetPixelFormat(), outfmt);
644     ASSERT_EQ(srcPixelMap->crop(rect), SUCCESS);
645 
646     uint8_t *data8 = const_cast<uint8_t *>(srcPixelMap->GetPixels());
647     const uint8_t *buffer = nullptr;
648     uint32_t size = (srcPixelMap->GetWidth() * srcPixelMap->GetHeight() + ((srcPixelMap->GetWidth() + 1) / NUM_2) *
649         ((srcPixelMap->GetHeight() + 1) / NUM_2) * NUM_2) * NUM_2;
650     uint32_t maxSize = MAXSIZE;
651     BufferPackerStream bufferPackerStream(data8, maxSize);
652     bool ret = bufferPackerStream.Write(buffer, size);
653     ASSERT_EQ(srcPixelMap->GetPixelFormat(), outfmt);
654     ASSERT_EQ(ret, false);
655     imageSize.width = srcPixelMap->GetWidth();
656     imageSize.height = srcPixelMap->GetHeight();
657     GTEST_LOG_(INFO) << "JpgYuvTest: ret size(" << imageSize.width << ", " << imageSize.height << ")";
658     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "YuvP010Crop/";
659     YuvWriteToFile(outpath, imageSize, outname, data8, size);
660 }
661 
YuvP010Rotate(PixelFormat outfmt,std::string outname,ImageSize & imageSize,float degrees)662 void JpgYuvTest::YuvP010Rotate(PixelFormat outfmt, std::string outname, ImageSize &imageSize, float degrees)
663 {
664     GTEST_LOG_(INFO) << "JpgYuvTest: request size(" << imageSize.width << ", " << imageSize.height << ")";
665     int32_t ySize = imageSize.width * imageSize.height;
666     int32_t uvSize = ((imageSize.width + 1) / 2) * ((imageSize.height + 1) / 2);
667     const size_t totalSize = (ySize + 2 * uvSize);
668     uint16_t* const chOrg = new uint16_t[totalSize];
669     bool result = ReadFile(chOrg, IMAGE_INPUT_YUV_PATH3, totalSize, 1);
670     ASSERT_EQ(result, true);
671     const uint32_t dataLength = totalSize * 2;
672     uint32_t *data = reinterpret_cast<uint32_t *>(chOrg);
673     InitializationOptions opts;
674     opts.srcPixelFormat = outfmt;
675     opts.pixelFormat = outfmt;
676     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
677     opts.size.width = imageSize.width;
678     opts.size.height = imageSize.height;
679     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(data, dataLength, opts);
680     ASSERT_NE(pixelMap.get(), nullptr);
681 
682     std::shared_ptr<PixelMap> srcPixelMap = std::move(pixelMap);
683     srcPixelMap->rotate(degrees);
684 
685     uint8_t *data8 = const_cast<uint8_t *>(srcPixelMap->GetPixels());
686     const uint8_t *buffer = nullptr;
687     uint32_t size = (srcPixelMap->GetWidth() * srcPixelMap->GetHeight() + ((srcPixelMap->GetWidth() + 1) / NUM_2) *
688         ((srcPixelMap->GetHeight() + 1) / NUM_2) * NUM_2) * NUM_2;
689     uint32_t maxSize = MAXSIZE;
690     BufferPackerStream bufferPackerStream(data8, maxSize);
691     bool ret = bufferPackerStream.Write(buffer, size);
692     ASSERT_EQ(srcPixelMap->GetPixelFormat(), outfmt);
693     ASSERT_EQ(ret, false);
694     imageSize.width = srcPixelMap->GetWidth();
695     imageSize.height = srcPixelMap->GetHeight();
696     GTEST_LOG_(INFO) << "JpgYuvTest: ret size(" << imageSize.width << ", " << imageSize.height << ")";
697     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "YuvP010Rotate/";
698     YuvWriteToFile(outpath, imageSize, outname, data8, size);
699 }
700 
ScaleYuv420P010(PixelFormat outfmt,std::string & outname,ImageSize & imageSize,AntiAliasingOption option)701 void JpgYuvTest::ScaleYuv420P010(PixelFormat outfmt, std::string &outname,
702     ImageSize &imageSize, AntiAliasingOption option)
703 {
704     GTEST_LOG_(INFO) << "JpgYuvTest: request size(" << imageSize.width << ", " << imageSize.height << ")";
705     int32_t ySize = imageSize.width * imageSize.height;
706     int32_t uvSize = ((imageSize.width + 1) / 2) * ((imageSize.height + 1) / 2);
707     const size_t totalSize = (ySize + 2 * uvSize);
708     uint16_t* const chOrg = new uint16_t[totalSize];
709     bool result = ReadFile(chOrg, IMAGE_INPUT_YUV_PATH3, totalSize, 1);
710     ASSERT_EQ(result, true);
711     const uint32_t dataLength = totalSize * 2;
712     uint32_t *data = reinterpret_cast<uint32_t *>(chOrg);
713     InitializationOptions opts;
714     opts.srcPixelFormat = outfmt;
715     opts.pixelFormat = outfmt;
716     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
717     opts.size.width = imageSize.width;
718     opts.size.height = imageSize.height;
719     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(data, dataLength, opts);
720     ASSERT_NE(pixelMap.get(), nullptr);
721 
722     std::shared_ptr<PixelMap> srcPixelMap = std::move(pixelMap);
723 
724     srcPixelMap->scale(imageSize.dstWidth, imageSize.dstHeight, option);
725 
726     uint8_t *data8 = const_cast<uint8_t *>(srcPixelMap->GetPixels());
727     const uint8_t *buffer = nullptr;
728     uint32_t size = srcPixelMap->GetCapacity();
729     uint32_t maxSize = MAXSIZE;
730     BufferPackerStream bufferPackerStream(data8, maxSize);
731     bool ret = bufferPackerStream.Write(buffer, size);
732     ASSERT_EQ(srcPixelMap->GetPixelFormat(), outfmt);
733     ASSERT_EQ(ret, false);
734     imageSize.width = srcPixelMap->GetWidth();
735     imageSize.height = srcPixelMap->GetHeight();
736     GTEST_LOG_(INFO) << "JpgYuvTest: ret size(" << imageSize.width << ", " << imageSize.height << ")";
737     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "P010scale/";
738     YuvWriteToFile(outpath, imageSize, outname, data8, size);
739 }
740 
ResizeYuv420P010(PixelFormat outfmt,std::string & outname,ImageSize & imageSize)741 void JpgYuvTest::ResizeYuv420P010(PixelFormat outfmt, std::string &outname, ImageSize &imageSize)
742 {
743     GTEST_LOG_(INFO) << "JpgYuvTest: request size(" << imageSize.width << ", " << imageSize.height << ")";
744     int32_t ySize = imageSize.width * imageSize.height;
745     int32_t uvSize = ((imageSize.width + 1) / 2) * ((imageSize.height + 1) / 2);
746     const size_t totalSize = (ySize + 2 * uvSize);
747     uint16_t* const chOrg = new uint16_t[totalSize];
748     bool result = ReadFile(chOrg, IMAGE_INPUT_YUV_PATH3, totalSize, 1);
749     ASSERT_EQ(result, true);
750     const uint32_t dataLength = totalSize * 2;
751     uint32_t *data = reinterpret_cast<uint32_t *>(chOrg);
752     InitializationOptions opts;
753     opts.srcPixelFormat = outfmt;
754     opts.pixelFormat = outfmt;
755     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
756     opts.size.width = imageSize.width;
757     opts.size.height = imageSize.height;
758     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(data, dataLength, opts);
759     ASSERT_NE(pixelMap.get(), nullptr);
760 
761     std::shared_ptr<PixelMap> srcPixelMap = std::move(pixelMap);
762     srcPixelMap->resize(imageSize.dstWidth, imageSize.dstHeight);
763 
764     uint8_t *data8 = const_cast<uint8_t *>(srcPixelMap->GetPixels());
765     const uint8_t *buffer = nullptr;
766     uint32_t size = srcPixelMap->GetCapacity();
767     uint32_t maxSize = MAXSIZE;
768     BufferPackerStream bufferPackerStream(data8, maxSize);
769     bool ret = bufferPackerStream.Write(buffer, size);
770     ASSERT_EQ(srcPixelMap->GetPixelFormat(), outfmt);
771     ASSERT_EQ(ret, false);
772     imageSize.width = srcPixelMap->GetWidth();
773     imageSize.height = srcPixelMap->GetHeight();
774     GTEST_LOG_(INFO) << "JpgYuvTest: ret size(" << imageSize.width << ", " << imageSize.height << ")";
775     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "P010resize/";
776     YuvWriteToFile(outpath, imageSize, outname, data8, size);
777 }
778 
FlipYuv420P010(PixelFormat outfmt,std::string & outname,ImageSize & imageSize,size_t i)779 void JpgYuvTest::FlipYuv420P010(PixelFormat outfmt, std::string &outname, ImageSize &imageSize, size_t i)
780 {
781     GTEST_LOG_(INFO) << "JpgYuvTest: request size(" << imageSize.width << ", " << imageSize.height << ")";
782     int32_t ySize = imageSize.width * imageSize.height;
783     int32_t uvSize = ((imageSize.width + 1) / 2) * ((imageSize.height + 1) / 2);
784     const size_t totalSize = (ySize + 2 * uvSize);
785     uint16_t* const chOrg = new uint16_t[totalSize];
786     bool result = ReadFile(chOrg, IMAGE_INPUT_YUV_PATH3, totalSize, 1);
787     ASSERT_EQ(result, true);
788     const uint32_t dataLength = totalSize * 2;
789     uint32_t *data = reinterpret_cast<uint32_t *>(chOrg);
790     InitializationOptions opts;
791     opts.srcPixelFormat = outfmt;
792     opts.pixelFormat = outfmt;
793     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
794     opts.size.width = imageSize.width;
795     opts.size.height = imageSize.height;
796     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(data, dataLength, opts);
797     ASSERT_NE(pixelMap.get(), nullptr);
798 
799     std::shared_ptr<PixelMap> srcPixelMap = std::move(pixelMap);
800 
801     bool xAxis;
802     bool yAxis;
803     GetFlipAxis(i, xAxis, yAxis);
804     srcPixelMap->flip(xAxis, yAxis);
805 
806     uint8_t *data8 = const_cast<uint8_t *>(srcPixelMap->GetPixels());
807     const uint8_t *buffer = nullptr;
808     uint32_t size = srcPixelMap->GetCapacity();
809     uint32_t maxSize = MAXSIZE;
810     BufferPackerStream bufferPackerStream(data8, maxSize);
811     bool ret = bufferPackerStream.Write(buffer, size);
812     ASSERT_EQ(srcPixelMap->GetPixelFormat(), outfmt);
813     ASSERT_EQ(ret, false);
814     imageSize.width = srcPixelMap->GetWidth();
815     imageSize.height = srcPixelMap->GetHeight();
816     GTEST_LOG_(INFO) << "JpgYuvTest: ret size(" << imageSize.width << ", " << imageSize.height << ")";
817     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "P010flip/";
818     YuvWriteToFile(outpath, imageSize, outname, data8, size);
819 }
820 
TranslateYuv420P010(PixelFormat outfmt,std::string & outname,ImageSize & imageSize,Coordinate & coordinate)821 void JpgYuvTest::TranslateYuv420P010(PixelFormat outfmt, std::string &outname,
822     ImageSize &imageSize, Coordinate &coordinate)
823 {
824     GTEST_LOG_(INFO) << "jpgYuvTest: request size(" << imageSize.width << ", " << imageSize.height << ")";
825     int32_t ySize = imageSize.width * imageSize.height;
826     int32_t uvSize = ((imageSize.width + 1) / 2) * ((imageSize.height + 1) / 2);
827     const size_t totalSize = (ySize + 2 * uvSize);
828     uint16_t* const chOrg = new uint16_t[totalSize];
829     bool result = ReadFile(chOrg, IMAGE_INPUT_YUV_PATH3, totalSize, 1);
830     ASSERT_EQ(result, true);
831     const uint32_t dataLength = totalSize * 2;
832     uint32_t *data = reinterpret_cast<uint32_t *>(chOrg);
833     InitializationOptions opts;
834     opts.srcPixelFormat = outfmt;
835     opts.pixelFormat = outfmt;
836     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
837     opts.size.width = imageSize.width;
838     opts.size.height = imageSize.height;
839     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(data, dataLength, opts);
840     ASSERT_NE(pixelMap.get(), nullptr);
841 
842     std::shared_ptr<PixelMap> srcPixelMap = std::move(pixelMap);
843 
844     srcPixelMap->translate(coordinate.xAxis, coordinate.yAxis);
845 
846     uint8_t *data8 = const_cast<uint8_t *>(srcPixelMap->GetPixels());
847     const uint8_t *buffer = nullptr;
848     uint32_t size = srcPixelMap->GetCapacity();
849     uint32_t maxSize = MAXSIZE;
850     BufferPackerStream bufferPackerStream(data8, maxSize);
851     bool ret = bufferPackerStream.Write(buffer, size);
852     ASSERT_EQ(srcPixelMap->GetPixelFormat(), outfmt);
853     ASSERT_EQ(ret, false);
854     imageSize.width = srcPixelMap->GetWidth();
855     imageSize.height = srcPixelMap->GetHeight();
856     GTEST_LOG_(INFO) << "jpgYuvTest: ret size(" << imageSize.width << ", " << imageSize.height << ")";
857     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "translate/";
858     YuvWriteToFile(outpath, imageSize, outname, data8, size);
859 }
860 
RGBA1010102Crop(PixelFormat outfmt,std::string outname,ImageSize & imageSize)861 void JpgYuvTest::RGBA1010102Crop(PixelFormat outfmt, std::string outname, ImageSize &imageSize)
862 {
863     GTEST_LOG_(INFO) << "JpgYuvTest: request size(" << imageSize.width << ", " << imageSize.height << ")";
864     int32_t ySize = imageSize.width * imageSize.height;
865     const size_t totalSize = ySize * NUM_4;
866     uint8_t* const chOrg = new uint8_t[totalSize];
867     bool result = ReadFile(chOrg, IMAGE_INPUT_YUV_PATH4, totalSize, 0);
868     ASSERT_EQ(result, true);
869     const uint32_t dataLength = totalSize;
870     uint32_t *data = reinterpret_cast<uint32_t *>(chOrg);
871     InitializationOptions opts;
872     opts.srcPixelFormat =outfmt;
873     opts.pixelFormat = outfmt;
874     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_PREMUL;
875     opts.size.width = imageSize.width;
876     opts.size.height = imageSize.height;
877     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(data, dataLength, opts);
878     ASSERT_NE(pixelMap.get(), nullptr);
879 
880     std::shared_ptr<PixelMap> srcPixelMap = std::move(pixelMap);
881 
882     Rect rect = {0, 0, 100, 100};
883     ASSERT_EQ(srcPixelMap->GetPixelFormat(), outfmt);
884     ASSERT_EQ(srcPixelMap->crop(rect), SUCCESS);
885 
886     uint8_t *data8 = const_cast<uint8_t *>(srcPixelMap->GetPixels());
887     const uint8_t *buffer = nullptr;
888     uint32_t size = srcPixelMap->GetWidth() * srcPixelMap->GetHeight() * NUM_4;
889     uint32_t maxSize = MAXSIZE;
890     BufferPackerStream bufferPackerStream(data8, maxSize);
891     bool ret = bufferPackerStream.Write(buffer, size);
892     ASSERT_EQ(srcPixelMap->GetPixelFormat(), outfmt);
893     ASSERT_EQ(ret, false);
894     imageSize.width = srcPixelMap->GetWidth();
895     imageSize.height = srcPixelMap->GetHeight();
896     GTEST_LOG_(INFO) << "JpgYuvTest: ret size(" << imageSize.width << ", " << imageSize.height << ")";
897     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "RGBACrop/";
898     YuvWriteToFile(outpath, imageSize, outname, data8, size);
899 }
900 
RGBA1010102Rotate(PixelFormat outfmt,std::string outname,ImageSize & imageSize,float degrees)901 void JpgYuvTest::RGBA1010102Rotate(PixelFormat outfmt, std::string outname, ImageSize &imageSize, float degrees)
902 {
903     GTEST_LOG_(INFO) << "JpgYuvTest: request size(" << imageSize.width << ", " << imageSize.height << ")";
904     int32_t ySize = imageSize.width * imageSize.height;
905     const size_t totalSize = ySize * NUM_4;
906     uint8_t* const chOrg = new uint8_t[totalSize];
907     bool result = ReadFile(chOrg, IMAGE_INPUT_YUV_PATH4, totalSize, 0);
908     ASSERT_EQ(result, true);
909     const uint32_t dataLength = totalSize;
910     uint32_t *data = reinterpret_cast<uint32_t *>(chOrg);
911     InitializationOptions opts;
912     opts.srcPixelFormat = outfmt;
913     opts.pixelFormat = outfmt;
914     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_PREMUL;
915     opts.size.width = imageSize.width;
916     opts.size.height = imageSize.height;
917     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(data, dataLength, opts);
918     ASSERT_NE(pixelMap.get(), nullptr);
919 
920     std::shared_ptr<PixelMap> srcPixelMap = std::move(pixelMap);
921     srcPixelMap->rotate(degrees);
922 
923     uint8_t *data8 = const_cast<uint8_t *>(srcPixelMap->GetPixels());
924     const uint8_t *buffer = nullptr;
925     uint32_t size = srcPixelMap->GetWidth() * srcPixelMap->GetHeight() * NUM_4;
926     uint32_t maxSize = MAXSIZE;
927     BufferPackerStream bufferPackerStream(data8, maxSize);
928     bool ret = bufferPackerStream.Write(buffer, size);
929     ASSERT_EQ(srcPixelMap->GetPixelFormat(), outfmt);
930     ASSERT_EQ(ret, false);
931     imageSize.width = srcPixelMap->GetWidth();
932     imageSize.height = srcPixelMap->GetHeight();
933     GTEST_LOG_(INFO) << "JpgYuvTest: ret size(" << imageSize.width << ", " << imageSize.height << ")";
934     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "RGBARotate/";
935     YuvWriteToFile(outpath, imageSize, outname, data8, size);
936 }
937 
RGBA1010102Scale(PixelFormat outfmt,std::string & outname,ImageSize & imageSize,AntiAliasingOption option)938 void JpgYuvTest::RGBA1010102Scale(PixelFormat outfmt, std::string &outname, ImageSize &imageSize,
939     AntiAliasingOption option)
940 {
941     GTEST_LOG_(INFO) << "JpgYuvTest: request size(" << imageSize.width << ", " << imageSize.height << ")";
942     int32_t ySize = imageSize.width * imageSize.height;
943     const size_t totalSize = ySize * NUM_4;
944     uint8_t* const chOrg = new uint8_t[totalSize];
945     bool result = ReadFile(chOrg, IMAGE_INPUT_YUV_PATH4, totalSize, 0);
946     ASSERT_EQ(result, true);
947     const uint32_t dataLength = totalSize;
948     uint32_t *data = reinterpret_cast<uint32_t *>(chOrg);
949     InitializationOptions opts;
950     opts.srcPixelFormat = outfmt;
951     opts.pixelFormat = outfmt;
952     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_PREMUL;
953     opts.size.width = imageSize.width;
954     opts.size.height = imageSize.height;
955     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(data, dataLength, opts);
956     ASSERT_NE(pixelMap.get(), nullptr);
957 
958     std::shared_ptr<PixelMap> srcPixelMap = std::move(pixelMap);
959 
960     srcPixelMap->scale(imageSize.dstWidth, imageSize.dstHeight, option);
961 
962     uint8_t *data8 = const_cast<uint8_t *>(srcPixelMap->GetPixels());
963     const uint8_t *buffer = nullptr;
964     uint32_t size = srcPixelMap->GetWidth() * srcPixelMap->GetHeight() * NUM_4;
965     uint32_t maxSize = MAXSIZE;
966     BufferPackerStream bufferPackerStream(data8, maxSize);
967     bool ret = bufferPackerStream.Write(buffer, size);
968     ASSERT_EQ(srcPixelMap->GetPixelFormat(), outfmt);
969     ASSERT_EQ(ret, false);
970     imageSize.width = srcPixelMap->GetWidth();
971     imageSize.height = srcPixelMap->GetHeight();
972     GTEST_LOG_(INFO) << "JpgYuvTest: ret size(" << imageSize.width << ", " << imageSize.height << ")";
973     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "RGBAScale/";
974     YuvWriteToFile(outpath, imageSize, outname, data8, size);
975 }
976 
RGBA1010102Resize(PixelFormat outfmt,std::string & outname,ImageSize & imageSize)977 void JpgYuvTest::RGBA1010102Resize(PixelFormat outfmt, std::string &outname, ImageSize &imageSize)
978 {
979     GTEST_LOG_(INFO) << "JpgYuvTest: request size(" << imageSize.width << ", " << imageSize.height << ")";
980     int32_t ySize = imageSize.width * imageSize.height;
981     const size_t totalSize = ySize * NUM_4;
982     uint8_t* const chOrg = new uint8_t[totalSize];
983     bool result = ReadFile(chOrg, IMAGE_INPUT_YUV_PATH4, totalSize, 0);
984     ASSERT_EQ(result, true);
985     const uint32_t dataLength = totalSize;
986     uint32_t *data = reinterpret_cast<uint32_t *>(chOrg);
987     InitializationOptions opts;
988     opts.srcPixelFormat = outfmt;
989     opts.pixelFormat = outfmt;
990     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_PREMUL;
991     opts.size.width = imageSize.width;
992     opts.size.height = imageSize.height;
993     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(data, dataLength, opts);
994     ASSERT_NE(pixelMap.get(), nullptr);
995 
996     std::shared_ptr<PixelMap> srcPixelMap = std::move(pixelMap);
997     srcPixelMap->resize(imageSize.dstWidth, imageSize.dstHeight);
998 
999     uint8_t *data8 = const_cast<uint8_t *>(srcPixelMap->GetPixels());
1000     const uint8_t *buffer = nullptr;
1001     uint32_t size = srcPixelMap->GetWidth() * srcPixelMap->GetHeight() * NUM_4;
1002     uint32_t maxSize = MAXSIZE;
1003     BufferPackerStream bufferPackerStream(data8, maxSize);
1004     bool ret = bufferPackerStream.Write(buffer, size);
1005     ASSERT_EQ(srcPixelMap->GetPixelFormat(), outfmt);
1006     ASSERT_EQ(ret, false);
1007     imageSize.width = srcPixelMap->GetWidth();
1008     imageSize.height = srcPixelMap->GetHeight();
1009     GTEST_LOG_(INFO) << "JpgYuvTest: ret size(" << imageSize.width << ", " << imageSize.height << ")";
1010     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "RGBAResize/";
1011     YuvWriteToFile(outpath, imageSize, outname, data8, size);
1012 }
1013 
RGBA1010102Flip(PixelFormat outfmt,std::string & outname,ImageSize & imageSize,size_t i)1014 void JpgYuvTest::RGBA1010102Flip(PixelFormat outfmt, std::string &outname, ImageSize &imageSize, size_t i)
1015 {
1016     GTEST_LOG_(INFO) << "JpgYuvTest: request size(" << imageSize.width << ", " << imageSize.height << ")";
1017     int32_t ySize = imageSize.width * imageSize.height;
1018     const size_t totalSize = ySize * NUM_4;
1019     uint8_t* const chOrg = new uint8_t[totalSize];
1020     bool result = ReadFile(chOrg, IMAGE_INPUT_YUV_PATH4, totalSize, 0);
1021     ASSERT_EQ(result, true);
1022     const uint32_t dataLength = totalSize;
1023     uint32_t *data = reinterpret_cast<uint32_t *>(chOrg);
1024     InitializationOptions opts;
1025     opts.srcPixelFormat = outfmt;
1026     opts.pixelFormat = outfmt;
1027     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_PREMUL;
1028     opts.size.width = imageSize.width;
1029     opts.size.height = imageSize.height;
1030     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(data, dataLength, opts);
1031     ASSERT_NE(pixelMap.get(), nullptr);
1032 
1033     std::shared_ptr<PixelMap> srcPixelMap = std::move(pixelMap);
1034 
1035     bool xAxis;
1036     bool yAxis;
1037     GetFlipAxis(i, xAxis, yAxis);
1038     srcPixelMap->flip(xAxis, yAxis);
1039 
1040     uint8_t *data8 = const_cast<uint8_t *>(srcPixelMap->GetPixels());
1041     const uint8_t *buffer = nullptr;
1042     uint32_t size = srcPixelMap->GetWidth() * srcPixelMap->GetHeight() * NUM_4;
1043     uint32_t maxSize = MAXSIZE;
1044     BufferPackerStream bufferPackerStream(data8, maxSize);
1045     bool ret = bufferPackerStream.Write(buffer, size);
1046     ASSERT_EQ(srcPixelMap->GetPixelFormat(), outfmt);
1047     ASSERT_EQ(ret, false);
1048     imageSize.width = srcPixelMap->GetWidth();
1049     imageSize.height = srcPixelMap->GetHeight();
1050     GTEST_LOG_(INFO) << "JpgYuvTest: ret size(" << imageSize.width << ", " << imageSize.height << ")";
1051     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "RGBAFlip/";
1052     YuvWriteToFile(outpath, imageSize, outname, data8, size);
1053 }
1054 
RGBA1010102Translate(PixelFormat outfmt,std::string & outname,ImageSize & imageSize,Coordinate & coordinate)1055 void JpgYuvTest::RGBA1010102Translate(PixelFormat outfmt, std::string &outname, ImageSize &imageSize,
1056     Coordinate &coordinate)
1057 {
1058     GTEST_LOG_(INFO) << "JpgYuvTest: request size(" << imageSize.width << ", " << imageSize.height << ")";
1059     int32_t ySize = imageSize.width * imageSize.height;
1060     const size_t totalSize = ySize * NUM_4;
1061     uint8_t* const chOrg = new uint8_t[totalSize];
1062     bool result = ReadFile(chOrg, IMAGE_INPUT_YUV_PATH4, totalSize, 0);
1063     ASSERT_EQ(result, true);
1064     const uint32_t dataLength = totalSize;
1065     uint32_t *data = reinterpret_cast<uint32_t *>(chOrg);
1066     InitializationOptions opts;
1067     opts.srcPixelFormat = outfmt;
1068     opts.pixelFormat = outfmt;
1069     opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_PREMUL;
1070     opts.size.width = imageSize.width;
1071     opts.size.height = imageSize.height;
1072     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(data, dataLength, opts);
1073     ASSERT_NE(pixelMap.get(), nullptr);
1074 
1075     std::shared_ptr<PixelMap> srcPixelMap = std::move(pixelMap);
1076 
1077     srcPixelMap->translate(coordinate.xAxis, coordinate.yAxis);
1078 
1079     uint8_t *data8 = const_cast<uint8_t *>(srcPixelMap->GetPixels());
1080     const uint8_t *buffer = nullptr;
1081     uint32_t size = srcPixelMap->GetWidth() * srcPixelMap->GetHeight() * NUM_4;
1082     uint32_t maxSize = MAXSIZE;
1083     BufferPackerStream bufferPackerStream(data8, maxSize);
1084     bool ret = bufferPackerStream.Write(buffer, size);
1085     ASSERT_EQ(srcPixelMap->GetPixelFormat(), outfmt);
1086     ASSERT_EQ(ret, false);
1087     imageSize.width = srcPixelMap->GetWidth();
1088     imageSize.height = srcPixelMap->GetHeight();
1089     GTEST_LOG_(INFO) << "jpgYuvTest: ret size(" << imageSize.width << ", " << imageSize.height << ")";
1090     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "translate/";
1091     YuvWriteToFile(outpath, imageSize, outname, data8, size);
1092 }
1093 
1094 HWTEST_F(JpgYuvTest, JpgYuvTest001, TestSize.Level3)
1095 {
1096     TestDecodeToSize(TREE_ORIGINAL_WIDTH, TREE_ORIGINAL_HEIGHT);
1097 }
1098 
1099 HWTEST_F(JpgYuvTest, JpgYuvTest002, TestSize.Level3)
1100 {
1101     int testWidth = 510;
1102     int testHeight = 460;
1103     TestDecodeToSize(testWidth, testHeight);
1104 }
1105 
1106 HWTEST_F(JpgYuvTest, JpgYuvTest003, TestSize.Level3)
1107 {
1108     int testWidth = 380;
1109     int testHeight = 211;
1110     TestDecodeToSize(testWidth, testHeight);
1111 }
1112 
1113 HWTEST_F(JpgYuvTest, JpgYuvTest004, TestSize.Level3)
1114 {
1115     int testWidth = 100;
1116     int testHeight = 100;
1117     TestDecodeToSize(testWidth, testHeight);
1118 }
1119 
1120 HWTEST_F(JpgYuvTest, JpgYuvTest005, TestSize.Level3)
1121 {
1122     int testWidth = 2000;
1123     int testHeight = 2000;
1124     TestDecodeToSize(testWidth, testHeight);
1125 }
1126 
1127 HWTEST_F(JpgYuvTest, JpgYuvTest006, TestSize.Level3)
1128 {
1129     PixelFormat outfmt[] = { PixelFormat::NV12, PixelFormat::NV21};
1130     const char* outNamePart2[] = { "-nv12.yuv", "-nv21.yuv"};
1131     for (uint32_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
1132         std::string jpgpath = IMAGE_INPUT_JPG_PATH;
1133         jpgpath.append("test_hw.jpg");
1134         std::string outname;
1135         outname.append("testhw");
1136         outname.append(outNamePart2[j]);
1137         int outWidth = 0;
1138         int outHeight = 0;
1139         DecodeToYuv(jpgpath, outfmt[j], outname, outWidth, outHeight);
1140     }
1141 }
1142 
1143 HWTEST_F(JpgYuvTest, JpgYuvTest007, TestSize.Level3)
1144 {
1145     std::string jpgpath = IMAGE_INPUT_JPG_PATH;
1146     jpgpath.append("test-tree-311.jpg");
1147 
1148     uint32_t errorCode = 0;
1149     SourceOptions opts;
1150     opts.formatHint = "image/jpeg";
1151     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(jpgpath, opts, errorCode);
1152     ASSERT_EQ(errorCode, SUCCESS);
1153     ASSERT_NE(imageSource.get(), nullptr);
1154     DecodeOptions decodeOpts;
1155     decodeOpts.desiredPixelFormat = PixelFormat::NV12;
1156     decodeOpts.desiredSize.width = 0;
1157     decodeOpts.desiredSize.height = 0;
1158     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
1159     ASSERT_EQ(errorCode, SUCCESS);
1160 }
1161 
1162 HWTEST_F(JpgYuvTest, JpgYuvTest008, TestSize.Level3)
1163 {
1164     std::string jpgpath = IMAGE_INPUT_JPG_PATH;
1165     jpgpath.append("test-bad.jpg");
1166 
1167     uint32_t errorCode = 0;
1168     SourceOptions opts;
1169     opts.formatHint = "image/jpeg";
1170     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(jpgpath, opts, errorCode);
1171     ASSERT_EQ(errorCode, SUCCESS);
1172     ASSERT_NE(imageSource.get(), nullptr);
1173     DecodeOptions decodeOpts;
1174     decodeOpts.desiredPixelFormat = PixelFormat::NV12;
1175     decodeOpts.desiredSize.width = 0;
1176     decodeOpts.desiredSize.height = 0;
1177     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
1178     ASSERT_NE(errorCode, SUCCESS);
1179 }
1180 
1181 HWTEST_F(JpgYuvTest, JpgYuvTest009, TestSize.Level3)
1182 {
1183     std::string jpgpath = IMAGE_INPUT_JPG_PATH;
1184     jpgpath.append("test_null.jpg");
1185 
1186     uint32_t errorCode = 0;
1187     SourceOptions opts;
1188     opts.formatHint = "image/jpeg";
1189     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(jpgpath, opts, errorCode);
1190     ASSERT_EQ(errorCode, SUCCESS);
1191     ASSERT_NE(imageSource.get(), nullptr);
1192     DecodeOptions decodeOpts;
1193     decodeOpts.desiredPixelFormat = PixelFormat::NV12;
1194     decodeOpts.desiredSize.width = 0;
1195     decodeOpts.desiredSize.height = 0;
1196     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
1197     ASSERT_NE(errorCode, SUCCESS);
1198 }
1199 
1200 HWTEST_F(JpgYuvTest, JpgYuvTest010, TestSize.Level3)
1201 {
1202     const char* srcjpg[] = { "test-treeodd-444.jpg", "test-treeodd-422.jpg", "test-treeodd-420.jpg",
1203         "test-treeodd-400.jpg", "test-treeodd-440.jpg", "test-treeodd-411.jpg"};
1204     const char* outNamePart1[] = { "treeodd-444", "treeodd-422", "treeodd-420",
1205         "treeodd-400", "treeodd-440", "treeodd-411"};
1206     const char* outNamePart2[] = { "-nv12.yuv", "-nv21.yuv"};
1207     PixelFormat outfmt[] = { PixelFormat::NV12, PixelFormat::NV21};
1208     for (uint32_t k = 0; k < sizeof(srcjpg) / sizeof(char*); k++) {
1209         for (uint32_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
1210             std::string jpgpath = IMAGE_INPUT_JPG_PATH;
1211             jpgpath.append(srcjpg[k]);
1212             std::string outname;
1213             outname.append(outNamePart1[k]);
1214             outname.append(outNamePart2[j]);
1215             int outWidth = ODDTREE_ORIGINAL_WIDTH;
1216             int outHeight = ODDTREE_ORIGINAL_HEIGHT;
1217             DecodeToYuv(jpgpath, outfmt[j], outname, outWidth, outHeight);
1218         }
1219     }
1220 }
1221 
1222 HWTEST_F(JpgYuvTest, JpgYuvTest011, TestSize.Level3)
1223 {
1224     int testWidth = 1;
1225     int testHeight = 1;
1226     TestDecodeToSize(testWidth, testHeight);
1227 }
1228 
1229 HWTEST_F(JpgYuvTest, JpgYuvTest012, TestSize.Level3)
1230 {
1231     int testWidth = 1;
1232     int testHeight = 100;
1233     TestDecodeToSize(testWidth, testHeight);
1234 }
1235 
1236 HWTEST_F(JpgYuvTest, JpgYuvTest013, TestSize.Level3)
1237 {
1238     float scale = 0.875;
1239     int outwidth = TREE_ORIGINAL_WIDTH * scale;
1240     int outheight = TREE_ORIGINAL_HEIGHT * scale;
1241     TestDecodeToSize(outwidth, outheight);
1242 }
1243 
1244 HWTEST_F(JpgYuvTest, JpgYuvTest014, TestSize.Level3)
1245 {
1246     float scalFactor = 2.5;
1247     float minscale = 0.05;
1248     float step = 0.01;
1249     for (; scalFactor >= minscale; scalFactor -= step) {
1250         std::string jpgpath = IMAGE_INPUT_JPG_PATH;
1251         jpgpath.append("test-tree-444.jpg");
1252 
1253         uint32_t errorCode = 0;
1254         SourceOptions opts;
1255         opts.formatHint = "image/jpeg";
1256         std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(jpgpath, opts, errorCode);
1257         ASSERT_EQ(errorCode, SUCCESS);
1258         ASSERT_NE(imageSource.get(), nullptr);
1259         DecodeOptions decodeOpts;
1260         decodeOpts.desiredPixelFormat = PixelFormat::NV12;
1261         decodeOpts.desiredSize.width = TREE_ORIGINAL_WIDTH * scalFactor;
1262         decodeOpts.desiredSize.height = TREE_ORIGINAL_HEIGHT * scalFactor;
1263         std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
1264         ASSERT_EQ(errorCode, SUCCESS);
1265     }
1266 }
1267 
1268 HWTEST_F(JpgYuvTest, JpgYuvTest015, TestSize.Level3)
1269 {
1270     DoTimeTest("test-tree-444.jpg");
1271 }
1272 
1273 HWTEST_F(JpgYuvTest, JpgYuvTest016, TestSize.Level3)
1274 {
1275     DoTimeTest("test-tree-440.jpg");
1276 }
1277 
1278 HWTEST_F(JpgYuvTest, JpgYuvTest017, TestSize.Level3)
1279 {
1280     DoTimeTest("test-tree-422.jpg");
1281 }
1282 
1283 HWTEST_F(JpgYuvTest, JpgYuvTest018, TestSize.Level3)
1284 {
1285     DoTimeTest("test-tree-420.jpg");
1286     DoTimeTest("test-treeodd-420.jpg");
1287 }
1288 
1289 HWTEST_F(JpgYuvTest, JpgYuvTest019, TestSize.Level3)
1290 {
1291     DoTimeTest("test-tree-411.jpg");
1292 }
1293 
1294 HWTEST_F(JpgYuvTest, JpgYuvTest020, TestSize.Level3)
1295 {
1296     uint32_t errorCode = 0;
1297     SourceOptions opts;
1298     std::string hw_jpg_path = "/data/local/tmp/image/test_hw.jpg";
1299     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(hw_jpg_path, opts, errorCode);
1300     ASSERT_EQ(errorCode, SUCCESS);
1301     ASSERT_NE(imageSource.get(), nullptr);
1302     DecodeOptions decodeOpts;
1303     decodeOpts.desiredPixelFormat = PixelFormat::NV21;
1304     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
1305     ASSERT_EQ(errorCode, SUCCESS);
1306 }
1307 
1308 HWTEST_F(JpgYuvTest, JpgYuvTest021, TestSize.Level3)
1309 {
1310     const char *srcjpg[] = {"test-treeodd-444.jpg"};
1311     PixelFormat outfmt[] = {PixelFormat::NV12, PixelFormat::NV21};
1312     std::string jpgpath = IMAGE_INPUT_JPG_PATH;
1313     jpgpath.append(srcjpg[0]);
1314     float degrees[] = {90, 180, 270, 280};
1315     int k = 0;
1316     const char *outFileName[] = {"90-nv12.yuv", "180-nv12.yuv", "270-nv12.yuv", "280-nv12.yuv",
1317                                     "90-nv21.yuv", "180-nv21.yuv", "270-nv21.yuv", "280-nv21.yuv"};
1318     for (int i = 0; i < sizeof(outfmt) / sizeof(PixelFormat); ++i) {
1319         for (int j = 0; j < sizeof(degrees) / sizeof(float); ++j) {
1320             std::string outname;
1321             outname.append(outFileName[k++]);
1322             ImageSize imageSize = {ODDTREE_ORIGINAL_WIDTH, ODDTREE_ORIGINAL_HEIGHT, 0, 0, 0, 0};
1323             YuvRotate(jpgpath, outfmt[i], outname, imageSize, degrees[j]);
1324         }
1325     }
1326 }
1327 
1328 HWTEST_F(JpgYuvTest, JpgYuvTest022, TestSize.Level3)
1329 {
1330     const char *srcjpg[] = {"test-treeodd-444.jpg"};
1331     PixelFormat outfmt[] = {PixelFormat::NV12, PixelFormat::NV21};
1332     std::string jpgpath = IMAGE_INPUT_JPG_PATH;
1333     jpgpath.append(srcjpg[0]);
1334     const char *outFileName[] = {"-nv12.yuv", "-nv21.yuv"};
1335     for (int i = 0; i < sizeof(outfmt) / sizeof(outfmt[0]); ++i) {
1336         std::string outname;
1337         outname.append(outFileName[i]);
1338         ImageSize imageSize = {ODDTREE_ORIGINAL_WIDTH, ODDTREE_ORIGINAL_HEIGHT, 0, 0, 0, 0};
1339         YuvCrop(jpgpath, outfmt[i], outname, imageSize);
1340     }
1341 }
1342 
1343 HWTEST_F(JpgYuvTest, JpgYuvTest023, TestSize.Level3)
1344 {
1345     const char *srcjpg[] = {"test-treeodd-444.jpg"};
1346     PixelFormat outfmt[] = {PixelFormat::NV12, PixelFormat::NV21};
1347     std::string jpgpath = IMAGE_INPUT_JPG_PATH;
1348     jpgpath.append(srcjpg[0]);
1349     const char *outFileName[] = {"-nv12.yuv", "-nv21.yuv"};
1350     for (int i = 0; i < sizeof(outfmt) / sizeof(outfmt[0]); ++i)
1351     {
1352         std::string outname;
1353         outname.append(outFileName[i]);
1354         ImageSize imageSize = {ODDTREE_ORIGINAL_WIDTH, ODDTREE_ORIGINAL_HEIGHT, 0, 0, 0, 0};
1355         YuvWriteConvert(jpgpath, outfmt[i], outname, imageSize);
1356     }
1357 }
1358 
1359 HWTEST_F(JpgYuvTest, JpgYuvTest024, TestSize.Level3)
1360 {
1361     PixelFormat outfmt[] = {PixelFormat::NV12, PixelFormat::NV21};
1362     const char *outNamePart2[] = {"-nv12.yuv", "-nv21.yuv"};
1363     AntiAliasingOption options[] = {AntiAliasingOption::NONE, AntiAliasingOption::LOW,
1364                                     AntiAliasingOption::MEDIUM, AntiAliasingOption::HIGH};
1365     std::filesystem::path dir("scale");
1366     if (!std::filesystem::exists(dir)) {
1367         ASSERT_EQ(std::filesystem::create_directory(dir), true);
1368     }
1369     for (size_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
1370         for (size_t i = 0; i < sizeof(options) / sizeof(AntiAliasingOption); i++) {
1371             std::string jpgpath = IMAGE_INPUT_JPG_PATH;
1372             jpgpath.append("test-treeodd-444.jpg");
1373             std::string outname;
1374             outname.append("testhw");
1375             switch (options[i]) {
1376                 case AntiAliasingOption::NONE:
1377                     outname.append("-NONE-");
1378                     break;
1379                 case AntiAliasingOption::LOW:
1380                     outname.append("-LOW-");
1381                     break;
1382                 case AntiAliasingOption::MEDIUM:
1383                     outname.append("-MEDIUM-");
1384                     break;
1385                 case AntiAliasingOption::HIGH:
1386                     outname.append("-HIGH-");
1387                     break;
1388                 default:
1389                     break;
1390             }
1391             outname.append(outNamePart2[j]);
1392             ImageSize imageSize = {ODDTREE_ORIGINAL_WIDTH, ODDTREE_ORIGINAL_HEIGHT, NUM_2, NUM_2, 0, 0};
1393             ScaleYuv420(jpgpath, outfmt[j], outname, imageSize, options[i]);
1394         }
1395     }
1396 }
1397 
1398 HWTEST_F(JpgYuvTest, JpgYuvTest025, TestSize.Level3)
1399 {
1400     PixelFormat outfmt[] = {PixelFormat::NV12, PixelFormat::NV21};
1401     const char *outNamePart2[] = {"-nv12.yuv", "-nv21.yuv"};
1402     std::filesystem::path dir("resize");
1403     if (!std::filesystem::exists(dir)) {
1404         ASSERT_EQ(std::filesystem::create_directory(dir), true);
1405     }
1406     for (size_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
1407         std::string jpgpath = IMAGE_INPUT_JPG_PATH;
1408         jpgpath.append("test-treeodd-444.jpg");
1409         std::string outname;
1410         outname.append("testhw");
1411         outname.append(outNamePart2[j]);
1412         ImageSize imageSize = {ODDTREE_ORIGINAL_WIDTH, ODDTREE_ORIGINAL_HEIGHT, NUM_2, NUM_2, 0, 0};
1413         ResizeYuv420(jpgpath, outfmt[j], outname, imageSize);
1414     }
1415 }
1416 
1417 HWTEST_F(JpgYuvTest, JpgYuvTest026, TestSize.Level3)
1418 {
1419     PixelFormat outfmt[] = {PixelFormat::NV12, PixelFormat::NV21};
1420     const char *outNamePart2[] = {"-nv12.yuv", "-nv21.yuv"};
1421     bool flips[4][2] = {{true, true}, {true, false}, {false, true}, {false, false}};
1422     std::filesystem::path dir("flip");
1423     if (!std::filesystem::exists(dir)) {
1424         ASSERT_EQ(std::filesystem::create_directory(dir), true);
1425     }
1426     for (size_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
1427         for (size_t i = 0; i < sizeof(flips) / (sizeof(bool) * 2); i++) {
1428             std::string jpgpath = IMAGE_INPUT_JPG_PATH;
1429             jpgpath.append("test-treeodd-444.jpg");
1430             std::string outname;
1431             outname.append("testhw");
1432             switch (i) {
1433                 case 0:
1434                     outname.append("-xy-");
1435                     break;
1436                 case 1:
1437                     outname.append("-x-");
1438                     break;
1439                 case 2:
1440                     outname.append("-y-");
1441                     break;
1442                 case 3:
1443                     outname.append("-no-");
1444                     break;
1445                 default:
1446                     break;
1447             }
1448             outname.append(outNamePart2[j]);
1449             ImageSize imageSize = {ODDTREE_ORIGINAL_WIDTH, ODDTREE_ORIGINAL_HEIGHT, 0, 0, 0, 0};
1450             FlipYuv420(jpgpath, outfmt[j], outname, imageSize, i);
1451         }
1452     }
1453 }
1454 
1455 #ifdef IMAGE_COLORSPACE_FLAG
1456 // using namespace OHOS::ColorManager;
ApplyColorSpaceYuv420(std::string & srcjpg,PixelFormat outfmt,std::string & outname,ImageSize & imageSize,const OHOS::ColorManager::ColorSpace & grColorSpace)1457 void JpgYuvTest::ApplyColorSpaceYuv420(std::string &srcjpg, PixelFormat outfmt, std::string &outname,
1458     ImageSize &imageSize, const OHOS::ColorManager::ColorSpace &grColorSpace)
1459 {
1460     uint32_t errorCode = 0;
1461     SourceOptions opts;
1462     opts.formatHint = "image/jpeg";
1463     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(srcjpg, opts, errorCode);
1464     ASSERT_EQ(errorCode, SUCCESS);
1465     ASSERT_NE(imageSource.get(), nullptr);
1466     DecodeOptions decodeOpts;
1467     decodeOpts.desiredPixelFormat = outfmt;
1468     decodeOpts.desiredSize.width = imageSize.width;
1469     decodeOpts.desiredSize.height = imageSize.height;
1470     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
1471     ASSERT_EQ(errorCode, SUCCESS);
1472     ASSERT_NE(pixelMap.get(), nullptr);
1473 
1474     pixelMap->ApplyColorSpace(grColorSpace);
1475 
1476     uint8_t *data = const_cast<uint8_t *>(pixelMap->GetPixels());
1477     const uint8_t *buffer = nullptr;
1478     uint32_t size = pixelMap->GetCapacity();
1479     uint32_t maxSize = MAXSIZE;
1480     BufferPackerStream bufferPackerStream(data, maxSize);
1481     bool ret = bufferPackerStream.Write(buffer, size);
1482     ASSERT_EQ(pixelMap->GetPixelFormat(), outfmt);
1483     ASSERT_EQ(ret, false);
1484     imageSize.width = pixelMap->GetWidth();
1485     imageSize.height = pixelMap->GetHeight();
1486     std::string outpath = IMAGE_OUTPUT_JPG_PATH + "applyCorlorSpace/";
1487     YuvWriteToFile(outpath, imageSize, outname, data, size);
1488 }
1489 
1490 HWTEST_F(JpgYuvTest, JpgYuvTest027, TestSize.Level3)
1491 {
1492     PixelFormat outfmt[] = {PixelFormat::NV12, PixelFormat::NV21};
1493     const char *outNamePart2[] = {"-nv12.yuv", "-nv21.yuv"};
1494     OHOS::ColorManager::ColorSpace colorSpaces[] = {
1495         OHOS::ColorManager::ColorSpace(OHOS::ColorManager::ColorSpaceName::SRGB),
1496         OHOS::ColorManager::ColorSpace(OHOS::ColorManager::ColorSpaceName::ADOBE_RGB),
1497         OHOS::ColorManager::ColorSpace(OHOS::ColorManager::ColorSpaceName::DISPLAY_P3),
1498         OHOS::ColorManager::ColorSpace(OHOS::ColorManager::ColorSpaceName::BT2020)};
1499     std::filesystem::path dir("applyCorlorSpace");
1500     if (!std::filesystem::exists(dir)) {
1501         ASSERT_EQ(std::filesystem::create_directory(dir), true);
1502     }
1503     for (size_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
1504         for (size_t i = 0; i < sizeof(colorSpaces) / sizeof(OHOS::ColorManager::ColorSpace); i++) {
1505             std::string jpgpath = IMAGE_INPUT_JPG_PATH;
1506             jpgpath.append("test-treeodd-444.jpg");
1507             std::string outname;
1508             outname.append("testhw");
1509             switch (colorSpaces[i].GetColorSpaceName()) {
1510                 case OHOS::ColorManager::ColorSpaceName::SRGB:
1511                     outname.append("-SRGB-");
1512                     break;
1513                 case OHOS::ColorManager::ColorSpaceName::ADOBE_RGB:
1514                     outname.append("-ADOBE_RGB-");
1515                     break;
1516                 case OHOS::ColorManager::ColorSpaceName::DISPLAY_P3:
1517                     outname.append("-DISPLAY_P3-");
1518                     break;
1519                 case OHOS::ColorManager::ColorSpaceName::BT2020:
1520                     outname.append("-BT2020-");
1521                     break;
1522                 default:
1523                     break;
1524             }
1525             outname.append(outNamePart2[j]);
1526             ImageSize imageSize = {ODDTREE_ORIGINAL_WIDTH, ODDTREE_ORIGINAL_HEIGHT, 0, 0, 0, 0};
1527             ApplyColorSpaceYuv420(jpgpath, outfmt[j], outname, imageSize, colorSpaces[i]);
1528         }
1529     }
1530 }
1531 #endif
1532 
1533 HWTEST_F(JpgYuvTest, JpgYuvTest028, TestSize.Level3)
1534 {
1535     PixelFormat outfmt[] = {PixelFormat::NV12, PixelFormat::NV21};
1536     const char* outNamePart2[] = {"-nv12.yuv", "-nv21.yuv"};
1537     std::filesystem::path dir("translate");
1538     if (!std::filesystem::exists(dir)) {
1539         ASSERT_EQ(std::filesystem::create_directory(dir), true);
1540     }
1541     for (size_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
1542         std::string jpgpath = IMAGE_INPUT_JPG_PATH;
1543         jpgpath.append("test-treeodd-444.jpg");
1544         std::string outname;
1545         outname.append("testhw");
1546         outname.append(outNamePart2[j]);
1547         ImageSize imageSize = {ODDTREE_ORIGINAL_WIDTH, ODDTREE_ORIGINAL_HEIGHT, 0, 0, 0, 0};
1548         Coordinate coordinate = {1, 1};
1549         TranslateYuv420(jpgpath, outfmt[j], outname, imageSize, coordinate);
1550     }
1551 }
1552 
1553 HWTEST_F(JpgYuvTest, JpgYuvTest029, TestSize.Level3)
1554 {
1555     PixelFormat outfmt[] = {PixelFormat::NV12, PixelFormat::NV21};
1556     const char* outNamePart2[] = {"-nv12.yuv", "-nv21.yuv"};
1557     std::filesystem::path dir("read");
1558     if (!std::filesystem::exists(dir)) {
1559         ASSERT_EQ(std::filesystem::create_directory(dir), true);
1560     }
1561     for (size_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
1562         std::string jpgpath = IMAGE_INPUT_JPG_PATH;
1563         jpgpath.append("test-treeodd-444.jpg");
1564         std::string outname;
1565         outname.append("testhw");
1566         outname.append(outNamePart2[j]);
1567         Position pos;
1568         pos.x = 1;
1569         pos.y = 1;
1570         ImageSize imageSize = {ODDTREE_ORIGINAL_WIDTH, ODDTREE_ORIGINAL_HEIGHT, 0, 0, 0, 0};
1571         ReadYuv420(jpgpath, outfmt[j], outname, pos, imageSize);
1572     }
1573 }
1574 
1575 HWTEST_F(JpgYuvTest, JpgYuvTest030, TestSize.Level3)
1576 {
1577     PixelFormat outfmt[] = {PixelFormat::NV12, PixelFormat::NV21};
1578     const char* outNamePart2[] = {"-nv12.yuv", "-nv21.yuv"};
1579     std::filesystem::path dir("write");
1580     if (!std::filesystem::exists(dir)) {
1581         ASSERT_EQ(std::filesystem::create_directory(dir), true);
1582     }
1583     for (size_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
1584         std::string jpgpath = IMAGE_INPUT_JPG_PATH;
1585         jpgpath.append("test-treeodd-444.jpg");
1586         std::string outname;
1587         outname.append("testhw");
1588         outname.append(outNamePart2[j]);
1589         Position pos;
1590         pos.x = 1;
1591         pos.y = 1;
1592         ImageSize imageSize = {ODDTREE_ORIGINAL_WIDTH, ODDTREE_ORIGINAL_HEIGHT, 0, 0, 0, 0};
1593         WriteYuv420(jpgpath, outfmt[j], outname, pos, imageSize);
1594     }
1595 }
1596 
1597 HWTEST_F(JpgYuvTest, JpgYuvTest031, TestSize.Level3)
1598 {
1599     PixelFormat outfmt[] = {PixelFormat::NV12, PixelFormat::NV21};
1600     const char* outNamePart2[] = {"-nv12.yuv", "-nv21.yuv"};
1601     std::filesystem::path dir("writePixels");
1602     if (!std::filesystem::exists(dir)) {
1603         ASSERT_EQ(std::filesystem::create_directory(dir), true);
1604     }
1605     for (size_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
1606         std::string jpgpath = IMAGE_INPUT_JPG_PATH;
1607         jpgpath.append("test-treeodd-444.jpg");
1608         std::string outname;
1609         outname.append("testhw");
1610         outname.append(outNamePart2[j]);
1611         ImageSize imageSize = {ODDTREE_ORIGINAL_WIDTH, ODDTREE_ORIGINAL_HEIGHT, 0, 0, 0, 0};
1612         WritesYuv420(jpgpath, outfmt[j], outname, imageSize);
1613     }
1614 }
1615 
1616 HWTEST_F(JpgYuvTest, P010JpgYuvTest001, TestSize.Level3)
1617 {
1618     GTEST_LOG_(INFO) << "JpgYuvTest: P010JpgYuvTest001 start";
1619     PixelFormat outfmt[] = {PixelFormat::YCBCR_P010, PixelFormat::YCRCB_P010};
1620     const char *outFileName[] = {"-ycbcr_p010.yuv", "-ycrcb_p010.yuv"};
1621     for (int i = 0; i < sizeof(outfmt) / sizeof(outfmt[0]); ++i) {
1622         std::string outname;
1623         outname.append(outFileName[i]);
1624         ImageSize imageSize = {P101TREE_ORIGINAL_WIDTH, P101TREE_ORIGINAL_HEIGHT, 0, 0, 0, 0};
1625         YuvP010Crop(outfmt[i], outname, imageSize);
1626     }
1627     GTEST_LOG_(INFO) << "JpgYuvTest: P010JpgYuvTest001 end";
1628 }
1629 
1630 HWTEST_F(JpgYuvTest, P010JpgYuvTest002, TestSize.Level3)
1631 {
1632     GTEST_LOG_(INFO) << "JpgYuvTest: P010JpgYuvTest002 start";
1633     PixelFormat outfmt[] = {PixelFormat::YCBCR_P010, PixelFormat::YCRCB_P010};
1634     float degrees[] = {90, 180, 270};
1635     int k = 0;
1636     const char *outFileName[] = {"90-ycbcr_p010.yuv", "180-ycbcr_p010.yuv", "270-ycbcr_p010.yuv",
1637                                     "90-ycrcb_p010.yuv", "180-ycrcb_p010.yuv", "270-ycrcb_p010.yuv"};
1638     for (int i = 0; i < sizeof(outfmt) / sizeof(PixelFormat); ++i) {
1639         for (int j = 0; j < sizeof(degrees) / sizeof(float); ++j) {
1640             std::string outname;
1641             outname.append(outFileName[k++]);
1642             ImageSize imageSize = {P101TREE_ORIGINAL_WIDTH, P101TREE_ORIGINAL_HEIGHT, 0, 0, 0, 0};
1643             YuvP010Rotate(outfmt[i], outname, imageSize, degrees[j]);
1644         }
1645     }
1646     GTEST_LOG_(INFO) << "JpgYuvTest: P010JpgYuvTest002 end";
1647 }
1648 HWTEST_F(JpgYuvTest, P010JpgYuvTest003, TestSize.Level3)
1649 {
1650     GTEST_LOG_(INFO) << "JpgYuvTest: P010JpgYuvTest003 start";
1651     PixelFormat outfmt[] = {PixelFormat::YCBCR_P010, PixelFormat::YCRCB_P010};
1652     const char *outNamePart2[] = {"-ycbcr_p010.yuv", "-ycrcb_p010.yuv"};
1653     AntiAliasingOption options[] = {AntiAliasingOption::NONE, AntiAliasingOption::LOW,
1654                                     AntiAliasingOption::MEDIUM, AntiAliasingOption::HIGH};
1655     std::filesystem::path dir("scale");
1656     if (!std::filesystem::exists(dir)) {
1657         ASSERT_EQ(std::filesystem::create_directory(dir), true);
1658     }
1659     for (size_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
1660         for (size_t i = 0; i < sizeof(options) / sizeof(AntiAliasingOption); i++) {
1661             std::string outname;
1662             outname.append("p010");
1663             switch (options[i]) {
1664                 case AntiAliasingOption::NONE:
1665                     outname.append("-NONE-");
1666                     break;
1667                 case AntiAliasingOption::LOW:
1668                     outname.append("-LOW-");
1669                     break;
1670                 case AntiAliasingOption::MEDIUM:
1671                     outname.append("-MEDIUM-");
1672                     break;
1673                 case AntiAliasingOption::HIGH:
1674                     outname.append("-HIGH-");
1675                     break;
1676                 default:
1677                     break;
1678             }
1679             outname.append(outNamePart2[j]);
1680             ImageSize imageSize = {P101TREE_ORIGINAL_WIDTH, P101TREE_ORIGINAL_HEIGHT, NUM_2, NUM_2, 0, 0};
1681             ScaleYuv420P010(outfmt[j], outname, imageSize, options[i]);
1682         }
1683     }
1684     GTEST_LOG_(INFO) << "JpgYuvTest: P010JpgYuvTest003 end";
1685 }
1686 
1687 HWTEST_F(JpgYuvTest, P010JpgYuvTest004, TestSize.Level3)
1688 {
1689     GTEST_LOG_(INFO) << "JpgYuvTest: P010JpgYuvTest004 start";
1690     PixelFormat outfmt[] = {PixelFormat::YCBCR_P010, PixelFormat::YCRCB_P010};
1691     const char *outNamePart2[] = {"-ycbcr_p010.yuv", "-ycrcb_p010.yuv"};
1692     std::filesystem::path dir("resize");
1693     if (!std::filesystem::exists(dir)) {
1694         ASSERT_EQ(std::filesystem::create_directory(dir), true);
1695     }
1696     for (size_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
1697         std::string outname;
1698         outname.append("p010");
1699         outname.append(outNamePart2[j]);
1700         ImageSize imageSize = {P101TREE_ORIGINAL_WIDTH, P101TREE_ORIGINAL_HEIGHT, NUM_2, NUM_2, 0, 0};
1701         ResizeYuv420P010(outfmt[j], outname, imageSize);
1702     }
1703     GTEST_LOG_(INFO) << "JpgYuvTest: P010JpgYuvTest004 end";
1704 }
1705 
1706 HWTEST_F(JpgYuvTest, P010JpgYuvTest005, TestSize.Level3)
1707 {
1708     GTEST_LOG_(INFO) << "JpgYuvTest: P010JpgYuvTest005 start";
1709     PixelFormat outfmt[] = {PixelFormat::YCBCR_P010, PixelFormat::YCRCB_P010};
1710     const char *outNamePart2[] = {"-ycbcr_p010.yuv", "-ycrcb_p010.yuv"};
1711     bool flips[4][2] = {{true, true}, {true, false}, {false, true}, {false, false}};
1712     std::filesystem::path dir("flip");
1713     if (!std::filesystem::exists(dir)) {
1714         ASSERT_EQ(std::filesystem::create_directory(dir), true);
1715     }
1716     for (size_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
1717         for (size_t i = 0; i < sizeof(flips) / (sizeof(bool) * 2); i++) {
1718             std::string outname;
1719             outname.append("testhw");
1720             switch (i) {
1721                 case 0:
1722                     outname.append("-xy-");
1723                     break;
1724                 case 1:
1725                     outname.append("-x-");
1726                     break;
1727                 case 2:
1728                     outname.append("-y-");
1729                     break;
1730                 case 3:
1731                     outname.append("-no-");
1732                     break;
1733                 default:
1734                     break;
1735             }
1736             outname.append(outNamePart2[j]);
1737             ImageSize imageSize = {P101TREE_ORIGINAL_WIDTH, P101TREE_ORIGINAL_HEIGHT, 0, 0, 0, 0};
1738             FlipYuv420P010(outfmt[j], outname, imageSize, i);
1739         }
1740     }
1741     GTEST_LOG_(INFO) << "JpgYuvTest: P010JpgYuvTest005 end";
1742 }
1743 
1744 HWTEST_F(JpgYuvTest, P010JpgYuvTest006, TestSize.Level3)
1745 {
1746     GTEST_LOG_(INFO) << "JpgYuvTest: P010JpgYuvTest006 start";
1747     PixelFormat outfmt[] = {PixelFormat::YCBCR_P010, PixelFormat::YCRCB_P010};
1748     const char *outNamePart2[] = {"-ycbcr_p010.yuv", "-ycrcb_p010.yuv"};
1749     std::filesystem::path dir("translate");
1750     if (!std::filesystem::exists(dir)) {
1751         ASSERT_EQ(std::filesystem::create_directory(dir), true);
1752     }
1753     for (size_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
1754         std::string outname;
1755         outname.append("testhw");
1756         outname.append(outNamePart2[j]);
1757         ImageSize imageSize = {P101TREE_ORIGINAL_WIDTH, P101TREE_ORIGINAL_HEIGHT, 0, 0, 0, 0};
1758         Coordinate coordinate = {1, 1};
1759         TranslateYuv420P010(outfmt[j], outname, imageSize, coordinate);
1760     }
1761     GTEST_LOG_(INFO) << "JpgYuvTest: P010JpgYuvTest006 end";
1762 }
1763 
1764 HWTEST_F(JpgYuvTest, JpgRgbaTest001, TestSize.Level3)
1765 {
1766     GTEST_LOG_(INFO) << "JpgYuvTest: JpgRgbaTest001 start";
1767     PixelFormat outfmt[] = {PixelFormat::RGBA_1010102};
1768     const char *outFileName[] = {"-RGBA_1010102.rgba"};
1769     for (int i = 0; i < sizeof(outfmt) / sizeof(outfmt[0]); ++i) {
1770         std::string outname;
1771         outname.append(outFileName[i]);
1772         ImageSize imageSize = {P101TREE_ORIGINAL_WIDTH, P101TREE_ORIGINAL_HEIGHT, 0, 0, 0, 0};
1773         RGBA1010102Crop(outfmt[i], outname, imageSize);
1774     }
1775     GTEST_LOG_(INFO) << "JpgYuvTest: JpgRgbaTest001 end";
1776 }
1777 
1778 HWTEST_F(JpgYuvTest, JpgRgbaTest002, TestSize.Level3)
1779 {
1780     GTEST_LOG_(INFO) << "JpgYuvTest: JpgRgbaTest002 start";
1781     PixelFormat outfmt[] = {PixelFormat::RGBA_1010102};
1782     float degrees[] = {90, 180, 270};
1783     int k = 0;
1784     const char *outFileName[] = {"90-rgba_1010102.rgba", "180-rgba_1010102.rgba", "270-rgba_1010102.rgba"};
1785     for (int i = 0; i < sizeof(outfmt) / sizeof(PixelFormat); ++i) {
1786         for (int j = 0; j < sizeof(degrees) / sizeof(float); ++j) {
1787             std::string outname;
1788             outname.append(outFileName[k++]);
1789             ImageSize imageSize = {P101TREE_ORIGINAL_WIDTH, P101TREE_ORIGINAL_HEIGHT, 0, 0, 0, 0};
1790             RGBA1010102Rotate(outfmt[i], outname, imageSize, degrees[j]);
1791         }
1792     }
1793     GTEST_LOG_(INFO) << "JpgYuvTest: JpgRgbaTest002 end";
1794 }
1795 HWTEST_F(JpgYuvTest, JpgRgbaTest003, TestSize.Level3)
1796 {
1797     GTEST_LOG_(INFO) << "JpgYuvTest: JpgRgbaTest003 start";
1798     PixelFormat outfmt[] = {PixelFormat::RGBA_1010102};
1799     const char *outNamePart2[] = {"-rgba_1010102.rgba"};
1800     AntiAliasingOption options[] = {AntiAliasingOption::NONE, AntiAliasingOption::LOW,
1801                                     AntiAliasingOption::MEDIUM, AntiAliasingOption::HIGH};
1802     std::filesystem::path dir("scale");
1803     if (!std::filesystem::exists(dir)) {
1804         ASSERT_EQ(std::filesystem::create_directory(dir), true);
1805     }
1806     for (size_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
1807         for (size_t i = 0; i < sizeof(options) / sizeof(AntiAliasingOption); i++) {
1808             std::string outname;
1809             outname.append("p010");
1810             switch (options[i]) {
1811                 case AntiAliasingOption::NONE:
1812                     outname.append("-NONE-");
1813                     break;
1814                 case AntiAliasingOption::LOW:
1815                     outname.append("-LOW-");
1816                     break;
1817                 case AntiAliasingOption::MEDIUM:
1818                     outname.append("-MEDIUM-");
1819                     break;
1820                 case AntiAliasingOption::HIGH:
1821                     outname.append("-HIGH-");
1822                     break;
1823                 default:
1824                     break;
1825             }
1826             outname.append(outNamePart2[j]);
1827             ImageSize imageSize = {P101TREE_ORIGINAL_WIDTH, P101TREE_ORIGINAL_HEIGHT, NUM_2, NUM_2, 0, 0};
1828             RGBA1010102Scale(outfmt[j], outname, imageSize, options[i]);
1829         }
1830     }
1831     GTEST_LOG_(INFO) << "JpgYuvTest: JpgRgbaTest003 end";
1832 }
1833 
1834 HWTEST_F(JpgYuvTest, JpgRgbaTest004, TestSize.Level3)
1835 {
1836     GTEST_LOG_(INFO) << "JpgYuvTest: JpgRgbaTest004 start";
1837     PixelFormat outfmt[] = {PixelFormat::RGBA_1010102};
1838     const char *outNamePart2[] = {"-rgba_1010102.rgba"};
1839     std::filesystem::path dir("resize");
1840     if (!std::filesystem::exists(dir)) {
1841         ASSERT_EQ(std::filesystem::create_directory(dir), true);
1842     }
1843     for (size_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
1844         std::string outname;
1845         outname.append(outNamePart2[j]);
1846         ImageSize imageSize = {P101TREE_ORIGINAL_WIDTH, P101TREE_ORIGINAL_HEIGHT, NUM_2, NUM_2, 0, 0};
1847         RGBA1010102Resize(outfmt[j], outname, imageSize);
1848     }
1849     GTEST_LOG_(INFO) << "JpgYuvTest: JpgRgbaTest004 end";
1850 }
1851 
1852 HWTEST_F(JpgYuvTest, JpgRgbaTest005, TestSize.Level3)
1853 {
1854     GTEST_LOG_(INFO) << "JpgYuvTest: JpgRgbaTest005 start";
1855     PixelFormat outfmt[] = {PixelFormat::RGBA_1010102};
1856     const char *outNamePart2[] = {"-rgba_1010102.rgba"};
1857     bool flips[4][2] = {{true, true}, {true, false}, {false, true}, {false, false}};
1858     std::filesystem::path dir("flip");
1859     if (!std::filesystem::exists(dir)) {
1860         ASSERT_EQ(std::filesystem::create_directory(dir), true);
1861     }
1862     for (size_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
1863         for (size_t i = 0; i < sizeof(flips) / (sizeof(bool) * 2); i++) {
1864             std::string outname;
1865             outname.append("testhw");
1866             switch (i) {
1867                 case 0:
1868                     outname.append("-xy-");
1869                     break;
1870                 case 1:
1871                     outname.append("-x-");
1872                     break;
1873                 case 2:
1874                     outname.append("-y-");
1875                     break;
1876                 case 3:
1877                     outname.append("-no-");
1878                     break;
1879                 default:
1880                     break;
1881             }
1882             outname.append(outNamePart2[j]);
1883             ImageSize imageSize = {P101TREE_ORIGINAL_WIDTH, P101TREE_ORIGINAL_HEIGHT, 0, 0, 0, 0};
1884             RGBA1010102Flip(outfmt[j], outname, imageSize, i);
1885         }
1886     }
1887     GTEST_LOG_(INFO) << "JpgYuvTest: JpgRgbaTest005 end";
1888 }
1889 
1890 HWTEST_F(JpgYuvTest, JpgRgbaTest006, TestSize.Level3)
1891 {
1892     GTEST_LOG_(INFO) << "JpgYuvTest: JpgRgbaTest006 start";
1893     PixelFormat outfmt[] = {PixelFormat::RGBA_1010102};
1894     const char *outNamePart2[] = {"-rgba_1010102.rgba"};
1895     std::filesystem::path dir("translate");
1896     if (!std::filesystem::exists(dir)) {
1897         ASSERT_EQ(std::filesystem::create_directory(dir), true);
1898     }
1899     for (size_t j = 0; j < sizeof(outfmt) / sizeof(PixelFormat); j++) {
1900         std::string outname;
1901         outname.append("testhw");
1902         outname.append(outNamePart2[j]);
1903         ImageSize imageSize = {P101TREE_ORIGINAL_WIDTH, P101TREE_ORIGINAL_HEIGHT, 0, 0, 0, 0};
1904         Coordinate coordinate = {1, 1};
1905         RGBA1010102Translate(outfmt[j], outname, imageSize, coordinate);
1906     }
1907     GTEST_LOG_(INFO) << "JpgYuvTest: JpgRgbaTest006 end";
1908 }
1909 }
1910 }