Skip to content

Commit

Permalink
untilTag no include
Browse files Browse the repository at this point in the history
  • Loading branch information
Djeisen642 committed Jul 16, 2016
1 parent db3d74c commit b9f6fea
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 25 deletions.
71 changes: 60 additions & 11 deletions dist/dicomParser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! dicom-parser - v1.7.2 - 2016-06-29 | (c) 2014 Chris Hafey | https://github.com/chafey/dicomParser */
/*! dicom-parser - v1.7.2 - 2016-07-16 | (c) 2014 Chris Hafey | https://github.com/chafey/dicomParser */
(function (root, factory) {

// node.js
Expand Down Expand Up @@ -1752,9 +1752,20 @@ var dicomParser = (function (dicomParser)
while(byteStream.position < maxPosition)
{
var element = dicomParser.readDicomElementExplicit(byteStream, dataSet.warnings, options.untilTag);
elements[element.tag] = element;
if(element.tag === options.untilTag) {
return;
if (element) {
elements[element.tag] = element;
}
switch (typeof options.untilTag) {
case 'string':
if (element.tag === options.untilTag) {
return;
}
break;
case 'object':
if ('tag' in options.untilTag && element.tag === options.untilTag.tag) {
return;
}
break;
}
}
if(byteStream.position > maxPosition) {
Expand Down Expand Up @@ -1786,9 +1797,21 @@ var dicomParser = (function (dicomParser)
while(byteStream.position < maxPosition)
{
var element = dicomParser.readDicomElementImplicit(byteStream, options.untilTag, options.vrCallback);
elements[element.tag] = element;
if(element.tag === options.untilTag) {
return;
if (element) {
elements[element.tag] = element;
}

switch (typeof options.untilTag) {
case 'string':
if (element.tag === options.untilTag) {
return;
}
break;
case 'object':
if ('tag' in options.untilTag && element.tag === options.untilTag.tag) {
return;
}
break;
}
}
};
Expand Down Expand Up @@ -1833,8 +1856,20 @@ var dicomParser = (function (dicomParser)
throw "dicomParser.readDicomElementExplicit: missing required parameter 'byteStream'";
}

var tag = dicomParser.readTag(byteStream);
var isUntilTag = false;
if (typeof untilTag === 'object' && tag === untilTag.tag) {
if (untilTag.include === false) {
return false;
} else {
isUntilTag = true;
}
} else if (typeof untilTag === 'string' && tag === untilTag) {
isUntilTag = true;
}

var element = {
tag : dicomParser.readTag(byteStream),
tag : tag,
vr : byteStream.readFixedString(2)
// length set below based on VR
// dataOffset set below based on VR and size of length
Expand All @@ -1858,7 +1893,7 @@ var dicomParser = (function (dicomParser)
element.hadUndefinedLength = true;
}

if(element.tag === untilTag) {
if(isUntilTag) {
return element;
}

Expand All @@ -1885,6 +1920,7 @@ var dicomParser = (function (dicomParser)

return dicomParser;
}(dicomParser));

/**
* Internal helper functions for for parsing DICOM elements
*/
Expand Down Expand Up @@ -1923,8 +1959,20 @@ var dicomParser = (function (dicomParser)
throw "dicomParser.readDicomElementImplicit: missing required parameter 'byteStream'";
}

var tag = dicomParser.readTag(byteStream);
var isUntilTag = false;
if (typeof untilTag === 'object' && tag === untilTag.tag) {
if (untilTag.include === false) {
return false;
} else {
isUntilTag = true;
}
} else if (typeof untilTag === 'string' && tag === untilTag) {
isUntilTag = true;
}

var element = {
tag : dicomParser.readTag(byteStream),
tag : tag,
length: byteStream.readUint32(),
dataOffset : byteStream.position
};
Expand All @@ -1933,7 +1981,7 @@ var dicomParser = (function (dicomParser)
element.hadUndefinedLength = true;
}

if(element.tag === untilTag) {
if(isUntilTag) {
return element;
}

Expand All @@ -1959,6 +2007,7 @@ var dicomParser = (function (dicomParser)

return dicomParser;
}(dicomParser));

/**
* Functionality for extracting encapsulated pixel data
*/
Expand Down
4 changes: 2 additions & 2 deletions dist/dicomParser.min.js

Large diffs are not rendered by default.

35 changes: 29 additions & 6 deletions src/parseDicomDataSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,20 @@ var dicomParser = (function (dicomParser)
while(byteStream.position < maxPosition)
{
var element = dicomParser.readDicomElementExplicit(byteStream, dataSet.warnings, options.untilTag);
elements[element.tag] = element;
if(element.tag === options.untilTag) {
return;
if (element) {
elements[element.tag] = element;
}
switch (typeof options.untilTag) {
case 'string':
if (element.tag === options.untilTag) {
return;
}
break;
case 'object':
if ('tag' in options.untilTag && element.tag === options.untilTag.tag) {
return;
}
break;
}
}
if(byteStream.position > maxPosition) {
Expand Down Expand Up @@ -68,9 +79,21 @@ var dicomParser = (function (dicomParser)
while(byteStream.position < maxPosition)
{
var element = dicomParser.readDicomElementImplicit(byteStream, options.untilTag, options.vrCallback);
elements[element.tag] = element;
if(element.tag === options.untilTag) {
return;
if (element) {
elements[element.tag] = element;
}

switch (typeof options.untilTag) {
case 'string':
if (element.tag === options.untilTag) {
return;
}
break;
case 'object':
if ('tag' in options.untilTag && element.tag === options.untilTag.tag) {
return;
}
break;
}
}
};
Expand Down
18 changes: 15 additions & 3 deletions src/readDicomElementExplicit.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,20 @@ var dicomParser = (function (dicomParser)
throw "dicomParser.readDicomElementExplicit: missing required parameter 'byteStream'";
}

var tag = dicomParser.readTag(byteStream);
var isUntilTag = false;
if (typeof untilTag === 'object' && tag === untilTag.tag) {
if (untilTag.include === false) {
return false;
} else {
isUntilTag = true;
}
} else if (typeof untilTag === 'string' && tag === untilTag) {
isUntilTag = true;
}

var element = {
tag : dicomParser.readTag(byteStream),
tag : tag,
vr : byteStream.readFixedString(2)
// length set below based on VR
// dataOffset set below based on VR and size of length
Expand All @@ -60,7 +72,7 @@ var dicomParser = (function (dicomParser)
element.hadUndefinedLength = true;
}

if(element.tag === untilTag) {
if(isUntilTag) {
return element;
}

Expand All @@ -86,4 +98,4 @@ var dicomParser = (function (dicomParser)
};

return dicomParser;
}(dicomParser));
}(dicomParser));
18 changes: 15 additions & 3 deletions src/readDicomElementImplicit.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,20 @@ var dicomParser = (function (dicomParser)
throw "dicomParser.readDicomElementImplicit: missing required parameter 'byteStream'";
}

var tag = dicomParser.readTag(byteStream);
var isUntilTag = false;
if (typeof untilTag === 'object' && tag === untilTag.tag) {
if (untilTag.include === false) {
return false;
} else {
isUntilTag = true;
}
} else if (typeof untilTag === 'string' && tag === untilTag) {
isUntilTag = true;
}

var element = {
tag : dicomParser.readTag(byteStream),
tag : tag,
length: byteStream.readUint32(),
dataOffset : byteStream.position
};
Expand All @@ -46,7 +58,7 @@ var dicomParser = (function (dicomParser)
element.hadUndefinedLength = true;
}

if(element.tag === untilTag) {
if(isUntilTag) {
return element;
}

Expand All @@ -71,4 +83,4 @@ var dicomParser = (function (dicomParser)


return dicomParser;
}(dicomParser));
}(dicomParser));

0 comments on commit b9f6fea

Please sign in to comment.