agg_draw_line_pattern

This commit is contained in:
p989 2009-07-09 03:35:26 +00:00
parent 24b0d4cc74
commit 740fbdf6f6
1 changed files with 146 additions and 1 deletions

View File

@ -17,6 +17,12 @@
#include "agg_embedded_raster_fonts.h"
#include "agg_renderer_raster_text.h"
#include "ctrl/agg_bezier_ctrl.h"
#include "platform/agg_platform_support.h"
#include "agg_pattern_filters_rgba.h"
#include "agg_renderer_outline_image.h"
#include "agg_rasterizer_outline_aa.h"
#define AGG_RGB555 //pixfmt will be rgb555
#include "pixel_formats.h" //this file is in agg/examples
@ -167,6 +173,144 @@ void agg_draw_raster_font(int x, int y, int r, int g, int b, int a, char* strbuf
rt.render_text(x, y, strbuf, !flipy);
}
static agg::int8u brightness_to_alpha[256 * 3] =
{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 254, 254, 254,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 253, 253,
253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 252,
252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 251, 251, 251, 251, 251,
251, 251, 251, 251, 250, 250, 250, 250, 250, 250, 250, 250, 249, 249, 249, 249,
249, 249, 249, 248, 248, 248, 248, 248, 248, 248, 247, 247, 247, 247, 247, 246,
246, 246, 246, 246, 246, 245, 245, 245, 245, 245, 244, 244, 244, 244, 243, 243,
243, 243, 243, 242, 242, 242, 242, 241, 241, 241, 241, 240, 240, 240, 239, 239,
239, 239, 238, 238, 238, 238, 237, 237, 237, 236, 236, 236, 235, 235, 235, 234,
234, 234, 233, 233, 233, 232, 232, 232, 231, 231, 230, 230, 230, 229, 229, 229,
228, 228, 227, 227, 227, 226, 226, 225, 225, 224, 224, 224, 223, 223, 222, 222,
221, 221, 220, 220, 219, 219, 219, 218, 218, 217, 217, 216, 216, 215, 214, 214,
213, 213, 212, 212, 211, 211, 210, 210, 209, 209, 208, 207, 207, 206, 206, 205,
204, 204, 203, 203, 202, 201, 201, 200, 200, 199, 198, 198, 197, 196, 196, 195,
194, 194, 193, 192, 192, 191, 190, 190, 189, 188, 188, 187, 186, 186, 185, 184,
183, 183, 182, 181, 180, 180, 179, 178, 177, 177, 176, 175, 174, 174, 173, 172,
171, 171, 170, 169, 168, 167, 166, 166, 165, 164, 163, 162, 162, 161, 160, 159,
158, 157, 156, 156, 155, 154, 153, 152, 151, 150, 149, 148, 148, 147, 146, 145,
144, 143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, 130, 129,
128, 128, 127, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114, 113,
112, 111, 110, 109, 108, 107, 106, 105, 104, 102, 101, 100, 99, 98, 97, 96,
95, 94, 93, 91, 90, 89, 88, 87, 86, 85, 84, 82, 81, 80, 79, 78,
77, 75, 74, 73, 72, 71, 70, 69, 67, 66, 65, 64, 63, 61, 60, 59,
58, 57, 56, 54, 53, 52, 51, 50, 48, 47, 46, 45, 44, 42, 41, 40,
39, 37, 36, 35, 34, 33, 31, 30, 29, 28, 27, 25, 24, 23, 22, 20,
19, 18, 17, 15, 14, 13, 12, 11, 9, 8, 7, 6, 4, 3, 2, 1
};
template<class Pattern,class Rasterizer,class Renderer,class PatternSource,class VertexSource>
void draw_curve(Pattern& patt,Rasterizer& ras,Renderer& ren,PatternSource& src,VertexSource& vs, double scale, double start)
{
patt.create(src);
ren.scale_x(scale);
ren.start_x(start);
ras.add_path(vs);
}
class pattern_src_brightness_to_alpha_rgba8
{
public:
pattern_src_brightness_to_alpha_rgba8(agg::rendering_buffer& rb) :
m_rb(&rb), m_pf(*m_rb) {}
unsigned width() const { return m_pf.width(); }
unsigned height() const { return m_pf.height(); }
agg::rgba8 pixel(int x, int y) const
{
agg::rgba8 c = m_pf.pixel(x, y);
c.a = brightness_to_alpha[c.r + c.g + c.b];
return c;
}
private:
agg::rendering_buffer* m_rb;
pixfmt m_pf;
};
void agg_draw_line_pattern(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, double scale, double start, char* filename){
int flipy = 0;
agg::platform_support platsup(agg::pix_format_rgb555, flipy);
platsup.load_img(0, filename);
agg::bezier_ctrl<agg::rgba8> m_curve1;
typedef agg::rasterizer_scanline_aa<> rasterizer_scanline;
typedef agg::scanline_p8 scanline;
m_curve1.curve(x1, y1, x2, y2, x3, y3, x4, y4);
m_curve1.no_transform();
rBuf.attach(GPU_tempScreen, width, height, stride);
pixfmt pixf(rBuf);
RendererBase ren_base(pixf);
RendererSolid ren(ren_base);
rasterizer_scanline ras;
scanline sl;
// Pattern source. Must have an interface:
// width() const
// height() const
// pixel(int x, int y) const
// Any agg::renderer_base<> or derived
// is good for the use as a source.
//-----------------------------------
pattern_src_brightness_to_alpha_rgba8 p1(platsup.rbuf_img(0));
agg::pattern_filter_bilinear_rgba8 fltr; // Filtering functor
// agg::line_image_pattern is the main container for the patterns. It creates
// a copy of the patterns extended according to the needs of the filter.
// agg::line_image_pattern can operate with arbitrary image width, but if the
// width of the pattern is power of 2, it's better to use the modified
// version agg::line_image_pattern_pow2 because it works about 15-25 percent
// faster than agg::line_image_pattern (because of using simple masking instead
// of expensive '%' operation).
typedef agg::line_image_pattern<agg::pattern_filter_bilinear_rgba8> pattern_type;
typedef agg::renderer_base<pixfmt> base_ren_type;
typedef agg::renderer_outline_image<base_ren_type, pattern_type> renderer_type;
typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type;
//-- Create uninitialized and set the source
pattern_type patt(fltr);
renderer_type ren_img(ren_base, patt);
rasterizer_type ras_img(ren_img);
draw_curve(patt, ras_img, ren_img, p1, m_curve1.curve(), scale, start);
}
//temporary, just for testing the lib
void AGGDraw() {
@ -174,4 +318,5 @@ void AGGDraw() {
agg_draw_solid_rectangle(100, 100, 200, 200, 0, 255, 0, 128);
agg_draw_solid_ellipse(70, 80, 50, 50, 255, 0, 0, 128);
agg_draw_raster_font(60, 60, 255, 0, 255, 128, "testing testing testing", "verdana18_bold");
}
agg_draw_line_pattern(64, 19, 14, 126, 118, 266, 19, 265, .76, 4.69, "C:\\7.bmp");
}