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

📄 dicopxt.h

📁 转化为DIB位图再显示出来的dicom文件C++代码
💻 H
📖 第 1 页 / 共 2 页
字号:
/* * *  Copyright (C) 1996-2005, OFFIS * *  This software and supporting documentation were developed by * *    Kuratorium OFFIS e.V. *    Healthcare Information and Communication Systems *    Escherweg 2 *    D-26121 Oldenburg, Germany * *  THIS SOFTWARE IS MADE AVAILABLE,  AS IS,  AND OFFIS MAKES NO  WARRANTY *  REGARDING  THE  SOFTWARE,  ITS  PERFORMANCE,  ITS  MERCHANTABILITY  OR *  FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES  OR *  ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND *  PERFORMANCE OF THE SOFTWARE IS WITH THE USER. * *  Module:  dcmimage * *  Author:  Joerg Riesmeier * *  Purpose: DicomColorPixelTemplate (Header) * *  Last Update:      $Author: meichel $ *  Update Date:      $Date: 2005/12/08 16:01:35 $ *  CVS/RCS Revision: $Revision: 1.25 $ *  Status:           $State: Exp $ * *  CVS/RCS Log at end of file * */#ifndef DICOPXT_H#define DICOPXT_H#include "dcmtk/config/osconfig.h"#include "dcmtk/dcmdata/dctypes.h"#include "dcmtk/ofstd/ofbmanip.h"#include "dcmtk/dcmimage/dicopx.h"#include "dcmtk/dcmimgle/dipxrept.h"/********************************************************************/inline Uint8 removeSign(const Uint8 value, const Uint8){    return value;}inline Uint16 removeSign(const Uint16 value, const Uint16){    return value;}inline Uint32 removeSign(const Uint32 value, const Uint32){    return value;}inline Uint8 removeSign(const Sint8 value, const Sint8 offset){    return OFstatic_cast(Uint8, OFstatic_cast(Sint16, value) + OFstatic_cast(Sint16, offset) + 1);}inline Uint16 removeSign(const Sint16 value, const Sint16 offset){    return OFstatic_cast(Uint16, OFstatic_cast(Sint32, value) + OFstatic_cast(Sint32, offset) + 1);}/*inline Uint32 removeSign(const Sint32 value, const Sint32 offset){    return (value < 0) ? OFstatic_cast(Uint32, value + offset + 1) : OFstatic_cast(Uint32, value) + OFstatic_cast(Uint32, offset) + 1;}inline Uint8 removeSign(const Sint8 value, const Uint8 mask){    return OFstatic_cast(Uint8, value) ^ mask;}inline Uint16 removeSign(const Sint16 value, const Uint16 mask){    return OFstatic_cast(Uint16, value) ^ mask;}*/inline Uint32 removeSign(const Sint32 value, const Uint32 mask){    return OFstatic_cast(Uint32, value) ^ mask;}/*---------------------* *  class declaration  * *---------------------*//** Template class to handle color pixel data */template<class T>class DiColorPixelTemplate  : public DiColorPixel,    public DiPixelRepresentationTemplate<T>{ public:    /** constructor     *     ** @param  docu         pointer to the DICOM document     *  @param  pixel        pointer to input pixel data     *  @param  samples      number of expected samples per pixel (for checking purposes)     *  @param  status       status of the image object (reference variable)     *  @param  sample_rate  dummy parameter (used for derived classes only)     */    DiColorPixelTemplate(const DiDocument *docu,                         const DiInputPixel *pixel,                         const Uint16 samples,                         EI_Status &status,                         const Uint16 sample_rate = 0)      : DiColorPixel(docu, pixel, samples, status, sample_rate)    {        Data[0] = NULL;        Data[1] = NULL;        Data[2] = NULL;    }    /** destructor     */    virtual ~DiColorPixelTemplate()    {        delete[] Data[0];        delete[] Data[1];        delete[] Data[2];    }    /** get integer representation     *     ** @return integer representation of the internally stored pixel data     */    inline EP_Representation getRepresentation() const    {        return DiPixelRepresentationTemplate<T>::getRepresentation();    }    /** get pointer to internal array of pixel data.     *  The returned array [0..2] points to the three image planes.     *     ** @return pointer to array of pixel data     */    inline const void *getData() const    {        return OFstatic_cast(const void *, Data);    }    /** get pointer to internal array of pixel data.     *  The returned array [0..2] points to the three image planes.     *     ** @return pointer to array of pixel data     */    inline void *getDataPtr()    {        return OFstatic_cast(void *, Data);    }    /** get pointer to internal array of pixel data.     *  The returned array [0..2] points to the three image planes.     *     ** @return reference to pointer to pixel data     */    inline void *getDataArrayPtr()    {        return OFstatic_cast(void *, Data);    }    /** fill given memory block with pixel data (all three image planes, RGB).     *  Currently, the samples are always ordered by plane, thus the DICOM attribute     *  'PlanarConfiguration' has to be set to '1'.     *     ** @param  data   pointer to memory block (array of 8 or 16 bit values, OB/OW)     *  @param  count  number of T-size entries allocated in the 'data' array     *     ** @return OFTrue if successful, OFFalse otherwise     */    OFBool getPixelData(void *data,                        const size_t count) const    {        OFBool result = OFFalse;        /* check parameters and internal data */        if ((data != NULL) && (count >= Count * 3) &&            (Data[0] != NULL) && (Data[1] != NULL) && (Data[2] != NULL))        {            /* copy all three planes to the given memory block */            OFBitmanipTemplate<T>::copyMem(Data[0], OFstatic_cast(T *, data), Count);            OFBitmanipTemplate<T>::copyMem(Data[1], OFstatic_cast(T *, data) + Count, Count);            OFBitmanipTemplate<T>::copyMem(Data[2], OFstatic_cast(T *, data) + 2 * Count, Count);            result = OFTrue;        }        return result;    }    /** create true color (24/32 bit) bitmap for MS Windows.     *     ** @param  data        untyped pointer memory buffer (set to NULL if not allocated externally)     *  @param  size        size of the memory buffer in bytes (if 0 'data' is set to NULL)     *  @param  width       number of columns of the image     *  @param  height      number of rows of the image     *  @param  frame       index of frame to be converted (starting from 0)     *  @param  fromBits    number of bits per sample used for internal representation of the image     *  @param  toBits      number of bits per sample used for the output bitmap (<= 8)     *  @param  mode        color output mode (24 or 32 bits, see dcmimgle/dcmimage.h for details)     *  @param  upsideDown  specifies the order of lines in the images (0 = top-down, bottom-up otherwise)     *  @param  padding     align each line to a 32-bit address if true     *     ** @return number of bytes allocated by the bitmap, or 0 if an error occured     */    unsigned long createDIB(void *&data,                            const unsigned long size,                            const Uint16 width,                            const Uint16 height,                            const unsigned long frame,                            const int fromBits,                            const int toBits,                            const int mode,                            const int upsideDown,                            const int padding) const    {        unsigned long bytes = 0;        if ((Data[0] != NULL) && (Data[1] != NULL) && (Data[2] != NULL) && (toBits <= 8))        {            const unsigned long count = OFstatic_cast(unsigned long, width) * OFstatic_cast(unsigned long, height);            const unsigned long start = count * frame + ((upsideDown) ?                OFstatic_cast(unsigned long, height - 1) * OFstatic_cast(unsigned long, width) : 0);            const signed long nextRow = (upsideDown) ? -2 * OFstatic_cast(signed long, width) : 0;            register const T *r = Data[0] + start;            register const T *g = Data[1] + start;            register const T *b = Data[2] + start;            register Uint16 x;            register Uint16 y;            if (mode == 24)     // 24 bits per pixel            {                const unsigned long wid3 = OFstatic_cast(unsigned long, width) * 3;                // each line has to start at 32-bit-address, if 'padding' is true                const int gap = (padding) ? OFstatic_cast(int, (4 - wid3 & 0x3) & 0x3) : 0;                unsigned long fsize = (wid3 + gap) * OFstatic_cast(unsigned long, height);                if ((data == NULL) || (size >= fsize))                {                    if (data == NULL)                        data = new Uint8[fsize];                    if (data != NULL)                    {                        register Uint8 *q = OFstatic_cast(Uint8 *, data);                        if (fromBits == toBits)                        {                            /* copy pixel data as is */                            for (y = height; y != 0; y--)                            {                                for (x = width; x != 0; x--)                                {                                    /* reverse sample order: B-G-R */                                    *(q++) = OFstatic_cast(Uint8, *(b++));                                    *(q++) = OFstatic_cast(Uint8, *(g++));                                    *(q++) = OFstatic_cast(Uint8, *(r++));                                }                                r += nextRow; g += nextRow; b += nextRow;           // go backwards if 'upsideDown'                                q += gap;                                           // new line: jump to next 32-bit address                            }                        }                        else if (fromBits < toBits)                        {                            /* increase color depth: multiply with factor */                            const double gradient1 = OFstatic_cast(double, DicomImageClass::maxval(toBits)) /                                                     OFstatic_cast(double, DicomImageClass::maxval(fromBits));                            const Uint8 gradient2 = OFstatic_cast(Uint8, gradient1);                            if (gradient1 == OFstatic_cast(double, gradient2))      // integer multiplication?                            {                                for (y = height; y != 0; y--)                                {                                    for (x = width; x != 0; x--)                                    {                                        /* reverse sample order: B-G-R */                                        *(q++) = OFstatic_cast(Uint8, *(b++) * gradient2);                                        *(q++) = OFstatic_cast(Uint8, *(g++) * gradient2);                                        *(q++) = OFstatic_cast(Uint8, *(r++) * gradient2);                                    }                                    r += nextRow; g += nextRow; b += nextRow;       // go backwards if 'upsideDown'                                    q += gap;                                       // new line: jump to next 32-bit address                                }                            } else {                                for (y = height; y != 0; y--)                                {                                    for (x = width; x != 0; x--)                                    {                                        /* reverse sample order: B-G-R */                                        *(q++) = OFstatic_cast(Uint8, OFstatic_cast(double, *(b++)) * gradient1);                                        *(q++) = OFstatic_cast(Uint8, OFstatic_cast(double, *(g++)) * gradient1);                                        *(q++) = OFstatic_cast(Uint8, OFstatic_cast(double, *(r++)) * gradient1);                                    }                                    r += nextRow; g += nextRow; b += nextRow;       // go backwards if 'upsideDown'                                    q += gap;                                       // new line: jump to next 32-bit address                                }                            }                        }                        else /* fromBits > toBits */                        {                            /* reduce color depth: right shift */                            const int shift = fromBits - toBits;                            for (y = height; y != 0; y--)                            {                                for (x = width; x != 0; x--)                                {                                    /* reverse sample order: B-G-R */                                    *(q++) = OFstatic_cast(Uint8, *(b++) >> shift);

⌨️ 快捷键说明

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