bmpx

package
v0.0.0-...-892a75d Latest Latest
Warning

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

Go to latest
Published: May 21, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Crop

func Crop(src io.Reader, dst io.Writer, region image.Rectangle) error

Crop crops the provided region of the BMP found in the input stream to the output stream.

The input BMP must be bottom-up, no alpha, and uncompressed.

Thanks to the simplicity of the BMP format, crop uses a very small amount of memory (~8KiB).

If src is an io.ReadSeeker, then the cropper will seek to skip pixels that are outside the cropping region.

Cropping complexity scales primarily with number of cropped rows, not columns. Depending on the data and number of crops, it may make sense to rotate the image accordingly.

func Resize

func Resize(
	src io.Reader,
	dst io.Writer,
	width, height int,
	opts ...ResizeOption,
) error

Resize a BMP image as a stream. Holds the smallest amount of pixels possible in memory. Amount of pixels held in memory is equal to the width of the image multiplied by the height of the resampling filter. Each pixel takes up 4 * 8 bytes.

Parts of this code are taken from or inspired by https://github.com/disintegration/imaging/blob/24d954dc01266ac1e8ba74cbe5e632c87fb0b38a/resize.go

Types

type Header struct {
	Config       image.Config
	BitsPerPixel int
	TopDown      bool
	AllowAlpha   bool
	HeaderBytes  []byte
	ImageOffset  uint32
}

func DecodeHeader

func DecodeHeader(r io.Reader) (res Header, err error)

bmpDecodeHeader was shamelessly copied from 'x/image/bmp' and edited for the usecase in this repo. Unlike the stdlib implementation, the header and palette bytes are retained so that they can be re-written to cropped images.

type ResizeOption

type ResizeOption interface {
	// contains filtered or unexported methods
}

func WithResizeFilter

func WithResizeFilter(filter imaging.ResampleFilter) ResizeOption

Resampling filter used for resizing.

func WithResizeParallelBatchSize

func WithResizeParallelBatchSize(chunk int) ResizeOption

Number of pixels in each job that the workers (go routines) take on.

func WithResizeParallelLimit

func WithResizeParallelLimit(limit int) ResizeOption

Maximum number of parallel workers (go routines).

Jump to

Keyboard shortcuts

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