1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <raylib.h>
#include <tiffio.h>
#include <lib/lib.h>
#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;
}
|