Exemplo n.º 1
0
static int IntensityCompare(const void *x,const void *y)
{
  const PixelInfo
    *color_1,
    *color_2;

  int
    intensity;

  color_1=(const PixelInfo *) x;
  color_2=(const PixelInfo *) y;
  intensity=(int) GetPixelInfoIntensity((const Image *) NULL,color_2)-(int)
    GetPixelInfoIntensity((const Image *) NULL,color_1);
  return(intensity);
}
Exemplo n.º 2
0
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   R e a d G R A D I E N T I m a g e                                         %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  ReadGRADIENTImage creates a gradient image and initializes it to
%  the color range as specified by the filename.  It allocates the memory
%  necessary for the new Image structure and returns a pointer to the new
%  image.
%
%  The format of the ReadGRADIENTImage method is:
%
%      Image *ReadGRADIENTImage(const ImageInfo *image_info,
%        ExceptionInfo *exception)
%
%  A description of each parameter follows:
%
%    o image_info: the image info.
%
%    o exception: return any errors or warnings in this structure.
%
*/
static Image *ReadGRADIENTImage(const ImageInfo *image_info,
  ExceptionInfo *exception)
{
  char
    colorname[MaxTextExtent];

  Image
    *image;

  MagickBooleanType
    status;

  PixelInfo
    start_color,
    stop_color;

  /*
    Initialize Image structure.
  */
  assert(image_info != (const ImageInfo *) NULL);
  assert(image_info->signature == MagickSignature);
  if (image_info->debug != MagickFalse)
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
      image_info->filename);
  assert(exception != (ExceptionInfo *) NULL);
  assert(exception->signature == MagickSignature);
  image=AcquireImage(image_info,exception);
  if ((image->columns == 0) || (image->rows == 0))
    ThrowReaderException(OptionError,"MustSpecifyImageSize");
  (void) SetImageAlpha(image,(Quantum) TransparentAlpha,exception);
  (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
  (void) CopyMagickString(colorname,image_info->filename,MaxTextExtent);
  (void) sscanf(image_info->filename,"%[^-]",colorname);
  status=QueryColorCompliance(colorname,AllCompliance,&start_color,exception);
  if (status == MagickFalse)
    {
      image=DestroyImage(image);
      return((Image *) NULL);
    }
  (void) CopyMagickString(colorname,"white",MaxTextExtent);
  if (GetPixelInfoIntensity(&start_color) > (Quantum) (QuantumRange/2))
    (void) CopyMagickString(colorname,"black",MaxTextExtent);
  (void) sscanf(image_info->filename,"%*[^-]-%s",colorname);
  status=QueryColorCompliance(colorname,AllCompliance,&stop_color,exception);
  if (status == MagickFalse)
    {
      image=DestroyImage(image);
      return((Image *) NULL);
    }
  (void) GradientImage(image,LocaleCompare(image_info->magick,"GRADIENT") == 0 ?
    LinearGradient : RadialGradient,PadSpread,&start_color,&stop_color,
    exception);
  return(GetFirstImageInList(image));
}
Exemplo n.º 3
0
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   W r i t e U I L I m a g e                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Procedure WriteUILImage() writes an image to a file in the X-Motif UIL table
%  format.
%
%  The format of the WriteUILImage method is:
%
%      MagickBooleanType WriteUILImage(const ImageInfo *image_info,
%        Image *image,ExceptionInfo *exception)
%
%  A description of each parameter follows.
%
%    o image_info: the image info.
%
%    o image:  The image.
%
%    o exception: return any errors or warnings in this structure.
%
*/
static MagickBooleanType WriteUILImage(const ImageInfo *image_info,Image *image,
                                       ExceptionInfo *exception)
{
#define MaxCixels  92

    char
    basename[MagickPathExtent],
             buffer[MagickPathExtent],
             name[MagickPathExtent],
             *symbol;

    int
    j;

    MagickBooleanType
    status,
    transparent;

    MagickSizeType
    number_pixels;

    PixelInfo
    pixel;

    register const Quantum
    *p;

    register ssize_t
    i,
    x;

    size_t
    characters_per_pixel,
    colors;

    ssize_t
    k,
    y;

    static const char
    Cixel[MaxCixels+1] = " .XoO+@#$%&*=-;:>,<1234567890qwertyuipasdfghjk"
                         "lzxcvbnmMNBVCZASDFGHJKLPIUYTREWQ!~^/()_`'][{}|";

    /*
      Open output image file.
    */
    assert(image_info != (const ImageInfo *) NULL);
    assert(image_info->signature == MagickCoreSignature);
    assert(image != (Image *) NULL);
    assert(image->signature == MagickCoreSignature);
    if (image->debug != MagickFalse)
        (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
    assert(exception != (ExceptionInfo *) NULL);
    assert(exception->signature == MagickCoreSignature);
    status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
    if (status == MagickFalse)
        return(status);
    (void) TransformImageColorspace(image,sRGBColorspace,exception);
    transparent=MagickFalse;
    i=0;
    p=(const Quantum *) NULL;
    if (image->storage_class == PseudoClass)
        colors=image->colors;
    else
    {
        unsigned char
        *matte_image;

        /*
          Convert DirectClass to PseudoClass image.
        */
        matte_image=(unsigned char *) NULL;
        if (image->alpha_trait != UndefinedPixelTrait)
        {
            /*
              Map all the transparent pixels.
            */
            number_pixels=(MagickSizeType) image->columns*image->rows;
            if (number_pixels != ((MagickSizeType) (size_t) number_pixels))
                ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
            matte_image=(unsigned char *) AcquireQuantumMemory(image->columns,
                        image->rows*sizeof(*matte_image));
            if (matte_image == (unsigned char *) NULL)
                ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
            for (y=0; y < (ssize_t) image->rows; y++)
            {
                p=GetVirtualPixels(image,0,y,image->columns,1,exception);
                if (p == (const Quantum *) NULL)
                    break;
                for (x=0; x < (ssize_t) image->columns; x++)
                {
                    matte_image[i]=(unsigned char) (GetPixelAlpha(image,p) ==
                                                    (Quantum) TransparentAlpha ? 1 : 0);
                    if (matte_image[i] != 0)
                        transparent=MagickTrue;
                    i++;
                    p+=GetPixelChannels(image);
                }
            }
        }
        (void) SetImageType(image,PaletteType,exception);
        colors=image->colors;
        if (transparent != MagickFalse)
        {
            register Quantum
            *q;

            colors++;
            for (y=0; y < (ssize_t) image->rows; y++)
            {
                q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
                if (q == (Quantum *) NULL)
                    break;
                for (x=0; x < (ssize_t) image->columns; x++)
                {
                    if (matte_image[i] != 0)
                        SetPixelIndex(image,(Quantum) image->colors,q);
                    q+=GetPixelChannels(image);
                }
            }
        }
        if (matte_image != (unsigned char *) NULL)
            matte_image=(unsigned char *) RelinquishMagickMemory(matte_image);
    }
    /*
      Compute the character per pixel.
    */
    characters_per_pixel=1;
    for (k=MaxCixels; (ssize_t) colors > k; k*=MaxCixels)
        characters_per_pixel++;
    /*
      UIL header.
    */
    symbol=AcquireString("");
    (void) WriteBlobString(image,"/* UIL */\n");
    GetPathComponent(image->filename,BasePath,basename);
    (void) FormatLocaleString(buffer,MagickPathExtent,
                              "value\n  %s_ct : color_table(\n",basename);
    (void) WriteBlobString(image,buffer);
    GetPixelInfo(image,&pixel);
    for (i=0; i < (ssize_t) colors; i++)
    {
        /*
          Define UIL color.
        */
        pixel=image->colormap[i];
        pixel.colorspace=sRGBColorspace;
        pixel.depth=8;
        pixel.alpha=(double) OpaqueAlpha;
        GetColorTuple(&pixel,MagickTrue,name);
        if (transparent != MagickFalse)
            if (i == (ssize_t) (colors-1))
                (void) CopyMagickString(name,"None",MagickPathExtent);
        /*
          Write UIL color.
        */
        k=i % MaxCixels;
        symbol[0]=Cixel[k];
        for (j=1; j < (int) characters_per_pixel; j++)
        {
            k=((i-k)/MaxCixels) % MaxCixels;
            symbol[j]=Cixel[k];
        }
        symbol[j]='\0';
        (void) SubstituteString(&symbol,"'","''");
        if (LocaleCompare(name,"None") == 0)
            (void) FormatLocaleString(buffer,MagickPathExtent,
                                      "    background color = '%s'",symbol);
        else
            (void) FormatLocaleString(buffer,MagickPathExtent,
                                      "    color('%s',%s) = '%s'",name,
                                      GetPixelInfoIntensity(image,image->colormap+i) <
                                      (QuantumRange/2.0) ? "background" : "foreground",symbol);
        (void) WriteBlobString(image,buffer);
        (void) FormatLocaleString(buffer,MagickPathExtent,"%s",
                                  (i == (ssize_t) (colors-1) ? ");\n" : ",\n"));
        (void) WriteBlobString(image,buffer);
    }
    /*
      Define UIL pixels.
    */
    GetPathComponent(image->filename,BasePath,basename);
    (void) FormatLocaleString(buffer,MagickPathExtent,
                              "  %s_icon : icon(color_table = %s_ct,\n",basename,basename);
    (void) WriteBlobString(image,buffer);
    for (y=0; y < (ssize_t) image->rows; y++)
    {
        p=GetVirtualPixels(image,0,y,image->columns,1,exception);
        if (p == (const Quantum *) NULL)
            break;
        (void) WriteBlobString(image,"    \"");
        for (x=0; x < (ssize_t) image->columns; x++)
        {
            k=((ssize_t) GetPixelIndex(image,p) % MaxCixels);
            symbol[0]=Cixel[k];
            for (j=1; j < (int) characters_per_pixel; j++)
            {
                k=(((int) GetPixelIndex(image,p)-k)/MaxCixels) %
                  MaxCixels;
                symbol[j]=Cixel[k];
            }
            symbol[j]='\0';
            (void) CopyMagickString(buffer,symbol,MagickPathExtent);
            (void) WriteBlobString(image,buffer);
            p+=GetPixelChannels(image);
        }
        (void) FormatLocaleString(buffer,MagickPathExtent,"\"%s\n",
                                  (y == (ssize_t) (image->rows-1) ? ");" : ","));
        (void) WriteBlobString(image,buffer);
        status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
                                image->rows);
        if (status == MagickFalse)
            break;
    }
    symbol=DestroyString(symbol);
    (void) CloseBlob(image);
    return(MagickTrue);
}
Exemplo n.º 4
0
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   R e a d G R A D I E N T I m a g e                                         %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  ReadGRADIENTImage creates a gradient image and initializes it to
%  the color range as specified by the filename.  It allocates the memory
%  necessary for the new Image structure and returns a pointer to the new
%  image.
%
%  The format of the ReadGRADIENTImage method is:
%
%      Image *ReadGRADIENTImage(const ImageInfo *image_info,
%        ExceptionInfo *exception)
%
%  A description of each parameter follows:
%
%    o image_info: the image info.
%
%    o exception: return any errors or warnings in this structure.
%
*/
static Image *ReadGRADIENTImage(const ImageInfo *image_info,
  ExceptionInfo *exception)
{
  char
    colorname[MagickPathExtent+4];

  Image
    *image;

  ImageInfo
    *read_info;

  MagickBooleanType
    icc_color,
    status;

  StopInfo
    *stops;

  /*
    Initialize Image structure.
  */
  assert(image_info != (const ImageInfo *) NULL);
  assert(image_info->signature == MagickCoreSignature);
  if (image_info->debug != MagickFalse)
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
      image_info->filename);
  assert(exception != (ExceptionInfo *) NULL);
  assert(exception->signature == MagickCoreSignature);
  read_info=CloneImageInfo(image_info);
  SetImageInfoBlob(read_info,(void *) NULL,0);
  (void) CopyMagickString(colorname,image_info->filename,MagickPathExtent);
  (void) sscanf(image_info->filename,"%[^-]",colorname);
  (void) FormatLocaleString(read_info->filename,MagickPathExtent,"xc:%s",
    colorname);
  image=ReadImage(read_info,exception);
  read_info=DestroyImageInfo(read_info);
  if (image == (Image *) NULL)
    return((Image *) NULL);
  (void) SetImageAlpha(image,(Quantum) TransparentAlpha,exception);
  (void) CopyMagickString(image->filename,image_info->filename,MagickPathExtent);
  icc_color=MagickFalse;
  if (LocaleCompare(colorname,"icc") == 0)
    {
      (void) ConcatenateMagickString(colorname,"-",MagickPathExtent);
      (void) sscanf(image_info->filename,"%*[^-]-%[^-]",colorname+4);
      icc_color=MagickTrue;
    }
  stops=(StopInfo *) AcquireQuantumMemory(2,sizeof(*stops));
  if (stops == (StopInfo *) NULL)
    ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
  stops[0].offset=0.0;
  stops[1].offset=1.0;
  status=QueryColorCompliance(colorname,AllCompliance,&stops[0].color,exception);
  if (status == MagickFalse)
    {
      stops=(StopInfo *) RelinquishMagickMemory(stops);
      image=DestroyImage(image);
      return((Image *) NULL);
    }
  (void) SetImageColorspace(image,stops[0].color.colorspace,exception);
  (void) CopyMagickString(colorname,"white",MagickPathExtent);
  if (GetPixelInfoIntensity(image,&stops[0].color) > (QuantumRange/2.0))
    (void) CopyMagickString(colorname,"black",MagickPathExtent);
  if (icc_color == MagickFalse)
    (void) sscanf(image_info->filename,"%*[^-]-%[^-]",colorname);
  else
    (void) sscanf(image_info->filename,"%*[^-]-%*[^-]-%[^-]",colorname);
  status=QueryColorCompliance(colorname,AllCompliance,&stops[1].color,exception);
  if (status == MagickFalse)
    {
      stops=(StopInfo *) RelinquishMagickMemory(stops);
      image=DestroyImage(image);
      return((Image *) NULL);
    }
  image->alpha_trait=stops[0].color.alpha_trait;
  if (stops[1].color.alpha_trait != UndefinedPixelTrait)
    image->alpha_trait=stops[1].color.alpha_trait;
  status=GradientImage(image,LocaleCompare(image_info->magick,"GRADIENT") == 0 ?
    LinearGradient : RadialGradient,PadSpread,stops,2,exception);
  stops=(StopInfo *) RelinquishMagickMemory(stops);
  if (status == MagickFalse)
    {
      image=DestroyImageList(image);
      return((Image *) NULL);
    }
  return(GetFirstImageInList(image));
}