Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't include tag if not needed #52

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (('vr' in element) || ('length') in 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 {tag: tag};
} 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 {tag: tag};
} 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 (('vr' in element) || ('length') in 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 {tag: tag};
} 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 {tag: tag};
} 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));