dicomio

package
v0.0.0-...-4353d90 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package dicomio provides utility functions for encoding and decoding low-level DICOM data types, such as integers and strings.

Index

Constants

This section is empty.

Variables

View Source
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.

StandardTransferSyntaxes is the list of standard transfer syntaxes.

Functions

func CanonicalTransferSyntaxUID

func CanonicalTransferSyntaxUID(uid string) (string, error)

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

func NewBytesDecoderWithTransferSyntax(data []byte, transferSyntaxUID string) *Decoder

NewBytesDecoderWithTransferSyntax is similar to NewBytesDecoder, but it takes a transfer syntax UID instead of a <byteorder, IsImplicitVR> pair.

func NewDecoder

func NewDecoder(
	in io.Reader,
	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) BytesRead

func (d *Decoder) BytesRead() int64

BytesRead returns the cumulative # of bytes read so far.

func (*Decoder) EOF

func (d *Decoder) EOF() bool

EOF checks if there is any more data to read.

func (*Decoder) Error

func (d *Decoder) Error() error

Error returns an error encountered so far.

func (*Decoder) Finish

func (d *Decoder) Finish() error

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

func (d *Decoder) PushLimit(bytes int64)

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

func (d *Decoder) PushTransferSyntaxByUID(uid string)

PushTransferSyntaxByUID is similar to PushTransferSyntax, but it takes a transfer syntax UID.

func (*Decoder) Read

func (d *Decoder) Read(p []byte) (int, error)

Read implements the io.Reader interface.

func (*Decoder) ReadByte

func (d *Decoder) ReadByte() (v byte)

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) ReadBytes

func (d *Decoder) ReadBytes(length int) []byte

func (*Decoder) ReadFloat32

func (d *Decoder) ReadFloat32() (v float32)

func (*Decoder) ReadFloat64

func (d *Decoder) ReadFloat64() (v float64)

func (*Decoder) ReadInt16

func (d *Decoder) ReadInt16() (v int16)

func (*Decoder) ReadInt32

func (d *Decoder) ReadInt32() (v int32)

func (*Decoder) ReadString

func (d *Decoder) ReadString(length int) string

func (*Decoder) ReadStringWithCodingSystem

func (d *Decoder) ReadStringWithCodingSystem(csType CodingSystemType, length int) string

func (*Decoder) ReadUInt16

func (d *Decoder) ReadUInt16() (v uint16)

func (*Decoder) ReadUInt32

func (d *Decoder) ReadUInt32() (v uint32)

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

func (d *Decoder) SetError(err error)

SetError sets the error to be reported by future Error() or Finish() calls.

REQUIRES: err != nil

func (*Decoder) SetErrorf

func (d *Decoder) SetErrorf(format string, args ...interface{})

SetErrorf is similar to SetError, but takes a printf format string.

func (*Decoder) Skip

func (d *Decoder) Skip(length int)

Skip advances the read pointer by "length" bytes.

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

func NewBytesEncoderWithTransferSyntax(transferSyntaxUID string) *Encoder

NewBytesEncoderWithTransferSyntax is similar to NewBytesEncoder, but it takes a transfersyntaxuid.

func NewEncoder

func NewEncoder(out io.Writer, bo binary.ByteOrder, implicit IsImplicitVR) *Encoder

NewEncoder creates a new encoder that writes to "out".

func NewEncoderWithTransferSyntax

func NewEncoderWithTransferSyntax(out io.Writer, transferSyntaxUID string) *Encoder

NewEncoderWithTransferSyntax is similar to NewEncoder, but it takes a transfersyntaxuid.

func (*Encoder) Bytes

func (e *Encoder) Bytes() []byte

Bytes returns the encoded data.

REQUIRES: Encoder was created by NewBytesEncoder (not NewEncoder). REQUIRES: e.Error() == nil.

func (*Encoder) Error

func (e *Encoder) Error() 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

func (e *Encoder) SetError(err error)

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) SetErrorf

func (e *Encoder) SetErrorf(format string, args ...interface{})

SetErrorf is similar to SetError, but takes a printf format string.

func (*Encoder) TransferSyntax

func (e *Encoder) TransferSyntax() (binary.ByteOrder, IsImplicitVR)

TransferSyntax returns the current transfer syntax.

func (*Encoder) WriteByte

func (e *Encoder) WriteByte(v byte)

func (*Encoder) WriteBytes

func (e *Encoder) WriteBytes(v []byte)

Copy the given data to the output.

func (*Encoder) WriteFloat32

func (e *Encoder) WriteFloat32(v float32)

func (*Encoder) WriteFloat64

func (e *Encoder) WriteFloat64(v float64)

func (*Encoder) WriteInt16

func (e *Encoder) WriteInt16(v int16)

func (*Encoder) WriteInt32

func (e *Encoder) WriteInt32(v int32)

func (*Encoder) WriteString

func (e *Encoder) WriteString(v string)

WriteString writes the string, withoutout any length prefix or padding.

func (*Encoder) WriteUInt16

func (e *Encoder) WriteUInt16(v uint16)

func (*Encoder) WriteUInt32

func (e *Encoder) WriteUInt32(v uint32)

func (*Encoder) WriteZeros

func (e *Encoder) WriteZeros(len int)

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, 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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL