David PHAM-VAN

Add support for GreyScale Jpeg

... ... @@ -16,6 +16,7 @@
- Simplify PdfImage constructor
- Implement Image orientation
- Add Exif reader
- Add support for GreyScale Jpeg
## 1.3.23
... ...
... ... @@ -205,6 +205,7 @@ class PDFImage extends PdfImage {
height: height,
alpha: alpha,
alphaChannel: false,
isRGB: true,
jpeg: false,
orientation: PdfImageOrientation.topLeft);
}
... ...
... ... @@ -24,6 +24,7 @@ class PdfJpegInfo {
int width;
int height;
int color;
int offset = 0;
while (offset < buffer.lengthInBytes) {
while (buffer.getUint8(offset) == 0xff) {
... ... @@ -55,6 +56,7 @@ class PdfJpegInfo {
if (mrkr == 0xc0) {
height = buffer.getUint16(offset + 1);
width = buffer.getUint16(offset + 3);
color = buffer.getUint8(offset + 5);
break;
}
offset += len - 2;
... ... @@ -62,15 +64,19 @@ class PdfJpegInfo {
final Map<PdfExifTag, dynamic> tags = _findExifInJpeg(buffer);
return PdfJpegInfo._(width, height, tags);
return PdfJpegInfo._(width, height, color, tags);
}
PdfJpegInfo._(this.width, this.height, this.tags);
PdfJpegInfo._(this.width, this.height, this._color, this.tags);
final int width;
final int height;
final int _color;
bool get isRGB => _color == 3;
final Map<PdfExifTag, dynamic> tags;
/// EXIF version
... ...
... ... @@ -51,6 +51,7 @@ class PdfImage extends PdfXObject {
height: height,
alpha: alpha,
alphaChannel: false,
isRGB: true,
jpeg: false,
orientation: orientation,
);
... ... @@ -62,12 +63,14 @@ class PdfImage extends PdfXObject {
@required int height,
@required this.alpha,
@required this.alphaChannel,
@required this.isRGB,
@required this.jpeg,
@required this.orientation,
}) : assert(alphaChannel == false || alpha == true),
assert(width != null),
assert(height != null),
assert(jpeg != null),
assert(isRGB != null),
assert(orientation != null),
_width = width,
_height = height,
... ... @@ -86,16 +89,17 @@ class PdfImage extends PdfXObject {
height: height,
alpha: alpha,
alphaChannel: true,
isRGB: false,
jpeg: jpeg,
orientation: orientation,
);
params['/SMask'] = PdfStream.string('${_sMask.objser} 0 R');
}
if (alphaChannel) {
params['/ColorSpace'] = PdfStream.string('/DeviceGray');
} else {
if (isRGB) {
params['/ColorSpace'] = PdfStream.string('/DeviceRGB');
} else {
params['/ColorSpace'] = PdfStream.string('/DeviceGray');
}
if (jpeg) {
... ... @@ -118,6 +122,7 @@ class PdfImage extends PdfXObject {
height: info.height,
jpeg: true,
alpha: false,
isRGB: info.isRGB,
alphaChannel: false,
orientation: orientation ?? info.orientation,
);
... ... @@ -145,6 +150,9 @@ class PdfImage extends PdfXObject {
/// The image data is a jpeg image
final bool jpeg;
/// The image data is a color RGB image
final bool isRGB;
/// The internal orientation of the image
final PdfImageOrientation orientation;
... ...