Produced by Araxis Merge on 10/18/2018 2:02:19 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | VIX_SIV_v3_0_patch_201_build_8.zip\v3.0_patch_201_build_8\VISA\Java\ImagingDicomDCFCommon\src\java\gov\va\med\imaging\dicom\dcftoolkit\common\mediainterchange | Part10Files.java | Thu Oct 11 13:30:11 2018 UTC |
2 | VIX_SIV_v3_0_patch_201_build_8.zip\v3.0_patch_201_build_8\VISA\Java\ImagingDicomDCFCommon\src\java\gov\va\med\imaging\dicom\dcftoolkit\common\mediainterchange | Part10Files.java | Wed Oct 17 18:52:44 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 3 | 1438 |
Changed | 2 | 4 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | /** | |
2 | * | |
3 | Package: MAG - Vis tA Imaging | |
4 | WARNING: Per VHA D irective 2 004-038, t his routin e should n ot be modi fied. | |
5 | Date Cre ated: | |
6 | Site Nam e: Washin gton OI Fi eld Office , Silver S pring, MD | |
7 | Developer: PII | |
8 | Descript ion: | |
9 | ||
10 | ;; +-------- ---------- ---------- ---------- ---------- ---------- ---------- + | |
11 | ;; Property of the US Government . | |
12 | ;; No permis sion to co py or redi stribute t his softwa re is give n. | |
13 | ;; Use of un released v ersions of this soft ware requi res the us er | |
14 | ;; to execu te a writt en test ag reement wi th the Vis tA Imaging | |
15 | ;; Developm ent Office of the De partment o f Veterans Affairs, | |
16 | ;; telephon e (301) 73 4-0100. | |
17 | ;; | |
18 | ;; The Food and Drug A dministrat ion classi fies this software a s | |
19 | ;; a Class I I medical device. A s such, it may not b e changed | |
20 | ;; in any wa y. Modifi cations to this soft ware may r esult in a n | |
21 | ;; adulterat ed medical device un der 21CFR8 20, the us e of which | |
22 | ;; is consid ered to be a violati on of US F ederal Sta tutes. | |
23 | ;; +-------- ---------- ---------- ---------- ---------- ---------- ---------- + | |
24 | ||
25 | */ | |
26 | package go v.va.med.i maging.dic om.dcftool kit.common .mediainte rchange; | |
27 | ||
28 | import jav a.io.FileI nputStream ; | |
29 | import jav a.io.FileN otFoundExc eption; | |
30 | import jav a.io.FileO utputStrea m; | |
31 | import jav a.io.IOExc eption; | |
32 | import jav a.io.Input Stream; | |
33 | import jav a.io.Outpu tStream; | |
34 | import jav a.nio.chan nels.Chann els; | |
35 | import jav a.nio.chan nels.Reada bleByteCha nnel; | |
36 | import jav a.util.Arr ayList; | |
37 | import jav a.util.Lis t; | |
38 | ||
39 | import org .apache.lo gging.log4 j.LogManag er; | |
40 | import org .apache.lo gging.log4 j.Logger; | |
41 | ||
42 | import com .lbs.CDS.C FGAttribut e; | |
43 | import com .lbs.CDS.C FGGroup; | |
44 | import com .lbs.DCF.D CFExceptio n; | |
45 | import com .lbs.DCS.D CM; | |
46 | import com .lbs.DCS.D CSExceptio n; | |
47 | import com .lbs.DCS.D icomCSElem ent; | |
48 | import com .lbs.DCS.D icomDataSe t; | |
49 | import com .lbs.DCS.D icomElemen t; | |
50 | import com .lbs.DCS.D icomFileIn put; | |
51 | import com .lbs.DCS.D icomFileOu tput; | |
52 | import com .lbs.DCS.D icomOBElem ent; | |
53 | import com .lbs.DCS.D icomOWElem ent; | |
54 | import com .lbs.DCS.D icomSessio nSettings; | |
55 | import com .lbs.DCS.D icomStream Reader; | |
56 | import com .lbs.DCS.D icomStream Writer; | |
57 | import com .lbs.DCS.D icomStream ableDataEl ement; | |
58 | import com .lbs.DCS.D icomStream ableDataEl ement.Data Type; | |
59 | import com .lbs.DCS.D icomUSElem ent; | |
60 | import com .lbs.DCS.F ileMetaInf ormation; | |
61 | import com .lbs.DCS.U ID; | |
62 | ||
63 | import gov .va.med.im aging.core .interface s.StorageC redentials ; | |
64 | import gov .va.med.im aging.dico m.common.D icomFileMe taInfo; | |
65 | import gov .va.med.im aging.dico m.common.e xceptions. Part10File Exception; | |
66 | import gov .va.med.im aging.dico m.common.i nterfaces. IDicomData Set; | |
67 | import gov .va.med.im aging.dico m.dcftoolk it.common. DataSetByt eReader; | |
68 | import gov .va.med.im aging.dico m.dcftoolk it.common. impl.Dicom DataSetImp l; | |
69 | import gov .va.med.im aging.exch ange.busin ess.dicom. exceptions .DicomExce ption; | |
70 | import gov .va.med.im aging.exch ange.busin ess.storag e.NetworkL ocationInf o; | |
71 | import gov .va.med.im aging.exch ange.stora ge.DataSou rceImageIn putStream; | |
72 | import gov .va.med.im aging.vist a.storage. SmbStorage Utility; | |
73 | ||
74 | /** | |
75 | * @author PII | |
76 | * | |
77 | */ | |
78 | public cla ss Part10F iles { | |
79 | ||
80 | privat e static L ogger logg er = LogMa nager.getL ogger(Part 10Files.cl ass); | |
81 | ||
82 | pu blic stati c void sto reAsPart10 (String fi lename, St ring trans ferSyntax, IDicomDat aSet dds)t hrows Part 10FileExce ption{ | |
83 | ||
84 | try{ | |
85 | Dico mDataSet d ataset = ( DicomDataS et)dds.get DicomDataS et(); | |
86 | // This is of fered to g ive an alt ernative m ethod to w rite the f ile | |
87 | // to disk. This doe s not use streaming. | |
88 | Di comFileOut put dfo = new DicomF ileOutput( | |
89 | file name, tran sferSyntax , true, tr ue ); | |
90 | df o.open(); | |
91 | df o.writeDat aSet(datas et); | |
92 | df o.close(); | |
93 | lo gger.info( "Saved mes sage to di sk by push ing DicomD ataSet obj ect to Dic omFileOutp ut."); | |
94 | } | |
95 | catc h(Exceptio n X){ | |
96 | logger .error("Fa iled to sa ve DICOM o bject to d isk by pus hing Dicom DataSet ob ject to Di comFileOut put."); | |
97 | throw new Part10 FileExcept ion(); | |
98 | } | |
99 | } | |
100 | ||
101 | pu blic stati c void sto reAsPart10 (String fi lename, In putStream in) throws Part10Fil eException { | |
102 | ||
103 | try{ | |
104 | int bl ock_size = 16384; | |
105 | byte b uffer[] = new byte[b lock_size] ; | |
106 | ||
107 | FileOu tputStream out = new FileOutpu tStream(fi lename); | |
108 | int co unt; | |
109 | ||
110 | while ((count = in.read( b uffer )) > 0){ | |
111 | out.writ e(buffer, 0, count); | |
112 | } | |
113 | out.cl ose(); | |
114 | } | |
115 | catc h (Excepti on X){ | |
116 | logger .error("Fa iled to sa ve DICOM o bject to d isk using InputStrea m from Dat aSetByteRe ader."); | |
117 | throw new Part10 FileExcept ion(); | |
118 | } | |
119 | } | |
120 | ||
121 | // BILL This does not w ork. Fix it later. | |
122 | /* pu blic void storeAsPar t10(String filename, String tr ansferSynt ax, Readab leByteChan nel messag e) throws Part10File Exception{ | |
123 | ||
124 | try{ | |
125 | DataSe tByteReade r dbr = (D ataSetByte Reader)mes sage; | |
126 | int bl ock_size = 16384; | |
127 | ByteBu ffer buffe r = ByteBu ffer.alloc ate(block_ size); | |
128 | DicomS essionSett ings setti ngs = new DicomSessi onSettings (); | |
129 | ||
130 | DicomF ileWriter writer = n ew DicomFi leWriter(f ilename, s ettings); | |
131 | DicomF ileOutput out = new DicomFileO utput(writ er, transf erSyntax, true, fals e, setting s); | |
132 | ||
133 | while( dbr.read(b uffer) > 0 ){ | |
134 | writer.w rite(buffe r); | |
135 | } | |
136 | out.cl ose(); | |
137 | logger .info("Sav ed object to disk us ing DataBy teReader." ); | |
138 | } | |
139 | catc h (Excepti on X){ | |
140 | logger .error("Fa iled to sa ve DICOM o bject to d isk using DataByteRe ader."); | |
141 | throw new Part10 FileExcept ion(); | |
142 | } | |
143 | } | |
144 | */ | |
145 | ||
146 | pu blic stati c IDicomDa taSet read DicomFile( NetworkLoc ationInfo networkLoc ationInfo, String fi lename, Di comFileInp ut fileIn) | |
147 | throws DicomExce ption | |
148 | { | |
149 | // che ck for DIC OM TS and if TS is s upported, read the d ataset, if TS is not supported , convert it to | |
150 | // the VI pr eferred DI COM TS (LE EVR) by wr iting it o ut to a te mporary fi le (conver ting) and reading it back | |
151 | St ring fromT SUID = nul l; | |
152 | St ring toTSU ID = UID.T RANSFERLIT TLEENDIANE XPLICIT; | |
153 | // from TSUID = ex tractTSUID (filename) ; | |
154 | // if ( fromTSUID == null) { | |
155 | // logger .error("Fa iled to fi nd/open/pr e-scan a D ICOM Part1 0 format f ile " + fi lename); | |
156 | // return null; | |
157 | // } | |
158 | Di comDataSet dataSet = null; | |
159 | Fi leMetaInfo rmation me tadata = n ull; | |
160 | ID icomDataSe t dds = ne w DicomDat aSetImpl() ; | |
161 | Di comSession Settings d SS=null; | |
162 | bo olean deco mpress = f alse; | |
163 | bo olean firs tFile=true ; | |
164 | SmbS torageUtil ity util = new SmbSt orageUtili ty(); | |
165 | Data SourceImag eInputStre am fis = n ull; | |
166 | Dico mStreamRea der dsr = null; | |
167 | tr y { | |
168 | // fir st open fi le, and re ad dataset | |
169 | dSS = new DicomS essionSett ings(); | |
170 | try | |
171 | { | |
172 | fis = ut il.openFil eInputStre am(filenam e, (Storag eCredentia ls)network LocationIn fo); | |
173 | } | |
174 | catch (Exception e) | |
175 | { | |
176 | logger.e rror("Fail ed to open or read D ICOM objec t file, " + filename + " as a stream."); | |
177 | throw new DicomE xception(e ); | |
178 | } | |
179 | ||
180 | dsr = new DicomS treamReade r(fis.getI nputStream (), dSS); | |
181 | fileIn = new Dic omFileInpu t(dsr, nul l, dSS); | |
182 | fileIn .open(); | |
183 | data Set = file In.readDat aSet(); | |
184 | metada ta = fileI n.fileMeta Informatio n(); | |
185 | fromTS UID = meta data.trans ferSyntaxU id(); | |
186 | ||
187 | if (fr omTSUID.eq uals(UID.R LE_LOSSLES S)) // "1. 2.840.1000 8.1.2.5" S OP Class U ID | |
188 | convertR LEDataSet( dataSet); // // RLE DCF 3.3.22 c bug fix support | |
189 | ||
190 | // now determ ine if TS is in VI a cceptable TSs | |
191 | decomp ress = tru e; | |
192 | try { | |
193 | // get a llowed TSs from \cfg \app\defau lts\Listen config fi le | |
194 | CFGGroup cfgOfDCS = CINFO.ge tConfig(); | |
195 | CFGGroup theTSGrou p = cfgOfD CS.getGrou p("default _session_c fg/support ed_transfe r_syntaxes "); | |
196 | CFGAtt ribute[] t heTSs = th eTSGroup.g etAttribut es(); | |
197 | int i; | |
198 | for (i =0; i < th eTSs[0].ge tValues(). length; i+ +) { | |
199 | if (theT Ss[0].getV alues()[i] .equals(fr omTSUID)) { | |
200 | decompress =false; | |
201 | break; | |
202 | } | |
203 | } | |
204 | } | |
205 | catc h (DCFExce ption de) { | |
206 | logger .error(de. getMessage ()); | |
207 | logg er.error(" Exception thrown whi le reading Attribute s from the DCF confi guration f ile."); | |
208 | } | |
209 | ||
210 | if ( decompress ) { | |
211 | ||
212 | fileIn .close(tru e); | |
213 | ||
214 | // some conve rsion need ed: Output dataset t o same fol der to a f ile called converted *.dcm | |
215 | String newFName = filename .concat("2 "); // appen d '2' to e xtension | |
216 | firstF ile = fals e; | |
217 | // reopen n ewly creat ed (& rena med) file | |
218 | Output Stream fos = null; | |
219 | try | |
220 | { | |
221 | fos = ut il.openOut putStream( newFName, (StorageCr edentials) networkLoc ationInfo) ; | |
222 | } | |
223 | catch (Exception e) | |
224 | { | |
225 | logger.e rror("Fail ed to open output st ream for " + newFNam e); | |
226 | throw ne w DicomExc eption(e); | |
227 | } | |
228 | ||
229 | DicomS treamWrite r dsw = ne w DicomStr eamWriter( fos, dSS); | |
230 | DicomF ileOutput dfo = new DicomFileO utput( | |
231 | dsw, | |
232 | toTSUID, | |
233 | true, fals e, dSS); / / make Par t 10 heade r, keep gr oup 2 | |
234 | dfo. open(); | |
235 | dataSe t.insert(D CM.E_TRANS FER_SYNTAX _UID, toTS UID); | |
236 | dfo. writeDataS et( dataSe t ); | |
237 | dfo. close(); | |
238 | ||
239 | data Set.clear( ); | |
240 | ||
241 | // replace or iginal fil e with new file | |
242 | try | |
243 | { | |
244 | if (ut il.fileExi sts(filena me, (Stora geCredenti als)networ kLocationI nfo)) | |
245 | { | |
246 | util.del eteFile(fi lename, (S torageCred entials)ne tworkLocat ionInfo); | |
247 | } | |
248 | ||
249 | util.ren ameFile(ne wFName, fi lename, (S torageCred entials)ne tworkLocat ionInfo); | |
250 | ||
251 | } | |
252 | catc h (IOExcep tion ioe) | |
253 | { | |
254 | logger.e rror("Fail ed to writ e / rename converted DICOM obj ect file, " + newFNa me); | |
255 | throw ne w DicomExc eption(ioe ); | |
256 | } | |
257 | ||
258 | // reopen n ewly creat ed (& rena med) file | |
259 | try | |
260 | { | |
261 | fis = ut il.openFil eInputStre am(filenam e, (Storag eCredentia ls)network LocationIn fo); | |
262 | } | |
263 | catch (Exception e) | |
264 | { | |
265 | logger.e rror("Fail ed to open or read D ICOM objec t file, " + filename + " as a stream."); | |
266 | throw ne w DicomExc eption(e); | |
267 | } | |
268 | ||
269 | dsr = new DicomS treamReade r(fis.getI nputStream (), dSS); | |
270 | file In = new D icomFileIn put(dsr, n ull, dSS); | |
271 | fileIn .open(); | |
272 | dataSe t = fileIn .readDataS et(); | |
273 | metada ta = fileI n.fileMeta Informatio n(); | |
274 | fromTS UID = meta data.trans ferSyntaxU id(); | |
275 | ||
276 | } | |
277 | ||
278 | dds.se tDicomData Set(dataSe t); | |
279 | dds.se tSourceAET (getSource AeTitle(me tadata)); | |
280 | dds. setReceive dTransferS yntax(from TSUID); | |
281 | ||
282 | } | |
283 | ca tch (DCSEx ception dc sX) | |
284 | { | |
285 | Stri ng message = ""; | |
286 | if ( firstFile) | |
287 | { | |
288 | messag e = "Faile d to open or read DI COM object file, " + filename; | |
289 | } | |
290 | else | |
291 | { | |
292 | messag e = "Faile d to open, convert o r read DIC OM object file " + f ilename + | |
293 | " (Convert from " + f romTSUID + " to " + toTSUID + ")"; | |
294 | } | |
295 | ||
296 | logg er.error(m essage); | |
297 | throw ne w DicomExc eption(mes sage, dcsX ); | |
298 | } | |
299 | retu rn dds; | |
300 | } | |
301 | ||
302 | ||
303 | pu blic stati c IDicomDa taSet read LocalDicom File(Strin g filename , DicomFil eInput fil eIn) | |
304 | throws DicomExce ption | |
305 | { | |
306 | // c heck for D ICOM TS an d if TS is supported , read the dataset, if TS is n ot support ed, conver t it to | |
307 | // t he VI pref erred DICO M TS (LEEV R) by writ ing it out to a temp orary file (converti ng) and re ading it b ack | |
308 | St ring fromT SUID = nul l; | |
309 | ||
310 | Di comDataSet dataSet = null; | |
311 | Fi leMetaInfo rmation me tadata = n ull; | |
312 | ID icomDataSe t dds = ne w DicomDat aSetImpl() ; | |
313 | Di comSession Settings d SS=null; | |
314 | File InputStrea m fis = nu ll; | |
315 | Dico mStreamRea der dsr = null; | |
316 | tr y { | |
317 | // fir st open fi le, and re ad dataset | |
318 | dSS = new DicomS essionSett ings(); | |
319 | try | |
320 | { | |
321 | fis = ne w FileInpu tStream(fi lename); | |
322 | } | |
323 | catch( FileNotFou ndExceptio n fnfX) | |
324 | { | |
325 | logger.e rror("File [" + file name + "] not found. "); | |
326 | logger.e rror(fnfX. getMessage (), fnfX); | |
327 | throw new DicomE xception(f nfX); | |
328 | ||
329 | } | |
330 | catch (Exception X) | |
331 | { | |
332 | logger.e rror("Exce ption thro wn opening File [" + filename + "] ."); | |
333 | logger.e rror(X.get Message(), X); | |
334 | ||
335 | throw new DicomE xception(X ); | |
336 | } | |
337 | ||
338 | dsr = new DicomS treamReade r(fis, dSS ); | |
339 | fileIn = new Dic omFileInpu t(dsr, nul l, dSS); | |
340 | fileIn .open(); | |
341 | data Set = file In.readDat aSet(); | |
342 | metada ta = fileI n.fileMeta Informatio n(); | |
343 | fromTS UID = meta data.trans ferSyntaxU id(); | |
344 | ||
345 | dds.se tDicomData Set(dataSe t); | |
346 | dds.se tSourceAET (getSource AeTitle(me tadata)); | |
347 | dds. setReceive dTransferS yntax(from TSUID); | |
348 | ||
349 | } | |
350 | ca tch (DCSEx ception dc sX) | |
351 | { | |
352 | Stri ng message = ""; | |
353 | messag e = "Faile d to open or read DI COM object file, " + filename + " : " + dcsX.getMe ssage(); | |
354 | ||
355 | logg er.error(m essage); | |
356 | throw ne w DicomExc eption(mes sage, dcsX ); | |
357 | } | |
358 | retu rn dds; | |
359 | } | |
360 | ||
361 | pr ivate stat ic String getSourceA eTitle(Fil eMetaInfor mation met adata) | |
362 | { | |
363 | try | |
364 | { | |
365 | return metadata. sourceAeTi tle(); | |
366 | } | |
367 | catc h (Excepti on e) {} | |
368 | ||
369 | retu rn ""; | |
370 | } | |
371 | ||
372 | /* this is not us ed now, bu t handy | |
373 | fi nal static int MarkS ize = 520; // this value need s to be at least 128 +4+30+68+6 8+68+1=367 | |
374 | ||
375 | pr ivate stat ic String extractTSU ID(String filename) { | |
376 | Stri ng tSUID=n ull; | |
377 | File InputStrea m ins=null ; | |
378 | tr y { | |
379 | ins = ne w FileInpu tStream(fi lename); | |
380 | ins.skip (128); | |
381 | int by te1, byte2 , byte3, b yte4 = 0; | |
382 | byte1 = ins.read (); | |
383 | byte2 = ins.read (); | |
384 | byte3 = ins.read (); | |
385 | byte4 = ins.read (); | |
386 | if((by te1== 68) && (byte2 == 73) && (byte3 == 67) && (by te4 == 77) ) { // fou nd the DIC M string | |
387 | String U ID=""; // look for D ICOM tag ( 0002,0010) TS UID | |
388 | for (int i=132; (i < MarkSiz e-8); ) { | |
389 | if (UID.le ngth()==0) | |
390 | by te1 = ins. read(); | |
391 | else | |
392 | UI D=""; | |
393 | byte2 = in s.read(); | |
394 | // fact: D ICOM group 2 is alwa ys in Litt le Endian Explicit V R! | |
395 | if ((byte1 == 2) && (byte2 == 0)){ | |
396 | by te3 = ins. read(); | |
397 | by te4 = ins. read(); | |
398 | if ((byte3 == 0x10) && (byte4 == 0)) { | |
399 | // D ICOM tag ( 0002,0010) -- TS UID -- found | |
400 | ins. skip(4); / / skip VR and lengt h | |
401 | i+=8 ; | |
402 | UID= ""; | |
403 | whil e ((i<Mark Size) && ( (byte1 = i ns.read()) >= 0x2e)) { | |
404 | UID += Character .toString( (char)byte 1); // col lect TS UI D string | |
405 | i++; | |
406 | } | |
407 | } else | |
408 | i+=2 ; | |
409 | } else | |
410 | i+ =2; | |
411 | if (UID.le ngth() > 0 ) | |
412 | br eak; | |
413 | } | |
414 | tSUID=UI D; | |
415 | } else { | |
416 | // DICM string was not found | |
417 | return n ull; | |
418 | } | |
419 | } catch (IOE xception i oe) { | |
420 | retu rn null; | |
421 | } finally { | |
422 | try { | |
423 | if (in s != null) { | |
424 | ins.clos e(); | |
425 | } | |
426 | } catch (IOExcepti on ioe) {} | |
427 | } | |
428 | retu rn tSUID; | |
429 | } | |
430 | */ | |
431 | // RLE DCF 3 .3.22c bug fix suppo rt | |
432 | privat e static v oid conver tRLEDataSe t(DicomDat aSet ds) t hrows DCSE xception | |
433 | { | |
434 | boo lean isPal etteColorI mage = ds. findElemen t(DCM.E_PH OTOMETRIC_ INTERPRETA TION).getS tringValue ().trim() | |
435 | .equ als("PALET TE COLOR") ; | |
436 | ||
437 | if (isPalette ColorImage ) | |
438 | { | |
439 | DicomEle ment bits = ds.findE lement(DCM .E_BITS_AL LOCATED); | |
440 | int outp utBits = b its.getInt Value(); / / 0, 8 or 16 | |
441 | if ( (ou tputBits ! = 0) && (o utputBits != 8) && ( outputBits != 16) ) | |
442 | outputBits = 0; | |
443 | DicomEle ment pix = ds.findEl ement(DCM. E_PIXEL_DA TA); | |
444 | ||
445 | logg er.debug(" Processing Photometr ic Interpr etation PA LETTE COLO R."); | |
446 | ||
447 | // Provi des info a bout the n umber of s amples, th e minimum sample val ue, and bi ts per sam ple. | |
448 | int[] re dPaletteIn fo = ((Dic omUSElemen t) ds.find Element(DC M.E_RED_PA LETTE_COLO R_LUT_DESC )).getUSDa ta(); | |
449 | int[] gr eenPalette Info = ((D icomUSElem ent) ds.fi ndElement( DCM.E_GREE N_PALETTE_ CLR_LUT_DE SC)).getUS Data(); | |
450 | int[] bl uePaletteI nfo = ((Di comUSEleme nt) ds.fin dElement(D CM.E_BLUE_ PALETTE_CO LOR_LUT_DE SC)).getUS Data(); | |
451 | if (redP aletteInfo [0] != gre enPaletteI nfo[0] || greenPalet teInfo[0] != bluePal etteInfo[0 ]) | |
452 | { | |
453 | thro w new DCSE xception(" number of entries is different between c hannels"); | |
454 | } | |
455 | if (redP aletteInfo [1] != gre enPaletteI nfo[1] || greenPalet teInfo[1] != bluePal etteInfo[1 ]) | |
456 | { | |
457 | thro w new DCSE xception(" first entr y is diffe rent betwe en channel s"); | |
458 | } | |
459 | if (redP aletteInfo [2] != gre enPaletteI nfo[2] || greenPalet teInfo[2] != bluePal etteInfo[2 ]) | |
460 | { | |
461 | thro w new DCSE xception(" number of bits is di fferent be tween chan nels"); | |
462 | } | |
463 | ||
464 | int pixe lBits = ds .findEleme nt(DCM.E_B ITS_STORED ).getIntVa lue(); | |
465 | if (outp utBits == 0) { | |
466 | outp utBits = r edPaletteI nfo[2]; | |
467 | } | |
468 | ||
469 | int[] re dPaletteLU T = conver tToLUT((Di comOWEleme nt) ds.fin dElement(D CM.E_RED_P ALETTE_COL OR_LUT_DAT A), redPal etteInfo, pixelBits, outputBit s); | |
470 | int[] gr eenPalette LUT = conv ertToLUT(( DicomOWEle ment) ds.f indElement (DCM.E_GRE EN_PALETTE _CLR_LUT_D ATA), gree nPaletteIn fo, pixelB its, outpu tBits); | |
471 | int[] bl uePaletteL UT = conve rtToLUT((D icomOWElem ent) ds.fi ndElement( DCM.E_BLUE _PALETTE_C OLOR_LUT_D ATA), blue PaletteInf o, pixelBi ts, output Bits); | |
472 | ||
473 | // dumpL uts(); | |
474 | ||
475 | // note that this assumes un signed pix el data. | |
476 | DicomStr eamableDat aElement s Pix = (Dic omStreamab leDataElem ent)pix; | |
477 | int data Type = sPi x.getBuffe rDataType( ); | |
478 | if (data Type == Da taType.BYT E || dataT ype == Dat aType.SBYT E) | |
479 | { | |
480 | byte [] pixels = sPix.get ByteData(t rue, true) ; | |
481 | if ( outputBits == 8) | |
482 | { | |
483 | byte[] tmp Pix = new byte[pixel s.length * 3]; | |
484 | for (int i = 0; i < pixels.len gth; i++) | |
485 | { | |
486 | int pi xelValue = pixels[i] & 0xFF; | |
487 | int j = i * 3; | |
488 | tmpPix [j] = (byt e) redPale tteLUT[pix elValue]; | |
489 | tmpPix [j + 1] = (byte) gre enPaletteL UT[pixelVa lue]; | |
490 | tmpPix [j + 2] = (byte) blu ePaletteLU T[pixelVal ue]; | |
491 | } | |
492 | ds.insert( new DicomO BElement(D CM.E_PIXEL _DATA, tmp Pix)); | |
493 | } | |
494 | else /*(output Bits == 16 )*/ | |
495 | { | |
496 | short[] tm pPix = new short[pix els.length * 3]; | |
497 | for (int i = 0; i < pixels.len gth; i++) | |
498 | { | |
499 | int pi xelValue = pixels[i] & 0xFF; | |
500 | int j = i * 3; | |
501 | tmpPix [j] = (sho rt) redPal etteLUT[pi xelValue]; | |
502 | tmpPix [j + 1] = (short) gr eenPalette LUT[pixelV alue]; | |
503 | tmpPix [j + 2] = (short) bl uePaletteL UT[pixelVa lue]; | |
504 | } | |
505 | ds.insert( new DicomO WElement(D CM.E_PIXEL _DATA, tmp Pix)); | |
506 | } | |
507 | } | |
508 | else if (dataType == DataTyp e.USHORT | | dataType == DataTy pe.SHORT) | |
509 | { | |
510 | shor t[] pixels = sPix.ge tShortData (true, tru e); | |
511 | int nBitShift = 0 /* red PaletteInf o[2] == 8 ? 0 : 8 */ ; | |
512 | if ( outputBits == 8) | |
513 | { | |
514 | byte[] tmp Pix = new byte[pixel s.length * 3]; | |
515 | for (int i = 0; i < pixels.len gth; i++) | |
516 | { | |
517 | int pi xelValue = pixels[i] & 0xFFFF; // ((pixe ls[i] >> 8 ) & 0xFF) | ((pixels [i] << 8) & 0xFF00); | |
518 | int j = i * 3; | |
519 | tmpPix [j] = (byt e) (redPal etteLUT[pi xelValue] >> nBitShi ft); | |
520 | tmpPix [j + 1] = (byte) (gr eenPalette LUT[pixelV alue] >> n BitShift); | |
521 | tmpPix [j + 2] = (byte) (bl uePaletteL UT[pixelVa lue] >> nB itShift); | |
522 | } | |
523 | ds.insert( new DicomO BElement(D CM.E_PIXEL _DATA, tmp Pix)); | |
524 | ds.insert( new DicomU SElement(D CM.E_BITS_ ALLOCATED, 8)); | |
525 | ds.insert( new DicomU SElement(D CM.E_BITS_ STORED, 8) ); | |
526 | ds.insert( new DicomU SElement(D CM.E_HIGH_ BIT, 7)); | |
527 | } | |
528 | else | |
529 | { | |
530 | short[] tm pPix = new short[pix els.length * 3]; | |
531 | for (int i = 0; i < pixels.len gth; i++) | |
532 | { | |
533 | int pi xelValue = pixels[i] & 0xFFFF; | |
534 | int j = i * 3; | |
535 | tmpPix [j] = (sho rt) redPal etteLUT[pi xelValue]; | |
536 | tmpPix [j + 1] = (short) gr eenPalette LUT[pixelV alue]; | |
537 | tmpPix [j + 2] = (short) bl uePaletteL UT[pixelVa lue]; | |
538 | } | |
539 | ds.insert( new DicomO WElement(D CM.E_PIXEL _DATA, tmp Pix)); | |
540 | } | |
541 | } | |
542 | else | |
543 | { | |
544 | thro w new DCSE xception(" invalid pi xel data t ype(" + da taType + " )"); | |
545 | } | |
546 | ||
547 | // Chang e Photomet ric Interp retation v alue, Samp les Per Pi xel 1 -> 3 , and Plan ar Configu ration | |
548 | ds.inser t(new Dico mCSElement (DCM.E_PHO TOMETRIC_I NTERPRETAT ION, "RGB ")); | |
549 | ds.inser t(new Dico mUSElement (DCM.E_SAM PLES_PER_P IXEL, 3)); | |
550 | ds.inser t(new Dico mUSElement (DCM.E_PLA NAR_CONFIG URATION, 0 )); | |
551 | ds.remov eElement(D CM.E_RED_P ALETTE_COL OR_LUT_DES C); | |
552 | ds.remov eElement(D CM.E_GREEN _PALETTE_C LR_LUT_DES C); | |
553 | ds.remov eElement(D CM.E_BLUE_ PALETTE_CO LOR_LUT_DE SC); | |
554 | ds.remov eElement(D CM.E_RED_P ALETTE_COL OR_LUT_DAT A); | |
555 | ds.remov eElement(D CM.E_GREEN _PALETTE_C LR_LUT_DAT A); | |
556 | ds.remov eElement(D CM.E_BLUE_ PALETTE_CO LOR_LUT_DA TA); | |
557 | ds.remov eElement(D CM.E_PALET TE_COLOR_L UT_UID); | |
558 | } | |
559 | } | |
560 | ||
561 | privat e static L ist<Object > iLuts = new ArrayL ist<Object >(); | |
562 | privat e static L ist<Object > oLuts = new ArrayL ist<Object >(); | |
563 | /** | |
564 | * Con vert one c hannel of a palette color lut to one cha nnel of an 8 or 16 b it RGB lut . | |
565 | * If the palett e color sp ecifies 16 bit values , and outp utBits is 8, we divi de these b y | |
566 | * 256 to provid e an 8bit output val ue. We as sume that the palett e color ch annel has unsigned | |
567 | * pix el values. | |
568 | * @pa ram el the lut data OW element . | |
569 | * @pa ram palett eInfo the array of s ize 3 that constitut es the lut descripto r. | |
570 | * @pa ram output Bits the n umber of o utput bits , 8 or 16 for 16 bit luts, or 8 for 8 bi t luts. | |
571 | * @re turn an in teger lut that maps the palett e to an 8 or 16 bit rgb channe l dependin g on outpu tBits. | |
572 | * @th rows DCSEx ception fo r invalid values or parameters . | |
573 | */ | |
574 | privat e static i nt[] conve rtToLUT(Di comOWEleme nt el, int [] palette Info, int pixelBits, int outpu tBits) thr ows DCSExc eption | |
575 | { | |
576 | if (paletteI nfo.length != 3) | |
577 | throw ne w DCSExcep tion("inva lid length for palet teInfo"); | |
578 | in t nEntries = palette Info[0] == 0 ? 65536 : palette Info[0]; | |
579 | in t firstEnt ry = palet teInfo[1]; | |
580 | in t nBits = paletteInf o[2]; | |
581 | if (nBits != 8 && nBit s != 16) | |
582 | throw ne w DCSExcep tion("inva lid bits a llocated") ; | |
583 | ||
584 | if (outputBi ts > nBits ) { | |
585 | // note that we do not conve rt 8 bit t o 16 bit p ixel value s | |
586 | throw ne w DCSExcep tion("inva lid output bits"); | |
587 | } | |
588 | ||
589 | in t[] lut; | |
590 | ||
591 | if (el.lengt h() == nEn tries) { | |
592 | // bits allocated was 8 | |
593 | byte[] e ntries = e l.getByteD ata(true, true); | |
594 | iLuts.ad d(entries) ; | |
595 | ||
596 | lut = ne w int[256] ; | |
597 | int mask = 0xFF; | |
598 | for (int i = 0; i < lut.leng th; i++) { | |
599 | int tmp; | |
600 | if ( i < firstE ntry) | |
601 | tmp = entr ies[0]; | |
602 | else if (i >= firstEntry + nEntrie s) | |
603 | tmp = entr ies[entrie s.length - 1]; | |
604 | else | |
605 | tmp = entr ies[i - fi rstEntry]; | |
606 | lut[ i] = (tmp & mask); | |
607 | } | |
608 | oLuts.ad d(lut); | |
609 | } | |
610 | el se if (el. length() = = 2 * nEnt ries) | |
611 | { | |
612 | // bits allocated was 16 | |
613 | short[] entries = el.getShor tData(true , false); | |
614 | iLuts.ad d(entries) ; | |
615 | lut = ne w int[6553 6]; | |
616 | int nBit Shift, mas k; | |
617 | // if (pi xelBits > 8 && nBits == 16) | |
618 | // { | |
619 | if ( outputBits == 8) { | |
620 | nBitShift = 8; | |
621 | mask = 0xF F; | |
622 | } | |
623 | else { | |
624 | nBitShift = 0; | |
625 | mask = 0xF FFF; | |
626 | } | |
627 | // } | |
628 | // else { | |
629 | // nB itShift = 0; | |
630 | // ma sk = 0xFF; | |
631 | // } | |
632 | for (int i = 0; i < 65536; i ++) | |
633 | { | |
634 | int tmp; | |
635 | if ( i < firstE ntry) | |
636 | tmp = entr ies[0]; | |
637 | else if (i >= firstEntry + nEntrie s) | |
638 | tmp = entr ies[entrie s.length - 1]; | |
639 | else | |
640 | tmp = entr ies[i - fi rstEntry]; | |
641 | lut[ i] = (tmp >> nBitShi ft) & mask ; | |
642 | } | |
643 | oLuts.ad d(lut); | |
644 | } | |
645 | el se | |
646 | throw ne w DCSExcep tion("inva lid bits a llocated") ; | |
647 | ||
648 | re turn lut; | |
649 | } | |
650 | // end RLE DCF b ug fix | |
651 | ||
652 | // ParseIOD from Dicom StorageSCP Impl morph ed into he re! | |
653 | // Als o allows n ow not for cing metah eader crea tion! | |
654 | public static Da taSetByteR eader getD icomFileRe adableByte Channel(ID icomDataSe t dds, Dic omFileMeta Info metaD ata) throw s DicomExc eption { | |
655 | ||
656 | Da taSetByteR eader dbr = null; | |
657 | Dico mDataSet d ataSet = ( DicomDataS et)dds.get DicomDataS et(); | |
658 | Fi leMetaInfo rmation fi lemeta = n ull; | |
659 | by te metaVer sion[] = n ew byte[2] ; | |
660 | ||
661 | // if metaDa ta is null -- a part 10 file wa s read in -- no need to create filemeta | |
662 | if (metaData != null) { | |
663 | // Set the DICOM version f or the Met aFileInfo. The Meta FileInfo i s the Grou p 0002 inf ormation. | |
664 | // Gro up 0002 mu st be crea ted for th e DataSetB yteReader to process successfu lly. | |
665 | meta Version[0] = 1; | |
666 | meta Version[1] = 0; | |
667 | } | |
668 | ||
669 | tr y{ | |
670 | // if me taData is null -- a part10 fil e was read in -- no need to cr eate filem eta (null) | |
671 | if (meta Data != nu ll) { // a DICOM fee d received -- needs new meta h eader | |
672 | // b uild FileM etaInforma tion objec t. | |
673 | file meta = new FileMetaI nformation (); | |
674 | filemeta.t ransferSyn taxUid(met aData.getT ransfersyn taxUID()); | |
675 | filemeta.f ileMetaInf ormationVe r(metaVers ion); | |
676 | filemeta.i mplementat ionClassUi d(metaData .getImplem entationCl assUID()); | |
677 | filemeta.i mplementat ionVersion Name(metaD ata.getImp lementatio nVersionNa me()); | |
678 | //filemeta .sourceAeT itle(metaD ata.getSou rceAET()); | |
679 | } | |
680 | //Create the DataS etByteRead er object. This set s up using streaming rest | |
681 | // of t he message , which co ntains the pixel dat a. | |
682 | dbr = ne w DataSetB yteReader( | |
683 | data Set, | |
684 | dds. getReceive dTransferS yntax(), | |
685 | true , // creat e part 10 header | |
686 | (fil emeta!=nul l), // inv ent group 2 data | |
687 | file meta, | |
688 | null , | |
689 | new DicomSessi onSettings ()); | |
690 | ||
691 | return d br; | |
692 | } | |
693 | ca tch (DCSEx ception dc sX) | |
694 | { | |
695 | Stri ng message = "Failed to create DataSetBy teReader o bject. "+ dcsX.getMe ssage(); | |
696 | logger.e rror(messa ge); | |
697 | throw ne w DicomExc eption(mes sage, dcsX ); | |
698 | } | |
699 | ca tch (Excep tion e) | |
700 | { | |
701 | Stri ng message = "Failed to create DataSetBy teReader o bject. "+ e.getMessa ge(); | |
702 | logger.e rror(messa ge); | |
703 | throw ne w DicomExc eption(mes sage, e); | |
704 | } | |
705 | } | |
706 | ||
707 | public static In putStream getDicomFi leInputStr eam(Readab leByteChan nel messag e) | |
708 | throws DicomExce ption | |
709 | { | |
710 | tr y | |
711 | { | |
712 | return Channels. newInputSt ream(messa ge); | |
713 | } | |
714 | ca tch (Excep tion e) | |
715 | { | |
716 | logger.e rror("DICO M Correct failed to create a F ileInputSt ream from the Readab leByteChan nel. "+ e. getMessage ()); | |
717 | throw ne w DicomExc eption(); | |
718 | } | |
719 | } | |
720 | } | |
721 |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.