RAW形式ファイルをテキストファイルに変換

7205 ワード

#include 
#include 
#include 
#include 
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, "
"
); } } 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; }