#include #include #include #include #include #include #define TAG 50839 #define OFFSET 16 int main() { SetConfigFlags(FLAG_WINDOW_RESIZABLE); const char* gui_title = "Image Manip - Useful for segmentations!"; InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, gui_title); TIFF *tif = TIFFOpen("./data/test.tif", "r"); if (!tif) { fprintf(stderr, "Failed to open TIFF file\n"); return 1; } /* else { int dircount = 0; do { dircount++; TIFFPrintDirectory(tif, stdout, TIFFPRINT_NONE); } while (TIFFReadDirectory(tif)); printf("%d directories in\n", dircount); return 0; } */ uint32_t width, height; TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width); TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height); uint32_t count; void* buffer; TIFFGetField(tif, TAG, &count, &buffer); printf("%d\n", count); for (size_t index = 0; index < 10; index++) { printf("%2X ", ((uint8_t *)buffer)[index]); } printf("\n"); uint32_t* raster = (uint32_t*)_TIFFmalloc(width*height*sizeof(uint32_t)); if (raster == NULL) { fprintf(stderr, "Memory allocation error\n"); TIFFClose(tif); return 1; } if (!TIFFReadRGBAImage(tif, width, height, raster, 0)) { fprintf(stderr, "Failed to read TIFF image\n"); _TIFFfree(raster); TIFFClose(tif); return 1; } struct timespec ts; char buff[100]; timespec_get(&ts, TIME_UTC); strftime(buff, sizeof buff, "%D %T", gmtime(&ts.tv_sec)); printf("Current time: %s.%09ld UTC\n", buff, ts.tv_nsec); uint32_t out = 0; for (size_t y = 0; y < height; y++) { for (size_t x = 0; x < width; x++) { out += x * y - out ^ 0xF; } } strftime(buff, sizeof buff, "%D %T", gmtime(&ts.tv_sec)); printf("Current time: %s.%09ld UTC\n", buff, ts.tv_nsec); Image RaylibImage; RaylibImage.data = raster; RaylibImage.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8; RaylibImage.width = width; RaylibImage.height = height; RaylibImage.mipmaps = 1; Texture2D RaylibTexture = LoadTextureFromImage(RaylibImage); Rectangle sourceRec = { 0.0f, 0.0f, (float)width, (float)height }; Rectangle destRec = { 0.0f, 0.0f, (float)SCREEN_WIDTH, (float)(SCREEN_HEIGHT-OFFSET) }; Vector2 origin = { (float)0, (float)-OFFSET }; SetTargetFPS(60); Camera2D camera = { 0 }; camera.zoom = 1.0f; while (!WindowShouldClose()) { //----------------------------------------------- //-DRAWING--------------------------------------- //----------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); BeginMode2D(camera); EndMode2D(); DrawText("Image Manip", 0, 0, OFFSET, DARKGRAY); DrawTexturePro(RaylibTexture, sourceRec, destRec, origin, (float)0, RAYWHITE); uint32_t x = 0x49, y = 0x4A; uint32_t dx = 0x69 - x, dy = 0x6E - y; x = (SCREEN_WIDTH*x)/width; y = SCREEN_HEIGHT-((SCREEN_HEIGHT-OFFSET)*y)/height; dx = (SCREEN_WIDTH*dx)/width; dy = SCREEN_HEIGHT-((SCREEN_HEIGHT-OFFSET)*dy)/height; DrawRectangleGradientH(x, y, dx, dy, MAROON, GOLD); EndDrawing(); //----------------------------------------------- } _TIFFfree(raster); TIFFClose(tif); CloseWindow(); return 0; }