dicomio

package
v0.1.1-0...-28a4c4b Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2017 License: MIT Imports: 7 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// See CodingSystem for explanations of these coding-system types.
	AlphabeticCodingSystem = iota
	IdeographicCodingSystem
	PhoneticCodingSystem
)

Variables

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

Standard list of 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
}

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 NewBytesDecoderWithTransferSyntax

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

func NewDecoder

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

func (d *Decoder) 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) Len

func (d *Decoder) Len() int64

Len() returns the number of bytes yet consumed.

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

func (d *Decoder) PushLimit(bytes int64)

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 (d *Decoder) PushTransferSyntaxByUID(uid string)

func (*Decoder) Read

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

io.Reader implementation

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)

Override the default (7bit ASCII) decoder used when converting a byte[] to a string.

func (*Decoder) SetError

func (d *Decoder) SetError(err error)

Set 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{})

func (*Decoder) Skip

func (d *Decoder) Skip(length int)

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 NewBytesEncoderWithTransferSyntax

func NewBytesEncoderWithTransferSyntax(transferSyntaxUID string) *Encoder

func NewEncoder

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

Create a new encoder that writes to "out".

func NewEncoderWithTransferSyntax

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

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 (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

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{})

func (*Encoder) TransferSyntax

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

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

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)

Encode an array of zero bytes.

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

Jump to

Keyboard shortcuts

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