adding imageframe/container to xlib

This commit is contained in:
pavlov%netscape.com 2001-01-23 20:46:36 +00:00
parent 7fc4e546c4
commit d8f78afc03
6 changed files with 281 additions and 67 deletions

View File

@ -33,7 +33,8 @@ IS_COMPONENT = 1
CPPSRCS = \
nsGfxFactory.cpp \
nsImage.cpp \
nsImageContainer.cpp \
nsImageFrame.cpp \
$(NULL)
SHARED_LIBRARY_LIBS = $(DIST)/lib/libgfx_base.a

View File

@ -24,18 +24,24 @@
#include "nsIGenericFactory.h"
#include "nsIModule.h"
#include "nsImage.h"
#include "nsImageContainer.h"
#include "nsImageFrame.h"
// objects that just require generic constructors
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImage)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageContainer)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageFrame)
static nsModuleComponentInfo components[] =
{
{ "xlib image",
NS_IMAGE_CID,
{ "xlib image container",
NS_IMAGECONTAINER_CID,
"@mozilla.org/gfx/image;2",
nsImageConstructor, },
nsImageContainerConstructor, },
{ "xlib image frame",
NS_IMAGEFRAME_CID,
"@mozilla.org/gfx/image/frame;2",
nsImageFrameConstructor, },
};
NS_IMPL_NSGETMODULE("nsGfx2Module", components)

View File

@ -0,0 +1,129 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#include "nsImageContainer.h"
#include "nsUnitConverters.h"
NS_IMPL_ISUPPORTS1(nsImageContainer, nsIImageContainer)
nsImageContainer::nsImageContainer()
{
NS_INIT_ISUPPORTS();
/* member initializers and constructor code */
mCurrentFrame = 0;
}
nsImageContainer::~nsImageContainer()
{
/* destructor code */
mFrames.Clear();
}
/* void init (in gfx_dimension aWidth, in gfx_dimension aHeight); */
NS_IMETHODIMP nsImageContainer::Init(gfx_dimension aWidth, gfx_dimension aHeight)
{
if (aWidth <= 0 || aHeight <= 0) {
printf("error - negative image size\n");
return NS_ERROR_FAILURE;
}
mSize.SizeTo(aWidth, aHeight);
return NS_OK;
}
/* readonly attribute gfx_dimension width; */
NS_IMETHODIMP nsImageContainer::GetWidth(gfx_dimension *aWidth)
{
*aWidth = mSize.width;
return NS_OK;
}
/* readonly attribute gfx_dimension height; */
NS_IMETHODIMP nsImageContainer::GetHeight(gfx_dimension *aHeight)
{
*aHeight = mSize.height;
return NS_OK;
}
/* readonly attribute nsIImageFrame currentFrame; */
NS_IMETHODIMP nsImageContainer::GetCurrentFrame(nsIImageFrame * *aCurrentFrame)
{
return this->GetFrameAt(mCurrentFrame, aCurrentFrame);
}
/* readonly attribute unsigned long numFrames; */
NS_IMETHODIMP nsImageContainer::GetNumFrames(PRUint32 *aNumFrames)
{
return mFrames.Count(aNumFrames);
}
/* nsIImageFrame getFrameAt (in unsigned long index); */
NS_IMETHODIMP nsImageContainer::GetFrameAt(PRUint32 index, nsIImageFrame **_retval)
{
nsISupports *sup = mFrames.ElementAt(index);
if (!sup)
return NS_ERROR_FAILURE;
*_retval = NS_REINTERPRET_CAST(nsIImageFrame *, sup);
return NS_OK;
}
/* void appendFrame (in nsIImageFrame item); */
NS_IMETHODIMP nsImageContainer::AppendFrame(nsIImageFrame *item)
{
return mFrames.AppendElement(NS_REINTERPRET_CAST(nsISupports*, item));
}
/* void removeFrame (in nsIImageFrame item); */
NS_IMETHODIMP nsImageContainer::RemoveFrame(nsIImageFrame *item)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* nsIEnumerator enumerate (); */
NS_IMETHODIMP nsImageContainer::Enumerate(nsIEnumerator **_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void clear (); */
NS_IMETHODIMP nsImageContainer::Clear()
{
return mFrames.Clear();
}
/* attribute long loopCount; */
NS_IMETHODIMP nsImageContainer::GetLoopCount(PRInt32 *aLoopCount)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsImageContainer::SetLoopCount(PRInt32 aLoopCount)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@ -0,0 +1,53 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#include "nsIImageContainer.h"
#include "nsSize2.h"
#include "nsSupportsArray.h"
#define NS_IMAGECONTAINER_CID \
{ /* 284f7652-1dd2-11b2-b0b4-d40aab841150 */ \
0x284f7652, \
0x1dd2, \
0x11b2, \
{0xb0, 0xb4, 0xd4, 0x0a, 0xab, 0x84, 0x11, 0x50} \
}
class nsImageContainer : public nsIImageContainer
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIIMAGECONTAINER
nsImageContainer();
virtual ~nsImageContainer();
private:
/* additional members */
nsSupportsArray mFrames;
nsSize2 mSize;
PRUint32 mCurrentFrame;
};

View File

@ -14,47 +14,44 @@
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2000-2001 Netscape Communications Corporation. All
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#include "nsImage.h"
#include "nsImageFrame.h"
#include "nsUnitConverters.h"
NS_IMPL_ISUPPORTS1(nsImage, nsIImage2)
NS_IMPL_ISUPPORTS1(nsImageFrame, nsIImageFrame)
nsImage::nsImage()
nsImageFrame::nsImageFrame() :
mBits(nsnull)
{
NS_INIT_ISUPPORTS();
/* member initializers and constructor code */
}
nsImageFrame::~nsImageFrame()
{
/* destructor code */
delete[] mBits;
mBits = nsnull;
}
nsImage::~nsImage()
{
#if 0
/* destructor code */
if (mBits) {
delete[] mBits;
mBits = nsnull;
}
#endif
}
/* void init (in gfx_dimension aWidth, in gfx_dimension aHeight, in gfx_format aFormat); */
NS_IMETHODIMP nsImage::Init(gfx_dimension aWidth, gfx_dimension aHeight, gfx_format aFormat)
/* void init (in gfx_coord aX, in gfx_coord aY, in gfx_dimension aWidth, in gfx_dimension aHeight, in gfx_format aFormat); */
NS_IMETHODIMP nsImageFrame::Init(gfx_coord aX, gfx_coord aY, gfx_dimension aWidth, gfx_dimension aHeight, gfx_format aFormat)
{
if (aWidth <= 0 || aHeight <= 0) {
printf("error - negative image size\n");
return NS_ERROR_FAILURE;
}
mSize.SizeTo(aWidth, aHeight);
delete[] mBits;
mRect.SetRect(aX, aY, aWidth, aHeight);
mFormat = aFormat;
switch (aFormat) {
@ -71,7 +68,7 @@ NS_IMETHODIMP nsImage::Init(gfx_dimension aWidth, gfx_dimension aHeight, gfx_for
break;
}
PRInt32 ceilWidth(GFXCoordToIntCeil(mSize.width));
PRInt32 ceilWidth(GFXCoordToIntCeil(mRect.width));
mBytesPerRow = (ceilWidth * mDepth) >> 5;
@ -79,67 +76,78 @@ NS_IMETHODIMP nsImage::Init(gfx_dimension aWidth, gfx_dimension aHeight, gfx_for
mBytesPerRow++;
mBytesPerRow <<= 2;
mBitsLength = mBytesPerRow * GFXCoordToIntCeil(mSize.height);
mBitsLength = mBytesPerRow * GFXCoordToIntCeil(mRect.height);
mBits = new PRUint8[mBitsLength];
return NS_OK;
}
/* void initFromDrawable (in nsIDrawable aDrawable, in gfx_coord aX, in gfx_coord aY, in gfx_dimension aWidth, in gfx_dimension aHeight); */
NS_IMETHODIMP nsImage::InitFromDrawable(nsIDrawable *aDrawable, gfx_coord aX, gfx_coord aY, gfx_dimension aWidth, gfx_dimension aHeight)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute gfx_dimension width; */
NS_IMETHODIMP nsImage::GetWidth(gfx_dimension *aWidth)
/* readonly attribute gfx_coord x; */
NS_IMETHODIMP nsImageFrame::GetX(gfx_coord *aX)
{
if (!mBits)
return NS_ERROR_NOT_INITIALIZED;
*aWidth = mSize.width;
*aX = mRect.x;
return NS_OK;
}
/* readonly attribute gfx_coord y; */
NS_IMETHODIMP nsImageFrame::GetY(gfx_coord *aY)
{
if (!mBits)
return NS_ERROR_NOT_INITIALIZED;
*aY = mRect.y;
return NS_OK;
}
/* readonly attribute gfx_dimension width; */
NS_IMETHODIMP nsImageFrame::GetWidth(gfx_dimension *aWidth)
{
if (!mBits)
return NS_ERROR_NOT_INITIALIZED;
*aWidth = mRect.width;
return NS_OK;
}
/* readonly attribute gfx_dimension height; */
NS_IMETHODIMP nsImage::GetHeight(gfx_dimension *aHeight)
NS_IMETHODIMP nsImageFrame::GetHeight(gfx_dimension *aHeight)
{
if (!mBits)
return NS_ERROR_NOT_INITIALIZED;
*aHeight = mSize.height;
*aHeight = mRect.height;
return NS_OK;
}
#include <gdk/gdk.h>
#include <gdk/gdkrgb.h>
#include <gdk/gdkx.h>
#include <gdk/gdkprivate.h>
/* readonly attribute gfx_format format; */
NS_IMETHODIMP nsImage::GetFormat(gfx_format *aFormat)
/* readonly attribute nsRect2 rect; */
NS_IMETHODIMP nsImageFrame::GetRect(nsRect2 **aRect)
{
return NS_ERROR_NOT_IMPLEMENTED;
if (!mBits)
return NS_ERROR_NOT_INITIALIZED;
GdkWindow *rw = gdk_window_lookup(GDK_ROOT_WINDOW());
GdkGC *gc = gdk_gc_new(rw);
gdk_draw_rgb_image(rw, gc,
0, 0, mSize.width, mSize.height,
GDK_RGB_DITHER_MAX,
mBits, 3*mSize.width);
gdk_gc_unref(gc);
// *aRect = mRect;
return NS_OK;
}
/* readonly attribute gfx_format format; */
NS_IMETHODIMP nsImageFrame::GetFormat(gfx_format *aFormat)
{
if (!mBits)
return NS_ERROR_NOT_INITIALIZED;
*aFormat = mFormat;
return NS_OK;
}
/* readonly attribute unsigned long bytesPerRow; */
NS_IMETHODIMP nsImage::GetBytesPerRow(PRUint32 *aBytesPerRow)
NS_IMETHODIMP nsImageFrame::GetBytesPerRow(PRUint32 *aBytesPerRow)
{
if (!mBits)
return NS_ERROR_NOT_INITIALIZED;
@ -149,7 +157,7 @@ NS_IMETHODIMP nsImage::GetBytesPerRow(PRUint32 *aBytesPerRow)
}
/* readonly attribute unsigned long bitsLength; */
NS_IMETHODIMP nsImage::GetBitsLength(PRUint32 *aBitsLength)
NS_IMETHODIMP nsImageFrame::GetBitsLength(PRUint32 *aBitsLength)
{
if (!mBits)
return NS_ERROR_NOT_INITIALIZED;
@ -159,7 +167,7 @@ NS_IMETHODIMP nsImage::GetBitsLength(PRUint32 *aBitsLength)
}
/* void getBits([array, size_is(length)] out PRUint8 bits, out unsigned long length); */
NS_IMETHODIMP nsImage::GetBits(PRUint8 **aBits, PRUint32 *length)
NS_IMETHODIMP nsImageFrame::GetBits(PRUint8 **aBits, PRUint32 *length)
{
if (!mBits)
return NS_ERROR_NOT_INITIALIZED;
@ -171,12 +179,25 @@ NS_IMETHODIMP nsImage::GetBits(PRUint8 **aBits, PRUint32 *length)
}
/* void setBits ([array, size_is (length), const] in PRUint8 data, in unsigned long length, in long offset); */
NS_IMETHODIMP nsImage::SetBits(const PRUint8 *data, PRUint32 length, PRInt32 offset)
NS_IMETHODIMP nsImageFrame::SetBits(const PRUint8 *data, PRUint32 length, PRInt32 offset)
{
if (!mBits)
return NS_ERROR_NOT_INITIALIZED;
if (((PRUint32)offset + length) > mBitsLength)
return NS_ERROR_FAILURE;
memcpy(mBits + offset, data, length);
return NS_OK;
}
/* attribute long timeout; */
NS_IMETHODIMP nsImageFrame::GetTimeout(PRInt32 *aTimeout)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsImageFrame::SetTimeout(PRInt32 aTimeout)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@ -21,27 +21,31 @@
* Stuart Parmenter <pavlov@netscape.com>
*/
#include "nsIImage2.h"
#include "nsIImageFrame.h"
#include "nsSize2.h"
#include "nsRect2.h"
#define NS_IMAGE_CID \
{0x73c72e6c, 0x1dd2, 0x11b2, \
{ 0x98, 0xb7, 0xae, 0x59, 0x35, 0xee, 0x63, 0xf5 }}
#define NS_IMAGEFRAME_CID \
{ /* 27d55516-1dd2-11b2-9b33-d9a6328f49bd */ \
0x27d55516, \
0x1dd2, \
0x11b2, \
{0x9b, 0x33, 0xd9, 0xa6, 0x32, 0x8f, 0x49, 0xbd} \
}
class nsImage : public nsIImage2
class nsImageFrame : public nsIImageFrame
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIIMAGE2
NS_DECL_NSIIMAGEFRAME
nsImage();
virtual ~nsImage();
nsImageFrame();
virtual ~nsImageFrame();
private:
/* additional members */
PRUint32 mBytesPerRow;
nsSize2 mSize;
nsRect2 mRect;
gfx_format mFormat;
PRUint32 mBitsLength;