📄 libmng_chunk_descr.c
字号:
#ifndef MNG_NO_DELTA_PNGMNG_LOCAL mng_chunk_descriptor mng_chunk_descr_dhdr = {mng_it_mng, mng_create_none, 0, 0, MNG_NULL, MNG_NULL, mng_special_dhdr, mng_fields_dhdr, (sizeof(mng_fields_dhdr) / sizeof(mng_field_descriptor)), MNG_NULL, MNG_DESCR_MHDR, MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR};#endif#ifndef MNG_NO_DELTA_PNGMNG_LOCAL mng_chunk_descriptor mng_chunk_descr_prom = {mng_it_mng, mng_create_none, 0, 0, MNG_NULL, MNG_NULL, mng_special_prom, mng_fields_prom, (sizeof(mng_fields_prom) / sizeof(mng_field_descriptor)), MNG_NULL, MNG_DESCR_MHDR | MNG_DESCR_DHDR, MNG_NULL};#endif#ifndef MNG_NO_DELTA_PNGMNG_LOCAL mng_chunk_descriptor mng_chunk_descr_ipng = {mng_it_mng, mng_create_none, 0, 0, MNG_NULL, MNG_NULL, mng_special_ipng, MNG_NULL, 0, MNG_DESCR_EMPTY | MNG_DESCR_EMPTYEMBED, MNG_DESCR_MHDR | MNG_DESCR_DHDR, MNG_NULL};#endif#ifndef MNG_NO_DELTA_PNGMNG_LOCAL mng_chunk_descriptor mng_chunk_descr_pplt = {mng_it_mng, mng_create_none, 0, 0, MNG_NULL, MNG_NULL, mng_special_pplt, mng_fields_pplt, (sizeof(mng_fields_pplt) / sizeof(mng_field_descriptor)), MNG_NULL, MNG_DESCR_MHDR | MNG_DESCR_DHDR, MNG_NULL};#endif#ifndef MNG_NO_DELTA_PNG#ifdef MNG_INCLUDE_JNGMNG_LOCAL mng_chunk_descriptor mng_chunk_descr_ijng = {mng_it_mng, mng_create_none, 0, 0, MNG_NULL, MNG_NULL, mng_special_ijng, MNG_NULL, 0, MNG_DESCR_EMPTY | MNG_DESCR_EMPTYEMBED, MNG_DESCR_MHDR | MNG_DESCR_DHDR, MNG_NULL};#endif#endif#ifndef MNG_NO_DELTA_PNGMNG_LOCAL mng_chunk_descriptor mng_chunk_descr_drop = {mng_it_mng, mng_create_none, 0, 0, MNG_NULL, MNG_NULL, mng_special_drop, mng_fields_drop, (sizeof(mng_fields_drop) / sizeof(mng_field_descriptor)), MNG_NULL, MNG_DESCR_MHDR | MNG_DESCR_DHDR, MNG_NULL};#endif#ifndef MNG_NO_DELTA_PNG#ifndef MNG_SKIPCHUNK_DBYKMNG_LOCAL mng_chunk_descriptor mng_chunk_descr_dbyk = {mng_it_mng, mng_create_none, 0, 0, MNG_NULL, MNG_NULL, mng_special_dbyk, mng_fields_dbyk, (sizeof(mng_fields_dbyk) / sizeof(mng_field_descriptor)), MNG_DESCR_EMPTY | MNG_DESCR_EMPTYEMBED, MNG_DESCR_MHDR | MNG_DESCR_DHDR, MNG_NULL};#endif#endif#ifndef MNG_NO_DELTA_PNG#ifndef MNG_SKIPCHUNK_ORDRMNG_LOCAL mng_chunk_descriptor mng_chunk_descr_ordr = {mng_it_mng, mng_create_none, 0, 0, MNG_NULL, MNG_NULL, mng_special_ordr, mng_fields_ordr, (sizeof(mng_fields_ordr) / sizeof(mng_field_descriptor)), MNG_NULL, MNG_DESCR_MHDR | MNG_DESCR_DHDR, MNG_NULL};#endif#endif#ifndef MNG_SKIPCHUNK_MAGNMNG_LOCAL mng_chunk_descriptor mng_chunk_descr_magn = {mng_it_mng, mng_create_none, 0, 0, MNG_NULL, MNG_NULL, mng_special_magn, mng_fields_magn, (sizeof(mng_fields_magn) / sizeof(mng_field_descriptor)), MNG_NULL, MNG_DESCR_MHDR, MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR};#endif#ifndef MNG_SKIPCHUNK_evNTMNG_LOCAL mng_chunk_descriptor mng_chunk_descr_evnt = {mng_it_mng, mng_create_none, 0, 0, MNG_NULL, MNG_NULL, mng_special_evnt, mng_fields_evnt, (sizeof(mng_fields_evnt) / sizeof(mng_field_descriptor)), MNG_NULL, MNG_DESCR_MHDR, MNG_DESCR_NOSAVE};#endif/* ************************************************************************** *//* ************************************************************************** *//* the good ol' unknown babe */MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_unknown = {mng_it_png, mng_create_none, 0, 0, MNG_NULL, MNG_NULL, mng_special_unknown, mng_fields_unknown, (sizeof(mng_fields_unknown) / sizeof(mng_field_descriptor)), MNG_DESCR_EMPTY | MNG_DESCR_EMPTYEMBED, MNG_NULL, MNG_NULL};/* ************************************************************************** *//* ************************************************************************** */MNG_LOCAL mng_chunk_header mng_chunk_unknown = {MNG_UINT_HUH, mng_init_general, mng_free_unknown, mng_read_general, mng_write_unknown, mng_assign_unknown, 0, 0, sizeof(mng_unknown_chunk), &mng_chunk_descr_unknown};/* ************************************************************************** */ /* the table-idea & binary search code was adapted from libpng 1.1.0 (pngread.c) */ /* NOTE1: the table must remain sorted by chunkname, otherwise the binary search will break !!! (ps. watch upper-/lower-case chunknames !!) */ /* NOTE2: the layout must remain equal to the header part of all the chunk-structures (yes, that means even the pNext and pPrev fields; it's wasting a bit of space, but hey, the code is a lot easier) */MNG_LOCAL mng_chunk_header mng_chunk_table [] = {#ifndef MNG_SKIPCHUNK_BACK {MNG_UINT_BACK, mng_init_general, mng_free_general, mng_read_general, mng_write_back, mng_assign_general, 0, 0, sizeof(mng_back), &mng_chunk_descr_back},#endif#ifndef MNG_SKIPCHUNK_BASI {MNG_UINT_BASI, mng_init_general, mng_free_general, mng_read_general, mng_write_basi, mng_assign_general, 0, 0, sizeof(mng_basi), &mng_chunk_descr_basi},#endif#ifndef MNG_SKIPCHUNK_CLIP {MNG_UINT_CLIP, mng_init_general, mng_free_general, mng_read_general, mng_write_clip, mng_assign_general, 0, 0, sizeof(mng_clip), &mng_chunk_descr_clip},#endif#ifndef MNG_SKIPCHUNK_CLON {MNG_UINT_CLON, mng_init_general, mng_free_general, mng_read_general, mng_write_clon, mng_assign_general, 0, 0, sizeof(mng_clon), &mng_chunk_descr_clon},#endif#ifndef MNG_NO_DELTA_PNG#ifndef MNG_SKIPCHUNK_DBYK {MNG_UINT_DBYK, mng_init_general, mng_free_dbyk, mng_read_general, mng_write_dbyk, mng_assign_dbyk, 0, 0, sizeof(mng_dbyk), &mng_chunk_descr_dbyk},#endif#endif#ifndef MNG_SKIPCHUNK_DEFI {MNG_UINT_DEFI, mng_init_general, mng_free_general, mng_read_general, mng_write_defi, mng_assign_general, 0, 0, sizeof(mng_defi), &mng_chunk_descr_defi},#endif#ifndef MNG_NO_DELTA_PNG {MNG_UINT_DHDR, mng_init_general, mng_free_general, mng_read_general, mng_write_dhdr, mng_assign_general, 0, 0, sizeof(mng_dhdr), &mng_chunk_descr_dhdr},#endif#ifndef MNG_SKIPCHUNK_DISC {MNG_UINT_DISC, mng_init_general, mng_free_disc, mng_read_general, mng_write_disc, mng_assign_disc, 0, 0, sizeof(mng_disc), &mng_chunk_descr_disc},#endif#ifndef MNG_NO_DELTA_PNG#ifndef MNG_SKIPCHUNK_DROP {MNG_UINT_DROP, mng_init_general, mng_free_drop, mng_read_general, mng_write_drop, mng_assign_drop, 0, 0, sizeof(mng_drop), &mng_chunk_descr_drop},#endif#endif#ifndef MNG_SKIPCHUNK_LOOP {MNG_UINT_ENDL, mng_init_general, mng_free_general, mng_read_general, mng_write_endl, mng_assign_general, 0, 0, sizeof(mng_endl), &mng_chunk_descr_endl},#endif#ifndef MNG_SKIPCHUNK_FRAM {MNG_UINT_FRAM, mng_init_general, mng_free_fram, mng_read_general, mng_write_fram, mng_assign_fram, 0, 0, sizeof(mng_fram), &mng_chunk_descr_fram},#endif {MNG_UINT_IDAT, mng_init_general, mng_free_idat, mng_read_general, mng_write_idat, mng_assign_idat, 0, 0, sizeof(mng_idat), &mng_chunk_descr_idat}, /* 12-th element! */ {MNG_UINT_IEND, mng_init_general, mng_free_general, mng_read_general, mng_write_iend, mng_assign_general, 0, 0, sizeof(mng_iend), &mng_chunk_descr_iend}, {MNG_UINT_IHDR, mng_init_general, mng_free_general, mng_read_general, mng_write_ihdr, mng_assign_general, 0, 0, sizeof(mng_ihdr), &mng_chunk_descr_ihdr},#ifndef MNG_NO_DELTA_PNG#ifdef MNG_INCLUDE_JNG {MNG_UINT_IJNG, mng_init_general, mng_free_general, mng_read_general, mng_write_ijng, mng_assign_general, 0, 0, sizeof(mng_ijng), &mng_chunk_descr_ijng},#endif {MNG_UINT_IPNG, mng_init_general, mng_free_general, mng_read_general, mng_write_ipng, mng_assign_general, 0, 0, sizeof(mng_ipng), &mng_chunk_descr_ipng},#endif#ifdef MNG_INCLUDE_JNG {MNG_UINT_JDAA, mng_init_general, mng_free_jdaa, mng_read_general, mng_write_jdaa, mng_assign_jdaa, 0, 0, sizeof(mng_jdaa), &mng_chunk_descr_jdaa}, {MNG_UINT_JDAT, mng_init_general, mng_free_jdat, mng_read_general, mng_write_jdat, mng_assign_jdat, 0, 0, sizeof(mng_jdat), &mng_chunk_descr_jdat}, {MNG_UINT_JHDR, mng_init_general, mng_free_general, mng_read_general, mng_write_jhdr, mng_assign_general, 0, 0, sizeof(mng_jhdr), &mng_chunk_descr_jhdr}, {MNG_UINT_JSEP, mng_init_general, mng_free_general, mng_read_general, mng_write_jsep, mng_assign_general, 0, 0, sizeof(mng_jsep), &mng_chunk_descr_jsep}, {MNG_UINT_JdAA, mng_init_general, mng_free_jdaa, mng_read_general, mng_write_jdaa, mng_assign_jdaa, 0, 0, sizeof(mng_jdaa), &mng_chunk_descr_jdaa},#endif#ifndef MNG_SKIPCHUNK_LOOP {MNG_UINT_LOOP, mng_init_general, mng_free_loop, mng_read_general, mng_write_loop, mng_assign_loop, 0, 0, sizeof(mng_loop), &mng_chunk_descr_loop},#endif#ifndef MNG_SKIPCHUNK_MAGN {MNG_UINT_MAGN, mng_init_general, mng_free_general, mng_read_general, mng_write_magn, mng_assign_general, 0, 0, sizeof(mng_magn), &mng_chunk_descr_magn},#endif {MNG_UINT_MEND, mng_init_general, mng_free_general, mng_read_general, mng_write_mend, mng_assign_general, 0, 0, sizeof(mng_mend), &mng_chunk_descr_mend}, {MNG_UINT_MHDR, mng_init_general, mng_free_general, mng_read_general, mng_write_mhdr, mng_assign_general, 0, 0, sizeof(mng_mhdr), &mng_chunk_descr_mhdr},#ifndef MNG_SKIPCHUNK_MOVE {MNG_UINT_MOVE, mng_init_general, mng_free_general, mng_read_general, mng_write_move, mng_assign_general, 0, 0, sizeof(mng_move), &mng_chunk_descr_move},#endif#ifndef MNG_NO_DELTA_PNG#ifndef MNG_SKIPCHUNK_ORDR {MNG_UINT_ORDR, mng_init_general, mng_free_ordr, mng_read_general, mng_write_ordr, mng_assign_ordr, 0, 0, sizeof(mng_ordr), &mng_chunk_descr_ordr},#endif#endif#ifndef MNG_SKIPCHUNK_PAST {MNG_UINT_PAST, mng_init_general, mng_free_past, mng_read_general, mng_write_past, mng_assign_past, 0, 0, sizeof(mng_past), &mng_chunk_descr_past},#endif {MNG_UINT_PLTE, mng_init_general, mng_free_general, mng_read_general, mng_write_plte, mng_assign_general, 0, 0, sizeof(mng_plte), &mng_chunk_descr_plte},#ifndef MNG_NO_DELTA_PNG {MNG_UINT_PPLT, mng_init_general, mng_free_general, mng_read_general, mng_write_pplt, mng_assign_general, 0, 0, sizeof(mng_pplt), &mng_chunk_descr_pplt}, {MNG_UINT_PROM, mng_init_general, mng_free_general, mng_read_general, mng_write_prom, mng_assign_general, 0, 0, sizeof(mng_prom), &mng_chunk_descr_prom},#endif #ifndef MNG_SKIPCHUNK_SAVE {MNG_UINT_SAVE, mng_init_general, mng_free_save, mng_read_general, mng_write_save, mng_assign_save, 0, 0, sizeof(mng_save), &mng_chunk_descr_save},#endif#ifndef MNG_SKIPCHUNK_SEEK {MNG_UINT_SEEK, mng_init_general, mng_free_seek, mng_read_general, mng_write_seek, mng_assign_seek, 0, 0, sizeof(mng_seek), &mng_chunk_descr_seek},#endif#ifndef MNG_SKIPCHUNK_SHOW {MNG_UINT_SHOW, mng_init_general, mng_free_general, mng_read_general, mng_write_show, mng_assign_general, 0, 0, sizeof(mng_show), &mng_chunk_descr_show},#endif#ifndef MNG_SKIPCHUNK_TERM {MNG_UINT_TERM, mng_init_general, mng_free_general, mng_read_general, mng_write_term, mng_assign_general, 0, 0, sizeof(mng_term), &mng_chunk_descr_term},#endif#ifndef MNG_SKIPCHUNK_bKGD {MNG_UINT_bKGD, mng_init_general, mng_free_general, mng_read_general, mng_write_bkgd, mng_assign_general, 0, 0, sizeof(mng_bkgd), &mng_chunk_descr_bkgd},#endif#ifndef MNG_SKIPCHUNK_cHRM {MNG_UINT_cHRM, mng_init_general, mng_free_general, mng_read_general, mng_write_chrm, mng_assign_general, 0, 0, sizeof(mng_chrm), &mng_chunk_descr_chrm},#endif#ifndef MNG_SKIPCHUNK_eXPI {MNG_UINT_eXPI, mng_init_general, mng_free_expi, mng_read_general, mng_write_expi, mng_assign_expi, 0, 0, sizeof(mng_expi), &mng_chunk_descr_expi},#endif#ifndef MNG_SKIPCHUNK_evNT {MNG_UINT_evNT, mng_init_general, mng_free_evnt, mng_read_general, mng_write_evnt, mng_assign_evnt, 0, 0, sizeof(mng_evnt), &mng_chunk_descr_evnt},#endif#ifndef MNG_SKIPCHUNK_fPRI {MNG_UINT_fPRI, mng_init_general, mng_free_general, mng_read_general, mng_write_fpri, mng_assign_general, 0, 0, sizeof(mng_fpri), &mng_chunk_descr_fpri},#endif#ifndef MNG_SKIPCHUNK_gAMA {MNG_UINT_gAMA, mng_init_general, mng_free_general, mng_read_general, mng_write_gama, mng_assign_general, 0, 0, sizeof(mng_gama), &mng_chunk_descr_gama},#endif#ifndef MNG_SKIPCHUNK_hIST {MNG_UINT_hIST, mng_init_general, mng_free_general, mng_read_general, mng_write_hist, mng_assign_general, 0, 0, sizeof(mng_hist), &mng_chunk_descr_hist},#endif#ifndef MNG_SKIPCHUNK_iCCP {MNG_UINT_iCCP, mng_init_general, mng_free_iccp, mng_read_general, mng_write_iccp, mng_assign_iccp, 0, 0, sizeof(mng_iccp), &mng_chunk_descr_iccp},#endif#ifndef MNG_SKIPCHUNK_iTXt {MNG_UINT_iTXt, mng_init_general, mng_free_itxt, mng_read_general, mng_write_itxt, mng_assign_itxt, 0, 0, sizeof(mng_itxt), &mng_chunk_descr_itxt},#endif#ifndef MNG_SKIPCHUNK_nEED {MNG_UINT_nEED, mng_init_general, mng_free_need, mng_read_general, mng_write_need, mng_assign_need, 0, 0, sizeof(mng_need), &mng_chunk_descr_need},#endif/* TODO: {MNG_UINT_oFFs, 0, 0, 0, 0, 0, 0}, *//* TODO: {MNG_UINT_pCAL, 0, 0, 0, 0, 0, 0}, */#ifndef MNG_SKIPCHUNK_pHYg {MNG_UINT_pHYg, mng_init_general, mng_free_general, mng_read_general, mng_write_phyg, mng_assign_general, 0, 0, sizeof(mng_phyg), &mng_chunk_descr_phyg},#endif#ifndef MNG_SKIPCHUNK_pHYs {MNG_UINT_pHYs, mng_init_general, mng_free_general, mng_read_general, mng_write_phys, mng_assign_general, 0, 0, sizeof(mng_phys), &mng_chunk_descr_phys},#endif#ifndef MNG_SKIPCHUNK_sBIT {MNG_UINT_sBIT, mng_init_general, mng_free_general, mng_read_general, mng_write_sbit, mng_assign_general, 0, 0, sizeof(mng_sbit), &mng_chunk_descr_sbit},#endif/* TODO: {MNG_UINT_sCAL, 0, 0, 0, 0, 0, 0}, */#ifndef MNG_SKIPCHUNK_sPLT {MNG_UINT_sPLT, mng_init_general, mng_free_splt, mng_read_general, mng_write_splt, mng_assign_splt, 0, 0, sizeof(mng_splt), &mng_chunk_descr_splt},#endif {MNG_UINT_sRGB, mng_init_general, mng_free_general, mng_read_general, mng_write_srgb, mng_assign_general, 0, 0, sizeof(mng_srgb), &mng_chunk_descr_srgb},#ifndef MNG_SKIPCHUNK_tEXt {MNG_UINT_tEXt, mng_init_general, mng_free_text, mng_read_general, mng_write_text, mng_assign_text, 0, 0, sizeof(mng_text), &mng_chunk_descr_text},#endif#ifndef MNG_SKIPCHUNK_tIME {MNG_UINT_tIME, mng_init_general, mng_free_general, mng_read_general, mng_write_time, mng_assign_general, 0, 0, sizeof(mng_time), &mng_chunk_descr_time},#endif {MNG_UINT_tRNS, mng_init_general, mng_free_general, mng_read_general, mng_write_trns, mng_assign_general, 0, 0, sizeof(mng_trns), &mng_chunk_descr_trns},#ifndef MNG_SKIPCHUNK_zTXt {MNG_UINT_zTXt, mng_init_general, mng_free_ztxt, mng_read_general, mng_write_ztxt, mng_assign_ztxt, 0, 0, sizeof(mng_ztxt), &mng_chunk_descr_ztxt},#endif };/* ************************************************************************** *//* ************************************************************************** */void mng_get_chunkheader (mng_chunkid iChunkname, mng_chunk_headerp pResult){ /* binary search variables */ mng_int32 iTop, iLower, iUpper, iMiddle; mng_chunk_headerp pEntry; /* pointer to found entry */ /* determine max index of table */ iTop = (sizeof (mng_chunk_table) / sizeof (mng_chunk_table [0])) - 1; /* binary search; with 54 chunks, worst-case is 7 comparisons */ iLower = 0;#ifndef MNG_NO_DELTA_PNG iMiddle = 11; /* start with the IDAT entry */#else iMiddle = 8;#endif iUpper = iTop; pEntry = 0; /* no goods yet! */ do /* the binary search itself */ { if (mng_chunk_table [iMiddle].iChunkname < iChunkname) iLower = iMiddle + 1; else if (mng_chunk_table [iMiddle].iChunkname > iChunkname) iUpper = iMiddle - 1; else { pEntry = &mng_chunk_table [iMiddle]; break; } iMiddle = (iLower + iUpper) >> 1; } while (iLower <= iUpper); if (!pEntry) /* unknown chunk ? */ pEntry = &mng_chunk_unknown; /* make it so! */ MNG_COPY (pResult, pEntry, sizeof(mng_chunk_header)); return;}/* ************************************************************************** *//* ************************************************************************** *//* PNG chunks */MNG_C_SPECIALFUNC (mng_special_ihdr){ pData->bHasIHDR = MNG_TRUE; /* indicate IHDR is present */ /* and store interesting fields */ if ((!pData->bHasDHDR) || (pData->iDeltatype == MNG_DELTATYPE_NOCHANGE)) { pData->iDatawidth = ((mng_ihdrp)pChunk)->iWidth; pData->iDataheight = ((mng_ihdrp)pChunk)->iHeight; } pData->iBitdepth = ((mng_ihdrp)pChunk)->iBitdepth; pData->iColortype = ((mng_ihdrp)pChunk)->iColortype; pData->iCompression = ((mng_ihdrp)pChunk)->iCompression; pData->iFilter = ((mng_ihdrp)pChunk)->iFilter; pData->iInterlace = ((mng_ihdrp)pChunk)->iInterlace;#if defined(MNG_NO_1_2_4BIT_SUPPORT) || defined(MNG_NO_16BIT_SUPPORT) pData->iPNGmult = 1; pData->iPNGdepth = pData->iBitdepth;#endif#ifdef MNG_NO_1_2_4BIT_SUPPORT if (pData->iBitdepth < 8) pData->iBitdepth = 8;#endif#ifdef MNG_NO_16BIT_SUPPORT if (pData->iBitdepth > 8) { pData->iBitdepth = 8; pData->iPNGmult = 2; }#endif if ((pData->iBitdepth != 8) /* parameter validity checks */#ifndef MNG_NO_1_2_4BIT_SUPPORT && (pData->iBitdepth != 1) && (pData->iBitdepth != 2) && (pData->iBitdepth != 4)#endi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -