2 * Copyright 2008 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.
31 const char *ale_translate_glsl(const char *);
33 static void beer_info_printf(const char *c
, ...) {
36 fprintf(stderr
, "beer: ");
39 vfprintf(stderr
, c
, ap
);
42 fprintf(stderr
, "\n");
45 static void beer_error_printf(const char *c
, ...) {
48 fprintf(stderr
, "beer: ");
51 vfprintf(stderr
, c
, ap
);
54 fprintf(stderr
, "\n");
55 fprintf(stderr
, "beer: Exiting.\n");
59 int main(int argc
, const char *argv
[]) {
67 cl_context cc
= clCreateContextFromType(0, CL_DEVICE_TYPE_GPU
, NULL
, NULL
, NULL
);
69 if (cc
== ((cl_context
) 0)) {
70 beer_error_printf("Failed to create an OpenCL context.");
73 ac
= ale_new_context(cc
);
76 beer_error_printf("Failed to create an ALE context.");
80 * Create a frame from a trivial image array.
83 unsigned char domain_data
[27] =
84 { 0, 0, 0, 0, 0, 0, 0, 0, 0,
85 0, 0, 0, 1, 1, 1, 0, 0, 0,
86 0, 0, 0, 0, 0, 0, 0, 0, 0 };
90 ale_image ai
= ale_new_image(ac
, ALE_IMAGE_RGB
, ALE_TYPE_UINT_8
);
92 ale_image_set_host_static(ai
, 3, 3, domain_data
, NULL
, NULL
);
94 ale_render ar
= ale_new_render_incremental(ac
, ALE_TYPE_FLOAT_32
, ALE_INVARIANT_MEAN
);
96 ale_render_resize(ar
, 0, 0, 3, 3);
98 ale_render_merge(ar
, ai
);
100 ale_image ari
= ale_render_data(ar
);
102 domain_data2
= ale_return_host(ari
);
106 printf("Input data:");
107 for (di
= 0; di
< 27; di
++) {
108 unsigned int i
= domain_data
[di
];
113 printf("Output data:");
114 for (di
= 0; di
< 27; di
++) {
115 float f
= domain_data2
[di
];
120 ale_return_release_host(domain_data2
);
121 ale_image_release(ai
);
122 ale_image_release(ari
);
123 ale_render_release(ar
);
124 ale_context_release(ac
);