imageprocessing/fileFunctions.c
BOOL writeImageFile(BYTE* image,int width,int height,char* outfile)
{
  FILE * pOut = NULL;
  BYTE* buffer = NULL;
  BOOL bOk = TRUE;
  int row, col, i; 
  buffer = (BYTE*) calloc(width*3,sizeof(BYTE));
  pOut = fopen(outfile,"wb");
  if ((pOut != NULL) && (buffer != NULL))
     {
     for (row = 0; row < height; row++) 
        {
        for (col=0; col< width; col++)
	   {
	   buffer[col*3] = 
             buffer[col*3+1] = 
               buffer[col*3+2] = pixval(col,row,width);
           }
	if (fwrite(buffer,sizeof(BYTE),width*3,pOut) != width*3)
           {
           printf("Error writing output file\n");
           bOk = FALSE;
	   break;
	   }
        }
     }
  else if (pOut == NULL)
     {
     printf("Error opening output file\n");
     bOk = FALSE;
     } 
  else if (buffer == NULL)
     {
     printf("Error allocating data buffer\n");
     bOk = FALSE;
     } 
  if (buffer != NULL)
     free(buffer);
  if (pOut != NULL)
     fclose(pOut);
  return bOk;
}
/* Write the byte data to an RGB file with three bytes per pixel 
 * (all three bytes identical). This is more convenient to work with
 * in ImageMagick.
 * @param   image      Byte array of data
 * @param   width      Number of pixels per line
 * @param   height     Number of lines
 * @param   outfile    Name of file to write
 * @return TRUE for success, FALSE for error.
 */
Write the byte data to an RGB file with three bytes per pixel
(all three bytes identical). This is more convenient to work with
in ImageMagick.
Write the byte data to an RGB file with three bytes per pixel ( all three bytes identical ) . This is more convenient to work with in ImageMagick .
BOOL writeImageFile(BYTE* image,int width,int height,char* outfile)
{
  FILE * pOut = NULL;
  BYTE* buffer = NULL;
  BOOL bOk = TRUE;
  int row, col, i; 
  buffer = (BYTE*) calloc(width*3,sizeof(BYTE));
  pOut = fopen(outfile,"wb");
  if ((pOut != NULL) && (buffer != NULL))
     {
     for (row = 0; row < height; row++) 
        {
        for (col=0; col< width; col++)
	   {
	   buffer[col*3] = 
             buffer[col*3+1] = 
               buffer[col*3+2] = pixval(col,row,width);
           }
	if (fwrite(buffer,sizeof(BYTE),width*3,pOut) != width*3)
           {
           printf("Error writing output file\n");
           bOk = FALSE;
	   break;
	   }
        }
     }
  else if (pOut == NULL)
     {
     printf("Error opening output file\n");
     bOk = FALSE;
     } 
  else if (buffer == NULL)
     {
     printf("Error allocating data buffer\n");
     bOk = FALSE;
     } 
  if (buffer != NULL)
     free(buffer);
  if (pOut != NULL)
     fclose(pOut);
  return bOk;
}
BOOL writeImageFile ( BYTE * image , int width , int height , char * outfile ) { FILE * pOut = NULL ; BYTE * buffer = NULL ; BOOL bOk = TRUE ; int row , col , i ; buffer = ( BYTE * ) calloc ( width * 3 , sizeof ( BYTE ) ) ; pOut = fopen ( outfile , " " ) ; if ( ( pOut != NULL ) && ( buffer != NULL ) ) { for ( row = 0 ; row < height ; row ++ ) { for ( col = 0 ; col < width ; col ++ ) { buffer [ col * 3 ] = buffer [ col * 3 + 1 ] = buffer [ col * 3 + 2 ] = pixval ( col , row , width ) ; } if ( fwrite ( buffer , sizeof ( BYTE ) , width * 3 , pOut ) != width * 3 ) { printf ( " \n " ) ; bOk = FALSE ; break ; } } } else if ( pOut == NULL ) { printf ( " \n " ) ; bOk = FALSE ; } else if ( buffer == NULL ) { printf ( " \n " ) ; bOk = FALSE ; } if ( buffer != NULL ) free ( buffer ) ; if ( pOut != NULL ) fclose ( pOut ) ; return bOk ; }
Write the byte data to an RGB file with three bytes per pixel
 (all three bytes identical).
Write the byte data to an RGB file with three bytes per pixel ( all three bytes identical ) .