toPlanar method
Convert RGBRGBRGB to RRRGGGBBB, will copy data
Implementation
Image toPlanar() {
final frameSize = _width * _height;
switch (dtype) {
case StbiDType.u8:
final temp = bytes;
final p = malloc<ffi.Uint8>(elemCount);
for (var i = 0; i < frameSize; i++) {
p[i] = temp[i * 3];
p[i + frameSize] = temp[i * 3 + 1];
p[i + frameSize * 2] = temp[i * 3 + 2];
}
return Image.fromPointer(
p.cast(),
width: _width,
height: _height,
channels: _channels,
desiredChannels: _desiredChannels,
dtype: StbiDType.u8,
);
case StbiDType.u16:
final temp = bytes.buffer.asUint16List();
final p = malloc<ffi.Uint16>(elemCount);
for (var i = 0; i < frameSize; i++) {
p[i] = temp[i * 3];
p[i + frameSize] = temp[i * 3 + 1];
p[i + frameSize * 2] = temp[i * 3 + 2];
}
return Image.fromPointer(
p.cast(),
width: _width,
height: _height,
channels: _channels,
desiredChannels: _desiredChannels,
dtype: StbiDType.u16,
);
case StbiDType.f32:
final temp = bytes.buffer.asFloat32List();
final p = malloc<ffi.Float>(elemCount);
for (var i = 0; i < frameSize; i++) {
p[i] = temp[i * 3];
p[i + frameSize] = temp[i * 3 + 1];
p[i + frameSize * 2] = temp[i * 3 + 2];
}
return Image.fromPointer(
p.cast(),
width: _width,
height: _height,
channels: _channels,
desiredChannels: _desiredChannels,
dtype: StbiDType.f32,
);
}
}