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>
26 #include "globalconf.h"
29 #include "common/luaobject.h"
38 /** Flag telling if the image is up to date or needs computing before
43 LUA_OBJECT_FUNCS(image_class
, image_t
, image
)
46 luaA_image_gc(lua_State
*L
)
48 image_t
*p
= luaA_checkudata(L
, 1, &image_class
);
49 imlib_context_set_image(p
->image
);
52 return luaA_object_gc(L
);
56 image_imlib_load_strerror(Imlib_Load_Error 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";
96 * \param image The image.
97 * \return The image width in pixel.
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.
122 image_getdata(image_t
*image
)
128 #if AWESOME_IS_BIG_ENDIAN
129 const int index_a
= 0, index_r
= 1, index_g
= 2, index_b
= 3;
131 const int index_a
= 3, index_r
= 2, index_g
= 1, index_b
= 0;
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;
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
++)
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
192 image_to_1bit_pixmap(image_t
*image
, xcb_drawable_t d
)
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
);
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
)
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
;
247 /** Load an image from filename.
248 * \param filename The image file to load.
249 * \return 1 if image is loaded and on stack, 0 otherwise.
252 image_new_from_file(const char *filename
)
255 Imlib_Load_Error e
= IMLIB_LOAD_ERROR_NONE
;
261 if(!(imimage
= imlib_load_image_with_error_return(filename
, &e
)))
263 warn("cannot load image %s: %s", filename
, image_imlib_load_strerror(e
));
267 image
= image_new(globalconf
.L
);
268 image
->image
= imimage
;
273 /** Create a new image object.
274 * \param L The Lua stack.
275 * \return The number of elements pushed on stack.
277 * \lparam The image path.
278 * \lreturn An image object.
281 luaA_image_new(lua_State
*L
)
283 const char *filename
;
285 if((filename
= lua_tostring(L
, 2)))
286 return image_new_from_file(filename
);
290 /** Create a new image object from ARGB32 data.
291 * \param L The Lua stack.
292 * \return The number of elements pushed on stack.
294 * \lparam The image width.
295 * \lparam The image height.
296 * \lparam The image data as a string in ARGB32 format, or nil to create an
298 * \lreturn An image object.
301 luaA_image_argb32_new(lua_State
*L
)
304 unsigned int width
= luaL_checknumber(L
, 1);
305 unsigned int height
= luaL_checknumber(L
, 2);
308 luaL_error(L
, "image.argb32() called with zero width");
310 luaL_error(L
, "image.argb32() called with zero height");
314 uint32_t *data
= p_new(uint32_t, width
* height
);
315 return image_new_from_argb32(width
, height
, data
);
318 const char *data
= luaL_checklstring(L
, 3, &len
);
320 if(width
* height
* 4 != len
)
321 luaL_error(L
, "string size does not match image size");
323 return image_new_from_argb32(width
, height
, (uint32_t *) data
);
326 /** Performs 90 degree rotations on the current image. Passing 0 orientation
327 * does not rotate, 1 rotates clockwise by 90 degree, 2, rotates clockwise by
328 * 180 degrees, 3 rotates clockwise by 270 degrees.
329 * \param L The Lua VM state.
330 * \return The number of elements pushed on stack.
333 * \lparam The rotation to perform.
336 luaA_image_orientate(lua_State
*L
)
338 image_t
*image
= luaA_checkudata(L
, 1, &image_class
);
339 int orientation
= luaL_checknumber(L
, 2);
341 imlib_context_set_image(image
->image
);
342 imlib_image_orientate(orientation
);
344 image
->isupdated
= false;
349 /** Rotate an image with specified angle radians and return a new image.
350 * \param L The Lua VM state.
351 * \return The number of elements pushed on stack.
354 * \lparam The angle in radians.
355 * \lreturn A rotated image.
358 luaA_image_rotate(lua_State
*L
)
360 image_t
*image
= luaA_checkudata(L
, 1, &image_class
), *new;
361 double angle
= luaL_checknumber(L
, 2);
365 imlib_context_set_image(image
->image
);
366 new->image
= imlib_create_rotated_image(angle
);
371 /** Crop an image to the given rectangle.
372 * \return The number of elements pushed on stack.
375 * \lparam The top left x coordinate of the rectangle.
376 * \lparam The top left y coordinate of the rectangle.
377 * \lparam The width of the rectangle.
378 * \lparam The height of the rectangle.
379 * \lreturn A cropped image.
382 luaA_image_crop(lua_State
*L
)
384 image_t
*image
= luaA_checkudata(L
, 1, &image_class
), *new;
385 int x
= luaL_checkint(L
, 2);
386 int y
= luaL_checkint(L
, 3);
387 int w
= luaL_checkint(L
, 4);
388 int h
= luaL_checkint(L
, 5);
392 imlib_context_set_image(image
->image
);
393 new->image
= imlib_create_cropped_image(x
, y
, w
, h
);
398 /** Crop the image to the given rectangle and scales it.
399 * \param L The Lua VM state.
400 * \return The number of elements pushed on stack.
403 * \lparam The top left x coordinate of the source rectangle.
404 * \lparam The top left y coordinate of the source rectangle.
405 * \lparam The width of the source rectangle.
406 * \lparam The height of the source rectangle.
407 * \lparam The width of the destination rectangle.
408 * \lparam The height of the destination rectangle.
409 * \lreturn A cropped image.
412 luaA_image_crop_and_scale(lua_State
*L
)
414 image_t
*image
= luaA_checkudata(L
, 1, &image_class
), *new;
415 int source_x
= luaL_checkint(L
, 2);
416 int source_y
= luaL_checkint(L
, 3);
417 int w
= luaL_checkint(L
, 4);
418 int h
= luaL_checkint(L
, 5);
419 int dest_w
= luaL_checkint(L
, 6);
420 int dest_h
= luaL_checkint(L
, 7);
424 imlib_context_set_image(image
->image
);
425 new->image
= imlib_create_cropped_scaled_image(source_x
,
433 /** Draw a pixel in an image
434 * \param L The Lua VM state
437 * \lparam The x coordinate of the pixel to draw
438 * \lparam The y coordinate of the pixel to draw
439 * \lparam The color to draw the pixel in
442 luaA_image_draw_pixel(lua_State
*L
)
446 color_init_cookie_t cookie
;
447 image_t
*image
= luaA_checkudata(L
, 1, &image_class
);
448 int x
= luaL_checkint(L
, 2);
449 int y
= luaL_checkint(L
, 3);
450 const char *buf
= luaL_checklstring(L
, 4, &len
);
452 cookie
= color_init_unchecked(&color
, buf
, len
);
453 imlib_context_set_image(image
->image
);
454 color_init_reply(cookie
);
456 if((x
> imlib_image_get_width()) || (y
> imlib_image_get_height()))
459 imlib_context_set_color(color
.red
, color
.green
, color
.blue
, color
.alpha
);
460 imlib_image_draw_pixel(x
, y
, 1);
461 image
->isupdated
= false;
465 /** Draw a line in an image
466 * \param L The Lua VM state
469 * \lparam The x1 coordinate of the line to draw
470 * \lparam The y1 coordinate of the line to draw
471 * \lparam The x2 coordinate of the line to draw
472 * \lparam The y2 coordinate of the line to draw
473 * \lparam The color to draw the line in
476 luaA_image_draw_line(lua_State
*L
)
480 color_init_cookie_t cookie
;
481 image_t
*image
= luaA_checkudata(L
, 1, &image_class
);
482 int x1
= luaL_checkint(L
, 2);
483 int y1
= luaL_checkint(L
, 3);
484 int x2
= luaL_checkint(L
, 4);
485 int y2
= luaL_checkint(L
, 5);
486 const char *buf
= luaL_checklstring(L
, 6, &len
);
488 cookie
= color_init_unchecked(&color
, buf
, len
);
489 imlib_context_set_image(image
->image
);
490 color_init_reply(cookie
);
492 if((MAX(x1
,x2
) > imlib_image_get_width()) || (MAX(y1
,y2
) > imlib_image_get_height()))
495 imlib_context_set_color(color
.red
, color
.green
, color
.blue
, color
.alpha
);
496 imlib_image_draw_line(x1
, y1
, x2
, y2
, 0);
497 image
->isupdated
= false;
501 /** Draw a rectangle in an image
502 * \param L The Lua VM state
505 * \lparam The x coordinate of the rectangles top left corner
506 * \lparam The y coordinate of the rectangles top left corner
507 * \lparam The width of the rectangle
508 * \lparam The height of the rectangle
509 * \lparam True if the rectangle should be filled, False otherwise
510 * \lparam The color to draw the rectangle in
513 luaA_image_draw_rectangle(lua_State
*L
)
517 color_init_cookie_t cookie
;
518 image_t
*image
= luaA_checkudata(L
, 1, &image_class
);
519 int x
= luaL_checkint(L
, 2);
520 int y
= luaL_checkint(L
, 3);
521 int width
= luaL_checkint(L
, 4);
522 int height
= luaL_checkint(L
, 5);
523 int fill
= luaA_checkboolean(L
, 6);
524 const char *buf
= luaL_checklstring(L
, 7, &len
);
526 cookie
= color_init_unchecked(&color
, buf
, len
);
527 imlib_context_set_image(image
->image
);
528 color_init_reply(cookie
);
530 if((x
> imlib_image_get_width()) || (x
+ width
> imlib_image_get_width()))
532 if((y
> imlib_image_get_height()) || (y
+ height
> imlib_image_get_height()))
535 imlib_context_set_color(color
.red
, color
.green
, color
.blue
, color
.alpha
);
537 imlib_image_draw_rectangle(x
, y
, width
, height
);
539 imlib_image_fill_rectangle(x
, y
, width
, height
);
540 image
->isupdated
= false;
544 /** Convert a table to a color range and set it as current color range.
545 * \param L The Lua VM state.
546 * \param ud The index of the table.
547 * \return A color range that you are responsible to free.
549 static Imlib_Color_Range
550 luaA_table_to_color_range(lua_State
*L
, int ud
)
552 Imlib_Color_Range range
= imlib_create_color_range();
554 imlib_context_set_color_range(range
);
556 for(size_t i
= 1; i
<= lua_objlen(L
, ud
); i
++)
559 lua_pushnumber(L
, i
);
563 const char *colstr
= lua_tolstring(L
, -1, &len
);
569 color_init_cookie_t cookie
= color_init_unchecked(&color
, colstr
, len
);
571 /* get value with colstr as key in table */
572 lua_pushvalue(L
, -1);
575 /* convert the distance, if any, to number, or set 1 */
576 int distance
= lua_tonumber(L
, -1);
577 /* remove distance */
580 color_init_reply(cookie
);
582 imlib_context_set_color(color
.red
, color
.green
, color
.blue
, color
.alpha
);
584 imlib_add_color_to_color_range(distance
);
587 /* remove color string (value) */
594 /** Draw a rectangle in an image with gradient color.
595 * \param L The Lua VM state.
596 * \return The number of elements pushed on stack.
599 * \lparam The x coordinate of the rectangles top left corner.
600 * \lparam The y coordinate of the rectangles top left corner.
601 * \lparam The width of the rectangle.
602 * \lparam The height of the rectangle.
603 * \lparam A table with the color to draw the rectangle. You can specified the
604 * color distance from the previous one by setting t[color] = distance.
605 * \lparam The angle of gradient.
608 luaA_image_draw_rectangle_gradient(lua_State
*L
)
610 image_t
*image
= luaA_checkudata(L
, 1, &image_class
);
611 int x
= luaL_checkint(L
, 2);
612 int y
= luaL_checkint(L
, 3);
613 int width
= luaL_checkint(L
, 4);
614 int height
= luaL_checkint(L
, 5);
615 luaA_checktable(L
, 6);
616 double angle
= luaL_checknumber(L
, 7);
618 if((x
> imlib_image_get_width()) || (x
+ width
> imlib_image_get_width()))
620 if((y
> imlib_image_get_height()) || (y
+ height
> imlib_image_get_height()))
623 imlib_context_set_image(image
->image
);
625 luaA_table_to_color_range(L
, 6);
627 imlib_image_fill_color_range_rectangle(x
, y
, width
, height
, angle
);
629 imlib_free_color_range();
631 image
->isupdated
= false;
636 /** Draw a circle in an image
637 * \param L The Lua VM state
640 * \lparam The x coordinate of the center of the circle
641 * \lparam The y coordinate of the center of the circle
642 * \lparam The horizontal amplitude (width)
643 * \lparam The vertical amplitude (height)
644 * \lparam True if the circle should be filled, False otherwise
645 * \lparam The color to draw the circle in
648 luaA_image_draw_circle(lua_State
*L
)
652 color_init_cookie_t cookie
;
653 image_t
*image
= luaA_checkudata(L
, 1, &image_class
);
654 int x
= luaL_checkint(L
, 2);
655 int y
= luaL_checkint(L
, 3);
656 int ah
= luaL_checkint(L
, 4);
657 int av
= luaL_checkint(L
, 5);
658 int fill
= luaA_checkboolean(L
, 6);
659 const char *buf
= luaL_checklstring(L
, 7, &len
);
661 cookie
= color_init_unchecked(&color
, buf
, len
);
662 imlib_context_set_image(image
->image
);
663 color_init_reply(cookie
);
665 if((x
> imlib_image_get_width()) || (x
+ ah
> imlib_image_get_width()) || (x
- ah
< 0))
667 if((y
> imlib_image_get_height()) || (y
+ av
> imlib_image_get_height()) || (y
- av
< 0))
670 imlib_context_set_color(color
.red
, color
.green
, color
.blue
, color
.alpha
);
672 imlib_image_draw_ellipse(x
, y
, ah
, av
);
674 imlib_image_fill_ellipse(x
, y
, ah
, av
);
675 image
->isupdated
= false;
679 /** Saves the image to the given path. The file extension (e.g. .png or .jpg)
680 * will affect the output format.
681 * \param L The Lua VM state.
682 * \return The number of elements pushed on stack.
685 * \lparam The image path.
688 luaA_image_save(lua_State
*L
)
690 image_t
*image
= luaA_checkudata(L
, 1, &image_class
);
691 const char *path
= luaL_checkstring(L
, 2);
692 Imlib_Load_Error err
;
694 imlib_context_set_image(image
->image
);
695 imlib_save_image_with_error_return(path
, &err
);
697 if(err
!= IMLIB_LOAD_ERROR_NONE
)
698 warn("cannot save image %s: %s", path
, image_imlib_load_strerror(err
));
703 /** Insert one image into another.
704 * \param L The Lua VM state.
705 * \return The number of elements pushed on stack.
708 * \lparam The image to insert.
709 * \lparam The X offset of the image to insert (optional).
710 * \lparam The Y offset of the image to insert (optional).
711 * \lparam The horizontal offset of the upper right image corner (optional).
712 * \lparam The vertical offset of the upper right image corner (optional).
713 * \lparam The horizontal offset of the lower left image corner (optional).
714 * \lparam The vertical offset of the lower left image corner (optional).
715 * \lparam The X coordinate of the source rectangle (optional).
716 * \lparam The Y coordinate of the source rectangle (optional).
717 * \lparam The width of the source rectangle (optional).
718 * \lparam The height of the source rectangle (optional).
721 luaA_image_insert(lua_State
*L
)
723 image_t
*image_target
= luaA_checkudata(L
, 1, &image_class
);
724 image_t
*image_source
= luaA_checkudata(L
, 2, &image_class
);
725 int xoff
= luaL_optnumber(L
, 3, 0);
726 int yoff
= luaL_optnumber(L
, 4, 0);
728 int xsrc
= luaL_optnumber(L
, 5, 0);
729 int ysrc
= luaL_optnumber(L
, 6, 0);
730 int wsrc
= luaL_optnumber(L
, 7, image_getwidth(image_source
));
731 int hsrc
= luaL_optnumber(L
, 8, image_getheight(image_source
));
733 int hxoff
= luaL_optnumber(L
, 9, image_getwidth(image_source
));
734 int hyoff
= luaL_optnumber(L
, 10, 0);
736 int vxoff
= luaL_optnumber(L
, 11, 0);
737 int vyoff
= luaL_optnumber(L
, 12, image_getheight(image_source
));
739 imlib_context_set_image(image_target
->image
);
741 imlib_blend_image_onto_image_skewed(image_source
->image
, 0,
742 /* source rectangle */
743 xsrc
, ysrc
, wsrc
, hsrc
,
744 /* position of the source image in the target image */
746 /* axis offsets for the source image, (w|0|0|h)
748 hxoff
, hyoff
, vxoff
, vyoff
);
750 image_target
->isupdated
= false;
756 luaA_image_get_width(lua_State
*L
, image_t
*image
)
758 lua_pushnumber(L
, image_getwidth(image
));
763 luaA_image_get_height(lua_State
*L
, image_t
*image
)
765 lua_pushnumber(L
, image_getheight(image
));
770 luaA_image_get_alpha(lua_State
*L
, image_t
*image
)
772 imlib_context_set_image(image
->image
);
773 lua_pushboolean(L
, imlib_image_has_alpha());
778 image_class_setup(lua_State
*L
)
780 static const struct luaL_reg image_methods
[] =
782 LUA_CLASS_METHODS(image
)
783 { "__call", luaA_image_new
},
784 { "argb32", luaA_image_argb32_new
},
788 static const struct luaL_reg image_meta
[] =
790 LUA_OBJECT_META(image
)
792 { "rotate", luaA_image_rotate
},
793 { "orientate", luaA_image_orientate
},
794 { "crop", luaA_image_crop
},
795 { "crop_and_scale", luaA_image_crop_and_scale
},
796 { "save", luaA_image_save
},
797 { "insert", luaA_image_insert
},
798 /* draw on images, whee! */
799 { "draw_pixel", luaA_image_draw_pixel
},
800 { "draw_line", luaA_image_draw_line
},
801 { "draw_rectangle", luaA_image_draw_rectangle
},
802 { "draw_rectangle_gradient", luaA_image_draw_rectangle_gradient
},
803 { "draw_circle", luaA_image_draw_circle
},
804 { "__gc", luaA_image_gc
},
808 luaA_class_setup(L
, &image_class
, "image", (lua_class_allocator_t
) image_new
,
809 luaA_class_index_miss_property
, luaA_class_newindex_miss_property
,
810 image_methods
, image_meta
);
811 luaA_class_add_property(&image_class
, A_TK_WIDTH
,
813 (lua_class_propfunc_t
) luaA_image_get_width
,
815 luaA_class_add_property(&image_class
, A_TK_HEIGHT
,
817 (lua_class_propfunc_t
) luaA_image_get_height
,
819 luaA_class_add_property(&image_class
, A_TK_ALPHA
,
821 (lua_class_propfunc_t
) luaA_image_get_alpha
,
825 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80