Documentation ¶
Overview ¶
Package dicomio provides utility functions for encoding and decoding low-level DICOM data types, such as integers and strings.
Index ¶
- Variables
- func CanonicalTransferSyntaxUID(uid string) (string, error)
- type CodingSystem
- type CodingSystemType
- type Decoder
- func (d *Decoder) ClearError()
- func (d *Decoder) Error() error
- func (d *Decoder) Finish() error
- func (d *Decoder) Len() int64
- func (d *Decoder) PopLimit()
- func (d *Decoder) PopTransferSyntax()
- func (d *Decoder) PushLimit(bytes int64)
- func (d *Decoder) PushTransferSyntax(bo binary.ByteOrder, implicit IsImplicitVR)
- func (d *Decoder) PushTransferSyntaxByUID(uid string)
- func (d *Decoder) Read(p []byte) (int, error)
- func (d *Decoder) ReadByte() (v byte)
- func (d *Decoder) ReadBytes(length int) []byte
- func (d *Decoder) ReadFloat32() (v float32)
- func (d *Decoder) ReadFloat64() (v float64)
- func (d *Decoder) ReadInt16() (v int16)
- func (d *Decoder) ReadInt32() (v int32)
- func (d *Decoder) ReadString(length int) string
- func (d *Decoder) ReadStringWithCodingSystem(csType CodingSystemType, length int) string
- func (d *Decoder) ReadUInt16() (v uint16)
- func (d *Decoder) ReadUInt32() (v uint32)
- func (d *Decoder) Seek(offset int64) (err error)
- func (d *Decoder) SetCodingSystem(cs CodingSystem)
- func (d *Decoder) SetError(err error)
- func (d *Decoder) SetErrorf(format string, args ...interface{})
- func (d *Decoder) Skip(length int)
- func (d *Decoder) TransferSyntax() (bo binary.ByteOrder, implicit IsImplicitVR)
- type Encoder
- func NewBytesEncoder(bo binary.ByteOrder, implicit IsImplicitVR) *Encoder
- func NewBytesEncoderWithTransferSyntax(transferSyntaxUID string) *Encoder
- func NewEncoder(out io.Writer, bo binary.ByteOrder, implicit IsImplicitVR) *Encoder
- func NewEncoderWithTransferSyntax(out io.Writer, transferSyntaxUID string) *Encoder
- func (e *Encoder) Bytes() []byte
- func (e *Encoder) Error() error
- func (e *Encoder) PopTransferSyntax()
- func (e *Encoder) PushTransferSyntax(bo binary.ByteOrder, implicit IsImplicitVR)
- func (e *Encoder) SetError(err error)
- func (e *Encoder) SetErrorf(format string, args ...interface{})
- func (e *Encoder) TransferSyntax() (binary.ByteOrder, IsImplicitVR)
- func (e *Encoder) WriteByte(v byte)
- func (e *Encoder) WriteBytes(v []byte)
- func (e *Encoder) WriteFloat32(v float32)
- func (e *Encoder) WriteFloat64(v float64)
- func (e *Encoder) WriteInt16(v int16)
- func (e *Encoder) WriteInt32(v int32)
- func (e *Encoder) WriteString(v string)
- func (e *Encoder) WriteUInt16(v uint16)
- func (e *Encoder) WriteUInt32(v uint32)
- func (e *Encoder) WriteZeros(len int)
- type IsImplicitVR
Constants ¶
This section is empty.
Variables ¶
var NativeByteOrder = binary.LittleEndian
NativeByteOrder is the byte order of this machine.
TODO(saito) Auto-detect the native byte order. For now, to assume that every machine in the world is little endian is not too horrible.
var StandardTransferSyntaxes = []string{ dicomuid.ImplicitVRLittleEndian, dicomuid.ExplicitVRLittleEndian, dicomuid.ExplicitVRBigEndian, dicomuid.DeflatedExplicitVRLittleEndian, }
Standard list of transfer syntaxes.
Functions ¶
func CanonicalTransferSyntaxUID ¶
CanonicalTransferSyntaxUID return the canonical transfer syntax UID (e.g., dicomuid.ExplicitVRLittleEndian or dicomuid.ImplicitVRLittleEndian), given an UID that represents any transfer syntax. Returns an error if the uid is not defined in DICOM standard, or if the uid does not represent a transfer syntax.
TODO(saito) Check the standard to see if we need to accept unknown UIDS as explicit little endian.
Types ¶
type CodingSystem ¶
type CodingSystem struct { // VR="PN" is the only place where we potentially use all three // decoders. For all other VR types, only Ideographic decoder is used. // See P3.5, 6.2. // // P3.5 6.1 is supposed to define the coding systems in detail. But the // spec text is insanely obtuse and I couldn't tell what its meaning // after hours of trying. So I just copied what pydicom charset.py is // doing. Alphabetic *encoding.Decoder Ideographic *encoding.Decoder Phonetic *encoding.Decoder }
CodingSystem defines how a []byte is translated into a utf8 string.
func ParseSpecificCharacterSet ¶
func ParseSpecificCharacterSet(encodingNames []string) (CodingSystem, error)
ParseSpecificCharacterSet converts DICOM character encoding names, such as "ISO-IR 100" to golang decoder. It will return nil, nil for the default (7bit ASCII) encoding. Cf. P3.2 D.6.2. http://dicom.nema.org/medical/dicom/2016d/output/chtml/part02/sect_D.6.2.html
type CodingSystemType ¶
type CodingSystemType int
CodingSystemType defines the where the coding system is going to be used. This distinction is useful in Japanese, but of little use in other languages.
const ( // AlphabeticCodingSystem is for writing a name in (English) alphabets. AlphabeticCodingSystem CodingSystemType = iota // IdeographicCodingSystem is for writing the name in the native writing // system (Kanji). IdeographicCodingSystem // PhoneticCodingSystem is for hirakana and/or katakana. PhoneticCodingSystem )
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder is a helper class for decoder low-level DICOM data types.
func NewBytesDecoder ¶
func NewBytesDecoder(data []byte, bo binary.ByteOrder, implicit IsImplicitVR) *Decoder
NewBytesDecoder creates a decoder that reads from a sequence of bytes. See NewDecoder() for explanation of other parameters.
func NewBytesDecoderWithTransferSyntax ¶
NewBytesDecoderWithTransferSyntax is similar to NewBytesDecoder, but it takes a transfer syntax UID instead of a <byteorder, IsImplicitVR> pair.
func NewDecoder ¶
func NewDecoder( in io.ReadSeeker, limit int64, bo binary.ByteOrder, implicit IsImplicitVR) *Decoder
NewDecoder creates a decoder object that reads up to "limit" bytes from "in". Don't pass just an arbitrary large number as the "limit". The underlying code assumes that "limit" accurately bounds the end of the data.
func (*Decoder) Finish ¶
Finish must be called after using the decoder. It returns any error encountered during decoding. It also returns an error if some data is left unconsumed.
func (*Decoder) PopLimit ¶
func (d *Decoder) PopLimit()
PopLimit restores the old limit overridden by PushLimit.
func (*Decoder) PopTransferSyntax ¶
func (d *Decoder) PopTransferSyntax()
PopTransferSyntax restores the encoding format active before the last call to PushTransferSyntax().
func (*Decoder) PushLimit ¶
PushLimit temporarily overrides the end of the buffer and clears d.err. PopLimit() will restore the old limit and error.
REQUIRES: limit must be smaller than the current limit
func (*Decoder) PushTransferSyntax ¶
func (d *Decoder) PushTransferSyntax(bo binary.ByteOrder, implicit IsImplicitVR)
PushTransferSyntax temporarily changes the encoding format. PopTrasnferSyntax() will restore the old format.
func (*Decoder) PushTransferSyntaxByUID ¶
PushTransferSyntaxByUID is similar to PushTransferSyntax, but it takes a transfer syntax UID.
func (*Decoder) ReadByte ¶
ReadByte reads a single byte from the buffer. On EOF, it returns a junk value, and sets an error to be returned by Error() or Finish().
func (*Decoder) ReadFloat32 ¶
func (*Decoder) ReadFloat64 ¶
func (*Decoder) ReadString ¶
func (*Decoder) ReadStringWithCodingSystem ¶
func (d *Decoder) ReadStringWithCodingSystem(csType CodingSystemType, length int) string
func (*Decoder) ReadUInt16 ¶
func (*Decoder) ReadUInt32 ¶
func (*Decoder) SetCodingSystem ¶
func (d *Decoder) SetCodingSystem(cs CodingSystem)
SetCodingSystem overrides the default (7bit ASCII) decoder used when converting a byte[] to a string.
func (*Decoder) SetError ¶
SetError sets the error to be reported by future Error() or Finish() calls.
REQUIRES: err != nil
func (*Decoder) TransferSyntax ¶
func (d *Decoder) TransferSyntax() (bo binary.ByteOrder, implicit IsImplicitVR)
TransferSyntax returns the current transfer syntax.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder is a helper class for encoding low-level DICOM data types.
func NewBytesEncoder ¶
func NewBytesEncoder(bo binary.ByteOrder, implicit IsImplicitVR) *Encoder
NewBytesEncoder creates a new Encoder that writes to an in-memory buffer. The contents can be obtained via Bytes() method.
func NewBytesEncoderWithTransferSyntax ¶
NewBytesEncoderWithTransferSyntax is similar to NewBytesEncoder, but it takes a transfersyntaxuid.
func NewEncoder ¶
Create a new encoder that writes to "out".
func NewEncoderWithTransferSyntax ¶
NewEncoderWithTransferSyntax is similar to NewEncoder, but it takes a transfersyntaxuid.
func (*Encoder) Bytes ¶
Bytes returns the encoded data.
REQUIRES: Encoder was created by NewBytesEncoder (not NewEncoder). REQUIRES: e.Error() == nil.
func (*Encoder) Error ¶
Error returns an error set by SetError(), if any. Returns nil if SetError() has never been called.
func (*Encoder) PopTransferSyntax ¶
func (e *Encoder) PopTransferSyntax()
PopTransferSyntax restores the encoding format active before the last call to PushTransferSyntax().
func (*Encoder) PushTransferSyntax ¶
func (e *Encoder) PushTransferSyntax(bo binary.ByteOrder, implicit IsImplicitVR)
PushTransferSyntax temporarily changes the encoding format. PopTrasnferSyntax() will restore the old format.
func (*Encoder) SetError ¶
SetError sets the error to be reported by future Error() calls. If called multiple times with different errors, Error() will return one of them, but exactly which is unspecified.
REQUIRES: err != nil
func (*Encoder) TransferSyntax ¶
func (e *Encoder) TransferSyntax() (binary.ByteOrder, IsImplicitVR)
TransferSyntax returns the current transfer syntax.
func (*Encoder) WriteBytes ¶
Copy the given data to the output.
func (*Encoder) WriteFloat32 ¶
func (*Encoder) WriteFloat64 ¶
func (*Encoder) WriteInt16 ¶
func (*Encoder) WriteInt32 ¶
func (*Encoder) WriteString ¶
WriteString writes the string, withoutout any length prefix or padding.
func (*Encoder) WriteUInt16 ¶
func (*Encoder) WriteUInt32 ¶
func (*Encoder) WriteZeros ¶
WriteZeros encodes an array of zero bytes.
type IsImplicitVR ¶
type IsImplicitVR int
IsImplicitVR defines whether a 2-character VR tag is emit with each data element.
const ( // ImplicitVR encodes a data element without a VR tag. The reader // consults the static tag->VR mapping (see tags.go) defined by DICOM // standard. ImplicitVR IsImplicitVR = iota // ExplicitVR stores the 2-byte VR value inline w/ a data element. ExplicitVR // UnknownVR is to be used when you never encode or decode DataElement. UnknownVR )
func ParseTransferSyntaxUID ¶
func ParseTransferSyntaxUID(uid string) (bo binary.ByteOrder, implicit IsImplicitVR, deflated bool, err error)
ParseTransferSyntaxUID parses a transfer syntax uid and returns its byteorder and implicitVR/explicitVR type. TrasnferSyntaxUID can be any UID that refers to a transfer syntax. It can be, e.g., 1.2.840.10008.1.2 (it will return LittleEndian, ImplicitVR) or 1.2.840.10008.1.2.4.54 (it will return (LittleEndian, ExplicitVR).