mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-14 10:20:21 +02:00
imagemagick: Adds a pixel access demo and updates some parts to newer imagemagick
git-svn-id: trunk@13967 -
This commit is contained in:
parent
d61eb3528f
commit
f7044272c8
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -2825,8 +2825,10 @@ packages/imagemagick/examples/image.png -text svneol=unset#image/png
|
||||
packages/imagemagick/examples/screenshot.lpr svneol=native#text/plain
|
||||
packages/imagemagick/examples/wanddemo.dpr svneol=native#text/plain
|
||||
packages/imagemagick/examples/wanddemo.lpr svneol=native#text/plain
|
||||
packages/imagemagick/examples/wandpixelaccess.pas svneol=native#text/plain
|
||||
packages/imagemagick/fpmake.pp svneol=native#text/plain
|
||||
packages/imagemagick/src/buildim.pp svneol=native#text/plain
|
||||
packages/imagemagick/src/cache.inc svneol=native#text/plain
|
||||
packages/imagemagick/src/cache_view.inc svneol=native#text/plain
|
||||
packages/imagemagick/src/compare.inc svneol=native#text/plain
|
||||
packages/imagemagick/src/constitute.inc svneol=native#text/plain
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 9.2 KiB |
@ -28,6 +28,7 @@ end;
|
||||
var
|
||||
status: MagickBooleanType;
|
||||
wand: PMagickWand;
|
||||
|
||||
begin
|
||||
{ Read an image. }
|
||||
|
||||
|
84
packages/imagemagick/examples/wandpixelaccess.pas
Normal file
84
packages/imagemagick/examples/wandpixelaccess.pas
Normal file
@ -0,0 +1,84 @@
|
||||
{
|
||||
Demonstration program for the ImageMagick Library
|
||||
|
||||
Usage: Just execute the program. It will change all black pixels
|
||||
in the image.png image on it's directory to be transparent
|
||||
and then it will save it as image2.png
|
||||
The idea is to demonstrate pixel access using MagickWand.
|
||||
}
|
||||
program wandpixelaccess;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses SysUtils, magick_wand, ImageMagick, ctypes;
|
||||
|
||||
procedure ThrowWandException(wand: PMagickWand);
|
||||
var
|
||||
description: PChar;
|
||||
severity: ExceptionType;
|
||||
begin
|
||||
description := MagickGetException(wand, @severity);
|
||||
WriteLn(Format('An error ocurred. Description: %s', [description]));
|
||||
description := MagickRelinquishMemory(description);
|
||||
Abort;
|
||||
end;
|
||||
|
||||
var
|
||||
status: MagickBooleanType;
|
||||
wand: PMagickWand = nil;
|
||||
pixel: MagickPixelPacket;
|
||||
iterator: PPixelIterator;
|
||||
pixels: PPPixelWand = nil;
|
||||
x, y: Integer;
|
||||
width: culong;
|
||||
begin
|
||||
{ Read an image. }
|
||||
|
||||
MagickWandGenesis;
|
||||
|
||||
wand := NewMagickWand();
|
||||
|
||||
try
|
||||
status := MagickReadImage(wand, 'image.png');
|
||||
if (status = MagickFalse) then ThrowWandException(wand);
|
||||
|
||||
iterator := NewPixelIterator(wand);
|
||||
if (iterator = nil) then ThrowWandException(wand);
|
||||
|
||||
for y := 0 to MagickGetImageHeight(wand) - 1 do
|
||||
begin
|
||||
// WriteLn(' Line ', y, ' from ', MagickGetImageHeight(wand) - 1);
|
||||
pixels := PixelGetNextIteratorRow(iterator, width);
|
||||
if (pixels = nil) then Break;
|
||||
|
||||
for x := 0 to width - 1 do
|
||||
begin
|
||||
// WriteLn(Format(' x %d y %d r %f g %f b %f o %f',
|
||||
// [x, y, pixel.red, pixel.green, pixel.blue, pixel.opacity]));
|
||||
PixelGetMagickColor(pixels[x], @pixel);
|
||||
if (pixel.red = 0.0) and
|
||||
(pixel.green = 0.0) and
|
||||
(pixel.blue = 0.0) then
|
||||
begin
|
||||
pixel.opacity := QuantumRange;
|
||||
pixel.matte := QuantumRange; // matte=alpha
|
||||
end;
|
||||
PixelSetMagickColor(pixels[x], @pixel);
|
||||
end;
|
||||
PixelSyncIterator(iterator);
|
||||
end;
|
||||
|
||||
// if y < MagickGetImageHeight(wand) then ThrowWandException(wand);
|
||||
iterator := DestroyPixelIterator(iterator);
|
||||
|
||||
{ Write the image }
|
||||
|
||||
status := MagickWriteImage(wand, 'image2.png');
|
||||
if (status = MagickFalse) then ThrowWandException(wand);
|
||||
finally
|
||||
{ Clean-up }
|
||||
if wand <> nil then wand := DestroyMagickWand(wand);
|
||||
MagickWandTerminus;
|
||||
end;
|
||||
end.
|
||||
|
66
packages/imagemagick/src/cache.inc
Normal file
66
packages/imagemagick/src/cache.inc
Normal file
@ -0,0 +1,66 @@
|
||||
{
|
||||
Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization
|
||||
dedicated to making software imaging solutions freely available.
|
||||
|
||||
You may not use this file except in compliance with the License.
|
||||
obtain a copy of the License at
|
||||
|
||||
http://www.imagemagick.org/script/license.php
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
MagickCore cache methods.
|
||||
}
|
||||
{
|
||||
Based on ImageMagick 6.5.7
|
||||
}
|
||||
|
||||
//#include "magick/blob.h"
|
||||
|
||||
{extern MagickExport const IndexPacket
|
||||
*GetVirtualIndexQueue(const Image *);
|
||||
|
||||
extern MagickExport const PixelPacket
|
||||
*GetVirtualPixels(const Image *,const long,const long,const unsigned long,
|
||||
const unsigned long,ExceptionInfo *),
|
||||
*GetVirtualPixelQueue(const Image *);
|
||||
|
||||
extern MagickExport IndexPacket
|
||||
*GetAuthenticIndexQueue(const Image *);
|
||||
|
||||
extern MagickExport MagickBooleanType
|
||||
GetOneVirtualMagickPixel(const Image *,const long,const long,
|
||||
MagickPixelPacket *,ExceptionInfo *),
|
||||
GetOneVirtualPixel(const Image *,const long,const long,PixelPacket *,
|
||||
ExceptionInfo *),
|
||||
GetOneVirtualMethodPixel(const Image *,const VirtualPixelMethod,const long,
|
||||
const long,PixelPacket *,ExceptionInfo *),
|
||||
GetOneAuthenticPixel(Image *,const long,const long,PixelPacket *,
|
||||
ExceptionInfo *),
|
||||
InstantiateCacheComponent(void),
|
||||
PersistPixelCache(Image *,const char *,const MagickBooleanType,
|
||||
MagickOffsetType *,ExceptionInfo *),
|
||||
SyncAuthenticPixels(Image *,ExceptionInfo *);
|
||||
|
||||
extern MagickExport MagickSizeType
|
||||
GetImageExtent(const Image *);}
|
||||
|
||||
//extern MagickExport PixelPacket
|
||||
function GetAuthenticPixels(_image: PImage; const x, y: clong;
|
||||
const columns, rows: culong; exception: PExceptionInfo
|
||||
): PPixelPacket; cdecl; external MagickExport;
|
||||
// *GetAuthenticPixelQueue(const Image *),
|
||||
// *QueueAuthenticPixels(Image *,const long,const long,const unsigned long,
|
||||
// const unsigned long,ExceptionInfo *);
|
||||
|
||||
{extern MagickExport VirtualPixelMethod
|
||||
GetPixelCacheVirtualMethod(const Image *),
|
||||
SetPixelCacheVirtualMethod(const Image *,const VirtualPixelMethod);
|
||||
|
||||
extern MagickExport void
|
||||
DestroyCacheFaclity(void);}
|
||||
|
@ -14,7 +14,8 @@
|
||||
limitations under the License.
|
||||
|
||||
ImageMagick Application Programming Interface declarations.
|
||||
|
||||
}
|
||||
{
|
||||
Converted from c by: Felipe Monteiro de Carvalho Dez/2005
|
||||
|
||||
Bug-fixed by Ángel Eduardo García Hernández
|
||||
@ -34,10 +35,18 @@ uses SysUtils, ctypes;
|
||||
|
||||
{$PACKENUM 4}
|
||||
|
||||
// Fix to compile in older FPC versions
|
||||
{$ifdef VER2_2}
|
||||
type
|
||||
Pcsize_t = ^size_t;
|
||||
{$endif}
|
||||
|
||||
const
|
||||
{$ifdef Win32}
|
||||
MagickExport = 'CORE_RL_magick_.dll';
|
||||
WandExport = 'CORE_RL_wand_.dll';
|
||||
{$else}
|
||||
MagickExport = 'libMagickCore';
|
||||
WandExport = 'libWand';
|
||||
{$endif}
|
||||
|
||||
@ -50,7 +59,7 @@ const
|
||||
{#$include annotate.inc}
|
||||
{#$include attribute.inc}
|
||||
{#$include blob.inc}
|
||||
{#$include cache.inc}
|
||||
{$include cache.inc}
|
||||
{$include cache_view.inc}
|
||||
{#include "magick/coder.h"
|
||||
#include "magick/client.h"
|
||||
|
@ -14,7 +14,10 @@
|
||||
limitations under the License.
|
||||
|
||||
ImageMagick MagickWand API.
|
||||
|
||||
}
|
||||
{
|
||||
Based on ImageMagick 6.2
|
||||
|
||||
Converted from c by: Felipe Monteiro de Carvalho Dez/2005
|
||||
|
||||
Bug-fixed by Ángel Eduardo García Hernández
|
||||
|
@ -54,6 +54,8 @@ type
|
||||
|
||||
type
|
||||
MagickPixelPacket = record
|
||||
storage_class: ClassType; // Added after 6.2
|
||||
|
||||
colorspace: ColorspaceType;
|
||||
|
||||
matte: MagickBooleanType;
|
||||
|
@ -82,7 +82,7 @@ function PixelGetYellowQuantum(const wand: PPixelWand): Quantum; cdecl; external
|
||||
function PixelGetColorCount(const wand: PPixelWand): culong; cdecl; external WandExport;
|
||||
|
||||
procedure ClearPixelWand(wand: PPixelWand); cdecl; external WandExport;
|
||||
procedure PixelGetMagickColor(const wand: PPixelWand; packet: PMagickPixelPacket); cdecl; external WandExport;
|
||||
// PixelGetHSL(const PixelWand *,double *,double *,double *), // Added after 6.2
|
||||
procedure PixelGetQuantumColor(const wand: PPixelWand; color: PPixelPacket); cdecl; external WandExport;
|
||||
procedure PixelSetAlpha(wand: PPixelWand; const opacity: Double); cdecl; external WandExport;
|
||||
procedure PixelSetAlphaQuantum(wand: PPixelWand; const opacity: Quantum); cdecl; external WandExport;
|
||||
@ -90,14 +90,18 @@ procedure PixelSetBlack(wand: PPixelWand; const opacity: Double); cdecl; externa
|
||||
procedure PixelSetBlackQuantum(wand: PPixelWand; const opacity: Quantum); cdecl; external WandExport;
|
||||
procedure PixelSetBlue(wand: PPixelWand; const opacity: Double); cdecl; external WandExport;
|
||||
procedure PixelSetBlueQuantum(wand: PPixelWand; const opacity: Quantum); cdecl; external WandExport;
|
||||
// PixelSetColorFromWand(PixelWand *,const PixelWand *), // Added after 6.2
|
||||
procedure PixelSetColorCount(wand: PPixelWand; const count: culong); cdecl; external WandExport;
|
||||
procedure PixelSetCyan(wand: PPixelWand; const opacity: Double); cdecl; external WandExport;
|
||||
procedure PixelSetCyanQuantum(wand: PPixelWand; const opacity: Quantum); cdecl; external WandExport;
|
||||
// PixelSetFuzz(PixelWand *,const double), // Added after 6.2
|
||||
procedure PixelSetGreen(wand: PPixelWand; const opacity: Double); cdecl; external WandExport;
|
||||
procedure PixelSetGreenQuantum(wand: PPixelWand; const opacity: Quantum); cdecl; external WandExport;
|
||||
// PixelSetHSL(PixelWand *,const double,const double,const double), // Added after 6.2
|
||||
procedure PixelSetIndex(wand: PPixelWand; const index: IndexPacket); cdecl; external WandExport;
|
||||
procedure PixelSetMagenta(wand: PPixelWand; const opacity: Double); cdecl; external WandExport;
|
||||
procedure PixelSetMagentaQuantum(wand: PPixelWand; const opacity: Quantum); cdecl; external WandExport;
|
||||
procedure PixelSetMagickColor(wand: PPixelWand; const color: PMagickPixelPacket); cdecl; external WandExport; // Added after 6.2
|
||||
procedure PixelSetOpacity(wand: PPixelWand; const opacity: Double); cdecl; external WandExport;
|
||||
procedure PixelSetOpacityQuantum(wand: PPixelWand; const opacity: Quantum); cdecl; external WandExport;
|
||||
procedure PixelSetQuantumColor(wand: PPixelWand; const color: PPixelPacket); cdecl; external WandExport;
|
||||
@ -106,4 +110,6 @@ procedure PixelSetRedQuantum(wand: PPixelWand; const opacity: Quantum); cdecl; e
|
||||
procedure PixelSetYellow(wand: PPixelWand; const opacity: Double); cdecl; external WandExport;
|
||||
procedure PixelSetYellowQuantum(wand: PPixelWand; const opacity: Quantum); cdecl; external WandExport;
|
||||
|
||||
// Considered a private method in newer versions (after 6.2)
|
||||
procedure PixelGetMagickColor(const wand: PPixelWand; packet: PMagickPixelPacket); cdecl; external WandExport;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user