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

📄 imfxdr.h

📁 image converter source code
💻 H
📖 第 1 页 / 共 2 页
字号:
/////////////////////////////////////////////////////////////////////////////// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas// Digital Ltd. LLC// // All rights reserved.// // Redistribution and use in source and binary forms, with or without// modification, are permitted provided that the following conditions are// met:// *       Redistributions of source code must retain the above copyright// notice, this list of conditions and the following disclaimer.// *       Redistributions in binary form must reproduce the above// copyright notice, this list of conditions and the following disclaimer// in the documentation and/or other materials provided with the// distribution.// *       Neither the name of Industrial Light & Magic nor the names of// its contributors may be used to endorse or promote products derived// from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE./////////////////////////////////////////////////////////////////////////////#ifndef INCLUDED_IMF_XDR_H#define INCLUDED_IMF_XDR_H//----------------------------------------------------------------------------////	Xdr -- routines to convert data between the machine's native//	format and a machine-independent external data representation:////	    write<R> (T &o, S v);	converts a value, v, of type S//					into a machine-independent//					representation and stores the//					result in an output buffer, o.////	    read<R> (T &i, S &v);	reads the machine-independent//					representation of a value of type//					S from input buffer i, converts//					the value into the machine's native//					representation, and stores the result//					in v.////	    size<S>();			returns the size, in bytes, of the//					machine-independent representation//					of an object of type S.//					//	The write() and read() routines are templates; data can be written//	to and read from any output or input buffer type T for which a helper//	class, R, exits.  Class R must define a method to store a char array//	in a T, and a method to read a char array from a T:////	    struct R//	    {//	        static void//	        writeChars (T &o, const char c[/*n*/], int n)//	        {//	            ... // Write c[0], c[1] ... c[n-1] to output buffer o.//	        }////	        static void//	        readChars (T &i, char c[/*n*/], int n)//	        {//	            ... // Read n characters from input buffer i//		        // and copy them to c[0], c[1] ... c[n-1].//	        }//	    };////	Example - writing to and reading from iostreams:////	    struct CharStreamIO//	    {//	        static void//	        writeChars (ostream &os, const char c[], int n)//	        {//	            os.write (c, n);//	        }////	        static void//	        readChars (istream &is, char c[], int n)//	        {//	            is.read (c, n);//	        }//	    };////          ...////	    Xdr::write<CharStreamIO> (os, 3);//	    Xdr::write<CharStreamIO> (os, 5.0);////----------------------------------------------------------------------------#include <ImfInt64.h>#include "IexMathExc.h"#include "half.h"#include <limits.h>namespace Imf {namespace Xdr {//-------------------------------// Write data to an output stream//-------------------------------template <class S, class T>voidwrite (T &out, bool v);template <class S, class T>voidwrite (T &out, char v);template <class S, class T>voidwrite (T &out, signed char v);template <class S, class T>voidwrite (T &out, unsigned char v);template <class S, class T>voidwrite (T &out, signed short v);template <class S, class T>voidwrite (T &out, unsigned short v);template <class S, class T>voidwrite (T &out, signed int v);template <class S, class T>voidwrite (T &out, unsigned int v);template <class S, class T>voidwrite (T &out, signed long v);template <class S, class T>voidwrite (T &out, unsigned long v);#if ULONG_MAX != 18446744073709551615LU    template <class S, class T>    void    write (T &out, Int64 v);#endiftemplate <class S, class T>voidwrite (T &out, float v);template <class S, class T>voidwrite (T &out, double v);template <class S, class T>voidwrite (T &out, half v);template <class S, class T>voidwrite (T &out, const char v[/*n*/], int n);	// fixed-size char arraytemplate <class S, class T>voidwrite (T &out, const char v[]);			// zero-terminated string//-----------------------------------------// Append padding bytes to an output stream//-----------------------------------------template <class S, class T>voidpad (T &out, int n);				// write n padding bytes//-------------------------------// Read data from an input stream//-------------------------------template <class S, class T>voidread (T &in, bool &v);template <class S, class T>voidread (T &in, char &v);template <class S, class T>voidread (T &in, signed char &v);template <class S, class T>voidread (T &in, unsigned char &v);template <class S, class T>voidread (T &in, signed short &v);template <class S, class T>voidread (T &in, unsigned short &v);template <class S, class T>voidread (T &in, signed int &v);template <class S, class T>voidread (T &in, unsigned int &v);template <class S, class T>voidread (T &in, signed long &v);template <class S, class T>voidread (T &in, unsigned long &v);#if ULONG_MAX != 18446744073709551615LU    template <class S, class T>    void    read (T &in, Int64 &v);#endiftemplate <class S, class T>voidread (T &in, float &v);template <class S, class T>voidread (T &in, double &v);template <class S, class T>voidread (T &in, half &v);template <class S, class T>voidread (T &in, char v[/*n*/], int n);		// fixed-size char arraytemplate <class S, class T>voidread (T &in, int n, char v[/*n*/]);		// zero-terminated string//-------------------------------------------// Skip over padding bytes in an input stream//-------------------------------------------template <class S, class T>voidskip (T &in, int n);				// skip n padding bytes//--------------------------------------// Size of the machine-independent// representation of an object of type S//--------------------------------------template <class S>intsize ();//---------------// Implementation//---------------template <class S, class T>inline voidwriteSignedChars (T &out, const signed char c[], int n){    S::writeChars (out, (const char *) c, n);}template <class S, class T>inline voidwriteUnsignedChars (T &out, const unsigned char c[], int n){    S::writeChars (out, (const char *) c, n);}template <class S, class T>inline voidreadSignedChars (T &in, signed char c[], int n){    S::readChars (in, (char *) c, n);}template <class S, class T>inline voidreadUnsignedChars (T &in, unsigned char c[], int n){    S::readChars (in, (char *) c, n);}template <class S, class T>inline voidwrite (T &out, bool v){    char c = !!v;    S::writeChars (out, &c, 1);}template <class S, class T>inline voidwrite (T &out, char v){    S::writeChars (out, &v, 1);}template <class S, class T>inline voidwrite (T &out, signed char v){    writeSignedChars<S> (out, &v, 1);}template <class S, class T>inline voidwrite (T &out, unsigned char v){    writeUnsignedChars<S> (out, &v, 1);}template <class S, class T>voidwrite (T &out, signed short v){    signed char b[2];    b[0] =  (signed char) (v);    b[1] =  (signed char) (v >> 8);    writeSignedChars<S> (out, b, 2);}template <class S, class T>voidwrite (T &out, unsigned short v){    unsigned char b[2];    b[0] =  (unsigned char) (v);    b[1] =  (unsigned char) (v >> 8);    writeUnsignedChars<S> (out, b, 2);}template <class S, class T>voidwrite (T &out, signed int v){    signed char b[4];    b[0] =  (signed char) (v);    b[1] =  (signed char) (v >> 8);    b[2] =  (signed char) (v >> 16);    b[3] =  (signed char) (v >> 24);    writeSignedChars<S> (out, b, 4);}template <class S, class T>voidwrite (T &out, unsigned int v){    unsigned char b[4];    b[0] =  (unsigned char) (v);    b[1] =  (unsigned char) (v >> 8);    b[2] =  (unsigned char) (v >> 16);    b[3] =  (unsigned char) (v >> 24);    writeUnsignedChars<S> (out, b, 4);}template <class S, class T>voidwrite (T &out, signed long v){    signed char b[8];    b[0] = (signed char) (v);    b[1] = (signed char) (v >> 8);    b[2] = (signed char) (v >> 16);    b[3] = (signed char) (v >> 24);    #if LONG_MAX == 2147483647	if (v >= 0)	{	    b[4] = 0;	    b[5] = 0;	    b[6] = 0;	    b[7] = 0;	}	else	{	    b[4] = ~0;	    b[5] = ~0;	    b[6] = ~0;	    b[7] = ~0;	}    #elif LONG_MAX == 9223372036854775807L	b[4] = (signed char) (v >> 32);	b[5] = (signed char) (v >> 40);	b[6] = (signed char) (v >> 48);	b[7] = (signed char) (v >> 56);    #else		#error write<T> (T &out, signed long v) not implemented    #endif    writeSignedChars<S> (out, b, 8);}

⌨️ 快捷键说明

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