Documentation ¶
Index ¶
- Constants
- Variables
- func CanonicalTransferSyntaxUID(uid string) (string, error)
- type CodingSystem
- type CodingSystemType
- type Decoder
- 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) 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 (d *Encoder) PopTransferSyntax()
- func (d *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 ¶
const ( // See CodingSystem for explanations of these coding-system types. AlphabeticCodingSystem = iota IdeographicCodingSystem PhoneticCodingSystem )
Variables ¶
var NativeByteOrder = binary.LittleEndian
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 }
Defines how a []byte is translated into a utf8 string.
func ParseSpecificCharacterSet ¶
func ParseSpecificCharacterSet(encodingNames []string) (CodingSystem, error)
Convert 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
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
func NewBytesDecoder ¶
func NewBytesDecoder(data []byte, bo binary.ByteOrder, implicit IsImplicitVR) *Decoder
Create a decoder that reads from a sequence of bytes. See NewDecoder() for explanation of other parameters.
func NewDecoder ¶
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()
Restore the old limit overridden by PushLimit.
func (*Decoder) PopTransferSyntax ¶
func (d *Decoder) PopTransferSyntax()
Restore the encoding format active before the last call to PushTransferSyntax().
func (*Decoder) PushLimit ¶
Temporarily override the end of the buffer. PopLimit() will restore the old limit.
REQUIRES: limit must be smaller than the current limit
func (*Decoder) PushTransferSyntax ¶
func (d *Decoder) PushTransferSyntax(bo binary.ByteOrder, implicit IsImplicitVR)
Temporarily change the encoding format. PopTrasnferSyntax() will restore the old format.
func (*Decoder) PushTransferSyntaxByUID ¶
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)
Override the default (7bit ASCII) decoder used when converting a byte[] to a string.
func (*Decoder) SetError ¶
Set 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)
Get the current transfer syntax.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
func NewBytesEncoder ¶
func NewBytesEncoder(bo binary.ByteOrder, implicit IsImplicitVR) *Encoder
Create a new Encoder that writes to an in-memory buffer. The contents can be obtained via Bytes() method.
func NewEncoder ¶
Create a new encoder that writes to "out".
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 (d *Encoder) PopTransferSyntax()
Restore the encoding format active before the last call to PushTransferSyntax().
func (*Encoder) PushTransferSyntax ¶
func (d *Encoder) PushTransferSyntax(bo binary.ByteOrder, implicit IsImplicitVR)
Temporarily change 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)
Get 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 ¶
func (*Encoder) WriteUInt16 ¶
func (*Encoder) WriteUInt32 ¶
type IsImplicitVR ¶
type IsImplicitVR int
const ( // With ImplicitVR, the VR is not encoded w/ a data element. Instead, // 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, err error)
Given a transfer syntax uid, return its encoding. 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).