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

Linux Cross Reference
Tina4/src/file/edges/edges_read.c

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

  1 /**@(#)
  2   */
  3 #include <stdio.h>
  4 #include <tina/sys.h>
  5 #include <tina/sysfuncs.h>
  6 #include <tina/math.h>
  7 #include <tina/mathfuncs.h>
  8 #include <tina/vision.h>
  9 
 10 extern Bool fclose_2(FILE * stream, const char *pathname);
 11 extern FILE *fopen_2(const char *pathname, const char *mode);
 12 
 13 Imrect *edges_read_stream(int height, int width, Imregion * region, FILE *
 14                                   stream, const char *pathname)
 15 {
 16     Imrect *edge_image;
 17     Imrect *im_alloc();
 18     float   (*buffer)[4];
 19     int     count, i;
 20     unsigned int buffsize;
 21 
 22     if (1 != fread((char *) &count, sizeof(int), 1, stream))
 23     {
 24         errorf(non_fatal, "edges_read_stream: empty file: %s\n", pathname);
 25         return (NULL);
 26     }
 27     buffsize = count * sizeof(float[4]);
 28     buffer = (float (*)[4]) ralloc(buffsize);
 29     if (fread((char *) buffer, sizeof(float[4]), count, stream)
 30                       != (unsigned int) count)
 31     {
 32         errorf(non_fatal, "edges_read_stream: premature end of file: %s\n", pathname);
 33         rfree((void *) buffer);
 34         return (NULL);
 35     }
 36     edge_image = im_alloc(height, width, region, ptr_v);
 37     region = edge_image->region;
 38 
 39     for (i = 0; i < count; ++i)
 40     {
 41         Edgel  *eptr;
 42         Edgel  *edge_alloc();
 43         extern int er_add_edge(Imrect * edgerect, Edgel * edge);
 44 
 45         float  *edge_buff = buffer[i];
 46 
 47         if (!roi_inregion(region, (int) edge_buff[1], (int) edge_buff[0]))
 48             continue;
 49 
 50         eptr = edge_alloc(EDGE_RAW);
 51         eptr->pos = vec2(edge_buff[1], edge_buff[0]);
 52         eptr->contrast = edge_buff[2];
 53         eptr->orient = edge_buff[3];
 54         (void) er_add_edge(edge_image, eptr);
 55     }
 56 
 57     rfree((void *) buffer);
 58     return (edge_image);
 59 }
 60 
 61 Imrect *edges_read_file(const char *pathname, const int height, const int width,
 62                                 Imregion * region)
 63 {
 64     FILE   *stream = fopen_2(pathname, "r");
 65     Imrect *er = NULL;
 66 
 67     if (stream)
 68     {
 69         er = edges_read_stream(height, width, region, stream, pathname);
 70         (void) fclose_2(stream, pathname);
 71     }
 72     return (er);
 73 }
 74 

~ [ 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.