Targa.c

From Organic Design wiki
Revision as of 10:20, 3 July 2006 by Nad (talk | contribs)

main() {

// Default Targa image header typedef struct { char idlength; char colourmaptype; char datatypecode; short int colourmaporigin; short int colourmaplength; char colourmapdepth; short int x_origin; short int y_origin; short width; short height; char bitsperpixel; char imagedescriptor; } 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; image = malloc(sizeOf(targaHeader)+width*height*4); image = {0,0,0,0,0,0,0,0,width,height,8,' '}; return (char*)ℑ }

void getPixel(char* image, short int x, y, int colour) { targaHeader* header = (targaHeader*)image; char* addr = image+sizeOf(header)+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); } }