Difference between revisions of "Targa.c"
m |
m |
||
| Line 3: | Line 3: | ||
// Default Targa image header | // Default Targa image header | ||
typedef struct { | typedef struct { | ||
| − | char idlength | + | char idlength; |
| − | char colourmaptype | + | char colourmaptype; |
| − | char datatypecode | + | char datatypecode; |
| − | short int colourmaporigin | + | short int colourmaporigin; |
| − | short int colourmaplength | + | short int colourmaplength; |
| − | char colourmapdepth | + | char colourmapdepth; |
| − | short int x_origin | + | short int x_origin; |
| − | short int y_origin | + | short int y_origin; |
| − | short width | + | short width; |
| − | short height | + | short height; |
| − | char bitsperpixel | + | 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 | + | image = {0,0,0,0,0,0,0,0,width,height,8,' '}; |
| − | |||
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); } }



