📄 libmng_object_prc.c
字号:
/* ************************************************************************** *//* * For conditions of distribution and use, * *//* * see copyright notice in libmng.h * *//* ************************************************************************** *//* * * *//* * project : libmng * *//* * file : libmng_object_prc.c copyright (c) 2000 G.Juyn * *//* * version : 1.0.2 * *//* * * *//* * purpose : Object processing routines (implementation) * *//* * * *//* * author : G.Juyn * *//* * web : http://www.3-t.com * *//* * email : mailto:info@3-t.com * *//* * * *//* * comment : implementation of the internal object processing routines * *//* * * *//* * changes : 0.5.1 - 05/08/2000 - G.Juyn * *//* * - changed strict-ANSI stuff * *//* * 0.5.1 - 05/12/2000 - G.Juyn * *//* * - changed trace to macro for callback error-reporting * *//* * * *//* * 0.5.2 - 05/20/2000 - G.Juyn * *//* * - fixed to support JNG objects * *//* * 0.5.2 - 05/24/2000 - G.Juyn * *//* * - added support for global color-chunks in animation * *//* * - added support for global PLTE,tRNS,bKGD in animation * *//* * - added SAVE & SEEK animation objects * *//* * 0.5.2 - 05/29/2000 - G.Juyn * *//* * - added initialization of framenr/layernr/playtime * *//* * - changed ani_object create routines not to return the * *//* * created object (wasn't necessary) * *//* * 0.5.2 - 05/30/2000 - G.Juyn * *//* * - added object promotion routine (PROM handling) * *//* * - added ani-object routines for delta-image processing * *//* * - added compression/filter/interlace fields to * *//* * object-buffer for delta-image processing * *//* * * *//* * 0.5.3 - 06/17/2000 - G.Juyn * *//* * - changed support for delta-image processing * *//* * 0.5.3 - 06/20/2000 - G.Juyn * *//* * - fixed some small things (as precaution) * *//* * 0.5.3 - 06/21/2000 - G.Juyn * *//* * - added processing of PLTE/tRNS & color-info for * *//* * delta-images in the ani_objects chain * *//* * 0.5.3 - 06/22/2000 - G.Juyn * *//* * - added support for PPLT chunk * *//* * * *//* * 0.9.1 - 07/07/2000 - G.Juyn * *//* * - added support for freeze/restart/resume & go_xxxx * *//* * 0.9.1 - 07/16/2000 - G.Juyn * *//* * - fixed support for mng_display() after mng_read() * *//* * * *//* * 0.9.2 - 07/29/2000 - G.Juyn * *//* * - fixed small bugs in display processing * *//* * 0.9.2 - 08/05/2000 - G.Juyn * *//* * - changed file-prefixes * *//* * * *//* * 0.9.3 - 08/07/2000 - G.Juyn * *//* * - B111300 - fixup for improved portability * *//* * 0.9.3 - 08/26/2000 - G.Juyn * *//* * - added MAGN chunk * *//* * 0.9.3 - 09/10/2000 - G.Juyn * *//* * - fixed DEFI behavior * *//* * 0.9.3 - 10/17/2000 - G.Juyn * *//* * - added valid-flag to stored objects for read() / display()* *//* * - added routine to discard "invalid" objects * *//* * 0.9.3 - 10/18/2000 - G.Juyn * *//* * - fixed delta-processing behavior * *//* * 0.9.3 - 10/19/2000 - G.Juyn * *//* * - added storage for pixel-/alpha-sampledepth for delta's * *//* * * *//* * 0.9.4 - 1/18/2001 - G.Juyn * *//* * - removed "old" MAGN methods 3 & 4 * *//* * - added "new" MAGN methods 3, 4 & 5 * *//* * * *//* * 0.9.5 - 1/22/2001 - G.Juyn * *//* * - B129681 - fixed compiler warnings SGI/Irix * *//* * * *//* * 1.0.2 - 06/23/2001 - G.Juyn * *//* * - added optimization option for MNG-video playback * *//* * * *//* ************************************************************************** */#include "libmng.h"#include "libmng_data.h"#include "libmng_error.h"#include "libmng_trace.h"#ifdef __BORLANDC__#pragma hdrstop#endif#include "libmng_memory.h"#include "libmng_objects.h"#include "libmng_display.h"#include "libmng_pixels.h"#include "libmng_object_prc.h"#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI)#pragma option -A /* force ANSI-C */#endif/* ************************************************************************** */#ifdef MNG_INCLUDE_DISPLAY_PROCS/* ************************************************************************** *//* * * *//* * Generic object routines * *//* * * *//* ************************************************************************** */mng_retcode drop_invalid_objects (mng_datap pData){ mng_objectp pObject; mng_objectp pNext; mng_cleanupobject fCleanup;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_DROP_INVALID_OBJECTS, MNG_LC_START)#endif pObject = pData->pFirstimgobj; /* get first stored image-object (if any) */ while (pObject) /* more objects to check ? */ { pNext = ((mng_object_headerp)pObject)->pNext; /* invalid ? */ if (!((mng_imagep)pObject)->bValid) { /* call appropriate cleanup */ fCleanup = ((mng_object_headerp)pObject)->fCleanup; fCleanup (pData, pObject); } pObject = pNext; /* neeeext */ }#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_DROP_INVALID_OBJECTS, MNG_LC_END)#endif return MNG_NOERROR;}/* ************************************************************************** *//* * * *//* * Image-data-object routines * *//* * * *//* * these handle the "object buffer" as defined by the MNG specification * *//* * * *//* ************************************************************************** */mng_retcode create_imagedataobject (mng_datap pData, mng_bool bConcrete, mng_bool bViewable, mng_uint32 iWidth, mng_uint32 iHeight, mng_uint8 iBitdepth, mng_uint8 iColortype, mng_uint8 iCompression, mng_uint8 iFilter, mng_uint8 iInterlace, mng_imagedatap *ppObject){ mng_imagedatap pImagedata; mng_uint32 iSamplesize = 0;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_CREATE_IMGDATAOBJECT, MNG_LC_START)#endif /* get a buffer */ MNG_ALLOC (pData, pImagedata, sizeof (mng_imagedata)) /* fill the appropriate fields */ pImagedata->sHeader.fCleanup = (mng_cleanupobject)free_imagedataobject; pImagedata->sHeader.fProcess = 0; pImagedata->iRefcount = 1; pImagedata->bFrozen = MNG_FALSE; pImagedata->bConcrete = bConcrete; pImagedata->bViewable = bViewable; pImagedata->iWidth = iWidth; pImagedata->iHeight = iHeight; pImagedata->iBitdepth = iBitdepth; pImagedata->iColortype = iColortype; pImagedata->iCompression = iCompression; pImagedata->iFilter = iFilter; pImagedata->iInterlace = iInterlace; pImagedata->iAlphabitdepth = 0; pImagedata->iJHDRcompression = 0; pImagedata->iJHDRinterlace = 0; pImagedata->iPixelsampledepth = iBitdepth; pImagedata->iAlphasampledepth = iBitdepth; /* determine samplesize from color_type/bit_depth */ switch (iColortype) /* for < 8-bit samples we just reserve 8 bits */ { case 0 : ; /* gray */ case 8 : { /* JPEG gray */ if (iBitdepth > 8) iSamplesize = 2; else iSamplesize = 1; break; } case 2 : ; /* rgb */ case 10 : { /* JPEG rgb */ if (iBitdepth > 8) iSamplesize = 6; else iSamplesize = 3; break; } case 3 : { /* indexed */ iSamplesize = 1; break; } case 4 : ; /* gray+alpha */ case 12 : { /* JPEG gray+alpha */ if (iBitdepth > 8) iSamplesize = 4; else iSamplesize = 2; break; } case 6 : ; /* rgb+alpha */ case 14 : { /* JPEG rgb+alpha */ if (iBitdepth > 8) iSamplesize = 8; else iSamplesize = 4; break; } } /* make sure we remember all this */ pImagedata->iSamplesize = iSamplesize; pImagedata->iRowsize = iSamplesize * iWidth; pImagedata->iImgdatasize = pImagedata->iRowsize * iHeight; if (pImagedata->iImgdatasize) /* need a buffer ? */ { /* so allocate it */ MNG_ALLOCX (pData, pImagedata->pImgdata, pImagedata->iImgdatasize) if (!pImagedata->pImgdata) /* enough memory ? */ { MNG_FREEX (pData, pImagedata, sizeof (mng_imagedata)) MNG_ERROR (pData, MNG_OUTOFMEMORY) } } /* check global stuff */ pImagedata->bHasGAMA = pData->bHasglobalGAMA; pImagedata->bHasCHRM = pData->bHasglobalCHRM; pImagedata->bHasSRGB = pData->bHasglobalSRGB; pImagedata->bHasICCP = pData->bHasglobalICCP; pImagedata->bHasBKGD = pData->bHasglobalBKGD; if (pData->bHasglobalGAMA) /* global gAMA present ? */ pImagedata->iGamma = pData->iGlobalGamma; if (pData->bHasglobalCHRM) /* global cHRM present ? */ { pImagedata->iWhitepointx = pData->iGlobalWhitepointx; pImagedata->iWhitepointy = pData->iGlobalWhitepointy; pImagedata->iPrimaryredx = pData->iGlobalPrimaryredx; pImagedata->iPrimaryredy = pData->iGlobalPrimaryredy; pImagedata->iPrimarygreenx = pData->iGlobalPrimarygreenx; pImagedata->iPrimarygreeny = pData->iGlobalPrimarygreeny; pImagedata->iPrimarybluex = pData->iGlobalPrimarybluex; pImagedata->iPrimarybluey = pData->iGlobalPrimarybluey; } if (pData->bHasglobalSRGB) /* glbal sRGB present ? */ pImagedata->iRenderingintent = pData->iGlobalRendintent; if (pData->bHasglobalICCP) /* glbal iCCP present ? */ { pImagedata->iProfilesize = pData->iGlobalProfilesize; if (pImagedata->iProfilesize) { MNG_ALLOCX (pData, pImagedata->pProfile, pImagedata->iProfilesize) if (!pImagedata->pProfile) /* enough memory ? */ { MNG_FREEX (pData, pImagedata->pImgdata, pImagedata->iImgdatasize) MNG_FREEX (pData, pImagedata, sizeof (mng_imagedata)) MNG_ERROR (pData, MNG_OUTOFMEMORY) } MNG_COPY (pImagedata->pProfile, pData->pGlobalProfile, pImagedata->iProfilesize) } } if (pData->bHasglobalBKGD) /* global bKGD present ? */ { pImagedata->iBKGDred = pData->iGlobalBKGDred; pImagedata->iBKGDgreen = pData->iGlobalBKGDgreen; pImagedata->iBKGDblue = pData->iGlobalBKGDblue; } *ppObject = pImagedata; /* return it */#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_CREATE_IMGDATAOBJECT, MNG_LC_END)#endif return MNG_NOERROR;}/* ************************************************************************** */mng_retcode free_imagedataobject (mng_datap pData, mng_imagedatap pImagedata){#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_FREE_IMGDATAOBJECT, MNG_LC_START)#endif if (pImagedata->iRefcount) /* decrease reference count */ pImagedata->iRefcount--; if (!pImagedata->iRefcount) /* reached zero ? */ { if (pImagedata->iProfilesize) /* stored an iCCP profile ? */ MNG_FREEX (pData, pImagedata->pProfile, pImagedata->iProfilesize) if (pImagedata->iImgdatasize) /* sample-buffer present ? */ MNG_FREEX (pData, pImagedata->pImgdata, pImagedata->iImgdatasize) /* drop the buffer */ MNG_FREEX (pData, pImagedata, sizeof (mng_imagedata)) }#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_FREE_IMGDATAOBJECT, MNG_LC_END)#endif return MNG_NOERROR;}/* ************************************************************************** */mng_retcode clone_imagedataobject (mng_datap pData, mng_bool bConcrete, mng_imagedatap pSource, mng_imagedatap *ppClone){ mng_imagedatap pNewdata;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_CLONE_IMGDATAOBJECT, MNG_LC_START)#endif /* get a buffer */ MNG_ALLOC (pData, pNewdata, sizeof (mng_imagedata)) /* blatently copy the original buffer */ MNG_COPY (pNewdata, pSource, sizeof (mng_imagedata)) pNewdata->iRefcount = 1; /* only the reference count */ pNewdata->bConcrete = bConcrete; /* and concrete-flag are different */ if (pNewdata->iImgdatasize) /* sample buffer present ? */ { MNG_ALLOCX (pData, pNewdata->pImgdata, pNewdata->iImgdatasize) if (!pNewdata->pImgdata) /* not enough memory ? */ { MNG_FREEX (pData, pNewdata, sizeof (mng_imagedata))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -