imageprocessing/fileFunctions.c
int writeTransformedImageFile(char* outfile, int width, int height,BYTE remap[256][3],BYTE* image)
{
  int x = 0;
  int y = 0;
  int bOk = 1;
  int buffersize = width * 3;
  FILE * pOut = NULL;
  BYTE* buffer = NULL;

  pOut = fopen(outfile,"wb");
  if (pOut == NULL)
     {
     printf("Error opening output image %s\n", outfile);
     bOk = 0;
     }
  if (bOk)
     {
     buffer = (BYTE*) calloc(buffersize,sizeof(BYTE));
     if (buffer == NULL)
         bOk = 0;
     }
  if (bOk)   /* transform and write, one line at a time */
     {         
     for (y = 0; (y < height) && (bOk); y++)
       {
       for (x = 0; x < width; x++)
	    {
	    BYTE imgval = pixval(x,y,width);
            buffer[x*3] = remap[imgval][0];            
            buffer[x*3+1] = remap[imgval][1];            
            buffer[x*3+2] = remap[imgval][2];            
            }
       if (fwrite(buffer,sizeof(BYTE),buffersize,pOut) != buffersize)
	    bOk = 0;
       } 
     }
  if (buffer != NULL)
    free(buffer);
  if (pOut != NULL)
    fclose(pOut);
  return bOk;
}
/* Write data from a buffer into a raw RGB file, 
 * Image is one byte per pixel
 * Output is three bytes per pixel
 * Use the remap[][] to transform to output colors.
 * @param outfile  name of file to write
 * @param width    number of pixels in each row
 * @param height   number of rows in the image
 * @param remap    two dimensional transformation array (256 x 3) 
 *                 to control output colors.
 * @param image    buffer of all data (row major)
 * @return 1 for success, 0 for error
 */
Write data from a buffer into a raw RGB file,
Image is one byte per pixel
Output is three bytes per pixel
Use the remap[][] to transform to output colors.
@param outfile  name of file to write
@param width    number of pixels in each row
@param height   number of rows in the image
@param remap    two dimensional transformation array (256 x 3)
to control output colors.
@param image    buffer of all data (row major)
@return 1 for success, 0 for error
Write data from a buffer into a raw RGB file Image is one byte per pixel Output is three bytes per pixel Use the remap [] [] to transform to output colors . @param outfile name of file to write @param width number of pixels in each row @param height number of rows in the image @param remap two dimensional transformation array ( 256 x 3 ) to control output colors . @param image buffer of all data ( row major ) @return 1 for success 0 for error
int writeTransformedImageFile(char* outfile, int width, int height,BYTE remap[256][3],BYTE* image)
{
  int x = 0;
  int y = 0;
  int bOk = 1;
  int buffersize = width * 3;
  FILE * pOut = NULL;
  BYTE* buffer = NULL;
  pOut = fopen(outfile,"wb");
  if (pOut == NULL)
     {
     printf("Error opening output image %s\n", outfile);
     bOk = 0;
     }
  if (bOk)
     {
     buffer = (BYTE*) calloc(buffersize,sizeof(BYTE));
     if (buffer == NULL)
         bOk = 0;
     }
  if (bOk)   
     {         
     for (y = 0; (y < height) && (bOk); y++)
       {
       for (x = 0; x < width; x++)
	    {
	    BYTE imgval = pixval(x,y,width);
            buffer[x*3] = remap[imgval][0];            
            buffer[x*3+1] = remap[imgval][1];            
            buffer[x*3+2] = remap[imgval][2];            
            }
       if (fwrite(buffer,sizeof(BYTE),buffersize,pOut) != buffersize)
	    bOk = 0;
       } 
     }
  if (buffer != NULL)
    free(buffer);
  if (pOut != NULL)
    fclose(pOut);
  return bOk;
}
int writeTransformedImageFile ( char * outfile , int width , int height , BYTE remap [ 256 ] [ 3 ] , BYTE * image ) { int x = 0 ; int y = 0 ; int bOk = 1 ; int buffersize = width * 3 ; FILE * pOut = NULL ; BYTE * buffer = NULL ; pOut = fopen ( outfile , " " ) ; if ( pOut == NULL ) { printf ( " \n " , outfile ) ; bOk = 0 ; } if ( bOk ) { buffer = ( BYTE * ) calloc ( buffersize , sizeof ( BYTE ) ) ; if ( buffer == NULL ) bOk = 0 ; } if ( bOk ) { for ( y = 0 ; ( y < height ) && ( bOk ) ; y ++ ) { for ( x = 0 ; x < width ; x ++ ) { BYTE imgval = pixval ( x , y , width ) ; buffer [ x * 3 ] = remap [ imgval ] [ 0 ] ; buffer [ x * 3 + 1 ] = remap [ imgval ] [ 1 ] ; buffer [ x * 3 + 2 ] = remap [ imgval ] [ 2 ] ; } if ( fwrite ( buffer , sizeof ( BYTE ) , buffersize , pOut ) != buffersize ) bOk = 0 ; } } if ( buffer != NULL ) free ( buffer ) ; if ( pOut != NULL ) fclose ( pOut ) ; return bOk ; }
Write data from a buffer into a raw RGB file,
 Image is one byte per pixel
 Output is three bytes per pixel
 Use the remap[][] to transform to output colors.
Write data from a buffer into a raw RGB file Image is one byte per pixel Output is three bytes per pixel Use the remap [] [] to transform to output colors .
/* transform and write, one line at a time */