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 headerStruct {
+
typedef struct {
 
char  idlength;
 
char  idlength;
 
char  colourmaptype;
 
char  colourmaptype;
Line 16: Line 16:
 
char  imagedescriptor;
 
char  imagedescriptor;
 
} targaHeader;
 
} targaHeader;
int szHeader = sizeOf(headerStruct);
 
  
 
char* image = targa( 100, 200 );
 
char* image = targa( 100, 200 );
Line 25: Line 24:
 
// Create a new targa image in memory
 
// Create a new targa image in memory
 
char* targa(short int width, height) {
 
char* targa(short int width, height) {
targaHeader* image = malloc(szHeader+width*height*4);
+
targaHeader* image;
 +
image = malloc(sizeOf(targaHeader)+width*height*4);
 
image = {0,0,0,0,0,0,0,0,width,height,8,' '};
 
image = {0,0,0,0,0,0,0,0,width,height,8,' '};
 
return (char*)ℑ
 
return (char*)ℑ
Line 32: Line 32:
 
void getPixel(char* image, short int x, y, int colour) {
 
void getPixel(char* image, short int x, y, int colour) {
 
targaHeader* header = (targaHeader*)image;
 
targaHeader* header = (targaHeader*)image;
char* addr = image+szHeader+4*(x+header->width*y);
+
char* addr = image+sizeOf(header)+4*(x+header->width*y);
 
return *addr;
 
return *addr;
 
}
 
}

Revision as of 10:20, 3 July 2006

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); } }