mipi raw10 转raw8 示例代码

代码思路参考raw10 转raw16 部分代码是我测试的时候小改
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


int main(int argc, const char *argv[])
{
    if (argc != 4)
    {
        printf("usage: <filename> <width> <height>\n");
        return -1;
    }
    int width = atoi(argv[2]);
    int height = atoi(argv[3]);
    FILE *fp = fopen(argv[1], "rb");
    if (!fp)
    {
        printf("Fail to open file <%s>\n", argv[1]);
        return -1;
    }
    char fn[128];
    sprintf(fn, "raw_%s", argv[1]);
    FILE *fo = fopen(fn, "wb");
    if (!fo)
    {
        printf("Fail to open file <%s>\n", fn);
        fclose(fp);
        return -1;
    }
    unsigned char buf[1024 * 8];
    int stride = ceil(width * 1.25 / 8) * 8;
    int i = 0;
    int j = 0;
    int n = 0;
    while (!feof(fp))
    {
        for (n = 0; n < height; n++)
        {
            int ret = fread(buf, 1, stride, fp);
            if (!ret)
            {
                break;
            }
            for (j = 0; j < width / 4; j++)
            {
                unsigned char *p = buf + j * 5;
                for (i = 0; i < 4; i++)
                {
                   fwrite(&d, 1, 1, fo);
                }
            }
        }
    }
    fclose(fo);
    fclose(fp);
    return 0;
}
 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
下面是 mipi raw10 换成 raw10 的 C 代码: ```c #include <stdio.h> void mipi_raw10_to_raw10(unsigned char *input, unsigned char *output, int width, int height) { int i, j; int index = 0; int output_index = 0; unsigned short pixel; for (i = 0; i < height; i++) { for (j = 0; j < width; j += 4) { pixel = input[index++] << 2; pixel |= input[index] >> 6; output[output_index++] = pixel & 0xff; output[output_index++] = (pixel >> 8) & 0xff; pixel = (input[index++] & 0x3f) << 4; pixel |= input[index] >> 4; output[output_index++] = pixel & 0xff; output[output_index++] = (pixel >> 8) & 0xff; pixel = (input[index++] & 0x0f) << 6; pixel |= input[index] >> 2; output[output_index++] = pixel & 0xff; output[output_index++] = (pixel >> 8) & 0xff; pixel = (input[index++] & 0x03) << 8; pixel |= input[index++]; output[output_index++] = pixel & 0xff; output[output_index++] = (pixel >> 8) & 0xff; } } } ``` 下面是 raw10 换成 raw8 的 C 代码: ```c #include <stdio.h> void raw10_to_raw8(unsigned char *input, unsigned char *output, int width, int height) { int i, j; int index = 0; int output_index = 0; unsigned short pixel; for (i = 0; i < height; i++) { for (j = 0; j < width; j += 4) { pixel = input[index++] << 2; pixel |= input[index] >> 6; output[output_index++] = pixel >> 2; pixel = (input[index++] & 0x3f) << 4; pixel |= input[index] >> 4; output[output_index++] = pixel >> 2; pixel = (input[index++] & 0x0f) << 6; pixel |= input[index] >> 2; output[output_index++] = pixel >> 2; pixel = (input[index++] & 0x03) << 8; pixel |= input[index++]; output[output_index++] = pixel >> 2; } } } ``` 以上代码仅供参考,具体实现需要根据具体的需求进行修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值