~ubuntu-branches/ubuntu/utopic/ginkgocadx/utopic-proposed

« back to all changes in this revision

Viewing changes to src/cadxcore/main/controllers/dcmtk/libi2d/pdf2dsource.cpp

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2012-05-19 11:37:14 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20120519113714-13jwx5svm7d4fnsq
Tags: 2.12.0.4889-1
* New upstream version
* debian/control: Standards-Version: 3.9.3 (no changes needed)
* debhelper 9 (control+compat)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  
 
3
 *  $Id: pdf2dsource.cpp 4723 2012-02-20 08:39:13Z tovar $
 
4
 *  Ginkgo CADx Project
 
5
 *
 
6
 *  Code addapted from DCMTK
 
7
 *
 
8
 *
 
9
 *  Copyright (C) 2001-2007, OFFIS
 
10
 *
 
11
 *  This software and supporting documentation were developed by
 
12
 *
 
13
 *    Kuratorium OFFIS e.V.
 
14
 *    Healthcare Information and Communication Systems
 
15
 *    Escherweg 2
 
16
 *    D-26121 Oldenburg, Germany
 
17
 *
 
18
 *  THIS SOFTWARE IS MADE AVAILABLE,  AS IS,  AND OFFIS MAKES NO  WARRANTY
 
19
 *  REGARDING  THE  SOFTWARE,  ITS  PERFORMANCE,  ITS  MERCHANTABILITY  OR
 
20
 *  FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES  OR
 
21
 *  ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND
 
22
 *  PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
 
23
 *
 
24
 *  Module:  dcmdata
 
25
 *
 
26
 *  Author:  Michael Onken
 
27
 *
 
28
 *  Purpose: Base Class for plugins extracting pixel data from standard
 
29
 *           image files
 
30
 *
 
31
 *  Last Update:      $Author: onken $
 
32
 *  Update Date:      $Date: 2009-01-16 09:51:55 $
 
33
 *  CVS/RCS Revision: $Revision: 1.2 $
 
34
 *  Status:           $State: Exp $
 
35
 *
 
36
 *  CVS/RCS Log at end of file
 
37
 *
 
38
 */
 
39
#ifdef verify
 
40
#define MACRO_QUE_ESTORBA verify
 
41
#undef verify
 
42
#endif
 
43
 
 
44
#include <dcmtk/config/osconfig.h>
 
45
#include "document2dcm.h"
 
46
#include <dcmtk/dcmdata/dcpxitem.h>
 
47
 
 
48
#include "dcmtk/dcmdata/dctk.h"
 
49
//#include "dcmtk/dcmdata/dcdebug.h"
 
50
#include "dcmtk/dcmdata/cmdlnarg.h"
 
51
#include "dcmtk/ofstd/ofconapp.h"
 
52
#include "dcmtk/dcmdata/dcuid.h"     /* for dcmtk version name */
 
53
#include "dcmtk/dcmdata/dcistrmf.h"
 
54
 
 
55
#include "pdf2dsource.h"
 
56
#include <main/controllers/controladorlog.h>
 
57
#include <main/entorno.h>
 
58
 
 
59
 
 
60
OFString PDF2DSource::inputFormat() const
 
61
{
 
62
        return "PDF";
 
63
}
 
64
/** Reads pixel data and corresponding attributes like rows etc. from image
 
65
         *  file and inserts them into dataset.
 
66
         *  @param dset - [out] The dataset to export the pixel data attributes to
 
67
         *  @param outputTS - [out] The proposed transfex syntax of the dataset
 
68
         *  @return EC_Normal, if successful, error otherwise
 
69
         */
 
70
OFCondition PDF2DSource::readAndInsertSpecificTags( DcmDataset* dset,
 
71
                                                                           E_TransferSyntax& outputTS)
 
72
        {
 
73
                OFCondition cond;
 
74
 
 
75
                //it's a secondary capture.. if conversion type is not set put  SD -> scanned document
 
76
                dset->putAndInsertString(DCM_ConversionType, "SD", false);
 
77
                dset->putAndInsertString(DCM_MIMETypeOfEncapsulatedDocument, "application/pdf", true);
 
78
 
 
79
                cond = dset->putAndInsertOFStringArray(DCM_SOPClassUID, UID_EncapsulatedPDFStorage);
 
80
                if (cond.bad())
 
81
                        return makeOFCondition(OFM_dcmdata, 18, OF_error, "Unable to insert SOP class into dataset");
 
82
 
 
83
                if (!dset->tagExists(DCM_Modality)) {
 
84
                        cond = dset->putAndInsertOFStringArray(DCM_Modality, "SC");
 
85
                        if (cond.bad())
 
86
                                return makeOFCondition(OFM_dcmdata, 18, OF_error, "Unable to insert Modality (SC) into dataset");
 
87
                }
 
88
 
 
89
                if (!dset->tagExists(DCM_BurnedInAnnotation)) {
 
90
                        cond = dset->putAndInsertOFStringArray(DCM_BurnedInAnnotation, "YES");
 
91
                        if (cond.bad())
 
92
                                return makeOFCondition(OFM_dcmdata, 18, OF_error, "Unable to insert DCM_BurnedInAnnotation into dataset");
 
93
                }
 
94
 
 
95
 
 
96
                //document
 
97
                //read file into unsigned char
 
98
                {
 
99
                        size_t fileSize = 0;
 
100
                        {
 
101
                                std::ifstream file;
 
102
                                file.open(m_file.c_str(),std::ios_base::binary);
 
103
                                if(!file.is_open()) {
 
104
                                        LOG_ERROR("PDF2DSource","Error opening file");
 
105
                                        return false;
 
106
                                }
 
107
                                //get the length of the file
 
108
                                file.seekg(0,std::ios::end);
 
109
                                fileSize = file.tellg();
 
110
                                if (fileSize %2 != 0) {
 
111
                                        LOG_INFO("VideoDicomizer", "Video size is odd, padding with 0");
 
112
                                        //file is odd
 
113
                                        m_isTemp = true;
 
114
                                        std::string m_TempFile = GNC::Entorno::Instance()->CreateGinkgoTempFile();
 
115
                                        if (!wxCopyFile(FROMPATH(m_file), FROMPATH(m_TempFile))) {
 
116
                                                LOG_ERROR("PDF2DSource", "Error creating temp file");
 
117
                                        }
 
118
                                        std::ofstream ofile;
 
119
                                        ofile.open(m_TempFile.c_str(), std::ios_base::app);
 
120
                                        ofile << '\0';
 
121
                                        ofile.close();
 
122
                                        m_file = m_TempFile.c_str();
 
123
                                        fileSize++;
 
124
                                }
 
125
                        }
 
126
                        DcmInputFileStreamFactory* pFactory = new DcmInputFileStreamFactory(m_file.c_str(), 0);
 
127
                        DcmOtherByteOtherWord* fileTag = new DcmOtherByteOtherWord(DCM_EncapsulatedDocument);
 
128
                        fileTag->setVR(EVR_OB);
 
129
                        fileTag->createValueFromTempFile(pFactory, fileSize, EBO_unknown);
 
130
 
 
131
                        dset->insert(fileTag, true);                    
 
132
                }                       
 
133
 
 
134
 
 
135
                outputTS = EXS_LittleEndianExplicit;
 
136
                return cond;
 
137
        }
 
138
 
 
139
        /** Do some completeness / validity checks. Should be called when
 
140
         *  dataset is completed and is about to be saved.
 
141
         *  @param dataset - [in] The dataset to check
 
142
         *  @return Error string if error occurs, empty string otherwise
 
143
         */
 
144
OFString PDF2DSource::isValid(DcmDataset& dset) const
 
145
        {
 
146
                if (m_debug)
 
147
                        printMessage(m_logStream, "I2DImgSource: Checking validity of DICOM output dataset");
 
148
                OFString dummy, err;
 
149
                OFCondition cond;
 
150
                err += checkAndInventType2Attrib(DCM_MIMETypeOfEncapsulatedDocument, &dset);
 
151
 
 
152
                err += checkAndInventType2Attrib(DCM_SOPInstanceUID, &dset);
 
153
                err += checkAndInventType2Attrib(DCM_ConversionType, &dset);
 
154
 
 
155
                return err;
 
156
        }
 
157
 
 
158
PDF2DSource::~PDF2DSource()
 
159
{
 
160
        if (m_isTemp)
 
161
        {
 
162
                wxRemoveFile(FROMPATH(m_file));
 
163
        }
 
164
}
 
 
b'\\ No newline at end of file'