RAW格式文件按轉換爲文本文件

#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <fstream>
using namespace std;

int g_width = 2448;
int g_height = 2048;

#define NSIZE  8

void Bin2Text(const char* sIn,const char* sOut){
    char buf[1024]; 

    FILE* inFile = fopen(sIn, "rb");
    FILE* outFile = fopen(sOut, "w");

    int count = 0;

    while(1)
    {
        int size = fread(buf, 8, 1, inFile);
        if (size <= 0)
            break;

        count += size;
        for(int i=0; i<size; i++)
        {
            unsigned char c = buf[i];
            fprintf(outFile, "%d ", c);
        } 

        if (count % g_width == 0)
                fprintf(outFile, "\n");
    }
}


int main()
{
    char* raw0 = "E:/bcat/work/zhjpeg/src/zhjpeg/output.raw";
    char* raw1 = "E:/bcat/work/zhjpeg/src/zhjpeg/output11.raw";

    char* out0 = "./raw0.txt";
    char* out1 = "./raw1.txt";

    Bin2Text(raw0, out0);
    Bin2Text(raw1, out1);

    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章