aboutsummaryrefslogtreecommitdiff
path: root/src/source.h
blob: 4f1a0dd9f09b25c8ff3e8b79330a62332a09f7be (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
#ifndef IMV_SOURCE_H
#define IMV_SOURCE_H

#include <pthread.h>
#include <stdbool.h>
#include "bitmap.h"

struct imv_source_message {
  /* Pointer to sender of message */
  struct imv_source *source;

  /* User-supplied pointer */
  void *user_data;

  /* Receiver is responsible for destroying bitmap */
  struct imv_bitmap *bitmap;

  /* If an animated gif, the frame's duration in milliseconds, else 0 */
  int frametime;

  /* Error message if bitmap was NULL */
  const char *error;
};

/* Generic source of one or more bitmaps. Essentially a single image file */
struct imv_source {
  /* usually the path of the image this is the source of */
  char *name; 

  /* source's image dimensions */
  int width;
  int height;

  /* Usually 1, more if animated */
  int num_frames;

  /* Next frame to be loaded, 0-indexed */
  int next_frame;

  /* Attempted to be locked by load_first_frame or load_next_frame.
   * If the mutex can't be locked, the call is aborted.
   * Used to prevent the source from having multiple worker threads at once.
   * Released by the source before calling the message callback with a result.
   */
  pthread_mutex_t busy;

  /* Trigger loading of the first frame. Returns 0 on success. */
  int (*load_first_frame)(struct imv_source *src);

  /* Trigger loading of next frame. Returns 0 on success. */
  int (*load_next_frame)(struct imv_source *src);

  /* Safely free contents of this source. After this returns
   * it is safe to dealocate/overwrite the imv_source instance.
   */
  void (*free)(struct imv_source *src);

  /* User-specified callback for returning messages */
  void (*callback)(struct imv_source_message *message);

  /* User-specified pointer, included in returned messages */
  void *user_data;

  /* Implementation private data */
  void *private;
};


#endif