1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* 18 * @file csc.h 19 * 20 * @brief color space convertion abstract header 21 * 22 * @author Pyoungjae Jung (pjet.jung@samsung.com) 23 * 24 * @version 1.0 25 * 26 * @history 27 * 2011.12.27 : Create 28 */ 29 30 #ifndef CSC_H 31 #define CSC_H 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 #define CSC_MAX_PLANES 3 38 39 typedef enum _CSC_ERRORCODE { 40 CSC_ErrorNone = 0, 41 CSC_Error, 42 CSC_ErrorNotInit, 43 CSC_ErrorInvalidAddress, 44 CSC_ErrorUnsupportFormat, 45 CSC_ErrorNotImplemented 46 } CSC_ERRORCODE; 47 48 typedef enum _CSC_METHOD { 49 CSC_METHOD_SW = 0, 50 CSC_METHOD_HW 51 } CSC_METHOD; 52 53 typedef enum _CSC_HW_PROPERTY_TYPE { 54 CSC_HW_PROPERTY_FIXED_NODE = 0, 55 CSC_HW_PROPERTY_MODE_DRM, 56 } CSC_HW_PROPERTY_TYPE; 57 58 typedef enum _CSC_MEMTYPE { 59 CSC_MEMORY_MMAP = 1, 60 CSC_MEMORY_USERPTR, 61 CSC_MEMORY_OVERLAY, 62 CSC_MEMORY_DMABUF, 63 CSC_MEMORY_MFC, 64 } CSC_MEMTYPE; 65 66 typedef enum _CSC_HW_ID { 67 CSC_HW_GSC0 = 0, 68 CSC_HW_GSC1, 69 CSC_HW_GSC2, 70 CSC_HW_GSC3, 71 CSC_HW_SC0, 72 CSC_HW_SC1, 73 CSC_HW_SC2, 74 CSC_HW_MAX, 75 } CSC_HW_ID; 76 77 typedef enum _CSC_PLANE { 78 CSC_Y_PLANE = 0, 79 CSC_RGB_PLANE = 0, 80 CSC_U_PLANE = 1, 81 CSC_UV_PLANE = 1, 82 CSC_V_PLANE = 2 83 } CSC_PLANE; 84 85 typedef enum _CSC_HW_TYPE { 86 CSC_HW_TYPE_FIMC = 0, 87 CSC_HW_TYPE_GSCALER 88 } CSC_HW_TYPE; 89 90 typedef enum _CSC_EQ_MODE { 91 CSC_EQ_MODE_USER = 0, 92 CSC_EQ_MODE_AUTO 93 } CSC_EQ_MODE; 94 95 typedef enum _CSC_EQ_COLORSPACE { 96 CSC_EQ_COLORSPACE_SMPTE170M = 1, 97 CSC_EQ_COLORSPACE_SMPTE240M = 2, 98 CSC_EQ_COLORSPACE_REC709 = 3, 99 CSC_EQ_COLORSPACE_BT878 = 4, 100 CSC_EQ_COLORSPACE_470_SYSTEM_M = 5, 101 CSC_EQ_COLORSPACE_470_SYSTEM_BG = 6, 102 CSC_EQ_COLORSPACE_BT2020 = 10, 103 } CSC_EQ_COLORSPACE; 104 105 typedef enum _CSC_EQ_RANGE { 106 CSC_EQ_RANGE_NARROW = 0, 107 CSC_EQ_RANGE_FULL 108 } CSC_EQ_RANGE; 109 110 typedef enum _CSC_HW_FILTER { 111 CSC_FT_NONE = 0, 112 CSC_FT_BLUR, 113 CSC_FT_240, 114 CSC_FT_480, 115 CSC_FT_720, 116 CSC_FT_960, 117 CSC_FT_1080, 118 CSC_FT_MAX 119 } CSC_HW_FILTER; 120 121 typedef struct _CSC_FORMAT { 122 unsigned int width; 123 unsigned int height; 124 unsigned int crop_left; 125 unsigned int crop_top; 126 unsigned int crop_width; 127 unsigned int crop_height; 128 unsigned int color_format; 129 unsigned int cacheable; 130 unsigned int mode_drm; 131 } CSC_FORMAT; 132 133 typedef struct _CSC_BUFFER { 134 void *planes[CSC_MAX_PLANES]; 135 int mem_type; 136 } CSC_BUFFER; 137 138 typedef struct _CSC_HW_PROPERTY { 139 int fixed_node; 140 int mode_drm; 141 } CSC_HW_PROPERTY; 142 143 typedef struct _CSC_HANDLE { 144 CSC_FORMAT dst_format; 145 CSC_FORMAT src_format; 146 CSC_BUFFER dst_buffer; 147 CSC_BUFFER src_buffer; 148 CSC_METHOD csc_method; 149 CSC_HW_TYPE csc_hw_type; 150 void *csc_hw_handle; 151 CSC_HW_PROPERTY hw_property; 152 153 /* CSC Equation */ 154 CSC_EQ_MODE csc_mode; 155 CSC_EQ_RANGE csc_range; 156 CSC_EQ_COLORSPACE colorspace; 157 158 /* Denoising filter */ 159 CSC_HW_FILTER filter; 160 161 unsigned int frame_rate; 162 } CSC_HANDLE; 163 164 /* 165 * change hal pixel format to omx pixel format 166 * 167 * @param hal_format 168 * hal pixel format[in] 169 * 170 * @return 171 * omx pixel format 172 */ 173 unsigned int hal_2_omx_pixel_format( 174 unsigned int hal_format); 175 176 /* 177 * change omx pixel format to hal pixel format 178 * 179 * @param hal_format 180 * omx pixel format[in] 181 * 182 * @return 183 * hal pixel format 184 */ 185 unsigned int omx_2_hal_pixel_format( 186 unsigned int omx_format); 187 188 /* 189 * Init CSC handle 190 * 191 * @return 192 * csc handle 193 */ 194 void *csc_init( 195 CSC_METHOD method); 196 197 /* 198 * Deinit CSC handle 199 * 200 * @param handle 201 * CSC handle[in] 202 * 203 * @return 204 * error code 205 */ 206 CSC_ERRORCODE csc_deinit( 207 void *handle); 208 209 /* 210 * get color space converter method 211 * 212 * @param handle 213 * CSC handle[in] 214 * 215 * @param method 216 * CSC method[out] 217 * 218 * @return 219 * error code 220 */ 221 CSC_ERRORCODE csc_get_method( 222 void *handle, 223 CSC_METHOD *method); 224 225 /* 226 * set color space converter method 227 * 228 * @param handle 229 * CSC handle[in] 230 * 231 * @param method 232 * CSC method[in] 233 * 234 * @return 235 * error code 236 */ 237 CSC_ERRORCODE csc_set_method( 238 void *handle, 239 CSC_METHOD method); 240 241 /* 242 * Set hw property 243 * 244 * @param handle 245 * CSC handle[in] 246 * 247 * @param property 248 * csc hw property[in] 249 * 250 * @param value 251 * csc hw property value[in] 252 * 253 * @return 254 * csc handle 255 */ 256 CSC_ERRORCODE csc_set_hw_property( 257 void *handle, 258 CSC_HW_PROPERTY_TYPE property, 259 int value); 260 261 /* 262 * Get csc equation property. 263 * 264 * @param handle 265 * CSC handle[in] 266 * 267 * @param mode 268 * csc equation mode[out] 269 * 270 * @param colorspace 271 * csc color space[out] 272 * 273 * @param range 274 * csc equation range[out] 275 * 276 * @return 277 * error code 278 */ 279 CSC_ERRORCODE csc_get_eq_property( 280 void *handle, 281 CSC_EQ_MODE *csc_mode, 282 CSC_EQ_RANGE *csc_range, 283 CSC_EQ_COLORSPACE *colorspace); 284 285 /* 286 * Set csc equation property. 287 * 288 * @param handle 289 * CSC handle[in] 290 * 291 * @param mode 292 * csc equation mode[in] 293 * 294 * @param colorspace 295 * csc color space[in] 296 * 297 * @param range 298 * csc equation range[in] 299 * 300 * @return 301 * error code 302 */ 303 CSC_ERRORCODE csc_set_eq_property( 304 void *handle, 305 CSC_EQ_MODE csc_mode, 306 CSC_EQ_RANGE csc_range, 307 CSC_EQ_COLORSPACE colorspace); 308 309 /* 310 * Set csc filter property. 311 * 312 * @param handle 313 * CSC handle[in] 314 * 315 * @param filter 316 * csc filter info[in] 317 * 318 * @return 319 * error code 320 */ 321 CSC_ERRORCODE csc_set_filter_property( 322 void *handle, 323 CSC_HW_FILTER filter); 324 325 /* 326 * Set framerate. 327 * 328 * @param handle 329 * CSC handle[in] 330 * 331 * @param frame_rate 332 * frame rate[in] 333 * 334 * @return 335 * error code 336 */ 337 CSC_ERRORCODE csc_set_framerate( 338 void *handle, 339 unsigned int frame_rate); 340 341 /* 342 * Get source format. 343 * 344 * @param handle 345 * CSC handle[in] 346 * 347 * @param width 348 * address of image width[out] 349 * 350 * @param height 351 * address of image height[out] 352 * 353 * @param crop_left 354 * address of image left crop size[out] 355 * 356 * @param crop_top 357 * address of image top crop size[out] 358 * 359 * @param crop_width 360 * address of cropped image width[out] 361 * 362 * @param crop_height 363 * address of cropped image height[out] 364 * 365 * @param color_format 366 * address of source color format(HAL format)[out] 367 * 368 * @return 369 * error code 370 */ 371 CSC_ERRORCODE csc_get_src_format( 372 void *handle, 373 unsigned int *width, 374 unsigned int *height, 375 unsigned int *crop_left, 376 unsigned int *crop_top, 377 unsigned int *crop_width, 378 unsigned int *crop_height, 379 unsigned int *color_format, 380 unsigned int *cacheable); 381 382 /* 383 * Set source format. 384 * Don't call each converting time. 385 * Pls call this function as below. 386 * 1. first converting time 387 * 2. format is changed 388 * 389 * @param handle 390 * CSC handle[in] 391 * 392 * @param width 393 * image width[in] 394 * 395 * @param height 396 * image height[in] 397 * 398 * @param crop_left 399 * image left crop size[in] 400 * 401 * @param crop_top 402 * image top crop size[in] 403 * 404 * @param crop_width 405 * cropped image width[in] 406 * 407 * @param crop_height 408 * cropped image height[in] 409 * 410 * @param color_format 411 * source color format(HAL format)[in] 412 * 413 * @return 414 * error code 415 */ 416 CSC_ERRORCODE csc_set_src_format( 417 void *handle, 418 unsigned int width, 419 unsigned int height, 420 unsigned int crop_left, 421 unsigned int crop_top, 422 unsigned int crop_width, 423 unsigned int crop_height, 424 unsigned int color_format, 425 unsigned int cacheable); 426 427 /* 428 * Get destination format. 429 * 430 * @param handle 431 * CSC handle[in] 432 * 433 * @param width 434 * address of image width[out] 435 * 436 * @param height 437 * address of image height[out] 438 * 439 * @param crop_left 440 * address of image left crop size[out] 441 * 442 * @param crop_top 443 * address of image top crop size[out] 444 * 445 * @param crop_width 446 * address of cropped image width[out] 447 * 448 * @param crop_height 449 * address of cropped image height[out] 450 * 451 * @param color_format 452 * address of color format(HAL format)[out] 453 * 454 * @return 455 * error code 456 */ 457 CSC_ERRORCODE csc_get_dst_format( 458 void *handle, 459 unsigned int *width, 460 unsigned int *height, 461 unsigned int *crop_left, 462 unsigned int *crop_top, 463 unsigned int *crop_width, 464 unsigned int *crop_height, 465 unsigned int *color_format, 466 unsigned int *cacheable); 467 468 /* 469 * Set destination format 470 * Don't call each converting time. 471 * Pls call this function as below. 472 * 1. first converting time 473 * 2. format is changed 474 * 475 * @param handle 476 * CSC handle[in] 477 * 478 * @param width 479 * image width[in] 480 * 481 * @param height 482 * image height[in] 483 * 484 * @param crop_left 485 * image left crop size[in] 486 * 487 * @param crop_top 488 * image top crop size[in] 489 * 490 * @param crop_width 491 * cropped image width[in] 492 * 493 * @param crop_height 494 * cropped image height[in] 495 * 496 * @param color_format 497 * destination color format(HAL format)[in] 498 * 499 * @return 500 * error code 501 */ 502 CSC_ERRORCODE csc_set_dst_format( 503 void *handle, 504 unsigned int width, 505 unsigned int height, 506 unsigned int crop_left, 507 unsigned int crop_top, 508 unsigned int crop_width, 509 unsigned int crop_height, 510 unsigned int color_format, 511 unsigned int cacheable); 512 513 /* 514 * Setup source buffer 515 * set_format func should be called before this this func. 516 * 517 * @param handle 518 * CSC handle[in] 519 * 520 * @param src_buffer 521 * source buffer pointer array[in] 522 * 523 * @param y 524 * y or RGB destination pointer[in] 525 * 526 * @param u 527 * u or uv destination pointer[in] 528 * 529 * @param v 530 * v or none destination pointer[in] 531 * 532 * @return 533 * error code 534 */ 535 CSC_ERRORCODE csc_set_src_buffer( 536 void *handle, 537 void *addr[CSC_MAX_PLANES], 538 int mem_type); 539 540 /* 541 * Setup destination buffer 542 * 543 * @param handle 544 * CSC handle[in] 545 * 546 * @param y 547 * y or RGB destination pointer[in] 548 * 549 * @param u 550 * u or uv destination pointer[in] 551 * 552 * @param v 553 * v or none destination pointer[in] 554 * 555 * @return 556 * error code 557 */ 558 CSC_ERRORCODE csc_set_dst_buffer( 559 void *handle, 560 void *addr[CSC_MAX_PLANES], 561 int mem_type); 562 563 /* 564 * Convert color space with presetup color format 565 * 566 * @param handle 567 * CSC handle[in] 568 * 569 * @return 570 * error code 571 */ 572 CSC_ERRORCODE csc_convert( 573 void *handle); 574 575 CSC_ERRORCODE csc_convert_with_rotation( 576 void *handle, int rotation, int flip_horizontal, int flip_vertical); 577 578 #ifdef __cplusplus 579 } 580 #endif 581 582 #endif 583