blob: a0b947994943e7ebc74b1a0533f818bcc0a821d7 [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>
Jiho Chang3b540842012-04-26 13:39:20 -070036#include <system/graphics.h>
Jiho Chang47bd9532012-03-24 05:56:11 +090037
38#include "csc.h"
39#include "exynos_format.h"
40#include "swconverter.h"
41
42#ifdef EXYNOS_OMX
43#include "Exynos_OMX_Def.h"
44#else
45#include "SEC_OMX_Def.h"
46#endif
47
Jiho Chang3b540842012-04-26 13:39:20 -070048#ifdef ENABLE_FIMC
Jiho Chang47bd9532012-03-24 05:56:11 +090049#include "hwconverter_wrapper.h"
50#endif
51
Jiho Chang3b540842012-04-26 13:39:20 -070052#ifdef ENABLE_GSCALER
Jiho Chang47bd9532012-03-24 05:56:11 +090053#include "exynos_gscaler.h"
54#endif
55
56#define GSCALER_IMG_ALIGN 16
57#define CSC_MAX_PLANES 3
58#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
59
60typedef enum _CSC_PLANE {
61 CSC_Y_PLANE = 0,
62 CSC_RGB_PLANE = 0,
63 CSC_U_PLANE = 1,
64 CSC_UV_PLANE = 1,
65 CSC_V_PLANE = 2
66} CSC_PLANE;
67
68typedef enum _CSC_HW_TYPE {
69 CSC_HW_TYPE_FIMC = 0,
70 CSC_HW_TYPE_GSCALER
71} CSC_HW_TYPE;
72
73typedef struct _CSC_FORMAT {
74 unsigned int width;
75 unsigned int height;
76 unsigned int crop_left;
77 unsigned int crop_top;
78 unsigned int crop_width;
79 unsigned int crop_height;
80 unsigned int color_format;
81 unsigned int cacheable;
Jiho Chang3b540842012-04-26 13:39:20 -070082 unsigned int mode_drm;
Jiho Chang47bd9532012-03-24 05:56:11 +090083} CSC_FORMAT;
84
85typedef struct _CSC_BUFFER {
86 unsigned char *planes[CSC_MAX_PLANES];
87 int ion_fd;
88} CSC_BUFFER;
89
Jiho Chang3b540842012-04-26 13:39:20 -070090typedef struct _CSC_HW_PROPERTY {
91 int fixed_node;
92 int mode_drm;
93} CSC_HW_PROPERTY;
94
Jiho Chang47bd9532012-03-24 05:56:11 +090095typedef struct _CSC_HANDLE {
96 CSC_FORMAT dst_format;
97 CSC_FORMAT src_format;
98 CSC_BUFFER dst_buffer;
99 CSC_BUFFER src_buffer;
100 CSC_METHOD csc_method;
101 CSC_HW_TYPE csc_hw_type;
102 void *csc_hw_handle;
Jiho Chang3b540842012-04-26 13:39:20 -0700103 CSC_HW_PROPERTY hw_property;
Jiho Chang47bd9532012-03-24 05:56:11 +0900104} CSC_HANDLE;
105
Jiho Chang47bd9532012-03-24 05:56:11 +0900106/* source is RGB888 */
107static CSC_ERRORCODE conv_sw_src_argb888(
108 CSC_HANDLE *handle)
109{
110 CSC_ERRORCODE ret = CSC_ErrorNone;
111
112 switch (handle->dst_format.color_format) {
113 case HAL_PIXEL_FORMAT_YCbCr_420_P:
114 csc_ARGB8888_to_YUV420P(
115 (unsigned char *)handle->dst_buffer.planes[CSC_Y_PLANE],
116 (unsigned char *)handle->dst_buffer.planes[CSC_U_PLANE],
117 (unsigned char *)handle->dst_buffer.planes[CSC_V_PLANE],
118 (unsigned char *)handle->src_buffer.planes[CSC_RGB_PLANE],
119 handle->src_format.width,
120 handle->src_format.height);
121 ret = CSC_ErrorNone;
122 break;
123 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
124 csc_ARGB8888_to_YUV420SP_NEON(
125 (unsigned char *)handle->dst_buffer.planes[CSC_Y_PLANE],
126 (unsigned char *)handle->dst_buffer.planes[CSC_UV_PLANE],
127 (unsigned char *)handle->src_buffer.planes[CSC_RGB_PLANE],
128 handle->src_format.width,
129 handle->src_format.height);
130 ret = CSC_ErrorNone;
131 break;
132 default:
133 ret = CSC_ErrorUnsupportFormat;
134 break;
135 }
136
137 return ret;
138}
139
140/* source is NV12T */
141static CSC_ERRORCODE conv_sw_src_nv12t(
142 CSC_HANDLE *handle)
143{
144 CSC_ERRORCODE ret = CSC_ErrorNone;
145
146 switch (handle->dst_format.color_format) {
147 case HAL_PIXEL_FORMAT_YCbCr_420_P:
148 csc_tiled_to_linear_y_neon(
149 (unsigned char *)handle->dst_buffer.planes[CSC_Y_PLANE],
150 (unsigned char *)handle->src_buffer.planes[CSC_Y_PLANE],
151 handle->src_format.width,
152 handle->src_format.height);
153 csc_tiled_to_linear_uv_deinterleave_neon(
154 (unsigned char *)handle->dst_buffer.planes[CSC_U_PLANE],
155 (unsigned char *)handle->dst_buffer.planes[CSC_V_PLANE],
156 (unsigned char *)handle->src_buffer.planes[CSC_UV_PLANE],
157 handle->src_format.width,
158 handle->src_format.height / 2);
159 ret = CSC_ErrorNone;
160 break;
161 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
162 csc_tiled_to_linear_y_neon(
163 (unsigned char *)handle->dst_buffer.planes[CSC_Y_PLANE],
164 (unsigned char *)handle->src_buffer.planes[CSC_Y_PLANE],
165 handle->src_format.width,
166 handle->src_format.height);
167 csc_tiled_to_linear_uv_neon(
168 (unsigned char *)handle->dst_buffer.planes[CSC_UV_PLANE],
169 (unsigned char *)handle->src_buffer.planes[CSC_UV_PLANE],
170 handle->src_format.width,
171 handle->src_format.height / 2);
172 ret = CSC_ErrorNone;
173 break;
174 default:
175 ret = CSC_ErrorUnsupportFormat;
176 break;
177 }
178
179 return ret;
180}
181
182/* source is YUV420P */
183static CSC_ERRORCODE conv_sw_src_yuv420p(
184 CSC_HANDLE *handle)
185{
186 CSC_ERRORCODE ret = CSC_ErrorNone;
187
188 switch (handle->dst_format.color_format) {
189 case HAL_PIXEL_FORMAT_YCbCr_420_P: /* bypass */
190 memcpy((unsigned char *)handle->dst_buffer.planes[CSC_Y_PLANE],
191 (unsigned char *)handle->src_buffer.planes[CSC_Y_PLANE],
192 handle->src_format.width * handle->src_format.height);
193 memcpy((unsigned char *)handle->dst_buffer.planes[CSC_U_PLANE],
194 (unsigned char *)handle->src_buffer.planes[CSC_U_PLANE],
195 (handle->src_format.width * handle->src_format.height) >> 2);
196 memcpy((unsigned char *)handle->dst_buffer.planes[CSC_V_PLANE],
197 (unsigned char *)handle->src_buffer.planes[CSC_V_PLANE],
198 (handle->src_format.width * handle->src_format.height) >> 2);
199 ret = CSC_ErrorNone;
200 break;
201 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
202 memcpy((unsigned char *)handle->dst_buffer.planes[CSC_Y_PLANE],
203 (unsigned char *)handle->src_buffer.planes[CSC_Y_PLANE],
204 handle->src_format.width * handle->src_format.height);
205 csc_interleave_memcpy_neon(
206 (unsigned char *)handle->dst_buffer.planes[CSC_UV_PLANE],
207 (unsigned char *)handle->src_buffer.planes[CSC_U_PLANE],
208 (unsigned char *)handle->src_buffer.planes[CSC_V_PLANE],
209 (handle->src_format.width * handle->src_format.height) >> 2);
210 ret = CSC_ErrorNone;
211 break;
212 default:
213 ret = CSC_ErrorUnsupportFormat;
214 break;
215 }
216
217 return ret;
218}
219
220/* source is YUV420SP */
221static CSC_ERRORCODE conv_sw_src_yuv420sp(
222 CSC_HANDLE *handle)
223{
224 CSC_ERRORCODE ret = CSC_ErrorNone;
225
226 switch (handle->dst_format.color_format) {
227 case HAL_PIXEL_FORMAT_YCbCr_420_P:
228 memcpy((unsigned char *)handle->dst_buffer.planes[CSC_Y_PLANE],
229 (unsigned char *)handle->src_buffer.planes[CSC_Y_PLANE],
230 handle->src_format.width * handle->src_format.height);
231 csc_deinterleave_memcpy(
232 (unsigned char *)handle->dst_buffer.planes[CSC_U_PLANE],
233 (unsigned char *)handle->dst_buffer.planes[CSC_V_PLANE],
234 (unsigned char *)handle->src_buffer.planes[CSC_UV_PLANE],
235 handle->src_format.width * handle->src_format.height >> 1);
236 ret = CSC_ErrorNone;
237 break;
238 case HAL_PIXEL_FORMAT_YCbCr_420_SP: /* bypass */
239 memcpy((unsigned char *)handle->dst_buffer.planes[CSC_Y_PLANE],
240 (unsigned char *)handle->src_buffer.planes[CSC_Y_PLANE],
241 handle->src_format.width * handle->src_format.height);
242 memcpy((unsigned char *)handle->dst_buffer.planes[CSC_UV_PLANE],
243 (unsigned char *)handle->src_buffer.planes[CSC_UV_PLANE],
244 handle->src_format.width * handle->src_format.height >> 1);
245 ret = CSC_ErrorNone;
246 break;
247 default:
248 ret = CSC_ErrorUnsupportFormat;
249 break;
250 }
251
252 return ret;
253}
254
255static CSC_ERRORCODE conv_sw(
256 CSC_HANDLE *handle)
257{
258 CSC_ERRORCODE ret = CSC_ErrorNone;
259
260 switch (handle->src_format.color_format) {
261 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
262 ret = conv_sw_src_nv12t(handle);
263 break;
264 case HAL_PIXEL_FORMAT_YCbCr_420_P:
265 ret = conv_sw_src_yuv420p(handle);
266 break;
267 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
268 ret = conv_sw_src_yuv420sp(handle);
269 break;
270 case HAL_PIXEL_FORMAT_ARGB888:
271 ret = conv_sw_src_argb888(handle);
272 break;
273 default:
274 ret = CSC_ErrorUnsupportFormat;
275 break;
276 }
277
278 return ret;
279}
280
281static CSC_ERRORCODE conv_hw(
282 CSC_HANDLE *handle)
283{
284 CSC_ERRORCODE ret = CSC_ErrorNone;
Jiho Chang47bd9532012-03-24 05:56:11 +0900285 switch (handle->csc_hw_type) {
Jiho Chang3b540842012-04-26 13:39:20 -0700286#ifdef ENABLE_FIMC
Jiho Chang47bd9532012-03-24 05:56:11 +0900287 case CSC_HW_TYPE_FIMC:
288 {
289 void *src_addr[3];
290 void *dst_addr[3];
Jiho Chang3b540842012-04-26 13:39:20 -0700291 OMX_COLOR_FORMATTYPE src_omx_format;
292 OMX_COLOR_FORMATTYPE dst_omx_format;
Jiho Chang47bd9532012-03-24 05:56:11 +0900293 src_addr[0] = handle->src_buffer.planes[CSC_Y_PLANE];
294 src_addr[1] = handle->src_buffer.planes[CSC_UV_PLANE];
295 dst_addr[0] = handle->dst_buffer.planes[CSC_Y_PLANE];
296 dst_addr[1] = handle->dst_buffer.planes[CSC_U_PLANE];
297 dst_addr[2] = handle->dst_buffer.planes[CSC_V_PLANE];
Jiho Chang3b540842012-04-26 13:39:20 -0700298 src_omx_format = hal_2_omx_pixel_format(handle->src_format.color_format);
299 dst_omx_format = hal_2_omx_pixel_format(handle->dst_format.color_format);
Jiho Chang47bd9532012-03-24 05:56:11 +0900300 csc_hwconverter_convert_nv12t(
301 handle->csc_hw_handle,
302 dst_addr,
303 src_addr,
304 handle->dst_format.width,
305 handle->dst_format.height,
Jiho Chang3b540842012-04-26 13:39:20 -0700306 dst_omx_format,
307 src_omx_format);
Jiho Chang47bd9532012-03-24 05:56:11 +0900308 break;
309 }
310#endif
Jiho Chang3b540842012-04-26 13:39:20 -0700311#ifdef ENABLE_GSCALER
Jiho Chang47bd9532012-03-24 05:56:11 +0900312 case CSC_HW_TYPE_GSCALER:
Jiho Chang3b540842012-04-26 13:39:20 -0700313 if (exynos_gsc_convert(handle->csc_hw_handle) != 0) {
314 ALOGE("%s:: exynos_gsc_convert() fail", __func__);
315 ret = CSC_Error;
316 }
Jiho Chang47bd9532012-03-24 05:56:11 +0900317 break;
318#endif
319 default:
Jiho Chang3b540842012-04-26 13:39:20 -0700320 ALOGE("%s:: unsupported csc_hw_type(%d)", __func__, handle->csc_hw_type);
321 ret = CSC_ErrorNotImplemented;
Jiho Chang47bd9532012-03-24 05:56:11 +0900322 break;
323 }
324
Jiho Chang3b540842012-04-26 13:39:20 -0700325 return ret;
Jiho Chang47bd9532012-03-24 05:56:11 +0900326}
327
Jiho Chang3b540842012-04-26 13:39:20 -0700328static CSC_ERRORCODE csc_init_hw(
329 void *handle)
Jiho Chang47bd9532012-03-24 05:56:11 +0900330{
331 CSC_HANDLE *csc_handle;
Jiho Chang3b540842012-04-26 13:39:20 -0700332 CSC_ERRORCODE ret = CSC_ErrorNone;
Jiho Chang47bd9532012-03-24 05:56:11 +0900333
Jiho Chang3b540842012-04-26 13:39:20 -0700334 csc_handle = (CSC_HANDLE *)handle;
335 if (csc_handle->csc_method == CSC_METHOD_HW) {
336#ifdef ENABLE_FIMC
Jiho Chang47bd9532012-03-24 05:56:11 +0900337 csc_handle->csc_hw_type = CSC_HW_TYPE_FIMC;
338#endif
Jiho Chang3b540842012-04-26 13:39:20 -0700339#ifdef ENABLE_GSCALER
Jiho Chang47bd9532012-03-24 05:56:11 +0900340 csc_handle->csc_hw_type = CSC_HW_TYPE_GSCALER;
341#endif
342 switch (csc_handle->csc_hw_type) {
Jiho Chang3b540842012-04-26 13:39:20 -0700343#ifdef ENABLE_FIMC
Jiho Chang47bd9532012-03-24 05:56:11 +0900344 case CSC_HW_TYPE_FIMC:
345 csc_handle->csc_hw_handle = csc_hwconverter_open();
Jiho Chang3b540842012-04-26 13:39:20 -0700346 ALOGV("%s:: CSC_HW_TYPE_FIMC", __func__);
Jiho Chang47bd9532012-03-24 05:56:11 +0900347 break;
348#endif
Jiho Chang3b540842012-04-26 13:39:20 -0700349#ifdef ENABLE_GSCALER
Jiho Chang47bd9532012-03-24 05:56:11 +0900350 case CSC_HW_TYPE_GSCALER:
Jiho Chang3b540842012-04-26 13:39:20 -0700351 if (csc_handle->hw_property.fixed_node >= 0)
352 csc_handle->csc_hw_handle = exynos_gsc_create_exclusive(csc_handle->hw_property.fixed_node, GSC_M2M_MODE, 0);
353 else
Jiho Chang47bd9532012-03-24 05:56:11 +0900354 csc_handle->csc_hw_handle = exynos_gsc_create();
Jiho Chang3b540842012-04-26 13:39:20 -0700355 ALOGV("%s:: CSC_HW_TYPE_GSCALER", __func__);
Jiho Chang47bd9532012-03-24 05:56:11 +0900356 break;
357#endif
358 default:
Dima Zavinbaa53d42012-04-02 23:44:05 -0700359 ALOGE("%s:: unsupported csc_hw_type, csc use sw", __func__);
Jiho Chang47bd9532012-03-24 05:56:11 +0900360 csc_handle->csc_hw_handle == NULL;
361 break;
362 }
363 }
364
Jiho Chang47bd9532012-03-24 05:56:11 +0900365 if (csc_handle->csc_method == CSC_METHOD_HW) {
366 if (csc_handle->csc_hw_handle == NULL) {
Dima Zavinbaa53d42012-04-02 23:44:05 -0700367 ALOGE("%s:: CSC_METHOD_HW can't open HW", __func__);
Jiho Chang47bd9532012-03-24 05:56:11 +0900368 free(csc_handle);
369 csc_handle = NULL;
370 }
371 }
372
Jiho Chang3b540842012-04-26 13:39:20 -0700373 ALOGV("%s:: CSC_METHOD=%d", __func__, csc_handle->csc_method);
374
375 return ret;
376}
377
378static CSC_ERRORCODE csc_set_format(
379 void *handle)
380{
381 CSC_HANDLE *csc_handle;
382 CSC_ERRORCODE ret = CSC_ErrorNone;
383
384 if (handle == NULL)
385 return CSC_ErrorNotInit;
386
387 csc_handle = (CSC_HANDLE *)handle;
388 if (csc_handle->csc_method == CSC_METHOD_HW) {
389 switch (csc_handle->csc_hw_type) {
390 case CSC_HW_TYPE_FIMC:
391 break;
392#ifdef ENABLE_GSCALER
393 case CSC_HW_TYPE_GSCALER:
394 exynos_gsc_set_src_format(
395 csc_handle->csc_hw_handle,
396 ALIGN(csc_handle->src_format.width, GSCALER_IMG_ALIGN),
397 ALIGN(csc_handle->src_format.height, GSCALER_IMG_ALIGN),
398 csc_handle->src_format.crop_left,
399 csc_handle->src_format.crop_top,
Jiho Changd50f6502012-06-01 20:40:47 +0000400 csc_handle->src_format.crop_width,
401 csc_handle->src_format.crop_height,
Jiho Chang3b540842012-04-26 13:39:20 -0700402 HAL_PIXEL_FORMAT_2_V4L2_PIX(csc_handle->src_format.color_format),
403 csc_handle->src_format.cacheable,
404 csc_handle->hw_property.mode_drm);
405
406 exynos_gsc_set_dst_format(
407 csc_handle->csc_hw_handle,
408 ALIGN(csc_handle->dst_format.width, GSCALER_IMG_ALIGN),
409 ALIGN(csc_handle->dst_format.height, GSCALER_IMG_ALIGN),
410 csc_handle->dst_format.crop_left,
411 csc_handle->dst_format.crop_top,
Jiho Changd50f6502012-06-01 20:40:47 +0000412 csc_handle->dst_format.crop_width,
413 csc_handle->dst_format.crop_height,
Jiho Chang3b540842012-04-26 13:39:20 -0700414 HAL_PIXEL_FORMAT_2_V4L2_PIX(csc_handle->dst_format.color_format),
415 csc_handle->dst_format.cacheable,
416 csc_handle->hw_property.mode_drm);
417 break;
418#endif
419 default:
420 ALOGE("%s:: unsupported csc_hw_type", __func__);
421 break;
422 }
423 }
424
425 return ret;
426}
427
428static CSC_ERRORCODE csc_set_buffer(
429 void *handle)
430{
431 CSC_HANDLE *csc_handle;
432 CSC_ERRORCODE ret = CSC_ErrorNone;
433 void *src_addr[3] = {NULL, };
434 void *dst_addr[3] = {NULL, };
435
436 if (handle == NULL)
437 return CSC_ErrorNotInit;
438
439 csc_handle = (CSC_HANDLE *)handle;
440 if (csc_handle->csc_method == CSC_METHOD_HW) {
441 src_addr[0] = csc_handle->src_buffer.planes[CSC_Y_PLANE];
442 src_addr[1] = csc_handle->src_buffer.planes[CSC_U_PLANE];
443 src_addr[2] = csc_handle->src_buffer.planes[CSC_V_PLANE];
444 dst_addr[0] = csc_handle->dst_buffer.planes[CSC_Y_PLANE];
445 dst_addr[1] = csc_handle->dst_buffer.planes[CSC_U_PLANE];
446 dst_addr[2] = csc_handle->dst_buffer.planes[CSC_V_PLANE];
447
448 switch (csc_handle->csc_hw_type) {
449 case CSC_HW_TYPE_FIMC:
450 break;
451#ifdef ENABLE_GSCALER
452 case CSC_HW_TYPE_GSCALER:
453 exynos_gsc_set_src_addr(csc_handle->csc_hw_handle, src_addr);
454 exynos_gsc_set_dst_addr(csc_handle->csc_hw_handle, dst_addr);
455 break;
456#endif
457 default:
458 ALOGE("%s:: unsupported csc_hw_type", __func__);
459 break;
460 }
461 }
462
463 return ret;
464}
465
466void *csc_init(
467 CSC_METHOD method)
468{
469 CSC_HANDLE *csc_handle;
470 csc_handle = (CSC_HANDLE *)malloc(sizeof(CSC_HANDLE));
471 if (csc_handle == NULL)
472 return NULL;
473
474 memset(csc_handle, 0, sizeof(CSC_HANDLE));
475 csc_handle->hw_property.fixed_node = -1;
476 csc_handle->hw_property.mode_drm = 0;
477 csc_handle->csc_method = method;
Jiho Chang47bd9532012-03-24 05:56:11 +0900478
479 return (void *)csc_handle;
480}
481
482CSC_ERRORCODE csc_deinit(
483 void *handle)
484{
485 CSC_ERRORCODE ret = CSC_ErrorNone;
486 CSC_HANDLE *csc_handle;
487
488 csc_handle = (CSC_HANDLE *)handle;
489 if (csc_handle->csc_method == CSC_METHOD_HW) {
490 switch (csc_handle->csc_hw_type) {
Jiho Chang3b540842012-04-26 13:39:20 -0700491#ifdef ENABLE_FIMC
Jiho Chang47bd9532012-03-24 05:56:11 +0900492 case CSC_HW_TYPE_FIMC:
493 csc_hwconverter_close(csc_handle->csc_hw_handle);
494 break;
495#endif
Jiho Chang3b540842012-04-26 13:39:20 -0700496#ifdef ENABLE_GSCALER
Jiho Chang47bd9532012-03-24 05:56:11 +0900497 case CSC_HW_TYPE_GSCALER:
498 exynos_gsc_destroy(csc_handle->csc_hw_handle);
499 break;
500#endif
501 default:
Dima Zavinbaa53d42012-04-02 23:44:05 -0700502 ALOGE("%s:: unsupported csc_hw_type", __func__);
Jiho Chang47bd9532012-03-24 05:56:11 +0900503 break;
504 }
505 }
506
507 if (csc_handle != NULL) {
508 free(csc_handle);
509 ret = CSC_ErrorNone;
510 }
511
512 return ret;
513}
514
515CSC_ERRORCODE csc_get_method(
516 void *handle,
517 CSC_METHOD *method)
518{
519 CSC_HANDLE *csc_handle;
520 CSC_ERRORCODE ret = CSC_ErrorNone;
521
522 if (handle == NULL)
523 return CSC_ErrorNotInit;
524
525 csc_handle = (CSC_HANDLE *)handle;
526 *method = csc_handle->csc_method;
527
528 return ret;
529}
530
Jiho Chang3b540842012-04-26 13:39:20 -0700531CSC_ERRORCODE csc_set_hw_property(
532 void *handle,
533 CSC_HW_PROPERTY_TYPE property,
534 int value)
535{
536 CSC_HANDLE *csc_handle;
537 CSC_ERRORCODE ret = CSC_ErrorNone;
538
539 if (handle == NULL)
540 return CSC_ErrorNotInit;
541
542 csc_handle = (CSC_HANDLE *)handle;
543 switch (property) {
544 case CSC_HW_PROPERTY_FIXED_NODE:
545 csc_handle->hw_property.fixed_node = value;
546 break;
547 case CSC_HW_PROPERTY_MODE_DRM:
548 csc_handle->hw_property.mode_drm = value;
549 break;
550 default:
551 ALOGE("%s:: not supported hw property", __func__);
552 ret = CSC_ErrorUnsupportFormat;
553 }
554
555 return ret;
556}
557
Jiho Chang47bd9532012-03-24 05:56:11 +0900558CSC_ERRORCODE csc_get_src_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->src_format.width;
577 *height = csc_handle->src_format.height;
578 *crop_left = csc_handle->src_format.crop_left;
579 *crop_top = csc_handle->src_format.crop_top;
580 *crop_width = csc_handle->src_format.crop_width;
581 *crop_height = csc_handle->src_format.crop_height;
582 *color_format = csc_handle->src_format.color_format;
583 *cacheable = csc_handle->src_format.cacheable;
584
585 return ret;
586}
587
588CSC_ERRORCODE csc_set_src_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->src_format.width = width;
607 csc_handle->src_format.height = height;
608 csc_handle->src_format.crop_left = crop_left;
609 csc_handle->src_format.crop_top = crop_top;
610 csc_handle->src_format.crop_width = crop_width;
611 csc_handle->src_format.crop_height = crop_height;
612 csc_handle->src_format.color_format = color_format;
613 csc_handle->src_format.cacheable = cacheable;
614
Jiho Chang47bd9532012-03-24 05:56:11 +0900615 return ret;
616}
617
618CSC_ERRORCODE csc_get_dst_format(
619 void *handle,
620 unsigned int *width,
621 unsigned int *height,
622 unsigned int *crop_left,
623 unsigned int *crop_top,
624 unsigned int *crop_width,
625 unsigned int *crop_height,
626 unsigned int *color_format,
627 unsigned int *cacheable)
628{
629 CSC_HANDLE *csc_handle;
630 CSC_ERRORCODE ret = CSC_ErrorNone;
631
632 if (handle == NULL)
633 return CSC_ErrorNotInit;
634
635 csc_handle = (CSC_HANDLE *)handle;
636 *width = csc_handle->dst_format.width;
637 *height = csc_handle->dst_format.height;
638 *crop_left = csc_handle->dst_format.crop_left;
639 *crop_top = csc_handle->dst_format.crop_top;
640 *crop_width = csc_handle->dst_format.crop_width;
641 *crop_height = csc_handle->dst_format.crop_height;
642 *color_format = csc_handle->dst_format.color_format;
643 *cacheable = csc_handle->dst_format.cacheable;
644
645 return ret;
646}
647
648CSC_ERRORCODE csc_set_dst_format(
649 void *handle,
650 unsigned int width,
651 unsigned int height,
652 unsigned int crop_left,
653 unsigned int crop_top,
654 unsigned int crop_width,
655 unsigned int crop_height,
656 unsigned int color_format,
657 unsigned int cacheable)
658{
659 CSC_HANDLE *csc_handle;
660 CSC_ERRORCODE ret = CSC_ErrorNone;
661
662 if (handle == NULL)
663 return CSC_ErrorNotInit;
664
665 csc_handle = (CSC_HANDLE *)handle;
666 csc_handle->dst_format.width = width;
667 csc_handle->dst_format.height = height;
668 csc_handle->dst_format.crop_left = crop_left;
669 csc_handle->dst_format.crop_top = crop_top;
670 csc_handle->dst_format.crop_width = crop_width;
671 csc_handle->dst_format.crop_height = crop_height;
672 csc_handle->dst_format.color_format = color_format;
673 csc_handle->dst_format.cacheable = cacheable;
674
Jiho Chang47bd9532012-03-24 05:56:11 +0900675 return ret;
676}
677
678CSC_ERRORCODE csc_set_src_buffer(
679 void *handle,
680 unsigned char *y,
681 unsigned char *u,
682 unsigned char *v,
683 int ion_fd)
684{
685 CSC_HANDLE *csc_handle;
686 CSC_ERRORCODE ret = CSC_ErrorNone;
687 void *addr[3] = {NULL, };
688
689 if (handle == NULL)
690 return CSC_ErrorNotInit;
691
692 csc_handle = (CSC_HANDLE *)handle;
693 csc_handle->src_buffer.planes[CSC_Y_PLANE] = y;
694 csc_handle->src_buffer.planes[CSC_U_PLANE] = u;
695 csc_handle->src_buffer.planes[CSC_V_PLANE] = v;
696
Jiho Chang47bd9532012-03-24 05:56:11 +0900697 return ret;
698}
699
700CSC_ERRORCODE csc_set_dst_buffer(
701 void *handle,
702 unsigned char *y,
703 unsigned char *u,
704 unsigned char *v,
705 int ion_fd)
706{
707 CSC_HANDLE *csc_handle;
708 CSC_ERRORCODE ret = CSC_ErrorNone;
709 void *addr[3] = {NULL, };
710
711 if (handle == NULL)
712 return CSC_ErrorNotInit;
713
714 csc_handle = (CSC_HANDLE *)handle;
715 csc_handle->dst_buffer.planes[CSC_Y_PLANE] = y;
716 csc_handle->dst_buffer.planes[CSC_U_PLANE] = u;
717 csc_handle->dst_buffer.planes[CSC_V_PLANE] = v;
718
Jiho Chang47bd9532012-03-24 05:56:11 +0900719 return ret;
720}
721
722CSC_ERRORCODE csc_convert(
723 void *handle)
724{
725 CSC_HANDLE *csc_handle = (CSC_HANDLE *)handle;
726 CSC_ERRORCODE ret = CSC_ErrorNone;
727
728 if (csc_handle == NULL)
729 return CSC_ErrorNotInit;
730
Jiho Chang3b540842012-04-26 13:39:20 -0700731 if ((csc_handle->csc_method == CSC_METHOD_HW) &&
732 (csc_handle->csc_hw_handle == NULL))
733 csc_init_hw(handle);
734
735 csc_set_format(csc_handle);
736 csc_set_buffer(csc_handle);
737
Jiho Chang47bd9532012-03-24 05:56:11 +0900738 if (csc_handle->csc_method == CSC_METHOD_HW)
739 ret = conv_hw(csc_handle);
740 else
741 ret = conv_sw(csc_handle);
742
743 return ret;
744}