Difference between revisions of "Targa.c"

From Organic Design wiki
m
(box-model primitives)
Line 1: Line 1:
 +
// Default Targa image header
 +
typedef struct {
 +
char  idlength = 0;
 +
char  colourmaptype = 0;
 +
char  datatypecode = 0;
 +
short int colourmaporigin = 0;
 +
short int colourmaplength = 0;
 +
char  colourmapdepth = 0;
 +
short int x_origin = 0;
 +
short int y_origin = 0;
 +
short width = 400;
 +
short height = 300;
 +
char  bitsperpixel = 8;
 +
char  imagedescriptor = ' ';
 +
} targaHeader;
 +
szHeader = sizeOf(targaHeader);
 +
 +
char* image = targa( 100, 200 );
 +
fillRect( image, 10, 20, 30, 40, 0xff0000ff );
 +
  
  
typedef struct {
+
// Create a new targa image in memory
  char  idlength = 0;
+
char* targa(short int width, height) {
  char  colourmaptype = 0;
+
targaHeader* image = malloc(szHeader+width*height*4);
  char  datatypecode = 0;
+
image->width = width;
  short int colourmaporigin = 0;
+
image->height = height;
  short int colourmaplength = 0;
+
return (char*)ℑ
  char colourmapdepth = 0;
+
}
  short int x_origin = 0;
+
 
  short int y_origin = 0;
+
void getPixel(char* image, short int x, y, int colour) {
  short width = 400;
+
targaHeader* header = (targaHeader*)image;
  short height = 300;
+
char* addr = image+szHeader+4*(x+header->width*y);
  char  bitsperpixel = 8;
+
return *addr;
  char  imagedescriptor = ' ';
+
}
} HEADER;
+
 
 +
void setPixel(char* image, short int x, y, int colour) {
 +
}
 +
 
 +
void fillRect( char* image, short int x1,y1,x2,y2, int colour) {
 +
int x,y;
 +
for (y=y1; y<y2; y++)
 +
for (x=x1; x<x2; x++)
 +
setPixel(image,x,y,colour);
 +
}

Revision as of 10:05, 3 July 2006

// Default Targa image header typedef struct { char idlength = 0; char colourmaptype = 0; char datatypecode = 0; short int colourmaporigin = 0; short int colourmaplength = 0; char colourmapdepth = 0; short int x_origin = 0; short int y_origin = 0; short width = 400; short height = 300; char bitsperpixel = 8; char imagedescriptor = ' '; } targaHeader; szHeader = sizeOf(targaHeader);

char* image = targa( 100, 200 ); fillRect( image, 10, 20, 30, 40, 0xff0000ff );


// Create a new targa image in memory char* targa(short int width, height) { targaHeader* image = malloc(szHeader+width*height*4); image->width = width; image->height = height; return (char*)ℑ }

void getPixel(char* image, short int x, y, int colour) { targaHeader* header = (targaHeader*)image; char* addr = image+szHeader+4*(x+header->width*y); return *addr; }

void setPixel(char* image, short int x, y, int colour) { }

void fillRect( char* image, short int x1,y1,x2,y2, int colour) { int x,y; for (y=y1; y<y2; y++) for (x=x1; x<x2; x++) setPixel(image,x,y,colour); }