blob: 26b26cc97d3ceb9cfccf5e31d2be916f6332fced [file] [log] [blame]
Jiho Chang47bd9532012-03-24 05:56:11 +09001/*
2 *
3 * Copyright 2012 Samsung Electronics S.LSI Co. LTD
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * @file csc.c
20 *
21 * @brief color space convertion abstract source
22 *
23 * @author Pyoungjae Jung(pjet.jung@samsung.com)
24 *
25 * @version 1.0.0
26 *
27 * @history
28 * 2012.1.11 : Create
29 */
30#define LOG_TAG "libcsc"
31#include <cutils/log.h>
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <utils/Log.h>
36
37#include "csc.h"
38#include "exynos_format.h"
39#include "swconverter.h"
40
41#ifdef EXYNOS_OMX
42#include "Exynos_OMX_Def.h"
43#else
44#include "SEC_OMX_Def.h"
45#endif
46
47#ifdef USE_FIMC
48#include "hwconverter_wrapper.h"
49#endif
50
51#ifdef USE_GSCALER
52#include "exynos_gscaler.h"
53#endif
54
55#define GSCALER_IMG_ALIGN 16
56#define CSC_MAX_PLANES 3
57#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
58
59typedef enum _CSC_PLANE {
60 CSC_Y_PLANE = 0,
61 CSC_RGB_PLANE = 0,
62 CSC_U_PLANE = 1,
63 CSC_UV_PLANE = 1,
64 CSC_V_PLANE = 2
65} CSC_PLANE;
66
67typedef enum _CSC_HW_TYPE {
68 CSC_HW_TYPE_FIMC = 0,
69 CSC_HW_TYPE_GSCALER
70} CSC_HW_TYPE;
71
72typedef struct _CSC_FORMAT {
73 unsigned int width;
74 unsigned int height;
75 unsigned int crop_left;
76 unsigned int crop_top;
77 unsigned int crop_width;
78 unsigned int crop_height;
79 unsigned int color_format;
80 unsigned int cacheable;
81} CSC_FORMAT;
82
83typedef struct _CSC_BUFFER {
84 unsigned char *planes[CSC_MAX_PLANES];
85 int ion_fd;
86} CSC_BUFFER;
87
88typedef struct _CSC_HANDLE {
89 CSC_FORMAT dst_format;
90 CSC_FORMAT src_format;
91 CSC_BUFFER dst_buffer;
92 CSC_BUFFER src_buffer;
93 CSC_METHOD csc_method;
94 CSC_HW_TYPE csc_hw_type;
95 void *csc_hw_handle;
96} CSC_HANDLE;
97
98OMX_COLOR_FORMATTYPE hal_2_omx_pixel_format(
99 unsigned int hal_format)
100{
101 OMX_COLOR_FORMATTYPE omx_format;
102 switch (hal_format) {
103 case HAL_PIXEL_FORMAT_YCbCr_420_P:
104 omx_format = OMX_COLOR_FormatYUV420Planar;
105 break;
106 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
107 omx_format = OMX_COLOR_FormatYUV420SemiPlanar;
108 break;
109 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
110 omx_format = OMX_SEC_COLOR_FormatNV12Tiled;
111 break;
112 case HAL_PIXEL_FORMAT_ARGB888:
113 omx_format = OMX_COLOR_Format32bitARGB8888;
114 break;
115 default:
116 omx_format = OMX_COLOR_FormatYUV420Planar;
117 break;
118 }
119 return omx_format;
120}
121
122unsigned int omx_2_hal_pixel_format(
123 OMX_COLOR_FORMATTYPE omx_format)
124{
125 unsigned int hal_format;
126 switch (omx_format) {
127 case OMX_COLOR_FormatYUV420Planar:
128 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
129 break;
130 case OMX_COLOR_FormatYUV420SemiPlanar:
131 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP;
132 break;
133 case OMX_SEC_COLOR_FormatNV12Tiled:
134 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED;
135 break;
136 case OMX_COLOR_Format32bitARGB8888:
137 hal_format = HAL_PIXEL_FORMAT_ARGB888;
138 break;
139 default:
140 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
141 break;
142 }
143 return hal_format;
144}
145
146/* source is RGB888 */
147static CSC_ERRORCODE conv_sw_src_argb888(
148 CSC_HANDLE *handle)
149{
150 CSC_ERRORCODE ret = CSC_ErrorNone;
151
152 switch (handle->dst_format.color_format) {
153 case HAL_PIXEL_FORMAT_YCbCr_420_P:
154 csc_ARGB8888_to_YUV420P(
155 (unsigned char *)handle->dst_buffer.planes[CSC_Y_PLANE],
156 (unsigned char *)handle->dst_buffer.planes[CSC_U_PLANE],
157 (unsigned char *)handle->dst_buffer.planes[CSC_V_PLANE],
158 (unsigned char *)handle->src_buffer.planes[CSC_RGB_PLANE],
159 handle->src_format.width,
160 handle->src_format.height);
161 ret = CSC_ErrorNone;
162 break;
163 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
164 csc_ARGB8888_to_YUV420SP_NEON(
165 (unsigned char *)handle->dst_buffer.planes[CSC_Y_PLANE],
166 (unsigned char *)handle->dst_buffer.planes[CSC_UV_PLANE],
167 (unsigned char *)handle->src_buffer.planes[CSC_RGB_PLANE],
168 handle->src_format.width,
169 handle->src_format.height);
170 ret = CSC_ErrorNone;
171 break;
172 default:
173 ret = CSC_ErrorUnsupportFormat;
174 break;
175 }
176
177 return ret;
178}
179
180/* source is NV12T */
181static CSC_ERRORCODE conv_sw_src_nv12t(
182 CSC_HANDLE *handle)
183{
184 CSC_ERRORCODE ret = CSC_ErrorNone;
185
186 switch (handle->dst_format.color_format) {
187 case HAL_PIXEL_FORMAT_YCbCr_420_P:
188 csc_tiled_to_linear_y_neon(
189 (unsigned char *)handle->dst_buffer.planes[CSC_Y_PLANE],
190 (unsigned char *)handle->src_buffer.planes[CSC_Y_PLANE],
191 handle->src_format.width,
192 handle->src_format.height);
193 csc_tiled_to_linear_uv_deinterleave_neon(
194 (unsigned char *)handle->dst_buffer.planes[CSC_U_PLANE],
195 (unsigned char *)handle->dst_buffer.planes[CSC_V_PLANE],
196 (unsigned char *)handle->src_buffer.planes[CSC_UV_PLANE],
197 handle->src_format.width,
198 handle->src_format.height / 2);
199 ret = CSC_ErrorNone;
200 break;
201 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
202 csc_tiled_to_linear_y_neon(
203 (unsigned char *)handle->dst_buffer.planes[CSC_Y_PLANE],
204 (unsigned char *)handle->src_buffer.planes[CSC_Y_PLANE],
205 handle->src_format.width,
206 handle->src_format.height);
207 csc_tiled_to_linear_uv_neon(
208 (unsigned char *)handle->dst_buffer.planes[CSC_UV_PLANE],
209 (unsigned char *)handle->src_buffer.planes[CSC_UV_PLANE],
210 handle->src_format.width,
211 handle->src_format.height / 2);
212 ret = CSC_ErrorNone;
213 break;
214 default:
215 ret = CSC_ErrorUnsupportFormat;
216 break;
217 }
218
219 return ret;
220}
221
222/* source is YUV420P */
223static CSC_ERRORCODE conv_sw_src_yuv420p(
224 CSC_HANDLE *handle)
225{
226 CSC_ERRORCODE ret = CSC_ErrorNone;
227
228 switch (handle->dst_format.color_format) {
229 case HAL_PIXEL_FORMAT_YCbCr_420_P: /* bypass */
230 memcpy((unsigned char *)handle->dst_buffer.planes[CSC_Y_PLANE],
231 (unsigned char *)handle->src_buffer.planes[CSC_Y_PLANE],
232 handle->src_format.width * handle->src_format.height);
233 memcpy((unsigned char *)handle->dst_buffer.planes[CSC_U_PLANE],
234 (unsigned char *)handle->src_buffer.planes[CSC_U_PLANE],
235 (handle->src_format.width * handle->src_format.height) >> 2);
236 memcpy((unsigned char *)handle->dst_buffer.planes[CSC_V_PLANE],
237 (unsigned char *)handle->src_buffer.planes[CSC_V_PLANE],
238 (handle->src_format.width * handle->src_format.height) >> 2);
239 ret = CSC_ErrorNone;
240 break;
241 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
242 memcpy((unsigned char *)handle->dst_buffer.planes[CSC_Y_PLANE],
243 (unsigned char *)handle->src_buffer.planes[CSC_Y_PLANE],
244 handle->src_format.width * handle->src_format.height);
245 csc_interleave_memcpy_neon(
246 (unsigned char *)handle->dst_buffer.planes[CSC_UV_PLANE],
247 (unsigned char *)handle->src_buffer.planes[CSC_U_PLANE],
248 (unsigned char *)handle->src_buffer.planes[CSC_V_PLANE],
249 (handle->src_format.width * handle->src_format.height) >> 2);
250 ret = CSC_ErrorNone;
251 break;
252 default:
253 ret = CSC_ErrorUnsupportFormat;
254 break;
255 }
256
257 return ret;
258}
259
260/* source is YUV420SP */
261static CSC_ERRORCODE conv_sw_src_yuv420sp(
262 CSC_HANDLE *handle)
263{
264 CSC_ERRORCODE ret = CSC_ErrorNone;
265
266 switch (handle->dst_format.color_format) {
267 case HAL_PIXEL_FORMAT_YCbCr_420_P:
268 memcpy((unsigned char *)handle->dst_buffer.planes[CSC_Y_PLANE],
269 (unsigned char *)handle->src_buffer.planes[CSC_Y_PLANE],
270 handle->src_format.width * handle->src_format.height);
271 csc_deinterleave_memcpy(
272 (unsigned char *)handle->dst_buffer.planes[CSC_U_PLANE],
273 (unsigned char *)handle->dst_buffer.planes[CSC_V_PLANE],
274 (unsigned char *)handle->src_buffer.planes[CSC_UV_PLANE],
275 handle->src_format.width * handle->src_format.height >> 1);
276 ret = CSC_ErrorNone;
277 break;
278 case HAL_PIXEL_FORMAT_YCbCr_420_SP: /* bypass */
279 memcpy((unsigned char *)handle->dst_buffer.planes[CSC_Y_PLANE],
280 (unsigned char *)handle->src_buffer.planes[CSC_Y_PLANE],
281 handle->src_format.width * handle->src_format.height);
282 memcpy((unsigned char *)handle->dst_buffer.planes[CSC_UV_PLANE],
283 (unsigned char *)handle->src_buffer.planes[CSC_UV_PLANE],
284 handle->src_format.width * handle->src_format.height >> 1);
285 ret = CSC_ErrorNone;
286 break;
287 default:
288 ret = CSC_ErrorUnsupportFormat;
289 break;
290 }
291
292 return ret;
293}
294
295static CSC_ERRORCODE conv_sw(
296 CSC_HANDLE *handle)
297{
298 CSC_ERRORCODE ret = CSC_ErrorNone;
299
300 switch (handle->src_format.color_format) {
301 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
302 ret = conv_sw_src_nv12t(handle);
303 break;
304 case HAL_PIXEL_FORMAT_YCbCr_420_P:
305 ret = conv_sw_src_yuv420p(handle);
306 break;
307 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
308 ret = conv_sw_src_yuv420sp(handle);
309 break;
310 case HAL_PIXEL_FORMAT_ARGB888:
311 ret = conv_sw_src_argb888(handle);
312 break;
313 default:
314 ret = CSC_ErrorUnsupportFormat;
315 break;
316 }
317
318 return ret;
319}
320
321static CSC_ERRORCODE conv_hw(
322 CSC_HANDLE *handle)
323{
324 CSC_ERRORCODE ret = CSC_ErrorNone;
325
326 switch (handle->csc_hw_type) {
327#ifdef USE_FIMC
328 case CSC_HW_TYPE_FIMC:
329 {
330 void *src_addr[3];
331 void *dst_addr[3];
332 OMX_COLOR_FORMATTYPE omx_format;
333 src_addr[0] = handle->src_buffer.planes[CSC_Y_PLANE];
334 src_addr[1] = handle->src_buffer.planes[CSC_UV_PLANE];
335 dst_addr[0] = handle->dst_buffer.planes[CSC_Y_PLANE];
336 dst_addr[1] = handle->dst_buffer.planes[CSC_U_PLANE];
337 dst_addr[2] = handle->dst_buffer.planes[CSC_V_PLANE];
338 omx_format = hal_2_omx_pixel_format(handle->dst_format.color_format);
339 csc_hwconverter_convert_nv12t(
340 handle->csc_hw_handle,
341 dst_addr,
342 src_addr,
343 handle->dst_format.width,
344 handle->dst_format.height,
345 omx_format);
346 break;
347 }
348#endif
349#ifdef USE_GSCALER
350 case CSC_HW_TYPE_GSCALER:
351 exynos_gsc_convert(handle->csc_hw_handle);
352 break;
353#endif
354 default:
355 LOGE("%s:: unsupported csc_hw_type", __func__);
356 break;
357 }
358
359 return CSC_ErrorNotImplemented;
360}
361
362void *csc_init(
363 CSC_METHOD *method)
364{
365 CSC_HANDLE *csc_handle;
366 csc_handle = (CSC_HANDLE *)malloc(sizeof(CSC_HANDLE));
367 if (csc_handle == NULL)
368 return NULL;
369
370 memset(csc_handle, 0, sizeof(CSC_HANDLE));
371
372 csc_handle->csc_method = *method;
373
374 if (csc_handle->csc_method == CSC_METHOD_HW ||
375 csc_handle->csc_method == CSC_METHOD_PREFER_HW) {
376#ifdef USE_FIMC
377 csc_handle->csc_hw_type = CSC_HW_TYPE_FIMC;
378#endif
379#ifdef USE_GSCALER
380 csc_handle->csc_hw_type = CSC_HW_TYPE_GSCALER;
381#endif
382 switch (csc_handle->csc_hw_type) {
383#ifdef USE_FIMC
384 case CSC_HW_TYPE_FIMC:
385 csc_handle->csc_hw_handle = csc_hwconverter_open();
386 LOGD("%s:: CSC_HW_TYPE_FIMC", __func__);
387 break;
388#endif
389#ifdef USE_GSCALER
390 case CSC_HW_TYPE_GSCALER:
391 csc_handle->csc_hw_handle = exynos_gsc_create();
392 LOGD("%s:: CSC_HW_TYPE_GSCALER", __func__);
393 break;
394#endif
395 default:
396 LOGE("%s:: unsupported csc_hw_type, csc use sw", __func__);
397 csc_handle->csc_hw_handle == NULL;
398 break;
399 }
400 }
401
402 if (csc_handle->csc_method == CSC_METHOD_PREFER_HW) {
403 if (csc_handle->csc_hw_handle == NULL) {
404 csc_handle->csc_method = CSC_METHOD_SW;
405 *method = CSC_METHOD_SW;
406 } else {
407 csc_handle->csc_method = CSC_METHOD_HW;
408 *method = CSC_METHOD_HW;
409 }
410 }
411
412 if (csc_handle->csc_method == CSC_METHOD_HW) {
413 if (csc_handle->csc_hw_handle == NULL) {
414 LOGE("%s:: CSC_METHOD_HW can't open HW", __func__);
415 free(csc_handle);
416 csc_handle = NULL;
417 }
418 }
419
420 LOGD("%s:: CSC_METHOD=%d", __func__, csc_handle->csc_method);
421
422 return (void *)csc_handle;
423}
424
425CSC_ERRORCODE csc_deinit(
426 void *handle)
427{
428 CSC_ERRORCODE ret = CSC_ErrorNone;
429 CSC_HANDLE *csc_handle;
430
431 csc_handle = (CSC_HANDLE *)handle;
432 if (csc_handle->csc_method == CSC_METHOD_HW) {
433 switch (csc_handle->csc_hw_type) {
434#ifdef USE_FIMC
435 case CSC_HW_TYPE_FIMC:
436 csc_hwconverter_close(csc_handle->csc_hw_handle);
437 break;
438#endif
439#ifdef USE_GSCALER
440 case CSC_HW_TYPE_GSCALER:
441 exynos_gsc_destroy(csc_handle->csc_hw_handle);
442 break;
443#endif
444 default:
445 LOGE("%s:: unsupported csc_hw_type", __func__);
446 break;
447 }
448 }
449
450 if (csc_handle != NULL) {
451 free(csc_handle);
452 ret = CSC_ErrorNone;
453 }
454
455 return ret;
456}
457
458CSC_ERRORCODE csc_get_method(
459 void *handle,
460 CSC_METHOD *method)
461{
462 CSC_HANDLE *csc_handle;
463 CSC_ERRORCODE ret = CSC_ErrorNone;
464
465 if (handle == NULL)
466 return CSC_ErrorNotInit;
467
468 csc_handle = (CSC_HANDLE *)handle;
469 *method = csc_handle->csc_method;
470
471 return ret;
472}
473
474CSC_ERRORCODE csc_get_src_format(
475 void *handle,
476 unsigned int *width,
477 unsigned int *height,
478 unsigned int *crop_left,
479 unsigned int *crop_top,
480 unsigned int *crop_width,
481 unsigned int *crop_height,
482 unsigned int *color_format,
483 unsigned int *cacheable)
484{
485 CSC_HANDLE *csc_handle;
486 CSC_ERRORCODE ret = CSC_ErrorNone;
487
488 if (handle == NULL)
489 return CSC_ErrorNotInit;
490
491 csc_handle = (CSC_HANDLE *)handle;
492 *width = csc_handle->src_format.width;
493 *height = csc_handle->src_format.height;
494 *crop_left = csc_handle->src_format.crop_left;
495 *crop_top = csc_handle->src_format.crop_top;
496 *crop_width = csc_handle->src_format.crop_width;
497 *crop_height = csc_handle->src_format.crop_height;
498 *color_format = csc_handle->src_format.color_format;
499 *cacheable = csc_handle->src_format.cacheable;
500
501 return ret;
502}
503
504CSC_ERRORCODE csc_set_src_format(
505 void *handle,
506 unsigned int width,
507 unsigned int height,
508 unsigned int crop_left,
509 unsigned int crop_top,
510 unsigned int crop_width,
511 unsigned int crop_height,
512 unsigned int color_format,
513 unsigned int cacheable)
514{
515 CSC_HANDLE *csc_handle;
516 CSC_ERRORCODE ret = CSC_ErrorNone;
517
518 if (handle == NULL)
519 return CSC_ErrorNotInit;
520
521 csc_handle = (CSC_HANDLE *)handle;
522 csc_handle->src_format.width = width;
523 csc_handle->src_format.height = height;
524 csc_handle->src_format.crop_left = crop_left;
525 csc_handle->src_format.crop_top = crop_top;
526 csc_handle->src_format.crop_width = crop_width;
527 csc_handle->src_format.crop_height = crop_height;
528 csc_handle->src_format.color_format = color_format;
529 csc_handle->src_format.cacheable = cacheable;
530
531 if (csc_handle->csc_method == CSC_METHOD_HW) {
532 switch (csc_handle->csc_hw_type) {
533 case CSC_HW_TYPE_FIMC:
534 break;
535#ifdef USE_GSCALER
536 case CSC_HW_TYPE_GSCALER:
537 exynos_gsc_set_src_format(
538 csc_handle->csc_hw_handle,
539 ALIGN(csc_handle->src_format.width, GSCALER_IMG_ALIGN),
540 ALIGN(csc_handle->src_format.height, GSCALER_IMG_ALIGN),
541 csc_handle->src_format.crop_left,
542 csc_handle->src_format.crop_top,
543 ALIGN(csc_handle->src_format.crop_width, GSCALER_IMG_ALIGN),
544 ALIGN(csc_handle->src_format.crop_height, GSCALER_IMG_ALIGN),
545 HAL_PIXEL_FORMAT_2_V4L2_PIX(csc_handle->src_format.color_format),
546 csc_handle->src_format.cacheable);
547 break;
548#endif
549 default:
550 LOGE("%s:: unsupported csc_hw_type", __func__);
551 break;
552 }
553 }
554
555 return ret;
556}
557
558CSC_ERRORCODE csc_get_dst_format(
559 void *handle,
560 unsigned int *width,
561 unsigned int *height,
562 unsigned int *crop_left,
563 unsigned int *crop_top,
564 unsigned int *crop_width,
565 unsigned int *crop_height,
566 unsigned int *color_format,
567 unsigned int *cacheable)
568{
569 CSC_HANDLE *csc_handle;
570 CSC_ERRORCODE ret = CSC_ErrorNone;
571
572 if (handle == NULL)
573 return CSC_ErrorNotInit;
574
575 csc_handle = (CSC_HANDLE *)handle;
576 *width = csc_handle->dst_format.width;
577 *height = csc_handle->dst_format.height;
578 *crop_left = csc_handle->dst_format.crop_left;
579 *crop_top = csc_handle->dst_format.crop_top;
580 *crop_width = csc_handle->dst_format.crop_width;
581 *crop_height = csc_handle->dst_format.crop_height;
582 *color_format = csc_handle->dst_format.color_format;
583 *cacheable = csc_handle->dst_format.cacheable;
584
585 return ret;
586}
587
588CSC_ERRORCODE csc_set_dst_format(
589 void *handle,
590 unsigned int width,
591 unsigned int height,
592 unsigned int crop_left,
593 unsigned int crop_top,
594 unsigned int crop_width,
595 unsigned int crop_height,
596 unsigned int color_format,
597 unsigned int cacheable)
598{
599 CSC_HANDLE *csc_handle;
600 CSC_ERRORCODE ret = CSC_ErrorNone;
601
602 if (handle == NULL)
603 return CSC_ErrorNotInit;
604
605 csc_handle = (CSC_HANDLE *)handle;
606 csc_handle->dst_format.width = width;
607 csc_handle->dst_format.height = height;
608 csc_handle->dst_format.crop_left = crop_left;
609 csc_handle->dst_format.crop_top = crop_top;
610 csc_handle->dst_format.crop_width = crop_width;
611 csc_handle->dst_format.crop_height = crop_height;
612 csc_handle->dst_format.color_format = color_format;
613 csc_handle->dst_format.cacheable = cacheable;
614
615 if (csc_handle->csc_method == CSC_METHOD_HW) {
616 switch (csc_handle->csc_hw_type) {
617 case CSC_HW_TYPE_FIMC:
618 break;
619#ifdef USE_GSCALER
620 case CSC_HW_TYPE_GSCALER:
621 exynos_gsc_set_dst_format(
622 csc_handle->csc_hw_handle,
623 ALIGN(csc_handle->dst_format.width, GSCALER_IMG_ALIGN),
624 ALIGN(csc_handle->dst_format.height, GSCALER_IMG_ALIGN),
625 csc_handle->dst_format.crop_left,
626 csc_handle->dst_format.crop_top,
627 ALIGN(csc_handle->dst_format.crop_width, GSCALER_IMG_ALIGN),
628 ALIGN(csc_handle->dst_format.crop_height, GSCALER_IMG_ALIGN),
629 HAL_PIXEL_FORMAT_2_V4L2_PIX(csc_handle->dst_format.color_format),
630 csc_handle->dst_format.cacheable);
631 break;
632#endif
633 default:
634 LOGE("%s:: unsupported csc_hw_type", __func__);
635 break;
636 }
637 }
638
639 return ret;
640}
641
642CSC_ERRORCODE csc_set_src_buffer(
643 void *handle,
644 unsigned char *y,
645 unsigned char *u,
646 unsigned char *v,
647 int ion_fd)
648{
649 CSC_HANDLE *csc_handle;
650 CSC_ERRORCODE ret = CSC_ErrorNone;
651 void *addr[3] = {NULL, };
652
653 if (handle == NULL)
654 return CSC_ErrorNotInit;
655
656 csc_handle = (CSC_HANDLE *)handle;
657 csc_handle->src_buffer.planes[CSC_Y_PLANE] = y;
658 csc_handle->src_buffer.planes[CSC_U_PLANE] = u;
659 csc_handle->src_buffer.planes[CSC_V_PLANE] = v;
660
661 if (csc_handle->csc_method == CSC_METHOD_HW) {
662 addr[0] = csc_handle->src_buffer.planes[CSC_Y_PLANE];
663 addr[1] = csc_handle->src_buffer.planes[CSC_U_PLANE];
664 addr[2] = csc_handle->src_buffer.planes[CSC_V_PLANE];
665
666 switch (csc_handle->csc_hw_type) {
667 case CSC_HW_TYPE_FIMC:
668 break;
669#ifdef USE_GSCALER
670 case CSC_HW_TYPE_GSCALER:
671 exynos_gsc_set_src_addr(csc_handle->csc_hw_handle, addr);
672 break;
673#endif
674 default:
675 LOGE("%s:: unsupported csc_hw_type", __func__);
676 break;
677 }
678 }
679
680 return ret;
681}
682
683CSC_ERRORCODE csc_set_dst_buffer(
684 void *handle,
685 unsigned char *y,
686 unsigned char *u,
687 unsigned char *v,
688 int ion_fd)
689{
690 CSC_HANDLE *csc_handle;
691 CSC_ERRORCODE ret = CSC_ErrorNone;
692 void *addr[3] = {NULL, };
693
694 if (handle == NULL)
695 return CSC_ErrorNotInit;
696
697 csc_handle = (CSC_HANDLE *)handle;
698 csc_handle->dst_buffer.planes[CSC_Y_PLANE] = y;
699 csc_handle->dst_buffer.planes[CSC_U_PLANE] = u;
700 csc_handle->dst_buffer.planes[CSC_V_PLANE] = v;
701
702 if (csc_handle->csc_method == CSC_METHOD_HW) {
703 addr[0] = csc_handle->dst_buffer.planes[CSC_Y_PLANE];
704 addr[1] = csc_handle->dst_buffer.planes[CSC_U_PLANE];
705 addr[2] = csc_handle->dst_buffer.planes[CSC_V_PLANE];
706
707 switch (csc_handle->csc_hw_type) {
708 case CSC_HW_TYPE_FIMC:
709 break;
710#ifdef USE_GSCALER
711 case CSC_HW_TYPE_GSCALER:
712 exynos_gsc_set_dst_addr(csc_handle->csc_hw_handle, addr);
713 break;
714#endif
715 default:
716 LOGE("%s:: unsupported csc_hw_type", __func__);
717 break;
718 }
719 }
720
721 return ret;
722}
723
724CSC_ERRORCODE csc_convert(
725 void *handle)
726{
727 CSC_HANDLE *csc_handle = (CSC_HANDLE *)handle;
728 CSC_ERRORCODE ret = CSC_ErrorNone;
729
730 if (csc_handle == NULL)
731 return CSC_ErrorNotInit;
732
733 if (csc_handle->csc_method == CSC_METHOD_HW)
734 ret = conv_hw(csc_handle);
735 else
736 ret = conv_sw(csc_handle);
737
738 return ret;
739}