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>
28 #include "common/luaobject.h"
37 /** Flag telling if the image is up to date or needs computing before
42 LUA_OBJECT_FUNCS(image_class
, image_t
, image
)
45 luaA_image_gc(lua_State
*L
)
47 image_t
*p
= luaA_checkudata(L
, 1, &image_class
);
48 imlib_context_set_image(p
->image
);
51 return luaA_object_gc(L
);
55 image_imlib_load_strerror(Imlib_Load_Error e
)
59 case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST
:
60 return "no such file or directory";
61 case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY
:
62 return "file is a directory";
63 case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ
:
64 return "read permission denied";
65 case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT
:
66 return "no loader for file format";
67 case IMLIB_LOAD_ERROR_PATH_TOO_LONG
:
68 return "path too long";
69 case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT
:
70 return "path component non existant";
71 case IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY
:
72 return "path compoment not a directory";
73 case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE
:
74 return "path points oustide address space";
75 case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS
:
76 return "too many symbolic links";
77 case IMLIB_LOAD_ERROR_OUT_OF_MEMORY
:
78 return "out of memory";
79 case IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS
:
80 return "out of file descriptors";
81 case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE
:
82 return "write permission denied";
83 case IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE
:
84 return "out of disk space";
85 case IMLIB_LOAD_ERROR_UNKNOWN
:
86 return "unknown error, that's really bad";
87 case IMLIB_LOAD_ERROR_NONE
:
88 return "no error, oops";
91 return "unknown error";
95 * \param image The image.
96 * \return The image width in pixel.
99 image_getwidth(image_t
*image
)
101 imlib_context_set_image(image
->image
);
102 return imlib_image_get_width();
105 /** Get image height.
106 * \param image The image.
107 * \return The image height in pixel.
110 image_getheight(image_t
*image
)
112 imlib_context_set_image(image
->image
);
113 return imlib_image_get_height();
116 /** Get the ARGB32 data from an image.
117 * \param image The image.
121 image_getdata(image_t
*image
)
127 #if AWESOME_IS_BIG_ENDIAN
128 const int index_a
= 0, index_r
= 1, index_g
= 2, index_b
= 3;
130 const int index_a
= 3, index_r
= 2, index_g
= 1, index_b
= 0;
136 imlib_context_set_image(image
->image
);
138 data
= imlib_image_get_data_for_reading_only();
140 size
= imlib_image_get_width() * imlib_image_get_height();
142 p_realloc(&image
->data
, size
* 4);
143 dataimg
= image
->data
;
145 for(i
= 0; i
< size
; i
++, dataimg
+= 4)
147 dataimg
[index_a
] = (data
[i
] >> 24) & 0xff; /* A */
148 /* cairo wants pre-multiplied alpha */
149 alpha
= dataimg
[index_a
] / 255.0;
150 dataimg
[index_r
] = ((data
[i
] >> 16) & 0xff) * alpha
; /* R */
151 dataimg
[index_g
] = ((data
[i
] >> 8) & 0xff) * alpha
; /* G */
152 dataimg
[index_b
] = (data
[i
] & 0xff) * alpha
; /* B */
155 image
->isupdated
= true;
162 image_draw_to_1bit_ximage(image_t
*image
, xcb_image_t
*img
)
164 imlib_context_set_image(image
->image
);
166 uint32_t *data
= imlib_image_get_data_for_reading_only();
168 int width
= imlib_image_get_width();
169 int height
= imlib_image_get_height();
171 for(int y
= 0; y
< height
; y
++)
172 for(int x
= 0; x
< width
; x
++)
178 // Sum up all color components ignoring alpha
179 tmp
= (data
[i
] >> 16) & 0xff;
180 tmp
+= (data
[i
] >> 8) & 0xff;
181 tmp
+= data
[i
] & 0xff;
183 pixel
= (tmp
/ 3 < 127) ? 0 : 1;
185 xcb_image_put_pixel(img
, x
, y
, pixel
);
189 // Convert an image to a 1bit pixmap
191 image_to_1bit_pixmap(image_t
*image
, xcb_drawable_t d
)
196 uint16_t width
, height
;
198 width
= image_getwidth(image
);
199 height
= image_getheight(image
);
201 /* Prepare the pixmap and gc */
202 pixmap
= xcb_generate_id(globalconf
.connection
);
203 xcb_create_pixmap(globalconf
.connection
, 1, pixmap
, d
, width
, height
);
205 gc
= xcb_generate_id(globalconf
.connection
);
206 xcb_create_gc(globalconf
.connection
, gc
, pixmap
, 0, NULL
);
208 /* Prepare the image */
209 img
= xcb_image_create_native(globalconf
.connection
, width
, height
,
210 XCB_IMAGE_FORMAT_XY_BITMAP
, 1, NULL
, 0, NULL
);
211 image_draw_to_1bit_ximage(image
, img
);
213 /* Paint the image to the pixmap */
214 xcb_image_put(globalconf
.connection
, pixmap
, gc
, img
, 0, 0, 0);
216 xcb_free_gc(globalconf
.connection
, gc
);
218 xcb_image_destroy(img
);
223 /** Create a new image from ARGB32 data.
224 * \param width The image width.
225 * \param height The image height.
226 * \param data The image data.
227 * \return 1 if an image has been pushed on stack, 0 otherwise.
230 image_new_from_argb32(int width
, int height
, uint32_t *data
)
234 if((imimage
= imlib_create_image_using_copied_data(width
, height
, data
)))
236 imlib_context_set_image(imimage
);
237 imlib_image_set_has_alpha(true);
238 image_t
*image
= image_new(globalconf
.L
);
239 image
->image
= imimage
;
246 /** Load an image from filename.
247 * \param filename The image file to load.
248 * \return 1 if image is loaded and on stack, 0 otherwise.
251 image_new_from_file(const char *filename
)
254 Imlib_Load_Error e
= IMLIB_LOAD_ERROR_NONE
;
260 if(!(imimage
= imlib_load_image_with_error_return(filename
, &e
)))
262 warn("cannot load image %s: %s", filename
, image_imlib_load_strerror(e
));
266 image
= image_new(globalconf
.L
);
267 image
->image
= imimage
;
272 /** Create a new image object.
273 * \param L The Lua stack.
274 * \return The number of elements pushed on stack.
276 * \lparam The image path.
277 * \lreturn An image object.
280 luaA_image_new(lua_State
*L
)
282 const char *filename
;
284 if((filename
= lua_tostring(L
, 2)))
285 return image_new_from_file(filename
);
289 /** Create a new image object from ARGB32 data.
290 * \param L The Lua stack.
291 * \return The number of elements pushed on stack.
293 * \lparam The image width.
294 * \lparam The image height.
295 * \lparam The image data as a string in ARGB32 format, or nil to create an
297 * \lreturn An image object.
300 luaA_image_argb32_new(lua_State
*L
)
303 unsigned int width
= luaL_checknumber(L
, 1);
304 unsigned int height
= luaL_checknumber(L
, 2);
307 luaL_error(L
, "image.argb32() called with zero width");
309 luaL_error(L
, "image.argb32() called with zero height");
313 uint32_t *data
= p_new(uint32_t, width
* height
);
314 return image_new_from_argb32(width
, height
, data
);
317 const char *data
= luaL_checklstring(L
, 3, &len
);
319 if(width
* height
* 4 != len
)
320 luaL_error(L
, "string size does not match image size");
322 return image_new_from_argb32(width
, height
, (uint32_t *) data
);
325 /** Performs 90 degree rotations on the current image. Passing 0 orientation
326 * does not rotate, 1 rotates clockwise by 90 degree, 2, rotates clockwise by
327 * 180 degrees, 3 rotates clockwise by 270 degrees.
328 * \param L The Lua VM state.
329 * \return The number of elements pushed on stack.
332 * \lparam The rotation to perform.
335 luaA_image_orientate(lua_State
*L
)
337 image_t
*image
= luaA_checkudata(L
, 1, &image_class
);
338 int orientation
= luaL_checknumber(L
, 2);
340 imlib_context_set_image(image
->image
);
341 imlib_image_orientate(orientation
);
343 image
->isupdated
= false;
348 /** Rotate an image with specified angle radians and return a new image.
349 * \param L The Lua VM state.
350 * \return The number of elements pushed on stack.
353 * \lparam The angle in radians.
354 * \lreturn A rotated image.
357 luaA_image_rotate(lua_State
*L
)
359 image_t
*image
= luaA_checkudata(L
, 1, &image_class
), *new;
360 double angle
= luaL_checknumber(L
, 2);
364 imlib_context_set_image(image
->image
);
365 new->image
= imlib_create_rotated_image(angle
);
370 /** Crop an image to the given rectangle.
371 * \return The number of elements pushed on stack.
374 * \lparam The top left x coordinate of the rectangle.
375 * \lparam The top left y coordinate of the rectangle.
376 * \lparam The width of the rectangle.
377 * \lparam The height of the rectangle.
378 * \lreturn A cropped image.
381 luaA_image_crop(lua_State
*L
)
383 image_t
*image
= luaA_checkudata(L
, 1, &image_class
), *new;
384 int x
= luaL_checkint(L
, 2);
385 int y
= luaL_checkint(L
, 3);
386 int w
= luaL_checkint(L
, 4);
387 int h
= luaL_checkint(L
, 5);
391 imlib_context_set_image(image
->image
);
392 new->image
= imlib_create_cropped_image(x
, y
, w
, h
);
397 /** Crop the image to the given rectangle and scales it.
398 * \param L The Lua VM state.
399 * \return The number of elements pushed on stack.
402 * \lparam The top left x coordinate of the source rectangle.
403 * \lparam The top left y coordinate of the source rectangle.
404 * \lparam The width of the source rectangle.
405 * \lparam The height of the source rectangle.
406 * \lparam The width of the destination rectangle.
407 * \lparam The height of the destination rectangle.
408 * \lreturn A cropped image.
411 luaA_image_crop_and_scale(lua_State
*L
)
413 image_t
*image
= luaA_checkudata(L
, 1, &image_class
), *new;
414 int source_x
= luaL_checkint(L
, 2);
415 int source_y
= luaL_checkint(L
, 3);
416 int w
= luaL_checkint(L
, 4);
417 int h
= luaL_checkint(L
, 5);
418 int dest_w
= luaL_checkint(L
, 6);
419 int dest_h
= luaL_checkint(L
, 7);
423 imlib_context_set_image(image
->image
);
424 new->image
= imlib_create_cropped_scaled_image(source_x
,
432 /** Draw a pixel in an image
433 * \param L The Lua VM state
436 * \lparam The x coordinate of the pixel to draw
437 * \lparam The y coordinate of the pixel to draw
438 * \lparam The color to draw the pixel in
441 luaA_image_draw_pixel(lua_State
*L
)
445 color_init_cookie_t cookie
;
446 image_t
*image
= luaA_checkudata(L
, 1, &image_class
);
447 int x
= luaL_checkint(L
, 2);
448 int y
= luaL_checkint(L
, 3);
449 const char *buf
= luaL_checklstring(L
, 4, &len
);
451 cookie
= color_init_unchecked(&color
, buf
, len
);
452 imlib_context_set_image(image
->image
);
453 color_init_reply(cookie
);
455 if((x
> imlib_image_get_width()) || (y
> imlib_image_get_height()))
458 imlib_context_set_color(color
.red
, color
.green
, color
.blue
, color
.alpha
);
459 imlib_image_draw_pixel(x
, y
, 1);
460 image
->isupdated
= false;
464 /** Draw a line in an image
465 * \param L The Lua VM state
468 * \lparam The x1 coordinate of the line to draw
469 * \lparam The y1 coordinate of the line to draw
470 * \lparam The x2 coordinate of the line to draw
471 * \lparam The y2 coordinate of the line to draw
472 * \lparam The color to draw the line in
475 luaA_image_draw_line(lua_State
*L
)
479 color_init_cookie_t cookie
;
480 image_t
*image
= luaA_checkudata(L
, 1, &image_class
);
481 int x1
= luaL_checkint(L
, 2);
482 int y1
= luaL_checkint(L
, 3);
483 int x2
= luaL_checkint(L
, 4);
484 int y2
= luaL_checkint(L
, 5);
485 const char *buf
= luaL_checklstring(L
, 6, &len
);
487 cookie
= color_init_unchecked(&color
, buf
, len
);
488 imlib_context_set_image(image
->image
);
489 color_init_reply(cookie
);
491 if((MAX(x1
,x2
) > imlib_image_get_width()) || (MAX(y1
,y2
) > imlib_image_get_height()))
494 imlib_context_set_color(color
.red
, color
.green
, color
.blue
, color
.alpha
);
495 imlib_image_draw_line(x1
, y1
, x2
, y2
, 0);
496 image
->isupdated
= false;
500 /** Draw a rectangle in an image
501 * \param L The Lua VM state
504 * \lparam The x coordinate of the rectangles top left corner
505 * \lparam The y coordinate of the rectangles top left corner
506 * \lparam The width of the rectangle
507 * \lparam The height of the rectangle
508 * \lparam True if the rectangle should be filled, False otherwise
509 * \lparam The color to draw the rectangle in
512 luaA_image_draw_rectangle(lua_State
*L
)
516 color_init_cookie_t cookie
;
517 image_t
*image
= luaA_checkudata(L
, 1, &image_class
);
518 int x
= luaL_checkint(L
, 2);
519 int y
= luaL_checkint(L
, 3);
520 int width
= luaL_checkint(L
, 4);
521 int height
= luaL_checkint(L
, 5);
522 int fill
= luaA_checkboolean(L
, 6);
523 const char *buf
= luaL_checklstring(L
, 7, &len
);
525 cookie
= color_init_unchecked(&color
, buf
, len
);
526 imlib_context_set_image(image
->image
);
527 color_init_reply(cookie
);
529 if((x
> imlib_image_get_width()) || (x
+ width
> imlib_image_get_width()))
531 if((y
> imlib_image_get_height()) || (y
+ height
> imlib_image_get_height()))
534 imlib_context_set_color(color
.red
, color
.green
, color
.blue
, color
.alpha
);
536 imlib_image_draw_rectangle(x
, y
, width
, height
);
538 imlib_image_fill_rectangle(x
, y
, width
, height
);
539 image
->isupdated
= false;
543 /** Convert a table to a color range and set it as current color range.
544 * \param L The Lua VM state.
545 * \param ud The index of the table.
546 * \return A color range that you are responsible to free.
548 static Imlib_Color_Range
549 luaA_table_to_color_range(lua_State
*L
, int ud
)
551 Imlib_Color_Range range
= imlib_create_color_range();
553 imlib_context_set_color_range(range
);
555 for(size_t i
= 1; i
<= lua_objlen(L
, ud
); i
++)
558 lua_pushnumber(L
, i
);
562 const char *colstr
= lua_tolstring(L
, -1, &len
);
568 color_init_cookie_t cookie
= color_init_unchecked(&color
, colstr
, len
);
570 /* get value with colstr as key in table */
571 lua_pushvalue(L
, -1);
574 /* convert the distance, if any, to number, or set 1 */
575 int distance
= lua_tonumber(L
, -1);
576 /* remove distance */
579 color_init_reply(cookie
);
581 imlib_context_set_color(color
.red
, color
.green
, color
.blue
, color
.alpha
);
583 imlib_add_color_to_color_range(distance
);
586 /* remove color string (value) */
593 /** Draw a rectangle in an image with gradient color.
594 * \param L The Lua VM state.
595 * \return The number of elements pushed on stack.
598 * \lparam The x coordinate of the rectangles top left corner.
599 * \lparam The y coordinate of the rectangles top left corner.
600 * \lparam The width of the rectangle.
601 * \lparam The height of the rectangle.
602 * \lparam A table with the color to draw the rectangle. You can specified the
603 * color distance from the previous one by setting t[color] = distance.
604 * \lparam The angle of gradient.
607 luaA_image_draw_rectangle_gradient(lua_State
*L
)
609 image_t
*image
= luaA_checkudata(L
, 1, &image_class
);
610 int x
= luaL_checkint(L
, 2);
611 int y
= luaL_checkint(L
, 3);
612 int width
= luaL_checkint(L
, 4);
613 int height
= luaL_checkint(L
, 5);
614 luaA_checktable(L
, 6);
615 double angle
= luaL_checknumber(L
, 7);
617 if((x
> imlib_image_get_width()) || (x
+ width
> imlib_image_get_width()))
619 if((y
> imlib_image_get_height()) || (y
+ height
> imlib_image_get_height()))
622 imlib_context_set_image(image
->image
);
624 luaA_table_to_color_range(L
, 6);
626 imlib_image_fill_color_range_rectangle(x
, y
, width
, height
, angle
);
628 imlib_free_color_range();
630 image
->isupdated
= false;
635 /** Draw a circle in an image
636 * \param L The Lua VM state
639 * \lparam The x coordinate of the center of the circle
640 * \lparam The y coordinate of the center of the circle
641 * \lparam The horizontal amplitude (width)
642 * \lparam The vertical amplitude (height)
643 * \lparam True if the circle should be filled, False otherwise
644 * \lparam The color to draw the circle in
647 luaA_image_draw_circle(lua_State
*L
)
651 color_init_cookie_t cookie
;
652 image_t
*image
= luaA_checkudata(L
, 1, &image_class
);
653 int x
= luaL_checkint(L
, 2);
654 int y
= luaL_checkint(L
, 3);
655 int ah
= luaL_checkint(L
, 4);
656 int av
= luaL_checkint(L
, 5);
657 int fill
= luaA_checkboolean(L
, 6);
658 const char *buf
= luaL_checklstring(L
, 7, &len
);
660 cookie
= color_init_unchecked(&color
, buf
, len
);
661 imlib_context_set_image(image
->image
);
662 color_init_reply(cookie
);
664 if((x
> imlib_image_get_width()) || (x
+ ah
> imlib_image_get_width()) || (x
- ah
< 0))
666 if((y
> imlib_image_get_height()) || (y
+ av
> imlib_image_get_height()) || (y
- av
< 0))
669 imlib_context_set_color(color
.red
, color
.green
, color
.blue
, color
.alpha
);
671 imlib_image_draw_ellipse(x
, y
, ah
, av
);
673 imlib_image_fill_ellipse(x
, y
, ah
, av
);
674 image
->isupdated
= false;
678 /** Saves the image to the given path. The file extension (e.g. .png or .jpg)
679 * will affect the output format.
680 * \param L The Lua VM state.
681 * \return The number of elements pushed on stack.
684 * \lparam The image path.
687 luaA_image_save(lua_State
*L
)
689 image_t
*image
= luaA_checkudata(L
, 1, &image_class
);
690 const char *path
= luaL_checkstring(L
, 2);
691 Imlib_Load_Error err
;
693 imlib_context_set_image(image
->image
);
694 imlib_save_image_with_error_return(path
, &err
);
696 if(err
!= IMLIB_LOAD_ERROR_NONE
)
697 warn("cannot save image %s: %s", path
, image_imlib_load_strerror(err
));
702 /** Insert one image into another.
703 * \param L The Lua VM state.
704 * \return The number of elements pushed on stack.
707 * \lparam The image to insert.
708 * \lparam The X offset of the image to insert (optional).
709 * \lparam The Y offset of the image to insert (optional).
710 * \lparam The horizontal offset of the upper right image corner (optional).
711 * \lparam The vertical offset of the upper right image corner (optional).
712 * \lparam The horizontal offset of the lower left image corner (optional).
713 * \lparam The vertical offset of the lower left image corner (optional).
714 * \lparam The X coordinate of the source rectangle (optional).
715 * \lparam The Y coordinate of the source rectangle (optional).
716 * \lparam The width of the source rectangle (optional).
717 * \lparam The height of the source rectangle (optional).
720 luaA_image_insert(lua_State
*L
)
722 image_t
*image_target
= luaA_checkudata(L
, 1, &image_class
);
723 image_t
*image_source
= luaA_checkudata(L
, 2, &image_class
);
724 int xoff
= luaL_optnumber(L
, 3, 0);
725 int yoff
= luaL_optnumber(L
, 4, 0);
727 int xsrc
= luaL_optnumber(L
, 5, 0);
728 int ysrc
= luaL_optnumber(L
, 6, 0);
729 int wsrc
= luaL_optnumber(L
, 7, image_getwidth(image_source
));
730 int hsrc
= luaL_optnumber(L
, 8, image_getheight(image_source
));
732 int hxoff
= luaL_optnumber(L
, 9, image_getwidth(image_source
));
733 int hyoff
= luaL_optnumber(L
, 10, 0);
735 int vxoff
= luaL_optnumber(L
, 11, 0);
736 int vyoff
= luaL_optnumber(L
, 12, image_getheight(image_source
));
738 imlib_context_set_image(image_target
->image
);
740 imlib_blend_image_onto_image_skewed(image_source
->image
, 0,
741 /* source rectangle */
742 xsrc
, ysrc
, wsrc
, hsrc
,
743 /* position of the source image in the target image */
745 /* axis offsets for the source image, (w|0|0|h)
747 hxoff
, hyoff
, vxoff
, vyoff
);
749 image_target
->isupdated
= false;
755 luaA_image_get_width(lua_State
*L
, image_t
*image
)
757 lua_pushnumber(L
, image_getwidth(image
));
762 luaA_image_get_height(lua_State
*L
, image_t
*image
)
764 lua_pushnumber(L
, image_getheight(image
));
769 luaA_image_get_alpha(lua_State
*L
, image_t
*image
)
771 imlib_context_set_image(image
->image
);
772 lua_pushboolean(L
, imlib_image_has_alpha());
777 image_class_setup(lua_State
*L
)
779 static const struct luaL_reg image_methods
[] =
781 LUA_CLASS_METHODS(image
)
782 { "__call", luaA_image_new
},
783 { "argb32", luaA_image_argb32_new
},
787 static const struct luaL_reg image_meta
[] =
789 LUA_OBJECT_META(image
)
791 { "rotate", luaA_image_rotate
},
792 { "orientate", luaA_image_orientate
},
793 { "crop", luaA_image_crop
},
794 { "crop_and_scale", luaA_image_crop_and_scale
},
795 { "save", luaA_image_save
},
796 { "insert", luaA_image_insert
},
797 /* draw on images, whee! */
798 { "draw_pixel", luaA_image_draw_pixel
},
799 { "draw_line", luaA_image_draw_line
},
800 { "draw_rectangle", luaA_image_draw_rectangle
},
801 { "draw_rectangle_gradient", luaA_image_draw_rectangle_gradient
},
802 { "draw_circle", luaA_image_draw_circle
},
803 { "__gc", luaA_image_gc
},
807 luaA_class_setup(L
, &image_class
, "image", (lua_class_allocator_t
) image_new
,
808 luaA_class_index_miss_property
, luaA_class_newindex_miss_property
,
809 image_methods
, image_meta
);
810 luaA_class_add_property(&image_class
, A_TK_WIDTH
,
812 (lua_class_propfunc_t
) luaA_image_get_width
,
814 luaA_class_add_property(&image_class
, A_TK_HEIGHT
,
816 (lua_class_propfunc_t
) luaA_image_get_height
,
818 luaA_class_add_property(&image_class
, A_TK_ALPHA
,
820 (lua_class_propfunc_t
) luaA_image_get_alpha
,
824 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80