aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
blob: 02697aa8447d2ae10c7bee0430852457a8b17afe (plain)
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
#include <stdio.h>
#include <stdlib.h>

#include <raylib.h>

#include <tiffio.h>

#include <lib/lib.h>

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;
  }

  uint32_t width, height;
  TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
  TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);

  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;
  }

  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)80, (float)80 };

  Vector2 origin = { (float)0, (float)-10 };

  SetTargetFPS(60);
  Camera2D camera = { 0 };
  camera.zoom = 1.0f;

  while (!WindowShouldClose()) {
    //-----------------------------------------------
    //-DRAWING---------------------------------------
    //-----------------------------------------------
    BeginDrawing();
    ClearBackground(RAYWHITE);
    BeginMode2D(camera);
    EndMode2D();
    DrawText("Image Manip", 0, 0, 10, DARKGRAY);
    DrawTexturePro(RaylibTexture, sourceRec, destRec, origin, (float)0, RAYWHITE);
    EndDrawing();
    //-----------------------------------------------
  }

  _TIFFfree(raster);
  TIFFClose(tif);

  CloseWindow();
  return 0;
}