dbus: check that interface is not NULL (FS#667)
[awesome.git] / image.c
blobd4d8c6082197ec24495eef1c4e23285b1a7d5a39
1 /*
2 * image.c - image object
4 * Copyright © 2008-2009 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <xcb/xcb_image.h>
24 #include <Imlib2.h>
26 #include "globalconf.h"
27 #include "config.h"
28 #include "luaa.h"
29 #include "common/luaobject.h"
31 struct image
33 LUA_OBJECT_HEADER
34 /** Imlib2 image */
35 Imlib_Image image;
36 /** Image data */
37 uint8_t *data;
38 /** Flag telling if the image is up to date or needs computing before
39 * drawing */
40 bool isupdated;
43 LUA_OBJECT_FUNCS(image_class, image_t, image)
45 static int
46 luaA_image_gc(lua_State *L)
48 image_t *p = luaA_checkudata(L, 1, &image_class);
49 imlib_context_set_image(p->image);
50 imlib_free_image();
51 p_delete(&p->data);
52 return luaA_object_gc(L);
55 static const char *
56 image_imlib_load_strerror(Imlib_Load_Error e)
58 switch(e)
60 case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST:
61 return "no such file or directory";
62 case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY:
63 return "file is a directory";
64 case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ:
65 return "read permission denied";
66 case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT:
67 return "no loader for file format";
68 case IMLIB_LOAD_ERROR_PATH_TOO_LONG:
69 return "path too long";
70 case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT:
71 return "path component non existent";
72 case IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY:
73 return "path component not a directory";
74 case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE:
75 return "path points outside address space";
76 case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS:
77 return "too many symbolic links";
78 case IMLIB_LOAD_ERROR_OUT_OF_MEMORY:
79 return "out of memory";
80 case IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS:
81 return "out of file descriptors";
82 case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE:
83 return "write permission denied";
84 case IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE:
85 return "out of disk space";
86 case IMLIB_LOAD_ERROR_UNKNOWN:
87 return "unknown error, that's really bad";
88 case IMLIB_LOAD_ERROR_NONE:
89 return "no error, oops";
92 return "unknown error";
95 /** Get image width.
96 * \param image The image.
97 * \return The image width in pixel.
99 int
100 image_getwidth(image_t *image)
102 imlib_context_set_image(image->image);
103 return imlib_image_get_width();
106 /** Get image height.
107 * \param image The image.
108 * \return The image height in pixel.
111 image_getheight(image_t *image)
113 imlib_context_set_image(image->image);
114 return imlib_image_get_height();
117 /** Get the ARGB32 data from an image.
118 * \param image The image.
119 * \return Data.
121 uint8_t *
122 image_getdata(image_t *image)
124 int size, i;
125 uint32_t *data;
126 double alpha;
127 uint8_t *dataimg;
128 #if AWESOME_IS_BIG_ENDIAN
129 const int index_a = 0, index_r = 1, index_g = 2, index_b = 3;
130 #else
131 const int index_a = 3, index_r = 2, index_g = 1, index_b = 0;
132 #endif
134 if(image->isupdated)
135 return image->data;
137 imlib_context_set_image(image->image);
139 data = imlib_image_get_data_for_reading_only();
141 size = imlib_image_get_width() * imlib_image_get_height();
143 p_realloc(&image->data, size * 4);
144 dataimg = image->data;
146 for(i = 0; i < size; i++, dataimg += 4)
148 dataimg[index_a] = (data[i] >> 24) & 0xff; /* A */
149 /* cairo wants pre-multiplied alpha */
150 alpha = dataimg[index_a] / 255.0;
151 dataimg[index_r] = ((data[i] >> 16) & 0xff) * alpha; /* R */
152 dataimg[index_g] = ((data[i] >> 8) & 0xff) * alpha; /* G */
153 dataimg[index_b] = (data[i] & 0xff) * alpha; /* B */
156 image->isupdated = true;
158 return image->data;
162 static void
163 image_draw_to_1bit_ximage(image_t *image, xcb_image_t *img)
165 imlib_context_set_image(image->image);
167 uint32_t *data = imlib_image_get_data_for_reading_only();
169 int width = imlib_image_get_width();
170 int height = imlib_image_get_height();
172 for(int y = 0; y < height; y++)
173 for(int x = 0; x < width; x++)
175 int i, pixel, tmp;
177 i = y * width + x;
179 // Sum up all color components ignoring alpha
180 tmp = (data[i] >> 16) & 0xff;
181 tmp += (data[i] >> 8) & 0xff;
182 tmp += data[i] & 0xff;
184 pixel = (tmp / 3 < 127) ? 0 : 1;
186 xcb_image_put_pixel(img, x, y, pixel);
190 // Convert an image to a 1bit pixmap
191 xcb_pixmap_t
192 image_to_1bit_pixmap(image_t *image, xcb_drawable_t d)
194 xcb_pixmap_t pixmap;
195 xcb_gcontext_t gc;
196 xcb_image_t *img;
197 uint16_t width, height;
199 width = image_getwidth(image);
200 height = image_getheight(image);
202 /* Prepare the pixmap and gc */
203 pixmap = xcb_generate_id(globalconf.connection);
204 xcb_create_pixmap(globalconf.connection, 1, pixmap, d, width, height);
206 gc = xcb_generate_id(globalconf.connection);
207 xcb_create_gc(globalconf.connection, gc, pixmap, 0, NULL);
209 /* Prepare the image */
210 img = xcb_image_create_native(globalconf.connection, width, height,
211 XCB_IMAGE_FORMAT_XY_BITMAP, 1, NULL, 0, NULL);
212 image_draw_to_1bit_ximage(image, img);
214 /* Paint the image to the pixmap */
215 xcb_image_put(globalconf.connection, pixmap, gc, img, 0, 0, 0);
217 xcb_free_gc(globalconf.connection, gc);
219 xcb_image_destroy(img);
221 return pixmap;
224 /** Create a new image from ARGB32 data.
225 * \param width The image width.
226 * \param height The image height.
227 * \param data The image data.
228 * \return 1 if an image has been pushed on stack, 0 otherwise.
231 image_new_from_argb32(int width, int height, uint32_t *data)
233 Imlib_Image imimage;
235 if((imimage = imlib_create_image_using_copied_data(width, height, data)))
237 imlib_context_set_image(imimage);
238 imlib_image_set_has_alpha(true);
239 image_t *image = image_new(globalconf.L);
240 image->image = imimage;
241 return 1;
244 return 0;
247 /** Create a new, completely black image.
248 * \param width The image width.
249 * \param height The image height.
250 * \return 1 if an image has been pushed on stack, 0 otherwise.
252 static int
253 image_new_blank(int width, int height)
255 Imlib_Image imimage;
257 if((imimage = imlib_create_image(width, height)))
259 imlib_context_set_image(imimage);
260 imlib_image_set_has_alpha(true);
261 /* After creation, an image has undefined content. Fix that up. */
262 imlib_context_set_color(0, 0, 0, 0xff);
263 imlib_image_fill_rectangle(0, 0, width, height);
264 image_t *image = image_new(globalconf.L);
265 image->image = imimage;
266 return 1;
269 return 0;
272 /** Load an image from filename.
273 * \param filename The image file to load.
274 * \return 1 if image is loaded and on stack, 0 otherwise.
276 static int
277 image_new_from_file(const char *filename)
279 Imlib_Image imimage;
280 image_t *image;
282 if(!filename)
283 return 0;
285 if(!(imimage = imlib_load_image_without_cache(filename)))
287 warn("cannot load image %s", filename);
288 return 0;
291 image = image_new(globalconf.L);
292 image->image = imimage;
294 return 1;
297 /** Create a new image object.
298 * \param L The Lua stack.
299 * \return The number of elements pushed on stack.
300 * \luastack
301 * \lparam The image path.
302 * \lreturn An image object.
304 static int
305 luaA_image_new(lua_State *L)
307 const char *filename;
309 if((filename = lua_tostring(L, 2)))
310 return image_new_from_file(filename);
311 return 0;
314 /** Create a new image object from ARGB32 data.
315 * \param L The Lua stack.
316 * \return The number of elements pushed on stack.
317 * \luastack
318 * \lparam The image width.
319 * \lparam The image height.
320 * \lparam The image data as a string in ARGB32 format, or nil to create an
321 * empty image.
322 * \lreturn An image object.
324 static int
325 luaA_image_argb32_new(lua_State *L)
327 size_t len;
328 unsigned int width = luaL_checknumber(L, 1);
329 unsigned int height = luaL_checknumber(L, 2);
331 if (width == 0)
332 luaL_error(L, "image.argb32() called with zero width");
333 if (height == 0)
334 luaL_error(L, "image.argb32() called with zero height");
336 if(lua_isnil(L, 3))
338 return image_new_blank(width, height);
341 const char *data = luaL_checklstring(L, 3, &len);
343 if(width * height * 4 != len)
344 luaL_error(L, "string size does not match image size");
346 return image_new_from_argb32(width, height, (uint32_t *) data);
349 /** Performs 90 degree rotations on the current image. Passing 0 orientation
350 * does not rotate, 1 rotates clockwise by 90 degree, 2, rotates clockwise by
351 * 180 degrees, 3 rotates clockwise by 270 degrees.
352 * \param L The Lua VM state.
353 * \return The number of elements pushed on stack.
354 * \luastack
355 * \lvalue An image.
356 * \lparam The rotation to perform.
358 static int
359 luaA_image_orientate(lua_State *L)
361 image_t *image = luaA_checkudata(L, 1, &image_class);
362 int orientation = luaL_checknumber(L, 2);
364 imlib_context_set_image(image->image);
365 imlib_image_orientate(orientation);
367 image->isupdated = false;
369 return 0;
372 /** Rotate an image with specified angle radians and return a new image.
373 * \param L The Lua VM state.
374 * \return The number of elements pushed on stack.
375 * \luastack
376 * \lvalue An image.
377 * \lparam The angle in radians.
378 * \lreturn A rotated image.
380 static int
381 luaA_image_rotate(lua_State *L)
383 image_t *image = luaA_checkudata(L, 1, &image_class), *new;
384 double angle = luaL_checknumber(L, 2);
386 new = image_new(L);
388 imlib_context_set_image(image->image);
389 new->image = imlib_create_rotated_image(angle);
391 return 1;
394 /** Crop an image to the given rectangle.
395 * \return The number of elements pushed on stack.
396 * \luastack
397 * \lvalue An image.
398 * \lparam The top left x coordinate of the rectangle.
399 * \lparam The top left y coordinate of the rectangle.
400 * \lparam The width of the rectangle.
401 * \lparam The height of the rectangle.
402 * \lreturn A cropped image.
404 static int
405 luaA_image_crop(lua_State *L)
407 image_t *image = luaA_checkudata(L, 1, &image_class), *new;
408 int x = luaL_checkint(L, 2);
409 int y = luaL_checkint(L, 3);
410 int w = luaL_checkint(L, 4);
411 int h = luaL_checkint(L, 5);
413 new = image_new(L);
415 imlib_context_set_image(image->image);
416 new->image = imlib_create_cropped_image(x, y, w, h);
418 return 1;
421 /** Crop the image to the given rectangle and scales it.
422 * \param L The Lua VM state.
423 * \return The number of elements pushed on stack.
424 * \luastack
425 * \lvalue An image.
426 * \lparam The top left x coordinate of the source rectangle.
427 * \lparam The top left y coordinate of the source rectangle.
428 * \lparam The width of the source rectangle.
429 * \lparam The height of the source rectangle.
430 * \lparam The width of the destination rectangle.
431 * \lparam The height of the destination rectangle.
432 * \lreturn A cropped image.
434 static int
435 luaA_image_crop_and_scale(lua_State *L)
437 image_t *image = luaA_checkudata(L, 1, &image_class), *new;
438 int source_x = luaL_checkint(L, 2);
439 int source_y = luaL_checkint(L, 3);
440 int w = luaL_checkint(L, 4);
441 int h = luaL_checkint(L, 5);
442 int dest_w = luaL_checkint(L, 6);
443 int dest_h = luaL_checkint(L, 7);
445 new = image_new(L);
447 imlib_context_set_image(image->image);
448 new->image = imlib_create_cropped_scaled_image(source_x,
449 source_y,
450 w, h,
451 dest_w, dest_h);
453 return 1;
456 /** Draw a pixel in an image
457 * \param L The Lua VM state
458 * \luastack
459 * \lvalue An image.
460 * \lparam The x coordinate of the pixel to draw
461 * \lparam The y coordinate of the pixel to draw
462 * \lparam The color to draw the pixel in
464 static int
465 luaA_image_draw_pixel(lua_State *L)
467 size_t len;
468 color_t color;
469 color_init_cookie_t cookie;
470 image_t *image = luaA_checkudata(L, 1, &image_class);
471 int x = luaL_checkint(L, 2);
472 int y = luaL_checkint(L, 3);
473 const char *buf = luaL_checklstring(L, 4, &len);
475 cookie = color_init_unchecked(&color, buf, len);
476 imlib_context_set_image(image->image);
477 color_init_reply(cookie);
479 if((x > imlib_image_get_width()) || (y > imlib_image_get_height()))
480 return 0;
482 imlib_context_set_color(color.red, color.green, color.blue, color.alpha);
483 imlib_image_draw_pixel(x, y, 1);
484 image->isupdated = false;
485 return 0;
488 /** Draw a line in an image
489 * \param L The Lua VM state
490 * \luastack
491 * \lvalue An image.
492 * \lparam The x1 coordinate of the line to draw
493 * \lparam The y1 coordinate of the line to draw
494 * \lparam The x2 coordinate of the line to draw
495 * \lparam The y2 coordinate of the line to draw
496 * \lparam The color to draw the line in
498 static int
499 luaA_image_draw_line(lua_State *L)
501 size_t len;
502 color_t color;
503 color_init_cookie_t cookie;
504 image_t *image = luaA_checkudata(L, 1, &image_class);
505 int x1 = luaL_checkint(L, 2);
506 int y1 = luaL_checkint(L, 3);
507 int x2 = luaL_checkint(L, 4);
508 int y2 = luaL_checkint(L, 5);
509 const char *buf = luaL_checklstring(L, 6, &len);
511 cookie = color_init_unchecked(&color, buf, len);
512 imlib_context_set_image(image->image);
513 color_init_reply(cookie);
515 imlib_context_set_color(color.red, color.green, color.blue, color.alpha);
516 imlib_image_draw_line(x1, y1, x2, y2, 0);
517 image->isupdated = false;
518 return 0;
521 /** Draw a rectangle in an image
522 * \param L The Lua VM state
523 * \luastack
524 * \lvalue An image.
525 * \lparam The x coordinate of the rectangles top left corner
526 * \lparam The y coordinate of the rectangles top left corner
527 * \lparam The width of the rectangle
528 * \lparam The height of the rectangle
529 * \lparam True if the rectangle should be filled, False otherwise
530 * \lparam The color to draw the rectangle in
532 static int
533 luaA_image_draw_rectangle(lua_State *L)
535 size_t len;
536 color_t color;
537 color_init_cookie_t cookie;
538 image_t *image = luaA_checkudata(L, 1, &image_class);
539 int x = luaL_checkint(L, 2);
540 int y = luaL_checkint(L, 3);
541 int width = luaL_checkint(L, 4);
542 int height = luaL_checkint(L, 5);
543 int fill = luaA_checkboolean(L, 6);
544 const char *buf = luaL_checklstring(L, 7, &len);
546 cookie = color_init_unchecked(&color, buf, len);
547 imlib_context_set_image(image->image);
548 color_init_reply(cookie);
550 imlib_context_set_color(color.red, color.green, color.blue, color.alpha);
551 if(!fill)
552 imlib_image_draw_rectangle(x, y, width, height);
553 else
554 imlib_image_fill_rectangle(x, y, width, height);
555 image->isupdated = false;
556 return 0;
559 /** Convert a table to a color range and set it as current color range.
560 * \param L The Lua VM state.
561 * \param ud The index of the table.
562 * \return A color range that you are responsible to free.
564 static Imlib_Color_Range
565 luaA_table_to_color_range(lua_State *L, int ud)
567 Imlib_Color_Range range = imlib_create_color_range();
569 imlib_context_set_color_range(range);
571 for(size_t i = 1; i <= lua_objlen(L, ud); i++)
573 /* get t[i] */
574 lua_pushnumber(L, i);
575 lua_gettable(L, ud);
577 size_t len;
578 const char *colstr = lua_tolstring(L, -1, &len);
580 if(colstr)
582 color_t color;
584 color_init_cookie_t cookie = color_init_unchecked(&color, colstr, len);
586 /* get value with colstr as key in table */
587 lua_pushvalue(L, -1);
588 lua_gettable(L, ud);
590 /* convert the distance, if any, to number, or set 1 */
591 int distance = lua_tonumber(L, -1);
592 /* remove distance */
593 lua_pop(L, 1);
595 color_init_reply(cookie);
597 imlib_context_set_color(color.red, color.green, color.blue, color.alpha);
599 imlib_add_color_to_color_range(distance);
602 /* remove color string (value) */
603 lua_pop(L, 1);
606 return range;
609 /** Draw a rectangle in an image with gradient color.
610 * \param L The Lua VM state.
611 * \return The number of elements pushed on stack.
612 * \luastack
613 * \lvalue An image.
614 * \lparam The x coordinate of the rectangles top left corner.
615 * \lparam The y coordinate of the rectangles top left corner.
616 * \lparam The width of the rectangle.
617 * \lparam The height of the rectangle.
618 * \lparam A table with the color to draw the rectangle. You can specified the
619 * color distance from the previous one by setting t[color] = distance.
620 * \lparam The angle of gradient.
622 static int
623 luaA_image_draw_rectangle_gradient(lua_State *L)
625 image_t *image = luaA_checkudata(L, 1, &image_class);
626 int x = luaL_checkint(L, 2);
627 int y = luaL_checkint(L, 3);
628 int width = luaL_checkint(L, 4);
629 int height = luaL_checkint(L, 5);
630 luaA_checktable(L, 6);
631 double angle = luaL_checknumber(L, 7);
633 imlib_context_set_image(image->image);
635 luaA_table_to_color_range(L, 6);
637 imlib_image_fill_color_range_rectangle(x, y, width, height, angle);
639 imlib_free_color_range();
641 image->isupdated = false;
643 return 0;
646 /** Draw a circle in an image
647 * \param L The Lua VM state
648 * \luastack
649 * \lvalue An image.
650 * \lparam The x coordinate of the center of the circle
651 * \lparam The y coordinate of the center of the circle
652 * \lparam The horizontal amplitude (width)
653 * \lparam The vertical amplitude (height)
654 * \lparam True if the circle should be filled, False otherwise
655 * \lparam The color to draw the circle in
657 static int
658 luaA_image_draw_circle(lua_State *L)
660 size_t len;
661 color_t color;
662 color_init_cookie_t cookie;
663 image_t *image = luaA_checkudata(L, 1, &image_class);
664 int x = luaL_checkint(L, 2);
665 int y = luaL_checkint(L, 3);
666 int ah = luaL_checkint(L, 4);
667 int av = luaL_checkint(L, 5);
668 int fill = luaA_checkboolean(L, 6);
669 const char *buf = luaL_checklstring(L, 7, &len);
671 cookie = color_init_unchecked(&color, buf, len);
672 imlib_context_set_image(image->image);
673 color_init_reply(cookie);
675 imlib_context_set_color(color.red, color.green, color.blue, color.alpha);
676 if(!fill)
677 imlib_image_draw_ellipse(x, y, ah, av);
678 else
679 imlib_image_fill_ellipse(x, y, ah, av);
680 image->isupdated = false;
681 return 0;
684 /** Saves the image to the given path. The file extension (e.g. .png or .jpg)
685 * will affect the output format.
686 * \param L The Lua VM state.
687 * \return The number of elements pushed on stack.
688 * \luastack
689 * \lvalue An image.
690 * \lparam The image path.
692 static int
693 luaA_image_save(lua_State *L)
695 image_t *image = luaA_checkudata(L, 1, &image_class);
696 const char *path = luaL_checkstring(L, 2);
697 Imlib_Load_Error err;
699 imlib_context_set_image(image->image);
700 imlib_save_image_with_error_return(path, &err);
702 if(err != IMLIB_LOAD_ERROR_NONE)
703 warn("cannot save image %s: %s", path, image_imlib_load_strerror(err));
705 return 0;
708 /** Insert one image into another.
709 * \param L The Lua VM state.
710 * \return The number of elements pushed on stack.
711 * \luastack
712 * \lvalue An image.
713 * \lparam The image to insert.
714 * \lparam The X offset of the image to insert (optional).
715 * \lparam The Y offset of the image to insert (optional).
716 * \lparam The horizontal offset of the upper right image corner (optional).
717 * \lparam The vertical offset of the upper right image corner (optional).
718 * \lparam The horizontal offset of the lower left image corner (optional).
719 * \lparam The vertical offset of the lower left image corner (optional).
720 * \lparam The X coordinate of the source rectangle (optional).
721 * \lparam The Y coordinate of the source rectangle (optional).
722 * \lparam The width of the source rectangle (optional).
723 * \lparam The height of the source rectangle (optional).
725 static int
726 luaA_image_insert(lua_State *L)
728 image_t *image_target = luaA_checkudata(L, 1, &image_class);
729 image_t *image_source = luaA_checkudata(L, 2, &image_class);
730 int xoff = luaL_optnumber(L, 3, 0);
731 int yoff = luaL_optnumber(L, 4, 0);
733 int xsrc = luaL_optnumber(L, 5, 0);
734 int ysrc = luaL_optnumber(L, 6, 0);
735 int wsrc = luaL_optnumber(L, 7, image_getwidth(image_source));
736 int hsrc = luaL_optnumber(L, 8, image_getheight(image_source));
738 int hxoff = luaL_optnumber(L, 9, image_getwidth(image_source));
739 int hyoff = luaL_optnumber(L, 10, 0);
741 int vxoff = luaL_optnumber(L, 11, 0);
742 int vyoff = luaL_optnumber(L, 12, image_getheight(image_source));
744 imlib_context_set_image(image_target->image);
746 imlib_blend_image_onto_image_skewed(image_source->image, 0,
747 /* source rectangle */
748 xsrc, ysrc, wsrc, hsrc,
749 /* position of the source image in the target image */
750 xoff, yoff,
751 /* axis offsets for the source image, (w|0|0|h)
752 * is the default */
753 hxoff, hyoff, vxoff, vyoff);
755 image_target->isupdated = false;
757 return 0;
760 static int
761 luaA_image_get_width(lua_State *L, image_t *image)
763 lua_pushnumber(L, image_getwidth(image));
764 return 1;
767 static int
768 luaA_image_get_height(lua_State *L, image_t *image)
770 lua_pushnumber(L, image_getheight(image));
771 return 1;
774 static int
775 luaA_image_get_alpha(lua_State *L, image_t *image)
777 imlib_context_set_image(image->image);
778 lua_pushboolean(L, imlib_image_has_alpha());
779 return 1;
782 void
783 image_class_setup(lua_State *L)
785 static const struct luaL_reg image_methods[] =
787 LUA_CLASS_METHODS(image)
788 { "__call", luaA_image_new },
789 { "argb32", luaA_image_argb32_new },
790 { NULL, NULL }
793 static const struct luaL_reg image_meta[] =
795 LUA_OBJECT_META(image)
796 LUA_CLASS_META
797 { "rotate", luaA_image_rotate },
798 { "orientate", luaA_image_orientate },
799 { "crop", luaA_image_crop },
800 { "crop_and_scale", luaA_image_crop_and_scale },
801 { "save", luaA_image_save },
802 { "insert", luaA_image_insert },
803 /* draw on images, whee! */
804 { "draw_pixel", luaA_image_draw_pixel },
805 { "draw_line", luaA_image_draw_line },
806 { "draw_rectangle", luaA_image_draw_rectangle },
807 { "draw_rectangle_gradient", luaA_image_draw_rectangle_gradient },
808 { "draw_circle", luaA_image_draw_circle },
809 { "__gc", luaA_image_gc },
810 { NULL, NULL }
813 luaA_class_setup(L, &image_class, "image", (lua_class_allocator_t) image_new,
814 luaA_class_index_miss_property, luaA_class_newindex_miss_property,
815 image_methods, image_meta);
816 luaA_class_add_property(&image_class, A_TK_WIDTH,
817 NULL,
818 (lua_class_propfunc_t) luaA_image_get_width,
819 NULL);
820 luaA_class_add_property(&image_class, A_TK_HEIGHT,
821 NULL,
822 (lua_class_propfunc_t) luaA_image_get_height,
823 NULL);
824 luaA_class_add_property(&image_class, A_TK_ALPHA,
825 NULL,
826 (lua_class_propfunc_t) luaA_image_get_alpha,
827 NULL);
830 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80