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 >
Wrap
C/C++ Source or Header
|
2002-06-25
|
1KB
|
58 lines
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include "image2d.h"
Image2D *ImageAlloc(int w, int h)
{
Image2D *im;
int totalRows;
int i,j;
im = (Image2D *)malloc(sizeof(Image2D));
im->width = w;
im->height = h;
im->byteWidth = sizeof(unsigned char)*w;
im->samplesPerPixel = 1;
im->data = (unsigned char **)malloc(h*sizeof(unsigned char *));
im->stream = im->data[0] = (unsigned char *)malloc(im->byteWidth*h);
totalRows = h;
for (i=1; i<totalRows; ++i)
im->data[i] = ((char *)im->data[i-1])+im->byteWidth;
for (i=0; i<h; i++)
for (j=0; j<w; j++)
im->data[i][j] = (unsigned char) 0;
return im;
}
void ImageFreeData(Image2D *im)
{
free(im->data[0]);
free(im->data);
im->data = NULL;
}
void ImageFree(Image2D *im)
{
if (im->data != NULL)
{
free(im->data[0]);
free(im->data);
}
free(im);
}