Commit e8f27fc7 authored by Enrico Ros's avatar Enrico Ros
Browse files

Highlight annotations: ok

PagePainter:
  Updated drawShape with RasterOperation (Normal, Multiply) for getting
  Highlight annotation types to work. All Highlight annotations are now
  drew using the Multiply raster operation.

Painter_AGG2:
  Replaced the agg_pixfmt_rgba.h pixformat definition template with an
  internal version that implements different raster operations too. The
  new version has been shrinked to the minimum, containing the only code
  needed by kpdf AGG2 rendering engine to work.

Thanks for Rob Buis for telling me the way to go and providing sample code
with his AGG2 algorithms.

svn path=/branches/kpdf_annotations/kdegraphics/kpdf/; revision=405338
parent c5b694d0
......@@ -274,7 +274,7 @@ void PagePainter::paintPageOnPainter( QPainter * destPainter, const KPDFPage * p
point.y = (inkPoint.y - yOffset) * yScale;
path.append( point );
// draw the normalized path into image
drawShapeOnImage( backImage, path, false, QPen( a->style.color ), QBrush(), Blend );
drawShapeOnImage( backImage, path, false, QPen( a->style.color ), QBrush() );
*/
}
// draw GeomAnnotation MISSING: all
......@@ -326,7 +326,7 @@ void PagePainter::paintPageOnPainter( QPainter * destPainter, const KPDFPage * p
path[ 1 ].y = ( path[ 1 ].y + 3*path[ 2 ].y ) / 4.0;
path.pop_back();
path.pop_back();
drawShapeOnImage( backImage, path, false, QPen( a->style.color, 2 ), QBrush(), Blend );
drawShapeOnImage( backImage, path, false, QPen( a->style.color, 2 ), QBrush() );
break;
// make a line at 1/2 of the height
case HighlightAnnotation::StrikeOut:
......@@ -336,7 +336,7 @@ void PagePainter::paintPageOnPainter( QPainter * destPainter, const KPDFPage * p
path[ 1 ].y = ( path[ 1 ].y + path[ 2 ].y ) / 2.0;
path.pop_back();
path.pop_back();
drawShapeOnImage( backImage, path, false, QPen( a->style.color, 2 ), QBrush(), Blend );
drawShapeOnImage( backImage, path, false, QPen( a->style.color, 2 ), QBrush() );
break;
}
}
......@@ -365,7 +365,7 @@ void PagePainter::paintPageOnPainter( QPainter * destPainter, const KPDFPage * p
path.append( point );
}
// draw the normalized path into image
drawShapeOnImage( backImage, path, false, QPen( a->style.color, 2 ), QBrush(), Blend );
drawShapeOnImage( backImage, path, false, QPen( a->style.color, 2 ), QBrush() );
}
}
} // end current annotation drawing
......@@ -629,8 +629,8 @@ void PagePainter::colorizeImage( QImage & grayImage, const QColor & color,
// directory. This is to be replaced by Arthur calls for drawing antialiased
// primitives, but until that AGG2 does its job very fast and good-looking.
#include "kpdf_pixfmt_rgba.h"
#include "agg_rendering_buffer.h"
#include "agg_pixfmt_rgba.h"
#include "agg_renderer_base.h"
#include "agg_scanline_u.h"
#include "agg_rasterizer_scanline_aa.h"
......@@ -644,7 +644,7 @@ void PagePainter::drawShapeOnImage(
bool closeShape,
const QPen & pen,
const QBrush & brush,
DrawingOperation op
RasterOperation op
//float antiAliasRadius
)
{
......@@ -671,8 +671,8 @@ void PagePainter::drawShapeOnImage(
// create 'pixel buffer', 'clipped renderer', 'scanline renderer' on bgra32 format
typedef agg::pixfmt_bgra32 bgra32;
typedef agg::renderer_base< bgra32 > rb_bgra32;
bgra32 * pixels = new bgra32( buffer );
rb_bgra32 rb( *pixels );
bgra32 pixels( buffer, op == Multiply ? 1 : 0 );
rb_bgra32 rb( pixels );
agg::renderer_scanline_aa_solid< rb_bgra32 > render( rb );
// create rasterizer and scaline
agg::rasterizer_scanline_aa<> rasterizer;
......@@ -687,7 +687,7 @@ void PagePainter::drawShapeOnImage(
span[ x ] = agg::rgba8(c);
}
for( int y = 0; y < imageHeight; y++ )
pixels->blend_color_hspan( 0, y, imageWidth, span, 0, (255*y)/imageHeight );
pixels.blend_color_hspan( 0, y, imageWidth, span, 0, (255*y)/imageHeight );
#endif
// fill rect
......
......@@ -53,14 +53,14 @@ class PagePainter
// my pretty dear raster function
typedef QValueList< NormalizedPoint > NormalizedPath;
enum DrawingOperation { Blend, Multiply };
enum RasterOperation { Normal, Multiply };
static void drawShapeOnImage(
QImage & image,
const NormalizedPath & imagePoints,
bool closeShape = true,
const QPen & pen = QPen(),
const QBrush & brush = QBrush(),
DrawingOperation op = Blend
RasterOperation op = Normal
//float antiAliasRadius = 1.0
);
};
......
......@@ -40,6 +40,9 @@ agg_array.h, agg_basics.h, agg_bezier_arc.h, agg_clip_liang_barsky.h,
agg_bezier_arc.cpp, agg_path_storage.cpp, agg_rasterizer_scanline_aa.cpp,
agg_trans_affine.cpp, agg_vcgen_stroke.cpp
< Raster Ops on RGBA color buffer >
kpdf_pixfmt_rgba.h (removed: agg_pixfmt_rgba.h)
< ..for every new algo added.. >
..append added files here..
......
This diff is collapsed.
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.3
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// Adaptation for high precision colors has been sponsored by
// Liberty Technology Systems, Inc., visit http://lib-sys.com
//
// Liberty Technology Systems, Inc. is the provider of
// PostScript and PDF technology for software developers.
//
//----------------------------------------------------------------------------
/**
* @short KPDF modified rgba pixel format provider for rastering operations
* This is the agg_pixfmt_rgba.h file with some added code. When syncing to
* the latest agg counterpart, diff the mods and apply them again after
* copying the legacy file over this.
* - Enrico Ros @ KDPF Team - 2005
*
* Thanks to Rob Buis <rwlbuis@xs4all.nl> for providing the raster algorithms
* he used when modifying agg for usage with KCanvas/KSvg2.
*/
#ifndef AGG_PIXFMT_RGBA_INCLUDED
#define AGG_PIXFMT_RGBA_INCLUDED
#include <string.h>
#include "agg_basics.h"
#include "agg_color_rgba.h"
#include "agg_rendering_buffer.h"
namespace agg
{
// Nice trick from Qt4's Arthur
inline int qt_div_255(int x) { return (x + (x>>8) + 0x80) >> 8; }
//=============================================================normal_blend_rgba
/** The standard blending algo */
template<class ColorT, class Order, class PixelT> struct normal_blend_rgba
{
typedef ColorT color_type;
typedef PixelT pixel_type;
typedef Order order_type;
typedef typename color_type::value_type value_type;
typedef typename color_type::calc_type calc_type;
enum
{
base_shift = color_type::base_shift,
base_mask = color_type::base_mask
};
//--------------------------------------------------------------------
static AGG_INLINE void blend_pix(value_type* p,
unsigned cr, unsigned cg, unsigned cb,
unsigned alpha,
unsigned)
{
calc_type r = p[Order::R];
calc_type g = p[Order::G];
calc_type b = p[Order::B];
calc_type a = p[Order::A];
p[Order::R] = (value_type)(((cr - r) * alpha + (r << base_shift)) >> base_shift);
p[Order::G] = (value_type)(((cg - g) * alpha + (g << base_shift)) >> base_shift);
p[Order::B] = (value_type)(((cb - b) * alpha + (b << base_shift)) >> base_shift);
p[Order::A] = (value_type)((alpha + a) - ((alpha * a + base_mask) >> base_shift));
}
};
//=============================================================multiply_blend_rgba
/** The Multiplier blending algo (for Highlighting pigmentation) */
template<class ColorT, class Order, class PixelT> struct multiply_blend_rgba
{
typedef ColorT color_type;
typedef PixelT pixel_type;
typedef Order order_type;
typedef typename color_type::value_type value_type;
typedef typename color_type::calc_type calc_type;
enum
{
base_shift = color_type::base_shift,
base_mask = color_type::base_mask
};
//--------------------------------------------------------------------
static AGG_INLINE void blend_pix(value_type* p,
unsigned cr, unsigned cg, unsigned cb,
unsigned alpha,
unsigned)
{
calc_type r = p[Order::R];
calc_type g = p[Order::G];
calc_type b = p[Order::B];
calc_type a = p[Order::A];
p[Order::R] = (value_type)(((qt_div_255(cr*r) - r) * alpha + (r << base_shift)) >> base_shift);
p[Order::G] = (value_type)(((qt_div_255(cg*g) - g) * alpha + (g << base_shift)) >> base_shift);
p[Order::B] = (value_type)(((qt_div_255(cb*b) - b) * alpha + (b << base_shift)) >> base_shift);
p[Order::A] = (value_type)((alpha + a) - ((alpha * a + base_mask) >> base_shift));
}
};
//=======================================================pixel_formats_rgba
/** The following functions have been modified for using different blenders:
* blend_pixel, blend_hline, blend_solid_hspan
* (the others are not used by kpdf and have been removed)
*/
template<class ColorT, class Order, class PixelT> class pixel_formats_rgba
{
public:
typedef rendering_buffer::row_data row_data;
typedef ColorT color_type;
typedef Order order_type;
typedef PixelT pixel_type;
typedef typename color_type::value_type value_type;
typedef typename color_type::calc_type calc_type;
enum
{
base_shift = color_type::base_shift,
base_size = color_type::base_size,
base_mask = color_type::base_mask
};
typedef normal_blend_rgba<ColorT, Order, PixelT> normal_blender;
typedef multiply_blend_rgba<ColorT, Order, PixelT> multiply_blender;
//--------------------------------------------------------------------
pixel_formats_rgba( rendering_buffer& rb, int rasterMode ) :
m_rbuf(&rb), m_mode( rasterMode )
{}
//--------------------------------------------------------------------
AGG_INLINE unsigned width() const { return m_rbuf->width(); }
AGG_INLINE unsigned height() const { return m_rbuf->height(); }
//--------------------------------------------------------------------
AGG_INLINE void blend_pixel(int x, int y, const color_type& c, int8u cover)
{
if ( !c.a )
return;
value_type* p = (value_type*)m_rbuf->row(y) + (x << 2);
if ( !m_mode )
{
calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8;
if(alpha == base_mask)
{
p[order_type::R] = c.r;
p[order_type::G] = c.g;
p[order_type::B] = c.b;
p[order_type::A] = c.a;
}
else
normal_blender::blend_pix(p, c.r, c.g, c.b, alpha, cover);
}
else if ( m_mode == 1 )
multiply_blender::blend_pix(p, c.r, c.g, c.b, alpha, cover);
}
//--------------------------------------------------------------------
void blend_hline(int x, int y,
unsigned len,
const color_type& c,
int8u cover)
{
if ( !c.a )
return;
value_type* p = (value_type*)m_rbuf->row(y) + (x << 2);
calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8;
switch ( m_mode )
{
case 0:
if ( alpha == base_mask )
{
pixel_type v;
((value_type*)&v)[order_type::R] = c.r;
((value_type*)&v)[order_type::G] = c.g;
((value_type*)&v)[order_type::B] = c.b;
((value_type*)&v)[order_type::A] = c.a;
while( len-- )
{
*(pixel_type*)p = v;
p += 4;
}
}
else
{
while( len-- )
{
normal_blender::blend_pix(p, c.r, c.g, c.b, alpha, cover);
p += 4;
}
}
break;
case 1:
while( len-- )
{
multiply_blender::blend_pix(p, c.r, c.g, c.b, alpha, cover);
p += 4;
}
break;
}
}
//--------------------------------------------------------------------
void blend_solid_hspan(int x, int y,
unsigned len,
const color_type& c,
const int8u* covers)
{
if ( !c.a )
return;
value_type* p = (value_type*)m_rbuf->row(y) + (x << 2);
switch ( m_mode )
{
case 0:
while( len-- )
{
calc_type alpha = (calc_type(c.a) * (calc_type(*covers) + 1)) >> 8;
if ( alpha == base_mask )
{
p[order_type::R] = c.r;
p[order_type::G] = c.g;
p[order_type::B] = c.b;
p[order_type::A] = base_mask;
}
else
normal_blender::blend_pix(p, c.r, c.g, c.b, alpha, *covers);
p += 4;
++covers;
}
break;
case 1:
while( len-- )
{
calc_type alpha = (calc_type(c.a) * (calc_type(*covers) + 1)) >> 8;
multiply_blender::blend_pix(p, c.r, c.g, c.b, alpha, *covers);
p += 4;
++covers;
}
break;
}
}
private:
rendering_buffer* m_rbuf;
int m_mode;
};
//-----------------------------------------------------------------------
// Order Types: order_rgba, order_argb, order_abgr, [order_bgra]
// the RBGA32 is used by kpdf/qimage ( 0xAARRGGBB in memory )
typedef pixel_formats_rgba<rgba8, order_bgra, int32u> pixfmt_bgra32;
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment