Documentation
¶
Index ¶
- Constants
- Variables
- func DecodePixelData(src []byte, opts PixelDataOptions) ([]byte, error)
- func Encode(src []byte, opts EncodeOptions) ([]byte, error)
- func EncodePixelData(src []byte, desc PixelDataDescriptor, opts EncodePixelDataOptions) ([]byte, error)
- func ReadStream(stream any) ([]byte, error)
- type ColourTransform
- type EncodeOptions
- type EncodePixelDataOptions
- type Format
- type FrameType
- type Image
- type LSInterleaving
- type Params
- type PixelDataDescriptor
- type PixelDataOptions
- type PixelDataVersion
Constants ¶
const ( PhotometricMonochrome1 = "MONOCHROME1" PhotometricMonochrome2 = "MONOCHROME2" PhotometricRGB = "RGB" PhotometricYBRFull = "YBR_FULL" PhotometricYBRFull422 = "YBR_FULL_422" )
PhotometricInterpretation values supported by DecodePixelData (v1).
Variables ¶
var ErrUnsupportedPlatform = native.ErrUnsupportedPlatform
ErrUnsupportedPlatform reports that this GOOS/GOARCH has no prebuilt native library, so JPEG and JPEG-LS data can be neither decoded nor encoded here. Every function in this package returns an error wrapping it rather than panicking, which keeps the module importable everywhere Go builds. Test for it with errors.Is. The README lists the platforms that do have a library.
Functions ¶
func DecodePixelData ¶ added in v1.1.0
func DecodePixelData(src []byte, opts PixelDataOptions) ([]byte, error)
DecodePixelData decodes encapsulated JPEG pixel data for DICOM handlers. Version 1 applies a colour transform from PhotometricInterpretation. Version 2 returns raw decoded bytes with no colour transform.
func Encode ¶ added in v1.2.0
func Encode(src []byte, opts EncodeOptions) ([]byte, error)
Encode compresses interleaved little-endian pixel samples to JPEG / JPEG-LS.
func EncodePixelData ¶ added in v1.2.0
func EncodePixelData(src []byte, desc PixelDataDescriptor, opts EncodePixelDataOptions) ([]byte, error)
EncodePixelData encodes one DICOM frame for JPEG / JPEG-LS transfer syntaxes.
func ReadStream ¶ added in v1.1.0
ReadStream reads JPEG data from bytes, a file path, or an io.Reader. This mirrors pylibjpeg-libjpeg stream handling for decode() and get_parameters().
Types ¶
type ColourTransform ¶ added in v1.1.0
type ColourTransform int
ColourTransform matches libjpeg JPGFLAG_MATRIX_COLORTRANSFORMATION_* values used by pylibjpeg-libjpeg decode().
const ( ColourTransformNone ColourTransform = 0 ColourTransformYCbCr ColourTransform = 1 ColourTransformRCT ColourTransform = 2 ColourTransformFreeform ColourTransform = 3 )
type EncodeOptions ¶ added in v1.2.0
type EncodeOptions struct {
Columns int
Rows int
SamplesPerPixel int
BitsPerSample int
FrameType FrameType
ColourTransform ColourTransform
// Quality applies to lossy JPEG (1–100). Ignored for lossless / JPEG-LS.
Quality int
// ErrorBound is the JPEG-LS NEAR parameter (0 = lossless).
ErrorBound int
// LSInterleaving applies when FrameType is FrameJPEGLS.
LSInterleaving LSInterleaving
}
EncodeOptions configures Encode / EncodePixelData.
type EncodePixelDataOptions ¶ added in v1.2.0
type EncodePixelDataOptions struct {
PhotometricInterpretation string
FrameType FrameType
Quality int
ErrorBound int
LSInterleaving LSInterleaving
}
EncodePixelDataOptions configures EncodePixelData for DICOM handlers.
type Format ¶
type Format int
Format selects a colour transform for DecodeWithFormat. Deprecated: prefer ColourTransform with DecodeImage.
type FrameType ¶ added in v1.2.0
type FrameType int
FrameType selects the JPEG encoding process (libjpeg JPGFLAG_* frame types).
const ( FrameBaseline FrameType = native.FrameBaseline FrameSequential FrameType = native.FrameSequential FrameLossless FrameType = native.FrameLossless FrameJPEGLS FrameType = native.FrameJPEGLS )
type Image ¶
Image holds decoded pixel data in native precision (8- or 16-bit), planar-interleaved.
func DecodeImage ¶ added in v1.1.0
func DecodeImage(stream any, colourTransform ColourTransform) (*Image, error)
DecodeImage decodes JPEG/JPEG-LS/JPEG XT data from stream. colourTransform matches pylibjpeg-libjpeg decode(colour_transform=...).
func DecodeWithFormat ¶
DecodeWithFormat decodes using a legacy Format colour-transform selector.
func (*Image) BytesPerSample ¶ added in v1.1.0
func (*Image) CornerSamples ¶ added in v1.1.0
CornerSamples returns top-left and bottom-right samples as integers. For multi-byte precision each component is truncated to the low byte for 8-bit cases.
type LSInterleaving ¶ added in v1.2.0
type LSInterleaving int
LSInterleaving configures JPEG-LS component interleaving.
const ( LSInterleaveNone LSInterleaving = native.LSInterleaveNone LSInterleaveLine LSInterleaving = native.LSInterleaveLine LSInterleaveSample LSInterleaving = native.LSInterleaveSample )
type Params ¶
Params holds JPEG image parameters without decoding pixels.
func GetImageParameters ¶ added in v1.1.0
GetImageParameters reads JPEG parameters without decoding pixels.
func GetParameters ¶
GetParameters is an alias for GetImageParameters using a byte buffer.
func (*Params) NrComponents ¶ added in v1.1.0
type PixelDataDescriptor ¶ added in v1.2.0
type PixelDataDescriptor struct {
Columns int
Rows int
SamplesPerPixel int
BitsAllocated int
BitsStored int
}
PixelDataDescriptor holds image geometry for EncodePixelData.
type PixelDataOptions ¶ added in v1.1.0
type PixelDataOptions struct {
Version PixelDataVersion
PhotometricInterpretation string
}
PixelDataOptions configures DecodePixelData (pylibjpeg decode_pixel_data).
type PixelDataVersion ¶ added in v1.1.0
type PixelDataVersion int
PixelDataVersion selects decode_pixel_data behaviour.
const ( PixelDataV1 PixelDataVersion = 1 PixelDataV2 PixelDataVersion = 2 )