dcmjpls/libcharls/util.h

00001 //
00002 // (C) Jan de Vaan 2007-2010, all rights reserved. See the accompanying "License.txt" for licensed use.
00003 //
00004 
00005 
00006 #ifndef CHARLS_UTIL
00007 #define CHARLS_UTIL
00008 
00009 #include "pubtypes.h"
00010 
00011 #ifndef MAX
00012 #define MAX(a,b)            (((a) > (b)) ? (a) : (b))
00013 #endif
00014 
00015 #ifndef MIN
00016 #define MIN(a,b)            (((a) < (b)) ? (a) : (b))
00017 #endif
00018 
00019 #ifndef ABS
00020 #define ABS(a)              (((a) > 0) ? (a) : -(a))
00021 #endif
00022 
00023 
00024 const LONG BASIC_RESET  = 64;
00025 
00026 inline LONG log_2(LONG n)
00027 {
00028     LONG x = 0;
00029     while (n > (LONG(1) << x))
00030     {
00031         ++x;
00032     }
00033     return x;
00034 
00035 }
00036 
00037 struct Size
00038 {
00039     Size(LONG width, LONG height) :
00040         cx(width),
00041         cy(height)
00042     {}
00043     LONG cx;
00044     LONG cy;
00045 };
00046 
00047 
00048 
00049 inline LONG Sign(LONG n)
00050     { return (n >> (LONG_BITCOUNT-1)) | 1;}
00051 
00052 inline LONG BitWiseSign(LONG i)
00053     { return i >> (LONG_BITCOUNT-1); }
00054 
00055 
00056 template<class SAMPLE>
00057 struct Triplet
00058 {
00059     Triplet() :
00060         v1(0),
00061         v2(0),
00062         v3(0)
00063     {}
00064 
00065     Triplet(LONG x1, LONG x2, LONG x3) :
00066         v1((SAMPLE)x1),
00067         v2((SAMPLE)x2),
00068         v3((SAMPLE)x3)
00069     {}
00070 
00071         union
00072         {
00073             SAMPLE v1;
00074             SAMPLE R;
00075         };
00076         union
00077         {
00078             SAMPLE v2;
00079             SAMPLE G;
00080         };
00081         union
00082         {
00083             SAMPLE v3;
00084             SAMPLE B;
00085         };
00086 };
00087 
00088 inline bool operator==(const Triplet<BYTE>& lhs, const Triplet<BYTE>& rhs)
00089     { return lhs.v1 == rhs.v1 && lhs.v2 == rhs.v2 && lhs.v3 == rhs.v3; }
00090 
00091 inline bool  operator!=(const Triplet<BYTE>& lhs, const Triplet<BYTE>& rhs)
00092     { return !(lhs == rhs); }
00093 
00094 
00095 template<class sample>
00096 struct Quad : public Triplet<sample>
00097 {
00098     Quad() :
00099         v4(0)
00100         {}
00101 
00102     Quad(Triplet<sample> triplet, LONG alpha) : Triplet<sample>(triplet), A((sample)alpha)
00103         {}
00104 
00105     union
00106     {
00107         sample v4;
00108         sample A;
00109     };
00110 };
00111 
00112 
00113 
00114 template<typename T>
00115 struct FromBigEndian
00116 {
00117     inlinehint static T Read(BYTE* pbyte)
00118     {
00119         T ret = pbyte[0];
00120         for (unsigned int i = 1; i < sizeof(T); i++)
00121         {
00122             ret <<= 8;
00123             ret |= pbyte[i];
00124         }
00125         return ret;
00126     }
00127 };
00128 
00129 
00130 class JlsException
00131 {
00132 public:
00133     JlsException(JLS_ERROR error) : _error(error)
00134         { }
00135 
00136     JLS_ERROR _error;
00137 };
00138 
00139 
00140 #endif


Generated on 6 Jan 2011 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.5.1