aboutsummaryrefslogtreecommitdiff
path: root/src/image.c
blob: 4610fdb1f49924f156831d60db9938ff2bbb40d8 (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
77
78
79
80
81
#include "image.h"

#include "bitmap.h"

#include <stdlib.h>

struct imv_image {
  int width;
  int height;
  struct imv_bitmap *bitmap;
  #ifdef IMV_BACKEND_LIBRSVG
  RsvgHandle *svg;
  #endif
};

struct imv_image *imv_image_create_from_bitmap(struct imv_bitmap *bmp)
{
  struct imv_image *image = calloc(1, sizeof *image);
  image->width = bmp->width;
  image->height = bmp->height;
  image->bitmap = bmp;
  return image;
}

#ifdef IMV_BACKEND_LIBRSVG
struct imv_image *imv_image_create_from_svg(RsvgHandle *handle)
{
  struct imv_image *image = calloc(1, sizeof *image);
  image->svg = handle;

  RsvgDimensionData dim;
  rsvg_handle_get_dimensions(handle, &dim);
  image->width = dim.width;
  image->height = dim.height;
  return image;
}
#endif

void imv_image_free(struct imv_image *image)
{
  if (!image) {
    return;
  }

  if (image->bitmap) {
    imv_bitmap_free(image->bitmap);
  }

#ifdef IMV_BACKEND_LIBRSVG
  if (image->svg) {
    g_object_unref(image->svg);
  }
#endif

  free(image);
}

int imv_image_width(const struct imv_image *image)
{
  return image ? image->width : 0;
}

int imv_image_height(const struct imv_image *image)
{
  return image ? image->height : 0;
}

/* Non-public functions, only used by imv_canvas */
struct imv_bitmap *imv_image_get_bitmap(const struct imv_image *image)
{
  return image->bitmap;
}

#ifdef IMV_BACKEND_LIBRSVG
RsvgHandle *imv_image_get_svg(const struct imv_image *image)
{
  return image->svg;
}
#endif

/* vim:set ts=2 sts=2 sw=2 et: */