|
From: Ken R. <res...@sp...> - 2005-11-17 00:32:40
|
I am basing my code on the images1 example and I have changed
the image 'partner' shape from an ellipse to a rectangle.
The partner rectangle comes out at X,Y and scales and rotates,
but the top left-hand corner of the image is always stuck at
(x,y)=3D(0,0). Only the part of the image that overlaps the=20
rectangle is visible, but that part scales and rotates properly.=20
When there is no overlap, there is no image.
I do not understand much of the the image1 example, so I am
lost as to what might be.the cause. Code is attached.
Would be most grateful for help and/or example code.
Best regards
Ken
void image ( HAGG * h , int x , int y , TCHAR * imgfilename )
{
if ( !loadimage ( h , imgfilename ) ) // sets image details in h
{
return ;
}
agg::rendering_buffer rbuf(h->pixels ,
h->frame_width ,=20
h->frame_height ,=20
-(h->frame_width * h->bytesperpixel) ) ;=20
typedef agg::renderer_base<pixfmt> renderer_base;
typedef agg::renderer_base<pixfmt_pre> =
renderer_base_pre;
typedef agg::renderer_scanline_aa_solid<renderer_base> =
renderer_solid;
pixfmt pixf(rbuf);
pixfmt_pre pixf_pre(rbuf);
renderer_base rb(pixf);
renderer_base_pre rb_pre(pixf_pre);
renderer_solid rs(rb);
rb.clear(agg::rgba(1.0, 1.0, 1.0));
agg::rasterizer_scanline_aa<> pf;
agg::scanline_u8 sl;
IMGINFO * i =3D &h->imgs [ 0 ] ;
double imgwd =3D i->width ; // image width
double imght =3D i->height ; // image height
agg::trans_affine src_mtx;
src_mtx *=3D agg::trans_affine_translation(-x,-y);
src_mtx *=3D agg::trans_affine_rotation(-h->t.angle); // in radians
src_mtx *=3D agg::trans_affine_scaling(h->t.scalex , h->t.scaley);
src_mtx *=3D agg::trans_affine_translation(x,y);
agg::trans_affine img_mtx;
img_mtx *=3D agg::trans_affine_translation(-x,-y);
img_mtx *=3D agg::trans_affine_rotation(-h->t.angle);
img_mtx *=3D agg::trans_affine_scaling(h->t.scalex , h->t.scaley);
img_mtx *=3D agg::trans_affine_translation(x,y);
img_mtx.invert();
typedef agg::span_allocator<color_type> span_alloc_type;
span_alloc_type sa;
typedef agg::span_interpolator_linear<> interpolator_type;
interpolator_type interpolator(img_mtx);
// "hardcoded" bilinear filter
typedef agg::span_image_filter_rgb_bilinear<color_type, =
component_order,=20
interpolator_type> =
span_gen_type;
typedef agg::renderer_scanline_aa<renderer_base_pre, span_gen_type> =
renderer_type;
agg::rendering_buffer rbuf_img(i->pixels ,
(int)imgwd ,=20
(int)imght ,=20
-i->stride ) ;=20
span_gen_type sg(sa,=20
rbuf_img, // rendering buf with image pixels
agg::rgba_pre(0, 0.4, 0, 0.5),
interpolator);
renderer_type ri(rb_pre, sg);
agg::path_storage path; // partner rectangle
path.move_to( x,y);
path.line_to( x+imgwd, y );
path.line_to( x+imgwd, y+imght);
path.line_to( x, y+imght);
path.close_polygon();
agg::conv_transform<agg::path_storage> tr(path, src_mtx);
=20
pf.add_path(tr);
agg::render_scanlines(pf, sl, ri);
}
static void drawimage ( )
{
RECT rt ;
GetClientRect(hwndmain, &rt);
int width =3D rt.right - rt.left;
int height =3D rt.bottom - rt.top;
HAGG * h =3D gethandle ( mybuf , width , height , 4 ) ;
settrans_scale ( h , scale ) ;
settrans_rotate ( h , degrees ) ;
// image ( h , 20,50 , "bmpeivor.bmp" ) ; // does not work
image ( h , 0,0 , "bmpeivor.bmp" ) ; // works
display ( h , hwndmain ) ; // on screen
}
|