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

Feat: allow custom converter from tag ParseSpecificCharacterSet to encoding names to support non-standard variants #292

Conversation

segmedmo
Copy link

This PR is a workaround to bypass error ParseSpecificCharacterSet: Unknown character set when we process dicom files having non-standard value for tag SpecificCharacterSet (specifically ISO_2022_IR_6)

Copy link
Owner

@suyashkumar suyashkumar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR! Had a quick question to learn more.

for _, opt := range opts {
opt(&optSet)
}
return optSet
}

// WithTagSpecificCharacterSetToEncodingNameConverter allows parser to map
// non-standard character sets with standard ones when assessing encoding names
func WithTagSpecificCharacterSetToEncodingNameConverter(handler func(string) string) ParseOption {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: can you tell me more about what kind of issues you're seeing in the wild? For example, is it always the case that the character set just need to be mapped to a "known" character set? Wondering if any of the below options might also be reasonable:

  • Option to try common substitutions (e.g. replace underscores, etc) to try to map to an internal character set before returning an error.
  • If this will always be a direct mapping, should we just take a map? Or will it be the case there might be some more complex logic that requires inspecting the input character set?

Overall though, having a user supplied function to help here could work but just want to understand the realistic space of possibilities. Ultimately allowing folks to register their own charsets could be useful too

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you tell me more about what kind of issues you're seeing in the wild? For example, is it always the case that the character set just need to be mapped to a "known" character set?

Yes, we got error ParseSpecificCharacterSet: Unknown character set and it didn't process the further (I included this in the description so not sure if it didn't make sense or I don't get this question right)

Option to try common substitutions (e.g. replace underscores, etc) to try to map to an internal character set before returning an error.

when I thought about this approach, of adding option to replace spaces with underscores, I also thought variants may come (like instead of _, it'd be - or . ) and we'd need to deal with them (I predicted, we haven't encountered any other cases rather than this value ISO_2022_IR_6 yet). And for ISO_IR 13 or ISO_IR 110 or the like, replacing may not be ideal

If this will always be a direct mapping, should we just take a map? Or will it be the case there might be some more complex logic that requires inspecting the input character set?

this sounds equivalent for our problem, I was just thinking that function is more flexible, such as:

switch charset {
  case x, y, z:
    charset = w
  case a, b, c:
    charset = d
  default:
    charset = something_else
}

Ultimately allowing folks to register their own charsets could be useful too

charset will eventually go through ParseSpecificCharacterSet to be mapped to available encoding names, so I thought an arbitrary set of charsets wouldn't always be mapped to a working encoding name

@segmedmo segmedmo closed this Dec 4, 2023
@segmedmo
Copy link
Author

segmedmo commented Dec 4, 2023

close this pr as we made a fork and we work on that one for better flexibility

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants