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

📄 diinpxt.h

📁 转化为DIB位图再显示出来的dicom文件C++代码
💻 H
📖 第 1 页 / 共 2 页
字号:
        register unsigned long i;        Data = new T2[Count];        if (Data != NULL)        {#ifdef DEBUG            if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Informationals))            {                ofConsole.lockCerr() << bitsAllocated << " " << bitsStored << " " << highBit << " " << isSigned() << endl;                ofConsole.unlockCerr();            }#endif            register const T1 *p = pixel;            register T2 *q = Data;            if (bitsof_T1 == bitsAllocated)                                             // case 1: equal 8/16 bit            {                if (bitsStored == bitsAllocated)                {#ifdef DEBUG                    if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Informationals))                    {                        ofConsole.lockCerr() << "convert pixelData: case 1a (single copy)" << endl;                        ofConsole.unlockCerr();                    }#endif                    for (i = Count; i != 0; --i)                        *(q++) = OFstatic_cast(T2, *(p++));                }                else /* bitsStored < bitsAllocated */                {                    register T1 mask = 0;                    for (i = 0; i < bitsStored; ++i)                        mask |= OFstatic_cast(T1, 1 << i);                    const T2 sign = 1 << (bitsStored - 1);                    T2 smask = 0;                    for (i = bitsStored; i < bitsof_T2; ++i)                        smask |= OFstatic_cast(T2, 1 << i);                    const Uint16 shift = highBit + 1 - bitsStored;                    if (shift == 0)                    {#ifdef DEBUG                        if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Informationals))                        {                            ofConsole.lockCerr() << "convert pixelData: case 1b (mask & sign)" << endl;                            ofConsole.unlockCerr();                        }#endif                        for (i = length_T1; i != 0; --i)                            *(q++) = expandSign(OFstatic_cast(T2, *(p++) & mask), sign, smask);                    }                    else /* shift > 0 */                    {#ifdef DEBUG                        if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Informationals))                        {                            ofConsole.lockCerr() << "convert pixelData: case 1c (shift & mask & sign)" << endl;                            ofConsole.unlockCerr();                        }#endif                        for (i = length_T1; i != 0; --i)                            *(q++) = expandSign(OFstatic_cast(T2, (*(p++) >> shift) & mask), sign, smask);                    }                }            }            else if ((bitsof_T1 > bitsAllocated) && (bitsof_T1 % bitsAllocated == 0))   // case 2: divisor of 8/16 bit            {                const Uint16 times = bitsof_T1 / bitsAllocated;                register T1 mask = 0;                for (i = 0; i < bitsStored; ++i)                    mask |= OFstatic_cast(T1, 1 << i);                register Uint16 j;                register T1 value;                if ((bitsStored == bitsAllocated) && (bitsStored == bitsof_T2))                {                    if (times == 2)                    {#ifdef DEBUG                        if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Informationals))                        {                            ofConsole.lockCerr() << "convert pixelData: case 2a (simple mask)" << endl;                            ofConsole.unlockCerr();                        }#endif                        for (i = length_T1; i != 0; --i, ++p)                        {                            *(q++) = OFstatic_cast(T2, *p & mask);                            *(q++) = OFstatic_cast(T2, *p >> bitsAllocated);                        }                    }                    else                    {#ifdef DEBUG                        if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Informationals))                        {                            ofConsole.lockCerr() << "convert pixelData: case 2b (mask)" << endl;                            ofConsole.unlockCerr();                        }#endif                        for (i = length_T1; i != 0; --i)                        {                            value = *(p++);                            for (j = times; j != 0; --j)                            {                                *(q++) = OFstatic_cast(T2, value & mask);                                value >>= bitsAllocated;                            }                        }                    }                }                else                {#ifdef DEBUG                    if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Informationals))                    {                        ofConsole.lockCerr() << "convert pixelData: case 2c (shift & mask & sign)" << endl;                        ofConsole.unlockCerr();                    }#endif                    const T2 sign = 1 << (bitsStored - 1);                    T2 smask = 0;                    for (i = bitsStored; i < bitsof_T2; ++i)                        smask |= OFstatic_cast(T2, 1 << i);                    const Uint16 shift = highBit + 1 - bitsStored;                    for (i = length_T1; i != 0; --i)                    {                        value = *(p++) >> shift;                        for (j = times; j != 0; --j)                        {                            *(q++) = expandSign(OFstatic_cast(T2, value & mask), sign, smask);                            value >>= bitsAllocated;                        }                    }                }            }            else if ((bitsof_T1 < bitsAllocated) && (bitsAllocated % bitsof_T1 == 0)    // case 3: multiplicant of 8/16                && (bitsStored == bitsAllocated))            {#ifdef DEBUG                if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Informationals))                {                    ofConsole.lockCerr() << "convert pixelData: case 3 (multi copy)" << endl;                    ofConsole.unlockCerr();                }#endif                const Uint16 times = bitsAllocated / bitsof_T1;                register Uint16 j;                register Uint16 shift;                register T2 value;                for (i = length_T1; i != 0; --i)                {                    shift = 0;                    value = OFstatic_cast(T2, *(p++));                    for (j = times; j > 1; --j, --i)                    {                        shift += bitsof_T1;                        value |= OFstatic_cast(T2, *(p++)) << shift;                    }                    *(q++) = value;                }            }            else                                                                        // case 4: anything else            {#ifdef DEBUG                if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Informationals))                {                    ofConsole.lockCerr() << "convert pixelData: case 4 (general)" << endl;                    ofConsole.unlockCerr();                }#endif                register T2 value = 0;                register Uint16 bits = 0;                register Uint32 skip = highBit + 1 - bitsStored;                register Uint32 times;                T1 mask[bitsof_T1];                mask[0] = 1;                for (i = 1; i < bitsof_T1; ++i)                    mask[i] = (mask[i - 1] << 1) | 1;                T2 smask = 0;                for (i = bitsStored; i < bitsof_T2; ++i)                    smask |= OFstatic_cast(T2, 1 << i);                const T2 sign = 1 << (bitsStored - 1);                const Uint32 gap = bitsAllocated - bitsStored;                i = 0;                while (i < length_T1)                {                    if (skip < bitsof_T1)                    {                        if (skip + bitsStored - bits < bitsof_T1)       // -++- --++                        {                            value |= (OFstatic_cast(T2, (*p >> skip) & mask[bitsStored - bits - 1]) << bits);                            skip += bitsStored - bits + gap;                            bits = bitsStored;                        }                        else                                            // ++-- ++++                        {                            value |= (OFstatic_cast(T2, (*p >> skip) & mask[bitsof_T1 - skip - 1]) << bits);                            bits += bitsof_T1 - OFstatic_cast(Uint16, skip);                            skip = (bits == bitsStored) ? gap : 0;                            ++i;                            ++p;                        }                        if (bits == bitsStored)                        {                            *(q++) = expandSign(value, sign, smask);                            value = 0;                            bits = 0;                        }                    }                    else                    {                        times = skip / bitsof_T1;                        i += times;                        p += times;                        skip -= times * bitsof_T1;                    }                }            }        }    }    /// pointer to pixel data    T2 *Data;    /// minimum pixel value ([0] = global, [1] = selected pixel range)    T2 MinValue[2];    /// maximum pixel value ([0] = global, [1] = selected pixel range)    T2 MaxValue[2]; // --- declarations to avoid compiler warnings    DiInputPixelTemplate(const DiInputPixelTemplate<T1,T2> &);    DiInputPixelTemplate<T1,T2> &operator=(const DiInputPixelTemplate<T1,T2> &);};#endif/* * * CVS/RCS Log: * $Log: diinpxt.h,v $ * Revision 1.30  2005/12/08 16:47:44  meichel * Changed include path schema for all DCMTK header files * * Revision 1.29  2004/04/21 10:00:36  meichel * Minor modifications for compilation with gcc 3.4.0 * * Revision 1.28  2004/02/06 11:07:50  joergr * Distinguish more clearly between const and non-const access to pixel data. * * Revision 1.27  2004/01/05 14:52:20  joergr * Removed acknowledgements with e-mail addresses from CVS log. * * Revision 1.26  2003/12/23 15:53:22  joergr * Replaced post-increment/decrement operators by pre-increment/decrement * operators where appropriate (e.g. 'i++' by '++i'). * * Revision 1.25  2003/12/08 19:10:52  joergr * Adapted type casts to new-style typecast operators defined in ofcast.h. * Removed leading underscore characters from preprocessor symbols (reserved * symbols). Updated copyright header. * * Revision 1.24  2002/10/21 10:13:50  joergr * Corrected wrong calculation of min/max pixel value in cases where the * stored pixel data exceeds the expected size. * * Revision 1.23  2001/11/13 18:07:36  joergr * Fixed bug occurring when processing monochrome images with an odd number of * pixels. * * Revision 1.22  2001/10/10 15:25:09  joergr * Removed redundant variable declarations to avoid compiler warnings * ("declaration of ... shadows previous local"). * * Revision 1.21  2001/09/28 13:04:59  joergr * Enhanced algorithm to determine the min and max value. * * Revision 1.20  2001/06/01 15:49:42  meichel * Updated copyright header * * Revision 1.19  2000/05/03 09:46:28  joergr * Removed most informational and some warning messages from release built * (#ifndef DEBUG). * * Revision 1.18  2000/04/28 12:32:30  joergr * DebugLevel - global for the module - now derived from OFGlobal (MF-safe). * * Revision 1.17  2000/04/27 13:08:39  joergr * Dcmimgle library code now consistently uses ofConsole for error output. * * Revision 1.16  2000/03/08 16:24:17  meichel * Updated copyright header. * * Revision 1.15  2000/03/03 14:09:12  meichel * Implemented library support for redirecting error messages into memory *   instead of printing them to stdout/stderr for GUI applications. * * Revision 1.14  1999/09/17 12:21:57  joergr * Added/changed/completed DOC++ style comments in the header files. * Enhanced efficiency of some "for" loops and of the implementation to * determine min/max values of the input pixels. * * Revision 1.13  1999/07/23 13:54:38  joergr * Optimized memory usage for converting input pixel data (reference instead * of copying where possible). * * Revision 1.12  1999/05/04 09:20:39  meichel * Minor code purifications to keep IBM xlC quiet * * Revision 1.11  1999/04/30 16:23:59  meichel * Minor code purifications to keep IBM xlC quiet * * Revision 1.10  1999/04/28 14:48:39  joergr * Introduced new scheme for the debug level variable: now each level can be * set separately (there is no "include" relationship). * * Revision 1.9  1999/03/24 17:20:03  joergr * Added/Modified comments and formatting. * * Revision 1.8  1999/02/11 16:00:54  joergr * Removed inline declarations from several methods. * * Revision 1.7  1999/02/03 17:04:37  joergr * Moved global functions maxval() and determineRepresentation() to class * DicomImageClass (as static methods). * * Revision 1.6  1999/01/20 15:01:31  joergr * Replaced invocation of getCount() by member variable Count where possible. * * Revision 1.5  1999/01/11 09:34:28  joergr * Corrected bug in determing 'AbsMaximum' (removed '+ 1'). * * Revision 1.4  1998/12/22 14:23:16  joergr * Added calculation of member variables AbsMinimum/AbsMaximum. * Replaced method copyMem by for-loop copying each item. * Removed some '#ifdef DEBUG'. * * Revision 1.3  1998/12/16 16:30:34  joergr * Added methods to determine absolute minimum and maximum value for given * value representation. * * Revision 1.2  1998/12/14 17:18:23  joergr * Reformatted source code. * * Revision 1.1  1998/11/27 15:08:21  joergr * Added copyright message. * Introduced global debug level for dcmimage module to control error output. * Added support for new bit manipulation class. * * Revision 1.8  1998/07/01 08:39:21  joergr * Minor changes to avoid compiler warnings (gcc 2.8.1 with additional * options), e.g. add copy constructors. * * Revision 1.7  1998/05/11 14:53:17  joergr * Added CVS/RCS header to each file. * * */

⌨️ 快捷键说明

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