5.5. tsPostAddCustom

Syntax

Pascal

procedure tsPostAddCustom(PostProcessProc: tsPostProcessProc; Data: Pointer);

C/C++

void tsPostAddCustom(tsPostProcessProc PostProcessProc, void * Data);

Description

With the custom post processor you are able to program your own post processors.

The following sample is an "flaming" like effekt. I only used the standard functions because it's only an demonstration. The main part of this effekt is an vertical blur of the chars. To quite higher position of the blured image might simulate some flames. For advanced programmers you have the abillity to manipulate the whole image by direct accessing the memory.

Sample Image for tsPostAddCustom
procedure CustomPostProcessor(ImageID: tsImageID; CharCode: WideChar;
  Data: Pointer); cdecl;
var
  TempImageID: tsImageID;
  X, Y: tsInt;
  GlyphRect: tsRect;
begin
  // clone the image
  tsImageCreate(@TempImageID);
  tsImageAssignFrom(TempImageID, ImageID);

  // fill with color
  tsImageFillColor3ub(TempImageID, $E0, $E0, $FF, TS_CHANNELS_RGB);

  // original image will be the shadow so blur image
  tsImageBlur(ImageID, 2, 8, TS_CHANNEL_ALPHA, TS_TRUE, @X, @Y);

  // fill with color
  tsImageFillColor3ub(ImageID, $00, $00, $FF, TS_CHANNELS_RGB);

  // blend cloned original image over blured original
  tsImageBlend(ImageID, TempImageID, X, Y + 5, TS_TRUE);

  // destroy temp
  tsImageDestroy(TempImageID);

  // the glyph rect has changed so get it
  tsFontGetCharParameteriv(CharCode, TS_CHAR_GLYPHRECT, @GlyphRect);

  // move the glyphrect by X and Y
  GlyphRect.Left := GlyphRect.Left + X;
  GlyphRect.Right := GlyphRect.Right + X;
  GlyphRect.Top := GlyphRect.Top + Y + 5;
  GlyphRect.Bottom := GlyphRect.Bottom + Y + 5;

  // and set it back
  tsFontSetCharParameteriv(CharCode, TS_CHAR_GLYPHRECT, @GlyphRect);
end;

Example 5.1. Custom Post Processor (Pascal)

Params

PostProcessProc

The proc is a pointer to an cdecl method they will called for each char. The method has this syntax.

Syntax

Pascal

procedure Proc(ImageID: tsImageID; CharCode: WideChar; Data: Pointer);

C/C++

void Proc(tsImageID ImageID, WideChar CharCode, void * Data);

Params

ImageID

The image ID of the char image. This ID is only temporally and will deleted after this post processing step.

CharCode

The char code of the actuall char.

Data

The pointer they passed to tsPostAddCustom.

Data

It's only an simple data pointer they will passed to the PostProcessProc.

Error Codes

TS_NO_ACTIVE_CONTEXT

If there was no context bound.

TS_NO_ACTIVE_FONT

If there is no font bound.

TS_INVALID_OPERATION

If the bound font isn't an font creator.