Documentation
¶
Overview ¶
Package codec implements RDP bitmap decompression algorithms including interleaved RLE, planar, and NSCodec as specified in MS-RDPBCGR and MS-RDPNSC.
Package nscodec implements the NSCodec bitmap codec decoder as specified in MS-RDPNSC. NSCodec compresses 24/32 bpp images using AYCoCg color space conversion and RLE compression.
Package codec implements RLE decompression for RDP bitmap data. This implements the Interleaved RLE algorithm as specified in MS-RDPBCGR section 2.2.9.1.1.3.1.2.4.
Index ¶
- Constants
- Variables
- func AYCoCgToRGBA(luma, co, cg, alpha []byte, planeWidth, planeHeight, imgWidth, imgHeight int) []byte
- func BGR24ToRGBA(src []byte, dst []byte)
- func BGRA32ToRGBA(src []byte, dst []byte)
- func ChromaSuperSample(plane []byte, srcWidth, srcHeight, dstWidth, dstHeight int) []byte
- func Decode(data []byte, width, height int) ([]byte, error)
- func DecodeNSCodecToRGBA(data []byte, width, height int) []byte
- func DecompressPlanar(src []byte, width, height int) []byte
- func Encode(s string) []byte
- func ExtractCodeID(bOrderHdr byte) uint
- func ExtractRunLength(code uint, src []byte, idx int) (length int, nextIdx int)
- func FlipVertical(data []byte, width, height, bytesPerPixel int)
- func IsLiteCode(code uint) bool
- func IsMegaMegaCode(code uint) bool
- func IsRegularCode(code uint) bool
- func NSCodecRLEDecompress(data []byte, expectedSize int) []byte
- func Palette8ToRGBA(src []byte, dst []byte)
- func ProcessBitmap(src []byte, width, height, bpp int, isCompressed bool, rowDelta int, ...) []byte
- func RGB555ToRGBA(src []byte, dst []byte)
- func RGB565ToRGBA(src []byte, dst []byte)
- func RLEDecompress[T uint8 | uint16 | uint32](pf PixelFormat[T], src []byte, dest []byte, rowDelta int) bool
- func RLEDecompress8(src []byte, dest []byte, rowDelta int) bool
- func RLEDecompress15(src []byte, dest []byte, rowDelta int) bool
- func RLEDecompress16(src []byte, dest []byte, rowDelta int) bool
- func RLEDecompress24(src []byte, dest []byte, rowDelta int) bool
- func RLEDecompress32(src []byte, dest []byte, rowDelta int) bool
- func ReadPixel15(data []byte, idx int) uint16
- func ReadPixel16(data []byte, idx int) uint16
- func ReadPixel24(data []byte, idx int) uint32
- func ReadPixel32(data []byte, idx int) uint32
- func RestoreColorLoss(plane []byte, colorLossLevel uint8) []byte
- func SetPalette(data []byte, numColors int)
- func UnwrapSecurityFlag(wire io.Reader) (uint16, error)
- func WrapSecurityFlag(flag uint16, data []byte) []byte
- func WriteFgBgImage8(dest []byte, destIdx int, rowDelta int, bitmask byte, fgPel byte, cBits int, ...) int
- func WriteFgBgImage15(dest []byte, destIdx int, rowDelta int, bitmask byte, fgPel uint16, cBits int, ...) int
- func WriteFgBgImage16(dest []byte, destIdx int, rowDelta int, bitmask byte, fgPel uint16, cBits int, ...) int
- func WriteFgBgImage24(dest []byte, destIdx int, rowDelta int, bitmask byte, fgPel uint32, cBits int, ...) int
- func WriteFgBgImage32(dest []byte, destIdx int, rowDelta int, bitmask byte, fgPel uint32, cBits int, ...) int
- func WritePixel15(data []byte, idx int, pixel uint16)
- func WritePixel16(data []byte, idx int, pixel uint16)
- func WritePixel24(data []byte, idx int, pixel uint32)
- func WritePixel32(data []byte, idx int, pixel uint32)
- type BitmapStream
- type PixelFormat
Constants ¶
const ( // Format header flags PlanarFlagRLE = 0x10 // Run Length Encoding PlanarFlagNoAlpha = 0x20 // No Alpha plane )
const ( RegularBgRun = 0x0 RegularFgRun = 0x1 RegularFgBgImage = 0x2 RegularColorRun = 0x3 RegularColorImage = 0x4 MegaMegaBgRun = 0xF0 MegaMegaFgRun = 0xF1 MegaMegaFgBgImage = 0xF2 MegaMegaColorRun = 0xF3 MegaMegaColorImage = 0xF4 MegaMegaSetFgRun = 0xF6 MegaMegaSetFgBgImage = 0xF7 MegaMegaDitheredRun = 0xF8 LiteSetFgFgRun = 0xC LiteSetFgFgBgImage = 0xD LiteDitheredRun = 0xE SpecialFgBg1 = 0xF9 SpecialFgBg2 = 0xFA White = 0xFD Black = 0xFE )
RLE compression order codes
Variables ¶
var ( ErrInvalidStream = errors.New("nscodec: invalid bitmap stream") ErrInvalidPlaneSize = errors.New("nscodec: invalid plane size") ErrInvalidColorLoss = errors.New("nscodec: invalid color loss level") ErrDecompressionFail = errors.New("nscodec: RLE decompression failed") )
var FgBgBitmasks = []byte{0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}
FgBgBitmasks contains bit masks used for foreground/background image orders.
var NSCodecGUID = [16]byte{
0xB9, 0x1B, 0x8D, 0xCA, 0x0F, 0x00, 0x4F, 0x15,
0x58, 0x9F, 0xAE, 0x2D, 0x1A, 0x87, 0xE2, 0xD6,
}
NSCodec GUID: CA8D1BB9-000F-154F-589F-AE2D1A87E2D6
var Pixel15 = PixelFormat[uint16]{ BytesPerPixel: 2, WhitePixel: 0x7FFF, BlackPixel: 0x0000, ReadPixel: func(data []byte, idx int) uint16 { if idx+1 >= len(data) { return 0 } return uint16(data[idx]) | (uint16(data[idx+1]) << 8) }, WritePixel: func(data []byte, idx int, pixel uint16) { if idx+1 >= len(data) { return } data[idx] = byte(pixel & 0xFF) data[idx+1] = byte((pixel >> 8) & 0xFF) }, }
Pixel15 defines the 15-bit pixel format (2 bytes per pixel, RGB555).
var Pixel16 = PixelFormat[uint16]{ BytesPerPixel: 2, WhitePixel: 0xFFFF, BlackPixel: 0x0000, ReadPixel: func(data []byte, idx int) uint16 { if idx+1 >= len(data) { return 0 } return uint16(data[idx]) | (uint16(data[idx+1]) << 8) }, WritePixel: func(data []byte, idx int, pixel uint16) { if idx+1 >= len(data) { return } data[idx] = byte(pixel & 0xFF) data[idx+1] = byte((pixel >> 8) & 0xFF) }, }
Pixel16 defines the 16-bit pixel format (2 bytes per pixel, RGB565).
var Pixel24 = PixelFormat[uint32]{ BytesPerPixel: 3, WhitePixel: 0xFFFFFF, BlackPixel: 0x000000, ReadPixel: func(data []byte, idx int) uint32 { if idx+2 >= len(data) { return 0 } return uint32(data[idx]) | (uint32(data[idx+1]) << 8) | (uint32(data[idx+2]) << 16) }, WritePixel: func(data []byte, idx int, pixel uint32) { if idx+2 >= len(data) { return } data[idx] = byte(pixel & 0xFF) data[idx+1] = byte((pixel >> 8) & 0xFF) data[idx+2] = byte((pixel >> 16) & 0xFF) }, }
Pixel24 defines the 24-bit pixel format (3 bytes per pixel, RGB888).
var Pixel32 = PixelFormat[uint32]{ BytesPerPixel: 4, WhitePixel: 0xFFFFFFFF, BlackPixel: 0x00000000, ReadPixel: func(data []byte, idx int) uint32 { if idx+3 >= len(data) { return 0 } return uint32(data[idx]) | (uint32(data[idx+1]) << 8) | (uint32(data[idx+2]) << 16) | (uint32(data[idx+3]) << 24) }, WritePixel: func(data []byte, idx int, pixel uint32) { if idx+3 >= len(data) { return } data[idx] = byte(pixel & 0xFF) data[idx+1] = byte((pixel >> 8) & 0xFF) data[idx+2] = byte((pixel >> 16) & 0xFF) data[idx+3] = byte((pixel >> 24) & 0xFF) }, }
Pixel32 defines the 32-bit pixel format (4 bytes per pixel, RGBA8888).
var Pixel8 = PixelFormat[uint8]{ BytesPerPixel: 1, WhitePixel: 0xFF, BlackPixel: 0x00, ReadPixel: func(data []byte, idx int) uint8 { if idx >= len(data) { return 0 } return data[idx] }, WritePixel: func(data []byte, idx int, pixel uint8) { if idx >= len(data) { return } data[idx] = pixel }, }
Pixel8 defines the 8-bit pixel format (1 byte per pixel).
Functions ¶
func AYCoCgToRGBA ¶
func AYCoCgToRGBA(luma, co, cg, alpha []byte, planeWidth, planeHeight, imgWidth, imgHeight int) []byte
AYCoCgToRGBA converts AYCoCg color space to RGBA
func BGR24ToRGBA ¶
BGR24ToRGBA converts 24-bit BGR to 32-bit RGBA
func BGRA32ToRGBA ¶
BGRA32ToRGBA converts 32-bit BGRA to 32-bit RGBA
func ChromaSuperSample ¶
ChromaSuperSample upsamples chroma planes from subsampled to full resolution
func Decode ¶
Decode decodes an NSCodec bitmap stream to RGBA pixels. Width and height specify the image dimensions. Returns RGBA pixel data (4 bytes per pixel).
func DecodeNSCodecToRGBA ¶
DecodeNSCodecToRGBA decodes an NSCodec bitmap stream to RGBA pixels
func DecompressPlanar ¶
DecompressPlanar decompresses RDP6 Planar codec data to RGBA
func ExtractCodeID ¶
ExtractCodeID extracts the order code from a header byte
func ExtractRunLength ¶
ExtractRunLength extracts the run length from the source buffer at the given index
func FlipVertical ¶
FlipVertical flips bitmap data vertically (in-place). RDP sends bitmaps bottom-up, this flips them to top-down.
func IsLiteCode ¶
IsLiteCode returns true if the code is a lite order code
func IsMegaMegaCode ¶
IsMegaMegaCode returns true if the code is a mega-mega order code
func IsRegularCode ¶
IsRegularCode returns true if the code is a regular order code
func NSCodecRLEDecompress ¶
NSCodecRLEDecompress decompresses NSCodec RLE data for a single plane. This is different from bitmap RLE - NSCodec uses a simpler format with run segments and literal segments. The last 4 bytes of compressed data are raw (not RLE-encoded) and appended directly to the output.
func Palette8ToRGBA ¶
Palette8ToRGBA converts 8-bit paletted data to 32-bit RGBA using current palette Thread-safe: uses mutex for concurrent access.
func ProcessBitmap ¶
func ProcessBitmap(src []byte, width, height, bpp int, isCompressed bool, rowDelta int, noHdr bool) []byte
ProcessBitmap handles decompression, flip, and color conversion in one call. Returns the RGBA output buffer on success, nil on failure. The noHdr flag indicates NO_BITMAP_COMPRESSION_HDR was set — for 32bpp compressed, this means RDP6 Planar codec; without it, 32bpp uses 24-bit interleaved RLE.
func RGB555ToRGBA ¶
RGB555ToRGBA converts 15-bit RGB555 to 32-bit RGBA
func RGB565ToRGBA ¶
RGB565ToRGBA converts 16-bit RGB565 to 32-bit RGBA
func RLEDecompress ¶
func RLEDecompress[T uint8 | uint16 | uint32](pf PixelFormat[T], src []byte, dest []byte, rowDelta int) bool
RLEDecompress decompresses RLE-encoded bitmap data using the specified pixel format.
func RLEDecompress8 ¶
RLEDecompress8 decompresses 8-bit RLE compressed bitmap data
func RLEDecompress15 ¶
RLEDecompress15 decompresses 15-bit RLE compressed bitmap data
func RLEDecompress16 ¶
RLEDecompress16 decompresses 16-bit RLE compressed bitmap data
func RLEDecompress24 ¶
RLEDecompress24 decompresses 24-bit RLE compressed bitmap data
func RLEDecompress32 ¶
RLEDecompress32 decompresses 32-bit RLE compressed bitmap data
func ReadPixel15 ¶
ReadPixel15 reads a 15-bit pixel from the buffer
func ReadPixel16 ¶
ReadPixel16 reads a 16-bit pixel from the buffer
func ReadPixel24 ¶
ReadPixel24 reads a 24-bit pixel from the buffer
func ReadPixel32 ¶
ReadPixel32 reads a 32-bit pixel from the buffer
func RestoreColorLoss ¶
RestoreColorLoss restores color values that were quantized during compression
func SetPalette ¶
SetPalette updates the current palette from server data RDP palette format: array of RGB entries (R, G, B - 3 bytes each) Thread-safe: uses mutex for concurrent access.
func UnwrapSecurityFlag ¶
UnwrapSecurityFlag reads and returns the security flag from an RDP security header.
func WrapSecurityFlag ¶
WrapSecurityFlag wraps data with an RDP security header containing the specified flag.
func WriteFgBgImage8 ¶
func WriteFgBgImage8(dest []byte, destIdx int, rowDelta int, bitmask byte, fgPel byte, cBits int, firstLine bool) int
WriteFgBgImage8 writes a foreground/background image for 8-bit color
func WriteFgBgImage15 ¶
func WriteFgBgImage15(dest []byte, destIdx int, rowDelta int, bitmask byte, fgPel uint16, cBits int, firstLine bool) int
WriteFgBgImage15 writes a foreground/background image for 15-bit color
func WriteFgBgImage16 ¶
func WriteFgBgImage16(dest []byte, destIdx int, rowDelta int, bitmask byte, fgPel uint16, cBits int, firstLine bool) int
WriteFgBgImage16 writes a foreground/background image for 16-bit color
func WriteFgBgImage24 ¶
func WriteFgBgImage24(dest []byte, destIdx int, rowDelta int, bitmask byte, fgPel uint32, cBits int, firstLine bool) int
WriteFgBgImage24 writes a foreground/background image for 24-bit color
func WriteFgBgImage32 ¶
func WriteFgBgImage32(dest []byte, destIdx int, rowDelta int, bitmask byte, fgPel uint32, cBits int, firstLine bool) int
WriteFgBgImage32 writes a foreground/background image for 32-bit color
func WritePixel15 ¶
WritePixel15 writes a 15-bit pixel to the buffer
func WritePixel16 ¶
WritePixel16 writes a 16-bit pixel to the buffer
func WritePixel24 ¶
WritePixel24 writes a 24-bit pixel to the buffer
func WritePixel32 ¶
WritePixel32 writes a 32-bit pixel to the buffer
Types ¶
type BitmapStream ¶
type BitmapStream struct {
LumaPlaneByteCount uint32
OrangeChromaPlaneByteCount uint32
GreenChromaPlaneByteCount uint32
AlphaPlaneByteCount uint32
ColorLossLevel uint8
ChromaSubsamplingLevel uint8
LumaPlane []byte
OrangeChromaPlane []byte
GreenChromaPlane []byte
AlphaPlane []byte
}
BitmapStream represents the NSCODEC_BITMAP_STREAM structure as specified in MS-RDPNSC.
func ParseBitmapStream ¶
func ParseBitmapStream(data []byte) (*BitmapStream, error)
ParseBitmapStream parses an NSCODEC_BITMAP_STREAM from raw bytes.