author | Tero Marttila <terom@fixme.fi> |
Sat, 07 Jun 2008 05:05:18 +0300 | |
changeset 13 | ee426f453cf5 |
child 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" |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
#include "render_internal.h" |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
5 |
#include "render_raw.h" |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
6 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
struct render_raw { |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
8 |
// some info that we need to keep from the struct render |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
9 |
u_int32_t img_w; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
10 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
11 |
// cb or stream? |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
12 |
FILE *io_stream; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
13 |
render_ctx_write_cb io_write_fn; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
render_ctx_flush_cb io_flush_fn; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
15 |
void *cb_arg; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
16 |
}; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
17 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
18 |
static void _render_raw_free (struct render_raw *ctx) { |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
19 |
free(ctx); |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
20 |
} |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
21 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
22 |
struct render_raw *render_raw_init (struct render *render) { |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
23 |
struct render_raw *ctx = NULL; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
24 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
25 |
// calloc the render_png |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
26 |
if (!(ctx = calloc(1, sizeof(struct render_raw)))) |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
27 |
ERROR("calloc"); |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
28 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
29 |
// store some info from the struct render |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
30 |
ctx->img_w = render->img_w; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
31 |
ctx->io_stream = render->io_stream; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
32 |
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
|
33 |
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
|
34 |
ctx->cb_arg = render->cb_arg; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
35 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
36 |
// success |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
37 |
return ctx; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
38 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
39 |
error: |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
40 |
_render_raw_free(ctx); |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
41 |
return NULL; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
42 |
} |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
43 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
44 |
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
|
45 |
// write it out |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
46 |
if (ctx->io_stream) { |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
47 |
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
|
48 |
PERROR("fwrite"); |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
49 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
50 |
} else if (ctx->io_write_fn) { |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
51 |
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
|
52 |
ERROR("io_write_fn"); |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
53 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
54 |
} else { |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
55 |
// ignore |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
56 |
} |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
57 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
58 |
// success |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
59 |
return 0; |
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 |
error: |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
62 |
// 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
|
63 |
return -1; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
64 |
} |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
65 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
66 |
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
|
67 |
// flush |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
68 |
if (ctx->io_stream) { |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
69 |
if (fflush(ctx->io_stream)) |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
70 |
PERROR("fflush"); |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
71 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
72 |
} else if (ctx->io_flush_fn) { |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
73 |
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
|
74 |
ERROR("io_flush_fn"); |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
75 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
76 |
} else { |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
77 |
// ignore |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
78 |
} |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
79 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
80 |
// free everything |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
81 |
_render_raw_free(ctx); |
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 |
// success |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
84 |
return 0; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
85 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
86 |
error: |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
87 |
_render_raw_free(ctx); |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
88 |
return -1; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
89 |
} |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
90 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
91 |
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
|
92 |
// just free it |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
93 |
_render_raw_free(ctx); |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
94 |
|
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
95 |
// success |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
96 |
return 0; |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
97 |
} |
ee426f453cf5
* fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
98 |