MBBitmapPixelPlane Class Reference

Inherits from NSObject
Declared in MBBitmapPixelPlane.h

Overview

Represents a plane of pixels that can be accessed individually, regardless of the underlying pixel format. This allows code to access and manipulate bitmaps without needing to worry about the internal representation of the pixels.

Important:

  • This class supports only integral pixels.
  • This class does not currently support floating-point channel values.
  • This class is only intended for use with iOS-compatible bitmaps.

Accessing bitmap information

  pixelCount

Returns the number of pixels in the bitmap.

@property (nonatomic, readonly) NSUInteger pixelCount

Declared In

MBBitmapPixelPlane.h

  columnCount

Returns the number of columns in the bitmap.

@property (nonatomic, readonly) NSUInteger columnCount

Declared In

MBBitmapPixelPlane.h

  rowCount

Returns the number of rows in the bitmap.

@property (nonatomic, readonly) NSUInteger rowCount

Declared In

MBBitmapPixelPlane.h

  channelsPerPixel

Returns the number of color channels for each pixel in the bitmap.

@property (nonatomic, readonly) NSUInteger channelsPerPixel

Declared In

MBBitmapPixelPlane.h

  channelMaximumValue

Returns the maximum value of an individual color component in the bitmap.

@property (nonatomic, readonly) MBColorComponent channelMaximumValue

Declared In

MBBitmapPixelPlane.h

  bytesPerPixel

Returns the number of bytes required to represent each pixel in the bitmap.

@property (nonatomic, readonly) NSUInteger bytesPerPixel

Declared In

MBBitmapPixelPlane.h

  sizeInBytes

Returns the number of bytes required to represent the bitmap.

@property (nonatomic, readonly) NSUInteger sizeInBytes

Declared In

MBBitmapPixelPlane.h

  pixelType

Returns a MBBitmapPixelType value indicating how the bitmap interprets pixel data.

@property (nonatomic, readonly) MBBitmapPixelType pixelType

Declared In

MBBitmapPixelPlane.h

Creating empty bitmaps

+ bitmapWithColumns:rows:

Creates a new MBBitmapPixelPlane containing the specified number of rows and columns.

+ (nullable instancetype)bitmapWithColumns:(NSUInteger)cols rows:(NSUInteger)rows

Parameters

cols

The number of pixel columns in the returned bitmap.

rows

The number of pixel rows in the returned bitmap.

Return Value

A new MBBitmapPixelPlane instance with the specified settings. Returns nil if an error occurred.

Discussion

The bitmap will use the device color space with 4 channel pixels (RGBA) having 8 bits per channel using the device’s native byte ordering.

Declared In

MBBitmapPixelPlane.h

+ bitmapWithSize:

Creates a new MBBitmapPixelPlane containing the specified number of rows and columns.

+ (nullable instancetype)bitmapWithSize:(CGSize)size

Parameters

size

The size, in pixels, of the returned bitmap. Only integral values are used; fractional values encountered for the width or height will be rounded up to the next integer value.

Return Value

A new MBBitmapPixelPlane instance with the specified settings. Returns nil if an error occurred.

Discussion

The bitmap will use the device color space with 4 channel pixels (RGBA) having 8 bits per channel using the device’s native byte ordering.

Declared In

MBBitmapPixelPlane.h

+ bitmapWithSize:bitsPerChannel:colorSpace:bitmapInfo:

Creates a new MBBitmapPixelPlane having the specified settings.

+ (nullable instancetype)bitmapWithSize:(CGSize)size bitsPerChannel:(NSUInteger)bits colorSpace:(nonnull CGColorSpaceRef)space bitmapInfo:(CGBitmapInfo)info

Parameters

size

The size, in pixels, of the returned bitmap. Only integral values are used; fractional values encountered for the width or height will be rounded up to the next integer value.

bits

The number of bits per color channel.

space

The color space that will be used by the bitmap.

info

The CGBitmapInfo flags describing the memory layout of the color channels.

Return Value

A new MBBitmapPixelPlane instance with the specified settings. Returns nil if an error occurred.

Declared In

MBBitmapPixelPlane.h

+ bitmapWithUIImage:

Creates a new MBBitmapPixelPlane populated using the content of the image data contained in the UIImage instance provided.

+ (nullable instancetype)bitmapWithUIImage:(nonnull UIImage *)image

Parameters

image

An image that will be used as the source content of the returned MBBitmapPixelPlane.

Return Value

A new MBBitmapPixelPlane instance containing the image specified. Returns nil if an error occurred.

Declared In

MBBitmapPixelPlane.h

+ bitmapWithNSImage:

Creates a new MBBitmapPixelPlane populated using the content of the image data contained in the NSImage instance provided.

+ (nullable instancetype)bitmapWithNSImage:(nonnull NSImage *)image

Parameters

image

An image that will be used as the source content of the returned MBBitmapPixelPlane.

Return Value

A new MBBitmapPixelPlane instance containing the image specified. Returns nil if an error occurred.

Declared In

MBBitmapPixelPlane.h

+ bitmapWithCGImage:

Creates a new MBBitmapPixelPlane populated using the content of the image data contained in the CGImageRef provided.

+ (nullable instancetype)bitmapWithCGImage:(nonnull CGImageRef)image

Parameters

image

An image that will be used as the source content of the returned MBBitmapPixelPlane.

Return Value

A new MBBitmapPixelPlane instance containing the image specified. Returns nil if an error occurred.

Declared In

MBBitmapPixelPlane.h

+ bitmapWithBitmapContext:

Creates a new MBBitmapPixelPlane populated using the content of the bitmap image data contained in the CGContextRef provided.

+ (nullable instancetype)bitmapWithBitmapContext:(nonnull CGContextRef)bitmap

Parameters

bitmap

A CoreGraphics context that will be used as the source content of the returned MBBitmapPixelPlane. This context must be bitmap-based.

Return Value

A new MBBitmapPixelPlane instance containing the image specified. Returns nil if an error occurred.

Declared In

MBBitmapPixelPlane.h

Getting individual pixel data

– getPixel:atColumn:row:

Retrieves the color channel values for the pixel at the specified column (x coordinate) and row (y coordinate).

- (BOOL)getPixel:(nonnull inout MBBitmapPixel *)pixelPtr atColumn:(NSUInteger)col row:(NSUInteger)row

Parameters

pixelPtr

A pointer to an MBBitmapPixel structure that will receive color data for the specified pixel if the method succeeds.

col

The column of the pixel whose color data is being retrieved.

row

The row of the pixel whose color data is being retrieved.

Return Value

YES on success. NO will be returned if pixel is nil or if the specified pixel falls outside the bounds of the bitmap.

Declared In

MBBitmapPixelPlane.h

– getPixel:atPoint:

Retrieves the color channel values for the pixel at the specified point.

- (BOOL)getPixel:(nonnull inout MBBitmapPixel *)pixelPtr atPoint:(CGPoint)point

Parameters

pixelPtr

A pointer to an MBBitmapPixel structure that will receive color data for the specified pixel if the method succeeds.

point

The point specifying the x and y coordinates of the pixel whose color data is being retrieved. Only integral values are used; fractional values encountered for the x or y coordinate will be rounded to the closest integer value.

Return Value

YES on success. NO will be returned if pixel is nil or if the specified pixel falls outside the bounds of the bitmap.

Declared In

MBBitmapPixelPlane.h

– getPixel:atIndex:

Retrieves the color channel values for the pixel at the specified index.

- (BOOL)getPixel:(nonnull inout MBBitmapPixel *)pixelPtr atIndex:(NSUInteger)index

Parameters

pixelPtr

A pointer to an MBBitmapPixel structure that will receive color data for the specified pixel if the method succeeds.

index

The index of the pixel in the bitmap. The top-left pixel is index 0, and the indices proceed from left-to-right then top-to-bottom.

Return Value

YES on success. NO will be returned if pixel is nil or if the specified pixel falls outside the bounds of the bitmap.

Declared In

MBBitmapPixelPlane.h

Setting individual pixel data

– setPixel:atColumn:row:

Sets the color channel values for the pixel at the specified column (x coordinate) and row (y coordinate).

- (BOOL)setPixel:(MBBitmapPixel)pixel atColumn:(NSUInteger)col row:(NSUInteger)row

Parameters

pixel

The MBBitmapPixel structure that specifies the new color channel values for the pixel.

col

The column of the pixel whose color data is being retrieved.

row

The row of the pixel whose color data is being retrieved.

Return Value

YES on success. NO will be returned if the specified pixel falls outside the bounds of the bitmap.

Discussion

Values provided in channels not supported by the underlying bitmap will be ignored.

Declared In

MBBitmapPixelPlane.h

– setPixel:atPoint:

Sets the color channel values for the pixel at the specified point.

- (BOOL)setPixel:(MBBitmapPixel)pixel atPoint:(CGPoint)point

Parameters

pixel

The MBBitmapPixel structure that specifies the new color channel values for the pixel.

point

The point specifying the x and y coordinates of the pixel whose color data is being set. Only integral values are used; fractional values encountered for the x or y coordinate will be rounded to the closest integer value.

Return Value

YES on success. NO will be returned if the specified pixel falls outside the bounds of the bitmap.

Discussion

Values provided in channels not supported by the underlying bitmap will be ignored.

Declared In

MBBitmapPixelPlane.h

– setPixel:atIndex:

Sets the color channel values for the pixel at the specified index.

- (BOOL)setPixel:(MBBitmapPixel)pixel atIndex:(NSUInteger)index

Parameters

pixel

The MBBitmapPixel structure that specifies the new color channel values for the pixel.

index

The index of the pixel in the bitmap. The top-left pixel is index 0, and the indices proceed from left-to-right then top-to-bottom.

Return Value

YES on success. NO will be returned if the specified pixel falls outside the bounds of the bitmap.

Discussion

Values provided in channels not supported by the underlying bitmap will be ignored.

Declared In

MBBitmapPixelPlane.h

– image

Creates a UIImage instance containing a visual representation of the current contents of the receiver.

- (nonnull UIImage *)image

Return Value

A new UIImage.

Declared In

MBBitmapPixelPlane.h