int main(int argc, char *argv[]) { uint16_t w = 1280; uint16_t h = 1024; uint8_t p[3 * w * h]; for(int y = 0; y < h; ++y) { float b = 1 - 2. * y / h; for(int x = 0; x < w; ++x) { float a = -2.5 + 3.5 * x / w; uint8_t v = 2 * mandelbrot(a, b); uint8_t r = v; uint8_t g = v; uint8_t b = v; int i = 3 * (y * w + x); p[i + 0] = r; p[i + 1] = g; p[i + 2] = b; } } tga_write(stdout, p, w, h); return EXIT_SUCCESS; }
tga_result tga_write_bgr_rle(const char *filename, uint8_t *image, const uint16_t width, const uint16_t height, const uint8_t depth) { tga_image img; init_tga_image(&img, image, width, height, depth); img.image_type = TGA_IMAGE_TYPE_BGR_RLE; return tga_write(filename, &img); }
tga_result tga_write_mono_rle(const char *filename, uint8_t *image, const uint16_t width, const uint16_t height) { tga_image img; init_tga_image(&img, image, width, height, 8); img.image_type = TGA_IMAGE_TYPE_MONO_RLE; return tga_write(filename, &img); }
tga_result tga_write_bgr(const char *filename, uint8_t *image, const uint16_t width, const uint16_t height, const uint8_t depth, tgaFileOperations* fops) { tga_image img; init_tga_image(&img, image, width, height, depth); img.image_type = TGA_IMAGE_TYPE_BGR; return tga_write(filename, &img, fops); }
/* Note: this function will MODIFY <image> */ tga_result tga_write_rgb(const char *filename, uint8_t *image, const uint16_t width, const uint16_t height, const uint8_t depth) { tga_image img; init_tga_image(&img, image, width, height, depth); img.image_type = TGA_IMAGE_TYPE_BGR; (void)tga_swap_red_blue(&img); return tga_write(filename, &img); }
void ImageFormat_TGA::Save(const Filename& filename, int width, int height, void* data) { tga_image tga; MemSet(&tga,0,sizeof(tga)); tga.image_id_length=0; tga.color_map_type=0; tga.image_type=TGA_IMAGE_TYPE_BGR; tga.color_map_origin=0; tga.color_map_length=0; tga.color_map_depth=0; tga.origin_x=0; tga.origin_y=0; tga.width=(unsigned short)width; tga.height=(unsigned short)height; tga.pixel_depth=32; tga.image_descriptor=TGA_T_TO_B_BIT; tga.image_id=0; tga.color_map_data=0; tga.image_data=static_cast<unsigned char*>(data); tga_write(filename.GetString(),&tga); }
static void populate_asset_dir( const char* rootdir, const char* assetdir) { uint32_t* hmap; uint32_t* smap; uint32_t* vmap; uint8_t* image; int32_t i; tga_header tga; tga_init(IMAGE_WIDTH, IMAGE_HEIGHT, 32, 0, &tga); hmap = (uint32_t*) malloc(IMAGE_WIDTH * IMAGE_HEIGHT * sizeof(*hmap)); smap = (uint32_t*) malloc(IMAGE_WIDTH * IMAGE_HEIGHT * sizeof(*hmap)); vmap = (uint32_t*) malloc(IMAGE_WIDTH * IMAGE_HEIGHT * sizeof(*hmap)); image = (uint8_t*) malloc(IMAGE_WIDTH * IMAGE_HEIGHT * 4); for(i = 0; i < NUM_IMAGES; ++i) { char fname[16]; char path[taa_PATH_SIZE]; FILE* fp; int32_t j; diamondsquare(IMAGE_WIDTH, IMAGE_HEIGHT, 0xffff, hmap); diamondsquare(IMAGE_WIDTH, IMAGE_HEIGHT, 0xffff, smap); diamondsquare(IMAGE_WIDTH, IMAGE_HEIGHT, 0xffff, vmap); // convert the hsv data into bgra for(j = 0; j < IMAGE_WIDTH * IMAGE_HEIGHT; ++j) { float b, g, r; float h, s, v; float h1, c, x, m; h = hmap[j] * (360.0f/0xffff); // hue in range 0 - 360 s = smap[j] * ( 1.0f/0xffff); // sat in range 0 - 1 v = vmap[j] * ( 1.0f/0xffff); // val in range 0 - 1 s = s * 0.5f + 0.5f; c = v * s; // chroma h1 = h/60.0f; // h' x = c * (1.0f - (float) fabs(fmod(h1, 2) - 1.0f)); if(h1 < FLT_EPSILON) { r = 0; g = 0; b = 0; } else if(h1 < 1.0f) { r = c; g = x; b = 0; } else if(h1 < 2.0f) { r = x; g = c; b = 0; } else if(h1 < 3.0f) { r = 0; g = c; b = x; } else if(h1 < 4.0f) { r = 0; g = x; b = c; } else if(h1 < 5.0f) { r = x; g = 0; b = c; } else { r = c; g = 0; b = x; } m = v - c; image[j*4+0] = (uint8_t) ((b + m) * 0xff); image[j*4+1] = (uint8_t) ((g + m) * 0xff); image[j*4+2] = (uint8_t) ((r + m) * 0xff); image[j*4+3] = 0xff; } sprintf(fname, "%i.tga", i); taa_path_set(path, sizeof(path), rootdir); taa_path_append(path, sizeof(path), assetdir); taa_path_append(path, sizeof(path), fname); fp = fopen(path, "wb"); if(fp != NULL) { unsigned char hbuf[tga_HEADER_SIZE]; tga_write(&tga, hbuf); fwrite(hbuf, 1, sizeof(hbuf), fp); fwrite(image, 1, IMAGE_WIDTH*IMAGE_HEIGHT*4, fp); assert(ftell(fp) == (tga_HEADER_SIZE+IMAGE_WIDTH*IMAGE_HEIGHT*4)); fclose(fp); } } free(image); free(vmap); free(smap); free(hmap); }
int main() { uint8_t alpha[NUM_IMAGES], r[NUM_IMAGES], g[NUM_IMAGES], b[NUM_IMAGES]; tga_image image[NUM_IMAGES]; int *pixels_addr[NUM_IMAGES]; int *pixels_addr_new; pixels_addr_new = malloc(sizeof(int)); int height[NUM_IMAGES], width[NUM_IMAGES]; int i = 0; tga_result result; char addr[256]; for(i=0;i<NUM_IMAGES;i++) { char path[256]; if(i<10) { sprintf(addr,"%s%d%s","/home/ankit/Work/Ankit/BlockColors_WithoutRLE/BlockColors_WithoutRLE_0000",i,".tga"); } else if(i>=10 && i<100) { sprintf(addr,"%s%d%s","/home/ankit/Work/Ankit/BlockColors_WithoutRLE/BlockColors_WithoutRLE_000",i,".tga"); } else if(i>=100 && i<1000) { sprintf(addr,"%s%d%s","/home/ankit/Work/Ankit/BlockColors_WithoutRLE/BlockColors_WithoutRLE_00",i,".tga"); } else if(i>=1000) { sprintf(addr,"%s%d%s","/home/ankit/Work/Ankit/BlockColors_WithoutRLE/BlockColors_WithoutRLE_0",i,".tga"); } printf("The image being opened is %s\n",addr); result = tga_read(&image[i],addr); if(result != TGA_NOERR) { printf("Error opening the image\n"); } else { pixels_addr[i] = (int *)image[i].image_data; height[i] = (int)image[i].height; width[i] = (int)image[i].width; } printf("The Height is %d\n",width[i]); } int j = 0, k = 0; tga_image img_new; int img[NUM_IMAGES]; char output[256]; for(k=0;k<NUM_IMAGES-1;k++) { for(i=0;i<height[k];i++) // for(i=0;i<18;i++) { for(j=0;j<width[k];j++) // for(j=0;j<86;j++) { img[k] = *(pixels_addr[k] + (i * width[k]) + j); img[k+1] = *(pixels_addr[k+1] + (i * width[k]) + j); *(pixels_addr[k] + (i *width[k]) + j ) = img[k] ^ img[k+1]; // printf("This is printing %d %d\n",i,j); } } // img_new.image_data = pixels_addr_new; sprintf(output,"%s%s%d%s","/home/ankit/Work/Ankit/BlockColors_WithoutRLE/","new",k+1,".tga"); result = tga_write(output,&image[k]); memset(pixels_addr[k],0,height[k]*width[k]); // tga_close(); } }