made some changes

This commit is contained in:
dcone 1998-06-18 22:04:23 +00:00
parent 7767fbf930
commit f349e57fda
2 changed files with 98 additions and 27 deletions

View File

@ -30,11 +30,13 @@ static NS_DEFINE_IID(kIImageIID, NS_IIMAGE_IID);
nsImageUnix :: nsImageUnix()
{
NS_INIT_REFCNT();
printf("==========================\nnsImageUnix :: nsImageUnix()\n");
mImage = nsnull ;
mImageBits = nsnull;
mWidth = 0;
mHeight = 0;
mDepth = 0;
mColorMap = nsnull;
}
//------------------------------------------------------------
@ -45,6 +47,11 @@ nsImageUnix :: ~nsImageUnix()
XDestroyImage(mImage);
mImage = nsnull;
}
if(nsnull != mImageBits)
{
//delete[] (PRUint8*)mImageBits;
mImageBits = nsnull;
}
}
NS_IMPL_ISUPPORTS(nsImageUnix, kIImageIID);
@ -57,9 +64,33 @@ nsresult nsImageUnix :: Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth,nsM
mHeight = aHeight;
mDepth = aDepth;
ComputePaletteSize(aDepth);
// create the memory for the image
ComputMetrics();
mImageBits = (PRUint8*) new PRUint8[mSizeImage];
printf("******************\nWidth %d Height %d Depth %d mSizeImage %d\n",
mWidth, mHeight, mDepth, mSizeImage);
//mImageBits = (PRUint8*) new PRUint8[mSizeImage];
char * buf = (char*) malloc(mSizeImage+1);
printf("Buf address %x\n", buf);
mImageBits = buf;
if (mImageBits == nsnull) {
printf("Bits are null!\n");
}
mColorMap = new nsColorMap;
if (mColorMap != nsnull)
{
mColorMap->NumColors = mNumPalleteColors;
mColorMap->Index = new PRUint8[3 * mNumPalleteColors];
// XXX Note: I added this because purify claims that we make a
// copy of the memory (which we do!). I'm not sure if this
// matters or not, but this shutup purify.
memset(mColorMap->Index, 0, sizeof(PRUint8) * (3 * mNumPalleteColors));
}
return NS_OK;
}
@ -73,6 +104,27 @@ void nsImageUnix::ComputMetrics()
mSizeImage = mRowBytes * mHeight;
}
// figure out how big our palette needs to be
void nsImageUnix :: ComputePaletteSize(PRIntn nBitCount)
{
switch (nBitCount)
{
case 8:
mNumPalleteColors = 256;
mNumBytesPixel = 1;
break;
case 24:
mNumPalleteColors = 0;
mNumBytesPixel = 3;
break;
default:
mNumPalleteColors = -1;
mNumBytesPixel = 0;
break;
}
}
//------------------------------------------------------------
@ -113,9 +165,16 @@ void nsImageUnix :: ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsR
PRBool nsImageUnix :: Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface, PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight)
{
nsDrawingSurfaceUnix *unixdrawing =(nsDrawingSurfaceUnix*) aSurface;
printf("Draw::XPutImage %d %d %d %d %d %d\n", aSX,aSY,aDX,aDY,aDWidth,aDHeight);
if (nsnull == mImage)
return PR_FALSE;
printf("Draw::XPutImage %d %d %d %d %d %d\n", aSX,aSY,aDX,aDY,aDWidth,aDHeight);
XPutImage(unixdrawing->display,unixdrawing->drawable,unixdrawing->gc,mImage,
aSX,aSY,aDX,aDY,aDWidth,aDHeight);
return PR_TRUE;
}
@ -125,8 +184,14 @@ PRBool nsImageUnix :: Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurf
PRBool nsImageUnix :: Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface,
PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
nsDrawingSurfaceUnix *unixdrawing =(nsDrawingSurfaceUnix*) aSurface;
printf("Draw::XPutImage2 %d %d %d %d %d %d\n", aX,aY,aX,aY,aWidth,aHeight);
if (nsnull == mImage)
return PR_FALSE;
printf("Draw::XPutImage2 %d %d %d %d %d %d\n", aX,aY,aX,aY,aWidth,aHeight);
XPutImage(unixdrawing->display,unixdrawing->drawable,unixdrawing->gc,mImage,
aX,aY,aX,aY,aWidth,aHeight);
return PR_TRUE;
}
@ -159,36 +224,38 @@ nsresult nsImageUnix::Optimize(nsDrawingSurface aDrawingSurface)
void nsImageUnix::CreateImage(nsDrawingSurface aSurface)
{
XWindowAttributes wa;
PRUint32 wdepth;
Visual * visual ;
PRUint32 format ;
XWindowAttributes wa;
PRUint32 wdepth;
Visual * visual ;
PRUint32 format ;
nsDrawingSurfaceUnix *unixdrawing =(nsDrawingSurfaceUnix*) aSurface;
char * data = (char *) PR_Malloc(sizeof(char) * mWidth * mHeight * mDepth);
//char * data = (char *) PR_Malloc(sizeof(char) * mWidth * mHeight * mDepth);
::XGetWindowAttributes(unixdrawing->display,
if(mImageBits)
{
::XGetWindowAttributes(unixdrawing->display,
unixdrawing->drawable,
&wa);
/* XXX What if mDepth != wDepth */
wdepth = wa.depth;
visual = wa.visual;
/* XXX What if mDepth != wDepth */
wdepth = wa.depth;
visual = wa.visual;
/* Need to support monochrome too */
if (visual->c_class == TrueColor || visual->c_class == DirectColor)
format = ZPixmap;
else
format = XYPixmap;
/* Need to support monochrome too */
if (visual->c_class == TrueColor || visual->c_class == DirectColor)
format = ZPixmap;
else
format = XYPixmap;
mImage = ::XCreateImage(unixdrawing->display,
mImage = ::XCreateImage(unixdrawing->display,
visual,
wdepth,
format,
0,
data,
mImageBits,
mWidth,
mHeight,
8,0);
}
return ;
}

View File

@ -36,14 +36,14 @@ public:
@see nsIImage.h
*/
virtual PRInt32 GetHeight() { return mHeight; }
virtual PRInt32 GetWidth() { return mDepth; }
virtual PRUint8* GetBits() { return nsnull; }
virtual PRInt32 GetWidth() { return mWidth; }
virtual PRUint8* GetBits() { printf("return Bits 0x%x\n", mImageBits);return mImageBits; }
virtual void* GetBitInfo() { return nsnull; }
virtual PRInt32 GetLineStride() {return 0; }
virtual PRInt32 GetLineStride() {return mRowBytes; }
virtual PRBool Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface, PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
virtual PRBool Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface, PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
virtual nsColorMap* GetColorMap() {return nsnull;}
virtual nsColorMap* GetColorMap() {return mColorMap;}
virtual void ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *aUpdateRect);
virtual nsresult Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequirements aMaskRequirements);
virtual PRBool IsOptimized() { return (mImage!=nsnull); }
@ -87,6 +87,8 @@ private:
* Calculate the amount of memory needed for the initialization of the image
*/
void ComputMetrics();
void ComputePaletteSize(PRIntn nBitCount);
private:
PRInt32 mWidth;
@ -94,10 +96,12 @@ private:
PRInt32 mDepth; // bits per pixel
PRInt32 mRowBytes;
Pixmap mThePixMap;
PRUint8* mImageBits;
PRInt32 mSizeImage;
XImage *mImage ;
PRUint8 * mImageBits;
PRInt32 mSizeImage;
XImage * mImage ;
nsColorMap *mColorMap;
PRInt16 mNumPalleteColors;
PRInt8 mNumBytesPixel;
};
#endif