📄 libmng_chunk_xs.c
字号:
/* ************************************************************************** *//* * For conditions of distribution and use, * *//* * see copyright notice in libmng.h * *//* ************************************************************************** *//* * * *//* * project : libmng * *//* * file : libmng_chunk_xs.c copyright (c) 2000 G. Juyn * *//* * version : 1.0.0 * *//* * * *//* * purpose : chunk access functions (implementation) * *//* * * *//* * author : G.Juyn * *//* * web : http://www.3-t.com * *//* * email : mailto:info@3-t.com * *//* * * *//* * comment : implementation of the chunk access functions * *//* * * *//* * changes : 0.5.1 - 05/06/2000 - G.Juyn * *//* * - changed and filled iterate-chunk function * *//* * 0.5.1 - 05/08/2000 - G.Juyn * *//* * - fixed calling convention * *//* * - added getchunk functions * *//* * - added putchunk functions * *//* * - changed strict-ANSI stuff * *//* * 0.5.1 - 05/11/2000 - G.Juyn * *//* * - added empty-chunk put-routines * *//* * 0.5.1 - 05/12/2000 - G.Juyn * *//* * - changed trace to macro for callback error-reporting * *//* * 0.5.1 - 05/15/2000 - G.Juyn * *//* * - added getimgdata & putimgdata functions * *//* * * *//* * 0.5.2 - 05/19/2000 - G.Juyn * *//* * - B004 - fixed problem with MNG_SUPPORT_WRITE not defined * *//* * also for MNG_SUPPORT_WRITE without MNG_INCLUDE_JNG * *//* * - Cleaned up some code regarding mixed support * *//* * * *//* * 0.9.1 - 07/19/2000 - G.Juyn * *//* * - fixed creation-code * *//* * * *//* * 0.9.2 - 08/05/2000 - G.Juyn * *//* * - changed file-prefixes * *//* * - added function to set simplicity field * *//* * - fixed putchunk_unknown() function * *//* * * *//* * 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 - 10/20/2000 - G.Juyn * *//* * - fixed putchunk_plte() to set bEmpty parameter * *//* * * *//* * 0.9.5 - 1/25/2001 - G.Juyn * *//* * - fixed some small compiler warnings (thanks Nikki) * *//* * * *//* ************************************************************************** */#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_chunks.h"#include "libmng_chunk_prc.h"#include "libmng_chunk_io.h"#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI)#pragma option -A /* force ANSI-C */#endif/* ************************************************************************** */#ifdef MNG_ACCESS_CHUNKS/* ************************************************************************** */mng_retcode MNG_DECL mng_iterate_chunks (mng_handle hHandle, mng_uint32 iChunkseq, mng_iteratechunk fProc){ mng_uint32 iSeq; mng_chunkid iChunkname; mng_datap pData; mng_chunkp pChunk; mng_bool bCont;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (((mng_datap)hHandle), MNG_FN_ITERATE_CHUNKS, MNG_LC_START)#endif MNG_VALIDHANDLE (hHandle) /* check validity handle */ pData = ((mng_datap)hHandle); /* and make it addressable */ iSeq = 0; bCont = MNG_TRUE; pChunk = pData->pFirstchunk; /* get the first chunk */ /* as long as there are some more */ while ((pChunk) && (bCont)) /* and the app didn't signal a stop */ { if (iSeq >= iChunkseq) /* reached the first target ? */ { /* then call this and next ones back in... */ iChunkname = ((mng_chunk_headerp)pChunk)->iChunkname; bCont = fProc (hHandle, (mng_handle)pChunk, iChunkname, iSeq); } iSeq++; /* next one */ pChunk = ((mng_chunk_headerp)pChunk)->pNext; }#ifdef MNG_SUPPORT_TRACE MNG_TRACE (((mng_datap)hHandle), MNG_FN_ITERATE_CHUNKS, MNG_LC_END)#endif return MNG_NOERROR;}/* ************************************************************************** */mng_retcode MNG_DECL mng_getchunk_ihdr (mng_handle hHandle, mng_handle hChunk, mng_uint32 *iWidth, mng_uint32 *iHeight, mng_uint8 *iBitdepth, mng_uint8 *iColortype, mng_uint8 *iCompression, mng_uint8 *iFilter, mng_uint8 *iInterlace){ mng_datap pData; mng_ihdrp pChunk;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_IHDR, MNG_LC_START)#endif MNG_VALIDHANDLE (hHandle) /* check validity handle */ pData = (mng_datap)hHandle; /* and make it addressable */ pChunk = (mng_ihdrp)hChunk; /* address the chunk */ if (pChunk->sHeader.iChunkname != MNG_UINT_IHDR) MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ *iWidth = pChunk->iWidth; /* fill the fields */ *iHeight = pChunk->iHeight; *iBitdepth = pChunk->iBitdepth; *iColortype = pChunk->iColortype; *iCompression = pChunk->iCompression; *iFilter = pChunk->iFilter; *iInterlace = pChunk->iInterlace;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_IHDR, MNG_LC_END)#endif return MNG_NOERROR;}/* ************************************************************************** */mng_retcode MNG_DECL mng_getchunk_plte (mng_handle hHandle, mng_handle hChunk, mng_uint32 *iCount, mng_palette8 *aPalette){ mng_datap pData; mng_pltep pChunk;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PLTE, MNG_LC_START)#endif MNG_VALIDHANDLE (hHandle) /* check validity handle */ pData = (mng_datap)hHandle; /* and make it addressable */ pChunk = (mng_pltep)hChunk; /* address the chunk */ if (pChunk->sHeader.iChunkname != MNG_UINT_PLTE) MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ *iCount = pChunk->iEntrycount; /* fill the fields */ MNG_COPY (*aPalette, pChunk->aEntries, sizeof (mng_palette8))#ifdef MNG_SUPPORT_TRACE MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PLTE, MNG_LC_END)#endif return MNG_NOERROR;}/* ************************************************************************** */mng_retcode MNG_DECL mng_getchunk_idat (mng_handle hHandle, mng_handle hChunk, mng_uint32 *iRawlen, mng_ptr *pRawdata){ mng_datap pData; mng_idatp pChunk;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_IDAT, MNG_LC_START)#endif MNG_VALIDHANDLE (hHandle) /* check validity handle */ pData = (mng_datap)hHandle; /* and make it addressable */ pChunk = (mng_idatp)hChunk; /* address the chunk */ if (pChunk->sHeader.iChunkname != MNG_UINT_IDAT) MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ *iRawlen = pChunk->iDatasize; /* fill the fields */ *pRawdata = pChunk->pData;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_IDAT, MNG_LC_END)#endif return MNG_NOERROR;}/* ************************************************************************** */mng_retcode MNG_DECL mng_getchunk_trns (mng_handle hHandle, mng_handle hChunk, mng_bool *bEmpty, mng_bool *bGlobal, mng_uint8 *iType, mng_uint32 *iCount, mng_uint8arr *aAlphas, mng_uint16 *iGray, mng_uint16 *iRed, mng_uint16 *iGreen, mng_uint16 *iBlue, mng_uint32 *iRawlen, mng_uint8arr *aRawdata){ mng_datap pData; mng_trnsp pChunk;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_TRNS, MNG_LC_START)#endif MNG_VALIDHANDLE (hHandle) /* check validity handle */ pData = (mng_datap)hHandle; /* and make it addressable */ pChunk = (mng_trnsp)hChunk; /* address the chunk */ if (pChunk->sHeader.iChunkname != MNG_UINT_tRNS) MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ *bEmpty = pChunk->bEmpty; /* fill the fields */ *bGlobal = pChunk->bGlobal; *iType = pChunk->iType; *iCount = pChunk->iCount; *iGray = pChunk->iGray; *iRed = pChunk->iRed; *iGreen = pChunk->iGreen; *iBlue = pChunk->iBlue; *iRawlen = pChunk->iRawlen; MNG_COPY (*aAlphas, pChunk->aEntries, sizeof (mng_uint8arr)) MNG_COPY (*aRawdata, pChunk->aRawdata, sizeof (mng_uint8arr))#ifdef MNG_SUPPORT_TRACE MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_TRNS, MNG_LC_END)#endif return MNG_NOERROR;}/* ************************************************************************** */mng_retcode MNG_DECL mng_getchunk_gama (mng_handle hHandle, mng_handle hChunk, mng_bool *bEmpty, mng_uint32 *iGamma){ mng_datap pData; mng_gamap pChunk;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_GAMA, MNG_LC_START)#endif MNG_VALIDHANDLE (hHandle) /* check validity handle */ pData = (mng_datap)hHandle; /* and make it addressable */ pChunk = (mng_gamap)hChunk; /* address the chunk */ if (pChunk->sHeader.iChunkname != MNG_UINT_gAMA) MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ *bEmpty = pChunk->bEmpty; /* fill the fields */ *iGamma = pChunk->iGamma;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_GAMA, MNG_LC_END)#endif return MNG_NOERROR;}/* ************************************************************************** */mng_retcode MNG_DECL mng_getchunk_chrm (mng_handle hHandle, mng_handle hChunk, mng_bool *bEmpty, mng_uint32 *iWhitepointx, mng_uint32 *iWhitepointy, mng_uint32 *iRedx, mng_uint32 *iRedy, mng_uint32 *iGreenx, mng_uint32 *iGreeny, mng_uint32 *iBluex, mng_uint32 *iBluey){ mng_datap pData; mng_chrmp pChunk;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_CHRM, MNG_LC_START)#endif MNG_VALIDHANDLE (hHandle) /* check validity handle */ pData = (mng_datap)hHandle; /* and make it addressable */ pChunk = (mng_chrmp)hChunk; /* address the chunk */ if (pChunk->sHeader.iChunkname != MNG_UINT_cHRM) MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ *bEmpty = pChunk->bEmpty; /* fill the fields */ *iWhitepointx = pChunk->iWhitepointx; *iWhitepointy = pChunk->iWhitepointy; *iRedx = pChunk->iRedx; *iRedy = pChunk->iRedy; *iGreenx = pChunk->iGreenx; *iGreeny = pChunk->iGreeny; *iBluex = pChunk->iBluex; *iBluey = pChunk->iBluey;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_CHRM, MNG_LC_END)#endif return MNG_NOERROR;}/* ************************************************************************** */mng_retcode MNG_DECL mng_getchunk_srgb (mng_handle hHandle, mng_handle hChunk, mng_bool *bEmpty, mng_uint8 *iRenderingintent){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -