aboutsummaryrefslogtreecommitdiffstats
path: root/src/meh.h
blob: b8522d9c7c996e0c7830493c05efa6c42a154a40 (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
#include <stdio.h>

#include "X11/Xlib.h"

struct image;

struct imageformat{
	struct image *(*open)(FILE *);
	void (*prep)(struct image *);
	int (*read)(struct image *);
	void (*close)(struct image *);
};

typedef enum{
	NONE,
	FASTLOADED,
	FASTSCALED,
	FASTDRAWN,
	LOADED,
	FASTSCALED2,
	FASTDRAWN2,
	SCALED,
	DRAWN,
	ERROR
} imgstate;

struct image{
	unsigned char *buf;
	unsigned int bufwidth, bufheight;
	struct imageformat *fmt;
	imgstate state;
	XImage *ximg;
};


/* scale */
void scale(struct image *img, unsigned int width, unsigned int height, unsigned int bytesperline, char* __restrict__ newBuf);
void nearestscale(struct image *img, unsigned int width, unsigned int height, unsigned int bytesperline, char* __restrict__ newBuf);

/* XLib */
void setaspect(unsigned int w, unsigned int h);
void xinit();
void drawimage(XImage *ximg, unsigned int width, unsigned int height);
XImage *getimage(struct image *img, unsigned int width, unsigned int height, int fast);
void freeXImg(XImage *ximg);

#ifdef TDEBUG
#define TDEBUG_START \
struct timeval t0;\
struct timeval t1;\
gettimeofday(&t0, NULL);
#define TDEBUG_END(x) \
gettimeofday(&t1, NULL); \
printf("%s: %li e2 us\n", (x), ((t1.tv_sec - t0.tv_sec) * 1000000 + t1.tv_usec - t0.tv_usec) / 100);
#else
#define TDEBUG_START
#define TDEBUG_END(x)
#endif

/* Supported Formats */
extern struct imageformat libjpeg;
extern struct imageformat giflib;
extern struct imageformat libpng;
extern struct imageformat bmp;
extern struct imageformat netpbm;
extern struct imageformat imagemagick;