- Renamed all references from zpdf to zcatpdf
- Module import: @import("zcatpdf")
- Consistent with zcatui, zcatgui naming convention
- All lowercase per Zig standards
Note: Directory rename (zpdf -> zcatpdf) and Forgejo repo rename
should be done manually after this commit.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
50 lines
1.6 KiB
Zig
50 lines
1.6 KiB
Zig
//! Image module for zcatpdf
|
|
//!
|
|
//! Provides image parsing and embedding support for PDF generation.
|
|
//! Supports JPEG (direct embedding) and PNG (with alpha support).
|
|
|
|
pub const jpeg = @import("jpeg.zig");
|
|
pub const png = @import("png.zig");
|
|
pub const ImageInfo = @import("image_info.zig").ImageInfo;
|
|
pub const ImageFormat = @import("image_info.zig").ImageFormat;
|
|
|
|
// Re-export common functions
|
|
pub const parseJpeg = jpeg.parse;
|
|
pub const parsePng = png.parse;
|
|
|
|
/// Detects image format from raw bytes
|
|
pub fn detectFormat(data: []const u8) ?ImageFormat {
|
|
if (data.len < 8) return null;
|
|
|
|
// JPEG: starts with FF D8 FF
|
|
if (data[0] == 0xFF and data[1] == 0xD8 and data[2] == 0xFF) {
|
|
return .jpeg;
|
|
}
|
|
|
|
// PNG: starts with 89 50 4E 47 0D 0A 1A 0A
|
|
if (data[0] == 0x89 and data[1] == 0x50 and data[2] == 0x4E and data[3] == 0x47 and
|
|
data[4] == 0x0D and data[5] == 0x0A and data[6] == 0x1A and data[7] == 0x0A)
|
|
{
|
|
return .png;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
test "detect JPEG format" {
|
|
const jpeg_header = [_]u8{ 0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46 };
|
|
const format = detectFormat(&jpeg_header);
|
|
try @import("std").testing.expectEqual(ImageFormat.jpeg, format.?);
|
|
}
|
|
|
|
test "detect PNG format" {
|
|
const png_header = [_]u8{ 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A };
|
|
const format = detectFormat(&png_header);
|
|
try @import("std").testing.expectEqual(ImageFormat.png, format.?);
|
|
}
|
|
|
|
test "detect unknown format" {
|
|
const unknown = [_]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
|
|
const format = detectFormat(&unknown);
|
|
try @import("std").testing.expect(format == null);
|
|
}
|