Rendering Buffer)

Source: Internet
Author: User
Document directory
  • External and GDI display
Rendering Buffer

Rendering Buffer is a memory block used to store image data. This is a bridge between the memory and the monitor. We need to display the memory image to identify the memory block and display it using the system API (in fact, there is almost no need to do the conversion work, because the image storage format used by the API is compatible with Rendering Buffer in both Windows and Linux ).

Header file:
#include "agg_rendering_buffer.h"
Type:

Rendering_buffer
Constructor:

rendering_buffer(int8u* buf, unsigned width, unsigned height, int stride);

The parameter represents the memory block pointer, width, height, and stride of each row respectively (when the stride is <0, it indicates that the stride is upside down)

Member method:
VoidAttach(Int8u * Buf, unsigned width, unsigned height, int STRIDE ); The parameters are the same as those of the constructor.
Int8u *Buf(); Return memory block pointer
UnsignedWidth() Const;
UnsignedHeight() Const;
IntStride() Const;
UnsignedStride_abs() Const;
Returns the width, height, and stride of each row.
Int8u *Row_ptr(INT y) Returns the pointer pointing to the starting point of row y.
VoidClear(Int8u value) Fill the entire memory block with the value
Template <class renbuf> voidCopy_from(Const renbuf & SRC) Copy data from another rendering_buffer
Lab code (based on the code here)

Add the following at the end of the on_draw () method:

  1. Rows: int8u * P = rbuf. row_ptr (20); // get the 20th rows pointer.
  2. Memset (p, 0, rbuf. stride_abs (); // fill the whole row with 0
The resulting figure is:


External and GDI display

The image storage method of Rendering Buffer is the same as that of Windows BMP, so it is very easy for the handler to process BMP. The following Code demonstrates how to display the handler on HDC.

  1. # Include <agg_rendering_buffer.h>
  2. # Include <agg_pixfmt_rgba.h>
  3. # Include <agg_renderer_base.h>
  4. # Include <agg_rasterizer_scanline_aa.h>
  5. # Include <agg_scanline_p.h>
  6. ...
  7. // First, let the system generate a 32-bit BMP Cache
  8. Bitmapinfo BMP _info;
  9. BMP _info.bmiheader.bisize = sizeof (bitmapinfoheader );
  10. BMP _info.bmiheader.biwidth = width;
  11. BMP _info.bmiheader.biheight = height;
  12. BMP _info.bmiheader.biplanes = 1;
  13. BMP _info.bmiheader.bibitcount = 32;
  14. BMP _info.bmiheader.bicompression = bi_rgb;
  15. BMP _info.bmiheader.bisizeimage = 0;
  16. BMP _info.bmiheader.bixpelspermeter = 0;
  17. BMP _info.bmiheader.biypelspermeter = 0;
  18. BMP _info.bmiheader.biclrused = 0;
  19. BMP _info.bmiheader.biclrimportant = 0;
  20. HDC mem_dc =: createcompatibledc (HDC );
  21. Void * Buf = 0;
  22. Hbitmap BMP =: createdibsection (
  23. Mem_dc,
  24. & BMP _info,
  25. Dib_rgb_colors,
  26. & Buf,
  27. 0,
  28. 0
  29. );
  30. // Associate BMP with mem_dc so that the worker can work with native GDI.
  31. Hbitmap temp = (hbitmap): SelectObject (mem_dc, BMP );
  32. // ================================================ ======================================
  33. // The following is the response code
  34. Expiration: rendering_buffer rbuf;
  35. // 32-Bit Bitmap. The number of bytes in each row is width * 4.
  36. // BMP is inverted. In order to be the same as that of GDI, the last parameter is a negative value.
  37. Rbuf. Attach (unsigned char *) BUF, width, height,-width * 4 );
  38. // Pixel format and renderer_base
  39. Authorization: pixfmt_bgra32 pixf (rbuf );
  40. Expiration: renderer_base <Expiration: pixfmt_bgra32> renb (pixf );
  41. Renb. Clear (partition: rgba8 (255,255,255,255 ));
  42. // Scanline Renderer
  43. Principal: renderer_scanline_aa_solid <principal: renderer_base <principal: pixfmt_bgra32> Ren (renb );
  44. // Rasterizer & scanline
  45. Authorization: rasterizer_scanline_aa <> RAS;
  46. Authorization: scanline_p8 SL;
  47. // Multidefinition line (triangle)
  48. RAS. move_to_d (20.7, 34.15 );
  49. RAS. line_to_d (398.23, 123.43 );
  50. RAS. line_to_d (165.45, 401.87 );
  51. // Set the color before rendering
  52. Ren. color (gradient: rgba8 (80, 90, 60 ));
  53. Expiration: render_scanlines (Ras, SL, Ren );
  54. // ================================================ ======================================
  55. // Display BMP to HDC. If the image contains an alpha channel, use alphablend instead of bitblt.
  56. : Bitblt (
  57. HDC,
  58. Rt. Left,
  59. Rt. Top,
  60. Width,
  61. Height,
  62. Mem_dc,
  63. 0,
  64. 0,
  65. Srccopy
  66. );
  67. // Release resources
  68. : SelectObject (mem_dc, temp );
  69. : Deleteobject (BMP );
  70. : Deleteobject (mem_dc );
The resulting figure is:

Use the pixel_map class provided by workers

If you think the above method is still a little annoying (it is too troublesome to blame Ms's API), you can consider using the pixel_map class provided by ghost friendship, it is much easier to use it to operate BMP. (Add [encoding]/src/platform/Win32/agg_win32_bmp .cpp for compilation)

  1. # Include <agg_rendering_buffer.h>
  2. # Include <agg_pixfmt_rgba.h>
  3. # Include <agg_renderer_base.h>
  4. # Include <agg_rasterizer_scanline_aa.h>
  5. # Include <agg_scanline_p.h>
  6. # Include <platform/Win32/agg_win32_bmp .h>
  7. ...
  8. Crect RC;
  9. Getclientrect (& rc );
  10. Usage: pixel_map PM;
  11. PM. Create (RC. Right, RC. Bottom, callback: org_color32 );
  12. // ================================================ ======================================
  13. // The following is the response code
  14. Expiration: rendering_buffer rbuf;
  15. Rbuf. Attach (PM. Buf (), PM. Width (), PM. Height (),-PM. stride ());
  16. // Pixel format and renderer_base
  17. Authorization: pixfmt_bgra32 pixf (rbuf );
  18. Expiration: renderer_base <Expiration: pixfmt_bgra32> renb (pixf );
  19. Renb. Clear (partition: rgba8 (255,255,255,255 ));
  20. // Scanline Renderer
  21. Principal: renderer_scanline_aa_solid <principal: renderer_base <principal: pixfmt_bgra32> Ren (renb );
  22. // Rasterizer & scanline
  23. Authorization: rasterizer_scanline_aa <> RAS;
  24. Authorization: scanline_p8 SL;
  25. // Multidefinition line (triangle)
  26. RAS. move_to_d (20.7, 34.15 );
  27. RAS. line_to_d (398.23, 123.43 );
  28. RAS. line_to_d (165.45, 401.87 );
  29. // Set the color before rendering
  30. Ren. color (gradient: rgba8 (80, 90, 60 ));
  31. Expiration: render_scanlines (Ras, SL, Ren );
  32. // ================================================ ======================================
  33. PM. Draw (HDC );

Pending

 

Author: Mao Source: www.cppprog.com

 

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.