A
download 8bim.c
Language: C
Copyright: (C) 2001 ImageMagick Studio, a non-profit organization dedicated %
LOC: 87
Project Info
bukoo
Server: SourceForge
Type: cvs
...koo\bukoo\jesse_sdk\magick\
   8bim.c
   animate.c
   animate.h
   annotate.c
   api.h
   art.c
   attributes.c
   attributes.h
   avi.c
   avs.c
   blob.c
   blob.h
   bmp.c
   cache.c
   cache.h
   cache_view.c
   cache_view.h
   classify.h
   cmyk.c
   colors.c
   compress.h
   compress_.c
   config.h
   constitute.c
   cut.c
   dcm.c
   decorate.c
   defines.h
   delegates.c
   delegates.h
   display.c
   display.h
   dps.c
   dpx.c
   draw.c
   draw.h
   effects.c
   enhance.c
   ept.c
   error.c
   error.h
   fax.c
   fits.c
   fpx.c
   gems.c
   gems.h
   gif.c
   gradient.c
   gray.c
   hdf.c
   histogram.c
   html.c
   icm.c
   icon.c
   image.c
   image.h
   iptc.c
   jbig.c
   jpeg.c
   label.c
   logo.c
   mac.c
   mac.h
   magic.c
   magic.h
   magick.c
   magick.h
   map.c
   matte.c
   memory.c
   miff.c
   modules.c
   modules.h
   modules.mgk
   monitor.c
   monitor.h
   mono.c
   montage.c
   mpc.c
   mtv.c
   mvg.c
   nt.c
   nt.h
   null.c
   pcd.c
   pcl.c
   pcx.c
   pdb.c
   pdf.c
   pict.c
   pix.c
   plasma.c
   png.c
   pnm.c
   PreRvIcccm.c
   PreRvIcccm.h
   preview.c
   ps.c
   ps2.c
   ps3.c
   psd.c
   pwp.c
   quantize.c
   quantize.h
   rgb.c
   rla.c
   rle.c
   sct.c
   segment.c
   semaphore.c
   semaphore.h
   sfw.c
   sgi.c
   shear.c
   signature.c
   stegano.c
   stream.c
   sun.c
   svg.c
   tga.c
   tiff.c
   tile.c
   tim.c
   timer.c
   timer.h
   transform.c
   ttf.c
   txt.c
   uil.c
   url.c
   utility.c
   utility.h
   uyvy.c
   version.h
   vicar.c
   vid.c
   viff.c
   vms.c
   vms.h
   wbmp.c
   widget.c
   widget.h
   wmf.c
   wpg.c
   x.c
   xbm.c
   xc.c
   xpm.c
   xwd.c
   xwindows.c
   xwindows.h
   yuv.c
   zoom.c

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%                            BBBB   IIIII  M   M                              %
%                            B   B    I    MM MM                              %
%                            BBBB     I    M M M                              %
%                            B   B    I    M   M                              %
%                            BBBB   IIIII  M   M                              %
%                                                                             %
%                                                                             %
%                    Read/Write ImageMagick Image Format.                     %
%                                                                             %
%                                                                             %
%                              Software Design                                %
%                                John Cristy                                  %
%                                 July 1999                                   %
%                                                                             %
%                                                                             %
%  Copyright (C) 2001 ImageMagick Studio, a non-profit organization dedicated %
%  to making software imaging solutions freely available.                     %
%                                                                             %
%  Permission is hereby granted, free of charge, to any person obtaining a    %
%  copy of this software and associated documentation files ("ImageMagick"),  %
%  to deal in ImageMagick without restriction, including without limitation   %
%  the rights to use, copy, modify, merge, publish, distribute, sublicense,   %
%  and/or sell copies of ImageMagick, and to permit persons to whom the       %
%  ImageMagick is furnished to do so, subject to the following conditions:    %
%                                                                             %
%  The above copyright notice and this permission notice shall be included in %
%  all copies or substantial portions of ImageMagick.                         %
%                                                                             %
%  The software is provided "as is", without warranty of any kind, express or %
%  implied, including but not limited to the warranties of merchantability,   %
%  fitness for a particular purpose and noninfringement.  In no event shall   %
%  ImageMagick Studio be liable for any claim, damages or other liability,    %
%  whether in an action of contract, tort or otherwise, arising from, out of  %
%  or in connection with ImageMagick or the use or other dealings in          %
%  ImageMagick.                                                               %
%                                                                             %
%  Except as contained in this notice, the name of the ImageMagick Studio     %
%  shall not be used in advertising or otherwise to promote the sale, use or  %
%  other dealings in ImageMagick without prior written authorization from the %
%  ImageMagick Studio.                                                        %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
  Include declarations.
*/
#include "magick.h"
#include "defines.h"

/*
  Forward declarations.
*/
static unsigned int
  Write8BIMImage(const ImageInfo *,Image *);

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   I s 8 B I M                                                               %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Method Is8BIM returns True if the image format type, identified by the
%  magick string, is 8BIM.
%
%  The format of the Is8BIM method is:
%
%      unsigned int Is8BIM(const unsigned char *magick,
%        const unsigned int length)
%
%  A description of each parameter follows:
%
%    o status:  Method Is8BIM returns True if the image format type is 8BIM.
%
%    o magick: This string is generally the first few bytes of an image file
%      or blob.
%
%    o length: Specifies the length of the magick string.
%
%
*/
static unsigned int Is8BIM(const unsigned char *magick,
  const unsigned int length)
{
  if (length < 4)
    return(False);
  if (LocaleNCompare((char *) magick,"8BIM",4) == 0)
    return(True);
  return(False);
}

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   R e a d 8 B I M I m a g e                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Method Read8BIMImage reads an binary file in the 8BIM format and returns it.
%  It allocates the memory necessary for the new Image structure and returns a
%  pointer to the new image.  This method differs from the other decoder
%  methods in that only the Photoshop resource (8BIM) information is useful in
%  the returned image.
%
%  The format of the Read8BIMImage method is:
%
%      Image *Read8BIMImage(const ImageInfo *image_info,
%        ExceptionInfo *exception)
%
%  A description of each parameter follows:
%
%    o image:  Method Read8BIMImage returns a pointer to the image after
%      reading. A null image is returned if there is a memory shortage or if
%      the image cannot be read.
%
%    o image_info: Specifies a pointer to an ImageInfo structure.
%
%    o exception: return any errors or warnings in this structure.
%
%
*/
static Image *Read8BIMImage(const ImageInfo *image_info,
  ExceptionInfo *exception)
{
  Image
    *image;

  int
    c;

  register unsigned char
    *q;

  unsigned int
    length,
    status;

  /*
    Open image file.
  */
  image=AllocateImage(image_info);
  status=OpenBlob(image_info,image,ReadBinaryType);
  if (status == False)
    ThrowReaderException(FileOpenWarning,"Unable to open file",image);
  image->columns=1;
  image->rows=1;
  SetImage(image,OpaqueOpacity);
  /*
    Read 8BIM image.
  */
  length=MaxTextExtent;
  image->iptc_profile.info=(unsigned char *) AcquireMemory(length+2);
  for (q=image->iptc_profile.info; image->iptc_profile.info; q++)
  {
    c=ReadBlobByte(image);
    if (c == EOF)
      break;
    if ((q-image->iptc_profile.info+1) >= (int) length)
      {
        image->iptc_profile.length=q-image->iptc_profile.info;
        length<<=1;
        ReacquireMemory((void **) &image->iptc_profile.info,length+2);
        if (image->iptc_profile.info == (unsigned char *) NULL)
          break;
        q=image->iptc_profile.info+image->iptc_profile.length;
      }
    *q=(unsigned char) c;
  }
  if (image->iptc_profile.info == (unsigned char *) NULL)
    ThrowReaderException(FileOpenWarning,"Memory allocation failed",image);
  image->iptc_profile.length=q-image->iptc_profile.info;
  CloseBlob(image);
  return(image);
}

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   R e g i s t e r 8 B I M I m a g e                                         %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Method Register8BIMImage adds attributes for the 8BIM image format to
%  the list of supported formats.  The attributes include the image format
%  tag, a method to read and/or write the format, whether the format
%  supports the saving of more than one frame to the same file or blob,
%  whether the format supports native in-memory I/O, and a brief
%  description of the format.
%
%  The format of the Register8BIMImage method is:
%
%      Register8BIMImage(void)
%
*/
ModuleExport void Register8BIMImage(void)
{
  MagickInfo
    *entry;

  entry=SetMagickInfo("8BIM");
  entry->decoder=Read8BIMImage;
  entry->encoder=Write8BIMImage;
  entry->magick=Is8BIM;
  entry->adjoin=False;
  entry->description=AllocateString("Photoshop resource format");
  entry->module=AllocateString("8BIM");
  RegisterMagickInfo(entry);
}

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   U n r e g i s t e r 8 B I M I m a g e                                     %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Method UnregisterBIMImage removes format registrations made by the
%  BIM module from the list of supported formats.
%
%  The format of the UnregisterBIMImage method is:
%
%      Unregister8BIMImage(void)
%
*/
ModuleExport void Unregister8BIMImage(void)
{
  UnregisterMagickInfo("8BIM");
}

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   W r i t e 8 B I M I m a g e                                               %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Method Write8BIMImage writes an image in the 8BIM format.
%
%  The format of the Write8BIMImage method is:
%
%      unsigned int Write8BIMImage(const ImageInfo *image_info,Image *image)
%
%  A description of each parameter follows.
%
%    o status: Method Write8BIMImage return True if the image is written.
%      False is returned is there is a memory shortage or if the image file
%      fails to write.
%
%    o image_info: Specifies a pointer to an ImageInfo structure.
%
%    o image:  A pointer to a Image structure.
%
%
*/
static unsigned int Write8BIMImage(const ImageInfo *image_info,Image *image)
{
  unsigned int
    status;

  if (image->iptc_profile.length == 0)
    ThrowWriterException(FileOpenWarning,"No 8BIM data is available",image);
  /*
    Open image file.
  */
  status=OpenBlob(image_info,image,WriteBinaryType);
  if (status == False)
    ThrowWriterException(FileOpenWarning,"Unable to open file",image);
  (void) WriteBlob(image,(int) image->iptc_profile.length,
    (char *) image->iptc_profile.info);
  CloseBlob(image);
  return(True);
}

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us