author | Tero Marttila <terom@fixme.fi> |
Fri, 08 Aug 2008 00:15:29 +0300 | |
changeset 31 | 12d5361e7472 |
parent 17 | 8e8b56b0e0f5 |
permissions | -rw-r--r-- |
13
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1 |
#include <stdlib.h> |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
2 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
3 |
#include "common.h" |
17
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
4 |
#include "render_struct.h" |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
5 |
#include "render.h" |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
6 |
#include "render_raw_struct.h" |
13
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
#include "render_raw.h" |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
8 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
9 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
10 |
|
17
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
11 |
int render_raw_deinit (struct render_raw *ctx) { |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
12 |
return 0; |
13
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
13 |
} |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
|
17
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
15 |
void render_raw_free (struct render_raw *ctx) { |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
16 |
render_raw_deinit(ctx); |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
17 |
|
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
18 |
if (ctx->owned_by_me) |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
19 |
free(ctx); |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
20 |
} |
13
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
21 |
|
17
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
22 |
int render_raw_init (struct render_raw *ctx, struct render *render) { |
13
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
23 |
// store some info from the struct render |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
24 |
ctx->img_w = render->img_w; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
25 |
ctx->io_stream = render->io_stream; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
26 |
ctx->io_write_fn = render->io_write_fn; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
27 |
ctx->io_flush_fn = render->io_flush_fn; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
28 |
ctx->cb_arg = render->cb_arg; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
29 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
30 |
// success |
17
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
31 |
return 0; |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
32 |
|
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
33 |
/* |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
34 |
error: |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
35 |
_render_raw_deinit(ctx); |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
36 |
return -1; |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
37 |
*/ |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
38 |
} |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
39 |
|
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
40 |
struct render_raw *render_raw_alloc (struct render *render) { |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
41 |
struct render_raw *ctx = NULL; |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
42 |
|
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
43 |
// calloc the render_png |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
44 |
if (!(ctx = calloc(1, sizeof(struct render_raw)))) |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
45 |
ERROR("calloc"); |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
46 |
|
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
47 |
// mark it to be freed |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
48 |
ctx->owned_by_me = 1; |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
49 |
|
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
50 |
// initialize |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
51 |
if (render_raw_init(ctx, render)) |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
52 |
goto error; |
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
53 |
|
13
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
54 |
return ctx; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
55 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
56 |
error: |
17
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
57 |
render_raw_free(ctx); |
13
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
58 |
return NULL; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
59 |
} |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
60 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
61 |
int render_raw_row (struct render_raw *ctx, unsigned char *rowbuf) { |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
62 |
// write it out |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
63 |
if (ctx->io_stream) { |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
64 |
if (fwrite(rowbuf, ctx->img_w, 1, ctx->io_stream) != 1) |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
65 |
PERROR("fwrite"); |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
66 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
67 |
} else if (ctx->io_write_fn) { |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
68 |
if (ctx->io_write_fn(rowbuf, ctx->img_w, ctx->cb_arg)) |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
69 |
ERROR("io_write_fn"); |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
70 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
71 |
} else { |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
72 |
// ignore |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
73 |
} |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
74 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
75 |
// success |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
76 |
return 0; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
77 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
78 |
error: |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
79 |
// don't free it yet, raw_{done,abort} does that! |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
80 |
return -1; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
81 |
} |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
82 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
83 |
int render_raw_done (struct render_raw *ctx) { |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
84 |
// flush |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
85 |
if (ctx->io_stream) { |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
86 |
if (fflush(ctx->io_stream)) |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
87 |
PERROR("fflush"); |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
88 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
89 |
} else if (ctx->io_flush_fn) { |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
90 |
if (ctx->io_flush_fn(ctx->cb_arg)) |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
91 |
ERROR("io_flush_fn"); |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
92 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
93 |
} else { |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
94 |
// ignore |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
95 |
} |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
96 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
97 |
// free everything |
17
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
98 |
render_raw_free(ctx); |
13
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
99 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
100 |
// success |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
101 |
return 0; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
102 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
103 |
error: |
17
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
104 |
render_raw_free(ctx); |
13
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
105 |
return -1; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
106 |
} |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
107 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
108 |
int render_raw_abort (struct render_raw *ctx) { |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
109 |
// just free it |
17
8e8b56b0e0f5
a half-working render_slices. Render_multi is currently semantically broken/buggy, but it's time to go to sleep
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
110 |
render_raw_free(ctx); |
13
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
111 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
112 |
// success |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
113 |
return 0; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
114 |
} |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
115 |