home *** CD-ROM | disk | FTP | other *** search
/ ftp.disi.unige.it / 2015-02-11.ftp.disi.unige.it.tar / ftp.disi.unige.it / pub / .person / BarlaA / sw / OLD / Simo / SVM_mono / image2d.c next >
C/C++ Source or Header  |  2002-06-25  |  1KB  |  58 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <memory.h>
  4. #include <string.h>
  5. #include "image2d.h"
  6.  
  7. Image2D *ImageAlloc(int w, int h)
  8. {
  9.     Image2D *im;
  10.     int totalRows;
  11.     int i,j;
  12.  
  13.  
  14.     im = (Image2D *)malloc(sizeof(Image2D));
  15.  
  16.     im->width           = w;
  17.     im->height          = h;
  18.     
  19.     im->byteWidth = sizeof(unsigned char)*w;
  20.     im->samplesPerPixel = 1;
  21.  
  22.     im->data = (unsigned char **)malloc(h*sizeof(unsigned char *));
  23.     im->stream = im->data[0] = (unsigned char *)malloc(im->byteWidth*h);
  24.     
  25.     totalRows = h;
  26.     for (i=1; i<totalRows; ++i)
  27.     im->data[i] = ((char *)im->data[i-1])+im->byteWidth;
  28.  
  29.     for (i=0; i<h; i++)
  30.        for (j=0; j<w; j++)
  31.           im->data[i][j] = (unsigned char) 0;
  32.  
  33.     return im;
  34. }
  35.  
  36.  
  37. void ImageFreeData(Image2D *im)
  38. {
  39.     free(im->data[0]);
  40.     free(im->data);
  41.     im->data = NULL;
  42. }
  43.  
  44.  
  45. void ImageFree(Image2D *im)
  46. {
  47.     if (im->data != NULL) 
  48.     {
  49.         free(im->data[0]);
  50.         free(im->data);
  51.     }
  52.     free(im);
  53. }
  54.  
  55.  
  56.  
  57.  
  58.