2 * Copyright 2008, 2009 David Hilvert <dhilvert@gmail.com>
4 * This file is part of libale.
6 * libale is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU Affero General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
11 * libale is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
16 * You should have received a copy of the GNU Affero General Public License
17 * along with libale. If not, see <http://www.gnu.org/licenses/>.
21 * beer: a simple client program for libale.
32 * beer_info_printf: Display informational message for format C.
35 static void beer_info_printf(const char *c
, ...) {
38 fprintf(stderr
, "beer: ");
41 vfprintf(stderr
, c
, ap
);
44 fprintf(stderr
, "\n");
48 * beer_error_printf: Display error message for format C.
51 static void beer_error_printf(const char *c
, ...) {
54 fprintf(stderr
, "beer: ");
57 vfprintf(stderr
, c
, ap
);
60 fprintf(stderr
, "\n");
61 fprintf(stderr
, "beer: Exiting.\n");
66 * main: Main routine (entry point).
69 int main(int argc
, const char *argv
[]) {
72 * Obtain OpenCL context CC.
75 cl_context cc
= clCreateContextFromType(0, CL_DEVICE_TYPE_GPU
, NULL
, NULL
, NULL
);
77 if (cc
== ((cl_context
) 0)) {
78 beer_error_printf("Failed to create an OpenCL context.");
82 * Obtain ALE context AC.
85 ale_context ac
= ale_new_context(cc
);
88 beer_error_printf("Failed to create an ALE context.");
92 * Create sample input frame AI from trivial image array DOMAIN_DATA.
95 unsigned char domain_data
[27] =
96 { 0, 0, 0, 0, 0, 0, 0, 0, 0,
97 0, 0, 0, 1, 1, 1, 0, 0, 0,
98 0, 0, 0, 0, 0, 0, 0, 0, 0 };
100 ale_image ai
= ale_new_image(ac
, ALE_IMAGE_RGB
, ALE_TYPE_UINT_8
);
102 ale_image_set_host_static(ai
, 3, 3, domain_data
, NULL
, NULL
);
105 * Create incremental renderer AR.
108 ale_render ar
= ale_new_render_incremental(ac
, ALE_TYPE_FLOAT_32
, ALE_INVARIANT_MEAN
);
111 * Create identity transformation AT with bounds AI.
114 ale_trans at
= ale_new_trans(ac
, ai
);
117 * Resize render area AR to bounds AT.
120 ale_render_resize(ar
, at
);
123 * Merge AI into AR with transformation AT.
126 ale_render_merge(ar
, at
, ai
);
129 * Retain rendered host image DOMAIN_DATA2 from AR.
132 ale_image ari
= ale_render_retain_image(ar
);
134 float *domain_data2
= ale_image_retain_host(ari
);
137 * Display results as text.
142 printf("Input data:");
143 for (di
= 0; di
< 27; di
++) {
144 unsigned int i
= domain_data
[di
];
149 printf("Output data:");
150 for (di
= 0; di
< 27; di
++) {
151 float f
= domain_data2
[di
];
157 * Release dynamic memory.
160 ale_image_release_host(ari
, domain_data2
);
161 ale_image_release(ai
);
162 ale_image_release(ari
);
163 ale_trans_release(at
);
164 ale_render_release(ar
);
165 ale_context_release(ac
);
168 * Return success (no error).