Showing
4 changed files
with
21 additions
and
5 deletions
@@ -205,6 +205,7 @@ class PDFImage extends PdfImage { | @@ -205,6 +205,7 @@ class PDFImage extends PdfImage { | ||
205 | height: height, | 205 | height: height, |
206 | alpha: alpha, | 206 | alpha: alpha, |
207 | alphaChannel: false, | 207 | alphaChannel: false, |
208 | + isRGB: true, | ||
208 | jpeg: false, | 209 | jpeg: false, |
209 | orientation: PdfImageOrientation.topLeft); | 210 | orientation: PdfImageOrientation.topLeft); |
210 | } | 211 | } |
@@ -24,6 +24,7 @@ class PdfJpegInfo { | @@ -24,6 +24,7 @@ class PdfJpegInfo { | ||
24 | 24 | ||
25 | int width; | 25 | int width; |
26 | int height; | 26 | int height; |
27 | + int color; | ||
27 | int offset = 0; | 28 | int offset = 0; |
28 | while (offset < buffer.lengthInBytes) { | 29 | while (offset < buffer.lengthInBytes) { |
29 | while (buffer.getUint8(offset) == 0xff) { | 30 | while (buffer.getUint8(offset) == 0xff) { |
@@ -55,6 +56,7 @@ class PdfJpegInfo { | @@ -55,6 +56,7 @@ class PdfJpegInfo { | ||
55 | if (mrkr == 0xc0) { | 56 | if (mrkr == 0xc0) { |
56 | height = buffer.getUint16(offset + 1); | 57 | height = buffer.getUint16(offset + 1); |
57 | width = buffer.getUint16(offset + 3); | 58 | width = buffer.getUint16(offset + 3); |
59 | + color = buffer.getUint8(offset + 5); | ||
58 | break; | 60 | break; |
59 | } | 61 | } |
60 | offset += len - 2; | 62 | offset += len - 2; |
@@ -62,15 +64,19 @@ class PdfJpegInfo { | @@ -62,15 +64,19 @@ class PdfJpegInfo { | ||
62 | 64 | ||
63 | final Map<PdfExifTag, dynamic> tags = _findExifInJpeg(buffer); | 65 | final Map<PdfExifTag, dynamic> tags = _findExifInJpeg(buffer); |
64 | 66 | ||
65 | - return PdfJpegInfo._(width, height, tags); | 67 | + return PdfJpegInfo._(width, height, color, tags); |
66 | } | 68 | } |
67 | 69 | ||
68 | - PdfJpegInfo._(this.width, this.height, this.tags); | 70 | + PdfJpegInfo._(this.width, this.height, this._color, this.tags); |
69 | 71 | ||
70 | final int width; | 72 | final int width; |
71 | 73 | ||
72 | final int height; | 74 | final int height; |
73 | 75 | ||
76 | + final int _color; | ||
77 | + | ||
78 | + bool get isRGB => _color == 3; | ||
79 | + | ||
74 | final Map<PdfExifTag, dynamic> tags; | 80 | final Map<PdfExifTag, dynamic> tags; |
75 | 81 | ||
76 | /// EXIF version | 82 | /// EXIF version |
@@ -51,6 +51,7 @@ class PdfImage extends PdfXObject { | @@ -51,6 +51,7 @@ class PdfImage extends PdfXObject { | ||
51 | height: height, | 51 | height: height, |
52 | alpha: alpha, | 52 | alpha: alpha, |
53 | alphaChannel: false, | 53 | alphaChannel: false, |
54 | + isRGB: true, | ||
54 | jpeg: false, | 55 | jpeg: false, |
55 | orientation: orientation, | 56 | orientation: orientation, |
56 | ); | 57 | ); |
@@ -62,12 +63,14 @@ class PdfImage extends PdfXObject { | @@ -62,12 +63,14 @@ class PdfImage extends PdfXObject { | ||
62 | @required int height, | 63 | @required int height, |
63 | @required this.alpha, | 64 | @required this.alpha, |
64 | @required this.alphaChannel, | 65 | @required this.alphaChannel, |
66 | + @required this.isRGB, | ||
65 | @required this.jpeg, | 67 | @required this.jpeg, |
66 | @required this.orientation, | 68 | @required this.orientation, |
67 | }) : assert(alphaChannel == false || alpha == true), | 69 | }) : assert(alphaChannel == false || alpha == true), |
68 | assert(width != null), | 70 | assert(width != null), |
69 | assert(height != null), | 71 | assert(height != null), |
70 | assert(jpeg != null), | 72 | assert(jpeg != null), |
73 | + assert(isRGB != null), | ||
71 | assert(orientation != null), | 74 | assert(orientation != null), |
72 | _width = width, | 75 | _width = width, |
73 | _height = height, | 76 | _height = height, |
@@ -86,16 +89,17 @@ class PdfImage extends PdfXObject { | @@ -86,16 +89,17 @@ class PdfImage extends PdfXObject { | ||
86 | height: height, | 89 | height: height, |
87 | alpha: alpha, | 90 | alpha: alpha, |
88 | alphaChannel: true, | 91 | alphaChannel: true, |
92 | + isRGB: false, | ||
89 | jpeg: jpeg, | 93 | jpeg: jpeg, |
90 | orientation: orientation, | 94 | orientation: orientation, |
91 | ); | 95 | ); |
92 | params['/SMask'] = PdfStream.string('${_sMask.objser} 0 R'); | 96 | params['/SMask'] = PdfStream.string('${_sMask.objser} 0 R'); |
93 | } | 97 | } |
94 | 98 | ||
95 | - if (alphaChannel) { | ||
96 | - params['/ColorSpace'] = PdfStream.string('/DeviceGray'); | ||
97 | - } else { | 99 | + if (isRGB) { |
98 | params['/ColorSpace'] = PdfStream.string('/DeviceRGB'); | 100 | params['/ColorSpace'] = PdfStream.string('/DeviceRGB'); |
101 | + } else { | ||
102 | + params['/ColorSpace'] = PdfStream.string('/DeviceGray'); | ||
99 | } | 103 | } |
100 | 104 | ||
101 | if (jpeg) { | 105 | if (jpeg) { |
@@ -118,6 +122,7 @@ class PdfImage extends PdfXObject { | @@ -118,6 +122,7 @@ class PdfImage extends PdfXObject { | ||
118 | height: info.height, | 122 | height: info.height, |
119 | jpeg: true, | 123 | jpeg: true, |
120 | alpha: false, | 124 | alpha: false, |
125 | + isRGB: info.isRGB, | ||
121 | alphaChannel: false, | 126 | alphaChannel: false, |
122 | orientation: orientation ?? info.orientation, | 127 | orientation: orientation ?? info.orientation, |
123 | ); | 128 | ); |
@@ -145,6 +150,9 @@ class PdfImage extends PdfXObject { | @@ -145,6 +150,9 @@ class PdfImage extends PdfXObject { | ||
145 | /// The image data is a jpeg image | 150 | /// The image data is a jpeg image |
146 | final bool jpeg; | 151 | final bool jpeg; |
147 | 152 | ||
153 | + /// The image data is a color RGB image | ||
154 | + final bool isRGB; | ||
155 | + | ||
148 | /// The internal orientation of the image | 156 | /// The internal orientation of the image |
149 | final PdfImageOrientation orientation; | 157 | final PdfImageOrientation orientation; |
150 | 158 |
-
Please register or login to post a comment