Sample Code for 2D graphic acceleration of pxa300/310

Source: Internet
Author: User

Indicate the source and author's contact information during reprinting.
Article Source: http://www.limodev.cn/blog
Contact information of the author: Li xianjing <xianjimli at Hotmail dot com>

The first time I used the pxa300/310 2D Graphics Accelerator library, it was a little troublesome. One problem is that the scaling function does not work at all. As long as the system does not move after the scaling function is executed, it takes two days to figure out the cause (datasheet is too long, otherwise, it will take two days to read the datasheet ). No relevant information can be found online. Here is a test program for your reference (if you are interested, you can test it with the new version of broncho A1 ).
# Include <stdio. h> <br/> # include <stdlib. h> <br/> # include <unistd. h> <br/> # include "m2d_lib.h" </P> <p> # define fb_w 320 <br/> # define fb_h 480 </P> <p> void test_fill (struct m2d_context * CTX, struct m2d_buff * SRC, int W, int H, gcu_pixel_format format, gcu_color_value color) <br/>{< br/> int ret = 0; <br/> struct m2d_op_region region; <br/> memset (& region, 0x00, sizeof (region); <br/> region. width = W; <br/> region. height = H; </P> <p> ret = m2d_set_dstbuf2 (CTX, Src); <br/> ret = m2d_set_fill_color (CTX, format, color ); <br/> ret = m2d_color_fill (CTX, & Region); </P> <p> ret = m2d_set_dstbuf2 (CTX, Src); <br/> m2d_set_line_width (CTX, 2); <br/> ret = m2d_set_line_color (CTX, format, 0xff); <br/> ret = m2d_draw_line (CTX, W/4, 0, W/4, h-1); <br/> ret = m2d_draw_line (CTX, W/2, 0, W/2, h-1); <br/> ret = m2d_draw_line (CTX, 3 * w/4, 0, 3 * w/4, h-1); </P> <p> ret = m2d_sync (CTX); </P> <p> return; <br/>}</P> <p> void test_stretch (struct m2d_context * CTX, struct m2d_buff * FB, struct m2d_buff * SRC) <br/> {<br/> int ret = 0; <br/> struct m2d_op_region region; <br/> printf ("% s: % d/N ", _ FUNC __, _ line _); <br/> memset (& region, 0x00, sizeof (region); <br/> region. width = fb_w/4; <br/> region. height = fb_h/4; <br/> ret = m2d_set_srcbuf0 (CTX, Src); <br/> ret = m2d_set_dstbuf2 (CTX, FB ); <br/> ret = m2d_stretch_blt (CTX, & region, fb_w, fb_h); <br/> ret = m2d_submit (CTX); </P> <p> return; <br/>}</P> <p> void test_decimate (struct m2d_context * CTX, struct m2d_buff * FB, struct m2d_buff * SRC) <br/> {<br/> int ret = 0; <br/> struct m2d_op_region region; <br/> printf ("% s: % d/N ", _ FUNC __, _ line _); <br/> memset (& region, 0x00, sizeof (region); <br/> region. width = fb_w/2; <br/> region. height = fb_h/2; <br/> ret = m2d_set_srcbuf0 (CTX, Src); <br/> ret = m2d_set_dstbuf2 (CTX, FB ); <br/> ret = m2d_decimate_blt (CTX, & region, fb_w/2, fb_h/2); <br/> ret = m2d_submit (CTX ); </P> <p> return; <br/>}</P> <p> void test_scale (struct m2d_context * CTX, struct m2d_buff * FB, struct m2d_buff * SRC) <br/> {<br/> int ret = 0; <br/> struct m2d_op_region region; <br/> printf ("% s: % d/N ", _ FUNC __, _ line _); <br/> memset (& region, 0x00, sizeof (region); <br/> region. width = FB_W-1; <br/> region. height = FB_H-1; <br/> ret = m2d_set_srcbuf0 (CTX, Src); <br/> ret = m2d_set_dstbuf2 (CTX, FB); <br/> ret = m2d_scale_blt (CTX, & region, 0x100); <br/> ret = m2d_submit (CTX); </P> <p> return; <br/>}</P> <p> void test_bias (struct m2d_context * CTX, struct m2d_buff * FB, struct m2d_buff * SRC) <br/> {<br/> int ret = 0; <br/> struct m2d_op_region region; <br/> printf ("% s: % d/N ", _ FUNC __, _ line _); <br/> memset (& region, 0x00, sizeof (region); <br/> region. width = FB_W-1; <br/> region. height = FB_H-1; <br/> ret = m2d_set_srcbuf0 (CTX, Src); <br/> ret = m2d_set_dstbuf2 (CTX, FB); <br/> ret = m2d_bias_blt (CTX, & region, 0); <br/> ret = m2d_submit (CTX); </P> <p> return; <br/>}</P> <p> void test_rotate (struct m2d_context * CTX, struct m2d_buff * FB, struct m2d_buff * SRC, int W, int H, gcu_rotation rot) <br/> {<br/> int ret = 0; <br/> struct m2d_op_region region; <br/> printf ("% s: % d/N ", _ FUNC __, _ line _); <br/> memset (& region, 0x00, sizeof (region); <br/> region. width = W; <br/> region. height = H; <br/> ret = m2d_set_srcbuf0 (CTX, Src); <br/> ret = m2d_set_dstbuf2 (CTX, FB); <br/> ret = m2d_rotate_blt (CTX, & region, rot); <br/> ret = m2d_submit (CTX); </P> <p> return; <br/>}</P> <p> gcu_color_value BG [] = {0 xFFFF, 0x1f, 0x7e0, 0xf40000, 0x00 }; <br/> int main (INT argc, char * argv []) <br/>{< br/> struct m2d_context * CTX = m2d_create_context (); <br/> struct m2d_buff * Fb = m2d_get_primary (); <br/> struct m2d_buff * src = m2d_alloc_buffer (CTX, fb_w, fb_h, gcu_pxlfmt_rgb565 ); <br/> struct m2d_buff * rsrc = m2d_alloc_buffer (CTX, fb_h, fb_w, gcu_pxlfmt_rgb565); </P> <p> test_fill (CTX, FB, fb_w, fb_h, callback, 0 xFFFF); <br/> test_fill (CTX, SRC, fb_w, fb_h, gcu_pxlfmt_rgb565, 0xf800); <br/> test_scale (CTX, FB, Src ); </P> <p> sleep (1); <br/> test_fill (CTX, FB, fb_w, fb_h, gcu_pxlfmt_rgb565, 0 xFFFF ); <br/> sleep (1); <br/> test_fill (CTX, SRC, fb_w, fb_h, gcu_pxlfmt_rgb565, 0x7e0); <br/> test_bias (CTX, FB, SRC); </P> <p> sleep (1); <br/> test_fill (CTX, FB, fb_w, fb_h, gcu_pxlfmt_rgb565, 0 xFFFF ); <br/> sleep (1); <br/> test_fill (CTX, SRC, fb_w, fb_h, gcu_pxlfmt_rgb565, 0xf800); <br/> test_stretch (CTX, FB, SRC); </P> <p> sleep (1); <br/> test_fill (CTX, FB, fb_w, fb_h, gcu_pxlfmt_rgb565, 0 xFFFF ); <br/> sleep (1); <br/> test_fill (CTX, SRC, fb_w, fb_h, gcu_pxlfmt_rgb565, 0x7e0); <br/> test_decimate (CTX, FB, SRC); </P> <p> sleep (1); <br/> test_fill (CTX, FB, fb_w, fb_h, gcu_pxlfmt_rgb565, 0 xFFFF ); <br/> sleep (1); <br/> test_fill (CTX, rsrc, fb_h, fb_w, gcu_pxlfmt_rgb565, 0xf800); <br/> test_rotate (CTX, FB, rsrc, fb_h, fb_w, gcu_rotate_90); <br/> sleep (1); </P> <p> test_fill (CTX, FB, fb_w, fb_h, gcu_pxlfmt_rgb565, 0 xFFFF ); <br/> sleep (1); <br/> test_fill (CTX, rsrc, fb_h, fb_w, gcu_pxlfmt_rgb565, 0xf800); <br/> test_rotate (CTX, FB, rsrc, fb_h, fb_w, gcu_rotate_270); <br/> sleep (1); </P> <p> test_fill (CTX, FB, fb_w, fb_h, gcu_pxlfmt_rgb565, 0 xFFFF ); <br/> sleep (1); <br/> test_fill (CTX, SRC, fb_w, fb_h, gcu_pxlfmt_rgb565, 0xf800); <br/> test_rotate (CTX, FB, SRC, fb_w, fb_h, gcu_rotate_0); <br/> sleep (1); </P> <p> test_fill (CTX, FB, fb_w, fb_h, gcu_pxlfmt_rgb565, 0 xFFFF ); <br/> sleep (1); <br/> test_fill (CTX, SRC, fb_w, fb_h, gcu_pxlfmt_rgb565, 0xf800); <br/> test_rotate (CTX, FB, SRC, fb_w, fb_h, gcu_rotate_180); <br/> sleep (1); </P> <p> m2d_free_buffer (CTX, Src); <br/> m2d_free_buffer (CTX, rsrc); <br/> m2d_free_context (CTX); </P> <p> return 0; <br/>}< br/>
Note:
1. If you want to execute the command immediately, call m2d_submit (CTX ).
2. The scaling width is limited. For details about the parameters, see datasheet.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.