1 /*
2 * Copyright (C) 2021 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 "image_format_convert_utils.h"
17
18 #include <cmath>
19 #include <cstring>
20 #include <map>
21 #include "hilog/log.h"
22 #include "image_log.h"
23 #include "image_utils.h"
24 #include "log_tags.h"
25 #include "securec.h"
26 #include "pixel_convert_adapter.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 #include "libswscale/swscale.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/imgutils.h"
34 #include "libavcodec/avcodec.h"
35 #ifdef __cplusplus
36 }
37 #endif
38
39 namespace {
40 constexpr uint32_t SRCSLICEY = 0;
41 constexpr uint32_t EVEN_ODD_DIVISOR = 2;
42 constexpr uint32_t TWO_SLICES = 2;
43 constexpr uint32_t BYTES_PER_PIXEL_RGB565 = 2;
44 constexpr uint32_t BYTES_PER_PIXEL_RGB = 3;
45 constexpr uint32_t BYTES_PER_PIXEL_RGBA = 4;
46 constexpr uint32_t BYTES_PER_PIXEL_BGRA = 4;
47 constexpr uint32_t STRIDES_PER_PLANE = 8;
48 constexpr int32_t PIXEL_MAP_MAX_RAM_SIZE = 600 * 1024 * 1024;
49 }
50
51 #undef LOG_TAG
52 #define LOG_TAG "ImageFormatConvert"
53 namespace OHOS {
54 namespace Media {
findPixelFormat(PixelFormat format)55 static AVPixelFormat findPixelFormat(PixelFormat format)
56 {
57 auto formatSearch = PixelConvertAdapter::FFMPEG_PIXEL_FORMAT_MAP.find(format);
58 if (formatSearch != PixelConvertAdapter::FFMPEG_PIXEL_FORMAT_MAP.end()) {
59 return formatSearch->second;
60 } else {
61 return AV_PIX_FMT_NONE;
62 }
63 }
64
CalcRGBStride(PixelFormat format,uint32_t width,int & stride)65 static bool CalcRGBStride(PixelFormat format, uint32_t width, int &stride)
66 {
67 if (format == PixelFormat::RGBA_1010102) {
68 stride = static_cast<int>(width * BYTES_PER_PIXEL_RGBA);
69 return true;
70 }
71 auto avFormat = findPixelFormat(format);
72 switch (avFormat) {
73 case AV_PIX_FMT_RGB565:
74 stride = static_cast<int>(width * BYTES_PER_PIXEL_RGB565);
75 break;
76 case AV_PIX_FMT_RGBA:
77 stride = static_cast<int>(width * BYTES_PER_PIXEL_RGBA);
78 break;
79 case AV_PIX_FMT_RGBA64:
80 stride = static_cast<int>(width * STRIDES_PER_PLANE);
81 break;
82 case AV_PIX_FMT_BGRA:
83 stride = static_cast<int>(width * BYTES_PER_PIXEL_BGRA);
84 break;
85 case AV_PIX_FMT_RGB24:
86 stride = static_cast<int>(width * BYTES_PER_PIXEL_RGB);
87 break;
88 default:
89 return false;
90 }
91 return true;
92 }
93
YuvToRGBParam(const YUVDataInfo & yDInfo,SrcConvertParam & srcParam,DestConvertParam & destParam,DestConvertInfo & destInfo)94 static bool YuvToRGBParam(const YUVDataInfo &yDInfo, SrcConvertParam &srcParam, DestConvertParam &destParam,
95 DestConvertInfo &destInfo)
96 {
97 srcParam.slice[0] = srcParam.buffer + yDInfo.yOffset;
98 srcParam.slice[1] = srcParam.buffer + yDInfo.uvOffset;
99 srcParam.stride[0] = static_cast<int>(yDInfo.yStride);
100 srcParam.stride[1] = static_cast<int>(yDInfo.uvStride);
101 int dstStride = 0;
102 if (destInfo.allocType == AllocatorType::DMA_ALLOC) {
103 dstStride = static_cast<int>(destInfo.yStride);
104 destParam.slice[0] = destInfo.buffer + destInfo.yOffset;
105 } else {
106 auto bRet = CalcRGBStride(destParam.format, destParam.width, dstStride);
107 if (!bRet) {
108 return false;
109 }
110 destParam.slice[0] = destInfo.buffer;
111 }
112 destParam.stride[0] = dstStride;
113 return true;
114 }
115
RGBToYuvParam(const RGBDataInfo & rgbInfo,SrcConvertParam & srcParam,DestConvertParam & destParam,DestConvertInfo & destInfo)116 static bool RGBToYuvParam(const RGBDataInfo &rgbInfo, SrcConvertParam &srcParam, DestConvertParam &destParam,
117 DestConvertInfo &destInfo)
118 {
119 srcParam.slice[0] = srcParam.buffer;
120 srcParam.stride[0] = static_cast<int>(rgbInfo.stride);
121 int destWidth = static_cast<int>(destParam.width);
122 int destHeight = static_cast<int>(destParam.height);
123 if (destInfo.allocType == AllocatorType::DMA_ALLOC) {
124 destParam.stride[0] = static_cast<int>(destInfo.yStride);
125 destParam.stride[1] = static_cast<int>(destInfo.uvStride);
126 destParam.slice[0] = destInfo.buffer + destInfo.yOffset;
127 destParam.slice[1] = destInfo.buffer + destInfo.uvOffset;
128 } else {
129 int uvStride = (destWidth % EVEN_ODD_DIVISOR == 0) ? (destWidth) : (destWidth + 1);
130 destParam.stride[0] = destWidth;
131 destParam.stride[1] = uvStride;
132 destParam.slice[0] = destInfo.buffer;
133 destParam.slice[1] = destInfo.buffer + destWidth * destHeight;
134 }
135 return true;
136 }
137
FillFrameInfo(AVFrame * frame,uint8_t * slice[],int stride[])138 static void FillFrameInfo(AVFrame *frame, uint8_t *slice[], int stride[])
139 {
140 if (frame == nullptr) {
141 IMAGE_LOGE("frame is null.");
142 return;
143 }
144 frame->data[0] = slice[0];
145 frame->data[1] = slice[1];
146 frame->linesize[0] = stride[0];
147 frame->linesize[1] = stride[1];
148 }
149
SoftDecode(const SrcConvertParam & srcParam,const DestConvertParam & destParam)150 static bool SoftDecode(const SrcConvertParam &srcParam, const DestConvertParam &destParam)
151 {
152 auto srcformat = findPixelFormat(srcParam.format);
153 auto dstformat = findPixelFormat(destParam.format);
154
155 SwsContext *swsContext = sws_getContext(srcParam.width, srcParam.height, srcformat, destParam.width,
156 destParam.height, dstformat, SWS_BILINEAR, nullptr, nullptr, nullptr);
157 if (swsContext == nullptr) {
158 IMAGE_LOGE("Error to create SwsContext.");
159 return false;
160 }
161 AVFrame *srcFrame = av_frame_alloc();
162 AVFrame *dstFrame = av_frame_alloc();
163 if (srcFrame == nullptr && dstFrame == nullptr) {
164 IMAGE_LOGE("FFMpeg: av_frame_alloc failed!");
165 sws_freeContext(swsContext);
166 return false;
167 }
168 uint8_t *srcSlice[4] = {const_cast<uint8_t *>(srcParam.slice[0]), const_cast<uint8_t *>(srcParam.slice[1]),
169 const_cast<uint8_t *>(srcParam.slice[2]), const_cast<uint8_t *>(srcParam.slice[3])};
170 FillFrameInfo(srcFrame, srcSlice, const_cast<int *>(srcParam.stride));
171 uint8_t *destSlice[4] = {const_cast<uint8_t *>(destParam.slice[0]), const_cast<uint8_t *>(destParam.slice[1]),
172 const_cast<uint8_t *>(destParam.slice[2]), const_cast<uint8_t *>(destParam.slice[3])};
173 FillFrameInfo(dstFrame, destSlice, const_cast<int *>(destParam.stride));
174
175 auto ret = sws_scale(swsContext, srcFrame->data, srcFrame->linesize, SRCSLICEY, destParam.height,
176 dstFrame->data, dstFrame->linesize);
177 av_frame_free(&srcFrame);
178 av_frame_free(&dstFrame);
179 sws_freeContext(swsContext);
180 if (ret <= 0) {
181 IMAGE_LOGE("Image pixel format conversion failed");
182 return false;
183 }
184 return true;
185 }
186
NV12P010ToNV21P010SoftDecode(const uint8_t * srcBuffer,const YUVDataInfo & yDInfo,uint8_t * destBuffer)187 static bool NV12P010ToNV21P010SoftDecode(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, uint8_t *destBuffer)
188 {
189 const uint16_t *src = reinterpret_cast<const uint16_t *>(srcBuffer);
190 uint16_t *dst = reinterpret_cast<uint16_t *>(destBuffer);
191 const uint16_t *src_uv = src + yDInfo.uvOffset;
192 uint16_t *dst_vu = dst + yDInfo.uvOffset;
193 uint32_t size_uv = yDInfo.uvOffset / TWO_SLICES;
194 for (uint32_t i = 0; i < yDInfo.uvOffset; i++) {
195 dst[i] = src[i];
196 }
197 for (uint32_t i = 0; i < size_uv; i += TWO_SLICES) {
198 dst_vu[i] = src_uv[i + 1];
199 dst_vu[i + 1] = src_uv[i];
200 }
201 return true;
202 }
203
RGBAConvert(const RGBDataInfo & rgbInfo,const uint8_t * srcBuffer,uint8_t * dstBuffer,Convert10bitInfo convertInfo)204 static bool RGBAConvert(const RGBDataInfo &rgbInfo, const uint8_t *srcBuffer, uint8_t *dstBuffer,
205 Convert10bitInfo convertInfo)
206 {
207 ImageInfo srcInfo;
208 ImageInfo destInfo;
209 srcInfo.alphaType = AlphaType::IMAGE_ALPHA_TYPE_PREMUL;
210 destInfo.alphaType = AlphaType::IMAGE_ALPHA_TYPE_PREMUL;
211 srcInfo.pixelFormat = convertInfo.srcPixelFormat;
212 destInfo.pixelFormat = convertInfo.dstPixelFormat;
213 srcInfo.size.width = rgbInfo.width;
214 srcInfo.size.height = rgbInfo.height;
215 destInfo.size.width = rgbInfo.width;
216 destInfo.size.height = rgbInfo.height;
217
218 Position pos;
219 if (!PixelConvertAdapter::WritePixelsConvert(srcBuffer, convertInfo.srcBytes, srcInfo,
220 dstBuffer, pos, convertInfo.dstBytes, destInfo)) {
221 IMAGE_LOGE("RGBAConvert: pixel convert in adapter failed.");
222 return false;
223 }
224 return true;
225 }
226
P010ToRGBA10101012SoftDecode(const YUVDataInfo & yDInfo,SrcConvertParam & srcParam,DestConvertParam & destParam)227 static bool P010ToRGBA10101012SoftDecode(const YUVDataInfo &yDInfo, SrcConvertParam &srcParam,
228 DestConvertParam &destParam)
229 {
230 size_t midBufferSize = static_cast<size_t>(yDInfo.yWidth * yDInfo.yHeight * STRIDES_PER_PLANE);
231 if (midBufferSize == 0 || midBufferSize > PIXEL_MAP_MAX_RAM_SIZE) {
232 IMAGE_LOGE("Invalid destination buffer size is 0!");
233 return false;
234 }
235 uint8_t *midBuffer = nullptr;
236 midBuffer = new(std::nothrow) uint8_t[midBufferSize]();
237 if (midBuffer == nullptr) {
238 IMAGE_LOGE("Apply space for dest buffer failed!");
239 return false;
240 }
241 DestConvertParam midParam = {yDInfo.yWidth, yDInfo.yHeight};
242 midParam.format = PixelFormat::RGBA_F16;
243 midParam.buffer = midBuffer;
244 midParam.slice[0] = midParam.buffer;
245 midParam.stride[0] = static_cast<int>(yDInfo.yWidth * STRIDES_PER_PLANE);
246 if (!SoftDecode(srcParam, midParam)) {
247 IMAGE_LOGE("RGB manual conversion to YUV failed!");
248 delete[] midBuffer;
249 return false;
250 }
251 RGBDataInfo rgbInfo;
252 rgbInfo.width = yDInfo.yWidth;
253 rgbInfo.height = yDInfo.yHeight;
254 Convert10bitInfo convertInfo;
255 convertInfo.srcPixelFormat = PixelFormat::RGBA_U16;
256 convertInfo.srcBytes = static_cast<uint32_t>(midParam.stride[0]);
257 convertInfo.dstPixelFormat = PixelFormat::RGBA_1010102;
258 convertInfo.dstBytes = static_cast<uint32_t>(destParam.stride[0]);
259 if (!RGBAConvert(rgbInfo, midParam.slice[0], destParam.slice[0], convertInfo)) {
260 IMAGE_LOGE("RGB888ToRGBA1010102: pixel convert in adapter failed.");
261 delete[] midBuffer;
262 return false;
263 }
264 delete[] midBuffer;
265 return true;
266 }
267
YuvP010ToRGBParam(const YUVDataInfo & yDInfo,SrcConvertParam & srcParam,DestConvertParam & destParam,DestConvertInfo & destInfo)268 static bool YuvP010ToRGBParam(const YUVDataInfo &yDInfo, SrcConvertParam &srcParam, DestConvertParam &destParam,
269 DestConvertInfo &destInfo)
270 {
271 srcParam.slice[0] = srcParam.buffer + yDInfo.yOffset;
272 srcParam.slice[1] = srcParam.buffer + yDInfo.uvOffset * TWO_SLICES;
273 srcParam.stride[0] = static_cast<int>(yDInfo.yStride * TWO_SLICES);
274 srcParam.stride[1] = static_cast<int>(yDInfo.uvStride * TWO_SLICES);
275 int dstStride = 0;
276 if (destInfo.allocType == AllocatorType::DMA_ALLOC) {
277 dstStride = static_cast<int>(destInfo.yStride);
278 destParam.slice[0] = destInfo.buffer + destInfo.yOffset;
279 } else {
280 auto bRet = CalcRGBStride(destParam.format, destParam.width, dstStride);
281 if (!bRet) {
282 return false;
283 }
284 destParam.slice[0] = destInfo.buffer;
285 }
286 destParam.stride[0] = dstStride;
287 return true;
288 }
289
YuvP010ToRGB10(const uint8_t * srcBuffer,const YUVDataInfo & yDInfo,PixelFormat srcFormat,DestConvertInfo & destInfo,PixelFormat dstFormat)290 static bool YuvP010ToRGB10(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, PixelFormat srcFormat,
291 DestConvertInfo &destInfo, PixelFormat dstFormat)
292 {
293 if (srcBuffer == nullptr || destInfo.buffer == nullptr || yDInfo.yWidth == 0 || yDInfo.yHeight == 0 ||
294 yDInfo.uvWidth == 0 || yDInfo.uvHeight == 0) {
295 return false;
296 }
297 SrcConvertParam srcParam = {yDInfo.yWidth, yDInfo.yHeight};
298 srcParam.format = srcFormat;
299 srcParam.buffer = srcBuffer;
300 DestConvertParam destParam = {yDInfo.yWidth, yDInfo.yHeight};
301 destParam.format = dstFormat;
302 if (!YuvP010ToRGBParam(yDInfo, srcParam, destParam, destInfo)) {
303 IMAGE_LOGE("yuv conversion to yuv failed!");
304 return false;
305 }
306 if (srcParam.format == PixelFormat::YCRCB_P010) {
307 size_t midBufferSize =
308 static_cast<size_t>((yDInfo.uvOffset + yDInfo.uvWidth * yDInfo.uvWidth * TWO_SLICES) * TWO_SLICES);
309 if (midBufferSize == 0 || midBufferSize > PIXEL_MAP_MAX_RAM_SIZE) {
310 IMAGE_LOGE("Invalid destination buffer size is 0!");
311 return false;
312 }
313 uint8_t *midBuffer = nullptr;
314 midBuffer = new(std::nothrow) uint8_t[midBufferSize]();
315 if (midBuffer == nullptr) {
316 IMAGE_LOGE("Apply space for dest buffer failed!");
317 return false;
318 }
319 NV12P010ToNV21P010SoftDecode(srcParam.slice[0], yDInfo, midBuffer);
320 SrcConvertParam midParam = {yDInfo.yWidth, yDInfo.yHeight};
321 midParam.format = srcFormat;
322 midParam.buffer = midBuffer;
323 midParam.slice[0] = midParam.buffer + yDInfo.yOffset;
324 midParam.slice[1] = midParam.buffer + yDInfo.uvOffset * TWO_SLICES;
325 midParam.stride[0] = static_cast<int>(yDInfo.yStride) * TWO_SLICES;
326 midParam.stride[1] = static_cast<int>(yDInfo.uvStride) * TWO_SLICES;
327 if (!P010ToRGBA10101012SoftDecode(yDInfo, midParam, destParam)) {
328 IMAGE_LOGE("P010ToRGBA1010102: pixel convert in adapter failed!");
329 delete[] midBuffer;
330 return false;
331 }
332 delete[] midBuffer;
333 return true;
334 }
335 if (!P010ToRGBA10101012SoftDecode(yDInfo, srcParam, destParam)) {
336 IMAGE_LOGE("P010ToRGBA1010102: pixel convert in adapter failed!");
337 return false;
338 }
339 return true;
340 }
341
RGBToYuvP010Param(const RGBDataInfo & rgbInfo,SrcConvertParam & srcParam,DestConvertParam & destParam,DestConvertInfo & destInfo)342 static bool RGBToYuvP010Param(const RGBDataInfo &rgbInfo, SrcConvertParam &srcParam, DestConvertParam &destParam,
343 DestConvertInfo &destInfo)
344 {
345 srcParam.slice[0] = srcParam.buffer;
346 srcParam.stride[0] = static_cast<int>(rgbInfo.stride);
347
348 if (destInfo.allocType == AllocatorType::DMA_ALLOC) {
349 destParam.stride[0] = static_cast<int>(destInfo.yStride) * TWO_SLICES;
350 destParam.stride[1] = static_cast<int>(destInfo.uvStride) * TWO_SLICES;
351 destParam.slice[0] = destInfo.buffer + destInfo.yOffset;
352 destParam.slice[1] = destInfo.buffer + destInfo.uvOffset * TWO_SLICES;
353 } else {
354 int uvStride = (destParam.width % EVEN_ODD_DIVISOR == 0) ?
355 static_cast<int>(destParam.width) : static_cast<int>(destParam.width + 1);
356 destParam.stride[0] = static_cast<int>(destParam.width) * TWO_SLICES;
357 destParam.stride[1] = static_cast<int>(uvStride) * TWO_SLICES;
358 destParam.slice[0] = destInfo.buffer;
359 destParam.slice[1] = destInfo.buffer + destParam.width * destParam.height * TWO_SLICES;
360 }
361 return true;
362 }
363
SwapNV21P010(DestConvertInfo & destInfo)364 static bool SwapNV21P010(DestConvertInfo &destInfo)
365 {
366 int32_t frameSize = static_cast<int32_t>(destInfo.width) * static_cast<int32_t>(destInfo.height);
367 size_t midBufferSize = (static_cast<uint32_t>(frameSize) +
368 (((destInfo.width + 1) / TWO_SLICES) * ((destInfo.height + 1) / TWO_SLICES) * TWO_SLICES)) * TWO_SLICES;
369 if (midBufferSize == 0 || midBufferSize > PIXEL_MAP_MAX_RAM_SIZE) {
370 IMAGE_LOGE("Invalid destination buffer size calculation!");
371 return false;
372 }
373 uint8_t *midBuffer = nullptr;
374 midBuffer = new(std::nothrow) uint8_t[midBufferSize]();
375 if (midBuffer == nullptr) {
376 IMAGE_LOGE("apply space for dest buffer failed!");
377 return false;
378 }
379
380 if (memcpy_s(midBuffer, midBufferSize, destInfo.buffer, midBufferSize) != 0) {
381 IMAGE_LOGE("Failed to copy memory for YCRCB!");
382 delete[] midBuffer;
383 return false;
384 }
385 YUVDataInfo yDInfo;
386 yDInfo.uvOffset = destInfo.width * destInfo.height;
387 bool result = NV12P010ToNV21P010SoftDecode(midBuffer, yDInfo, destInfo.buffer);
388 if (!result) {
389 IMAGE_LOGE("NV12P010ToNV21P010 failed!");
390 delete[] midBuffer;
391 return false;
392 }
393 delete[] midBuffer;
394 return true;
395 }
396
RGBToYuvP010(const uint8_t * srcBuffer,const RGBDataInfo & rgbInfo,PixelFormat srcFormat,DestConvertInfo & destInfo,PixelFormat dstFormat)397 static bool RGBToYuvP010(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo, PixelFormat srcFormat,
398 DestConvertInfo &destInfo, PixelFormat dstFormat)
399 {
400 if (srcBuffer == nullptr || destInfo.buffer == nullptr || rgbInfo.width == 0 || rgbInfo.height == 0) {
401 return false;
402 }
403 SrcConvertParam srcParam = {rgbInfo.width, rgbInfo.height};
404 srcParam.format = srcFormat;
405 srcParam.buffer = srcBuffer;
406
407 DestConvertParam destParam = {rgbInfo.width, rgbInfo.height};
408 destParam.format = dstFormat;
409
410 if (!RGBToYuvP010Param(rgbInfo, srcParam, destParam, destInfo)) {
411 IMAGE_LOGE("RGB conversion to YUVP010 failed!");
412 return false;
413 }
414
415 if (!SoftDecode(srcParam, destParam)) {
416 IMAGE_LOGE("RGB manual conversion to YUV failed!");
417 return false;
418 }
419
420 if (destInfo.format == PixelFormat::YCRCB_P010) {
421 if (!SwapNV21P010(destInfo)) {
422 IMAGE_LOGE("SwapNV21P010 failed!");
423 return false;
424 }
425 }
426 return true;
427 }
428
RGB10ToYuv(const uint8_t * srcBuffer,const RGBDataInfo & rgbInfo,PixelFormat srcFormat,DestConvertInfo & destInfo,PixelFormat dstFormat)429 static bool RGB10ToYuv(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo, PixelFormat srcFormat,
430 DestConvertInfo &destInfo, PixelFormat dstFormat)
431 {
432 if (srcBuffer == nullptr || destInfo.buffer == nullptr || rgbInfo.width == 0 || rgbInfo.height == 0) {
433 return false;
434 }
435 SrcConvertParam srcParam = {rgbInfo.width, rgbInfo.height};
436 srcParam.format = srcFormat;
437 srcParam.buffer = srcBuffer;
438 DestConvertParam destParam = {rgbInfo.width, rgbInfo.height};
439 destParam.format = dstFormat;
440 if (!RGBToYuvParam(rgbInfo, srcParam, destParam, destInfo)) {
441 IMAGE_LOGE("RGB conversion to YUV failed!");
442 return false;
443 }
444 size_t midBufferSize = static_cast<size_t>(rgbInfo.width * rgbInfo.height * STRIDES_PER_PLANE);
445 if (midBufferSize == 0 || midBufferSize > PIXEL_MAP_MAX_RAM_SIZE) {
446 IMAGE_LOGE("Invalid destination buffer size is 0!");
447 return false;
448 }
449 uint8_t *midBuffer = nullptr;
450 midBuffer = new(std::nothrow) uint8_t[midBufferSize]();
451 if (midBuffer == nullptr) {
452 IMAGE_LOGE("Apply space for dest buffer failed!");
453 return false;
454 }
455 Convert10bitInfo convertInfo;
456 convertInfo.srcPixelFormat = PixelFormat::RGBA_1010102;
457 convertInfo.srcBytes = static_cast<uint32_t>(srcParam.stride[0]);
458 convertInfo.dstPixelFormat = PixelFormat::RGB_888;
459 convertInfo.dstBytes = rgbInfo.width * BYTES_PER_PIXEL_RGB;
460 if (!RGBAConvert(rgbInfo, srcParam.slice[0], midBuffer, convertInfo)) {
461 IMAGE_LOGE("RGBA1010102ToRGB888: pixel convert in adapter failed.");
462 delete[] midBuffer;
463 return false;
464 }
465 SrcConvertParam midParam = {rgbInfo.width, rgbInfo.height};
466 midParam.format = PixelFormat::RGB_888;
467 midParam.buffer = midBuffer;
468 midParam.slice[0] = midParam.buffer;
469 midParam.stride[0] = static_cast<int>(rgbInfo.width * BYTES_PER_PIXEL_RGB);
470 if (!SoftDecode(midParam, destParam)) {
471 IMAGE_LOGE("RGB manual conversion to YUV failed!");
472 delete[] midBuffer;
473 return false;
474 }
475 delete[] midBuffer;
476 return true;
477 }
478
RGBA1010102ToP010SoftDecode(const RGBDataInfo & rgbInfo,SrcConvertParam & srcParam,DestConvertParam & destParam,DestConvertInfo & destInfo)479 static bool RGBA1010102ToP010SoftDecode(const RGBDataInfo &rgbInfo, SrcConvertParam &srcParam,
480 DestConvertParam &destParam, DestConvertInfo &destInfo)
481 {
482 size_t midBufferSize = static_cast<size_t>(rgbInfo.width * rgbInfo.height * STRIDES_PER_PLANE);
483 if (midBufferSize == 0 || midBufferSize > PIXEL_MAP_MAX_RAM_SIZE) {
484 IMAGE_LOGE("Invalid destination buffer size is 0!");
485 return false;
486 }
487 uint8_t *midBuffer = nullptr;
488 midBuffer = new(std::nothrow) uint8_t[midBufferSize]();
489 if (midBuffer == nullptr) {
490 IMAGE_LOGE("Apply space for dest buffer failed!");
491 return false;
492 }
493 Convert10bitInfo convertInfo;
494 convertInfo.srcPixelFormat = PixelFormat::RGBA_1010102;
495 convertInfo.srcBytes = static_cast<uint32_t>(srcParam.stride[0]);
496 convertInfo.dstPixelFormat = PixelFormat::RGBA_U16;
497 convertInfo.dstBytes = rgbInfo.width * STRIDES_PER_PLANE;
498 if (!RGBAConvert(rgbInfo, srcParam.slice[0], midBuffer, convertInfo)) {
499 IMAGE_LOGE("RGBA1010102ToRGB888: pixel convert in adapter failed.");
500 delete[] midBuffer;
501 return false;
502 }
503 SrcConvertParam midParam = {rgbInfo.width, rgbInfo.height};
504 midParam.format = PixelFormat::RGBA_F16;
505 midParam.buffer = midBuffer;
506 midParam.slice[0] = midParam.buffer;
507 midParam.stride[0] = static_cast<int>(rgbInfo.width * STRIDES_PER_PLANE);
508 if (!SoftDecode(midParam, destParam)) {
509 IMAGE_LOGE("RGB manual conversion to YUV failed!");
510 delete[] midBuffer;
511 return false;
512 }
513 if (destInfo.format == PixelFormat::YCRCB_P010) {
514 if (!SwapNV21P010(destInfo)) {
515 IMAGE_LOGE("SwapNV21P010 failed!");
516 delete[] midBuffer;
517 return false;
518 }
519 }
520 delete[] midBuffer;
521 return true;
522 }
523
RGB10ToYuvP010(const uint8_t * srcBuffer,const RGBDataInfo & rgbInfo,PixelFormat srcFormat,DestConvertInfo & destInfo,PixelFormat dstFormat)524 static bool RGB10ToYuvP010(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo, PixelFormat srcFormat,
525 DestConvertInfo &destInfo, PixelFormat dstFormat)
526 {
527 if (srcBuffer == nullptr || destInfo.buffer == nullptr || rgbInfo.width == 0 || rgbInfo.height == 0) {
528 return false;
529 }
530 SrcConvertParam srcParam = {rgbInfo.width, rgbInfo.height};
531 srcParam.format = srcFormat;
532 srcParam.buffer = srcBuffer;
533 DestConvertParam destParam = {rgbInfo.width, rgbInfo.height};
534 destParam.format = dstFormat;
535 if (!RGBToYuvP010Param(rgbInfo, srcParam, destParam, destInfo)) {
536 IMAGE_LOGE("RGB conversion to YUV failed!");
537 return false;
538 }
539 if (!RGBA1010102ToP010SoftDecode(rgbInfo, srcParam, destParam, destInfo)) {
540 IMAGE_LOGE("RGB10bit manual conversion to YUVP010 failed!");
541 return false;
542 }
543 return true;
544 }
545
YUVToRGBA1010102SoftDecode(const YUVDataInfo & yDInfo,SrcConvertParam & srcParam,DestConvertParam & destParam)546 static bool YUVToRGBA1010102SoftDecode(const YUVDataInfo &yDInfo, SrcConvertParam &srcParam,
547 DestConvertParam &destParam)
548 {
549 size_t midBufferSize = static_cast<size_t>(yDInfo.yWidth * yDInfo.yHeight * BYTES_PER_PIXEL_RGB);
550 if (midBufferSize == 0 || midBufferSize > PIXEL_MAP_MAX_RAM_SIZE) {
551 IMAGE_LOGE("Invalid destination buffer size is 0!");
552 return false;
553 }
554 uint8_t *midBuffer = nullptr;
555 midBuffer = new(std::nothrow) uint8_t[midBufferSize]();
556 if (midBuffer == nullptr) {
557 IMAGE_LOGE("Apply space for dest buffer failed!");
558 return false;
559 }
560 DestConvertParam midParam = {yDInfo.yWidth, yDInfo.yHeight};
561 midParam.format = PixelFormat::RGB_888;
562 midParam.buffer = midBuffer;
563 midParam.slice[0] = midParam.buffer;
564 midParam.stride[0] = static_cast<int>(yDInfo.yWidth * BYTES_PER_PIXEL_RGB);
565 if (!SoftDecode(srcParam, midParam)) {
566 IMAGE_LOGE("RGB manual conversion to YUV failed!");
567 delete[] midBuffer;
568 return false;
569 }
570 RGBDataInfo rgbInfo;
571 rgbInfo.width = yDInfo.yWidth;
572 rgbInfo.height = yDInfo.yHeight;
573 Convert10bitInfo convertInfo;
574 convertInfo.srcPixelFormat = PixelFormat::RGB_888;
575 convertInfo.srcBytes = static_cast<uint32_t>(midParam.stride[0]);
576 convertInfo.dstPixelFormat = PixelFormat::RGBA_1010102;
577 convertInfo.dstBytes = static_cast<uint32_t>(destParam.stride[0]);
578 if (!RGBAConvert(rgbInfo, midParam.slice[0], destParam.slice[0], convertInfo)) {
579 IMAGE_LOGE("RGB888ToRGBA1010102: pixel convert in adapter failed.");
580 delete[] midBuffer;
581 return false;
582 }
583 delete[] midBuffer;
584 return true;
585 }
586
YUVToRGB10(const uint8_t * srcBuffer,const YUVDataInfo & yDInfo,PixelFormat srcFormat,DestConvertInfo & destInfo,PixelFormat dstFormat)587 static bool YUVToRGB10(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, PixelFormat srcFormat,
588 DestConvertInfo &destInfo, PixelFormat dstFormat)
589 {
590 if (srcBuffer == nullptr || destInfo.buffer == nullptr || yDInfo.yWidth == 0 || yDInfo.yHeight == 0 ||
591 yDInfo.uvWidth == 0 || yDInfo.uvHeight == 0) {
592 return false;
593 }
594 SrcConvertParam srcParam = {yDInfo.yWidth, yDInfo.yHeight};
595 srcParam.format = srcFormat;
596 srcParam.buffer = srcBuffer;
597
598 DestConvertParam destParam = {yDInfo.yWidth, yDInfo.yHeight};
599 destParam.format = dstFormat;
600 if (!YuvToRGBParam(yDInfo, srcParam, destParam, destInfo)) {
601 IMAGE_LOGE("yuv conversion to RGB failed!");
602 return false;
603 }
604 if (!YUVToRGBA1010102SoftDecode(yDInfo, srcParam, destParam)) {
605 IMAGE_LOGE("YUVToRGBA1010102: pixel convert in adapter failed!");
606 return false;
607 }
608 return true;
609 }
610
YuvToYuvP010Param(const YUVDataInfo & yDInfo,SrcConvertParam & srcParam,DestConvertParam & destParam,DestConvertInfo & destInfo)611 static bool YuvToYuvP010Param(const YUVDataInfo &yDInfo, SrcConvertParam &srcParam, DestConvertParam &destParam,
612 DestConvertInfo &destInfo)
613 {
614 srcParam.slice[0] = srcParam.buffer + yDInfo.yOffset;
615 srcParam.slice[1] = srcParam.buffer + yDInfo.uvOffset;
616
617 srcParam.stride[0] = static_cast<int>(yDInfo.yStride);
618 srcParam.stride[1] = static_cast<int>(yDInfo.uvStride);
619
620 uint32_t dstyStride = 0;
621 uint32_t dstuvStride = 0;
622 if (destInfo.allocType == AllocatorType::DMA_ALLOC) {
623 dstyStride = destInfo.yStride;
624 dstuvStride = destInfo.uvStride;
625 destParam.slice[0] = destInfo.buffer + destInfo.yOffset;
626 destParam.slice[1] = destInfo.buffer + destInfo.uvOffset * TWO_SLICES;
627 } else {
628 dstyStride = destParam.width;
629 dstuvStride = (destParam.width % EVEN_ODD_DIVISOR == 0) ?
630 destParam.width : (destParam.width + 1);
631 destParam.slice[0] = destInfo.buffer;
632 destParam.slice[1] = destInfo.buffer + dstyStride * destParam.height * TWO_SLICES;
633 }
634
635 destParam.stride[0] = static_cast<int>(dstyStride * TWO_SLICES);
636 destParam.stride[1] = static_cast<int>(dstuvStride * TWO_SLICES);
637 return true;
638 }
639
YuvToYuvP010(const uint8_t * srcBuffer,const YUVDataInfo & yDInfo,PixelFormat srcFormat,DestConvertInfo & destInfo,PixelFormat dstFormat)640 static bool YuvToYuvP010(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, PixelFormat srcFormat,
641 DestConvertInfo &destInfo, PixelFormat dstFormat)
642 {
643 if (srcBuffer == nullptr || destInfo.buffer == nullptr || yDInfo.yWidth == 0 || yDInfo.yHeight == 0 ||
644 yDInfo.uvWidth == 0 || yDInfo.uvHeight == 0) {
645 return false;
646 }
647 SrcConvertParam srcParam = {yDInfo.yWidth, yDInfo.yHeight};
648 srcParam.format = srcFormat;
649 srcParam.buffer = srcBuffer;
650 DestConvertParam destParam = {yDInfo.yWidth, yDInfo.yHeight};
651 destParam.format = dstFormat;
652 if (!YuvToYuvP010Param(yDInfo, srcParam, destParam, destInfo)) {
653 IMAGE_LOGE("yuv conversion to yuv failed!");
654 return false;
655 }
656 if (!SoftDecode(srcParam, destParam)) {
657 IMAGE_LOGE("yuv manual conversion to yuv failed!");
658 return false;
659 }
660 if (destInfo.format == PixelFormat::YCRCB_P010) {
661 if (!SwapNV21P010(destInfo)) {
662 IMAGE_LOGE("SwapNV21P010 failed!");
663 return false;
664 }
665 }
666 return true;
667 }
668
YuvP010ToYuvParam(const YUVDataInfo & yDInfo,SrcConvertParam & srcParam,DestConvertParam & destParam,DestConvertInfo & destInfo)669 static bool YuvP010ToYuvParam(const YUVDataInfo &yDInfo, SrcConvertParam &srcParam, DestConvertParam &destParam,
670 DestConvertInfo &destInfo)
671 {
672 srcParam.slice[0] = srcParam.buffer + yDInfo.yOffset;
673 srcParam.slice[1] = srcParam.buffer + yDInfo.uvOffset * TWO_SLICES;
674
675 srcParam.stride[0] = static_cast<int>(yDInfo.yStride * TWO_SLICES);
676 srcParam.stride[1] = static_cast<int>(yDInfo.uvStride * TWO_SLICES);
677
678 uint32_t dstyStride = 0;
679 uint32_t dstuvStride = 0;
680 if (destInfo.allocType == AllocatorType::DMA_ALLOC) {
681 dstyStride = destInfo.yStride;
682 dstuvStride = destInfo.uvStride;
683 destParam.slice[0] = destInfo.buffer + destInfo.yOffset;
684 destParam.slice[1] = destInfo.buffer + destInfo.uvOffset;
685 } else {
686 dstyStride = destParam.width;
687 dstuvStride = (destParam.width % EVEN_ODD_DIVISOR == 0) ?
688 destParam.width : (destParam.width + 1);
689 destParam.slice[0] = destInfo.buffer;
690 destParam.slice[1] = destInfo.buffer + dstyStride * destParam.height;
691 }
692
693 destParam.stride[0] = static_cast<int>(dstyStride);
694 destParam.stride[1] = static_cast<int>(dstuvStride);
695 return true;
696 }
697
YuvP010ToYuv(const uint8_t * srcBuffer,const YUVDataInfo & yDInfo,PixelFormat srcFormat,DestConvertInfo & destInfo,PixelFormat dstFormat)698 static bool YuvP010ToYuv(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, PixelFormat srcFormat,
699 DestConvertInfo &destInfo, PixelFormat dstFormat)
700 {
701 if (srcBuffer == nullptr || destInfo.buffer == nullptr || yDInfo.yWidth == 0 || yDInfo.yHeight == 0 ||
702 yDInfo.uvWidth == 0 || yDInfo.uvHeight == 0) {
703 return false;
704 }
705 SrcConvertParam srcParam = {yDInfo.yWidth, yDInfo.yHeight};
706 srcParam.format = srcFormat;
707 srcParam.buffer = srcBuffer;
708 DestConvertParam destParam = {yDInfo.yWidth, yDInfo.yHeight};
709 destParam.format = dstFormat;
710 if (!YuvP010ToYuvParam(yDInfo, srcParam, destParam, destInfo)) {
711 IMAGE_LOGE("yuv conversion to yuv failed!");
712 return false;
713 }
714 if (srcParam.format == PixelFormat::YCRCB_P010) {
715 size_t midBufferSize =
716 static_cast<size_t>((yDInfo.uvOffset + yDInfo.uvWidth * yDInfo.uvWidth * TWO_SLICES) * TWO_SLICES);
717 if (midBufferSize == 0 || midBufferSize > PIXEL_MAP_MAX_RAM_SIZE) {
718 IMAGE_LOGE("Invalid destination buffer size is 0!");
719 return false;
720 }
721 uint8_t *midBuffer = nullptr;
722 midBuffer = new(std::nothrow) uint8_t[midBufferSize]();
723 if (midBuffer == nullptr) {
724 IMAGE_LOGE("Apply space for dest buffer failed!");
725 return false;
726 }
727 NV12P010ToNV21P010SoftDecode(srcParam.slice[0], yDInfo, midBuffer);
728 SrcConvertParam midParam = {yDInfo.yWidth, yDInfo.yHeight};
729 midParam.format = srcFormat;
730 midParam.buffer = midBuffer;
731 midParam.slice[0] = midParam.buffer + yDInfo.yOffset;
732 midParam.slice[1] = midParam.buffer + yDInfo.uvOffset * TWO_SLICES;
733 midParam.stride[0] = static_cast<int>(yDInfo.yStride) * TWO_SLICES;
734 midParam.stride[1] = static_cast<int>(yDInfo.uvStride) * TWO_SLICES;
735 if (!SoftDecode(midParam, destParam)) {
736 IMAGE_LOGE("yuv manual conversion to yuv failed!");
737 delete[] midBuffer;
738 return false;
739 }
740 delete[] midBuffer;
741 return true;
742 }
743 if (!SoftDecode(srcParam, destParam)) {
744 IMAGE_LOGE("yuv manual conversion to yuv failed!");
745 return false;
746 }
747 return true;
748 }
749
YuvP010ToYuvP010Param(const YUVDataInfo & yDInfo,SrcConvertParam & srcParam,DestConvertParam & destParam,DestConvertInfo & destInfo)750 static bool YuvP010ToYuvP010Param(const YUVDataInfo &yDInfo, SrcConvertParam &srcParam, DestConvertParam &destParam,
751 DestConvertInfo &destInfo)
752 {
753 srcParam.slice[0] = srcParam.buffer + yDInfo.yOffset;
754 srcParam.slice[1] = srcParam.buffer + yDInfo.uvOffset * TWO_SLICES;
755
756 srcParam.stride[0] = static_cast<int>(yDInfo.yStride) * TWO_SLICES;
757 srcParam.stride[1] = static_cast<int>(yDInfo.uvStride) * TWO_SLICES;
758
759 uint32_t dstyStride = 0;
760 uint32_t dstuvStride = 0;
761 if (destInfo.allocType == AllocatorType::DMA_ALLOC) {
762 dstyStride = destInfo.yStride;
763 dstuvStride = destInfo.uvStride;
764 destParam.slice[0] = destInfo.buffer + destInfo.yOffset;
765 destParam.slice[1] = destInfo.buffer + destInfo.uvOffset * TWO_SLICES;
766 } else {
767 dstyStride = destParam.width;
768 dstuvStride = (destParam.width % EVEN_ODD_DIVISOR == 0) ?
769 destParam.width : (destParam.width + 1);
770 destParam.slice[0] = destInfo.buffer;
771 destParam.slice[1] = destInfo.buffer + dstyStride * destParam.height * TWO_SLICES;
772 }
773
774 destParam.stride[0] = static_cast<int>(dstyStride * TWO_SLICES);
775 destParam.stride[1] = static_cast<int>(dstuvStride * TWO_SLICES);
776 return true;
777 }
778
779 bool ImageFormatConvertUtils::NV12P010ToNV21P010(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
780 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
781 {
782 if (srcBuffer == nullptr || destInfo.buffer == nullptr || yDInfo.yWidth == 0 || yDInfo.yHeight == 0 ||
783 yDInfo.uvWidth == 0 || yDInfo.uvHeight == 0) {
784 return false;
785 }
786 SrcConvertParam srcParam = {yDInfo.yWidth, yDInfo.yHeight};
787 srcParam.format = PixelFormat::YCBCR_P010;
788 srcParam.buffer = srcBuffer;
789 DestConvertParam destParam = {yDInfo.yWidth, yDInfo.yHeight};
790 destParam.format = PixelFormat::YCRCB_P010;
791
792 if (!YuvP010ToYuvP010Param(yDInfo, srcParam, destParam, destInfo)) {
793 IMAGE_LOGE("yuvP010 conversion to yuv failed!");
794 return false;
795 }
796
797 bool result = false;
798 result = NV12P010ToNV21P010SoftDecode(srcParam.slice[0], yDInfo, destParam.slice[0]);
799 if (!result) {
800 IMAGE_LOGE("NV12P010ToNV21P010 failed!");
801 return result;
802 }
803 return result;
804 }
805
YuvP010ToRGB(const uint8_t * srcBuffer,const YUVDataInfo & yDInfo,PixelFormat srcFormat,DestConvertInfo & destInfo,PixelFormat dstFormat)806 static bool YuvP010ToRGB(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, PixelFormat srcFormat,
807 DestConvertInfo &destInfo, PixelFormat dstFormat)
808 {
809 if (srcBuffer == nullptr || destInfo.buffer == nullptr || yDInfo.yWidth == 0 || yDInfo.yHeight == 0 ||
810 yDInfo.uvWidth == 0 || yDInfo.uvHeight == 0) {
811 return false;
812 }
813 SrcConvertParam srcParam = {yDInfo.yWidth, yDInfo.yHeight};
814 srcParam.format = srcFormat;
815 srcParam.buffer = srcBuffer;
816 DestConvertParam destParam = {yDInfo.yWidth, yDInfo.yHeight};
817 destParam.format = dstFormat;
818 if (!YuvP010ToRGBParam(yDInfo, srcParam, destParam, destInfo)) {
819 IMAGE_LOGE("yuv conversion to yuv failed!");
820 return false;
821 }
822 if (srcParam.format == PixelFormat::YCRCB_P010) {
823 size_t midBufferSize =
824 static_cast<size_t>((yDInfo.uvOffset + yDInfo.uvWidth * yDInfo.uvWidth * TWO_SLICES) * TWO_SLICES);
825 if (midBufferSize == 0 || midBufferSize > PIXEL_MAP_MAX_RAM_SIZE) {
826 IMAGE_LOGE("Invalid destination buffer size is 0!");
827 return false;
828 }
829 uint8_t *midBuffer = nullptr;
830 midBuffer = new(std::nothrow) uint8_t[midBufferSize]();
831 if (midBuffer == nullptr) {
832 IMAGE_LOGE("Apply space for dest buffer failed!");
833 return false;
834 }
835 NV12P010ToNV21P010SoftDecode(srcParam.slice[0], yDInfo, midBuffer);
836 SrcConvertParam midParam = {yDInfo.yWidth, yDInfo.yHeight};
837 midParam.format = srcFormat;
838 midParam.buffer = midBuffer;
839 midParam.slice[0] = midParam.buffer + yDInfo.yOffset;
840 midParam.slice[1] = midParam.buffer + yDInfo.uvOffset * TWO_SLICES;
841 midParam.stride[0] = static_cast<int>(yDInfo.yStride) * TWO_SLICES;
842 midParam.stride[1] = static_cast<int>(yDInfo.uvStride) * TWO_SLICES;
843 if (!SoftDecode(midParam, destParam)) {
844 IMAGE_LOGE("yuv manual conversion to yuv failed!");
845 delete[] midBuffer;
846 return false;
847 }
848 delete[] midBuffer;
849 return true;
850 }
851 if (!SoftDecode(srcParam, destParam)) {
852 IMAGE_LOGE("yuv manual conversion to yuv failed!");
853 return false;
854 }
855 return true;
856 }
857
858 bool ImageFormatConvertUtils::NV12P010ToRGB565(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
859 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
860 {
861 return YuvP010ToRGB(srcBuffer, yDInfo, PixelFormat::YCBCR_P010, destInfo, PixelFormat::RGB_565);
862 }
863
864 bool ImageFormatConvertUtils::NV12P010ToRGBA8888(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
865 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
866 {
867 return YuvP010ToRGB(srcBuffer, yDInfo, PixelFormat::YCBCR_P010, destInfo, PixelFormat::RGBA_8888);
868 }
869
870 bool ImageFormatConvertUtils::NV12P010ToBGRA8888(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
871 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
872 {
873 return YuvP010ToRGB(srcBuffer, yDInfo, PixelFormat::YCBCR_P010, destInfo, PixelFormat::BGRA_8888);
874 }
875
876 bool ImageFormatConvertUtils::NV12P010ToRGB888(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
877 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
878 {
879 return YuvP010ToRGB(srcBuffer, yDInfo, PixelFormat::YCBCR_P010, destInfo, PixelFormat::RGB_888);
880 }
881
882 bool ImageFormatConvertUtils::NV12P010ToRGBAF16(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
883 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
884 {
885 return YuvP010ToRGB(srcBuffer, yDInfo, PixelFormat::YCBCR_P010, destInfo, PixelFormat::RGBA_F16);
886 }
887
888 bool ImageFormatConvertUtils::NV21P010ToNV12(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
889 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
890 {
891 return YuvP010ToYuv(srcBuffer, yDInfo, PixelFormat::YCRCB_P010, destInfo, PixelFormat::NV12);
892 }
893
894 bool ImageFormatConvertUtils::NV21P010ToNV21(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
895 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
896 {
897 return YuvP010ToYuv(srcBuffer, yDInfo, PixelFormat::YCRCB_P010, destInfo, PixelFormat::NV21);
898 }
899
900 bool ImageFormatConvertUtils::NV21P010ToNV12P010(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
901 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
902 {
903 if (srcBuffer == nullptr || destInfo.buffer == nullptr || yDInfo.yWidth == 0 || yDInfo.yHeight == 0 ||
904 yDInfo.uvWidth == 0 || yDInfo.uvHeight == 0) {
905 return false;
906 }
907
908 SrcConvertParam srcParam = {yDInfo.yWidth, yDInfo.yHeight};
909 srcParam.format = PixelFormat::YCRCB_P010;
910 srcParam.buffer = srcBuffer;
911 DestConvertParam destParam = {yDInfo.yWidth, yDInfo.yHeight};
912 destParam.format = PixelFormat::YCBCR_P010;
913
914 if (!YuvP010ToYuvP010Param(yDInfo, srcParam, destParam, destInfo)) {
915 IMAGE_LOGE("yuvP010 conversion to yuv failed!");
916 return false;
917 }
918
919 bool result = false;
920 result = NV12P010ToNV21P010SoftDecode(srcParam.slice[0], yDInfo, destParam.slice[0]);
921 if (!result) {
922 IMAGE_LOGE("NV12P010ToNV21P010 failed!");
923 return result;
924 }
925 return result;
926 }
927
928 bool ImageFormatConvertUtils::NV21P010ToRGB565(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
929 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
930 {
931 return YuvP010ToRGB(srcBuffer, yDInfo, PixelFormat::YCRCB_P010, destInfo, PixelFormat::RGB_565);
932 }
933
934 bool ImageFormatConvertUtils::NV21P010ToRGBA8888(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
935 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
936 {
937 return YuvP010ToRGB(srcBuffer, yDInfo, PixelFormat::YCRCB_P010, destInfo, PixelFormat::RGBA_8888);
938 }
939
940 bool ImageFormatConvertUtils::NV21P010ToBGRA8888(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
941 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
942 {
943 return YuvP010ToRGB(srcBuffer, yDInfo, PixelFormat::YCRCB_P010, destInfo, PixelFormat::BGRA_8888);
944 }
945
946 bool ImageFormatConvertUtils::NV21P010ToRGB888(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
947 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
948 {
949 return YuvP010ToRGB(srcBuffer, yDInfo, PixelFormat::YCRCB_P010, destInfo, PixelFormat::RGB_888);
950 }
951
952 bool ImageFormatConvertUtils::NV21P010ToRGBAF16(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
953 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
954 {
955 return YuvP010ToRGB(srcBuffer, yDInfo, PixelFormat::YCRCB_P010, destInfo, PixelFormat::RGBA_F16);
956 }
957
958 bool ImageFormatConvertUtils::NV12P010ToNV12(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
959 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
960 {
961 return YuvP010ToYuv(srcBuffer, yDInfo, PixelFormat::YCBCR_P010, destInfo, PixelFormat::NV12);
962 }
963
964 bool ImageFormatConvertUtils::NV12P010ToNV21(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
965 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
966 {
967 return YuvP010ToYuv(srcBuffer, yDInfo, PixelFormat::YCBCR_P010, destInfo, PixelFormat::NV21);
968 }
969
970 bool ImageFormatConvertUtils::NV12ToNV12P010(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
971 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
972 {
973 return YuvToYuvP010(srcBuffer, yDInfo, PixelFormat::NV12, destInfo, PixelFormat::YCBCR_P010);
974 }
975
976 bool ImageFormatConvertUtils::NV12ToNV21P010(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
977 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
978 {
979 return YuvToYuvP010(srcBuffer, yDInfo, PixelFormat::NV12, destInfo, PixelFormat::YCRCB_P010);
980 }
981 bool ImageFormatConvertUtils::NV21ToNV12P010(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
982 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
983 {
984 return YuvToYuvP010(srcBuffer, yDInfo, PixelFormat::NV21, destInfo, PixelFormat::YCBCR_P010);
985 }
986 bool ImageFormatConvertUtils::NV21ToNV21P010(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
987 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
988 {
989 return YuvToYuvP010(srcBuffer, yDInfo, PixelFormat::NV21, destInfo, PixelFormat::YCRCB_P010);
990 }
991
992 bool ImageFormatConvertUtils::NV12ToRGBA1010102(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
993 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
994 {
995 return YUVToRGB10(srcBuffer, yDInfo, PixelFormat::NV12, destInfo, PixelFormat::RGBA_1010102);
996 }
997
998 bool ImageFormatConvertUtils::NV21ToRGBA1010102(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
999 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
1000 {
1001 return YUVToRGB10(srcBuffer, yDInfo, PixelFormat::NV21, destInfo, PixelFormat::RGBA_1010102);
1002 }
1003
1004 bool ImageFormatConvertUtils::NV12P010ToRGBA1010102(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
1005 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
1006 {
1007 return YuvP010ToRGB10(srcBuffer, yDInfo, PixelFormat::YCBCR_P010, destInfo, PixelFormat::RGBA_1010102);
1008 }
1009
1010 bool ImageFormatConvertUtils::NV21P010ToRGBA1010102(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
1011 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
1012 {
1013 return YuvP010ToRGB10(srcBuffer, yDInfo, PixelFormat::YCRCB_P010, destInfo, PixelFormat::RGBA_1010102);
1014 }
1015
1016 bool ImageFormatConvertUtils::RGB565ToNV12P010(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1017 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
1018 {
1019 return RGBToYuvP010(srcBuffer, rgbInfo, PixelFormat::RGB_565, destInfo, PixelFormat::YCBCR_P010);
1020 }
1021
1022 bool ImageFormatConvertUtils::RGB565ToNV21P010(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1023 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
1024 {
1025 return RGBToYuvP010(srcBuffer, rgbInfo, PixelFormat::RGB_565, destInfo, PixelFormat::YCRCB_P010);
1026 }
1027
1028 bool ImageFormatConvertUtils::RGBAToNV12P010(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1029 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
1030 {
1031 return RGBToYuvP010(srcBuffer, rgbInfo, PixelFormat::RGBA_8888, destInfo, PixelFormat::YCBCR_P010);
1032 }
1033
1034 bool ImageFormatConvertUtils::RGBAToNV21P010(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1035 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
1036 {
1037 return RGBToYuvP010(srcBuffer, rgbInfo, PixelFormat::RGBA_8888, destInfo, PixelFormat::YCRCB_P010);
1038 }
1039
1040 bool ImageFormatConvertUtils::BGRAToNV12P010(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1041 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
1042 {
1043 return RGBToYuvP010(srcBuffer, rgbInfo, PixelFormat::BGRA_8888, destInfo, PixelFormat::YCBCR_P010);
1044 }
1045
1046 bool ImageFormatConvertUtils::BGRAToNV21P010(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1047 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
1048 {
1049 return RGBToYuvP010(srcBuffer, rgbInfo, PixelFormat::BGRA_8888, destInfo, PixelFormat::YCRCB_P010);
1050 }
1051
1052 bool ImageFormatConvertUtils::RGBToNV12P010(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1053 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
1054 {
1055 return RGBToYuvP010(srcBuffer, rgbInfo, PixelFormat::RGB_888, destInfo, PixelFormat::YCBCR_P010);
1056 }
1057
1058 bool ImageFormatConvertUtils::RGBToNV21P010(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1059 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
1060 {
1061 return RGBToYuvP010(srcBuffer, rgbInfo, PixelFormat::RGB_888, destInfo, PixelFormat::YCRCB_P010);
1062 }
1063
1064 bool ImageFormatConvertUtils::RGBAF16ToNV12P010(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1065 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
1066 {
1067 return RGBToYuvP010(srcBuffer, rgbInfo, PixelFormat::RGBA_F16, destInfo, PixelFormat::YCBCR_P010);
1068 }
1069
1070 bool ImageFormatConvertUtils::RGBAF16ToNV21P010(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1071 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
1072 {
1073 return RGBToYuvP010(srcBuffer, rgbInfo, PixelFormat::RGBA_F16, destInfo, PixelFormat::YCRCB_P010);
1074 }
1075
1076 bool ImageFormatConvertUtils::RGBA1010102ToNV12(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1077 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
1078 {
1079 return RGB10ToYuv(srcBuffer, rgbInfo, PixelFormat::RGBA_1010102, destInfo, PixelFormat::NV12);
1080 }
1081
1082 bool ImageFormatConvertUtils::RGBA1010102ToNV21(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1083 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
1084 {
1085 return RGB10ToYuv(srcBuffer, rgbInfo, PixelFormat::RGBA_1010102, destInfo, PixelFormat::NV21);
1086 }
1087
1088 bool ImageFormatConvertUtils::RGBA1010102ToNV12P010(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1089 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
1090 {
1091 return RGB10ToYuvP010(srcBuffer, rgbInfo, PixelFormat::RGBA_1010102, destInfo, PixelFormat::YCBCR_P010);
1092 }
1093
1094 bool ImageFormatConvertUtils::RGBA1010102ToNV21P010(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1095 DestConvertInfo &destInfo, [[maybe_unused]]ColorSpace colorSpace)
1096 {
1097 return RGB10ToYuvP010(srcBuffer, rgbInfo, PixelFormat::RGBA_1010102, destInfo, PixelFormat::YCRCB_P010);
1098 }
1099
YuvToYuvParam(const YUVDataInfo & yDInfo,SrcConvertParam & srcParam,DestConvertParam & destParam,DestConvertInfo & destInfo)1100 static bool YuvToYuvParam(const YUVDataInfo &yDInfo, SrcConvertParam &srcParam, DestConvertParam &destParam,
1101 DestConvertInfo &destInfo)
1102 {
1103 srcParam.slice[0] = srcParam.buffer + yDInfo.yOffset;
1104 srcParam.slice[1] = srcParam.buffer + yDInfo.uvOffset;
1105
1106 srcParam.stride[0] = static_cast<int>(yDInfo.yStride);
1107 srcParam.stride[1] = static_cast<int>(yDInfo.uvStride);
1108
1109 int dstyStride = 0;
1110 int dstuvStride = 0;
1111 int destWidth = static_cast<int>(destParam.width);
1112 int destHeight = static_cast<int>(destParam.height);
1113 if (destInfo.allocType == AllocatorType::DMA_ALLOC) {
1114 dstyStride = static_cast<int>(destInfo.yStride);
1115 dstuvStride = static_cast<int>(destInfo.uvStride);
1116 destParam.slice[0] = destInfo.buffer + destInfo.yOffset;
1117 destParam.slice[1] = destInfo.buffer + destInfo.uvOffset;
1118 } else {
1119 dstyStride = destWidth;
1120 dstuvStride = (destWidth % EVEN_ODD_DIVISOR == 0) ? (destWidth) : (destWidth + 1);
1121 destParam.slice[0] = destInfo.buffer;
1122 destParam.slice[1] = destInfo.buffer + dstyStride * destHeight;
1123 }
1124
1125 destParam.stride[0] = dstyStride;
1126 destParam.stride[1] = dstuvStride;
1127 return true;
1128 }
1129
YuvToYuv(const uint8_t * srcBuffer,const YUVDataInfo & yDInfo,PixelFormat srcFormat,DestConvertInfo & destInfo,PixelFormat destFormat)1130 static bool YuvToYuv(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, PixelFormat srcFormat,
1131 DestConvertInfo &destInfo, PixelFormat destFormat)
1132 {
1133 if (srcBuffer == nullptr || destInfo.buffer == nullptr || yDInfo.yWidth == 0 || yDInfo.yHeight == 0 ||
1134 yDInfo.uvWidth == 0 || yDInfo.uvHeight == 0 || destInfo.bufferSize == 0) {
1135 return false;
1136 }
1137 SrcConvertParam srcParam = {yDInfo.yWidth, yDInfo.yHeight};
1138 srcParam.format = srcFormat;
1139 srcParam.buffer = srcBuffer;
1140
1141 DestConvertParam destParam = {destInfo.width, destInfo.height};
1142 destParam.format = destFormat;
1143
1144 if (!YuvToYuvParam(yDInfo, srcParam, destParam, destInfo)) {
1145 IMAGE_LOGE("yuv conversion to yuv failed!");
1146 return false;
1147 }
1148 if (!SoftDecode(srcParam, destParam)) {
1149 IMAGE_LOGE("yuv manual conversion to yuv failed!");
1150 return false;
1151 }
1152 return true;
1153 }
1154
YuvToRGB(const uint8_t * srcBuffer,const YUVDataInfo & yDInfo,PixelFormat srcFormat,DestConvertInfo & destInfo,PixelFormat destFormat)1155 static bool YuvToRGB(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, PixelFormat srcFormat,
1156 DestConvertInfo &destInfo, PixelFormat destFormat)
1157 {
1158 if (srcBuffer == nullptr || destInfo.buffer == nullptr || yDInfo.yWidth == 0 || yDInfo.yHeight == 0 ||
1159 yDInfo.uvWidth == 0 || yDInfo.uvHeight == 0 || destInfo.bufferSize == 0) {
1160 return false;
1161 }
1162 SrcConvertParam srcParam = {yDInfo.yWidth, yDInfo.yHeight};
1163 srcParam.format = srcFormat;
1164 srcParam.buffer = srcBuffer;
1165
1166 DestConvertParam destParam = {destInfo.width, destInfo.height};
1167 destParam.format = destFormat;
1168
1169 if (!YuvToRGBParam(yDInfo, srcParam, destParam, destInfo)) {
1170 IMAGE_LOGE("yuv conversion to RGB failed!");
1171 return false;
1172 }
1173 if (!SoftDecode(srcParam, destParam)) {
1174 IMAGE_LOGE("yuv manual conversion to RGB failed!");
1175 return false;
1176 }
1177 return true;
1178 }
1179
RGBToYuv(const uint8_t * srcBuffer,const RGBDataInfo & rgbInfo,PixelFormat srcFormat,DestConvertInfo & destInfo,PixelFormat destFormat)1180 static bool RGBToYuv(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo, PixelFormat srcFormat,
1181 DestConvertInfo &destInfo, PixelFormat destFormat)
1182 {
1183 if (srcBuffer == nullptr || destInfo.buffer == nullptr || rgbInfo.width == 0 || rgbInfo.height == 0 ||
1184 destInfo.bufferSize == 0) {
1185 return false;
1186 }
1187 SrcConvertParam srcParam = {rgbInfo.width, rgbInfo.height};
1188 srcParam.format = srcFormat;
1189 srcParam.buffer = srcBuffer;
1190
1191 DestConvertParam destParam = {destInfo.width, destInfo.height};
1192 destParam.format = destFormat;
1193
1194 if (!RGBToYuvParam(rgbInfo, srcParam, destParam, destInfo)) {
1195 IMAGE_LOGE("RGB conversion to YUV failed!");
1196 return false;
1197 }
1198 if (!SoftDecode(srcParam, destParam)) {
1199 IMAGE_LOGE("RGB manual conversion to YUV failed!");
1200 return false;
1201 }
1202 return true;
1203 }
1204
1205 bool ImageFormatConvertUtils::NV12ToRGB565(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
1206 DestConvertInfo &destInfo,
1207 [[maybe_unused]]ColorSpace colorSpace)
1208 {
1209 return YuvToRGB(srcBuffer, yDInfo, PixelFormat::NV12, destInfo, PixelFormat::RGB_565);
1210 }
1211
1212 bool ImageFormatConvertUtils::NV21ToRGB565(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
1213 DestConvertInfo &destInfo,
1214 [[maybe_unused]]ColorSpace colorSpace)
1215 {
1216 return YuvToRGB(srcBuffer, yDInfo, PixelFormat::NV21, destInfo, PixelFormat::RGB_565);
1217 }
1218
1219 bool ImageFormatConvertUtils::NV21ToRGB(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
1220 DestConvertInfo &destInfo,
1221 [[maybe_unused]]ColorSpace colorSpace)
1222 {
1223 return YuvToRGB(srcBuffer, yDInfo, PixelFormat::NV21, destInfo, PixelFormat::RGB_888);
1224 }
1225
1226 bool ImageFormatConvertUtils::NV12ToRGB(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
1227 DestConvertInfo &destInfo,
1228 [[maybe_unused]]ColorSpace colorSpace)
1229 {
1230 return YuvToRGB(srcBuffer, yDInfo, PixelFormat::NV12, destInfo, PixelFormat::RGB_888);
1231 }
1232
1233 bool ImageFormatConvertUtils::NV21ToRGBA(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
1234 DestConvertInfo &destInfo,
1235 [[maybe_unused]]ColorSpace colorSpace)
1236 {
1237 return YuvToRGB(srcBuffer, yDInfo, PixelFormat::NV21, destInfo, PixelFormat::RGBA_8888);
1238 }
1239
1240 bool ImageFormatConvertUtils::NV12ToRGBA(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
1241 DestConvertInfo &destInfo,
1242 [[maybe_unused]]ColorSpace colorSpace)
1243 {
1244 return YuvToRGB(srcBuffer, yDInfo, PixelFormat::NV12, destInfo, PixelFormat::RGBA_8888);
1245 }
1246
1247 bool ImageFormatConvertUtils::NV21ToBGRA(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
1248 DestConvertInfo &destInfo,
1249 [[maybe_unused]]ColorSpace colorSpace)
1250 {
1251 return YuvToRGB(srcBuffer, yDInfo, PixelFormat::NV21, destInfo, PixelFormat::BGRA_8888);
1252 }
1253
1254 bool ImageFormatConvertUtils::NV12ToBGRA(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
1255 DestConvertInfo &destInfo,
1256 [[maybe_unused]]ColorSpace colorSpace)
1257 {
1258 return YuvToRGB(srcBuffer, yDInfo, PixelFormat::NV12, destInfo, PixelFormat::BGRA_8888);
1259 }
1260
1261 bool ImageFormatConvertUtils::NV21ToRGBAF16(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
1262 DestConvertInfo &destInfo,
1263 [[maybe_unused]]ColorSpace colorSpace)
1264 {
1265 return YuvToRGB(srcBuffer, yDInfo, PixelFormat::NV21, destInfo, PixelFormat::RGBA_F16);
1266 }
1267
1268 bool ImageFormatConvertUtils::NV12ToRGBAF16(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
1269 DestConvertInfo &destInfo,
1270 [[maybe_unused]]ColorSpace colorSpace)
1271 {
1272 return YuvToRGB(srcBuffer, yDInfo, PixelFormat::NV12, destInfo, PixelFormat::RGBA_F16);
1273 }
1274
1275 bool ImageFormatConvertUtils::NV12ToNV21(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
1276 DestConvertInfo &destInfo,
1277 [[maybe_unused]]ColorSpace colorSpace)
1278 {
1279 return YuvToYuv(srcBuffer, yDInfo, PixelFormat::NV12, destInfo, PixelFormat::NV21);
1280 }
1281
1282 bool ImageFormatConvertUtils::NV21ToNV12(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo,
1283 DestConvertInfo &destInfo,
1284 [[maybe_unused]]ColorSpace colorSpace)
1285 {
1286 return YuvToYuv(srcBuffer, yDInfo, PixelFormat::NV21, destInfo, PixelFormat::NV12);
1287 }
1288
1289 bool ImageFormatConvertUtils::RGBToNV21(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1290 DestConvertInfo &destInfo,
1291 [[maybe_unused]]ColorSpace colorSpace)
1292 {
1293 return RGBToYuv(srcBuffer, rgbInfo, PixelFormat::RGB_888, destInfo, PixelFormat::NV21);
1294 }
1295
1296 bool ImageFormatConvertUtils::RGBToNV12(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1297 DestConvertInfo &destInfo,
1298 [[maybe_unused]]ColorSpace colorSpace)
1299 {
1300 return RGBToYuv(srcBuffer, rgbInfo, PixelFormat::RGB_888, destInfo, PixelFormat::NV12);
1301 }
1302
1303 bool ImageFormatConvertUtils::RGB565ToNV21(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1304 DestConvertInfo &destInfo,
1305 [[maybe_unused]]ColorSpace colorSpace)
1306 {
1307 return RGBToYuv(srcBuffer, rgbInfo, PixelFormat::RGB_565, destInfo, PixelFormat::NV21);
1308 }
1309
1310 bool ImageFormatConvertUtils::RGB565ToNV12(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1311 DestConvertInfo &destInfo,
1312 [[maybe_unused]]ColorSpace colorSpace)
1313 {
1314 return RGBToYuv(srcBuffer, rgbInfo, PixelFormat::RGB_565, destInfo, PixelFormat::NV12);
1315 }
1316
1317 bool ImageFormatConvertUtils::RGBAToNV21(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1318 DestConvertInfo &destInfo,
1319 [[maybe_unused]]ColorSpace colorSpace)
1320 {
1321 return RGBToYuv(srcBuffer, rgbInfo, PixelFormat::RGBA_8888, destInfo, PixelFormat::NV21);
1322 }
1323
1324 bool ImageFormatConvertUtils::RGBAToNV12(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1325 DestConvertInfo &destInfo,
1326 [[maybe_unused]]ColorSpace colorSpace)
1327 {
1328 return RGBToYuv(srcBuffer, rgbInfo, PixelFormat::RGBA_8888, destInfo, PixelFormat::NV12);
1329 }
1330
1331 bool ImageFormatConvertUtils::BGRAToNV21(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1332 DestConvertInfo &destInfo,
1333 [[maybe_unused]]ColorSpace colorSpace)
1334 {
1335 return RGBToYuv(srcBuffer, rgbInfo, PixelFormat::BGRA_8888, destInfo, PixelFormat::NV21);
1336 }
1337
1338 bool ImageFormatConvertUtils::BGRAToNV12(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1339 DestConvertInfo &destInfo,
1340 [[maybe_unused]]ColorSpace colorSpace)
1341 {
1342 return RGBToYuv(srcBuffer, rgbInfo, PixelFormat::BGRA_8888, destInfo, PixelFormat::NV12);
1343 }
1344
1345 bool ImageFormatConvertUtils::RGBAF16ToNV21(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1346 DestConvertInfo &destInfo,
1347 [[maybe_unused]]ColorSpace colorSpace)
1348 {
1349 return RGBToYuv(srcBuffer, rgbInfo, PixelFormat::RGBA_F16, destInfo, PixelFormat::NV21);
1350 }
1351
1352 bool ImageFormatConvertUtils::RGBAF16ToNV12(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo,
1353 DestConvertInfo &destInfo,
1354 [[maybe_unused]]ColorSpace colorSpace)
1355 {
1356 return RGBToYuv(srcBuffer, rgbInfo, PixelFormat::RGBA_F16, destInfo, PixelFormat::NV12);
1357 }
1358 } // namespace Media
1359 } // namespace OHOS