37- (id) initWithW : (
unsigned) width H : (
unsigned) height scaleFactor : (CGFloat) scaleFactor
39 if (self = [super init]) {
44 if (![self resizeW :
width H :
height scaleFactor : scaleFactor]) {
54- (BOOL) resizeW : (
unsigned) width H : (
unsigned) height scaleFactor : (CGFloat) scaleFactor
56 assert(
width > 0 &&
"resizeW:H:, Pixmap width must be positive");
57 assert(
height > 0 &&
"resizeW:H:, Pixmap height must be positive");
61 std::vector<unsigned char> memory;
67 memory.resize(scaledW * scaledH * 4);
68 }
catch (
const std::bad_alloc &) {
69 NSLog(
@"QuartzPixmap: -resizeW:H:, memory allocation failed");
74 if (!colorSpace.Get()) {
75 NSLog(
@"QuartzPixmap: -resizeW:H:, CGColorSpaceCreateDeviceRGB failed");
80 scaledW * 4, colorSpace.Get(),
81 kCGImageAlphaPremultipliedLast, NULL, 0));
83 NSLog(
@"QuartzPixmap: -resizeW:H:, CGBitmapContextCreateWithData failed");
105 return [
self createImageFromPixmap : X11::Rectangle(0, 0, fWidth, fHeight)];
116 assert(cropArea.fX >= 0 &&
"createImageFromPixmap:, cropArea.fX is negative");
117 assert(cropArea.fY >= 0 &&
"createImageFromPixmap:, cropArea.fY is negative");
118 assert(cropArea.fWidth <=
fWidth &&
"createImageFromPixmap:, bad cropArea.fWidth");
119 assert(cropArea.fHeight <=
fHeight &&
"createImageFromPixmap:, bad cropArea.fHeight");
126 scaledW * scaledH * 4,
nullptr));
127 if (!provider.Get()) {
128 NSLog(
@"QuartzPixmap: -pixmapToImage, CGDataProviderCreateWithData failed");
134 if (!colorSpace.Get()) {
135 NSLog(
@"QuartzPixmap: -pixmapToImage, CGColorSpaceCreateDeviceRGB failed");
143 kCGImageAlphaPremultipliedLast, provider.Get(), 0,
144 false, kCGRenderingIntentDefault);
170 assert(
fContext.
Get() != 0 &&
"fContext, called for bad pixmap");
178 assert(
fContext.
Get() != 0 &&
"fWidth, called for bad pixmap");
186 assert(
fContext.
Get() != 0 &&
"fHeight, called for bad pixmap");
216- (void) setDirectDraw : (BOOL) mode
228- (void) copyImage : (
QuartzImage *) srcImage area : (
X11::Rectangle) area
229 withMask : (
QuartzImage *) mask clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
234 assert(srcImage != nil &&
"copyImage:area:withMask:clipOrigin:toPoint:, srcImage parameter is nil");
235 assert(srcImage.
fImage != nil &&
"copyImage:area:withMask:clipOrigin:toPoint:, srcImage.fImage is nil");
238 NSLog(
@"QuartzPixmap: -copyImage:srcImage:area:withMask:clipOrigin"
239 ":toPoint, srcRect and copyRect do not intersect");
244 bool needSubImage =
false;
245 if (area.fX || area.fY || area.fWidth != srcImage.
fWidth || area.fHeight != srcImage.
fHeight) {
249 NSLog(
@"QuartzPixmap: -copyImage:area:withMask:clipOrigin:toPoint:, subimage creation failed");
253 subImage = srcImage.
fImage;
259 assert(
mask.fImage != nil &&
"copyImage:area:withMask:clipOrigin:toPoint, mask is not nil, but mask.fImage is nil");
260 assert(CGImageIsMask(
mask.fImage) &&
"copyImage:area:withMask:clipOrigin:toPoint, mask.fImage is not a mask");
263 const CGRect clipRect = CGRectMake(clipXY.fX, clipXY.fY,
mask.fWidth,
mask.fHeight);
269 const CGRect imageRect = CGRectMake(dstPoint.fX, dstPoint.fY, area.fWidth, area.fHeight);
270 CGContextDrawImage(
fContext.
Get(), imageRect, subImage);
273 CGImageRelease(subImage);
278 withMask : (
QuartzImage *)mask clipOrigin : (
X11::Point) clipXY toPoint : (
X11::Point) dstPoint
282 assert(srcPixmap != nil &&
283 "copyPixmap:area:withMask:clipOrigin:toPoint, srcPixmap parameter is nil");
286 NSLog(
@"QuartzPixmap: -copyPixmap:area:withMask:clipOrigin:"
287 "toPoint, srcRect and copyRect do not intersect");
298 assert(
mask.fImage != nil &&
299 "copyPixmap:area:withMask:clipOrigin:toPoint, mask is not nil, but mask.fImage is nil");
300 assert(CGImageIsMask(
mask.fImage) &&
301 "copyPixmap:area:withMask:clipOrigin:toPoint, mask.fImage is not a mask");
304 const CGRect clipRect = CGRectMake(clipXY.fX, clipXY.fY,
mask.fWidth,
mask.fHeight);
310 const CGRect imageRect = CGRectMake(dstPoint.fX, dstPoint.fY, area.
fWidth, area.
fHeight);
316 withMask : (
QuartzImage *)mask clipOrigin : (
X11::Point) origin toPoint : (
X11::Point) dstPoint
319 "copy:area:widthMask:clipOrigin:toPoint, empty area to copy");
322 [
self copyImage : (QuartzImage *)src area : area withMask : mask clipOrigin : origin toPoint : dstPoint];
324 [
self copyPixmap : (QuartzPixmap *)src area : area withMask : mask clipOrigin : origin toPoint : dstPoint];
326 assert(0 &&
"Can copy only from pixmap or image");
330- (
unsigned char *) readColorBits : (
X11::
Rectangle) area
332 assert(area.
fWidth && area.
fHeight &&
"readColorBits:, empty area to copy");
335 NSLog(
@"QuartzPixmap: readColorBits:intoBuffer:, src and copy area do not intersect");
340 unsigned char *buffer = 0;
342 buffer =
new unsigned char[area.fWidth * area.fHeight * 4]();
343 }
catch (
const std::bad_alloc &) {
344 NSLog(
@"QuartzImage: -readColorBits:, memory allocation failed");
353 if (!scaledPixmap.
Get()) {
354 NSLog(
@"QuartzImage: -readColorBits:, can not create scaled pixmap");
358 [scaledPixmap.Get() copy : self area : X11::Rectangle(0, 0, fWidth, fHeight)
359 withMask : nil clipOrigin : X11::Point() toPoint : X11::Point()];
362 unsigned char *dstPixel = buffer;
367 : &scaledPixmap.Get()->fData[0] + area.fY * fWidth * 4;
369 const unsigned char *srcPixel =
line + area.
fX * 4;
371 for (
unsigned i = 0; i < area.
fHeight; ++i) {
372 for (
unsigned j = 0; j < area.
fWidth; ++j, srcPixel += 4, dstPixel += 4) {
373 dstPixel[0] = srcPixel[0];
374 dstPixel[1] = srcPixel[1];
375 dstPixel[2] = srcPixel[2];
376 dstPixel[3] = srcPixel[3];
380 srcPixel =
line + area.
fX * 4;
387- (
unsigned char *)
fData
393- (void) putPixel : (const
unsigned char *) rgb X : (
unsigned) x Y : (
unsigned) y
396 assert(rgb != 0 &&
"putPixel:X:Y:, rgb parameter is null");
397 assert(x < fWidth && "putPixel:X:Y:, x parameter is >= self.fWidth
");
398 assert(y < fHeight && "putPixel:
X:Y:,
y parameter is >= self.
fHeight");
400 unsigned char * const data = &fData[0];
401 if (fScaleFactor > 1) {
402 //Ooops, and what should I do now???
403 const unsigned scaledW = fWidth * fScaleFactor;
404 unsigned char *dst = data + unsigned(y * fScaleFactor * scaledW * 4) + unsigned(x * fScaleFactor * 4);
406 for (unsigned i = 0; i < 2; ++i, dst += 4) {
416 for (unsigned i = 0; i < 2; ++i, dst += 4) {
423 unsigned char *dst = data + y * fWidth * 4 + x * 4;
432//______________________________________________________________________________
433- (void) addPixel : (const unsigned char *) rgb
435 //Primitive version of XAddPixel.
436 assert(rgb != 0 && "addPixel:, rgb parameter is
null");
438 for (unsigned i = 0; i < fHeight; ++i) {
439 for (unsigned j = 0; j < fWidth; ++j) {
440 fData[i * fWidth * 4 + j * 4] = rgb[0];
441 fData[i * fWidth * 4 + j * 4 + 1] = rgb[1];
442 fData[i * fWidth * 4 + j * 4 + 2] = rgb[2];
443 fData[i * fWidth * 4 + j * 4 + 3] = rgb[3];