xref: /aosp_15_r20/external/libultrahdr/tests/editorhelper_test.cpp (revision 89a0ef05262152531a00a15832a2d3b1e3990773)
1*89a0ef05SAndroid Build Coastguard Worker /*
2*89a0ef05SAndroid Build Coastguard Worker  * Copyright 2024 The Android Open Source Project
3*89a0ef05SAndroid Build Coastguard Worker  *
4*89a0ef05SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*89a0ef05SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*89a0ef05SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*89a0ef05SAndroid Build Coastguard Worker  *
8*89a0ef05SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*89a0ef05SAndroid Build Coastguard Worker  *
10*89a0ef05SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*89a0ef05SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*89a0ef05SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*89a0ef05SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*89a0ef05SAndroid Build Coastguard Worker  * limitations under the License.
15*89a0ef05SAndroid Build Coastguard Worker  */
16*89a0ef05SAndroid Build Coastguard Worker 
17*89a0ef05SAndroid Build Coastguard Worker #include <gtest/gtest.h>
18*89a0ef05SAndroid Build Coastguard Worker 
19*89a0ef05SAndroid Build Coastguard Worker #include <fstream>
20*89a0ef05SAndroid Build Coastguard Worker #include <iostream>
21*89a0ef05SAndroid Build Coastguard Worker 
22*89a0ef05SAndroid Build Coastguard Worker #include "ultrahdr/editorhelper.h"
23*89a0ef05SAndroid Build Coastguard Worker 
24*89a0ef05SAndroid Build Coastguard Worker // #define DUMP_OUTPUT
25*89a0ef05SAndroid Build Coastguard Worker 
26*89a0ef05SAndroid Build Coastguard Worker #ifdef __ANDROID__
27*89a0ef05SAndroid Build Coastguard Worker #define INPUT_IMAGE "/data/local/tmp/raw_p010_image.p010"
28*89a0ef05SAndroid Build Coastguard Worker #else
29*89a0ef05SAndroid Build Coastguard Worker #define INPUT_IMAGE "./data/raw_p010_image.p010"
30*89a0ef05SAndroid Build Coastguard Worker #endif
31*89a0ef05SAndroid Build Coastguard Worker 
32*89a0ef05SAndroid Build Coastguard Worker #define OUTPUT_P010_IMAGE "output.p010"
33*89a0ef05SAndroid Build Coastguard Worker #define OUTPUT_YUV_IMAGE "output.yuv"
34*89a0ef05SAndroid Build Coastguard Worker #define OUTPUT_RGBA_IMAGE "output.rgb"
35*89a0ef05SAndroid Build Coastguard Worker 
36*89a0ef05SAndroid Build Coastguard Worker #ifdef DUMP_OUTPUT
writeFile(std::string prefixName,uhdr_raw_image_t * img)37*89a0ef05SAndroid Build Coastguard Worker static bool writeFile(std::string prefixName, uhdr_raw_image_t* img) {
38*89a0ef05SAndroid Build Coastguard Worker   char filename[50];
39*89a0ef05SAndroid Build Coastguard Worker 
40*89a0ef05SAndroid Build Coastguard Worker   if (img->fmt == UHDR_IMG_FMT_24bppYCbCrP010) {
41*89a0ef05SAndroid Build Coastguard Worker     snprintf(filename, sizeof filename, "%s_%d_%s", prefixName.c_str(), img->fmt,
42*89a0ef05SAndroid Build Coastguard Worker              OUTPUT_P010_IMAGE);
43*89a0ef05SAndroid Build Coastguard Worker   } else if (img->fmt == UHDR_IMG_FMT_12bppYCbCr420 || img->fmt == UHDR_IMG_FMT_8bppYCbCr400) {
44*89a0ef05SAndroid Build Coastguard Worker     snprintf(filename, sizeof filename, "%s_%d_%s", prefixName.c_str(), img->fmt, OUTPUT_YUV_IMAGE);
45*89a0ef05SAndroid Build Coastguard Worker   } else if (img->fmt == UHDR_IMG_FMT_32bppRGBA1010102 || img->fmt == UHDR_IMG_FMT_32bppRGBA8888 ||
46*89a0ef05SAndroid Build Coastguard Worker              img->fmt == UHDR_IMG_FMT_64bppRGBAHalfFloat) {
47*89a0ef05SAndroid Build Coastguard Worker     snprintf(filename, sizeof filename, "%s_%d_%s", prefixName.c_str(), img->fmt,
48*89a0ef05SAndroid Build Coastguard Worker              OUTPUT_RGBA_IMAGE);
49*89a0ef05SAndroid Build Coastguard Worker   } else {
50*89a0ef05SAndroid Build Coastguard Worker     return false;
51*89a0ef05SAndroid Build Coastguard Worker   }
52*89a0ef05SAndroid Build Coastguard Worker 
53*89a0ef05SAndroid Build Coastguard Worker   std::ofstream ofd(filename, std::ios::binary);
54*89a0ef05SAndroid Build Coastguard Worker   if (ofd.is_open()) {
55*89a0ef05SAndroid Build Coastguard Worker     int bpp = 1;
56*89a0ef05SAndroid Build Coastguard Worker 
57*89a0ef05SAndroid Build Coastguard Worker     if (img->fmt == UHDR_IMG_FMT_24bppYCbCrP010) {
58*89a0ef05SAndroid Build Coastguard Worker       bpp = 2;
59*89a0ef05SAndroid Build Coastguard Worker     } else if (img->fmt == UHDR_IMG_FMT_32bppRGBA8888 ||
60*89a0ef05SAndroid Build Coastguard Worker                img->fmt == UHDR_IMG_FMT_32bppRGBA1010102) {
61*89a0ef05SAndroid Build Coastguard Worker       bpp = 4;
62*89a0ef05SAndroid Build Coastguard Worker     } else if (img->fmt == UHDR_IMG_FMT_64bppRGBAHalfFloat) {
63*89a0ef05SAndroid Build Coastguard Worker       bpp = 8;
64*89a0ef05SAndroid Build Coastguard Worker     }
65*89a0ef05SAndroid Build Coastguard Worker 
66*89a0ef05SAndroid Build Coastguard Worker     const char* data = static_cast<char*>(img->planes[UHDR_PLANE_Y]);
67*89a0ef05SAndroid Build Coastguard Worker     size_t stride = img->stride[UHDR_PLANE_Y] * bpp;
68*89a0ef05SAndroid Build Coastguard Worker     size_t length = img->w * bpp;
69*89a0ef05SAndroid Build Coastguard Worker     for (unsigned i = 0; i < img->h; i++, data += stride) {
70*89a0ef05SAndroid Build Coastguard Worker       ofd.write(data, length);
71*89a0ef05SAndroid Build Coastguard Worker     }
72*89a0ef05SAndroid Build Coastguard Worker 
73*89a0ef05SAndroid Build Coastguard Worker     if (img->fmt == UHDR_IMG_FMT_24bppYCbCrP010) {
74*89a0ef05SAndroid Build Coastguard Worker       data = static_cast<char*>(img->planes[UHDR_PLANE_UV]);
75*89a0ef05SAndroid Build Coastguard Worker       stride = img->stride[UHDR_PLANE_UV] * bpp;
76*89a0ef05SAndroid Build Coastguard Worker       length = img->w * bpp;
77*89a0ef05SAndroid Build Coastguard Worker       for (unsigned i = 0; i < img->h / 2; i++, data += stride) {
78*89a0ef05SAndroid Build Coastguard Worker         ofd.write(data, length);
79*89a0ef05SAndroid Build Coastguard Worker       }
80*89a0ef05SAndroid Build Coastguard Worker     } else if (img->fmt == UHDR_IMG_FMT_12bppYCbCr420) {
81*89a0ef05SAndroid Build Coastguard Worker       data = static_cast<char*>(img->planes[UHDR_PLANE_U]);
82*89a0ef05SAndroid Build Coastguard Worker       stride = img->stride[UHDR_PLANE_U] * bpp;
83*89a0ef05SAndroid Build Coastguard Worker       length = (img->w / 2) * bpp;
84*89a0ef05SAndroid Build Coastguard Worker       for (unsigned i = 0; i < img->h / 2; i++, data += stride) {
85*89a0ef05SAndroid Build Coastguard Worker         ofd.write(data, length);
86*89a0ef05SAndroid Build Coastguard Worker       }
87*89a0ef05SAndroid Build Coastguard Worker       data = static_cast<char*>(img->planes[UHDR_PLANE_V]);
88*89a0ef05SAndroid Build Coastguard Worker       stride = img->stride[UHDR_PLANE_V] * bpp;
89*89a0ef05SAndroid Build Coastguard Worker       length = (img->w / 2) * bpp;
90*89a0ef05SAndroid Build Coastguard Worker       for (unsigned i = 0; i < img->h / 2; i++, data += stride) {
91*89a0ef05SAndroid Build Coastguard Worker         ofd.write(data, length);
92*89a0ef05SAndroid Build Coastguard Worker       }
93*89a0ef05SAndroid Build Coastguard Worker     }
94*89a0ef05SAndroid Build Coastguard Worker     return true;
95*89a0ef05SAndroid Build Coastguard Worker   }
96*89a0ef05SAndroid Build Coastguard Worker   std::cerr << "unable to write to file : " << filename << std::endl;
97*89a0ef05SAndroid Build Coastguard Worker   return false;
98*89a0ef05SAndroid Build Coastguard Worker }
99*89a0ef05SAndroid Build Coastguard Worker #endif
100*89a0ef05SAndroid Build Coastguard Worker 
101*89a0ef05SAndroid Build Coastguard Worker namespace ultrahdr {
102*89a0ef05SAndroid Build Coastguard Worker 
loadFile(const char * filename,uhdr_raw_image_t * handle)103*89a0ef05SAndroid Build Coastguard Worker static bool loadFile(const char* filename, uhdr_raw_image_t* handle) {
104*89a0ef05SAndroid Build Coastguard Worker   std::ifstream ifd(filename, std::ios::binary);
105*89a0ef05SAndroid Build Coastguard Worker   if (ifd.good()) {
106*89a0ef05SAndroid Build Coastguard Worker     if (handle->fmt == UHDR_IMG_FMT_24bppYCbCrP010) {
107*89a0ef05SAndroid Build Coastguard Worker       const int bpp = 2;
108*89a0ef05SAndroid Build Coastguard Worker       ifd.read(static_cast<char*>(handle->planes[UHDR_PLANE_Y]), handle->w * handle->h * bpp);
109*89a0ef05SAndroid Build Coastguard Worker       ifd.read(static_cast<char*>(handle->planes[UHDR_PLANE_UV]),
110*89a0ef05SAndroid Build Coastguard Worker                (handle->w / 2) * (handle->h / 2) * bpp * 2);
111*89a0ef05SAndroid Build Coastguard Worker       return true;
112*89a0ef05SAndroid Build Coastguard Worker     } else if (handle->fmt == UHDR_IMG_FMT_12bppYCbCr420) {
113*89a0ef05SAndroid Build Coastguard Worker       ifd.read(static_cast<char*>(handle->planes[UHDR_PLANE_Y]), handle->w * handle->h);
114*89a0ef05SAndroid Build Coastguard Worker       ifd.read(static_cast<char*>(handle->planes[UHDR_PLANE_U]), (handle->w / 2) * (handle->h / 2));
115*89a0ef05SAndroid Build Coastguard Worker       ifd.read(static_cast<char*>(handle->planes[UHDR_PLANE_V]), (handle->w / 2) * (handle->h / 2));
116*89a0ef05SAndroid Build Coastguard Worker       return true;
117*89a0ef05SAndroid Build Coastguard Worker     } else if (handle->fmt == UHDR_IMG_FMT_32bppRGBA8888 ||
118*89a0ef05SAndroid Build Coastguard Worker                handle->fmt == UHDR_IMG_FMT_64bppRGBAHalfFloat ||
119*89a0ef05SAndroid Build Coastguard Worker                handle->fmt == UHDR_IMG_FMT_32bppRGBA1010102) {
120*89a0ef05SAndroid Build Coastguard Worker       int bpp = handle->fmt == UHDR_IMG_FMT_64bppRGBAHalfFloat ? 8 : 4;
121*89a0ef05SAndroid Build Coastguard Worker       ifd.read(static_cast<char*>(handle->planes[UHDR_PLANE_PACKED]), handle->w * handle->h * bpp);
122*89a0ef05SAndroid Build Coastguard Worker       return true;
123*89a0ef05SAndroid Build Coastguard Worker     } else if (handle->fmt == UHDR_IMG_FMT_8bppYCbCr400) {
124*89a0ef05SAndroid Build Coastguard Worker       ifd.read(static_cast<char*>(handle->planes[UHDR_PLANE_Y]), handle->w * handle->h);
125*89a0ef05SAndroid Build Coastguard Worker       return true;
126*89a0ef05SAndroid Build Coastguard Worker     }
127*89a0ef05SAndroid Build Coastguard Worker     return false;
128*89a0ef05SAndroid Build Coastguard Worker   }
129*89a0ef05SAndroid Build Coastguard Worker   std::cerr << "unable to open file : " << filename << std::endl;
130*89a0ef05SAndroid Build Coastguard Worker   return false;
131*89a0ef05SAndroid Build Coastguard Worker }
132*89a0ef05SAndroid Build Coastguard Worker 
initImageHandle(uhdr_raw_image_t * handle,int width,int height,uhdr_img_fmt_t format)133*89a0ef05SAndroid Build Coastguard Worker void initImageHandle(uhdr_raw_image_t* handle, int width, int height, uhdr_img_fmt_t format) {
134*89a0ef05SAndroid Build Coastguard Worker   handle->fmt = format;
135*89a0ef05SAndroid Build Coastguard Worker   handle->cg = UHDR_CG_DISPLAY_P3;
136*89a0ef05SAndroid Build Coastguard Worker   handle->ct = UHDR_CT_SRGB;
137*89a0ef05SAndroid Build Coastguard Worker   handle->range = UHDR_CR_UNSPECIFIED;
138*89a0ef05SAndroid Build Coastguard Worker   handle->w = width;
139*89a0ef05SAndroid Build Coastguard Worker   handle->h = height;
140*89a0ef05SAndroid Build Coastguard Worker   if (handle->fmt == UHDR_IMG_FMT_24bppYCbCrP010) {
141*89a0ef05SAndroid Build Coastguard Worker     handle->planes[UHDR_PLANE_Y] = malloc(width * height * 2);
142*89a0ef05SAndroid Build Coastguard Worker     handle->planes[UHDR_PLANE_UV] = malloc((width / 2) * (height / 2) * 2 * 2);
143*89a0ef05SAndroid Build Coastguard Worker     handle->planes[UHDR_PLANE_V] = nullptr;
144*89a0ef05SAndroid Build Coastguard Worker     handle->stride[UHDR_PLANE_Y] = width;
145*89a0ef05SAndroid Build Coastguard Worker     handle->stride[UHDR_PLANE_UV] = width;
146*89a0ef05SAndroid Build Coastguard Worker     handle->stride[UHDR_PLANE_V] = 0;
147*89a0ef05SAndroid Build Coastguard Worker   } else if (handle->fmt == UHDR_IMG_FMT_12bppYCbCr420) {
148*89a0ef05SAndroid Build Coastguard Worker     handle->planes[UHDR_PLANE_Y] = malloc(width * height);
149*89a0ef05SAndroid Build Coastguard Worker     handle->planes[UHDR_PLANE_U] = malloc((width / 2) * (height / 2));
150*89a0ef05SAndroid Build Coastguard Worker     handle->planes[UHDR_PLANE_V] = malloc((width / 2) * (height / 2));
151*89a0ef05SAndroid Build Coastguard Worker     handle->stride[UHDR_PLANE_Y] = width;
152*89a0ef05SAndroid Build Coastguard Worker     handle->stride[UHDR_PLANE_U] = width / 2;
153*89a0ef05SAndroid Build Coastguard Worker     handle->stride[UHDR_PLANE_V] = width / 2;
154*89a0ef05SAndroid Build Coastguard Worker   } else if (handle->fmt == UHDR_IMG_FMT_32bppRGBA8888 ||
155*89a0ef05SAndroid Build Coastguard Worker              handle->fmt == UHDR_IMG_FMT_64bppRGBAHalfFloat ||
156*89a0ef05SAndroid Build Coastguard Worker              handle->fmt == UHDR_IMG_FMT_32bppRGBA1010102) {
157*89a0ef05SAndroid Build Coastguard Worker     int bpp = handle->fmt == UHDR_IMG_FMT_64bppRGBAHalfFloat ? 8 : 4;
158*89a0ef05SAndroid Build Coastguard Worker     handle->planes[UHDR_PLANE_PACKED] = malloc(width * height * bpp);
159*89a0ef05SAndroid Build Coastguard Worker     handle->planes[UHDR_PLANE_U] = nullptr;
160*89a0ef05SAndroid Build Coastguard Worker     handle->planes[UHDR_PLANE_V] = nullptr;
161*89a0ef05SAndroid Build Coastguard Worker     handle->stride[UHDR_PLANE_PACKED] = width;
162*89a0ef05SAndroid Build Coastguard Worker     handle->stride[UHDR_PLANE_U] = 0;
163*89a0ef05SAndroid Build Coastguard Worker     handle->stride[UHDR_PLANE_V] = 0;
164*89a0ef05SAndroid Build Coastguard Worker   } else if (handle->fmt == UHDR_IMG_FMT_8bppYCbCr400) {
165*89a0ef05SAndroid Build Coastguard Worker     handle->planes[UHDR_PLANE_Y] = malloc(width * height);
166*89a0ef05SAndroid Build Coastguard Worker     handle->planes[UHDR_PLANE_U] = nullptr;
167*89a0ef05SAndroid Build Coastguard Worker     handle->planes[UHDR_PLANE_V] = nullptr;
168*89a0ef05SAndroid Build Coastguard Worker     handle->stride[UHDR_PLANE_Y] = width;
169*89a0ef05SAndroid Build Coastguard Worker     handle->stride[UHDR_PLANE_U] = 0;
170*89a0ef05SAndroid Build Coastguard Worker     handle->stride[UHDR_PLANE_V] = 0;
171*89a0ef05SAndroid Build Coastguard Worker   }
172*89a0ef05SAndroid Build Coastguard Worker }
173*89a0ef05SAndroid Build Coastguard Worker 
compare_planes(void * ref_plane,void * test_plane,int ref_stride,int test_stride,int width,int height,int bpp)174*89a0ef05SAndroid Build Coastguard Worker void compare_planes(void* ref_plane, void* test_plane, int ref_stride, int test_stride, int width,
175*89a0ef05SAndroid Build Coastguard Worker                     int height, int bpp) {
176*89a0ef05SAndroid Build Coastguard Worker   uint8_t* ref = (uint8_t*)ref_plane;
177*89a0ef05SAndroid Build Coastguard Worker   uint8_t* test = (uint8_t*)test_plane;
178*89a0ef05SAndroid Build Coastguard Worker   const size_t length = width * bpp;
179*89a0ef05SAndroid Build Coastguard Worker 
180*89a0ef05SAndroid Build Coastguard Worker   for (int i = 0; i < height; i++, ref += (ref_stride * bpp), test += (test_stride * bpp)) {
181*89a0ef05SAndroid Build Coastguard Worker     ASSERT_EQ(0, memcmp(ref, test, length));
182*89a0ef05SAndroid Build Coastguard Worker   }
183*89a0ef05SAndroid Build Coastguard Worker }
184*89a0ef05SAndroid Build Coastguard Worker 
compareImg(uhdr_raw_image_t * ref,uhdr_raw_image_t * test)185*89a0ef05SAndroid Build Coastguard Worker void compareImg(uhdr_raw_image_t* ref, uhdr_raw_image_t* test) {
186*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(ref->fmt, test->fmt);
187*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(ref->cg, test->cg);
188*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(ref->ct, test->ct);
189*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(ref->range, test->range);
190*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(ref->w, test->w);
191*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(ref->h, test->h);
192*89a0ef05SAndroid Build Coastguard Worker   int bpp = 1;
193*89a0ef05SAndroid Build Coastguard Worker   if (ref->fmt == UHDR_IMG_FMT_24bppYCbCrP010) {
194*89a0ef05SAndroid Build Coastguard Worker     bpp = 2;
195*89a0ef05SAndroid Build Coastguard Worker     compare_planes(ref->planes[UHDR_PLANE_Y], test->planes[UHDR_PLANE_Y], ref->stride[UHDR_PLANE_Y],
196*89a0ef05SAndroid Build Coastguard Worker                    test->stride[UHDR_PLANE_Y], ref->w, ref->h, bpp);
197*89a0ef05SAndroid Build Coastguard Worker     compare_planes(ref->planes[UHDR_PLANE_UV], test->planes[UHDR_PLANE_UV],
198*89a0ef05SAndroid Build Coastguard Worker                    ref->stride[UHDR_PLANE_UV], test->stride[UHDR_PLANE_UV], ref->w, ref->h / 2,
199*89a0ef05SAndroid Build Coastguard Worker                    bpp);
200*89a0ef05SAndroid Build Coastguard Worker   } else if (ref->fmt == UHDR_IMG_FMT_12bppYCbCr420) {
201*89a0ef05SAndroid Build Coastguard Worker     compare_planes(ref->planes[UHDR_PLANE_Y], test->planes[UHDR_PLANE_Y], ref->stride[UHDR_PLANE_Y],
202*89a0ef05SAndroid Build Coastguard Worker                    test->stride[UHDR_PLANE_Y], ref->w, ref->h, bpp);
203*89a0ef05SAndroid Build Coastguard Worker     compare_planes(ref->planes[UHDR_PLANE_U], test->planes[UHDR_PLANE_U], ref->stride[UHDR_PLANE_U],
204*89a0ef05SAndroid Build Coastguard Worker                    test->stride[UHDR_PLANE_U], ref->w / 2, ref->h / 2, bpp);
205*89a0ef05SAndroid Build Coastguard Worker     compare_planes(ref->planes[UHDR_PLANE_V], test->planes[UHDR_PLANE_V], ref->stride[UHDR_PLANE_V],
206*89a0ef05SAndroid Build Coastguard Worker                    test->stride[UHDR_PLANE_V], ref->w / 2, ref->h / 2, bpp);
207*89a0ef05SAndroid Build Coastguard Worker   } else if (ref->fmt == UHDR_IMG_FMT_32bppRGBA8888 || ref->fmt == UHDR_IMG_FMT_32bppRGBA1010102 ||
208*89a0ef05SAndroid Build Coastguard Worker              ref->fmt == UHDR_IMG_FMT_64bppRGBAHalfFloat) {
209*89a0ef05SAndroid Build Coastguard Worker     bpp = ref->fmt == UHDR_IMG_FMT_64bppRGBAHalfFloat ? 8 : 4;
210*89a0ef05SAndroid Build Coastguard Worker     compare_planes(ref->planes[UHDR_PLANE_PACKED], test->planes[UHDR_PLANE_PACKED],
211*89a0ef05SAndroid Build Coastguard Worker                    ref->stride[UHDR_PLANE_PACKED], test->stride[UHDR_PLANE_PACKED], ref->w, ref->h,
212*89a0ef05SAndroid Build Coastguard Worker                    bpp);
213*89a0ef05SAndroid Build Coastguard Worker   } else if (ref->fmt == UHDR_IMG_FMT_8bppYCbCr400) {
214*89a0ef05SAndroid Build Coastguard Worker     compare_planes(ref->planes[UHDR_PLANE_Y], test->planes[UHDR_PLANE_Y], ref->stride[UHDR_PLANE_Y],
215*89a0ef05SAndroid Build Coastguard Worker                    test->stride[UHDR_PLANE_Y], ref->w, ref->h, bpp);
216*89a0ef05SAndroid Build Coastguard Worker   }
217*89a0ef05SAndroid Build Coastguard Worker }
218*89a0ef05SAndroid Build Coastguard Worker 
219*89a0ef05SAndroid Build Coastguard Worker class EditorHelperTest
220*89a0ef05SAndroid Build Coastguard Worker     : public ::testing::TestWithParam<std::tuple<std::string, int, int, uhdr_img_fmt_t>> {
221*89a0ef05SAndroid Build Coastguard Worker  public:
EditorHelperTest()222*89a0ef05SAndroid Build Coastguard Worker   EditorHelperTest()
223*89a0ef05SAndroid Build Coastguard Worker       : filename(std::get<0>(GetParam())),
224*89a0ef05SAndroid Build Coastguard Worker         width(std::get<1>(GetParam())),
225*89a0ef05SAndroid Build Coastguard Worker         height(std::get<2>(GetParam())),
226*89a0ef05SAndroid Build Coastguard Worker         fmt(std::get<3>(GetParam())) {
227*89a0ef05SAndroid Build Coastguard Worker #ifdef UHDR_ENABLE_GLES
228*89a0ef05SAndroid Build Coastguard Worker     gl_ctxt = new uhdr_opengl_ctxt();
229*89a0ef05SAndroid Build Coastguard Worker     opengl_ctxt = static_cast<uhdr_opengl_ctxt*>(gl_ctxt);
230*89a0ef05SAndroid Build Coastguard Worker     opengl_ctxt->init_opengl_ctxt();
231*89a0ef05SAndroid Build Coastguard Worker     if (opengl_ctxt->mErrorStatus.error_code != UHDR_CODEC_OK) {
232*89a0ef05SAndroid Build Coastguard Worker       opengl_ctxt->delete_opengl_ctxt();
233*89a0ef05SAndroid Build Coastguard Worker       delete opengl_ctxt;
234*89a0ef05SAndroid Build Coastguard Worker       gl_ctxt = nullptr;
235*89a0ef05SAndroid Build Coastguard Worker     }
236*89a0ef05SAndroid Build Coastguard Worker #endif
237*89a0ef05SAndroid Build Coastguard Worker   };
238*89a0ef05SAndroid Build Coastguard Worker 
~EditorHelperTest()239*89a0ef05SAndroid Build Coastguard Worker   ~EditorHelperTest() {
240*89a0ef05SAndroid Build Coastguard Worker     int count = sizeof img_a.planes / sizeof img_a.planes[0];
241*89a0ef05SAndroid Build Coastguard Worker     for (int i = 0; i < count; i++) {
242*89a0ef05SAndroid Build Coastguard Worker       if (img_a.planes[i]) {
243*89a0ef05SAndroid Build Coastguard Worker         free(img_a.planes[i]);
244*89a0ef05SAndroid Build Coastguard Worker         img_a.planes[i] = nullptr;
245*89a0ef05SAndroid Build Coastguard Worker       }
246*89a0ef05SAndroid Build Coastguard Worker     }
247*89a0ef05SAndroid Build Coastguard Worker #ifdef UHDR_ENABLE_GLES
248*89a0ef05SAndroid Build Coastguard Worker     if (gl_ctxt) {
249*89a0ef05SAndroid Build Coastguard Worker       uhdr_opengl_ctxt* opengl_ctxt = static_cast<uhdr_opengl_ctxt*>(gl_ctxt);
250*89a0ef05SAndroid Build Coastguard Worker       opengl_ctxt->delete_opengl_ctxt();
251*89a0ef05SAndroid Build Coastguard Worker       delete opengl_ctxt;
252*89a0ef05SAndroid Build Coastguard Worker     }
253*89a0ef05SAndroid Build Coastguard Worker     if (Texture) glDeleteTextures(1, &Texture);
254*89a0ef05SAndroid Build Coastguard Worker #endif
255*89a0ef05SAndroid Build Coastguard Worker   }
256*89a0ef05SAndroid Build Coastguard Worker 
257*89a0ef05SAndroid Build Coastguard Worker   std::string filename;
258*89a0ef05SAndroid Build Coastguard Worker   int width;
259*89a0ef05SAndroid Build Coastguard Worker   int height;
260*89a0ef05SAndroid Build Coastguard Worker   uhdr_img_fmt_t fmt;
261*89a0ef05SAndroid Build Coastguard Worker   uhdr_raw_image_t img_a{};
262*89a0ef05SAndroid Build Coastguard Worker   void* gl_ctxt = nullptr;
263*89a0ef05SAndroid Build Coastguard Worker   void* texture = nullptr;
264*89a0ef05SAndroid Build Coastguard Worker #ifdef UHDR_ENABLE_GLES
265*89a0ef05SAndroid Build Coastguard Worker   GLuint Texture = 0;
266*89a0ef05SAndroid Build Coastguard Worker   uhdr_opengl_ctxt* opengl_ctxt = nullptr;
267*89a0ef05SAndroid Build Coastguard Worker #endif
268*89a0ef05SAndroid Build Coastguard Worker };
269*89a0ef05SAndroid Build Coastguard Worker 
TEST_P(EditorHelperTest,Rotate)270*89a0ef05SAndroid Build Coastguard Worker TEST_P(EditorHelperTest, Rotate) {
271*89a0ef05SAndroid Build Coastguard Worker   initImageHandle(&img_a, width, height, fmt);
272*89a0ef05SAndroid Build Coastguard Worker   ASSERT_TRUE(loadFile(filename.c_str(), &img_a)) << "unable to load file " << filename;
273*89a0ef05SAndroid Build Coastguard Worker   ultrahdr::uhdr_rotate_effect_t r90(90), r180(180), r270(270);
274*89a0ef05SAndroid Build Coastguard Worker #ifdef UHDR_ENABLE_GLES
275*89a0ef05SAndroid Build Coastguard Worker   if (gl_ctxt != nullptr) {
276*89a0ef05SAndroid Build Coastguard Worker     Texture = opengl_ctxt->create_texture(img_a.fmt, img_a.w, img_a.h, img_a.planes[0]);
277*89a0ef05SAndroid Build Coastguard Worker     texture = static_cast<void*>(&Texture);
278*89a0ef05SAndroid Build Coastguard Worker   }
279*89a0ef05SAndroid Build Coastguard Worker #endif
280*89a0ef05SAndroid Build Coastguard Worker   auto dst = apply_rotate(&r90, &img_a, gl_ctxt, texture);
281*89a0ef05SAndroid Build Coastguard Worker   dst = apply_rotate(&r90, dst.get(), gl_ctxt, texture);
282*89a0ef05SAndroid Build Coastguard Worker   dst = apply_rotate(&r180, dst.get(), gl_ctxt, texture);
283*89a0ef05SAndroid Build Coastguard Worker   dst = apply_rotate(&r270, dst.get(), gl_ctxt, texture);
284*89a0ef05SAndroid Build Coastguard Worker   dst = apply_rotate(&r90, dst.get(), gl_ctxt, texture);
285*89a0ef05SAndroid Build Coastguard Worker   dst = apply_rotate(&r90, dst.get(), gl_ctxt, texture);
286*89a0ef05SAndroid Build Coastguard Worker   dst = apply_rotate(&r270, dst.get(), gl_ctxt, texture);
287*89a0ef05SAndroid Build Coastguard Worker #ifdef UHDR_ENABLE_GLES
288*89a0ef05SAndroid Build Coastguard Worker   if (gl_ctxt != nullptr) {
289*89a0ef05SAndroid Build Coastguard Worker     opengl_ctxt->read_texture(static_cast<GLuint*>(texture), dst->fmt, dst->w, dst->h,
290*89a0ef05SAndroid Build Coastguard Worker                               dst->planes[0]);
291*89a0ef05SAndroid Build Coastguard Worker   }
292*89a0ef05SAndroid Build Coastguard Worker #endif
293*89a0ef05SAndroid Build Coastguard Worker   ASSERT_NO_FATAL_FAILURE(compareImg(&img_a, dst.get()))
294*89a0ef05SAndroid Build Coastguard Worker       << "failed for resolution " << width << " x " << height << " format: " << fmt;
295*89a0ef05SAndroid Build Coastguard Worker }
296*89a0ef05SAndroid Build Coastguard Worker 
TEST_P(EditorHelperTest,Mirror)297*89a0ef05SAndroid Build Coastguard Worker TEST_P(EditorHelperTest, Mirror) {
298*89a0ef05SAndroid Build Coastguard Worker   initImageHandle(&img_a, width, height, fmt);
299*89a0ef05SAndroid Build Coastguard Worker   ASSERT_TRUE(loadFile(filename.c_str(), &img_a)) << "unable to load file " << filename;
300*89a0ef05SAndroid Build Coastguard Worker   ultrahdr::uhdr_mirror_effect_t mhorz(UHDR_MIRROR_HORIZONTAL), mvert(UHDR_MIRROR_VERTICAL);
301*89a0ef05SAndroid Build Coastguard Worker #ifdef UHDR_ENABLE_GLES
302*89a0ef05SAndroid Build Coastguard Worker   if (gl_ctxt != nullptr) {
303*89a0ef05SAndroid Build Coastguard Worker     Texture = opengl_ctxt->create_texture(img_a.fmt, img_a.w, img_a.h, img_a.planes[0]);
304*89a0ef05SAndroid Build Coastguard Worker     texture = static_cast<void*>(&Texture);
305*89a0ef05SAndroid Build Coastguard Worker   }
306*89a0ef05SAndroid Build Coastguard Worker #endif
307*89a0ef05SAndroid Build Coastguard Worker   auto dst = apply_mirror(&mhorz, &img_a, gl_ctxt, texture);
308*89a0ef05SAndroid Build Coastguard Worker   dst = apply_mirror(&mvert, dst.get(), gl_ctxt, texture);
309*89a0ef05SAndroid Build Coastguard Worker   dst = apply_mirror(&mhorz, dst.get(), gl_ctxt, texture);
310*89a0ef05SAndroid Build Coastguard Worker   dst = apply_mirror(&mvert, dst.get(), gl_ctxt, texture);
311*89a0ef05SAndroid Build Coastguard Worker #ifdef UHDR_ENABLE_GLES
312*89a0ef05SAndroid Build Coastguard Worker   if (gl_ctxt != nullptr) {
313*89a0ef05SAndroid Build Coastguard Worker     opengl_ctxt->read_texture(static_cast<GLuint*>(texture), dst->fmt, dst->w, dst->h,
314*89a0ef05SAndroid Build Coastguard Worker                               dst->planes[0]);
315*89a0ef05SAndroid Build Coastguard Worker   }
316*89a0ef05SAndroid Build Coastguard Worker #endif
317*89a0ef05SAndroid Build Coastguard Worker   ASSERT_NO_FATAL_FAILURE(compareImg(&img_a, dst.get()))
318*89a0ef05SAndroid Build Coastguard Worker       << "failed for resolution " << width << " x " << height << " format: " << fmt;
319*89a0ef05SAndroid Build Coastguard Worker }
320*89a0ef05SAndroid Build Coastguard Worker 
TEST_P(EditorHelperTest,Crop)321*89a0ef05SAndroid Build Coastguard Worker TEST_P(EditorHelperTest, Crop) {
322*89a0ef05SAndroid Build Coastguard Worker   const int left = 16;
323*89a0ef05SAndroid Build Coastguard Worker   const int top = 16;
324*89a0ef05SAndroid Build Coastguard Worker   const int crop_wd = 32;
325*89a0ef05SAndroid Build Coastguard Worker   const int crop_ht = 32;
326*89a0ef05SAndroid Build Coastguard Worker 
327*89a0ef05SAndroid Build Coastguard Worker   if (width < (left + crop_wd) || height <= (top + crop_ht)) {
328*89a0ef05SAndroid Build Coastguard Worker     GTEST_SKIP() << "Test skipped as crop attributes are too large for resolution " +
329*89a0ef05SAndroid Build Coastguard Worker                         std::to_string(width) + " x " + std::to_string(height) +
330*89a0ef05SAndroid Build Coastguard Worker                         " format: " + std::to_string(fmt);
331*89a0ef05SAndroid Build Coastguard Worker   }
332*89a0ef05SAndroid Build Coastguard Worker   std::string msg = "failed for resolution " + std::to_string(width) + " x " +
333*89a0ef05SAndroid Build Coastguard Worker                     std::to_string(height) + " format: " + std::to_string(fmt);
334*89a0ef05SAndroid Build Coastguard Worker   initImageHandle(&img_a, width, height, fmt);
335*89a0ef05SAndroid Build Coastguard Worker   ASSERT_TRUE(loadFile(filename.c_str(), &img_a)) << "unable to load file " << filename;
336*89a0ef05SAndroid Build Coastguard Worker   ultrahdr::uhdr_crop_effect_t crop(left, left + crop_wd, top, top + crop_ht);
337*89a0ef05SAndroid Build Coastguard Worker #ifdef UHDR_ENABLE_GLES
338*89a0ef05SAndroid Build Coastguard Worker   if (gl_ctxt != nullptr) {
339*89a0ef05SAndroid Build Coastguard Worker     Texture = opengl_ctxt->create_texture(img_a.fmt, img_a.w, img_a.h, img_a.planes[0]);
340*89a0ef05SAndroid Build Coastguard Worker     texture = static_cast<void*>(&Texture);
341*89a0ef05SAndroid Build Coastguard Worker   }
342*89a0ef05SAndroid Build Coastguard Worker #endif
343*89a0ef05SAndroid Build Coastguard Worker   auto dst = apply_crop(&crop, &img_a, left, top, crop_wd, crop_ht, gl_ctxt, texture);
344*89a0ef05SAndroid Build Coastguard Worker #ifdef UHDR_ENABLE_GLES
345*89a0ef05SAndroid Build Coastguard Worker   if (gl_ctxt != nullptr) {
346*89a0ef05SAndroid Build Coastguard Worker     opengl_ctxt->read_texture(static_cast<GLuint*>(texture), dst->fmt, dst->w, dst->h,
347*89a0ef05SAndroid Build Coastguard Worker                               dst->planes[0]);
348*89a0ef05SAndroid Build Coastguard Worker   }
349*89a0ef05SAndroid Build Coastguard Worker #endif
350*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(img_a.fmt, dst->fmt) << msg;
351*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(img_a.cg, dst->cg) << msg;
352*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(img_a.ct, dst->ct) << msg;
353*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(img_a.range, dst->range) << msg;
354*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(dst->w, crop_wd) << msg;
355*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(dst->h, crop_ht) << msg;
356*89a0ef05SAndroid Build Coastguard Worker #ifdef DUMP_OUTPUT
357*89a0ef05SAndroid Build Coastguard Worker   if (!writeFile("cropped", dst.get())) {
358*89a0ef05SAndroid Build Coastguard Worker     std::cerr << "unable to write output file" << std::endl;
359*89a0ef05SAndroid Build Coastguard Worker   }
360*89a0ef05SAndroid Build Coastguard Worker #endif
361*89a0ef05SAndroid Build Coastguard Worker }
362*89a0ef05SAndroid Build Coastguard Worker 
TEST_P(EditorHelperTest,Resize)363*89a0ef05SAndroid Build Coastguard Worker TEST_P(EditorHelperTest, Resize) {
364*89a0ef05SAndroid Build Coastguard Worker   if ((fmt == UHDR_IMG_FMT_12bppYCbCr420 || UHDR_IMG_FMT_24bppYCbCrP010) &&
365*89a0ef05SAndroid Build Coastguard Worker       (((width / 2) % 2 != 0) || ((height / 2) % 2 != 0))) {
366*89a0ef05SAndroid Build Coastguard Worker     GTEST_SKIP() << "Test skipped for resolution " + std::to_string(width) + " x " +
367*89a0ef05SAndroid Build Coastguard Worker                         std::to_string(height) + " format: " + std::to_string(fmt);
368*89a0ef05SAndroid Build Coastguard Worker   }
369*89a0ef05SAndroid Build Coastguard Worker   std::string msg = "failed for resolution " + std::to_string(width) + " x " +
370*89a0ef05SAndroid Build Coastguard Worker                     std::to_string(height) + " format: " + std::to_string(fmt);
371*89a0ef05SAndroid Build Coastguard Worker   initImageHandle(&img_a, width, height, fmt);
372*89a0ef05SAndroid Build Coastguard Worker   ASSERT_TRUE(loadFile(filename.c_str(), &img_a)) << "unable to load file " << filename;
373*89a0ef05SAndroid Build Coastguard Worker   ultrahdr::uhdr_resize_effect_t resize(width / 2, height / 2);
374*89a0ef05SAndroid Build Coastguard Worker #ifdef UHDR_ENABLE_GLES
375*89a0ef05SAndroid Build Coastguard Worker   if (gl_ctxt != nullptr) {
376*89a0ef05SAndroid Build Coastguard Worker     Texture = opengl_ctxt->create_texture(img_a.fmt, img_a.w, img_a.h, img_a.planes[0]);
377*89a0ef05SAndroid Build Coastguard Worker     texture = static_cast<void*>(&Texture);
378*89a0ef05SAndroid Build Coastguard Worker   }
379*89a0ef05SAndroid Build Coastguard Worker #endif
380*89a0ef05SAndroid Build Coastguard Worker   auto dst = apply_resize(&resize, &img_a, width / 2, height / 2, gl_ctxt, texture);
381*89a0ef05SAndroid Build Coastguard Worker #ifdef UHDR_ENABLE_GLES
382*89a0ef05SAndroid Build Coastguard Worker   if (gl_ctxt != nullptr) {
383*89a0ef05SAndroid Build Coastguard Worker     opengl_ctxt->read_texture(static_cast<GLuint*>(texture), dst->fmt, dst->w, dst->h,
384*89a0ef05SAndroid Build Coastguard Worker                               dst->planes[0]);
385*89a0ef05SAndroid Build Coastguard Worker   }
386*89a0ef05SAndroid Build Coastguard Worker #endif
387*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(img_a.fmt, dst->fmt) << msg;
388*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(img_a.cg, dst->cg) << msg;
389*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(img_a.ct, dst->ct) << msg;
390*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(img_a.range, dst->range) << msg;
391*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(dst->w, width / 2) << msg;
392*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(dst->h, height / 2) << msg;
393*89a0ef05SAndroid Build Coastguard Worker #ifdef DUMP_OUTPUT
394*89a0ef05SAndroid Build Coastguard Worker   if (!writeFile("resize", dst.get())) {
395*89a0ef05SAndroid Build Coastguard Worker     std::cerr << "unable to write output file" << std::endl;
396*89a0ef05SAndroid Build Coastguard Worker   }
397*89a0ef05SAndroid Build Coastguard Worker #endif
398*89a0ef05SAndroid Build Coastguard Worker }
399*89a0ef05SAndroid Build Coastguard Worker 
TEST_P(EditorHelperTest,MultipleEffects)400*89a0ef05SAndroid Build Coastguard Worker TEST_P(EditorHelperTest, MultipleEffects) {
401*89a0ef05SAndroid Build Coastguard Worker   std::string msg = "failed for resolution " + std::to_string(width) + " x " +
402*89a0ef05SAndroid Build Coastguard Worker                     std::to_string(height) + " format: " + std::to_string(fmt);
403*89a0ef05SAndroid Build Coastguard Worker   initImageHandle(&img_a, width, height, fmt);
404*89a0ef05SAndroid Build Coastguard Worker   ASSERT_TRUE(loadFile(filename.c_str(), &img_a)) << "unable to load file " << filename;
405*89a0ef05SAndroid Build Coastguard Worker   ultrahdr::uhdr_rotate_effect_t r90(90), r180(180), r270(270);
406*89a0ef05SAndroid Build Coastguard Worker   ultrahdr::uhdr_mirror_effect_t mhorz(UHDR_MIRROR_HORIZONTAL), mvert(UHDR_MIRROR_VERTICAL);
407*89a0ef05SAndroid Build Coastguard Worker   ultrahdr::uhdr_resize_effect_t resize(width / 2, height / 2);
408*89a0ef05SAndroid Build Coastguard Worker #ifdef UHDR_ENABLE_GLES
409*89a0ef05SAndroid Build Coastguard Worker   if (gl_ctxt != nullptr) {
410*89a0ef05SAndroid Build Coastguard Worker     Texture = opengl_ctxt->create_texture(img_a.fmt, img_a.w, img_a.h, img_a.planes[0]);
411*89a0ef05SAndroid Build Coastguard Worker     texture = static_cast<void*>(&Texture);
412*89a0ef05SAndroid Build Coastguard Worker   }
413*89a0ef05SAndroid Build Coastguard Worker #endif
414*89a0ef05SAndroid Build Coastguard Worker   auto dst = apply_mirror(&mhorz, &img_a, gl_ctxt, texture);
415*89a0ef05SAndroid Build Coastguard Worker   dst = apply_rotate(&r180, dst.get(), gl_ctxt, texture);
416*89a0ef05SAndroid Build Coastguard Worker   dst = apply_mirror(&mhorz, dst.get(), gl_ctxt, texture);
417*89a0ef05SAndroid Build Coastguard Worker   dst = apply_rotate(&r180, dst.get(), gl_ctxt, texture);
418*89a0ef05SAndroid Build Coastguard Worker #ifdef UHDR_ENABLE_GLES
419*89a0ef05SAndroid Build Coastguard Worker   if (gl_ctxt != nullptr) {
420*89a0ef05SAndroid Build Coastguard Worker     opengl_ctxt->read_texture(static_cast<GLuint*>(texture), dst->fmt, dst->w, dst->h,
421*89a0ef05SAndroid Build Coastguard Worker                               dst->planes[0]);
422*89a0ef05SAndroid Build Coastguard Worker   }
423*89a0ef05SAndroid Build Coastguard Worker #endif
424*89a0ef05SAndroid Build Coastguard Worker   ASSERT_NO_FATAL_FAILURE(compareImg(&img_a, dst.get())) << msg;
425*89a0ef05SAndroid Build Coastguard Worker 
426*89a0ef05SAndroid Build Coastguard Worker   dst = apply_mirror(&mhorz, dst.get(), gl_ctxt, texture);
427*89a0ef05SAndroid Build Coastguard Worker   dst = apply_rotate(&r90, dst.get(), gl_ctxt, texture);
428*89a0ef05SAndroid Build Coastguard Worker   dst = apply_rotate(&r90, dst.get(), gl_ctxt, texture);
429*89a0ef05SAndroid Build Coastguard Worker   dst = apply_mirror(&mvert, dst.get(), gl_ctxt, texture);
430*89a0ef05SAndroid Build Coastguard Worker #ifdef UHDR_ENABLE_GLES
431*89a0ef05SAndroid Build Coastguard Worker   if (gl_ctxt != nullptr) {
432*89a0ef05SAndroid Build Coastguard Worker     opengl_ctxt->read_texture(static_cast<GLuint*>(texture), dst->fmt, dst->w, dst->h,
433*89a0ef05SAndroid Build Coastguard Worker                               dst->planes[0]);
434*89a0ef05SAndroid Build Coastguard Worker   }
435*89a0ef05SAndroid Build Coastguard Worker #endif
436*89a0ef05SAndroid Build Coastguard Worker   ASSERT_NO_FATAL_FAILURE(compareImg(&img_a, dst.get())) << msg;
437*89a0ef05SAndroid Build Coastguard Worker 
438*89a0ef05SAndroid Build Coastguard Worker   dst = apply_rotate(&r270, dst.get(), gl_ctxt, texture);
439*89a0ef05SAndroid Build Coastguard Worker   dst = apply_mirror(&mvert, dst.get(), gl_ctxt, texture);
440*89a0ef05SAndroid Build Coastguard Worker   dst = apply_rotate(&r90, dst.get(), gl_ctxt, texture);
441*89a0ef05SAndroid Build Coastguard Worker   dst = apply_mirror(&mhorz, dst.get(), gl_ctxt, texture);
442*89a0ef05SAndroid Build Coastguard Worker #ifdef UHDR_ENABLE_GLES
443*89a0ef05SAndroid Build Coastguard Worker   if (gl_ctxt != nullptr) {
444*89a0ef05SAndroid Build Coastguard Worker     opengl_ctxt->read_texture(static_cast<GLuint*>(texture), dst->fmt, dst->w, dst->h,
445*89a0ef05SAndroid Build Coastguard Worker                               dst->planes[0]);
446*89a0ef05SAndroid Build Coastguard Worker   }
447*89a0ef05SAndroid Build Coastguard Worker #endif
448*89a0ef05SAndroid Build Coastguard Worker   ASSERT_NO_FATAL_FAILURE(compareImg(&img_a, dst.get())) << msg;
449*89a0ef05SAndroid Build Coastguard Worker 
450*89a0ef05SAndroid Build Coastguard Worker   dst = apply_resize(&resize, dst.get(), width * 2, height * 2, gl_ctxt, texture);
451*89a0ef05SAndroid Build Coastguard Worker #ifdef UHDR_ENABLE_GLES
452*89a0ef05SAndroid Build Coastguard Worker   if (gl_ctxt != nullptr) {
453*89a0ef05SAndroid Build Coastguard Worker     opengl_ctxt->read_texture(static_cast<GLuint*>(texture), dst->fmt, dst->w, dst->h,
454*89a0ef05SAndroid Build Coastguard Worker                               dst->planes[0]);
455*89a0ef05SAndroid Build Coastguard Worker   }
456*89a0ef05SAndroid Build Coastguard Worker #endif
457*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(img_a.fmt, dst->fmt) << msg;
458*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(img_a.cg, dst->cg) << msg;
459*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(img_a.ct, dst->ct) << msg;
460*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(img_a.range, dst->range) << msg;
461*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(dst->w, width * 2) << msg;
462*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(dst->h, height * 2) << msg;
463*89a0ef05SAndroid Build Coastguard Worker 
464*89a0ef05SAndroid Build Coastguard Worker   const int left = 16;
465*89a0ef05SAndroid Build Coastguard Worker   const int top = 16;
466*89a0ef05SAndroid Build Coastguard Worker   const int crop_wd = 32;
467*89a0ef05SAndroid Build Coastguard Worker   const int crop_ht = 32;
468*89a0ef05SAndroid Build Coastguard Worker   if (dst->w < (left + crop_wd) || dst->h <= (top + crop_ht)) {
469*89a0ef05SAndroid Build Coastguard Worker     GTEST_SKIP() << "Test skipped as crop attributes are too large for resolution " +
470*89a0ef05SAndroid Build Coastguard Worker                         std::to_string(dst->w) + " x " + std::to_string(dst->h) +
471*89a0ef05SAndroid Build Coastguard Worker                         " format: " + std::to_string(fmt);
472*89a0ef05SAndroid Build Coastguard Worker   }
473*89a0ef05SAndroid Build Coastguard Worker   ultrahdr::uhdr_crop_effect_t crop(left, left + crop_wd, top, top + crop_ht);
474*89a0ef05SAndroid Build Coastguard Worker   dst = apply_crop(&crop, dst.get(), left, top, crop_wd, crop_ht, gl_ctxt, texture);
475*89a0ef05SAndroid Build Coastguard Worker #ifdef UHDR_ENABLE_GLES
476*89a0ef05SAndroid Build Coastguard Worker   if (gl_ctxt != nullptr) {
477*89a0ef05SAndroid Build Coastguard Worker     opengl_ctxt->read_texture(static_cast<GLuint*>(texture), dst->fmt, dst->w, dst->h,
478*89a0ef05SAndroid Build Coastguard Worker                               dst->planes[0]);
479*89a0ef05SAndroid Build Coastguard Worker   }
480*89a0ef05SAndroid Build Coastguard Worker #endif
481*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(img_a.fmt, dst->fmt) << msg;
482*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(img_a.cg, dst->cg) << msg;
483*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(img_a.ct, dst->ct) << msg;
484*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(img_a.range, dst->range) << msg;
485*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(crop_wd, dst->w) << msg;
486*89a0ef05SAndroid Build Coastguard Worker   ASSERT_EQ(crop_ht, dst->h) << msg;
487*89a0ef05SAndroid Build Coastguard Worker }
488*89a0ef05SAndroid Build Coastguard Worker 
489*89a0ef05SAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
490*89a0ef05SAndroid Build Coastguard Worker     EditorAPIParameterizedTests, EditorHelperTest,
491*89a0ef05SAndroid Build Coastguard Worker     ::testing::Combine(::testing::Values(INPUT_IMAGE), ::testing::Range(2, 80, 2),
492*89a0ef05SAndroid Build Coastguard Worker                        ::testing::Values(64),
493*89a0ef05SAndroid Build Coastguard Worker                        ::testing::Values(UHDR_IMG_FMT_24bppYCbCrP010, UHDR_IMG_FMT_12bppYCbCr420,
494*89a0ef05SAndroid Build Coastguard Worker                                          UHDR_IMG_FMT_8bppYCbCr400, UHDR_IMG_FMT_32bppRGBA1010102,
495*89a0ef05SAndroid Build Coastguard Worker                                          UHDR_IMG_FMT_64bppRGBAHalfFloat,
496*89a0ef05SAndroid Build Coastguard Worker                                          UHDR_IMG_FMT_32bppRGBA8888)));
497*89a0ef05SAndroid Build Coastguard Worker 
498*89a0ef05SAndroid Build Coastguard Worker }  // namespace ultrahdr
499