Difference between revisions of "Targa.c"

From Organic Design wiki
m
m
Line 2: Line 2:
  
 
// Default Targa image header
 
// Default Targa image header
typedef struct {
+
typedef struct headerStruct {
 
char  idlength;
 
char  idlength;
 
char  colourmaptype;
 
char  colourmaptype;
Line 16: Line 16:
 
char  imagedescriptor;
 
char  imagedescriptor;
 
} targaHeader;
 
} targaHeader;
int szHeader = sizeOf(targaHeader);
+
int szHeader = sizeOf(headerStruct);
  
 
char* image = targa( 100, 200 );
 
char* image = targa( 100, 200 );

Revision as of 10:18, 3 July 2006

main() {

// Default Targa image header typedef struct headerStruct { 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; int szHeader = sizeOf(headerStruct);

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 = {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+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); } }