mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
made some changes
This commit is contained in:
parent
7767fbf930
commit
f349e57fda
@ -30,11 +30,13 @@ static NS_DEFINE_IID(kIImageIID, NS_IIMAGE_IID);
|
|||||||
nsImageUnix :: nsImageUnix()
|
nsImageUnix :: nsImageUnix()
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
|
printf("==========================\nnsImageUnix :: nsImageUnix()\n");
|
||||||
mImage = nsnull ;
|
mImage = nsnull ;
|
||||||
|
mImageBits = nsnull;
|
||||||
mWidth = 0;
|
mWidth = 0;
|
||||||
mHeight = 0;
|
mHeight = 0;
|
||||||
mDepth = 0;
|
mDepth = 0;
|
||||||
|
mColorMap = nsnull;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------
|
//------------------------------------------------------------
|
||||||
@ -45,6 +47,11 @@ nsImageUnix :: ~nsImageUnix()
|
|||||||
XDestroyImage(mImage);
|
XDestroyImage(mImage);
|
||||||
mImage = nsnull;
|
mImage = nsnull;
|
||||||
}
|
}
|
||||||
|
if(nsnull != mImageBits)
|
||||||
|
{
|
||||||
|
//delete[] (PRUint8*)mImageBits;
|
||||||
|
mImageBits = nsnull;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS(nsImageUnix, kIImageIID);
|
NS_IMPL_ISUPPORTS(nsImageUnix, kIImageIID);
|
||||||
@ -57,9 +64,33 @@ nsresult nsImageUnix :: Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth,nsM
|
|||||||
mHeight = aHeight;
|
mHeight = aHeight;
|
||||||
mDepth = aDepth;
|
mDepth = aDepth;
|
||||||
|
|
||||||
|
ComputePaletteSize(aDepth);
|
||||||
|
|
||||||
// create the memory for the image
|
// create the memory for the image
|
||||||
ComputMetrics();
|
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;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
@ -73,6 +104,27 @@ void nsImageUnix::ComputMetrics()
|
|||||||
mSizeImage = mRowBytes * mHeight;
|
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,
|
PRBool nsImageUnix :: Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface, PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
|
||||||
PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight)
|
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)
|
if (nsnull == mImage)
|
||||||
return PR_FALSE;
|
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;
|
return PR_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,8 +184,14 @@ PRBool nsImageUnix :: Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurf
|
|||||||
PRBool nsImageUnix :: Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface,
|
PRBool nsImageUnix :: Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface,
|
||||||
PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
|
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)
|
if (nsnull == mImage)
|
||||||
return PR_FALSE;
|
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;
|
return PR_TRUE;
|
||||||
}
|
}
|
||||||
@ -159,36 +224,38 @@ nsresult nsImageUnix::Optimize(nsDrawingSurface aDrawingSurface)
|
|||||||
|
|
||||||
void nsImageUnix::CreateImage(nsDrawingSurface aSurface)
|
void nsImageUnix::CreateImage(nsDrawingSurface aSurface)
|
||||||
{
|
{
|
||||||
XWindowAttributes wa;
|
XWindowAttributes wa;
|
||||||
PRUint32 wdepth;
|
PRUint32 wdepth;
|
||||||
Visual * visual ;
|
Visual * visual ;
|
||||||
PRUint32 format ;
|
PRUint32 format ;
|
||||||
nsDrawingSurfaceUnix *unixdrawing =(nsDrawingSurfaceUnix*) aSurface;
|
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,
|
unixdrawing->drawable,
|
||||||
&wa);
|
&wa);
|
||||||
|
|
||||||
/* XXX What if mDepth != wDepth */
|
/* XXX What if mDepth != wDepth */
|
||||||
wdepth = wa.depth;
|
wdepth = wa.depth;
|
||||||
visual = wa.visual;
|
visual = wa.visual;
|
||||||
|
|
||||||
/* Need to support monochrome too */
|
/* Need to support monochrome too */
|
||||||
if (visual->c_class == TrueColor || visual->c_class == DirectColor)
|
if (visual->c_class == TrueColor || visual->c_class == DirectColor)
|
||||||
format = ZPixmap;
|
format = ZPixmap;
|
||||||
else
|
else
|
||||||
format = XYPixmap;
|
format = XYPixmap;
|
||||||
|
|
||||||
mImage = ::XCreateImage(unixdrawing->display,
|
mImage = ::XCreateImage(unixdrawing->display,
|
||||||
visual,
|
visual,
|
||||||
wdepth,
|
wdepth,
|
||||||
format,
|
format,
|
||||||
0,
|
0,
|
||||||
data,
|
mImageBits,
|
||||||
mWidth,
|
mWidth,
|
||||||
mHeight,
|
mHeight,
|
||||||
8,0);
|
8,0);
|
||||||
|
}
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
@ -36,14 +36,14 @@ public:
|
|||||||
@see nsIImage.h
|
@see nsIImage.h
|
||||||
*/
|
*/
|
||||||
virtual PRInt32 GetHeight() { return mHeight; }
|
virtual PRInt32 GetHeight() { return mHeight; }
|
||||||
virtual PRInt32 GetWidth() { return mDepth; }
|
virtual PRInt32 GetWidth() { return mWidth; }
|
||||||
virtual PRUint8* GetBits() { return nsnull; }
|
virtual PRUint8* GetBits() { printf("return Bits 0x%x\n", mImageBits);return mImageBits; }
|
||||||
virtual void* GetBitInfo() { return nsnull; }
|
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 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
|
||||||
virtual PRBool Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface, PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
|
virtual PRBool Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface, PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
|
||||||
PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
|
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 void ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *aUpdateRect);
|
||||||
virtual nsresult Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequirements aMaskRequirements);
|
virtual nsresult Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequirements aMaskRequirements);
|
||||||
virtual PRBool IsOptimized() { return (mImage!=nsnull); }
|
virtual PRBool IsOptimized() { return (mImage!=nsnull); }
|
||||||
@ -87,6 +87,8 @@ private:
|
|||||||
* Calculate the amount of memory needed for the initialization of the image
|
* Calculate the amount of memory needed for the initialization of the image
|
||||||
*/
|
*/
|
||||||
void ComputMetrics();
|
void ComputMetrics();
|
||||||
|
void ComputePaletteSize(PRIntn nBitCount);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PRInt32 mWidth;
|
PRInt32 mWidth;
|
||||||
@ -94,10 +96,12 @@ private:
|
|||||||
PRInt32 mDepth; // bits per pixel
|
PRInt32 mDepth; // bits per pixel
|
||||||
PRInt32 mRowBytes;
|
PRInt32 mRowBytes;
|
||||||
Pixmap mThePixMap;
|
Pixmap mThePixMap;
|
||||||
PRUint8* mImageBits;
|
PRUint8 * mImageBits;
|
||||||
PRInt32 mSizeImage;
|
PRInt32 mSizeImage;
|
||||||
XImage *mImage ;
|
XImage * mImage ;
|
||||||
|
nsColorMap *mColorMap;
|
||||||
|
PRInt16 mNumPalleteColors;
|
||||||
|
PRInt8 mNumBytesPixel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user