fcl-image

From Lazarus wiki
Revision as of 08:01, 26 April 2010 by Joseph.montanez (talk | contribs)
Jump to navigationJump to search

English (en) | 日本語 (ja)

Introduction

FCL-Image started life as "fpimage", pretty much as an attempt to implement a generally portable TImage like class, without the deep win32 and VCL ties.

Current file list

The central units are fpimage and fpcanvas and these are further enhanced by OOP derivation.

  • bmpcomn A few structures and constants for the BMP fileformat
  • clipping Some utility routines that help with clipping and intersecting of rects.
  • ellipses Drawing of ellipses and arcs, and filling ellipses and pies.
    • TEllipseInfo
  • extinterpolation interpolation filters for TFPCanvas.StretchDraw (
    • TBlackmanInterpolation
    • TBlackmanSincInterpolation
    • TBlackmanBesselInterpolation
    • TGaussianInterpolation
    • TBoxInterpolation
    • THermiteInterpolation
    • TLanczosInterpolation
    • TQuadraticInterpolation
    • TCubicInterpolation
    • TCatromInterpolation
    • TBilineairInterpolation
    • THanningInterpolation
    • THammingInterpolation
  • fpcanvas Generic Canvas classes.
    • TFPCanvasException
    • TFPPenException
    • TFPBrushException
    • TFPFontException
    • TFPCustomCanvas
    • TFPCanvasHelper
    • TFPCustomFont
    • TFPCustomFontClass
    • TFPCustomPen
    • TFPCustomPenClass
    • TFPCustomBrush
    • TFPCustomBrushClass
    • TFPCustomInterpolation
    • TFPBaseInterpolation
    • TMitchelInterpolation
    • TFPCustomCanvas
    • TFPCustomDrawFont
    • TFPEmptyFont
    • TFPCustomDrawPen
    • TFPEmptyPen
    • TFPCustomDrawBrush
    • TFPEmptyBrush
  • fpcolhash an implementation of a color hash table.
    • TFPColorHashException
    • TFPColorHashTable
  • fpditherer contains classes used to dither images.
    • FPDithererException
    • TFPBaseDitherer
    • TFPFloydSteinbergDitherer
  • fpimage fpImage base definitions and classes
    • TFPCustomImageReader
    • TFPCustomImageWriter
    • TFPCustomImage
    • FPImageException
    • TFPPalette
    • TFPCustomImage
    • TFPMemoryImage
    • TFPCustomImageHandler
    • TFPCustomImageReader
    • TFPCustomImageWriter
    • TIHData
    • TImageHandlersManager
  • fpimgcanv Image Canvas - canvas which draws on an image.
    • TFPImageCanvas
  • fpimgcmn Image Common: small procedural Helpers (swap,crc)
  • fppixlcanv
    • TPixelCanvas
  • fpquantizer classes used to quantize images.
  • freetype Encapsulating classes over freetype
  • freetypeh Freetype header translation
  • ftfont More freetype related font classes
  • pcxcomn PCX fileformat records and types
  • pixtools Pixel drawing routines.
  • pngcomn PNG fileformat records and types
  • pscanvas TPostScriptCanvas implementation.
  • targacmn Targa fileformat records and types

Readers and writers for various image formats

  • fpreadbmp
  • fpreadjpeg
  • fpreadpcx
  • fpreadpng
  • fpreadpnm
  • fpreadtga
  • fpreadxpm
  • fpwritebmp
  • fpwritejpeg
  • fpwritepcx
  • fpwritepng
  • fpwritepnm
  • fpwritetga
  • fpwritexpm

INC files uses in fpcanvas

  • fpbrush
  • fpcanvas
  • fpcdrawh
  • fpfont
  • fphelper
  • fpinterpolation
  • fppen

INC files uses in fpmake

  • fpcolors
  • fpimage
  • fphandler
  • fpcolcnv
  • fppalette

Demoes

  • drawing
  • imgconv

Known Issues and limitations

  • fcl-image is written for maximal portability and maintainability and is quite slow. The main storage type is 16-bit RGBA, storing always 64-bit per pixel, and a function is called to get each pixel.
  • pngwriter doesn't implement automatic detection of filters, and thus is always "filter none"

Walk-through

Basic Canvas Setup

You'll need a few things to start up. A canvas, image, and writer. The writer is to write images like PNG. The sample below will give you a 100x100 black png.

{$mode objfpc}{$h+}
program demo;
 
uses classes, sysutils,
     FPImage, FPCanvas, FPImgCanv,
     FPWritePNG;
 
var canvas : TFPCustomCanvas;
    image : TFPCustomImage;
    writer : TFPCustomImageWriter;
begin
  { Create an image 100x100 pixels}
  image := TFPMemoryImage.Create (100,100);
  
  { Attach the image to the canvas }
  Canvas := TFPImageCanvas.Create (image);
  
  { Create the writer }
  Writer := TFPWriterPNG.Create;
  
  { Save to file }
  image.SaveToFile ('DrawTest.png', writer);
  
  { Clean up! }
  Canvas.Free;
  image.Free;
  writer.Free;
end.

Drawing a Circle

Drawing a circle requires a bit more then just giving a width. You'll need to setup the pen style, mode, width, and color to do this. FCL-Image comes with a few pen modes and styles, it will really be up to you to decide which you'll need. Its best for now to try with a few modes and styles to get a better understanding of what FCL-Image can do.


{$mode objfpc}{$h+}
program demo;
 
uses classes, sysutils,
     FPImage, FPCanvas, FPImgCanv,
     FPWritePNG;
 
var canvas : TFPcustomCanvas;
    image : TFPCustomImage;
    writer : TFPCustomImageWriter;
    { 
      Colors range from 0 to 65535 in each primary color. 
      They can also show as hexideciaml:
      $FFFF = 65535, $0000 = 0 
    }
    passionRed: TFPColor = (Red: 65535; Green: 0; Blue: 0; Alpha: 65535);
begin
  image := TFPMemoryImage.Create (100,100);
  Canvas := TFPImageCanvas.Create (image);
  Writer := TFPWriterPNG.Create;

  { Set the pen styles }
  with canvas do
  begin
    pen.mode    := pmCopy;
    pen.style   := psSolid;
    pen.width   := 1;
    pen.FPColor := passionRed;
  end;

  { Draw a circle }
  canvas.Ellipse (10,10, 90,90);
  
  { Save to file }
  image.SaveToFile ('DrawTest.png', writer);
  
  { Clean up! }
  Canvas.Free;
  image.Free;
  writer.Free;
end.

Pen Modes

The pen mode is how the pixel drawn will react to the pixels beneath it. So if its a white pixel and you draw a red pixel over it with the mode of pmXor then you'll get a vibrate blue pixel.

  • pmBlack
  • pmWhite
  • pmNop
  • pmNot
  • pmCopy
  • pmNotCopy
  • pmMergePenNot
  • pmMaskPenNot
  • pmMergeNotPen
  • pmMaskNotPen
  • pmMerge
  • pmNotMerge
  • pmMask
  • pmNotMask
  • pmXor
  • pmNotXor


Pen Styles

  • psSolid
  • psDash
  • psDot
  • psDashDot
  • psDashDotDot
  • psinsideFrame
  • psPattern
  • psClear

Links

Go to back Packages List