---
title: YCbCrI420ToRGB24
description: "将图像模型由YCbCrI格式转换为RGB或者BGR格式。计算公式如下："
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2200/accel/kunpengaccel_hmpp_06_0167.html
sourcePath: /source/zh/kunpengboostkithistory/2200/accel/kunpengaccel_hmpp_06_0167.html
indexId: 48d726cf2f14cbead79b2f9067517f23e14de71adcc1c4f6d7e3f618ce436c2d75
---
# YCbCrI420ToRGB24

将图像模型由YCbCrI格式转换为RGB或者BGR格式。计算公式如下：

，

，

，

，

，

，其中clamp表示限定值在[0, 255]。

函数接口声明如下：

- YCbCrI420转换为RGB24：
  HmppResult HMPPI_YCbCrI420ToRGB24_8u(const uint8_t *src, uint8_t *dst, int32_t width, int32_t height);

- YCbCrI420转换为BGR24：
  HmppResult HMPPI_YCbCrI420ToBGR24_8u(const uint8_t *src, uint8_t *dst, int32_t width, int32_t height);


#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| src | 指向源向量的指针。 | 非空 | 输入 |
| dst | 指向目的向量的指针。 | 非空 | 输出 |
| width | 图像宽度（按像素计算）。 | (0, INT\_MAX]，可被2整除 | 输入 |
| height | 图像高度（按像素计算）。 | (0, INT\_MAX]，可被2整除 | 输入 |


#### 返回值

- 成功：返回HMPP_STS_NO_ERR。
- 失败：返回错误码。


#### 错误码

| 错误码 | 描述 |
| --- | --- |
| HMPP\_STS\_NULL\_PTR\_ERR | src、dst这两个入参中存在空指针。 |
| HMPP\_STS\_SIZE\_ERR | width、height这两个入参中存在值小于或等于0。 |
| HMPP\_STS\_DOUBLE\_SIZE\_ERR | width、height这两个入参中存在值不是2的倍数。 |


#### 示例

```
#define SRC_BUFFER_SIZE_T 6
#define DST_BUFFER_SIZE_T 12
int YcbcrToRgbExample(){
int32_t i;
uint8_t dst[DST_BUFFER_SIZE_T] = {0};
uint8_t src[SRC_BUFFER_SIZE_T] = {0, 255, 5, 34, 122, 78};
HmppResult result = HMPPI_YCbCrI420ToRGB24_8u(src, dst, 2, 2);
printf("result = %d \ndst =", result);
for (i = 0; i < DST_BUFFER_SIZE_T; i++) {
printf(" %d  ", dst[i]);
}
return 0;
}
```

运行结果：

```
result = 0
dst = 0   24   0   199   255   255   0   30   0   0   64   9
```
