also looking at this
feat(media): implement native JPEG coding and bounded MJPEG streaming
#912
5 files
+442
-263
| @@ -0,0 +1,23 @@ | ||
| 1 | const std = ; | |
| 2 | const image = ; | |
| 3 | const jpeg = ; | |
| 4 | test { | |
| 5 | _ = jpeg; | |
| 6 | } | |
| 7 | test "native JPEG encodes scan data readable by the Home decoder" { | |
| 8 | var img = try image.Image.init(std.testing.allocator, 17, 9, .rgb8); | |
| 9 | defer img.deinit(); | |
| 10 | for (0..17 * 9) |i| { | |
| 11 | @memcpy(img.pixels[i * 3 ..][0..3], &[_]u8{ 200, 50, 100 }); | |
| 12 | } | |
| 13 | const encoded = try jpeg.encodeWithQuality(std.testing.allocator, &img, 98); | |
| 14 | defer std.testing.allocator.free(encoded); | |
| 15 | var decoded = try jpeg.decode(std.testing.allocator, encoded); | |
| 16 | defer decoded.deinit(); | |
| 17 | try std.testing.expectEqual(@as(u32, 17), decoded.width); | |
| 18 | try std.testing.expectEqual(@as(u32, 9), decoded.height); | |
| 19 | const pixel = decoded.getPixel(8, 4).?; | |
| 20 | try std.testing.expectApproxEqAbs(@as(f64, 200), @as(f64, @floatFromInt(pixel.r)), 5); | |
| 21 | try std.testing.expectApproxEqAbs(@as(f64, 50), @as(f64, @floatFromInt(pixel.g)), 5); | |
| 22 | try std.testing.expectApproxEqAbs(@as(f64, 100), @as(f64, @floatFromInt(pixel.b)), 5); | |
| 23 | } | |