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

📄 attribute.c

📁 gif图像文件软件解码器的arm版本的源代码程序
💻 C
字号:
///////////////////////////////////////////////////////////////////////////////
//
//  attribute.c
//
//  DESCRIPTION
//        Define functions to get, set, or destroy attributes associated
//        with a particular image (e.g. comments, copyright, author, etc).
//
//
///////////////////////////////////////////////////////////////////////////////


/*
  Include declarations.
*/

#include "gifcommon.h"

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   D e s t r o y I m a g e A t t r i b u t e s                               %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  DestroyImageAttributes() deallocates memory associated with the image
%  attribute list.
%
%  The format of the DestroyImageAttributes method is:
%
%      DestroyImageAttributes(Image *image)
%
%  A description of each parameter follows:
%
%    o image: The image.
%
%
*/
void DestroyImageAttributes
(
    Image   *image
)
{
    ImageAttribute              *attribute;
    register ImageAttribute     *p;

    for (p = image->attributes; p != (ImageAttribute *) OP_NULL; )
    {
        attribute = p;
        p = p->next;
        if (attribute->key != (char *) OP_NULL)
        {
            image->freememory((void *) attribute->key);
        }
        if (attribute->value != (char *) OP_NULL)
        {
            image->freememory((void *) attribute->value);
        }
        image->freememory((void *) attribute);
    }
    image->attributes = (ImageAttribute *) OP_NULL;
}

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   S e t I m a g e A t t r i b u t e                                         %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  SetImageAttribute() searches the list of image attributes and replaces the
%  attribute value.  If it is not found in the list, the attribute name
%  and value is added to the list.   If the attribute exists in the list,
%  the value is concatenated to the attribute.  SetImageAttribute returns
%  True if the attribute is successfully concatenated or added to the list,
%  otherwise False.  If the value is OP_NULL, the matching key is deleted
%  from the list.
%
%  The format of the SetImageAttribute method is:
%
%      unsigned int SetImageAttribute(Image *image,const char *key,
%        const char *value)
%
%  A description of each parameter follows:
%
%    o image: The image.
%
%    o key,value:  These character strings are the name and value of an image
%      attribute to replace or add to the list.
%
%
*/
unsigned int SetImageAttribute
(
    Image           *image,
    const char      *key,
    const char      *value
)
{
    ImageAttribute              *attribute;
    register ImageAttribute     *p;

    /*
    Initialize new attribute.
    */
    if ((key == (const char *) OP_NULL) || (*key == '\0'))
    {
        return(OP_FALSE);
    }
    if (value == (const char *) OP_NULL)
    {
        /*
        Delete attribute from the image attributes list.
        */
        for (p = image->attributes; p != (ImageAttribute *) OP_NULL; p = p->next)
        {
            if (LocaleCompare(key,p->key) == 0)
            {
                break;
            }
        }
        if (p == (ImageAttribute *) OP_NULL)
        {
            return(OP_FALSE);
        }
        if (p->key != (char *) OP_NULL)
        {
            image->freememory((void *) p->key);
        }
        if (p->value != (char *) OP_NULL)
        {
            image->freememory((void *) p->value);
        }
        if (p->previous != (ImageAttribute *) OP_NULL)
        {
            p->previous->next=p->next;
        }
        else
        {
            image->attributes=p->next;
            if (p->next != (ImageAttribute *) OP_NULL)
            {
                p->next->previous=(ImageAttribute *) OP_NULL;
            }
        }
        if (p->next != (ImageAttribute *) OP_NULL)
        {
            p->next->previous = p->previous;
        }
        attribute = p;
        image->freememory((void *) attribute);
        return(OP_TRUE);
    }
    if (*value == '\0')
    {
        return(OP_FALSE);
    }
    attribute = (ImageAttribute *) image->getmemory(sizeof(ImageAttribute));
    if (attribute == (ImageAttribute *) OP_NULL)
    {
        return(OP_FALSE);
    }
    attribute->key = AllocateString(key, image->getmemory);
    if ((LocaleNCompare(key,"IPTC",4) == 0) || (LocaleNCompare(key,"8BIM",4) == 0) ||
            (LocaleNCompare(key,"EXIF",4) == 0) || (LocaleNCompare(key,"comment",7) == 0))
    {
        attribute->value = AllocateString(value, image->getmemory);
    }
    else
    {
        attribute->value = OP_NULL;
    }
    attribute->compression = OP_FALSE;
    attribute->previous = (ImageAttribute *) OP_NULL;
    attribute->next = (ImageAttribute *) OP_NULL;
    
    if (image->attributes == (ImageAttribute *) OP_NULL)
    {
        image->attributes = attribute;
        return(OP_TRUE);
    }
    for (p = image->attributes; p != (ImageAttribute *) OP_NULL; p = p->next)
    {
        if (LocaleCompare(attribute->key,p->key) == 0)
        {
            (void) ConcatenateString(&p->value,attribute->value, image->getmemory,image->freememory);
            image->freememory((void *) attribute->value);
            image->freememory((void *) attribute->key);
            image->freememory((void *) attribute);
            return(OP_TRUE);
        }
        if (p->next == (ImageAttribute *) OP_NULL)
        {
            break;
        }
    }
    /*
    Place new attribute at the end of the attribute list.
    */
    attribute->previous = p;
    p->next = attribute;
    return(OP_TRUE);
}

⌨️ 快捷键说明

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