~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/file/raw/raw_io.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)Functions to read/write RAW image files
  2 */
  3 
  4 #include <stdio.h>
  5 #include <string.h>
  6 #include <tina/file.h>
  7 #include <tina/sys.h>
  8 #include <tina/sys_types.h>
  9 #include <tina/sysfuncs.h>
 10 
 11 extern Bool fclose_2(FILE * stream, const char *pathname);
 12 extern FILE *fopen_2(const char *pathname, const char *mode);
 13 extern Bool fread_imrect_data(const Imrect * imrect, FILE * stream, const char *pathname);
 14 extern Bool fwrite_imrect_data(const Imrect * imrect, FILE * stream, const char *pathname);
 15 
 16 /* Create an imrect and read an image file called 'pathname' into it.
 17  * Open file, read data and close file. On failure, give error message
 18  * and return NULL. */
 19 Imrect *raw_read_image(const char *pathname, const int width, const int height,
 20                                const Vartype vtype, unsigned int padding )
 21 {
 22     FILE   *stream = fopen_2(pathname, "rb");
 23     Imrect *imrect = NULL;
 24 
 25     if (stream)
 26     {
 27         Imregion *imregion = NULL;
 28 
 29         if (padding == 0 || fread_padding(padding, stream, pathname)==true)
 30         {
 31            imrect = im_alloc(height, width, imregion, (Vartype) vtype);
 32            if (!fread_imrect_data(imrect, stream, pathname))
 33            {
 34                im_free(imrect);
 35                imrect = NULL;
 36            }
 37         }
 38         fclose_2(stream, pathname);
 39     }
 40     return imrect;
 41 }
 42 
 43 /* Write an imrect to  an image file called 'pathname'. Open file, read
 44  * data and close file. On failure, give error message and return
 45  * false. */
 46 Bool    raw_write_image(const Imrect * imrect, const char *pathname)
 47 {
 48     Bool    write_ok = false;
 49 
 50     if (imrect)
 51     {
 52         FILE   *stream = fopen_2(pathname, "wb");
 53 
 54         if (stream)
 55         {
 56             write_ok = fwrite_imrect_data(imrect, stream, pathname);
 57             (void) fclose_2(stream, pathname);
 58         }
 59     } else
 60     {
 61         errorf(non_fatal, "No image to write to: %s\n", pathname);
 62     }
 63     return write_ok;
 64 }
 65 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.