File: ddpiimpl.cc

package info (click to toggle)
dcmtk 3.6.0-12
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 32,976 kB
  • sloc: cpp: 193,852; ansic: 46,292; sh: 4,020; makefile: 3,969; perl: 3,278; lex: 94
file content (145 lines) | stat: -rw-r--r-- 4,894 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
 *
 *  Copyright (C) 2003-2010, OFFIS e.V.
 *  All rights reserved.  See COPYRIGHT file for details.
 *
 *  This software and supporting documentation were developed by
 *
 *    OFFIS e.V.
 *    R&D Division Health
 *    Escherweg 2
 *    D-26121 Oldenburg, Germany
 *
 *
 *  Module:  dcmdata
 *
 *  Author:  Joerg Riesmeier
 *
 *  Purpose: Implementation of DICOMDIR image support (plugin)
 *
 *  Last Update:      $Author: joergr $
 *  Update Date:      $Date: 2010-10-14 13:14:21 $
 *  CVS/RCS Revision: $Revision: 1.4 $
 *  Status:           $State: Exp $
 *
 *  CVS/RCS Log at end of file
 *
 */


#include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */

#include "dcmtk/dcmjpeg/ddpiimpl.h"
#include "dcmtk/dcmimgle/dcmimage.h"  /* for class DicomImage */
#include "dcmtk/dcmimgle/discalet.h"  /* for direct image scaling */

#include "dcmtk/ofstd/ofcast.h"


/*------------------*
 *  implementation  *
 *------------------*/

// constructor
DicomDirImageImplementation::DicomDirImageImplementation()
{
}


// destructor
DicomDirImageImplementation::~DicomDirImageImplementation()
{
}


// scale pixel data
OFBool DicomDirImageImplementation::scaleData(const Uint8 *srcData,
                                              const unsigned int srcWidth,
                                              const unsigned int srcHeight,
                                              Uint8 *dstData,
                                              const unsigned int dstWidth,
                                              const unsigned int dstHeight) const
{
    OFBool result = OFFalse;
    /* check parameters (at least the pointers) */
    if ((srcData != NULL) && (dstData != NULL))
    {
        DiScaleTemplate<Uint8> scale(1, OFstatic_cast(Uint16, srcWidth), OFstatic_cast(Uint16, srcHeight),
                                        OFstatic_cast(Uint16, dstWidth), OFstatic_cast(Uint16, dstHeight), 1);
        scale.scaleData(OFstatic_cast(const Uint8 **, &srcData), &dstData, 1 /* interpolate */);
        result = OFTrue;
    }
    return result;
}


// get scaled pixel data from DICOM image (monochrome only)
OFBool DicomDirImageImplementation::scaleImage(DcmItem *dataset,
                                               Uint8 *pixel,
                                               const unsigned long count,
                                               const unsigned long frame,
                                               const unsigned int width,
                                               const unsigned int height,
                                               const OFBool decompressAll) const
{
    OFBool result = OFFalse;
    /* check parameters (at least the pointers) */
    if ((dataset != NULL) && (pixel != NULL) && (frame > 0))
    {
        unsigned long flags = CIF_UsePartialAccessToPixelData | CIF_NeverAccessEmbeddedOverlays;
        if (decompressAll)
            flags |= CIF_DecompressCompletePixelData;
        /* open referenced image */
        DicomImage *image = new DicomImage(dataset, EXS_Unknown, flags, frame - 1 /*fstart*/, 1 /*fcount*/);
        if ((image != NULL) && (image->getStatus() == EIS_Normal))
        {
            /* check if image is monochrome */
            if (!image->isMonochrome())
            {
                /* ... if not create one */
                DicomImage *mono = image->createMonochromeImage();
                /* replace image by monochrome one */
                delete image;
                image = mono;
            }
            if (image != NULL)
            {
                /* create icon */
                DicomImage *scaled = image->createScaledImage(OFstatic_cast(unsigned long, width),
                                                              OFstatic_cast(unsigned long, height), 1 /*interpolate*/);
                if (scaled != NULL)
                {
                    /* set VOI window */
                    if (!scaled->setWindow(0))
                        scaled->setMinMaxWindow();
                    /* get pixel data */
                    void *data = OFstatic_cast(void *, pixel);
                    if (scaled->getOutputData(data, count, 8))
                        result = OFTrue;
                    delete scaled;
                }
            }
        }
        delete image;
    }
    return result;
}


/*
 *  CVS/RCS Log:
 *  $Log: ddpiimpl.cc,v $
 *  Revision 1.4  2010-10-14 13:14:21  joergr
 *  Updated copyright header. Added reference to COPYRIGHT file.
 *
 *  Revision 1.3  2009-11-25 13:36:05  joergr
 *  Adapted code for new approach to access individual frames of a DICOM image.
 *
 *  Revision 1.2  2005-12-08 15:43:24  meichel
 *  Changed include path schema for all DCMTK header files
 *
 *  Revision 1.1  2003/08/12 13:14:54  joergr
 *  Added plugable image support for the new DICOMDIR class.
 *
 *
 */