Difference between revisions of "Targa.c"

From Organic Design wiki
m
m
Line 3: Line 3:
 
// Default Targa image header
 
// Default Targa image header
 
typedef struct {
 
typedef struct {
char  idlength = 0;
+
char  idlength;
char  colourmaptype = 0;
+
char  colourmaptype;
char  datatypecode = 0;
+
char  datatypecode;
short int colourmaporigin = 0;
+
short int colourmaporigin;
short int colourmaplength = 0;
+
short int colourmaplength;
char  colourmapdepth = 0;
+
char  colourmapdepth;
short int x_origin = 0;
+
short int x_origin;
short int y_origin = 0;
+
short int y_origin;
short width = 400;
+
short width;
short height = 300;
+
short height;
char  bitsperpixel = 8;
+
char  bitsperpixel;
char  imagedescriptor = ' ';
+
char  imagedescriptor;
 
} targaHeader;
 
} targaHeader;
 
szHeader = sizeOf(targaHeader);
 
szHeader = sizeOf(targaHeader);
Line 26: Line 26:
 
char* targa(short int width, height) {
 
char* targa(short int width, height) {
 
targaHeader* image = malloc(szHeader+width*height*4);
 
targaHeader* image = malloc(szHeader+width*height*4);
image->width = width;
+
image = {0,0,0,0,0,0,0,0,width,height,8,' '};
image->height = height;
 
 
return (char*)ℑ
 
return (char*)ℑ
 
}
 
}

Revision as of 10:16, 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; 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 = {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); } }