add flipY argument to pixelBufferToPng
This commit is contained in:
@@ -42,15 +42,15 @@ Future<Uint8List> pixelBufferToBmp(Uint8List pixelBuffer, int width, int height,
|
|||||||
final srcIndex = (y * width + x) * (hasAlpha ? 4 : 3); // RGBA format
|
final srcIndex = (y * width + x) * (hasAlpha ? 4 : 3); // RGBA format
|
||||||
final dstIndex = 54 + y * rowSize + x * 3; // BGR format
|
final dstIndex = 54 + y * rowSize + x * 3; // BGR format
|
||||||
|
|
||||||
data[dstIndex] = isFloat
|
data[dstIndex] = isFloat
|
||||||
? (floatData![srcIndex + 2] * 255).toInt()
|
? (floatData![srcIndex + 2] * 255).toInt()
|
||||||
: pixelBuffer[srcIndex + 2]; // Blue
|
: pixelBuffer[srcIndex + 2]; // Blue
|
||||||
data[dstIndex + 1] = isFloat
|
data[dstIndex + 1] = isFloat
|
||||||
? (floatData![srcIndex + 1] * 255).toInt()
|
? (floatData![srcIndex + 1] * 255).toInt()
|
||||||
: pixelBuffer[srcIndex + 1]; // Green
|
: pixelBuffer[srcIndex + 1]; // Green
|
||||||
data[dstIndex + 2] = isFloat
|
data[dstIndex + 2] = isFloat
|
||||||
? (floatData![srcIndex] * 255).toInt()
|
? (floatData![srcIndex] * 255).toInt()
|
||||||
: pixelBuffer[srcIndex]; // Red
|
: pixelBuffer[srcIndex]; // Red
|
||||||
|
|
||||||
// Alpha channel is discarded
|
// Alpha channel is discarded
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,11 @@ Future<Uint8List> pixelBufferToBmp(Uint8List pixelBuffer, int width, int height,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Uint8List> pixelBufferToPng(Uint8List pixelBuffer, int width, int height,
|
Future<Uint8List> pixelBufferToPng(Uint8List pixelBuffer, int width, int height,
|
||||||
{bool hasAlpha = true, bool isFloat = false, bool linearToSrgb = false, bool invertAces = false}) async {
|
{bool hasAlpha = true,
|
||||||
|
bool isFloat = false,
|
||||||
|
bool linearToSrgb = false,
|
||||||
|
bool invertAces = false,
|
||||||
|
bool flipY = false}) async {
|
||||||
final image = img.Image(width: width, height: height);
|
final image = img.Image(width: width, height: height);
|
||||||
|
|
||||||
Float32List? floatData;
|
Float32List? floatData;
|
||||||
@@ -75,10 +79,15 @@ Future<Uint8List> pixelBufferToPng(Uint8List pixelBuffer, int width, int height,
|
|||||||
|
|
||||||
for (int y = 0; y < height; y++) {
|
for (int y = 0; y < height; y++) {
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
final int pixelIndex = (y * width + x) * (hasAlpha ? 4 : 3);
|
late int pixelIndex;
|
||||||
|
if (flipY) {
|
||||||
|
pixelIndex = ((height - 1 - y) * width + x) * (hasAlpha ? 4 : 3);
|
||||||
|
} else {
|
||||||
|
pixelIndex = (y * width + x) * (hasAlpha ? 4 : 3);
|
||||||
|
}
|
||||||
|
|
||||||
double r, g, b, a;
|
double r, g, b, a;
|
||||||
|
|
||||||
if (isFloat) {
|
if (isFloat) {
|
||||||
r = floatData![pixelIndex];
|
r = floatData![pixelIndex];
|
||||||
g = floatData[pixelIndex + 1];
|
g = floatData[pixelIndex + 1];
|
||||||
|
|||||||
Reference in New Issue
Block a user