⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libmng_chunk_io.c

📁 Linux下的基于X11的图形开发环境。
💻 C
📖 第 1 页 / 共 5 页
字号:
/* ************************************************************************** *//* *             For conditions of distribution and use,                    * *//* *                see copyright notice in libmng.h                        * *//* ************************************************************************** *//* *                                                                        * *//* * project   : libmng                                                     * *//* * file      : libmng_chunk_io.c         copyright (c) 2000 G.Juyn        * *//* * version   : 1.0.2                                                      * *//* *                                                                        * *//* * purpose   : Chunk I/O routines (implementation)                        * *//* *                                                                        * *//* * author    : G.Juyn                                                     * *//* * web       : http://www.3-t.com                                         * *//* * email     : mailto:info@3-t.com                                        * *//* *                                                                        * *//* * comment   : implementation of chunk input/output routines              * *//* *                                                                        * *//* * changes   : 0.5.1 - 05/01/2000 - G.Juyn                                * *//* *             - cleaned up left-over teststuff in the BACK chunk routine * *//* *             0.5.1 - 05/04/2000 - G.Juyn                                * *//* *             - changed CRC initialization to use dynamic structure      * *//* *               (wasn't thread-safe the old way !)                       * *//* *             0.5.1 - 05/06/2000 - G.Juyn                                * *//* *             - filled in many missing sequence&length checks            * *//* *             - filled in many missing chunk-store snippets              * *//* *             0.5.1 - 05/08/2000 - G.Juyn                                * *//* *             - added checks for running animations                      * *//* *             - filled some write routines                               * *//* *             - changed strict-ANSI stuff                                * *//* *             0.5.1 - 05/10/2000 - G.Juyn                                * *//* *             - filled some more write routines                          * *//* *             0.5.1 - 05/11/2000 - G.Juyn                                * *//* *             - filled remaining write routines                          * *//* *             - fixed read_pplt with regard to deltatype                 * *//* *             - added callback error-reporting support                   * *//* *             - added pre-draft48 support (short MHDR, frame_mode, LOOP) * *//* *             0.5.1 - 05/12/2000 - G.Juyn                                * *//* *             - changed trace to macro for callback error-reporting      * *//* *             - fixed chunk-storage bit in several routines              * *//* *             0.5.1 - 05/13/2000 - G.Juyn                                * *//* *             - added eMNGma hack (will be removed in 1.0.0 !!!)         * *//* *             - added TERM animation object pointer (easier reference)   * *//* *             - supplemented the SAVE & SEEK display processing          * *//* *                                                                        * *//* *             0.5.2 - 05/18/2000 - G.Juyn                                * *//* *             - B004 - fixed problem with MNG_SUPPORT_WRITE not defined  * *//* *               also for MNG_SUPPORT_WRITE without MNG_INCLUDE_JNG       * *//* *             0.5.2 - 05/19/2000 - G.Juyn                                * *//* *             - cleaned up some code regarding mixed support             * *//* *             0.5.2 - 05/20/2000 - G.Juyn                                * *//* *             - implemented JNG support                                  * *//* *             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 support for SAVE & SEEK in animation               * *//* *             0.5.2 - 05/29/2000 - G.Juyn                                * *//* *             - changed ani_create calls not returning object pointer    * *//* *             - create ani objects always (not just inside TERM/LOOP)    * *//* *             0.5.2 - 05/30/2000 - G.Juyn                                * *//* *             - added support for delta-image processing                 * *//* *             0.5.2 - 05/31/2000 - G.Juyn                                * *//* *             - fixed up punctuation (contributed by Tim Rowley)         * *//* *             0.5.2 - 06/02/2000 - G.Juyn                                * *//* *             - changed SWAP_ENDIAN to BIGENDIAN_SUPPORTED               * *//* *             0.5.2 - 06/03/2000 - G.Juyn                                * *//* *             - fixed makeup for Linux gcc compile                       * *//* *                                                                        * *//* *             0.5.3 - 06/12/2000 - G.Juyn                                * *//* *             - added processing of color-info on delta-image            * *//* *             0.5.3 - 06/13/2000 - G.Juyn                                * *//* *             - fixed handling of empty SAVE chunk                       * *//* *             0.5.3 - 06/17/2000 - G.Juyn                                * *//* *             - changed to support delta-images                          * *//* *             - added extra checks for delta-images                      * *//* *             0.5.3 - 06/20/2000 - G.Juyn                                * *//* *             - fixed possible trouble if IEND display-process got       * *//* *               broken up                                                * *//* *             0.5.3 - 06/21/2000 - G.Juyn                                * *//* *             - added processing of PLTE & tRNS for delta-images         * *//* *             - added administration of imagelevel parameter             * *//* *             0.5.3 - 06/22/2000 - G.Juyn                                * *//* *             - implemented support for PPLT chunk                       * *//* *             0.5.3 - 06/26/2000 - G.Juyn                                * *//* *             - added precaution against faulty iCCP chunks from PS      * *//* *             0.5.3 - 06/29/2000 - G.Juyn                                * *//* *             - fixed some 64-bit warnings                               * *//* *                                                                        * *//* *             0.9.1 - 07/14/2000 - G.Juyn                                * *//* *             - changed pre-draft48 frame_mode=3 to frame_mode=1         * *//* *             0.9.1 - 07/16/2000 - G.Juyn                                * *//* *             - fixed storage of images during mng_read()                * *//* *             - fixed support for mng_display() after mng_read()         * *//* *             0.9.1 - 07/19/2000 - G.Juyn                                * *//* *             - fixed several chunk-writing routines                     * *//* *             0.9.1 - 07/24/2000 - G.Juyn                                * *//* *             - fixed reading of still-images                            * *//* *                                                                        * *//* *             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/08/2000 - G.Juyn                                * *//* *             - fixed compiler-warnings from Mozilla                     * *//* *             0.9.3 - 08/09/2000 - G.Juyn                                * *//* *             - added check for simplicity-bits in MHDR                  * *//* *             0.9.3 - 08/12/2000 - G.Juyn                                * *//* *             - fixed check for simplicity-bits in MHDR (JNG)            * *//* *             0.9.3 - 08/12/2000 - G.Juyn                                * *//* *             - added workaround for faulty PhotoShop iCCP chunk         * *//* *             0.9.3 - 08/22/2000 - G.Juyn                                * *//* *             - fixed write-code for zTXt & iTXt                         * *//* *             - fixed read-code for iTXt                                 * *//* *             0.9.3 - 08/26/2000 - G.Juyn                                * *//* *             - added MAGN chunk                                         * *//* *             0.9.3 - 09/07/2000 - G.Juyn                                * *//* *             - added support for new filter_types                       * *//* *             0.9.3 - 09/10/2000 - G.Juyn                                * *//* *             - fixed DEFI behavior                                      * *//* *             0.9.3 - 10/02/2000 - G.Juyn                                * *//* *             - fixed simplicity-check in compliance with draft 81/0.98a * *//* *             0.9.3 - 10/10/2000 - G.Juyn                                * *//* *             - added support for alpha-depth prediction                 * *//* *             0.9.3 - 10/11/2000 - G.Juyn                                * *//* *             - added support for nEED                                   * *//* *             0.9.3 - 10/16/2000 - G.Juyn                                * *//* *             - added support for JDAA                                   * *//* *             0.9.3 - 10/17/2000 - G.Juyn                                * *//* *             - fixed support for MAGN                                   * *//* *             - implemented nEED "xxxx" (where "xxxx" is a chunkid)      * *//* *             - added callback to process non-critical unknown chunks    * *//* *             - fixed support for bKGD                                   * *//* *             0.9.3 - 10/23/2000 - G.Juyn                                * *//* *             - fixed bug in empty PLTE handling                         * *//* *                                                                        * *//* *             0.9.4 - 11/20/2000 - G.Juyn                                * *//* *             - changed IHDR filter_method check for PNGs                * *//* *             0.9.4 -  1/18/2001 - G.Juyn                                * *//* *             - added errorchecking for MAGN methods                     * *//* *             - removed test filter-methods 1 & 65                       * *//* *                                                                        * *//* *             0.9.5 -  1/25/2001 - G.Juyn                                * *//* *             - fixed some small compiler warnings (thanks Nikki)        * *//* *                                                                        * *//* *             1.0.2 - 05/05/2000 - G.Juyn                                * *//* *             - B421427 - writes wrong format in bKGD and tRNS           * *//* *             1.0.2 - 06/20/2000 - G.Juyn                                * *//* *             - B434583 - compiler-warning if MNG_STORE_CHUNKS undefined * *//* *                                                                        * *//* ************************************************************************** */#include "libmng.h"#include "libmng_data.h"#include "libmng_error.h"#include "libmng_trace.h"#ifdef __BORLANDC__#pragma hdrstop#endif#include "libmng_objects.h"#include "libmng_object_prc.h"#include "libmng_chunks.h"#ifdef MNG_CHECK_BAD_ICCP#include "libmng_chunk_prc.h"#endif#include "libmng_memory.h"#include "libmng_display.h"#include "libmng_zlib.h"#include "libmng_pixels.h"#include "libmng_chunk_io.h"#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI)#pragma option -A                      /* force ANSI-C */#endif/* ************************************************************************** *//* *                                                                        * *//* * CRC - Cyclic Redundancy Check                                          * *//* *                                                                        * *//* * The code below is taken directly from the sample provided with the     * *//* * PNG specification.                                                     * *//* * (it is only adapted to the library's internal data-definitions)        * *//* *                                                                        * *//* ************************************************************************** *//* Make the table for a fast CRC. */void make_crc_table (mng_datap pData){  mng_uint32 iC;  mng_int32  iN, iK;  for (iN = 0; iN < 256; iN++)  {    iC = (mng_uint32) iN;    for (iK = 0; iK < 8; iK++)    {      if (iC & 1)        iC = 0xedb88320U ^ (iC >> 1);      else        iC = iC >> 1;    }    pData->aCRCtable [iN] = iC;  }  pData->bCRCcomputed = MNG_TRUE;}/* Update a running CRC with the bytes buf[0..len-1]--the CRC   should be initialized to all 1's, and the transmitted value   is the 1's complement of the final running CRC (see the   crc() routine below). */mng_uint32 update_crc (mng_datap  pData,                       mng_uint32 iCrc,                       mng_uint8p pBuf,                       mng_int32  iLen){  mng_uint32 iC = iCrc;  mng_int32 iN;  if (!pData->bCRCcomputed)    make_crc_table (pData);  for (iN = 0; iN < iLen; iN++)    iC = pData->aCRCtable [(iC ^ pBuf [iN]) & 0xff] ^ (iC >> 8);  return iC;}/* Return the CRC of the bytes buf[0..len-1]. */mng_uint32 crc (mng_datap  pData,                mng_uint8p pBuf,                mng_int32  iLen){  return update_crc (pData, 0xffffffffU, pBuf, iLen) ^ 0xffffffffU;}/* ************************************************************************** *//* *                                                                        * *//* * Routines for swapping byte-order from and to graphic files             * *//* * (This code is adapted from the libpng package)                         * *//* *                                                                        * *//* ************************************************************************** */#ifndef MNG_BIGENDIAN_SUPPORTED/* ************************************************************************** */mng_uint32 mng_get_uint32 (mng_uint8p pBuf){   mng_uint32 i = ((mng_uint32)(*pBuf)       << 24) +                  ((mng_uint32)(*(pBuf + 1)) << 16) +                  ((mng_uint32)(*(pBuf + 2)) <<  8) +                   (mng_uint32)(*(pBuf + 3));   return (i);}/* ************************************************************************** */mng_int32 mng_get_int32 (mng_uint8p pBuf){   mng_int32 i = ((mng_int32)(*pBuf)       << 24) +                 ((mng_int32)(*(pBuf + 1)) << 16) +                 ((mng_int32)(*(pBuf + 2)) <<  8) +                  (mng_int32)(*(pBuf + 3));   return (i);}/* ************************************************************************** */mng_uint16 mng_get_uint16 (mng_uint8p pBuf){   mng_uint16 i = (mng_uint16)(((mng_uint16)(*pBuf) << 8) +                                (mng_uint16)(*(pBuf + 1)));   return (i);}/* ************************************************************************** */void mng_put_uint32 (mng_uint8p pBuf,                     mng_uint32 i){   *pBuf     = (mng_uint8)((i >> 24) & 0xff);   *(pBuf+1) = (mng_uint8)((i >> 16) & 0xff);   *(pBuf+2) = (mng_uint8)((i >> 8) & 0xff);   *(pBuf+3) = (mng_uint8)(i & 0xff);}/* ************************************************************************** */void mng_put_int32 (mng_uint8p pBuf,                    mng_int32  i){   *pBuf     = (mng_uint8)((i >> 24) & 0xff);   *(pBuf+1) = (mng_uint8)((i >> 16) & 0xff);   *(pBuf+2) = (mng_uint8)((i >> 8) & 0xff);   *(pBuf+3) = (mng_uint8)(i & 0xff);}/* ************************************************************************** */void mng_put_uint16 (mng_uint8p pBuf,                     mng_uint16 i){   *pBuf     = (mng_uint8)((i >> 8) & 0xff);   *(pBuf+1) = (mng_uint8)(i & 0xff);}/* ************************************************************************** */#endif /* !MNG_BIGENDIAN_SUPPORTED *//* ************************************************************************** *//* *                                                                        * *//* * Helper routines to simplify chunk-data extraction                      * *//* *                                                                        * *//* ************************************************************************** */#ifdef MNG_INCLUDE_READ_PROCS/* ************************************************************************** */mng_uint8p find_null (mng_uint8p pIn){  mng_uint8p pOut = pIn;  while (*pOut)                        /* the read_graphic routine has made sure there's */    pOut++;                            /* always at least 1 zero-byte in the buffer */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -