📄 libmng_object_prc.c
字号:
{ /* 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;#ifndef MNG_SKIPCHUNK_cHRM pImagedata->bHasCHRM = pData->bHasglobalCHRM;#endif pImagedata->bHasSRGB = pData->bHasglobalSRGB;#ifndef MNG_SKIPCHUNK_iCCP pImagedata->bHasICCP = pData->bHasglobalICCP;#endif#ifndef MNG_SKIPCHUNK_bKGD pImagedata->bHasBKGD = pData->bHasglobalBKGD;#endif if (pData->bHasglobalGAMA) /* global gAMA present ? */ pImagedata->iGamma = pData->iGlobalGamma;#ifndef MNG_SKIPCHUNK_cHRM 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; }#endif if (pData->bHasglobalSRGB) /* glbal sRGB present ? */ pImagedata->iRenderingintent = pData->iGlobalRendintent;#ifndef MNG_SKIPCHUNK_iCCP 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); } }#endif#ifndef MNG_SKIPCHUNK_bKGD if (pData->bHasglobalBKGD) /* global bKGD present ? */ { pImagedata->iBKGDred = pData->iGlobalBKGDred; pImagedata->iBKGDgreen = pData->iGlobalBKGDgreen; pImagedata->iBKGDblue = pData->iGlobalBKGDblue; }#endif *ppObject = pImagedata; /* return it */#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_CREATE_IMGDATAOBJECT, MNG_LC_END);#endif return MNG_NOERROR;}/* ************************************************************************** */mng_retcode mng_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 ? */ {#ifndef MNG_SKIPCHUNK_iCCP if (pImagedata->iProfilesize) /* stored an iCCP profile ? */ MNG_FREEX (pData, pImagedata->pProfile, pImagedata->iProfilesize);#endif 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 mng_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 */ pNewdata->bFrozen = MNG_FALSE; 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)); MNG_ERROR (pData, MNG_OUTOFMEMORY); } /* make a copy */ MNG_COPY (pNewdata->pImgdata, pSource->pImgdata, pNewdata->iImgdatasize); }#ifndef MNG_SKIPCHUNK_iCCP if (pNewdata->iProfilesize) /* iCCP profile present ? */ { MNG_ALLOCX (pData, pNewdata->pProfile, pNewdata->iProfilesize); if (!pNewdata->pProfile) /* enough memory ? */ { MNG_FREEX (pData, pNewdata, sizeof (mng_imagedata)); MNG_ERROR (pData, MNG_OUTOFMEMORY); } /* make a copy */ MNG_COPY (pNewdata->pProfile, pSource->pProfile, pNewdata->iProfilesize); }#endif *ppClone = pNewdata; /* return the clone */#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_CLONE_IMGDATAOBJECT, MNG_LC_END);#endif return MNG_NOERROR;}/* ************************************************************************** *//* * * *//* * Image-object routines * *//* * * *//* * these handle the "object" as defined by the MNG specification * *//* * * *//* ************************************************************************** */mng_retcode mng_create_imageobject (mng_datap pData, mng_uint16 iId, mng_bool bConcrete, mng_bool bVisible, 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_int32 iPosx, mng_int32 iPosy, mng_bool bClipped, mng_int32 iClipl, mng_int32 iClipr, mng_int32 iClipt, mng_int32 iClipb, mng_imagep *ppObject){ mng_imagep pImage; mng_imagep pPrev, pNext; mng_retcode iRetcode; mng_imagedatap pImgbuf;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_CREATE_IMGOBJECT, MNG_LC_START);#endif /* get a buffer */ MNG_ALLOC (pData, pImage, sizeof (mng_image)); /* now get a new "object buffer" */ iRetcode = mng_create_imagedataobject (pData, bConcrete, bViewable, iWidth, iHeight, iBitdepth, iColortype, iCompression, iFilter, iInterlace, &pImgbuf); if (iRetcode) /* on error bail out */ { MNG_FREEX (pData, pImage, sizeof (mng_image)); return iRetcode; } /* fill the appropriate fields */ pImage->sHeader.fCleanup = (mng_cleanupobject)mng_free_imageobject; pImage->sHeader.fProcess = MNG_NULL;#ifdef MNG_OPTIMIZE_OBJCLEANUP pImage->sHeader.iObjsize = sizeof (mng_image);#endif pImage->iId = iId; pImage->bFrozen = MNG_FALSE; pImage->bVisible = bVisible; pImage->bViewable = bViewable; pImage->bValid = (mng_bool)((pData->bDisplaying) && ((pData->bRunning) || (pData->bSearching)) && (!pData->bFreezing)); pImage->iPosx = iPosx; pImage->iPosy = iPosy; pImage->bClipped = bClipped; pImage->iClipl = iClipl; pImage->iClipr = iClipr; pImage->iClipt = iClipt; pImage->iClipb = iClipb;#ifndef MNG_SKIPCHUNK_MAGN pImage->iMAGN_MethodX = 0; pImage->iMAGN_MethodY = 0; pImage->iMAGN_MX = 0; pImage->iMAGN_MY = 0; pImage->iMAGN_ML = 0; pImage->iMAGN_MR = 0; pImage->iMAGN_MT = 0; pImage->iMAGN_MB = 0;#endif#ifndef MNG_SKIPCHUNK_PAST pImage->iPastx = 0; pImage->iPasty = 0;#endif pImage->pImgbuf = pImgbuf; if (iId) /* only if not object 0 ! */ { /* find previous lower object-id */ pPrev = (mng_imagep)pData->pLastimgobj; while ((pPrev) && (pPrev->iId > iId)) pPrev = (mng_imagep)pPrev->sHeader.pPrev; if (pPrev) /* found it ? */ { pImage->sHeader.pPrev = pPrev; /* than link it in place */ pImage->sHeader.pNext = pPrev->sHeader.pNext; pPrev->sHeader.pNext = pImage; } else /* if not found, it becomes the first ! */ { pImage->sHeader.pNext = pData->pFirstimgobj; pData->pFirstimgobj = pImage; } pNext = (mng_imagep)pImage->sHeader.pNext; if (pNext) pNext->sHeader.pPrev = pImage; else pData->pLastimgobj = pImage; } *ppObject = pImage; /* and return the new buffer */#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_CREATE_IMGOBJECT, MNG_LC_END);#endif return MNG_NOERROR; /* okido */}/* ************************************************************************** */mng_retcode mng_free_imageobject (mng_datap pData, mng_imagep pImage){ mng_retcode iRetcode; mng_imagep pPrev = pImage->sHeader.pPrev; mng_imagep pNext = pImage->sHeader.pNext; mng_imagedatap pImgbuf = pImage->pImgbuf;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_FREE_IMGOBJECT, MNG_LC_START);#endif if (pImage->iId) /* not for object 0 */ { if (pPrev) /* unlink from the list first ! */ pPrev->sHeader.pNext = pImage->sHeader.pNext; else pData->pFirstimgobj = pImage->sHeader.pNext; if (pNext) pNext->sHeader.pPrev = pImage->sHeader.pPrev; else pData->pLastimgobj = pImage->sHeader.pPrev; } /* unlink the image-data buffer */ iRetcode = mng_free_imagedataobject (pData, pImgbuf); /* drop it's own buffer */ MNG_FREEX (pData, pImage, sizeof (mng_image));#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_FREE_IMGOBJECT, MNG_LC_END);#endif return iRetcode;}/* ************************************************************************** */mng_imagep mng_find_imageobject (mng_datap pData, mng_uint16 iId){ mng_imagep pImage = (mng_imagep)pData->pFirstimgobj;#ifdef MNG_SUPPORT_TRACE MNG_TRACEX (pData, MNG_FN_FIND_IMGOBJECT, MNG_LC_START);#endif /* look up the right id */ while ((pImage) && (pImage->iId != iId)) pImage = (mng_imagep)pImage->sHeader.pNext;#ifdef MNG_SUPPORT_TRACE MNG_TRACEX (pData, MNG_FN_FIND_IMGOBJECT, MNG_LC_END);#endif return pImage;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -