⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 image.c

📁 gif图像文件软件解码器的arm版本的源代码程序
💻 C
字号:
///////////////////////////////////////////////////////////////////////////////
//
//  image.c
//
//  DESCRIPTION
//        Define functions for image handling
//
//
///////////////////////////////////////////////////////////////////////////////


/*
  Include declarations.
*/

#include "gifcommon.h"


/*
I am not sure whether this declaration is necessary or not.
I think that this is unnecessary. maybe...
*/
/*
  Constant declaration.
*/
const char
  *AppendBinaryType = "ab",
  *BackgroundColor = "#ffffff",  /* white */
  *BorderColor = "#dfdfdf",  /* gray */
  *DefaultTileFrame = "15x15+3+3",
  *DefaultTileGeometry = "120x120+4+3>",
  *DefaultTileLabel = "%f\n%wx%h\n%b",
  *ForegroundColor = "#000000",  /* black */
  *LoadImageText = "  Loading image...  ",
  *LoadImagesText = "  Loading images...  ",
  *MatteColor = "#bdbdbd",  /* gray */
  *PSDensityGeometry = "72.0x72.0",
  *PSPageGeometry = "612x792>",
  *ReadBinaryType = "rb",
  *ReadBinaryUnbufferedType = "rbu",
  *SaveImageText = "  Saving image...  ",
  *SaveImagesText = "  Saving images...  ",
  *WriteBinaryType = "wb";

const unsigned long  DefaultCompressionQuality = 75;


/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   A l l o c a t e I m a g e                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% AllocateImage() returns a pointer to an image structure initialized to
% default values.
%
%  The format of the AllocateImage method is:
%
%      Image *AllocateImage(const ImageInfo *image_info)
%
%  A description of each parameter follows:
%
%    o image_info: Many of the image default values are set from this
%      structure.  For example, filename, compression, depth, background color,
%      and others.
%
%
*/
Image *AllocateImage
(
    const Image     *image_info
)
{
    Image    *allocate_image;

    /*
    Allocate image structure.
    */
    allocate_image = (Image *) image_info->getmemory(sizeof(Image));
    if (allocate_image == (Image *) OP_NULL)
    {
        return OP_NULL;
    }
    (void) memset(allocate_image, 0, sizeof(Image));
    /*
    Initialize Image structure.
    */
    allocate_image->pixeldata = OP_NULL;
    allocate_image->pixeldatasize = 0;
    allocate_image->depth = QuantumDepth;
    allocate_image->interlace = NoInterlace;
    allocate_image->blob = CloneBlobInfo((BlobInfo *) OP_NULL, image_info->getmemory);
    if (image_info == OP_NULL)
    {
        return(allocate_image);
    }
    /*
    Transfer image info.
    */
    allocate_image->getmemory = image_info->getmemory;
    allocate_image->freememory = image_info->freememory;
    allocate_image->interlace = image_info->interlace;
    allocate_image->depth = image_info->depth;
    allocate_image->background_color = image_info->background_color;
    allocate_image->border_color = image_info->border_color;
    allocate_image->matte_color = image_info->matte_color;
    allocate_image->page = image_info->page;  
    if(image_info->blob) 
    {
        *allocate_image->blob = (*image_info->blob);
    }
    return(allocate_image);
}

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   A l l o c a t e I m a g e C o l o r m a p                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  AllocateImageColormap() allocates an image colormap and initializes
%  it to a linear gray colorspace.  If the image already has a colormap,
%  it is replaced.  AllocateImageColormap() returns True if successful,
%  otherwise False if there is not enough memory.
%
%  The format of the AllocateImageColormap method is:
%
%      unsigned int AllocateImageColormap(Image *image,
%        const unsigned long colors)
%
%  A description of each parameter follows:
%
%    o image: The image.
%
%    o colors: The number of colors in the image colormap.
%
%
*/
unsigned int AllocateImageColormap
(
    Image                   *image,
    const unsigned long     colors
)
{
    register long    i;

    unsigned int     length;

    /*
    Allocate image colormap.
    */
    image->colors = colors;
    length = Max(image->colors,MaxRGB+1)*sizeof(PixelPacket);
    if (image->colormap == (PixelPacket *) OP_NULL)
    {
        image->colormap=(PixelPacket *) image->getmemory(length);
    }
    else
    {
        ReacquireMemory((void **) &image->colormap, length, image->getmemory, image->freememory);
    }
    if (image->colormap == (PixelPacket *) OP_NULL)
    {
        return(OP_FALSE);
    }
    for (i=0; i < (long) image->colors; i++)
    {
        image->colormap[i].red = (Quantum) ((unsigned long) (MaxRGB*i)/Max(colors-1,1));
        image->colormap[i].green = (Quantum) ((unsigned long) (MaxRGB*i)/Max(colors-1,1));
        image->colormap[i].blue = (Quantum) ((unsigned long) (MaxRGB*i)/Max(colors-1,1));
        image->colormap[i].opacity = OpaqueOpacity;
    }
    
    return(OP_TRUE);
}

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   A l l o c a t e N e x t I m a g e                                         %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Use AllocateNextImage() to initialize the next image in a sequence to
%  default values.  The next member of image points to the newly allocated
%  image.  If there is a memory shortage, next is assigned OP_NULL.
%
%  The format of the AllocateNextImage method is:
%
%      void AllocateNextImage(const ImageInfo *image_info,Image *image)
%
%  A description of each parameter follows:
%
%    o image_info: Many of the image default values are set from this
%      structure.  For example, filename, compression, depth, background color,
%      and others.
%
%    o image: The image.
%
%
*/
void AllocateNextImage
(
    Image   *image
)
{
    /*
    Allocate image structure.
    */
    image->next = AllocateImage(image);
    if (image->next == (Image *) OP_NULL)
    {
        return;
    }
    image->next->previous = image;
}

 /*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   D e s t r o y I m a g e                                                   %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  DestroyImage() dereferences an image, deallocating memory associated with
%  the image if the reference count becomes zero.
%
%  The format of the DestroyImage method is:
%
%      void DestroyImage(Image *image)
%
%  A description of each parameter follows:
%
%    o image: The image.
%
%
*/
void DestroyImage
(
    Image   *image
)
{
    /*
    Dereference image.
    */

    /*
    Destroy image.
    */
    /*
    Investigate for CloseBlob()
    I think that CloseBlob is unnecessary.
    */
    CloseBlob(image);
    if (image->colormap != (PixelPacket *) OP_NULL)
    {
        image->freememory((void *) image->colormap);
    }
    DestroyImageAttributes(image);
    DestroyBlobInfo(image->blob, image->freememory);
    image->freememory((void *) image);
}

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   D e s t r o y I m a g e s                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  DestroyImages() is a convenience method.  It calls DestroyImage() for each
%  image in the sequence.
%
%  The format of the DestroyImages method is:
%
%      void DestroyImages(Image *image)
%
%  A description of each parameter follows:
%
%    o image: The image sequence.
%
%
*/
void DestroyImages
(
    Image *image
)
{
    Image    *next;

    /*
    Proceed to the top of the image list.
    */
    while (image->previous != (Image *) OP_NULL)
    image = image->previous;
    do
    {
        /*
          Destroy this image.
        */
        next = image->next;
        if (next != (Image *)OP_NULL)
        {
            next->previous = (Image *) OP_NULL;
        }
        DestroyImage(image);
        image = next;
    } while (image != (Image *) OP_NULL);
}

const PixelPacket *AcquireImagePixels
(
    const Image             *image, 
    const long              x, 
    const long              y,
    const unsigned long     width, 
    const unsigned long     height
)
{
    if(image->pixeldata == OP_NULL) 
    {
        return OP_NULL;
    }
    else
    {
        return (image->pixeldata + image->columns * y + x);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -