Framebuffer rotation patch
RFC 1/1 Framebuffer rotation patch
Hello
Sending a preliminary framebuffer rotation patch.
You can use videotest to see 4 tiles rotated from the same bitmap data.
Known issues:
- font glyphs and terminal do not rotate properly
- no accelerated blitters for rotated modes, at least the 1bit blitter should work
To be done
- split out signed rectangle patch that changes graphics coordinates from unsigned to signed
- make up some naming scheme and rename functions and macros accordingly
- make up some acceptable way to specify framebnuffer rotation in the environment like gfxmode
Thanks
Michal
commands/videotest.c +143 -5
@@ -24,6 +24,105 @@#include <grub/font.h> #include <grub/term.h> #include <grub/command.h> +#include <grub/fbtran.h> +#include <grub/fbfill.h> /*for some reason render target type is defined there */ +#include <grub/bitmap.h> + +char leaf_data[] = {0x00 ,0x0f ,0xe0 ,0x00 , +0x00 ,0x7f ,0xfc ,0x00 , +0x01 ,0xff ,0xff ,0x00 , +0x03 ,0xff ,0xff ,0x80 , + +0x07 ,0xff ,0xff ,0xe0 , +0x0f ,0xff ,0xff ,0xf0 , +0x1f ,0xff ,0xff ,0xf0 , +0x3f ,0xff ,0xff ,0xf8 , + +0x3f ,0xff ,0xff ,0xf8 , +0x7f ,0xff ,0xff ,0xfc , +0x7f ,0xff ,0xff ,0xfc , +0xff ,0xff ,0xff ,0xfe , + +0xff ,0xff ,0xff ,0xfe , +0xff ,0xff ,0xff ,0xfe , +0xff ,0xff ,0xff ,0xfe , +0xff ,0xff ,0xff ,0xfe , + +0xff ,0xff ,0xff ,0xfe , +0xff ,0xff ,0xff ,0xfe , +0xff ,0xff ,0xff ,0xfe , +0xff ,0xff ,0xff ,0xfe , + +0xff ,0xff ,0xff ,0xfc , +0xff ,0xff ,0xff ,0xfc , +0xff ,0xff ,0xff ,0xf8 , +0xff ,0xff ,0xff ,0xf8 , + +0xff ,0xff ,0xff ,0xf0 , +0xff ,0xff ,0xff ,0xe0 , +0xff ,0xff ,0xff ,0xc0 , +0xff ,0xff ,0xff ,0x80 , + +0xff ,0xff ,0xff ,0x00 , +0xff ,0xff ,0xfc ,0x00 , +0xff ,0xff ,0xe0 ,0x00 , +0xff ,0x00 ,0x00 ,0x00 }; +#define LEAF_SIZE 32 + +struct grub_video_bitmap leaves[4 ]; + +static void init_leaves (void ) +{ + + leaves[0 ].mode_info.width =LEAF_SIZE ; + leaves[0 ].mode_info.height =LEAF_SIZE ; + leaves[0 ].mode_info.transform =FB_TRAN_EAST ; + leaves[0 ].mode_info.mode_type = + (1 <<GRUB_VIDEO_MODE_TYPE_DEPTH_POS ) + |GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP ; + leaves[0 ].mode_info.blit_format =GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED ; + leaves[0 ].mode_info.bpp =1 ; + leaves[0 ].mode_info.bytes_per_pixel =0 ; + leaves[0 ].mode_info.pitch =LEAF_SIZE ; + leaves[0 ].mode_info.number_of_colors =2 ; + leaves[0 ].mode_info.bg_red =128 ; + leaves[0 ].mode_info.fg_red =255 ; + leaves[0 ].mode_info.bg_green =128 ; + leaves[0 ].mode_info.fg_green =255 ; + leaves[0 ].mode_info.bg_blue =128 ; + leaves[0 ].mode_info.fg_blue =255 ; + leaves[0 ].data = leaf_data; + +grub_memcpy (&leaves[1 ], leaves,sizeof (leaves[0 ])); +grub_memcpy (&leaves[2 ], leaves,2 *sizeof (leaves[0 ])); + leaves[1 ].mode_info.transform =FB_TRAN_NORTH ; + leaves[2 ].mode_info.transform =FB_TRAN_WEST ; + leaves[3 ].mode_info.transform =FB_TRAN_SOUTH ; + leaves[0 ].mode_info.fg_red =0 ; + leaves[1 ].mode_info.fg_green =0 ; + leaves[2 ].mode_info.fg_blue =0 ; + leaves[3 ].mode_info.fg_blue =0 ; + leaves[3 ].mode_info.fg_green =0 ; + leaves[3 ].mode_info.fg_red =0 ; +} + +#define BORDER 20 + +static void draw_leaves (void ) +{ +grub_font_t sans; +grub_video_color_t color; + + sans =grub_font_get ("Helvetica Bold 14" ); + color =grub_video_map_rgb (255 ,255 ,255 ); + +grub_video_blit_bitmap (leaves,GRUB_VIDEO_BLIT_REPLACE ,BORDER ,BORDER ,0 ,0 ,LEAF_SIZE ,LEAF_SIZE ); +grub_video_blit_bitmap (leaves +1 ,GRUB_VIDEO_BLIT_REPLACE ,BORDER +LEAF_SIZE ,BORDER ,0 ,0 ,LEAF_SIZE ,LEAF_SIZE ); +grub_video_blit_bitmap (leaves +2 ,GRUB_VIDEO_BLIT_REPLACE ,BORDER +LEAF_SIZE ,BORDER +LEAF_SIZE ,0 ,0 ,LEAF_SIZE ,LEAF_SIZE ); +grub_video_blit_bitmap (leaves +3 ,GRUB_VIDEO_BLIT_REPLACE ,BORDER ,BORDER +LEAF_SIZE ,0 ,0 ,LEAF_SIZE ,LEAF_SIZE ); +grub_font_draw_string ("Leaves" , sans, color,BORDER +LEAF_SIZE /2 ,4 *LEAF_SIZE +BORDER ); + +} static grub_err_t grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)),
@@ -34,10 +133,10 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)),return grub_errno;grub_video_color_t color; -unsigned int x; -unsigned int y; -unsigned int width; -unsigned int height; +int x; +int y; +int width; +int height;int i;grub_font_t sansbig;grub_font_t sans;
@@ -48,9 +147,47 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)),grub_video_color_t palette[16 ];const char *str;int texty; +struct grub_video_fbrender_target * tgt; +grub_video_fb_get_active_render_target (&tgt); +init_leaves ();grub_video_get_viewport (&x, &y, &width, &height); +draw_leaves (); + + tgt->mode_info.transform=FB_TRAN_MIRROR ; +draw_leaves (); + + tgt->mode_info.transform=FB_TRAN_FLIP |FB_TRAN_MIRROR ; +draw_leaves (); + + tgt->mode_info.transform=FB_TRAN_FLIP ; +draw_leaves (); + +grub_getkey (); + + tgt->mode_info.transform=FB_TRAN_NORTH ; + color =grub_video_map_rgb (0 ,0 ,0 ); +grub_video_fill_rect (color,0 ,0 , width, height); +draw_leaves (); + + tgt->mode_info.transform=FB_TRAN_EAST ; +grub_video_set_viewport (x, y, height, width); +draw_leaves (); + + tgt->mode_info.transform=FB_TRAN_SOUTH ; +grub_video_set_viewport (x, y, width, height); +draw_leaves (); + + tgt->mode_info.transform=FB_TRAN_WEST ; +grub_video_set_viewport (x, y, height, width); +draw_leaves (); + + tgt->mode_info.transform=FB_TRAN_NORTH ; +grub_video_set_viewport (x, y, width, height); + +grub_getkey (); +grub_video_create_render_target (&text_layer, width, height,GRUB_VIDEO_MODE_TYPE_RGB |GRUB_VIDEO_MODE_TYPE_ALPHA );
@@ -115,7 +252,8 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)), str ="Unicode test: happy\xE2\x98\xBA \xC2\xA3 5.00" " \xC2\xA1\xCF\x84\xC3\xA4u! " -" \xE2\x84\xA4\xE2\x8A\x87\xE2\x84\x9D" ; +" \xE2\x84\xA4\xE2\x8A\x87\xE2\x84\x9D " +" \343\201\202!" /* hiragana letter a */ ; color =grub_video_map_rgb (128 ,128 ,255 );/* All characters in the string exist in the 'Fixed 20' (10x20) font. */
font/font.c +2 -0
@@ -987,8 +987,10 @@ grub_font_draw_glyph (struct grub_font_glyph *glyph,if (glyph->width ==0 || glyph->height ==0 )return GRUB_ERR_NONE ; +/* TODO: add support for bitmaps to create_bitmap */ glyph_bitmap.mode_info.width = glyph->width; glyph_bitmap.mode_info.height = glyph->height; + glyph_bitmap.mode_info.transform =0 ; glyph_bitmap.mode_info.mode_type = (1 <<GRUB_VIDEO_MODE_TYPE_DEPTH_POS ) |GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP ;
include/grub/fbblit.h +2 -2
@@ -28,7 +28,7 @@ void grub_video_fbblit_replace (struct grub_video_fbblit_info *dst, struct grub_video_fbblit_info *src, int x, int y, int width, int height, - int offset_x, int offset_y); + int offset_x, int offset_y, int transform); void grub_video_fbblit_replace_directN (struct grub_video_fbblit_info *dst,
@@ -94,7 +94,7 @@ void grub_video_fbblit_blend (struct grub_video_fbblit_info *dst, struct grub_video_fbblit_info *src, int x, int y, int width, int height, - int offset_x, int offset_y); + int offset_x, int offset_y, int transform); void grub_video_fbblit_blend_BGRA8888_RGBA8888 (struct grub_video_fbblit_info *dst,
include/grub/fbfill.h +4 -4
@@ -32,10 +32,10 @@ struct grub_video_fbrender_targetstruct { -unsigned int x; -unsigned int y; -unsigned int width; -unsigned int height; +int x; +int y; +int width; +int height; } viewport;/* Indicates whether the data has been allocated by us and must be freed
include/grub/fbtran.h new file +235 -0
235 lines not on this page · raw message
include/grub/misc.h +9 -0
@@ -212,6 +212,15 @@ grub_max (long x, long y)return y; } +static inline long +grub_min (long x,long y) +{ +if (x > y) +return y; +else +return x; +} +/* Rounded-up division */ static inline unsigned int grub_div_roundup (unsigned int x,unsigned int y)
include/grub/util/misc.h +3 -0
@@ -39,6 +39,9 @@extern char *progname;extern int verbosity; +static inline void swap_int (int *a,int *b) {int tmp = *a; *a = *b; *b = tmp; } +static inline void swap_unsigned (unsigned *a,unsigned *b) {unsigned tmp = *a; *a = *b; *b = tmp; } +void grub_util_warn (const char *fmt, ...);void grub_util_info (const char *fmt, ...);void grub_util_error (const char *fmt, ...) __attribute__ ((noreturn));
include/grub/video.h +15 -16
@@ -149,6 +149,8 @@ struct grub_video_mode_infogrub_uint8_t fg_green;grub_uint8_t fg_blue;grub_uint8_t fg_alpha; + +int transform; };struct grub_video_palette_data
@@ -171,7 +173,7 @@ struct grub_video_adaptergrub_err_t (*fini) (void);grub_err_t (*setup) (unsigned int width,unsigned int height, -unsigned int mode_type); +unsigned int mode_type,int transform);grub_err_t (*get_info) (struct grub_video_mode_info *mode_info);
@@ -184,11 +186,9 @@ struct grub_video_adaptergrub_err_t (*get_palette) (unsigned int start,unsigned int count,struct grub_video_palette_data *palette_data); -grub_err_t (*set_viewport) (unsigned int x,unsigned int y, -unsigned int width,unsigned int height); +grub_err_t (*set_viewport) (int x,int y,int width,int height); -grub_err_t (*get_viewport) (unsigned int *x,unsigned int *y, -unsigned int *width,unsigned int *height); +grub_err_t (*get_viewport) (int *x, int *y, int *width, int *height);grub_video_color_t (*map_color) (grub_uint32_t color_name);
@@ -203,17 +203,17 @@ struct grub_video_adapter grub_uint8_t *blue, grub_uint8_t *alpha);grub_err_t (*fill_rect) (grub_video_color_t color,int x,int y, -unsigned int width,unsigned int height); +int width,int height);grub_err_t (*blit_bitmap) (struct grub_video_bitmap *bitmap,enum grub_video_blit_operators oper,int x,int y,int offset_x,int offset_y, -unsigned int width,unsigned int height); +int width,int height);grub_err_t (*blit_render_target) (struct grub_video_render_target *source,enum grub_video_blit_operators oper,int x,int y,int offset_x,int offset_y, -unsigned int width,unsigned int height); +int width,int height);grub_err_t (*scroll) (grub_video_color_t color,int dx,int dy);
@@ -258,11 +258,11 @@ grub_err_t grub_video_set_palette (unsigned int start, unsigned int count,grub_err_t grub_video_get_palette (unsigned int start,unsigned int count,struct grub_video_palette_data *palette_data); -grub_err_t grub_video_set_viewport (unsigned int x,unsigned int y, -unsigned int width,unsigned int height); +grub_err_t grub_video_set_viewport (int x,int y, +int width,int height); -grub_err_t grub_video_get_viewport (unsigned int *x,unsigned int *y, -unsigned int *width,unsigned int *height); +grub_err_t grub_video_get_viewport (int *x,int *y, +int *width,int *height);grub_video_color_t grub_video_map_color (grub_uint32_t color_name);
@@ -277,19 +277,18 @@ grub_err_t grub_video_unmap_color (grub_video_color_t color, grub_uint8_t *blue, grub_uint8_t *alpha);grub_err_t grub_video_fill_rect (grub_video_color_t color,int x,int y, -unsigned int width,unsigned int height); +int width,int height);grub_err_t grub_video_blit_bitmap (struct grub_video_bitmap *bitmap,enum grub_video_blit_operators oper,int x,int y,int offset_x,int offset_y, -unsigned int width,unsigned int height); +int width,int height);grub_err_t grub_video_blit_render_target (struct grub_video_render_target *source,enum grub_video_blit_operators oper,int x,int y,int offset_x,int offset_y, -unsigned int width, -unsigned int height); +int width,int height);grub_err_t grub_video_scroll (grub_video_color_t color,int dx,int dy);
include/grub/video_fb.h +23 -7
@@ -36,6 +36,22 @@ struct grub_video_fbblit_info;struct grub_video_fbrender_target ; +/* make width and height of a rectangle non-negative */ +static inline grub_err_t grub_fb_norm_rect (int *x,int *y,int *width,int *height) +{ +if (*width <0 ) + { + *width = -*width; + *x -= *width -1 ; + } +if (*height <0 ) + { + *height = -*height; + *y -= *height -1 ; + } +return GRUB_ERR_NONE ; +} +#define GRUB_VIDEO_FBSTD_NUMCOLORS 16extern struct grub_video_palette_data grub_video_fbstd_colors[GRUB_VIDEO_FBSTD_NUMCOLORS ];
@@ -55,11 +71,11 @@ grub_err_t grub_video_fb_set_palette (unsigned int start, unsigned int count, struct grub_video_palette_data *palette_data);grub_err_t -grub_video_fb_set_viewport (unsigned int x,unsigned int y, -unsigned int width,unsigned int height); +grub_video_fb_set_viewport (int x,int y, +int width,int height);grub_err_t -grub_video_fb_get_viewport (unsigned int *x,unsigned int *y, -unsigned int *width,unsigned int *height); +grub_video_fb_get_viewport (int *x,int *y, +int *width,int *height);grub_video_color_t grub_video_fb_map_color (grub_uint32_t color_name);
@@ -85,19 +101,19 @@ grub_video_fb_unmap_color_int (struct grub_video_fbblit_info * source,grub_err_t grub_video_fb_fill_rect (grub_video_color_t color,int x,int y, -unsigned int width,unsigned int height); +int width,int height);grub_err_t grub_video_fb_blit_bitmap (struct grub_video_bitmap *bitmap,enum grub_video_blit_operators oper,int x,int y,int offset_x,int offset_y, -unsigned int width,unsigned int height); +int width,int height);grub_err_t grub_video_fb_blit_render_target (struct grub_video_fbrender_target *source,enum grub_video_blit_operators oper,int x,int y,int offset_x,int offset_y, -unsigned int width,unsigned int height); +int width,int height);grub_err_t grub_video_fb_scroll (grub_video_color_t color,int dx,int dy);
video/bitmap.c +1 -0
@@ -75,6 +75,7 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap, mode_info->width = width; mode_info->height = height; mode_info->blit_format = blit_format; + mode_info->transform =0 ;switch (blit_format) {
video/fb/fbblit.c +16 -5
@@ -27,16 +27,19 @@#include <grub/misc.h> #include <grub/types.h> #include <grub/video.h> +#include <grub/fbtran.h> /* Generic replacing blitter (slow). Works for every supported format. */ void grub_video_fbblit_replace (struct grub_video_fbblit_info *dst,struct grub_video_fbblit_info *src,int x,int y,int width,int height, -int offset_x,int offset_y) +int offset_x,int offset_y,int transform) {int i;int j; +int dx = (transform &FB_TRAN_MIRROR ) ?-1 :1 ; +int dy = (transform &FB_TRAN_FLIP ) ?-1 :1 ;grub_uint8_t src_red;grub_uint8_t src_green;grub_uint8_t src_blue;
@@ -56,8 +59,11 @@ grub_video_fbblit_replace (struct grub_video_fbblit_info *dst, dst_color =grub_video_fb_map_rgba (src_red, src_green, src_blue, src_alpha); -set_pixel (dst, x + i, y + j, dst_color); - } +if (transform &FB_TRAN_SWAP ) +set_pixel (dst, x + j*dy, y + i*dx, dst_color); +else +set_pixel (dst, x + i*dx, y + j*dy, dst_color); + } } }
@@ -409,10 +415,12 @@ void grub_video_fbblit_blend (struct grub_video_fbblit_info *dst, struct grub_video_fbblit_info *src, int x, int y, int width, int height, - int offset_x, int offset_y) + int offset_x, int offset_y, int transform) { int i;int j; +int dx = (transform &FB_TRAN_MIRROR ) ?-1 :1 ; +int dy = (transform &FB_TRAN_FLIP ) ?-1 :1 ;for (j =0 ; j < height; j++) {
@@ -460,7 +468,10 @@ grub_video_fbblit_blend (struct grub_video_fbblit_info *dst, dst_color =grub_video_fb_map_rgba (dst_red, dst_green, dst_blue, dst_alpha); -set_pixel (dst, x + i, y + j, dst_color); +if (transform &FB_TRAN_SWAP ) +set_pixel (dst, x + j*dy, y + i*dx, dst_color); +else +set_pixel (dst, x + i*dx, y + j*dy, dst_color); } } }
video/fb/video_fb.c +97 -50
358 lines not on this page · raw message
video/i386/pc/vbe.c +3 -1
@@ -381,7 +381,7 @@ grub_video_vbe_fini (void)static grub_err_t grub_video_vbe_setup (unsigned int width,unsigned int height, -unsigned int mode_type) +unsigned int mode_type,int transform) {grub_uint16_t *p;struct grub_vbe_mode_info_block vbe_mode_info;
@@ -499,6 +499,8 @@ grub_video_vbe_setup (unsigned int width, unsigned int height, framebuffer.mode_info.blit_format =grub_video_get_blit_format (&framebuffer.mode_info); + framebuffer.mode_info.transform = transform; + err =grub_video_fb_create_render_target_from_pointer (&framebuffer.render_target, &framebuffer.mode_info, framebuffer.ptr);if (err)
video/video.c +45 -9
114 lines not on this page · raw message
Sending an updated patch.
fbtran should be applied after signed-rect:
Use signed rectangles in video
* include/grub/video_fb.h (grub_fb_norm_rect): new inline
* include/grub/video_fb.h: make viewport, fill and blit function prototypes use signed rectangles
* include/grub/video.h: ditto
* include/grub/fbfill (grub_video_fbrender_target): make viewport signed
* video/fb/video_fb.c: update viewport, fill and blit functions to use signed rectangles and grub_fb_norm_rect, update casts
* video/video.c: update viewport, fill and blit functions to
signed rectangles
* commands/videotest.c (grub_cmd_videotest): make locals signed
Add simple fb coordinate transform support
* include/grub/fbtran.h: new file
* include/grub/fbtran.h: (fb_tran_swap_tran,
fb_tran_append, fb_tran_invert, fb_tran_diff, fb_tran_rect, fb_tran_rect_back, fb_tran_rect_intern, fb_tran_point, fb_tran_point_back, fb_tran_point_intern, fb_tran_dim, fb_tran_dim_backi, fb_tran_blit): new inlines
* include/grub/util/misc.h (swap_int, swap_unsigned, grub_min): new inlines
* include/grub/video.h (struct grub_video_mode_info): add transform
* include/grub/video.h (grub_video_adapter.setup): add transform
* include/grub/fbblit.h (grub_video_fbblit_blend, grub_video_fbblit_replace): add transform
* video/fb/fbblit.c (grub_video_fbblit_blend, grub_video_fbblit_replace): add transform support
* video/fb/video_fb.c (grub_video_fb_create_render_target): copy transform from the active target
* video/fb/video_fb.c: add coordinate transforms from user coordinates
* video/fb/video_fb.c (common_blitter): use only generic blitter when transform is required
* video/i386/pc/vbe.c (grub_video_vbe_setup): add transform argument, copy it to mode_info
* video/video.c (grub_video_set_mode): parse transform from the mode string
* video/bitmap.c (grub_video_bitmap_create): set transform to 0 in
created bitmaps
* font/font.c (grub_font_draw_glyph): set transform to 0 in created bitmaps
* term/gfxterm.c (view_width, view_height): new local variables
* term/gfxterm.c: save viewport size in view_width, view_height
- use view_width, view_height insterd of mode_info
* commands/videotest.c: add transform tests
* commands/videotest.c: leaf_data, leaves: new local variables
* commands/videotest.c: init_leaves, draw_leaves: new functions
2009/8/28 Michal Suchanek <[email protected]>:
Quoted 10 lines
Hello
Sending a preliminary framebuffer rotation patch.
You can use videotest to see 4 tiles rotated from the same bitmap data.
Known issues:
- no "accelerated" blitters for rotated modes, at least the 1bit blitter should work
However, I did not see any difference between the specialized 1bit blitter and generic blitter on qemu.
Quoted 11 lines
To be done
- make up some naming scheme and rename functions and macros accordingly
- make up some acceptable way to specify framebnuffer rotation in the environment like gfxmodeThanks
Michal
commands/videotest.c +4 -4
@@ -34,10 +34,10 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)),return grub_errno;grub_video_color_t color; -unsigned int x; -unsigned int y; -unsigned int width; -unsigned int height; +int x; +int y; +int width; +int height;int i;grub_font_t sansbig;grub_font_t sans;
include/grub/fbfill.h +4 -4
@@ -32,10 +32,10 @@ struct grub_video_fbrender_targetstruct { -unsigned int x; -unsigned int y; -unsigned int width; -unsigned int height; +int x; +int y; +int width; +int height; } viewport;/* Indicates whether the data has been allocated by us and must be freed
include/grub/video.h +12 -15
@@ -184,11 +184,9 @@ struct grub_video_adaptergrub_err_t (*get_palette) (unsigned int start,unsigned int count,struct grub_video_palette_data *palette_data); -grub_err_t (*set_viewport) (unsigned int x,unsigned int y, -unsigned int width,unsigned int height); +grub_err_t (*set_viewport) (int x,int y,int width,int height); -grub_err_t (*get_viewport) (unsigned int *x,unsigned int *y, -unsigned int *width,unsigned int *height); +grub_err_t (*get_viewport) (int *x, int *y, int *width, int *height);grub_video_color_t (*map_color) (grub_uint32_t color_name);
@@ -203,17 +201,17 @@ struct grub_video_adapter grub_uint8_t *blue, grub_uint8_t *alpha);grub_err_t (*fill_rect) (grub_video_color_t color,int x,int y, -unsigned int width,unsigned int height); +int width,int height);grub_err_t (*blit_bitmap) (struct grub_video_bitmap *bitmap,enum grub_video_blit_operators oper,int x,int y,int offset_x,int offset_y, -unsigned int width,unsigned int height); +int width,int height);grub_err_t (*blit_render_target) (struct grub_video_render_target *source,enum grub_video_blit_operators oper,int x,int y,int offset_x,int offset_y, -unsigned int width,unsigned int height); +int width,int height);grub_err_t (*scroll) (grub_video_color_t color,int dx,int dy);
@@ -258,11 +256,11 @@ grub_err_t grub_video_set_palette (unsigned int start, unsigned int count,grub_err_t grub_video_get_palette (unsigned int start,unsigned int count,struct grub_video_palette_data *palette_data); -grub_err_t grub_video_set_viewport (unsigned int x,unsigned int y, -unsigned int width,unsigned int height); +grub_err_t grub_video_set_viewport (int x,int y, +int width,int height); -grub_err_t grub_video_get_viewport (unsigned int *x,unsigned int *y, -unsigned int *width,unsigned int *height); +grub_err_t grub_video_get_viewport (int *x,int *y, +int *width,int *height);grub_video_color_t grub_video_map_color (grub_uint32_t color_name);
@@ -277,19 +275,18 @@ grub_err_t grub_video_unmap_color (grub_video_color_t color, grub_uint8_t *blue, grub_uint8_t *alpha);grub_err_t grub_video_fill_rect (grub_video_color_t color,int x,int y, -unsigned int width,unsigned int height); +int width,int height);grub_err_t grub_video_blit_bitmap (struct grub_video_bitmap *bitmap,enum grub_video_blit_operators oper,int x,int y,int offset_x,int offset_y, -unsigned int width,unsigned int height); +int width,int height);grub_err_t grub_video_blit_render_target (struct grub_video_render_target *source,enum grub_video_blit_operators oper,int x,int y,int offset_x,int offset_y, -unsigned int width, -unsigned int height); +int width,int height);grub_err_t grub_video_scroll (grub_video_color_t color,int dx,int dy);
include/grub/video_fb.h +23 -7
@@ -36,6 +36,22 @@ struct grub_video_fbblit_info;struct grub_video_fbrender_target ; +/* make width and height of a rectangle non-negative */ +static inline grub_err_t grub_fb_norm_rect (int *x,int *y,int *width,int *height) +{ +if (*width <0 ) + { + *width = -*width; + *x -= *width -1 ; + } +if (*height <0 ) + { + *height = -*height; + *y -= *height -1 ; + } +return GRUB_ERR_NONE ; +} +#define GRUB_VIDEO_FBSTD_NUMCOLORS 16extern struct grub_video_palette_data grub_video_fbstd_colors[GRUB_VIDEO_FBSTD_NUMCOLORS ];
@@ -55,11 +71,11 @@ grub_err_t grub_video_fb_set_palette (unsigned int start, unsigned int count, struct grub_video_palette_data *palette_data);grub_err_t -grub_video_fb_set_viewport (unsigned int x,unsigned int y, -unsigned int width,unsigned int height); +grub_video_fb_set_viewport (int x,int y, +int width,int height);grub_err_t -grub_video_fb_get_viewport (unsigned int *x,unsigned int *y, -unsigned int *width,unsigned int *height); +grub_video_fb_get_viewport (int *x,int *y, +int *width,int *height);grub_video_color_t grub_video_fb_map_color (grub_uint32_t color_name);
@@ -85,19 +101,19 @@ grub_video_fb_unmap_color_int (struct grub_video_fbblit_info * source,grub_err_t grub_video_fb_fill_rect (grub_video_color_t color,int x,int y, -unsigned int width,unsigned int height); +int width,int height);grub_err_t grub_video_fb_blit_bitmap (struct grub_video_bitmap *bitmap,enum grub_video_blit_operators oper,int x,int y,int offset_x,int offset_y, -unsigned int width,unsigned int height); +int width,int height);grub_err_t grub_video_fb_blit_render_target (struct grub_video_fbrender_target *source,enum grub_video_blit_operators oper,int x,int y,int offset_x,int offset_y, -unsigned int width,unsigned int height); +int width,int height);grub_err_t grub_video_fb_scroll (grub_video_color_t color,int dx,int dy);
video/fb/video_fb.c +48 -34
212 lines not on this page · raw message
video/video.c +5 -7
@@ -227,8 +227,7 @@ grub_video_get_palette (unsigned int start, unsigned int count,/* Set viewport dimensions. */ grub_err_t -grub_video_set_viewport (unsigned int x,unsigned int y, -unsigned int width,unsigned int height) +grub_video_set_viewport (int x,int y,int width,int height) {if (! grub_video_adapter_active)return grub_error (GRUB_ERR_BAD_DEVICE ,"No video mode activated" );
@@ -238,8 +237,7 @@ grub_video_set_viewport (unsigned int x, unsigned int y,/* Get viewport dimensions. */ grub_err_t -grub_video_get_viewport (unsigned int *x,unsigned int *y, -unsigned int *width,unsigned int *height) +grub_video_get_viewport (int *x,int *y,int *width,int *height) {if (! grub_video_adapter_active)return grub_error (GRUB_ERR_BAD_DEVICE ,"No video mode activated" );
@@ -297,7 +295,7 @@ grub_video_unmap_color (grub_video_color_t color, grub_uint8_t *red,/* Fill rectangle using specified color. */ grub_err_t grub_video_fill_rect (grub_video_color_t color,int x,int y, -unsigned int width,unsigned int height) +int width,int height) {if (! grub_video_adapter_active)return grub_error (GRUB_ERR_BAD_DEVICE ,"No video mode activated" );
@@ -310,7 +308,7 @@ grub_err_t grub_video_blit_bitmap (struct grub_video_bitmap *bitmap, enum grub_video_blit_operators oper, int x, int y, int offset_x, int offset_y, - unsigned int width, unsigned int height) + int width, int height) { if (! grub_video_adapter_active) return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
@@ -325,7 +323,7 @@ grub_err_t grub_video_blit_render_target (struct grub_video_render_target *target, enum grub_video_blit_operators oper, int x, int y, int offset_x, int offset_y, - unsigned int width, unsigned int height) + int width, int height) { if (! grub_video_adapter_active) return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
commands/videotest.c +153 -2
173 lines not on this page · raw message
font/font.c +2 -0
@@ -987,8 +987,10 @@ grub_font_draw_glyph (struct grub_font_glyph *glyph,if (glyph->width ==0 || glyph->height ==0 )return GRUB_ERR_NONE ; +/* TODO: add support for bitmaps to create_bitmap */ glyph_bitmap.mode_info.width = glyph->width; glyph_bitmap.mode_info.height = glyph->height; + glyph_bitmap.mode_info.transform =0 ; glyph_bitmap.mode_info.mode_type = (1 <<GRUB_VIDEO_MODE_TYPE_DEPTH_POS ) |GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP ;
include/grub/fbblit.h +2 -2
@@ -28,7 +28,7 @@ void grub_video_fbblit_replace (struct grub_video_fbblit_info *dst, struct grub_video_fbblit_info *src, int x, int y, int width, int height, - int offset_x, int offset_y); + int offset_x, int offset_y, int transform); void grub_video_fbblit_replace_directN (struct grub_video_fbblit_info *dst,
@@ -94,7 +94,7 @@ void grub_video_fbblit_blend (struct grub_video_fbblit_info *dst, struct grub_video_fbblit_info *src, int x, int y, int width, int height, - int offset_x, int offset_y); + int offset_x, int offset_y, int transform); void grub_video_fbblit_blend_BGRA8888_RGBA8888 (struct grub_video_fbblit_info *dst,
include/grub/fbtran.h new file +220 -0
220 lines not on this page · raw message
include/grub/misc.h +9 -0
@@ -212,6 +212,15 @@ grub_max (long x, long y)return y; } +static inline long +grub_min (long x,long y) +{ +if (x > y) +return y; +else +return x; +} +/* Rounded-up division */ static inline unsigned int grub_div_roundup (unsigned int x,unsigned int y)
include/grub/util/misc.h +3 -0
@@ -39,6 +39,9 @@extern char *progname;extern int verbosity; +static inline void swap_int (int *a,int *b) {int tmp = *a; *a = *b; *b = tmp; } +static inline void swap_unsigned (unsigned *a,unsigned *b) {unsigned tmp = *a; *a = *b; *b = tmp; } +void grub_util_warn (const char *fmt, ...);void grub_util_info (const char *fmt, ...);void grub_util_error (const char *fmt, ...) __attribute__ ((noreturn));
include/grub/video.h +3 -1
@@ -149,6 +149,8 @@ struct grub_video_mode_infogrub_uint8_t fg_green;grub_uint8_t fg_blue;grub_uint8_t fg_alpha; + +int transform; };struct grub_video_palette_data
@@ -171,7 +173,7 @@ struct grub_video_adaptergrub_err_t (*fini) (void);grub_err_t (*setup) (unsigned int width,unsigned int height, -unsigned int mode_type); +unsigned int mode_type,int transform);grub_err_t (*get_info) (struct grub_video_mode_info *mode_info);
term/gfxterm.c +12 -7
@@ -105,6 +105,9 @@ static struct grub_virtual_screen virtual_screen;static struct grub_video_mode_info mode_info; +static int view_width; +static int view_height; +static struct grub_video_render_target *text_layer;static unsigned int bitmap_width;
@@ -259,6 +262,7 @@ grub_gfxterm_init (void)grub_video_color_t color;int width;int height; +int view_x, view_y;grub_err_t err;/* Select the font to use. */
@@ -287,14 +291,15 @@ grub_gfxterm_init (void)if (err)return err; +grub_video_get_viewport (&view_x, &view_y, &view_width, &view_height);/* Make sure screen is black. */ color =grub_video_map_rgb (0 ,0 ,0 ); -grub_video_fill_rect (color,0 ,0 , mode_info.width, mode_info.height); +grub_video_fill_rect (color,0 ,0 , view_width, view_height); bitmap =0 ;/* Leave borders for virtual screen. */ - width = mode_info.width - (2 *DEFAULT_BORDER_WIDTH ); - height = mode_info.height - (2 *DEFAULT_BORDER_WIDTH ); + width = view_width - (2 *DEFAULT_BORDER_WIDTH ); + height = view_height - (2 *DEFAULT_BORDER_WIDTH );/* Create virtual screen. */ if (grub_virtual_screen_setup (DEFAULT_BORDER_WIDTH, DEFAULT_BORDER_WIDTH,
@@ -306,7 +311,7 @@ grub_gfxterm_init (void)/* Mark whole screen as dirty. */ dirty_region_reset (); -dirty_region_add (0 ,0 , mode_info.width, mode_info.height); +dirty_region_add (0 ,0 , view_width, view_height);return (grub_errno =GRUB_ERR_NONE ); }
@@ -814,7 +819,7 @@ grub_gfxterm_cls (void)/* Clear text layer. */ grub_video_set_active_render_target (text_layer); color = virtual_screen.bg_color; -grub_video_fill_rect (color,0 ,0 , mode_info.width, mode_info.height); +grub_video_fill_rect (color,0 ,0 , view_width, view_height);grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY );/* Mark virtual screen to be redrawn. */
@@ -900,7 +905,7 @@ grub_gfxterm_background_image_cmd (grub_command_t cmd __attribute__ ((unused)),/* Mark whole screen as dirty. */ dirty_region_reset (); -dirty_region_add (0 ,0 , mode_info.width, mode_info.height); +dirty_region_add (0 ,0 , view_width, view_height); }/* If filename was provided, try to load that. */
@@ -920,7 +925,7 @@ grub_gfxterm_background_image_cmd (grub_command_t cmd __attribute__ ((unused)),/* Mark whole screen as dirty. */ dirty_region_reset (); -dirty_region_add (0 ,0 , mode_info.width, mode_info.height); +dirty_region_add (0 ,0 , view_width, view_height); } }
video/bitmap.c +1 -0
@@ -75,6 +75,7 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap, mode_info->width = width; mode_info->height = height; mode_info->blit_format = blit_format; + mode_info->transform =0 ;switch (blit_format) {
video/fb/fbblit.c +24 -8
@@ -27,16 +27,19 @@#include <grub/misc.h> #include <grub/types.h> #include <grub/video.h> +#include <grub/fbtran.h> /* Generic replacing blitter (slow). Works for every supported format. */ void grub_video_fbblit_replace (struct grub_video_fbblit_info *dst,struct grub_video_fbblit_info *src,int x,int y,int width,int height, -int offset_x,int offset_y) +int offset_x,int offset_y,int transform) {int i;int j; +int dx = (transform &FB_TRAN_MIRROR ) ?-1 :1 ; +int dy = (transform &FB_TRAN_FLIP ) ?-1 :1 ;grub_uint8_t src_red;grub_uint8_t src_green;grub_uint8_t src_blue;
@@ -56,8 +59,11 @@ grub_video_fbblit_replace (struct grub_video_fbblit_info *dst, dst_color =grub_video_fb_map_rgba (src_red, src_green, src_blue, src_alpha); -set_pixel (dst, x + i, y + j, dst_color); - } +if (transform &FB_TRAN_SWAP ) +set_pixel (dst, x + j*dy, y + i*dx, dst_color); +else +set_pixel (dst, x + i*dx, y + j*dy, dst_color); + } } }
@@ -705,10 +711,12 @@ void grub_video_fbblit_blend (struct grub_video_fbblit_info *dst, struct grub_video_fbblit_info *src, int x, int y, int width, int height, - int offset_x, int offset_y) + int offset_x, int offset_y, int transform) { int i;int j; +int dx = (transform &FB_TRAN_MIRROR ) ?-1 :1 ; +int dy = (transform &FB_TRAN_FLIP ) ?-1 :1 ;for (j =0 ; j < height; j++) {
@@ -735,12 +743,17 @@ grub_video_fbblit_blend (struct grub_video_fbblit_info *dst,if (src_alpha ==255 ) { dst_color =grub_video_fb_map_rgba (src_red, src_green, - src_blue, src_alpha); -set_pixel (dst, x + i, y + j, dst_color); + src_blue, src_alpha); +if (transform &FB_TRAN_SWAP ) +set_pixel (dst, x + j*dy, y + i*dx, dst_color); +else +set_pixel (dst, x + i*dx, y + j*dy, dst_color);continue ; } - dst_color =get_pixel (dst, x + i, y + j); + dst_color = (transform &FB_TRAN_SWAP ) ? +get_pixel (dst, x + j*dy, y + i*dx) : +get_pixel (dst, x + i*dx, y + j*dy) ;grub_video_fb_unmap_color_int (dst, dst_color, &dst_red, &dst_green, &dst_blue, &dst_alpha);
@@ -756,7 +769,10 @@ grub_video_fbblit_blend (struct grub_video_fbblit_info *dst, dst_color =grub_video_fb_map_rgba (dst_red, dst_green, dst_blue, dst_alpha); -set_pixel (dst, x + i, y + j, dst_color); +if (transform &FB_TRAN_SWAP ) +set_pixel (dst, x + j*dy, y + i*dx, dst_color); +else +set_pixel (dst, x + i*dx, y + j*dy, dst_color); } } }
video/fb/video_fb.c +56 -24
216 lines not on this page · raw message
video/i386/pc/vbe.c +3 -1
@@ -381,7 +381,7 @@ grub_video_vbe_fini (void)static grub_err_t grub_video_vbe_setup (unsigned int width,unsigned int height, -unsigned int mode_type) +unsigned int mode_type,int transform) {grub_uint16_t *p;struct grub_vbe_mode_info_block vbe_mode_info;
@@ -499,6 +499,8 @@ grub_video_vbe_setup (unsigned int width, unsigned int height, framebuffer.mode_info.blit_format =grub_video_get_blit_format (&framebuffer.mode_info); + framebuffer.mode_info.transform = transform; + err =grub_video_fb_create_render_target_from_pointer (&framebuffer.render_target, &framebuffer.mode_info, framebuffer.ptr);if (err)
video/video.c +40 -2
72 lines not on this page · raw message
Quoted 7 lines · Michal Suchanek
Hello
Sending a preliminary framebuffer rotation patch.
You can use videotest to see 4 tiles rotated from the same bitmap data.
+char leaf_data[] = { 0x00, 0x0f, 0xe0, 0x00,
+ 0x00, 0x7f, 0xfc, 0x00, + 0x01, 0xff, 0xff, 0x00, + 0x03, 0xff, 0xff, 0x80,
This is a blob. Could it be generated automatically at build time? +
+ sans = grub_font_get ("Helvetica Bold 14");
Please use free font rather than Helvetica
Could you split addition of videotests from the rest of the patch?
- unsigned int x; - unsigned int y; - unsigned int width; - unsigned int height; + int x; + int y; + int width; + int height; Why do you need negative values? +/* Supported operations are simple and easy to understand. + * MIRROR | swap image across (around) the vertical axis + * FLIP - swap image across the horizontal axis - upside down + * SWAP / swap image across the x=y axis - swap the x and y coordinates
It's just a D_8 group. Could you add a comment to functions what they do in group theoretical sense? It would make the code easier to follow and compute transformations for mathematicians. Perhaps another representation of D_8 would result in more efficient code? +static inline void grub_swap_int(int *a, int *b) { int tmp = *a; *a = *b; *b = tmp; }
+static inline void grub_swap_unsigned(unsigned *a, unsigned *b) { unsigned tmp = *a; *a = *b; *b = tmp; }
+
With typeof macro this can be made type-neutral avoiding potential mistakes. +static inline long
+grub_min (long x, long y)
+{
+ if (x > y)
+ return y;
+ else
+ return x;
+}
+
Same here
+
+ int transform;
I would prefer an enum
Skipping term/gfxterm.c since it has to be adjusted for gfxmenu-related gfxterm.c updates.
- set_pixel (dst, x + i, y + j, dst_color);
- }
+ if (transform & FB_TRAN_SWAP)
+ set_pixel (dst, x + j*dy, y + i*dx, dst_color);
+ else
+ set_pixel (dst, x + i*dx, y + j*dy, dst_color);
+ }
Could you split it into 4 functions? I understand it's the slow fallback function but still it should be kept as fast as possible. Perhaps you could consider compiling same file with different #define's to obtain function variants
grub_err_t
-grub_video_fb_set_viewport (unsigned int x, unsigned int y,
- unsigned int width, unsigned int height)
+grub_video_fb_set_viewport (int x, int y, int width, int height)
{
You don't check for x < 0 and y < 0
Quoted 25 lines
Known issues:
- font glyphs and terminal do not rotate properly
- no accelerated blitters for rotated modes, at least the 1bit blitter should workTo be done
- split out signed rectangle patch that changes graphics coordinates from unsigned to signed
- make up some naming scheme and rename functions and macros accordingly
- make up some acceptable way to specify framebnuffer rotation in the environment like gfxmodeThanks
Michal
------------------------------------------------------------------------
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
2010/2/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 5 lines
Quoted 4 lines · Michal Suchanek
Hello
Sending a preliminary framebuffer rotation patch.
Quoted 8 lines
Quoted 3 lines
You can use videotest to see 4 tiles rotated from the same bitmap data.
+char leaf_data[] = {
0x00,0x0f,0xe0,0x00,
+0x00,0x7f,0xfc,0x00,
+0x01,0xff,0xff,0x00,
+0x03,0xff,0xff,0x80,
This is a blob. Could it be generated automatically at build time?
How less of a blob it would be if it was included as a bitmap?
This is just a shape used for the video tests.
There are some X tools for working with bitmaps/pixmaps which could generate this from a viewable file but they are usually not available on Windows and other non-X platforms AFAIK.
Quoted 3 lines
+
+ sans =grub_font_get("Helvetica Bold 14");
Please use free font rather than Helvetica
I am pretty sure I did not choose the fonts, they must have been there before I started with modifications to the tests.
Quoted 10 lines
Could you split addition of videotests from the rest of the patch?
- unsigned int x;
- unsigned int y;
- unsigned int width;
- unsigned int height;
+ int x;
+ int y;
+ int width;
+ int height;
Why do you need negative values?
I don't need the negative values everywhere but this change was to align the typing so that casts are not required.
Quoted 6 lines
+/* Supported operations are simple and easy to understand.
+ * MIRROR | swap image across (around) the vertical axis
+ * FLIP - swap image across the horizontal axis - upside down
+ * SWAP / swap image across the x=y axis - swap the x and y coordinates It's just aD_8group. Could you add a comment to functions what they do in group theoretical sense? It would make the code easier to follow and
Obviously it is a group, any set of transforms closed on composition is.
And according to Wikipedia it's actually called D4.
Quoted 2 lines
compute transformations for mathematicians. Perhaps another representation of
D_8would result in more efficient code?
If you have clearer explanation or more efficient code please share.
Quoted 6 lines
+static inline void
grub_swap_int(int *a, int *b){ int tmp = *a; *a = *b; *b = tmp; }
+static inline voidgrub_swap_unsigned(unsigned *a, unsigned *b){ unsigned tmp = *a; *a = *b; *b = tmp; }
+
With typeof macro this can be made type-neutral avoiding potential mistakes.
OK, I will look at typeof.
Quoted 9 lines
include/grub/misc.h +9
-0+static inline long +grub_min (long x,long y) +{ + if (x > y) + return y; + else + return x; +} +
Quoted 4 lines
Same here
+
+ int transform;
I would prefer an enum
This is a bit field. How does it transform into an enum?
Quoted 5 lines
Skipping
term/gfxterm.csince it has to be adjusted for gfxmenu-relatedgfxterm.cupdates.
-set_pixel(dst, x + i, y + j,dst_color);
- }
+ if (transform &FB_TRAN_SWAP)
Quoted 8 lines
+ set_pixel (dst, x + j*dy, y + i*dx,
dst_color);
+ else
+ set_pixel (dst, x + i*dx, y + j*dy,dst_color);
+ }
Could you split it into 4 functions? I understand it's the slow fallback function but still it should be kept as fast as possible. Perhaps you could consider compiling same file with different #define's to obtain function variants
I would rather get a patch with minimal changes first so that it's obvious what it does.
I can look into separating this later.
Quoted 6 lines
grub_err_t
video/fb/video_fb.c +1
-2-grub_video_fb_set_viewport (unsigned int x, unsigned int y, - unsigned int width, unsigned int height) +grub_video_fb_set_viewport (int x, int y, int width, int height){
You don't check for x < 0 and y < 0
Indeed, should check for those.
Quoted 3 lines
Quoted 3 lines
Known issues:
- font glyphs and terminal do not rotate properly
This should be working already.
Thanks
Michal
Quoted 51 lines · Michal Suchanek
2010/2/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 5 lines
Quoted 4 lines · Michal Suchanek
Hello
Sending a preliminary framebuffer rotation patch.
Quoted 8 lines
Quoted 3 lines
You can use videotest to see 4 tiles rotated from the same bitmap data.
+char leaf_data[] = {
0x00,0x0f,0xe0,0x00,
+0x00,0x7f,0xfc,0x00,
+0x01,0xff,0xff,0x00,
+0x03,0xff,0xff,0x80,
This is a blob. Could it be generated automatically at build time?How less of a blob it would be if it was included as a bitmap?
This is just a shape used for the video tests.
There are some X tools for working with bitmaps/pixmaps which could generate this from a viewable file but they are usually not available on Windows and other non-X platforms AFAIK.
Quoted 3 lines
+
+ sans =grub_font_get("Helvetica Bold 14");
Please use free font rather than HelveticaI am pretty sure I did not choose the fonts, they must have been there before I started with modifications to the tests.
Quoted 10 lines
Could you split addition of videotests from the rest of the patch?
- unsigned int x;
- unsigned int y;
- unsigned int width;
- unsigned int height;
+ int x;
+ int y;
+ int width;
+ int height;
Why do you need negative values?I don't need the negative values everywhere but this change was to align the typing so that casts are not required.
Quoted 6 lines
+/* Supported operations are simple and easy to understand.
+ * MIRROR | swap image across (around) the vertical axis
+ * FLIP - swap image across the horizontal axis - upside down
+ * SWAP / swap image across the x=y axis - swap the x and y coordinates It's just aD_8group. Could you add a comment to functions what they do in group theoretical sense? It would make the code easier to follow and
Quoted 9 lines
Obviously it is a group, any set of transforms closed on composition is.
And according to Wikipedia it's actually called D4.
Quoted 2 lines
compute transformations for mathematicians. Perhaps another representation of
D_8would result in more efficient code?If you have clearer explanation or more efficient code please share.
Let me elaborate a bit more on this one.
The provided explanation should make it possible for anybody who understands plain English to also understand the operations used and how they interact should they know group theory in English, any other language, or not at all.
I guess mentioning the English mathematical terms where applicable and where I can figure them out should not that much of a problem, as well as checking that the transform functions are sufficiently described.
Still the fact that is used (and explained) is that the operations I,
- and / generate the group and in addition you can get all members of the group if you compose a subset of these generators in a fixed order which is trivially true for comutative groups but not so for a non-comutative group such as this one.
Thanks
Michal
Quoted 71 lines · Michal Suchanek
Quoted 59 lines · Michal Suchanek
2010/2/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 14 lines
Quoted 8 lines · Michal Suchanek
Hello
Sending a preliminary framebuffer rotation patch.
You can use videotest to see 4 tiles rotated from the same bitmap data.
commands/videotest.c +4
-0+char leaf_data[] = {0x00 ,0x0f ,0xe0 ,0x00 , +0x00 ,0x7f ,0xfc ,0x00 , +0x01 ,0xff ,0xff ,0x00 , +0x03 ,0xff ,0xff ,0x80 ,Quoted 2 lines
This is a blob. Could it be generated automatically at build time?
How less of a blob it would be if it was included as a bitmap?
This is just a shape used for the video tests.
There are some X tools for working with bitmaps/pixmaps which could generate this from a viewable file but they are usually not available on Windows and other non-X platforms AFAIK.
Quoted 4 lines
(quoted diff) +2
-0+ + sans = grub_font_get ("Helvetica Bold 14");Please use free font rather than Helvetica
I am pretty sure I did not choose the fonts, they must have been there before I started with modifications to the tests.
Quoted 11 lines
Could you split addition of videotests from the rest of the patch?
commands/videotest.c +4
-4-unsigned int x; -unsigned int y; -unsigned int width; -unsigned int height; +int x; +int y; +int width; +int height;Why do you need negative values?
I don't need the negative values everywhere but this change was to align the typing so that casts are not required.
Quoted 7 lines
+/* Supported operations are simple and easy to understand.
+ * MIRROR | swap image across (around) the vertical axis + * FLIP - swap image across the horizontal axis - upside down + * SWAP / swap image across the x=y axis - swap the x and y coordinatesIt's just a
D_8group. Could you add a comment to functions what they do in group theoretical sense? It would make the code easier to follow andObviously it is a group, any set of transforms closed on composition is.
Quoted 9 lines
And according to Wikipedia it's actually called D4.
Quoted 3 lines
compute transformations for mathematicians. Perhaps another representation of
D_8would result in more efficient code?If you have clearer explanation or more efficient code please share.
Quoted 7 lines
Let me elaborate a bit more on this one.
The provided explanation should make it possible for anybody who understands plain English to also understand the operations used and how they interact should they know group theory in English, any other language, or not at all.
Perhaps one could add an example of how it moves vertices of a square? E.g for vertical flip:
1---2 2----1
| | --> | | 4---3 3----4
Quoted 5 lines
I guess mentioning the English mathematical terms where applicable and where I can figure them out should not that much of a problem, as well as checking that the transform functions are sufficiently described.
Feel free to ask any questions.
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 12 lines · Michal Suchanek
2010/2/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 10 lines
Quoted 8 lines · Michal Suchanek
Hello
Sending a preliminary framebuffer rotation patch.
You can use videotest to see 4 tiles rotated from the same bitmap data.
Quoted 10 lines
Quoted 6 lines
commands/videotest.c +4
-0+char leaf_data[] = {0x00 ,0x0f ,0xe0 ,0x00 , +0x00 ,0x7f ,0xfc ,0x00 , +0x01 ,0xff ,0xff ,0x00 , +0x03 ,0xff ,0xff ,0x80 ,This is a blob. Could it be generated automatically at build time?
How less of a blob it would be if it was included as a bitmap?
It's not easily editable in current form.
Quoted 7 lines
This is just a shape used for the video tests.
There are some X tools for working with bitmaps/pixmaps which could generate this from a viewable file but they are usually not available on Windows and other non-X platforms AFAIK.
Using XBM is fine (it's easily editable in either gimp or emacs) and you should be able to
#include "leaf1.xbm"
Quoted 9 lines
Quoted 4 lines
(quoted diff) +2
-0+ + sans = grub_font_get ("Helvetica Bold 14");Please use free font rather than Helvetica
I am pretty sure I did not choose the fonts, they must have been there before I started with modifications to the tests.
Ok, it has to be fixed in mainstream then.
Quoted 12 lines
Quoted 11 lines
Could you split addition of videotests from the rest of the patch?
commands/videotest.c +4
-4-unsigned int x; -unsigned int y; -unsigned int width; -unsigned int height; +int x; +int y; +int width; +int height;Why do you need negative values?
Quoted 4 lines
I don't need the negative values everywhere but this change was to align the typing so that casts are not required.
Perhaps few casts together with appropiate checks when casting is better than potentially exposing the whole code to the values it's not intended for.
Quoted 8 lines
Quoted 7 lines
+/* Supported operations are simple and easy to understand.
+ * MIRROR | swap image across (around) the vertical axis + * FLIP - swap image across the horizontal axis - upside down + * SWAP / swap image across the x=y axis - swap the x and y coordinatesIt's just a
D_8group. Could you add a comment to functions what they do in group theoretical sense? It would make the code easier to follow and
Quoted 5 lines
Obviously it is a group,
any set of transforms closed on composition is.
Not true. Consider an example of empty set: it has no identity element. Less trivial counter-example: set of transformations: (x,y)->(kx,ky), 0<k<1. It's non-empty but has no identity element. If you replace < 1 with <=1 you will have an identity element but no other element is invertible.
Quoted 3 lines
And according to Wikipedia it's actually called D4.
There are 2 conventions for naming dihedral groups:
1) Geometrical: since dihedral group is a symetry group of a regular n-gone it's called D_n
2) Algebraical: since dihedral group has 2n elements it's called D_{2n} Sometimes these conventions bear to confusion.
Quoted 7 lines
Quoted 3 lines
compute transformations for mathematicians. Perhaps another representation of
D_8would result in more efficient code?If you have clearer explanation or more efficient code please share.
I was thinking of using 2 generators instead of 3:
1) standard generators: s=rot90 or rot270, t=any reflection. Then all elements are s^k or s^k*t. It makes computation of composition easier. Rules on generators are:
s^n=t^2=1
tst=s^{-1}
2) or using 2 reflections. E.g. u=| and v=/. You already figured how to generate with u=|, v=/, w=-
But w=uvuv
Then rules of computation are:
u^2=v^2=(uv)^4=1
Quoted 8 lines
Quoted 8 lines
include/grub/misc.h +8
-0+static inline long +grub_min (long x,long y) +{ +if (x > y) +return y; +else +return x; +}
Quoted 9 lines
Quoted 6 lines
+
Same hereinclude/grub/video.h +2
-0+ +int transform;I would prefer an enum
This is a bit field. How does it transform into an enum?
enum my_bitfield
{
MY_BITFIELD_NONE=0,
MY_BITFIELD_BIT0 = 1 << 0,
MY_BITFIELD_BIT1 = 1 << 1,
MY_BITFIELD_BIT2 = 1 << 2
};
Quoted 6 lines
I would rather get a patch with minimal changes first so that it's obvious what it does.
I can look into separating this later.
ok
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
2010/2/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 26 lines
Quoted 12 lines · Michal Suchanek
2010/2/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 10 lines
Quoted 8 lines · Michal Suchanek
Hello
Sending a preliminary framebuffer rotation patch.
You can use videotest to see 4 tiles rotated from the same bitmap data.
Quoted 10 lines
Quoted 6 lines
+char leaf_data[] = {
0x00,0x0f,0xe0,0x00,
+0x00,0x7f,0xfc,0x00,
+0x01,0xff,0xff,0x00,
+0x03,0xff,0xff,0x80,
This is a blob. Could it be generated automatically at build time?How less of a blob it would be if it was included as a bitmap?
It's not easily editable in current form.
Quoted 2 lines
This is just a shape used for the video tests.
Quoted 8 lines
Quoted 5 lines
There are some X tools for working with bitmaps/pixmaps which could generate this from a viewable file but they are usually not available on Windows and other non-X platforms AFAIK.
Using XBM is fine (it's easily editable in either gimp or emacs) and you should be able to
#include "leaf1.xbm"
That would work if XBM and grub did not have opposite bit order. The bytes are ordered the same but the bits are reversed.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Could you split addition of videotests from the rest of the patch?
Yes, there should be no problem with that.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
- unsigned int x;
- unsigned int y;
- unsigned int width;
- unsigned int height;
+ int x;
+ int y;
+ int width;
+ int height;
Why do you need negative values?
Quoted 7 lines
Quoted 4 lines
I don't need the negative values everywhere but this change was to align the typing so that casts are not required.
Perhaps few casts together with appropiate checks when casting is better than potentially exposing the whole code to the values it's not intended for.
How is it exposed to more unwanted values than now?
It uses the variables only to store the viewport dimensions and at most adds a border around it. The unsigned integer is able to represent values outside of the viewport as much as signed integers are, only signed integer can represent values outside of viewport in both directions. The unwanted values (if erroneously calculated which does not seem to be the case here) are clipped by the viewport clipping in video_fb.
On the other hand, there would be more than a few casts as the variables are used multiple times and the interface now uses signed integers.
Quoted 10 lines
Quoted 9 lines
Quoted 7 lines
+/* Supported operations are simple and easy to understand.
+ * MIRROR | swap image across (around) the vertical axis
+ * FLIP - swap image across the horizontal axis - upside down
+ * SWAP / swap image across the x=y axis - swap the x and y coordinates It's just aD_8group. Could you add a comment to functions what they do in group theoretical sense? It would make the code easier to follow andObviously it is a group,
Quoted 8 lines
Quoted 3 lines
any set of transforms closed on composition is.
Not true. Consider an example of empty set: it has no identity element. Less trivial counter-example: set of transformations: (x,y)->(kx,ky), 0<k<1. It's non-empty but has no identity element. If you replace < 1 with <=1 you will have an identity element but no other element is invertible.
It depends on your exact definition of group which somewhat varies but it is true that most definitions at least require the set to be non-empty.
Quoted 4 lines
Quoted 4 lines
If you have clearer explanation or more efficient code please share.
Quoted 11 lines
I was thinking of using 2 generators instead of 3:
1) standard generators: s=rot90 or rot270, t=any reflection. Then all elements are s^k or s^k*t. It makes computation of composition easier. Rules on generators are:
s^n=t^2=1
tst=s^{-1}
2) or using 2 reflections. E.g. u=| and v=/. You already figured how to generate with u=|, v=/, w=-
But w=uvuv
Then rules of computation are:
u^2=v^2=(uv)^4=1
This might be mathematically optimal but how that maps to actual efficient code?
In my view the v (and s) operations are expensive so I want to avoid them if possible.
This requires that both u and w be in the chosen set of generators because otherwise use of v or s twice is required to get one from the other. Using (u or w) and v as the two basic operations additionally requires composing generators in non-fixed order to get all the 8 possible combinations.
The other reason for having 3 generators is clear and efficient reperesentation of the 8 possible transformations. They are represented as bits in the bitmap where each bit specifies if the particular basic transform is included or not but they are always applied in fixed order and at most once.
Compare this to your representation of s^k,s^k*t where k is 0..3. Depending on representation the composition and inversion rules might still be somewhat non-trivial in actual code, using two reflections which require multiple applications of the two generators in particular order would lead to even more "interesting" code.
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
include/grub/misc.h +8
-0+static inline long +grub_min (long x,long y) +{ + if (x > y) + return y; + else + return x; +}Quoted 9 lines
Quoted 6 lines
+
Same here
+
+ int transform;
I would prefer an enumThis is a bit field. How does it transform into an enum?
Quoted 7 lines
enum
my_bitfield
{
MY_BITFIELD_NONE=0,
MY_BITFIELD_BIT0 = 1 << 0,
MY_BITFIELD_BIT1 = 1 << 1,
MY_BITFIELD_BIT2 = 1 << 2
};
The whole point of a bitfield is to have values like MY_BITFIELD_1_AND_2 = MY_BITFIELD_BIT1 | MY_BITFIELD_BIT2 which enum does not allow.
Thanks
Michal
Re: [RFC] Framebuffer rotation patch, or why 'unsigned' fails us
Quoted 34 lines · On Sat, 13 Feb 2010 18:29:41 +0100 Michal Suchanek <[email protected]> wrote:
2010/2/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 16 lines
Quoted 15 lines · Michal Suchanek
2010/2/11 Vladimir 'φ-coder/phcoder' Serbinenko
<[email protected]>:Quoted 11 lines
Michal Suchanek wrote:
- unsigned int x;
- unsigned int y;
- unsigned int width;
- unsigned int height;
+ int x;
+ int y;
+ int width;
+ int height;
Why do you need negative values?Quoted 7 lines
Quoted 4 lines
I don't need the negative values everywhere but this change was to align the typing so that casts are not required.
Perhaps few casts together with appropiate checks when casting is better than potentially exposing the whole code to the values it's not intended for.
How is it exposed to more unwanted values than now?
It uses the variables only to store the viewport dimensions and at most adds a border around it. The unsigned integer is able to represent values outside of the viewport as much as signed integers are, only signed integer can represent values outside of viewport in both directions. The unwanted values (if erroneously calculated which does not seem to be the case here) are clipped by the viewport clipping invideo_fb.
Quoted 3 lines
On the other hand, there would be more than a few casts as the variables are used multiple times and the interface now uses signed integers.
I have to chime in on this one since I've learned the hard way that 'unsigned' doesn't pull its weight in these use cases. Using unsigned integer values in C when a lot of arithmetic is performed (as in graphics programming) is really a nightmare. Well, maybe if you are a grand master C programmer you would remember when you need to cast and never make a mistake, but remember that there are us mere mortals who would benefit by more logical and predictable code behavior. (I use 'predictable' not in the sense that expressions involving both signed and unsigned values are have an undefined result, but rather that it's usually not the obvious result that the average C programmer would expect at first glance.
Certainly it would be nice if we could use the 'unsigned' qualifier to enforce an invariant requiring only non-negative values be stored in it (which it technically does, but it doesn't necessarily make the result any more correct). It almost never really fixes the kind of problems we'd like it to. We could easily try to store the result of a subtraction that conceptually should produce a negative value into an unsigned variable, and--OOPS!--we now have an enormous value instead of a negative value. Not much better. More significant is code that involves multiple operations such that the result of the entire expression should be nonnegative, but it involves temporary negative values in subexpressions such that the implicit signed-unsigned conversion produces the "wrong" result (i.e., not what the programmer intended even though the expression looks correct).
Let me quote an entry from my gfxmenu project journal, 31 May 2008:
It is worthwhile noting the potential perils of unsigned types in C (and C++). I spent a lot of time trying to figure out why my apparently simple code was not working. It turns out that I had expressions that combined signed and unsigned integral types. The unsigned types were the viewport origin/size, which GRUB defines to be unsigned, and one of the signed types was an offset that was added to the bitmap position during the animation. This offset had to be signed since it could be either positive or negative, depending on the present direction of the bitmap's movement. The final solution was to use signed types only. I read some discussions on signed vs. unsigned types and found this quote from Bjarne Stroustrup, which in my experience is wise advice:
The unsigned integer types are ideal for uses that treat storage as a bit array. Using an unsigned instead of an int to gain one more bit to represent positive integers is almost never a good idea. Attempts to ensure that some values are positive by declaring variables unsigned will typically be defeated by the implicit conversion rules.
Anyway, that's my two cents after having been bitten by arithmetic involving both signed an unsigned values. And it's tedious to go check the exact types of each value involved in an expression just to see what casts you might need to produce the right result, especially when the values involved are declared far away in some header file (i.e., structure members).
Regards,
Colin
Re: [RFC] Framebuffer rotation patch, or why 'unsigned' fails us
Quoted 53 lines · Colin D Bennett
Quoted 34 lines · On Sat, 13 Feb 2010 18:29:41 +0100 Michal Suchanek <[email protected]> wrote:
2010/2/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 16 lines
Quoted 15 lines · Michal Suchanek
2010/2/11 Vladimir 'φ-coder/phcoder' Serbinenko
<[email protected]>:Quoted 11 lines
Michal Suchanek wrote:
- unsigned int x;
- unsigned int y;
- unsigned int width;
- unsigned int height;
+ int x;
+ int y;
+ int width;
+ int height;
Why do you need negative values?Quoted 7 lines
Quoted 4 lines
I don't need the negative values everywhere but this change was to align the typing so that casts are not required.
Perhaps few casts together with appropiate checks when casting is better than potentially exposing the whole code to the values it's not intended for.
How is it exposed to more unwanted values than now?
It uses the variables only to store the viewport dimensions and at most adds a border around it. The unsigned integer is able to represent values outside of the viewport as much as signed integers are, only signed integer can represent values outside of viewport in both directions. The unwanted values (if erroneously calculated which does not seem to be the case here) are clipped by the viewport clipping invideo_fb.Quoted 3 lines
On the other hand, there would be more than a few casts as the variables are used multiple times and the interface now uses signed integers.
I have to chime in on this one since I've learned the hard way that 'unsigned' doesn't pull its weight in these use cases. Using unsigned integer values in C when a lot of arithmetic is performed (as in graphics programming) is really a nightmare. Well, maybe if you are a grand master C programmer you would remember when you need to cast and never make a mistake, but remember that there are us mere mortals who would benefit by more logical and predictable code behavior. (I use 'predictable' not in the sense that expressions involving both signed and unsigned values are have an undefined result, but rather that it's usually not the obvious result that the average C programmer would expect at first glance.
Quoted 14 lines
Certainly it would be nice if we could use the 'unsigned' qualifier to enforce an invariant requiring only non-negative values be stored in it (which it technically does, but it doesn't necessarily make the result any more correct). It almost never really fixes the kind of problems we'd like it to. We could easily try to store the result of a subtraction that conceptually should produce a negative value into an unsigned variable, and--OOPS!--we now have an enormous value instead of a negative value. Not much better. More significant is code that involves multiple operations such that the result of the entire expression should be nonnegative, but it involves temporary negative values in subexpressions such that the implicit signed-unsigned conversion produces the "wrong" result (i.e., not what the programmer intended even though the expression looks correct).
I started using negative integers because I need that rectangles overflowing to the top and left are not special and different from rectangles overflowing to the bottom and right as transforms might map the latter to the former.
This also enhances the video interface so that drawing at negative position is representable in the arguments. Iit is then possible to blit a bitmap without first clipping the topleft part by just blitting at negative position which should make some operations easier to carry out.
What is left unsigned is the framebuffer size in mode info and it indeed requires some casts and causes trouble. It made me change one of the transform routines to asymmetric types because it is used (almost) exclusively on the mode info structure. The members of mode_info should not ever become negative, though and the unsigned type is probably meant to make that clear. I can't say if making that clear outweights the possible issues when using the values in calculations.
Thanks
Michal
Re: [RFC] Framebuffer rotation patch, or why 'unsigned' fails us
Quoted 8 lines · On Mon, 15 Feb 2010 19:14:57 +0100 Michal Suchanek <[email protected]> wrote:
What is left unsigned is the framebuffer size in mode info and it indeed requires some casts and causes trouble. It made me change one of the transform routines to asymmetric types because it is used (almost) exclusively on the mode info structure. The members of
mode_infoshould not ever become negative, though and the unsigned type is probably meant to make that clear. I can't say if making that clear outweights the possible issues when using the values in calculations.
I think it is obvious that width and height values are never negative. Since the data type (unsigned) is only visible the to programmer in the declaration of the struct, not in uses of its members, I think it would be just as effective to declare such values as signed types with a comment at the declaration like "/* Nonnegative */" to make it clear, and this would avoid signed/unsigned conversion/comparision problems.
Regards,
Colin
Re: [RFC] Framebuffer rotation patch, or why 'unsigned' fails us
In reply to Michal SuchanekQuoted 6 lines · Michal Suchanek
This also enhances the video interface so that drawing at negative position is representable in the arguments. Iit is then possible to blit a bitmap without first clipping the topleft part by just blitting at negative position which should make some operations easier to carry out.
It's a good reason then. Just be sure that every code reacts sanely to negative integers either by sanitising or correctly handling
Quoted 7 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
Re: [RFC] Framebuffer rotation patch, or why 'unsigned' fails us
2010/2/16 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 9 lines
Quoted 6 lines · Michal Suchanek
This also enhances the video interface so that drawing at negative position is representable in the arguments. Iit is then possible to blit a bitmap without first clipping the topleft part by just blitting at negative position which should make some operations easier to carry out.
It's a good reason then. Just be sure that every code reacts sanely to negative integers either by sanitising or correctly handling
Actually it was possible to blit a bitmap at negative position but it was not possile to draw a rectangle at the same position which was somewhat odd.
Thanks
Michal
Quoted 133 lines · Michal Suchanek
2010/2/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 38 lines
Quoted 15 lines · Michal Suchanek
2010/2/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 12 lines
Quoted 9 lines · Michal Suchanek
Hello
Sending a preliminary framebuffer rotation patch.
You can use videotest to see 4 tiles rotated from the same bitmap data.
Quoted 11 lines
Quoted 7 lines
commands/videotest.c +4
-0+char leaf_data[] = {0x00 ,0x0f ,0xe0 ,0x00 , +0x00 ,0x7f ,0xfc ,0x00 , +0x01 ,0xff ,0xff ,0x00 , +0x03 ,0xff ,0xff ,0x80 ,This is a blob. Could it be generated automatically at build time?
How less of a blob it would be if it was included as a bitmap?
It's not easily editable in current form.
Quoted 8 lines
This is just a shape used for the video tests.
There are some X tools for working with bitmaps/pixmaps which could generate this from a viewable file but they are usually not available on Windows and other non-X platforms AFAIK.
Quoted 4 lines
Using XBM is fine (it's easily editable in either gimp or emacs) and you should be able to
#include "leaf1.xbm"That would work if XBM and grub did not have opposite bit order. The bytes are ordered the same but the bits are reversed.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Could you split addition of videotests from the rest of the patch?
Yes, there should be no problem with that.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
commands/videotest.c +4
-4-unsigned int x; -unsigned int y; -unsigned int width; -unsigned int height; +int x; +int y; +int width; +int height;Why do you need negative values?
Quoted 9 lines
Quoted 5 lines
I don't need the negative values everywhere but this change was to align the typing so that casts are not required.
Perhaps few casts together with appropiate checks when casting is better than potentially exposing the whole code to the values it's not intended for.
How is it exposed to more unwanted values than now?
It uses the variables only to store the viewport dimensions and at most adds a border around it. The unsigned integer is able to represent values outside of the viewport as much as signed integers are, only signed integer can represent values outside of viewport in both directions. The unwanted values (if erroneously calculated which does not seem to be the case here) are clipped by the viewport clipping invideo_fb.On the other hand, there would be more than a few casts as the variables are used multiple times and the interface now uses signed integers.
Quoted 14 lines
Quoted 8 lines
Quoted 8 lines
+/* Supported operations are simple and easy to understand.
+ * MIRROR | swap image across (around) the vertical axis + * FLIP - swap image across the horizontal axis - upside down + * SWAP / swap image across the x=y axis - swap the x and y coordinatesIt's just a
D_8group. Could you add a comment to functions what they do in group theoretical sense? It would make the code easier to follow andQuoted 6 lines
Obviously it is a group,
any set of transforms closed on composition is.
Quoted 6 lines
Not true. Consider an example of empty set: it has no identity element. Less trivial counter-example: set of transformations: (x,y)->(kx,ky), 0<k<1. It's non-empty but has no identity element. If you replace < 1 with <=1 you will have an identity element but no other element is invertible.
It depends on your exact definition of group which somewhat varies but it is true that most definitions at least require the set to be non-empty.
Quoted 4 lines
Quoted 4 lines
If you have clearer explanation or more efficient code please share.
Quoted 12 lines
I was thinking of using 2 generators instead of 3:
1) standard generators: s=rot90 or rot270, t=any reflection. Then all elements are s^k or s^k*t. It makes computation of composition easier. Rules on generators are:
s^n=t^2=1
tst=s^{-1}
2) or using 2 reflections. E.g. u=| and v=/. You already figured how to generate with u=|, v=/, w=-
But w=uvuv
Then rules of computation are:
u^2=v^2=(uv)^4=1
Quoted 5 lines
This might be mathematically optimal but how that maps to actual efficient code?
In my view the v (and s) operations are expensive so I want to avoid them if possible.
I actualy though of using preprocessor magic to make 8 blitting functions. I don't insist on any particular group representation, just want to be sure you take it into account.
Quoted 12 lines
This requires that both u and w be in the chosen set of generators because otherwise use of v or s twice is required to get one from the other. Using (u or w) and v as the two basic operations additionally requires composing generators in non-fixed order to get all the 8 possible combinations.
The other reason for having 3 generators is clear and efficient reperesentation of the 8 possible transformations. They are represented as bits in the bitmap where each bit specifies if the particular basic transform is included or not but they are always applied in fixed order and at most once.
Quoted 7 lines
Compare this to your representation of s^k,s^k*t where k is 0..3. Depending on representation the composition and inversion rules might still be somewhat non-trivial in actual code, using two reflections which require multiple applications of the two generators in particular order would lead to even more "interesting" code.
You don't have to use same representation through whole code
Quoted 27 lines
Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
include/grub/misc.h +8
-0+static inline long +grub_min (long x,long y) +{ +if (x > y) +return y; +else +return x; +}Quoted 10 lines
Quoted 7 lines
+
Same hereinclude/grub/video.h +2
-0+ +int transform;I would prefer an enum
This is a bit field. How does it transform into an enum?
Quoted 8 lines
enum
my_bitfield
{
MY_BITFIELD_NONE=0,
MY_BITFIELD_BIT0= 1 << 0,
MY_BITFIELD_BIT1= 1 << 1,
MY_BITFIELD_BIT2= 1 << 2
};
Quoted 4 lines
The whole point of a bitfield is to have values like
MY_BITFIELD_1_AND_2=MY_BITFIELD_BIT1|MY_BITFIELD_BIT2which enum does not allow.
enum allows it just fine
Quoted 11 lines
Thanks
Michal
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
2010/2/16 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 17 lines
Quoted 16 lines · Michal Suchanek
2010/2/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 1 line
Michal Suchanek wrote:
This requires that both u and w be in the chosen set of generators because otherwise use of v or s twice is required to get one from the other. Using (u or w) and v as the two basic operations additionally requires composing generators in non-fixed order to get all the 8 possible combinations.
The other reason for having 3 generators is clear and efficient reperesentation of the 8 possible transformations. They are represented as bits in the bitmap where each bit specifies if the particular basic transform is included or not but they are always applied in fixed order and at most once.
Quoted 8 lines
Quoted 7 lines
Compare this to your representation of s^k,s^k*t where k is 0..3. Depending on representation the composition and inversion rules might still be somewhat non-trivial in actual code, using two reflections which require multiple applications of the two generators in particular order would lead to even more "interesting" code.
You don't have to use same representation through whole code
I don't see any benefit in changing it and it would make the code harder to understand.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 1 line
enum
my_bitfield
{
MY_BITFIELD_NONE=0,
MY_BITFIELD_BIT0 = 1 << 0,
MY_BITFIELD_BIT1 = 1 << 1,
MY_BITFIELD_BIT2 = 1 << 2
};
Quoted 5 lines
Quoted 4 lines
The whole point of a bitfield is to have values like
MY_BITFIELD_1_AND_2=MY_BITFIELD_BIT1|MY_BITFIELD_BIT2which enum does not allow.enum allows it just fine
Not here:
typedef enum t1 { BTI1 = 1,
BIT2 = 2,
BIT12 = BIT1 + BIT2} t;int main(int argc, char** argv) { return 0 ; }
testenum.c:3: error: ‘BIT1’ undeclared here (not in a function)
Thanks
Michal
Quoted 5 lines · Michal Suchanek
Quoted 1 line
enum allows it just fine
Not here:
typedef enum t1 { BTI1 = 1,
typo, should be "BIT1". then it works. (In C. Also remember not to get confused by the fact that it doesn't work in C++, for type-related reasons that we don't need to get into here because GRUB is written in C.)
Quoted 6 lines
BIT2 = 2, BIT12 = BIT1 + BIT2} t;int
main(int argc, char** argv){ return 0 ; }testenum.c:3: error: ‘BIT1’ undeclared here (not in a function)
-Isaac
Quoted 10 lines · Isaac Dupree
Quoted 6 lines · Michal Suchanek
Quoted 2 lines
enum allows it just fine
Not here:
typedef enum t1 { BTI1 = 1,
typo, should be "BIT1". then it works. (In C. Also remember not to get confused by the fact that it doesn't work in C++, for type-related reasons
Says who?
Comeau is perfectly happy with this code, in strict C++ mode:
enum flags
{
BIT1 = 1,
BIT2 = 2,
BIT12 = BIT1 | BIT2
};
int main(int argc, char** argv) { return 0 ; }
[Off-topic] C++ enums
Quoted 6 lines · On 02/16/10 13:15, [email protected] wrote:
Quoted 4 lines · Isaac Dupree
Quoted 3 lines · Michal Suchanek
Quoted 2 lines
enum allows it just fine
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Not here:
typedef enum t1 { BTI1 = 1,
typo, should be "BIT1". then it works. (In C. Also remember not to get confused by the fact that it doesn't work in C++, for type-related reasons
Says who?
OK, I guess I'll get into it, since you asked...
Quoted 8 lines
Comeau is perfectly happy with this code, in strict C++ mode:
enum flags
{ BIT1 = 1, BIT2 = 2, BIT12 = BIT1 | BIT2 };
In C and C++, enums are their own type distinct from int. In C, there exist implicit conversions both from and to all enum types and int. In C++, there only exist implicit conversions from enum types to int. Bitwise and arithmetic operators only operate on int, not enum types (unless a C++ operator overload is declared); these operators appear to work with enums because of all the implicit conversion.
Your example works even in C++ because the right-hand side of an "=" in an enum-declaration is of type int, rather than the enum type (as you can see from the fact that you can put "1" there as well). Now BIT1, BIT2, and BIT12 are all (in C++) values (rvalues) of type "flags" (note this does not apply to the left-hand sides in the enum declaration that define their constant values, but it does apply to those right-hand sides).
Now try and combine your with this main function:
int main(int argc, char** argv) {
flags foo1 = BIT1; // fine
flags foo12 = BIT12; // fine
int bar = BIT1 | BIT2; // fine
flags baz = BIT1 | BIT2; // error
return 0 ;
}
(If you want to see it compile in C, add "typedef enum flags flags;" before main().)
See http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.19 for some discussion by a C++ expert. And then return to GRUB2 coding where none of this matters. The only weird thing about enums in C is that they're not guaranteed by the standard to be isomorphic to type "int"; each enum might correspond to a different-size, (possibly even different-signedness), integral type, if this is possible given the range of values in the particular "enum{...};" declaration. (This weird thing also affects C++ but I omitted it in the above explanation of enum versus integral types.)
-Isaac
2010/2/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 40 lines
Quoted 7 lines · Michal Suchanek
Hello
Sending a preliminary framebuffer rotation patch.
You can use videotest to see 4 tiles rotated from the same bitmap data.
+char leaf_data[] = {
0x00,0x0f,0xe0,0x00,
+0x00,0x7f,0xfc,0x00,
+0x01,0xff,0xff,0x00,
+0x03,0xff,0xff,0x80,
This is a blob. Could it be generated automatically at build time? +
+ sans =grub_font_get("Helvetica Bold 14");
Please use free font rather than Helvetica
Could you split addition of videotests from the rest of the patch?
- unsigned int x;
- unsigned int y;
- unsigned int width;
- unsigned int height;
+ int x;
+ int y;
+ int width;
+ int height;
Why do you need negative values?
+/* Supported operations are simple and easy to understand.
+ * MIRROR | swap image across (around) the vertical axis
+ * FLIP - swap image across the horizontal axis - upside down
+ * SWAP / swap image across the x=y axis - swap the x and y coordinates It's just aD_8group. Could you add a comment to functions what they do in group theoretical sense? It would make the code easier to follow and compute transformations for mathematicians. Perhaps another representation ofD_8would result in more efficient code? +static inline voidgrub_swap_int(int *a, int *b){ int tmp = *a; *a = *b; *b = tmp; }
+static inline voidgrub_swap_unsigned(unsigned *a, unsigned *b){ unsigned tmp = *a; *a = *b; *b = tmp; }
+
With typeof macro this can be made type-neutral avoiding potential mistakes.
include/grub/misc.h grub_max (long x, long y) · line 223
Quoted 9 lines
include/grub/misc.h +9
-0+static inline long +grub_min (long x,long y) +{ + if (x > y) + return y; + else + return x; +} +
I don't see how typeof would be used. As I understand the docs it can only set types relative to something what is already defined (and in some cases actually dereference/call it) and there is nothing defined at the point these functions are declared to copy the type from.
Still the grub_min being long is somewhat suspicious. iirc I just reused an existing function or copied grub_max.
If declaring it as long can cause problems then its utility as a general purpose function is dubious.
Thanks
Michal
Quoted 8 lines · Michal Suchanek
Quoted 8 lines
With typeof macro this can be made type-neutral avoiding potential mistakes.
include/grub/misc.h +7
-0+static inline long +grub_min (long x,long y) +{ +if (x > y) +return y; +else +return x;
Quoted 9 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+} +I don't see how typeof would be used. As I understand the docs it can only set types relative to something what is already defined (and in some cases actually dereference/call it) and there is nothing defined at the point these functions are declared to copy the type from.
#include <stdio.h>
#define swap(a,b) {typeof (a) mytemp ## __LINE__; mytemp ## __LINE__ = b; b = a; a = mytemp ## __LINE__; }
int
main ()
{
int x = 1, y = 2;
swap (x,y);
printf ("%d, %d\n", x, y);
}
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
2010/2/16 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 18 lines
Quoted 8 lines · Michal Suchanek
Quoted 8 lines
With typeof macro this can be made type-neutral avoiding potential mistakes.
include/grub/misc.h +7
-0+static inline long +grub_min (long x,long y) +{ + if (x > y) + return y; + else + return x;Quoted 9 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+} +I don't see how typeof would be used. As I understand the docs it can only set types relative to something what is already defined (and in some cases actually dereference/call it) and there is nothing defined at the point these functions are declared to copy the type from.
Quoted 4 lines
#include <
stdio.h>
#defineswap(a,b){typeof (a) mytemp ##__LINE__; mytemp ##__LINE__= b; b = a; a = mytemp ##__LINE__; }
Unlike inlines this pollutes the local namespace with unexpected identifiers.. Perhaps the temporary variable should be at least prefixed with an underscore or something.
But if that is ok then perhaps the existing functions in include/grub/misc.h should be converted.
There is grub_max, grub_abs and grub_div_roundup already.
Thanks
Michal
Quoted 19 lines · Michal Suchanek
2010/2/16 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 18 lines
Quoted 17 lines · Michal Suchanek
include/grub/misc.h grub_max (long x, long y) · line 223
Quoted 11 lines
With typeof macro this can be made type-neutral avoiding potential mistakes.
include/grub/misc.h +9
-0+static inline long +grub_min (long x,long y) +{ + if (x > y) + return y; + else + return x; +} +I don't see how typeof would be used. As I understand the docs it can only set types relative to something what is already defined (and in some cases actually dereference/call it) and there is nothing defined at the point these functions are declared to copy the type from.
Quoted 8 lines
Quoted 4 lines
#include <
stdio.h>
#defineswap(a,b){typeof (a) mytemp ##__LINE__; mytemp ##__LINE__= b; b = a; a = mytemp ##__LINE__; }Unlike inlines this pollutes the local namespace with unexpected identifiers.. Perhaps the temporary variable should be at least prefixed with an underscore or something.
The braces introduce a block and the variable goes out of scope, in fact there's no need for __LINE__ because of this.
Quoted 25 lines · On 16 February 2010 22:14, [email protected] <[email protected]>…
Quoted 24 lines · Michal Suchanek
2010/2/16 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 22 lines
Quoted 8 lines · Michal Suchanek
Quoted 8 lines
With typeof macro this can be made type-neutral avoiding potential mistakes.
include/grub/misc.h +7
-0+static inline long +grub_min (long x,long y) +{ + if (x > y) + return y; + else + return x;Quoted 9 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+} +I don't see how typeof would be used. As I understand the docs it can only set types relative to something what is already defined (and in some cases actually dereference/call it) and there is nothing defined at the point these functions are declared to copy the type from.
#include <
stdio.h>
#defineswap(a,b){typeof (a) mytemp ##__LINE__; mytemp ##__LINE__= b; b = a; a = mytemp ##__LINE__; }
Quoted 6 lines
Quoted 3 lines
Unlike inlines this pollutes the local namespace with unexpected identifiers.. Perhaps the temporary variable should be at least prefixed with an underscore or something.
The braces introduce a block and the variable goes out of scope, in fact there's no need for
__LINE__because of this.
It breaks things when you do have a mytemp already:
$ gcc -Wall testdef.c
$ ./a.out
2 1 3 4
$ cat testdef.c
#include <stdio.h>
#define swap(a,b) {typeof (a) mytemp; mytemp = b; b = a; a = mytemp; }int main( int argc, char ** argv)
{
int x=1, y=2, z=3, mytemp=4;
swap(x,y);
swap(z,mytemp);
return printf("%i %i %i %i\n", x, y, z, mytemp);
}
Thanks
Michal
Quoted 24 lines · Michal Suchanek
2010/2/16 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 18 lines
Quoted 8 lines · Michal Suchanek
Quoted 8 lines
With typeof macro this can be made type-neutral avoiding potential mistakes.
include/grub/misc.h +7
-0+static inline long +grub_min (long x,long y) +{ + if (x > y) + return y; + else + return x;Quoted 9 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+} +I don't see how typeof would be used. As I understand the docs it can only set types relative to something what is already defined (and in some cases actually dereference/call it) and there is nothing defined at the point these functions are declared to copy the type from.
Quoted 4 lines
#include <
stdio.h>
#defineswap(a,b){typeof (a) mytemp ##__LINE__; mytemp ##__LINE__= b; b = a; a = mytemp ##__LINE__; }
Quoted 8 lines
Unlike inlines this pollutes the local namespace with unexpected identifiers.. Perhaps the temporary variable should be at least prefixed with an underscore or something.
But if that is ok then perhaps the existing functions in
include/grub/misc.hshould be converted.There is
grub_max,grub_absandgrub_div_roundupalready.
Hmm, we don't have stdio.h in grub.
Perhaps it's no that good idea after all.
Thanks
Michal