codice:
#include<stdio.h>
#include<malloc.h>
int rows=512,cols=512;
unsigned char **img1,**imgR,**imgG,**imgB;
unsigned char** allocabuffer(int r, int c);
void eliminabuffer(unsigned char **buffer,int r);
void readraw(char *filepath,unsigned char **buffer);
void readrawR(char *filepath,unsigned char **buffer);
void readrawG(char *filepath,unsigned char **buffer);
void readrawB(char *filepath,unsigned char **buffer);
void saveraw(char *filepath,unsigned char **buffer);
FILE *out;
main()
{
int i;
imgR=allocabuffer(rows, cols);
readrawR("C:\Documents and Settings\Paolo L\Desktop\EIV\img.raw\img.raw",imgR);
saveraw("C:\Documents and Settings\Paolo L\Desktop\EIV\img.raw\img_R.raw",imgR);
eliminabuffer(imgR,rows);
}
unsigned char** allocabuffer(int r, int c)
{
int i;
unsigned char **buffer=(unsigned char**)malloc(r*sizeof(unsigned char*));
for(i=0;i<r;i++)
buffer[i]=(unsigned char*)calloc(3*c,sizeof(unsigned char));
return (buffer);
}
// readraw RGB
void readrawR(char *filepath,unsigned char **buffer)
{
int i;
out=fopen(filepath,"rb");
for(i=0;i<rows*cols*3;i=i+3) fread(buffer[i],1,1,out);
fclose(out);
}
void readrawG(char *filepath,unsigned char **buffer)
{
int i;
FILE *source=fopen(filepath,"rb");
for(i=1;i<rows;i=i+3) fread(buffer[i],1,cols,source);
fclose(source);
}
void readrawB(char *filepath,unsigned char **buffer)
{
int i;
FILE *source=fopen(filepath,"rb");
for(i=2;i<rows;i=i+3) fread(buffer[i],1,cols,source);
fclose(source);
}
void eliminabuffer(unsigned char **buffer,int r)
{
int i;
for(i=0;i<r;i++) free(buffer[i]);
free(buffer);
}
void saveraw(char *filepath,unsigned char **buffer)
{
int i;
FILE *source=fopen(filepath,"wb");
for(i=0;i<rows;i++) fwrite(buffer[i],1,1,source);
fclose(source);
}
Adesso è corretto, questo file dovrebbe aprire l immagine che ho in raw e salvare in un buffer tutte le componenti R del file raw... il file si compila ed esegue senza alcun problema, ma non mi crea alcuna immagine raw con solo le componenti R del file raw...come devo fare per risolvere questo problema... inoltre devo fare la stessa cosa per estrarre G e B... non cè una procedura + semplice?