Mercurial > projects > dwt-mac
comparison dwt/internal/cocoa/NSBitmapImageRep.d @ 45:d8635bb48c7c
Merge with SWT 3.5
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 01 Dec 2008 17:07:00 +0100 |
parents | f565d3a95c0a |
children | 62202ce0039f |
comparison
equal
deleted
inserted
replaced
44:ca5e494f2bbf | 45:d8635bb48c7c |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2007 IBM Corporation and others. | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * | 10 * |
11 * Port to the D programming language: | 11 * Port to the D programming language: |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | 12 * Jacob Carlborg <doob@me.com> |
13 *******************************************************************************/ | 13 *******************************************************************************/ |
14 module dwt.internal.cocoa.NSBitmapImageRep; | 14 module dwt.internal.cocoa.NSBitmapImageRep; |
15 | 15 |
16 import dwt.internal.cocoa.CGFloat; | 16 import dwt.internal.c.Carbon; |
17 import dwt.internal.cocoa.CIImage; | 17 import cocoa = dwt.internal.cocoa.id; |
18 import dwt.internal.cocoa.id; | |
19 import dwt.internal.cocoa.NSArray; | 18 import dwt.internal.cocoa.NSArray; |
20 import dwt.internal.cocoa.NSColor; | 19 import dwt.internal.cocoa.NSColor; |
21 import dwt.internal.cocoa.NSData; | 20 import dwt.internal.cocoa.NSData; |
22 import dwt.internal.cocoa.NSDictionary; | 21 import dwt.internal.cocoa.NSDictionary; |
23 import dwt.internal.cocoa.NSImageRep; | 22 import dwt.internal.cocoa.NSImageRep; |
24 import dwt.internal.cocoa.NSInteger; | |
25 import dwt.internal.cocoa.NSRect; | 23 import dwt.internal.cocoa.NSRect; |
26 import dwt.internal.cocoa.NSString; | 24 import dwt.internal.cocoa.NSString; |
27 import dwt.internal.cocoa.OS; | 25 import dwt.internal.cocoa.OS; |
26 import dwt.internal.objc.cocoa.Cocoa; | |
28 import objc = dwt.internal.objc.runtime; | 27 import objc = dwt.internal.objc.runtime; |
29 | 28 |
30 enum NSTIFFCompression : NSUInteger | 29 enum NSTIFFCompression : NSUInteger { |
31 { | |
32 NSTIFFCompressionNone = 1, | 30 NSTIFFCompressionNone = 1, |
33 NSTIFFCompressionCCITTFAX3 = 3, | 31 NSTIFFCompressionCCITTFAX3 = 3, |
34 NSTIFFCompressionCCITTFAX4 = 4, | 32 NSTIFFCompressionCCITTFAX4 = 4, |
35 NSTIFFCompressionLZW = 5, | 33 NSTIFFCompressionLZW = 5, |
36 NSTIFFCompressionJPEG = 6, | 34 NSTIFFCompressionJPEG = 6, |
37 NSTIFFCompressionNEXT = 32766, | 35 NSTIFFCompressionNEXT = 32766, |
38 NSTIFFCompressionPackBits = 32773, | 36 NSTIFFCompressionPackBits = 32773, |
39 NSTIFFCompressionOldJPEG = 32865 | 37 NSTIFFCompressionOldJPEG = 32865 |
40 } | 38 } |
41 | 39 |
42 alias NSTIFFCompression.NSTIFFCompressionNone NSTIFFCompressionNone; | 40 enum NSBitmapFormat : NSUInteger { |
43 alias NSTIFFCompression.NSTIFFCompressionCCITTFAX3 NSTIFFCompressionCCITTFAX3; | |
44 alias NSTIFFCompression.NSTIFFCompressionCCITTFAX4 NSTIFFCompressionCCITTFAX4; | |
45 alias NSTIFFCompression.NSTIFFCompressionLZW NSTIFFCompressionLZW; | |
46 alias NSTIFFCompression.NSTIFFCompressionJPEG NSTIFFCompressionJPEG; | |
47 alias NSTIFFCompression.NSTIFFCompressionNEXT NSTIFFCompressionNEXT; | |
48 alias NSTIFFCompression.NSTIFFCompressionPackBits NSTIFFCompressionPackBits; | |
49 alias NSTIFFCompression.NSTIFFCompressionOldJPEG NSTIFFCompressionOldJPEG; | |
50 | |
51 enum NSBitmapFormat : NSUInteger | |
52 { | |
53 NSAlphaFirstBitmapFormat = 1 << 0, | 41 NSAlphaFirstBitmapFormat = 1 << 0, |
54 NSAlphaNonpremultipliedBitmapFormat = 1 << 1, | 42 NSAlphaNonpremultipliedBitmapFormat = 1 << 1, |
55 NSFloatingPointSamplesBitmapFormat = 1 << 2 | 43 NSFloatingPointSamplesBitmapFormat = 1 << 2 |
56 } | 44 } |
57 | 45 |
58 alias NSBitmapFormat.NSAlphaFirstBitmapFormat NSAlphaFirstBitmapFormat; | 46 public class NSBitmapImageRep : NSImageRep { |
59 alias NSBitmapFormat.NSAlphaNonpremultipliedBitmapFormat NSAlphaNonpremultipliedBitmapFormat; | 47 |
60 alias NSBitmapFormat.NSFloatingPointSamplesBitmapFormat NSFloatingPointSamplesBitmapFormat; | 48 public this () { |
49 super(); | |
50 } | |
61 | 51 |
62 public class NSBitmapImageRep : NSImageRep | 52 public this (objc.id id) { |
63 { | 53 super(id); |
64 public this () | 54 } |
65 { | |
66 super(); | |
67 } | |
68 | 55 |
69 public this (objc.id id) | 56 public this (cocoa.id id) { |
70 { | 57 super(id); |
71 super(id); | |
72 } | |
73 | 58 |
74 public objc.id CGImage () | 59 } |
75 { | |
76 return OS.objc_msgSend(this.id_, OS.sel_CGImage); | |
77 } | |
78 | 60 |
79 public NSData TIFFRepresentation () | 61 public objc.id bitmapData () { |
80 { | 62 return OS.objc_msgSend(this.id, OS.sel_bitmapData); |
81 objc.id result = OS.objc_msgSend(this.id_, OS.sel_TIFFRepresentation); | 63 } |
82 return result !is null ? new NSData(result) : null; | |
83 } | |
84 | 64 |
85 public static NSData static_TIFFRepresentationOfImageRepsInArray_ (NSArray array) | 65 public NSInteger bitsPerPixel () { |
86 { | 66 return cast(NSInteger) OS.objc_msgSend(this.id, OS.sel_bitsPerPixel); |
87 objc.id result = OS.objc_msgSend(OS.class_NSBitmapImageRep, OS.sel_TIFFRepresentationOfImageRepsInArray_1, array !is null ? array.id_ : null); | 67 } |
88 return result !is null ? new NSData(result) : null; | |
89 } | |
90 | 68 |
91 public static NSData static_TIFFRepresentationOfImageRepsInArray_usingCompression_factor_ (NSArray array, objc.id comp, float factor) | 69 public NSInteger bytesPerPlane () { |
92 { | 70 return cast(NSInteger) OS.objc_msgSend(this.id, OS.sel_bytesPerPlane); |
93 objc.id result = OS.objc_msgSend(OS.class_NSBitmapImageRep, OS.sel_TIFFRepresentationOfImageRepsInArray_1usingCompression_1factor_1, | 71 } |
94 array !is null ? array.id_ : null, comp, factor); | |
95 return result !is null ? new NSData(result) : null; | |
96 } | |
97 | 72 |
98 public NSData TIFFRepresentationUsingCompression (objc.id comp, float factor) | 73 public NSInteger bytesPerRow () { |
99 { | 74 return cast(NSInteger) OS.objc_msgSend(this.id, OS.sel_bytesPerRow); |
100 objc.id result = OS.objc_msgSend(this.id_, OS.sel_TIFFRepresentationUsingCompression_1factor_1, comp, factor); | 75 } |
101 return result !is null ? new NSData(result) : null; | |
102 } | |
103 | 76 |
104 public objc.id bitmapData () | 77 public NSBitmapImageRep initWithBitmapDataPlanes (ubyte** planes, NSInteger width, NSInteger height, NSInteger bps, NSInteger spp, bool alpha, bool isPlanar, NSString colorSpaceName, NSBitmapFormat bitmapFormat, NSInteger rBytes, NSInteger pBits) { |
105 { | 78 objc.id result = OS.objc_msgSend(this.id, OS.sel_initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel_, planes, width, height, bps, spp, alpha, isPlanar, colorSpaceName !is null ? colorSpaceName.id : null, bitmapFormat, rBytes, pBits); |
106 return OS.objc_msgSend(this.id_, OS.sel_bitmapData); | 79 return result !is null ? this : null; |
107 } | 80 } |
108 | 81 |
109 public objc.id bitmapFormat () | 82 public NSBitmapImageRep initWithBitmapDataPlanes (ubyte** planes, NSInteger width, NSInteger height, NSInteger bps, NSInteger spp, bool alpha, bool isPlanar, NSString colorSpaceName, NSInteger rBytes, NSInteger pBits) { |
110 { | 83 objc.id result = OS.objc_msgSend(this.id, OS.sel_initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel_, planes, width, height, bps, spp, alpha, isPlanar, colorSpaceName !is null ? colorSpaceName.id : null, rBytes, pBits); |
111 return OS.objc_msgSend(this.id_, OS.sel_bitmapFormat); | 84 return result !is null ? this : null; |
112 } | 85 } |
113 | 86 |
114 public NSInteger bitsPerPixel () | 87 public bool isPlanar () { |
115 { | 88 return OS.objc_msgSend_bool(this.id, OS.sel_isPlanar); |
116 return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_bitsPerPixel); | 89 } |
117 } | |
118 | 90 |
119 public NSInteger bytesPerPlane () | 91 public NSInteger samplesPerPixel () { |
120 { | 92 return cast(NSInteger) OS.objc_msgSend(this.id, OS.sel_samplesPerPixel); |
121 return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_bytesPerPlane); | 93 } |
122 } | |
123 | 94 |
124 public NSInteger bytesPerRow () | |
125 { | |
126 return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_bytesPerRow); | |
127 } | |
128 | |
129 public bool canBeCompressedUsing (objc.id compression) | |
130 { | |
131 return OS.objc_msgSend(this.id_, OS.sel_canBeCompressedUsing_1, compression) !is null; | |
132 } | |
133 | |
134 public NSColor colorAtX (NSInteger x, NSInteger y) | |
135 { | |
136 objc.id result = OS.objc_msgSend(this.id_, OS.sel_colorAtX_1y_1, x, y); | |
137 return result !is null ? new NSColor(result) : null; | |
138 } | |
139 | |
140 public void colorizeByMappingGray (CGFloat midPoint, NSColor midPointColor, NSColor shadowColor, NSColor lightColor) | |
141 { | |
142 OS.objc_msgSend(this.id_, OS.sel_colorizeByMappingGray_1toColor_1blackMapping_1whiteMapping_1, midPoint, | |
143 midPointColor !is null ? midPointColor.id_ : null, shadowColor !is null ? shadowColor.id_ : null, | |
144 lightColor !is null ? lightColor.id_ : null); | |
145 } | |
146 | |
147 public void getBitmapDataPlanes (objc.id data) | |
148 { | |
149 OS.objc_msgSend(this.id_, OS.sel_getBitmapDataPlanes_1, data); | |
150 } | |
151 | |
152 public void getCompression (NSTIFFCompression* compression, float* factor) | |
153 { | |
154 OS.objc_msgSend(this.id_, OS.sel_getCompression_1factor_1, compression, factor); | |
155 } | |
156 | |
157 public void getPixel (/*NSUInteger[]*/NSUInteger* p, NSInteger x, NSInteger y) | |
158 { | |
159 OS.objc_msgSend(this.id_, OS.sel_getPixel_1atX_1y_1, p, x, y); | |
160 } | |
161 | |
162 public static void getTIFFCompressionTypes (/*const*/NSTIFFCompression** list, NSInteger* numTypes) | |
163 { | |
164 OS.objc_msgSend(OS.class_NSBitmapImageRep, OS.sel_getTIFFCompressionTypes_1count_1, list, numTypes); | |
165 } | |
166 | |
167 public static id imageRepWithData (NSData data) | |
168 { | |
169 objc.id result = OS.objc_msgSend(OS.class_NSBitmapImageRep, OS.sel_imageRepWithData_1, data !is null ? data.id_ : null); | |
170 return result !is null ? new id(result) : null; | |
171 } | |
172 | |
173 public static NSArray imageRepsWithData (NSData data) | |
174 { | |
175 objc.id result = OS.objc_msgSend(OS.class_NSBitmapImageRep, OS.sel_imageRepsWithData_1, data !is null ? data.id_ : null); | |
176 return result !is null ? new NSArray(result) : null; | |
177 } | |
178 | |
179 public NSInteger incrementalLoadFromData (NSData data, bool complete) | |
180 { | |
181 return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_incrementalLoadFromData_1complete_1, data !is null ? data.id_ : null, complete); | |
182 } | |
183 | |
184 public NSBitmapImageRep initForIncrementalLoad () | |
185 { | |
186 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initForIncrementalLoad); | |
187 return result !is null ? this : null; | |
188 } | |
189 | |
190 public NSBitmapImageRep initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel_ ( | |
191 ubyte** planes, NSInteger width, NSInteger height, NSInteger bps, NSInteger spp, bool alpha, bool isPlanar, NSString colorSpaceName, | |
192 NSBitmapFormat bitmapFormat, NSInteger rBytes, NSInteger pBits) | |
193 { | |
194 objc.id | |
195 result = OS.objc_msgSend( | |
196 this.id_, | |
197 OS.sel_initWithBitmapDataPlanes_1pixelsWide_1pixelsHigh_1bitsPerSample_1samplesPerPixel_1hasAlpha_1isPlanar_1colorSpaceName_1bitmapFormat_1bytesPerRow_1bitsPerPixel_1, | |
198 planes, width, height, bps, spp, alpha, isPlanar, colorSpaceName !is null ? colorSpaceName.id_ : null, bitmapFormat, rBytes, | |
199 pBits); | |
200 return result !is null ? this : null; | |
201 } | |
202 | |
203 public NSBitmapImageRep initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel_ ( | |
204 ubyte** planes, NSInteger width, NSInteger height, NSInteger bps, NSInteger spp, bool alpha, bool isPlanar, NSString colorSpaceName, NSInteger rBytes, NSInteger pBits) | |
205 { | |
206 objc.id | |
207 result = OS.objc_msgSend( | |
208 this.id_, | |
209 OS.sel_initWithBitmapDataPlanes_1pixelsWide_1pixelsHigh_1bitsPerSample_1samplesPerPixel_1hasAlpha_1isPlanar_1colorSpaceName_1bytesPerRow_1bitsPerPixel_1, | |
210 planes, width, height, bps, spp, alpha, isPlanar, colorSpaceName !is null ? colorSpaceName.id_ : null, rBytes, pBits); | |
211 return result !is null ? this : null; | |
212 } | |
213 | |
214 public NSBitmapImageRep initWithCGImage (objc.id cgImage) | |
215 { | |
216 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithCGImage_1, cgImage); | |
217 return result !is null ? this : null; | |
218 } | |
219 | |
220 public NSBitmapImageRep initWithCIImage (CIImage ciImage) | |
221 { | |
222 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithCIImage_1, ciImage !is null ? ciImage.id_ : null); | |
223 return result !is null ? this : null; | |
224 } | |
225 | |
226 public NSBitmapImageRep initWithData (NSData data) | |
227 { | |
228 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithData_1, data !is null ? data.id_ : null); | |
229 return result !is null ? this : null; | |
230 } | |
231 | |
232 public NSBitmapImageRep initWithFocusedViewRect (NSRect rect) | |
233 { | |
234 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithFocusedViewRect_1, rect); | |
235 return result !is null ? this : null; | |
236 } | |
237 | |
238 public bool isPlanar () | |
239 { | |
240 return OS.objc_msgSend(this.id_, OS.sel_isPlanar) !is null; | |
241 } | |
242 | |
243 public static NSString localizedNameForTIFFCompressionType (objc.id compression) | |
244 { | |
245 objc.id result = OS.objc_msgSend(OS.class_NSBitmapImageRep, OS.sel_localizedNameForTIFFCompressionType_1, compression); | |
246 return result !is null ? new NSString(result) : null; | |
247 } | |
248 | |
249 public NSInteger numberOfPlanes () | |
250 { | |
251 return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_numberOfPlanes); | |
252 } | |
253 | |
254 public static NSData representationOfImageRepsInArray (NSArray imageReps, objc.id storageType, NSDictionary properties) | |
255 { | |
256 objc.id result = OS.objc_msgSend(OS.class_NSBitmapImageRep, OS.sel_representationOfImageRepsInArray_1usingType_1properties_1, | |
257 imageReps !is null ? imageReps.id_ : null, storageType, properties !is null ? properties.id_ : null); | |
258 return result !is null ? new NSData(result) : null; | |
259 } | |
260 | |
261 public NSData representationUsingType (objc.id storageType, NSDictionary properties) | |
262 { | |
263 objc.id result = OS.objc_msgSend(this.id_, OS.sel_representationUsingType_1properties_1, storageType, | |
264 properties !is null ? properties.id_ : null); | |
265 return result !is null ? new NSData(result) : null; | |
266 } | |
267 | |
268 public NSInteger samplesPerPixel () | |
269 { | |
270 return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_samplesPerPixel); | |
271 } | |
272 | |
273 public void setColor (NSColor color, NSInteger x, NSInteger y) | |
274 { | |
275 OS.objc_msgSend(this.id_, OS.sel_setColor_1atX_1y_1, color !is null ? color.id_ : null, x, y); | |
276 } | |
277 | |
278 public void setCompression (NSTIFFCompression compression, float factor) | |
279 { | |
280 OS.objc_msgSend(this.id_, OS.sel_setCompression_1factor_1, compression, factor); | |
281 } | |
282 | |
283 public void setPixel (/*NSUInteger[]*/NSUInteger* p, NSInteger x, NSInteger y) | |
284 { | |
285 OS.objc_msgSend(this.id_, OS.sel_setPixel_1atX_1y_1, p, x, y); | |
286 } | |
287 | |
288 public void setProperty (NSString property, id value) | |
289 { | |
290 OS.objc_msgSend(this.id_, OS.sel_setProperty_1withValue_1, property !is null ? property.id_ : null, value !is null ? value.id_ : null); | |
291 } | |
292 | |
293 public id valueForProperty (NSString property) | |
294 { | |
295 objc.id result = OS.objc_msgSend(this.id_, OS.sel_valueForProperty_1, property !is null ? property.id_ : null); | |
296 return result !is null ? new id(result) : null; | |
297 } | |
298 } | 95 } |