X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=www%2Fmagick-core.html;h=fddb580a09674400248f8459f6dffce9709bdb6f;hb=f827fac67b6458d82d4ae4d52cae4e68b3973d3f;hp=7fcd5da019a25f4a1adae42677e442a02dd7ed11;hpb=c496086ea0b28b69bbfc994d93bbbd86c1732425;p=imagemagick diff --git a/www/magick-core.html b/www/magick-core.html index 7fcd5da01..fddb580a0 100644 --- a/www/magick-core.html +++ b/www/magick-core.html @@ -3,20 +3,17 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - - - - - - ImageMagick: MagickCore, Low-level C API for ImageMagick + + + ImageMagick: MagickCore, Low-level C API for ImageMagick + + + - @@ -25,6 +22,12 @@ + + + + @@ -43,12 +46,25 @@ style="width: 114px; height: 118px; border: 0px; float: right;" /> -
+
+ +
+ Unix +
+ +
+ Windows +
+
@@ -76,9 +92,6 @@ -
-
- Unix -
- - -
@@ -125,30 +128,42 @@
+
- +
+ +
@@ -192,6 +207,7 @@
  • Interactively Animate an Image Sequence
  • Convert to and from Cipher Pixels
  • Working with Image Lists
  • +
  • Image View Methods
  • Get or Set Image Pixels
  • Working with Cache Views
  • The Pixel FIFO
  • @@ -210,7 +226,7 @@

    After you write your MagickCore program, compile it like this:

    -

    $magick> cc `MagickCore-config --cflags --cppflags` core.c \
    `MagickCore-config --ldflags --libs`

    +

    $magick> cc `MagickCore-config --cflags --cppflags` -O2 core.c \
    `MagickCore-config --ldflags --libs`

    Here is a example program that utilizes the MagickCore API to get you started, core.c. It reads a GIF image, creates a thumbnail, and writes it to disk in the PNG image format.

    @@ -280,14 +296,136 @@ }
    +

    Now lets perform the same contrast enhancement while taking advantage of our dual or quad-core processing system by running the algorithm in parallel utilizing wand views. The sigmoidal-contrast.c module reads an image, applies sigmoidal non-linearity contrast control, and writes the result to disk just like the previous contrast enhancement program, but now it does its work in parallel (assumes ImageMagick is built with OpenMP support).

    + +
    +
    +#include <stdio.h>
    +#include <stdlib.h>
    +#include <math.h>
    +#include <magick/MagickCore.h>
    +
    +static MagickBooleanType SigmoidalContrast(ImageView *contrast_view,
    +  const ssize_t y,const int id,void *context)
    +{
    +#define QuantumScale  ((MagickRealType) 1.0/(MagickRealType) QuantumRange)
    +#define SigmoidalContrast(x) \
    +  (QuantumRange*(1.0/(1+exp(10.0*(0.5-QuantumScale*x)))-0.0066928509)*1.0092503)
    +
    +  RectangleInfo
    +    extent;
    +
    +  register IndexPacket
    +    *indexes;
    +
    +  register PixelPacket
    +    *pixels;
    +
    +  register ssize_t
    +    x;
    +
    +  extent=GetImageViewExtent(contrast_view);
    +  pixels=GetImageViewAuthenticPixels(contrast_view);
    +  for (x=0; x < (ssize_t) (extent.width-extent.x); x++)
    +  {
    +    pixels[x].red=RoundToQuantum(SigmoidalContrast(pixels[x].red));
    +    pixels[x].green=RoundToQuantum(SigmoidalContrast(pixels[x].green));
    +    pixels[x].blue=RoundToQuantum(SigmoidalContrast(pixels[x].blue));
    +    pixels[x].opacity=RoundToQuantum(SigmoidalContrast(pixels[x].opacity));
    +  }
    +  indexes=GetImageViewAuthenticIndexes(contrast_view);
    +  if (indexes != (IndexPacket *) NULL)
    +    for (x=0; x < (ssize_t) (extent.width-extent.x); x++)
    +      indexes[x]=(IndexPacket) RoundToQuantum(SigmoidalContrast(indexes[x]));
    +  return(MagickTrue);
    +}
    +
    +int main(int argc,char **argv)
    +{
    +#define ThrowImageException(image) \
    +{ \
    + \
    +  CatchException(exception); \
    +  if (contrast_image != (Image *) NULL) \
    +    contrast_image=DestroyImage(contrast_image); \
    +  exit(-1); \
    +}
    +#define ThrowViewException(view) \
    +{ \
    +  char \
    +    *description; \
    + \
    +  ExceptionType \
    +    severity; \
    + \
    +  description=GetImageViewException(view,&severity); \
    +  (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
    +  description=DestroyString(description); \
    +  exit(-1); \
    +}
    +
    +  ExceptionInfo
    +    *exception;
    +
    +  Image
    +    *contrast_image;
    +
    +  ImageInfo
    +    *image_info;
    +
    +  ImageView
    +    *contrast_view;
    +
    +  MagickBooleanType
    +    status;
    +
    +  if (argc != 3)
    +    {
    +      (void) fprintf(stdout,"Usage: %s image sigmoidal-image\n",argv[0]);
    +      exit(0);
    +    }
    +  /*
    +    Read an image.
    +  */
    +  MagickCoreGenesis(*argv,MagickTrue);
    +  image_info=AcquireImageInfo();
    +  (void) CopyMagickString(image_info->filename,argv[1],MaxTextExtent);
    +  exception=AcquireExceptionInfo();
    +  contrast_image=ReadImage(image_info,exception);
    +  if (contrast_image == (Image *) NULL)
    +    ThrowImageException(contrast_image);
    +  /*
    +    Sigmoidal non-linearity contrast control.
    +  */
    +  contrast_view=NewImageView(contrast_image);
    +  if (contrast_view == (ImageView *) NULL)
    +    ThrowImageException(contrast_image);
    +  status=UpdateImageViewIterator(contrast_view,SigmoidalContrast,(void *) NULL);
    +  if (status == MagickFalse)
    +    ThrowImageException(contrast_image);
    +  contrast_view=DestroyImageView(contrast_view);
    +  /*
    +    Write the image then destroy it.
    +  */
    +  status=WriteImages(image_info,contrast_image,argv[2],exception);
    +  if (status == MagickFalse)
    +    ThrowImageException(contrast_image);
    +  contrast_image=DestroyImage(contrast_image);
    +  exception=DestroyExceptionInfo(exception);
    +  image_info=DestroyImageInfo(image_info);
    +  MagickCoreTerminus();
    +  return(0);
    +}
    +
    +
    @@ -296,5 +434,16 @@ Contact the Wizards
    +