mipi raw10 转raw8 示例代码

代码思路参考raw10 转raw16 部分代码是我测试的时候小改
#include
#include
#include
#include


int main(int argc, const char *argv[])
{
    if (argc != 4)
    {
        printf("usage: \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;
}
 

你可能感兴趣的:(编程,图形和图像处理)