Board index » delphi » Text antialias with supersampling too slow , any alternative ?

Text antialias with supersampling too slow , any alternative ?

i tried to follow some advices given in this newsgroup for text antialias :
i took a text (it is rotated by some angle) and put it on a bitmap : then i
supersample (ratio 2:1) and then resubsample the bitmap but the thing is too
slow : for example if the text is rotated , the bitmap can be quite large
and doing a 2:1 quality supersample is not a joke : if anybody has faster
routines for what i have tried or tell me how can i speed up the whole
process , i would be very grateful :
thanx,
Francesco .
 

Re:Text antialias with supersampling too slow , any alternative ?


Hi Francesco!

Of course it is slower than non-antialiased text. So it is important to
optimize the routine. Here is some part of the routine I use, it's
probably the part that's most important to optimize (might be faster
when precalculating OfsPtr to an array?):

      For OuterY := 0 To TextDIB.Height-1 Do Begin
        TextPtr := ResultBitmap.ScanLine[OuterY];
        InnerOffset := 0;
        For OuterX := 0 To TempBitmap.Width-1 Do Begin
          // get average color
          VSum := 0;
          For InnerY := 0 To Zoom2 Do Begin
            OfsPtr := TempBitmap.ScanLine[(OuterY SHL FQuality)+InnerY];
            For InnerX := 0 To Zoom2 Do Begin
              Inc (VSum,OfsPtr^[InnerOffset+InnerX]);
            End;
          End;
          // set pixel
          TextPtr^ := VSum SHR ShiftValue;
          // next pixel
          Inc (TextPtr);
          Inc (InnerOffset,FZoom);
        End;
      End;

I guess I have to explain some variables. The quality is set by
FQuality, some variables that are used often are precalculated:
  FZoom := 1 SHL FQuality;
  Zoom2 := FZoom-1;
  ShiftValue := FQuality SHL 1;
TempBitmap is FZoom times larger than ResultBitmap

As I always draw the text to 8 bit bitmaps, OfsPtr = ^TByteArray where
TByteArray = Array[0..65535] of Byte. The result is 8 bit, too (so
TextPtr = ^Byte) because I use this result to combine it with the
original image by some other procedure. This is more flexible, because
you have to calculate the result only once and can use it for colored
text, its shadow and any other effect you can think of. Of course you
can do this in one step, then you have to interpret black (or white) as
transparent and grays as semi-transparent. The code would look like:

   VVal := VSum SHR ShiftValue;
   TextPtr^.Red := TextPtr^.Red+((SomeColor.Red-TextPtr^.Red)*VVal DIV
256);
   TextPtr^.Green :=
TextPtr^.Green+((SomeColor.Green-TextPtr^.Green)*VVal DIV 256);
   TextPtr^.Blue := TextPtr^.Blue+((SomeColor.Blue-TextPtr^.Blue)*VVal
DIV 256);

But I guess it's not much slower when doing this in a second step where
VVal := TextPtr^ (the difference is that you save all VVals in
ResultBitmap before you use them) and really much more powerful when
adding routines for effects like shadow, glow etc. to your routine.

Jens

Re:Text antialias with supersampling too slow , any alternative ?


When you supersample the rotated text, skip all DWORDS that are 100%
background
color, and use a precalculated value. Likewise, when supersampling a DWORD
that is
100% text color, use another precalculated value.

You can take this approach into extreme and produce ridiculously fast
antialiasing:
Use lookuptables for 3x3 kernel values.

Frank

Quote
"Francesco Savastano" <francescos...@tiscalinet.it> wrote in message

news:3b61faa6$2_1@dnews...
Quote
> i tried to follow some advices given in this newsgroup for text antialias
:
> i took a text (it is rotated by some angle) and put it on a bitmap : then
i
> supersample (ratio 2:1) and then resubsample the bitmap but the thing is
too
> slow : for example if the text is rotated , the bitmap can be quite large
> and doing a 2:1 quality supersample is not a joke : if anybody has faster
> routines for what i have tried or tell me how can i speed up the whole
> process , i would be very grateful :
> thanx,
> Francesco .

Re:Text antialias with supersampling too slow , any alternative ?


Dear Francesco,
ImageLib Corporate Suite offers 7 different algorithms for anti-aliasing.
Download a
trial and try anti6 , it works for most text images.  It is very fast and
makes those images
nice and sharp and clear and easy to read.
If you go to client comments on the ImageLib website, you will see what
people have said about
it.
www.imagelib.com
Sincerely,
Jillian Pinsker
Quote
"Francesco Savastano" <francescos...@tiscalinet.it> wrote in message

news:3b61faa6$2_1@dnews...
Quote
> i tried to follow some advices given in this newsgroup for text antialias
:
> i took a text (it is rotated by some angle) and put it on a bitmap : then
i
> supersample (ratio 2:1) and then resubsample the bitmap but the thing is
too
> slow : for example if the text is rotated , the bitmap can be quite large
> and doing a 2:1 quality supersample is not a joke : if anybody has faster
> routines for what i have tried or tell me how can i speed up the whole
> process , i would be very grateful :
> thanx,
> Francesco .

Other Threads