Difference between revisions of "Targa.c"

From Organic Design wiki
m
m
Line 1: Line 1:
// Default Targa image header
+
main() {
typedef struct x {
 
char  idlength = 0;
 
char  colourmaptype = 0;
 
char  datatypecode = 0;
 
short int colourmaporigin = 0;
 
short int colourmaplength = 0;
 
char  colourmapdepth = 0;
 
short int x_origin = 0;
 
short int y_origin = 0;
 
short width = 400;
 
short height = 300;
 
char  bitsperpixel = 8;
 
char  imagedescriptor = ' ';
 
} targaHeader;
 
szHeader = sizeOf(targaHeader);
 
  
char* image = targa( 100, 200 );
+
// Default Targa image header
fillRect( image, 10, 20, 30, 40, 0xff0000ff );
+
typedef struct {
 +
char  idlength = 0;
 +
char  colourmaptype = 0;
 +
char  datatypecode = 0;
 +
short int colourmaporigin = 0;
 +
short int colourmaplength = 0;
 +
char colourmapdepth = 0;
 +
short int x_origin = 0;
 +
short int y_origin = 0;
 +
short width = 400;
 +
short height = 300;
 +
char  bitsperpixel = 8;
 +
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->width = width;
 
image->height = height;
 
return (char*)ℑ
 
}
 
  
void getPixel(char* image, short int x, y, int colour) {
+
// Create a new targa image in memory
targaHeader* header = (targaHeader*)image;
+
char* targa(short int width, height) {
char* addr = image+szHeader+4*(x+header->width*y);
+
targaHeader* image = malloc(szHeader+width*height*4);
return *addr;
+
image->width = width;
}
+
image->height = height;
 +
return (char*)ℑ
 +
}
  
void setPixel(char* image, short int x, y, int colour) {
+
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 fillRect( char* image, short int x1,y1,x2,y2, int colour) {
+
void setPixel(char* image, short int x, y, int colour) {
int x,y;
+
}
for (y=y1; y<y2; y++)
+
 
for (x=x1; x<x2; x++)
+
void fillRect( char* image, short int x1,y1,x2,y2, int colour) {
setPixel(image,x,y,colour);
+
int x,y;
 +
for (y=y1; y<y2; y++)
 +
for (x=x1; x<x2; x++)
 +
setPixel(image,x,y,colour);
 +
}
 
}
 
}

Revision as of 10:14, 3 July 2006

main() {

// Default Targa image header typedef struct { char idlength = 0; char colourmaptype = 0; char datatypecode = 0; short int colourmaporigin = 0; short int colourmaplength = 0; char colourmapdepth = 0; short int x_origin = 0; short int y_origin = 0; short width = 400; short height = 300; char bitsperpixel = 8; 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->width = width; image->height = height; 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); } }