JXImage::JXImage ( const Pixmap bitmap, const JCoordinate width, const JCoordinate height, JXDisplay* display ) : JImage(width, height, display->GetColormap()) { #ifndef NDEBUG { Window rootWindow; int x,y; unsigned int w,h, bw, depth; const Status ok = XGetGeometry(*display, bitmap, &rootWindow, &x, &y, &w, &h, &bw, &depth); assert( ok && depth == 1 ); } #endif JXImageX(display, 1); itsPixmap = bitmap; itsGC = new JXGC(itsDisplay, itsPixmap); assert( itsGC != NULL ); }
JXImage::JXImage ( JXDisplay* display ) : JImage(0,0, display->GetColormap()) { JXImageX(display); }
JXImage::JXImage ( JXDisplay* display, JXColormap* colormap ) : JImage(0,0, colormap) { JXImageX(display, colormap); }
JXImage::JXImage ( JXDisplay* display, const JCoordinate width, const JCoordinate height, const JColorIndex origInitColor, const JSize depth, const State initState ) : JImage(width, height, display->GetColormap()) { JXImageX(display, depth); const JColorIndex initColor = (origInitColor == kJXTransparentColor && itsDepth > 1 ? itsXColormap->GetDefaultBackColor() : origInitColor); if (initState == kRemoteStorage) { itsPixmap = XCreatePixmap(*itsDisplay, itsDisplay->GetRootWindow(), width, height, itsDepth); assert( itsPixmap != None ); // We need a private GC so we can draw. itsGC = new JXGC(itsDisplay, itsPixmap); assert( itsGC != NULL ); itsGC->SetDrawingColor(initColor); itsGC->FillRect(itsPixmap, 0,0, width, height); // We don't convert to an image because the user probably wants // to draw to us. } else { assert( initState == kLocalStorage ); PrepareForImageData(); if (origInitColor != 0) { for (JCoordinate x=0; x<width; x++) { for (JCoordinate y=0; y<height; y++) { SetColor(x,y, initColor); } } } } }
JXImage::JXImage ( JXDisplay* display, const JXPM& data ) : JImage(0,0, display->GetColormap()) { JXImageX(display); ReadFromJXPM(data); }
JXImage::JXImage ( JXDisplay* display, JXColormap* colormap, const JXPM& data ) : JImage(0,0, colormap) { JXImageX(display, colormap); ReadFromJXPM(data); }
JXImage::JXImage ( JXDisplay* display, JXColormap* colormap, const JConstBitmap& bitmap, const JColorIndex origForeColor, const JColorIndex origBackColor, const JSize depth ) : JImage(bitmap.w, bitmap.h, colormap) { JXImageX(display, colormap, depth); const JColorIndex foreColor = (origForeColor == kJXTransparentColor && itsDepth > 1 ? colormap->GetBlackColor() : origForeColor); const JColorIndex backColor = (origBackColor == kJXTransparentColor && itsDepth > 1 ? colormap->GetDefaultBackColor() : origBackColor); unsigned long forePixel, backPixel; if (itsDepth == 1) { forePixel = JXImageMask::ColorToBit(foreColor); backPixel = JXImageMask::ColorToBit(backColor); } else { forePixel = itsColormap->GetXPixel(foreColor); backPixel = itsColormap->GetXPixel(backColor); } itsPixmap = XCreatePixmapFromBitmapData(*itsDisplay, itsDisplay->GetRootWindow(), (char*) bitmap.data, bitmap.w, bitmap.h, forePixel, backPixel, itsDepth); assert( itsPixmap != None ); if (itsDepth != itsDisplay->GetDepth()) { itsGC = new JXGC(itsDisplay, itsColormap, itsPixmap); assert( itsGC != NULL ); } RegisterColor(foreColor); RegisterColor(backColor); }
JXImage::JXImage ( const JXImage& source, const JRect& rect ) : JImage(rect.width(), rect.height(), source.GetColormap()) { JXImageX(source.itsDisplay, source.itsColormap, source.itsDepth); itsDefState = source.itsDefState; if (source.itsGC != NULL) { ForcePrivateGC(); } Pixmap sourcePixmap; if (source.itsPixmap != None) { sourcePixmap = source.itsPixmap; } else { sourcePixmap = source.CreatePixmap(); } itsPixmap = XCreatePixmap(*itsDisplay, itsDisplay->GetRootWindow(), GetWidth(), GetHeight(), itsDepth); assert( itsPixmap != None ); (GetGC())->CopyPixels(sourcePixmap, rect.left, rect.top, GetWidth(), GetHeight(), itsPixmap, 0,0); if (source.itsPixmap == None) { XFreePixmap(*itsDisplay, sourcePixmap); } if (source.itsMask != NULL) { itsMask = new JXImageMask(*(source.itsMask), rect); assert( itsMask != NULL ); } CopyColorList(source); }
JXImage::JXImage ( const JXImage& source ) : JImage(source) { JXImageX(source.itsDisplay, source.itsColormap, source.itsDepth); itsDefState = source.itsDefState; if (source.itsGC != NULL) { ForcePrivateGC(); } if (source.itsPixmap != None) { itsPixmap = source.CreatePixmap(); } if (source.itsImage != NULL) { Pixmap tempPixmap = source.CreatePixmap(); itsImage = XGetImage(*itsDisplay, tempPixmap, 0,0, GetWidth(), GetHeight(), AllPlanes, ZPixmap); assert( itsImage != NULL ); XFreePixmap(*itsDisplay, tempPixmap); } if (source.itsMask != NULL) { itsMask = new JXImageMask(*(source.itsMask)); assert( itsMask != NULL ); } CopyColorList(source); }
void JXImage::JXImageFromDrawable ( JXDisplay* display, Drawable source, const JRect& origRect ) { JXImageX(display); JRect rect = origRect; { Window rootWindow; int x,y; unsigned int w,h, bw, depth; XGetGeometry(*itsDisplay, source, &rootWindow, &x, &y, &w, &h, &bw, &depth); itsDepth = depth; if (rect.IsEmpty()) { SetDimensions(w,h); rect = GetBounds(); } } itsPixmap = XCreatePixmap(*itsDisplay, itsDisplay->GetRootWindow(), GetWidth(), GetHeight(), itsDepth); assert( itsPixmap != None ); if (itsDepth != itsDisplay->GetDepth()) { itsGC = new JXGC(itsDisplay, itsPixmap); assert( itsGC != NULL ); } (GetGC())->CopyPixels(source, rect.left, rect.top, rect.width(), rect.height(), itsPixmap, 0,0); }
JXImage::JXImage ( JXDisplay* display, JXColormap* colormap, const JCoordinate width, const JCoordinate height, const JColorIndex origInitColor, const JSize depth ) : JImage(width, height, colormap) { JXImageX(display, colormap, depth); const JColorIndex initColor = (origInitColor == kJXTransparentColor && itsDepth > 1 ? colormap->GetDefaultBackColor() : origInitColor); itsPixmap = XCreatePixmap(*itsDisplay, itsDisplay->GetRootWindow(), width, height, itsDepth); assert( itsPixmap != None ); // We need a private GC so we can draw. itsGC = new JXGC(itsDisplay, itsColormap, itsPixmap); assert( itsGC != NULL ); itsGC->SetDrawingColor(initColor); itsGC->FillRect(itsPixmap, 0,0, width, height); RegisterColor(initColor); // We don't convert to an image because the user probably wants // to draw to us. }
void JXImage::JXImageFromDrawable ( JXDisplay* display, JXColormap* colormap, Drawable source, const JRect& origRect ) { JXImageX(display, colormap); JRect rect = origRect; { Window rootWindow; int x,y; unsigned int w,h, bw, depth; XGetGeometry(*itsDisplay, source, &rootWindow, &x, &y, &w, &h, &bw, &depth); itsDepth = depth; if (rect.IsEmpty()) { SetDimensions(w,h); rect = GetBounds(); } } itsPixmap = XCreatePixmap(*itsDisplay, itsDisplay->GetRootWindow(), GetWidth(), GetHeight(), itsDepth); assert( itsPixmap != None ); if (itsDepth != itsDisplay->GetDepth()) { itsGC = new JXGC(itsDisplay, itsColormap, itsPixmap); assert( itsGC != NULL ); } (GetGC())->CopyPixels(source, rect.left, rect.top, rect.width(), rect.height(), itsPixmap, 0,0); // register the colors that are used in the drawable const JBoolean needRegister = JConvertToBoolean( itsDepth > 1 && !itsColormap->AllColorsPreallocated() ); if (needRegister && itsColormap->GetVisualClass() == DirectColor) { // With DirectColor, there could be just as many colors as pixels, // so we actually waste time (and memory!) by building a list of // X pixel values before converting them to JColorIndices. ConvertToImage(); const JCoordinate w = GetWidth(); const JCoordinate h = GetHeight(); for (JCoordinate y=0; y<=h; y++) { for (JCoordinate x=0; x<=w; x++) { JColorIndex color; const unsigned long xPixel = XGetPixel(itsImage, x,y); itsColormap->AllocateStaticColor(xPixel, &color); RegisterColor(color, kJFalse); } } } else if (needRegister) // using PseudoColor => small # of X pixels { // By building a list of unique X pixel values and then converting // each once, we reduce O(W H (alloc)) to O(W H) + O(P (alloc)), // where W=width, H=height, P=# of distinct pixels in Drawable. // Typically, W*H is much larger than P. Alloc usually requires // a server call. JIndex i; // build boolean array telling which X pixel values are used ConvertToImage(); const JSize maxColorCount = itsColormap->GetMaxColorCount(); char* pixelUsed = new char [ maxColorCount ]; assert( pixelUsed != NULL ); for (i=0; i<maxColorCount; i++) { pixelUsed[i] = 0; } const JCoordinate w = GetWidth(); const JCoordinate h = GetHeight(); for (JCoordinate y=0; y<=h; y++) { for (JCoordinate x=0; x<=w; x++) { const unsigned long xPixel = XGetPixel(itsImage, x,y); assert( xPixel < maxColorCount ); pixelUsed [ xPixel ] = 1; } } // register each X pixel value that is used JColorIndex color; for (i=0; i<maxColorCount; i++) { if (pixelUsed[i]) { itsColormap->AllocateStaticColor(i, &color); RegisterColor(color, kJFalse); } } delete [] pixelUsed; } }