📄 libmng_object_prc.c
字号:
/* ************************************************************************** */mng_retcode mng_clone_imageobject (mng_datap pData, mng_uint16 iId, mng_bool bPartial, mng_bool bVisible, mng_bool bAbstract, mng_bool bHasloca, mng_uint8 iLocationtype, mng_int32 iLocationx, mng_int32 iLocationy, mng_imagep pSource, mng_imagep *ppClone){ mng_ptr pTemp; mng_imagep pNew; mng_imagep pPrev, pNext; mng_retcode iRetcode; mng_imagedatap pImgbuf;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_CLONE_IMGOBJECT, MNG_LC_START);#endif#ifndef MNG_SKIPCHUNK_MAGN if ((pSource->iId) && /* needs magnification ? */ ((pSource->iMAGN_MethodX) || (pSource->iMAGN_MethodY))) { iRetcode = mng_magnify_imageobject (pData, pSource); if (iRetcode) /* on error bail out */ return iRetcode; }#endif /* get a buffer */#ifdef MNG_OPTIMIZE_OBJCLEANUP { mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_image), (mng_cleanupobject)mng_free_imageobject, MNG_NULL, &pTemp); if (iRetcode) return iRetcode; pNew = (mng_imagep)pTemp; }#else MNG_ALLOC (pData, pNew, sizeof (mng_image)); /* fill or copy the appropriate fields */ pNew->sHeader.fCleanup = (mng_cleanupobject)mng_free_imageobject; pNew->sHeader.fProcess = MNG_NULL;#endif pNew->iId = iId; pNew->bFrozen = MNG_FALSE; pNew->bVisible = bVisible; pNew->bViewable = pSource->bViewable; pNew->bValid = MNG_TRUE; if (bHasloca) /* location info available ? */ { if (iLocationtype == 0) /* absolute position ? */ { pNew->iPosx = iLocationx; pNew->iPosy = iLocationy; } else /* relative */ { pNew->iPosx = pSource->iPosx + iLocationx; pNew->iPosy = pSource->iPosy + iLocationy; } } else /* copy from source */ { pNew->iPosx = pSource->iPosx; pNew->iPosy = pSource->iPosy; } /* copy clipping info */ pNew->bClipped = pSource->bClipped; pNew->iClipl = pSource->iClipl; pNew->iClipr = pSource->iClipr; pNew->iClipt = pSource->iClipt; pNew->iClipb = pSource->iClipb;#ifndef MNG_SKIPCHUNK_MAGN /* copy magnification info *//* pNew->iMAGN_MethodX = pSource->iMAGN_MethodX; LET'S NOT !!!!!! pNew->iMAGN_MethodY = pSource->iMAGN_MethodY; pNew->iMAGN_MX = pSource->iMAGN_MX; pNew->iMAGN_MY = pSource->iMAGN_MY; pNew->iMAGN_ML = pSource->iMAGN_ML; pNew->iMAGN_MR = pSource->iMAGN_MR; pNew->iMAGN_MT = pSource->iMAGN_MT; pNew->iMAGN_MB = pSource->iMAGN_MB; */#endif#ifndef MNG_SKIPCHUNK_PAST pNew->iPastx = 0; /* initialize PAST info */ pNew->iPasty = 0;#endif if (iId) /* not for 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 ? */ { pNew->sHeader.pPrev = pPrev; /* than link it in place */ pNew->sHeader.pNext = pPrev->sHeader.pNext; pPrev->sHeader.pNext = pNew; } else /* if not found, it becomes the first ! */ { pNew->sHeader.pNext = pData->pFirstimgobj; pData->pFirstimgobj = pNew; } pNext = (mng_imagep)pNew->sHeader.pNext; if (pNext) pNext->sHeader.pPrev = pNew; else pData->pLastimgobj = pNew; } if (bPartial) /* partial clone ? */ { pNew->pImgbuf = pSource->pImgbuf; /* use the same object buffer */ pNew->pImgbuf->iRefcount++; /* and increase the reference count */ } else /* create a full clone ! */ { mng_bool bConcrete = MNG_FALSE; /* it's abstract by default (?) */ if (!bAbstract) /* determine concreteness from source ? */ bConcrete = pSource->pImgbuf->bConcrete; /* create a full clone ! */ iRetcode = mng_clone_imagedataobject (pData, bConcrete, pSource->pImgbuf, &pImgbuf); if (iRetcode) /* on error bail out */ { MNG_FREEX (pData, pNew, sizeof (mng_image)); return iRetcode; } pNew->pImgbuf = pImgbuf; /* and remember it */ } *ppClone = pNew; /* return it */#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_CLONE_IMGOBJECT, MNG_LC_END);#endif return MNG_NOERROR;}/* ************************************************************************** */mng_retcode mng_renum_imageobject (mng_datap pData, mng_imagep pSource, mng_uint16 iId, mng_bool bVisible, mng_bool bAbstract, mng_bool bHasloca, mng_uint8 iLocationtype, mng_int32 iLocationx, mng_int32 iLocationy){ mng_imagep pPrev, pNext;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_RENUM_IMGOBJECT, MNG_LC_START);#endif pSource->bVisible = bVisible; /* store the new visibility */ if (bHasloca) /* location info available ? */ { if (iLocationtype == 0) /* absolute position ? */ { pSource->iPosx = iLocationx; pSource->iPosy = iLocationy; } else /* relative */ { pSource->iPosx = pSource->iPosx + iLocationx; pSource->iPosy = pSource->iPosy + iLocationy; } } if (iId) /* not for object 0 */ { /* find previous lower object-id */ pPrev = (mng_imagep)pData->pLastimgobj; while ((pPrev) && (pPrev->iId > iId)) pPrev = (mng_imagep)pPrev->sHeader.pPrev; /* different from current ? */ if (pPrev != (mng_imagep)pSource->sHeader.pPrev) { if (pSource->sHeader.pPrev) /* unlink from current position !! */ ((mng_imagep)pSource->sHeader.pPrev)->sHeader.pNext = pSource->sHeader.pNext; else pData->pFirstimgobj = pSource->sHeader.pNext; if (pSource->sHeader.pNext) ((mng_imagep)pSource->sHeader.pNext)->sHeader.pPrev = pSource->sHeader.pPrev; else pData->pLastimgobj = pSource->sHeader.pPrev; if (pPrev) /* found the previous ? */ { /* than link it in place */ pSource->sHeader.pPrev = pPrev; pSource->sHeader.pNext = pPrev->sHeader.pNext; pPrev->sHeader.pNext = pSource; } else /* if not found, it becomes the first ! */ { pSource->sHeader.pNext = pData->pFirstimgobj; pData->pFirstimgobj = pSource; } pNext = (mng_imagep)pSource->sHeader.pNext; if (pNext) pNext->sHeader.pPrev = pSource; else pData->pLastimgobj = pSource; } } pSource->iId = iId; /* now set the new id! */ if (bAbstract) /* force it to abstract ? */ pSource->pImgbuf->bConcrete = MNG_FALSE;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_RENUM_IMGOBJECT, MNG_LC_END);#endif return MNG_NOERROR;}/* ************************************************************************** */mng_retcode mng_reset_object_details (mng_datap pData, mng_imagep pImage, mng_uint32 iWidth, mng_uint32 iHeight, mng_uint8 iBitdepth, mng_uint8 iColortype, mng_uint8 iCompression, mng_uint8 iFilter, mng_uint8 iInterlace, mng_bool bResetall){ mng_imagedatap pBuf = pImage->pImgbuf; mng_uint32 iSamplesize = 0; mng_uint32 iRowsize; mng_uint32 iImgdatasize;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_RESET_OBJECTDETAILS, MNG_LC_START);#endif pBuf->iWidth = iWidth; /* set buffer characteristics */ pBuf->iHeight = iHeight; pBuf->iBitdepth = iBitdepth; pBuf->iColortype = iColortype; pBuf->iCompression = iCompression; pBuf->iFilter = iFilter; pBuf->iInterlace = iInterlace; pBuf->bCorrected = MNG_FALSE; pBuf->iAlphabitdepth = 0; /* 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 */#ifndef MNG_NO_16BIT_SUPPORT if (iBitdepth > 8) iSamplesize = 2; else#endif iSamplesize = 1; break; } case 2 : ; /* rgb */ case 10 : { /* JPEG rgb */#ifndef MNG_NO_16BIT_SUPPORT if (iBitdepth > 8) iSamplesize = 6; else#endif iSamplesize = 3; break; } case 3 : { /* indexed */ iSamplesize = 1; break; } case 4 : ; /* gray+alpha */ case 12 : { /* JPEG gray+alpha */#ifndef MNG_NO_16BIT_SUPPORT if (iBitdepth > 8) iSamplesize = 4; else#endif iSamplesize = 2; break; } case 6 : ; /* rgb+alpha */ case 14 : { /* JPEG rgb+alpha */#ifndef MNG_NO_16BIT_SUPPORT if (iBitdepth > 8) iSamplesize = 8; else#endif iSamplesize = 4; break; } } iRowsize = iSamplesize * iWidth; iImgdatasize = iRowsize * iHeight; /* buffer size changed ? */ if (iImgdatasize != pBuf->iImgdatasize) { /* drop the old one */ MNG_FREE (pData, pBuf->pImgdata, pBuf->iImgdatasize); if (iImgdatasize) /* allocate new sample-buffer ? */ MNG_ALLOC (pData, pBuf->pImgdata, iImgdatasize); } else { if (iImgdatasize) /* clear old buffer */ { mng_uint8p pTemp = pBuf->pImgdata; mng_uint32 iX; for (iX = 0; iX < (iImgdatasize & (mng_uint32)(~3L)); iX += 4) { *((mng_uint32p)pTemp) = 0x00000000l; pTemp += 4; } while (pTemp < (pBuf->pImgdata + iImgdatasize)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -