mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-28 13:21:28 +00:00
mering from the IMGLIB2_20010126_BRANCH
This commit is contained in:
parent
276a183d07
commit
2f41c5d5c4
43
gfx2/src/Makefile.in
Normal file
43
gfx2/src/Makefile.in
Normal file
@ -0,0 +1,43 @@
|
||||
#
|
||||
# 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) 2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Stuart Parmenter <pavlov@netscape.com>
|
||||
#
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = gfx2
|
||||
#LIBRARY_NAME = gfx_base
|
||||
|
||||
#CPPSRCS = \
|
||||
# $(NULL)
|
||||
|
||||
DIRS = gtk
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a static lib.
|
||||
#override NO_SHARED_LIB=1
|
||||
#override NO_STATIC_LIB=
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
66
gfx2/src/gtk/Makefile.in
Normal file
66
gfx2/src/gtk/Makefile.in
Normal file
@ -0,0 +1,66 @@
|
||||
#
|
||||
# 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) 2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Stuart Parmenter <pavlov@netscape.com>
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = gfx2
|
||||
XPIDL_MODULE = gfx2gtk
|
||||
LIBRARY_NAME = gfx2
|
||||
IS_COMPONENT = 1
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsPIImageContainerGtk.idl \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
nsGfxFactory.cpp \
|
||||
nsImageContainer.cpp \
|
||||
nsImageFrame.cpp \
|
||||
$(NULL)
|
||||
|
||||
CSRCS = \
|
||||
XIE.c \
|
||||
$(NULL)
|
||||
|
||||
#SHARED_LIBRARY_LIBS = $(DIST)/lib/libgfx_base.a
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
EXTRA_DSO_LDOPTS += -L$(DIST)/bin
|
||||
EXTRA_DSO_LDOPTS += $(TK_LIBS) -lgdk_pixbuf -lXIE
|
||||
CXXFLAGS += $(TK_CFLAGS)
|
||||
CFLAGS += $(TK_CFLAGS)
|
||||
|
||||
EXTRA_DSO_LDOPTS += \
|
||||
$(NSPR_LIBS) \
|
||||
-lxpcom \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(OS_ARCH), Linux)
|
||||
DEFINES += -D_BSD_SOURCE
|
||||
endif
|
||||
|
197
gfx2/src/gtk/XIE.c
Normal file
197
gfx2/src/gtk/XIE.c
Normal file
@ -0,0 +1,197 @@
|
||||
/* -*- 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>
|
||||
* Syd Logan <syd@netscape.com>
|
||||
*/
|
||||
|
||||
#include "drawers.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
#include <X11/extensions/XIElib.h>
|
||||
|
||||
/*#define DEBUG_XIE 1*/
|
||||
|
||||
static PRBool inited = PR_FALSE;
|
||||
static XiePhotospace gPhotospace;
|
||||
static XiePhotoElement *photoElement;
|
||||
|
||||
static void
|
||||
DoFlo(Display *display,
|
||||
Drawable aDest,
|
||||
GC aGC,
|
||||
Drawable aSrc,
|
||||
PRInt32 aSrcWidth,
|
||||
PRInt32 aSrcHeight,
|
||||
PRInt32 aSX,
|
||||
PRInt32 aSY,
|
||||
PRInt32 aSWidth,
|
||||
PRInt32 aSHeight,
|
||||
PRInt32 aDX,
|
||||
PRInt32 aDY,
|
||||
PRInt32 aDWidth,
|
||||
PRInt32 aDHeight)
|
||||
{
|
||||
XieExtensionInfo *info;
|
||||
float coeffs[6];
|
||||
XieConstant constant;
|
||||
XiePhototag idx = 0, src;
|
||||
/* static PRBool firsttime = PR_TRUE;
|
||||
static XiePhotomap pmap;
|
||||
*/
|
||||
|
||||
/* create the pretty flo graph */
|
||||
|
||||
|
||||
|
||||
/* import */
|
||||
XieFloImportDrawable(&photoElement[idx], aSrc, aSX, aSY, aSWidth, aSHeight, 0, PR_FALSE);
|
||||
++idx;
|
||||
src = idx;
|
||||
|
||||
/* do the scaling stuff */
|
||||
coeffs[0] = (float)aSrcWidth / (float)aDWidth;
|
||||
coeffs[1] = 0.0;
|
||||
coeffs[2] = 0.0;
|
||||
coeffs[3] = (float)aSrcHeight / (float)aDHeight;
|
||||
coeffs[4] = 0.0;
|
||||
coeffs[5] = 0.0;
|
||||
|
||||
constant[0] = 128.0;
|
||||
constant[1] = 128.0;
|
||||
constant[2] = 128.0;
|
||||
|
||||
XieFloGeometry(&photoElement[idx], src, aDWidth, aDHeight,
|
||||
coeffs,
|
||||
constant,
|
||||
0x07,
|
||||
xieValGeomNearestNeighbor,
|
||||
NULL);
|
||||
++idx;
|
||||
|
||||
/* export */
|
||||
XieFloExportDrawable(&photoElement[idx], idx, aDest, aGC,
|
||||
(aDX - aSX),
|
||||
(aDY - aSY));
|
||||
++idx;
|
||||
|
||||
|
||||
/* do the scale thing baby */
|
||||
XieExecuteImmediate(display, gPhotospace, 1, PR_FALSE, photoElement, idx);
|
||||
|
||||
|
||||
/*
|
||||
XieFreePhotofloGraph(photoElement, 3);
|
||||
*/
|
||||
|
||||
#ifdef DEBUG_XIE
|
||||
gdk_flush();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
PRBool
|
||||
DrawScaledImageXIE(Display *display,
|
||||
GdkDrawable *aDest,
|
||||
GdkGC *aGC,
|
||||
GdkDrawable *aSrc,
|
||||
GdkDrawable *aSrcMask,
|
||||
PRInt32 aSrcWidth,
|
||||
PRInt32 aSrcHeight,
|
||||
PRInt32 aSX,
|
||||
PRInt32 aSY,
|
||||
PRInt32 aSWidth,
|
||||
PRInt32 aSHeight,
|
||||
PRInt32 aDX,
|
||||
PRInt32 aDY,
|
||||
PRInt32 aDWidth,
|
||||
PRInt32 aDHeight)
|
||||
{
|
||||
Drawable importDrawable = GDK_WINDOW_XWINDOW(aSrc);
|
||||
Drawable exportDrawable = GDK_WINDOW_XWINDOW(aDest);
|
||||
|
||||
GdkPixmap *alphaMask = NULL;
|
||||
|
||||
GdkGC *gc = NULL;
|
||||
|
||||
#ifdef DEBUG_XIE
|
||||
printf("DrawScaledImageXIE\n");
|
||||
#endif
|
||||
|
||||
if (!inited) {
|
||||
XieExtensionInfo *info;
|
||||
inited = PR_TRUE;
|
||||
if (!XieInitialize(display, &info))
|
||||
return PR_FALSE;
|
||||
|
||||
/* create the photospace (we only need to do this once) */
|
||||
gPhotospace = XieCreatePhotospace(display);
|
||||
|
||||
photoElement = XieAllocatePhotofloGraph(3);
|
||||
|
||||
/* we want to destroy this at shutdown
|
||||
XieDestroyPhotospace(display, photospace);
|
||||
*/
|
||||
}
|
||||
|
||||
if (aSrcMask) {
|
||||
Drawable destMask;
|
||||
|
||||
#ifdef DEBUG_XIE
|
||||
fprintf(stderr, "DrawScaledImageXIE with alpha mask\n");
|
||||
#endif
|
||||
|
||||
alphaMask = gdk_pixmap_new(aSrcMask, aDWidth, aDHeight, 1);
|
||||
destMask = GDK_WINDOW_XWINDOW(alphaMask);
|
||||
gc = gdk_gc_new(alphaMask);
|
||||
DoFlo(display, destMask, GDK_GC_XGC(gc), GDK_WINDOW_XWINDOW(aSrcMask), aSrcWidth, aSrcHeight,
|
||||
aSX, aSY, aSWidth, aSHeight,
|
||||
aDX, aDY, aDWidth, aDHeight);
|
||||
gdk_gc_unref(gc);
|
||||
|
||||
gc = gdk_gc_new(aDest);
|
||||
|
||||
gdk_gc_copy(gc, aGC);
|
||||
gdk_gc_set_clip_mask(gc, alphaMask);
|
||||
gdk_gc_set_clip_origin(gc, aDX + aSX, aDY + aSY);
|
||||
}
|
||||
|
||||
if (!gc) {
|
||||
gc = aGC;
|
||||
gdk_gc_ref(gc);
|
||||
}
|
||||
|
||||
DoFlo(display, exportDrawable, GDK_GC_XGC(gc), importDrawable, aSrcWidth, aSrcHeight,
|
||||
aSX, aSY, aSWidth, aSHeight,
|
||||
aDX, aDY, aDWidth, aDHeight);
|
||||
|
||||
if (alphaMask)
|
||||
gdk_pixmap_unref(alphaMask);
|
||||
|
||||
gdk_gc_unref(gc);
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
49
gfx2/src/gtk/drawers.h
Normal file
49
gfx2/src/gtk/drawers.h
Normal file
@ -0,0 +1,49 @@
|
||||
/* -*- 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 "prtypes.h"
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
PRBool
|
||||
DrawScaledImageXIE(Display *display,
|
||||
GdkDrawable *aDest,
|
||||
GdkGC *aGC,
|
||||
GdkDrawable *aSrc,
|
||||
GdkDrawable *aSrcMask,
|
||||
PRInt32 aSrcWidth,
|
||||
PRInt32 aSrcHeight,
|
||||
PRInt32 aSX,
|
||||
PRInt32 aSY,
|
||||
PRInt32 aSWidth,
|
||||
PRInt32 aSHeight,
|
||||
PRInt32 aDX,
|
||||
PRInt32 aDY,
|
||||
PRInt32 aDWidth,
|
||||
PRInt32 aDHeight);
|
||||
|
||||
PR_END_EXTERN_C
|
48
gfx2/src/gtk/nsGfxFactory.cpp
Normal file
48
gfx2/src/gtk/nsGfxFactory.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/* -*- 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) 2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <pavlov@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsIModule.h"
|
||||
|
||||
#include "nsImageContainer.h"
|
||||
#include "nsImageFrame.h"
|
||||
|
||||
// objects that just require generic constructors
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageContainer)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageFrame)
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ "gtk image container",
|
||||
NS_IMAGECONTAINER_CID,
|
||||
"@mozilla.org/gfx/image;2",
|
||||
nsImageContainerConstructor, },
|
||||
{ "gtk image frame",
|
||||
NS_IMAGEFRAME_CID,
|
||||
"@mozilla.org/gfx/image/frame;2",
|
||||
nsImageFrameConstructor, },
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("nsGfx2Module", components)
|
||||
|
171
gfx2/src/gtk/nsImageContainer.cpp
Normal file
171
gfx2/src/gtk/nsImageContainer.cpp
Normal file
@ -0,0 +1,171 @@
|
||||
/* -*- 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 "nsCOMPtr.h"
|
||||
|
||||
#include "nsImageFrame.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsImageContainer, gfxIImageContainer, nsPIImageContainerGtk)
|
||||
|
||||
nsImageContainer::nsImageContainer()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
/* member initializers and constructor code */
|
||||
mCurrentFrame = 0;
|
||||
}
|
||||
|
||||
nsImageContainer::~nsImageContainer()
|
||||
{
|
||||
/* destructor code */
|
||||
mFrames.Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* void init (in nscoord aWidth, in nscoord aHeight, in gfxIImageContainerObserver aObserver); */
|
||||
NS_IMETHODIMP nsImageContainer::Init(nscoord aWidth, nscoord aHeight, gfxIImageContainerObserver *aObserver)
|
||||
{
|
||||
if (aWidth <= 0 || aHeight <= 0) {
|
||||
printf("error - negative image size\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
mSize.SizeTo(aWidth, aHeight);
|
||||
|
||||
mObserver = aObserver;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute gfx_format preferredAlphaChannelFormat; */
|
||||
NS_IMETHODIMP nsImageContainer::GetPreferredAlphaChannelFormat(gfx_format *aFormat)
|
||||
{
|
||||
*aFormat = gfxIFormats::RGBA;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord width; */
|
||||
NS_IMETHODIMP nsImageContainer::GetWidth(nscoord *aWidth)
|
||||
{
|
||||
*aWidth = mSize.width;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord height; */
|
||||
NS_IMETHODIMP nsImageContainer::GetHeight(nscoord *aHeight)
|
||||
{
|
||||
*aHeight = mSize.height;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* readonly attribute gfxIImageFrame currentFrame; */
|
||||
NS_IMETHODIMP nsImageContainer::GetCurrentFrame(gfxIImageFrame * *aCurrentFrame)
|
||||
{
|
||||
return this->GetFrameAt(mCurrentFrame, aCurrentFrame);
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long numFrames; */
|
||||
NS_IMETHODIMP nsImageContainer::GetNumFrames(PRUint32 *aNumFrames)
|
||||
{
|
||||
return mFrames.Count(aNumFrames);
|
||||
}
|
||||
|
||||
/* gfxIImageFrame getFrameAt (in unsigned long index); */
|
||||
NS_IMETHODIMP nsImageContainer::GetFrameAt(PRUint32 index, gfxIImageFrame **_retval)
|
||||
{
|
||||
nsISupports *sup = mFrames.ElementAt(index);
|
||||
if (!sup)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*_retval = NS_REINTERPRET_CAST(gfxIImageFrame *, sup);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void appendFrame (in gfxIImageFrame item); */
|
||||
NS_IMETHODIMP nsImageContainer::AppendFrame(gfxIImageFrame *item)
|
||||
{
|
||||
return mFrames.AppendElement(NS_REINTERPRET_CAST(nsISupports*, item));
|
||||
}
|
||||
|
||||
/* void removeFrame (in gfxIImageFrame item); */
|
||||
NS_IMETHODIMP nsImageContainer::RemoveFrame(gfxIImageFrame *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;
|
||||
}
|
||||
|
||||
|
||||
/** nsPIImageContainerGtk methods **/
|
||||
|
||||
NS_IMETHODIMP nsImageContainer::DrawImage(GdkDrawable *dest, const GdkGC *gc, const nsRect * aSrcRect, const nsPoint * aDestPoint)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<gfxIImageFrame> img;
|
||||
rv = this->GetCurrentFrame(getter_AddRefs(img));
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return NS_REINTERPRET_CAST(nsImageFrame*, img.get())->DrawImage(dest, gc, aSrcRect, aDestPoint);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImageContainer::DrawScaledImage(GdkDrawable *dest, const GdkGC *gc, const nsRect * aSrcRect, const nsRect * aDestRect)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<gfxIImageFrame> img;
|
||||
rv = this->GetCurrentFrame(getter_AddRefs(img));
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return NS_REINTERPRET_CAST(nsImageFrame*,
|
||||
img.get())->DrawScaledImage(dest, gc,
|
||||
aSrcRect, aDestRect);
|
||||
}
|
62
gfx2/src/gtk/nsImageContainer.h
Normal file
62
gfx2/src/gtk/nsImageContainer.h
Normal file
@ -0,0 +1,62 @@
|
||||
/* -*- 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 "gfxIImageContainer.h"
|
||||
#include "nsPIImageContainerGtk.h"
|
||||
|
||||
#include "gfxIImageContainerObserver.h"
|
||||
|
||||
#include "nsSize.h"
|
||||
|
||||
#include "nsSupportsArray.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#define NS_IMAGECONTAINER_CID \
|
||||
{ /* 5e04ec5e-1dd2-11b2-8fda-c4db5fb666e0 */ \
|
||||
0x5e04ec5e, \
|
||||
0x1dd2, \
|
||||
0x11b2, \
|
||||
{0x8f, 0xda, 0xc4, 0xdb, 0x5f, 0xb6, 0x66, 0xe0} \
|
||||
}
|
||||
|
||||
class nsImageContainer : public gfxIImageContainer,
|
||||
public nsPIImageContainerGtk
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIIMAGECONTAINER
|
||||
NS_DECL_NSPIIMAGECONTAINERGTK
|
||||
|
||||
nsImageContainer();
|
||||
virtual ~nsImageContainer();
|
||||
|
||||
private:
|
||||
/* additional members */
|
||||
nsSupportsArray mFrames;
|
||||
nsSize mSize;
|
||||
PRUint32 mCurrentFrame;
|
||||
|
||||
nsCOMPtr<gfxIImageContainerObserver> mObserver;
|
||||
};
|
||||
|
584
gfx2/src/gtk/nsImageFrame.cpp
Normal file
584
gfx2/src/gtk/nsImageFrame.cpp
Normal file
@ -0,0 +1,584 @@
|
||||
/* -*- 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 "nsImageFrame.h"
|
||||
|
||||
#include "nsTransform2D.h"
|
||||
|
||||
#include <gdk/gdkx.h>
|
||||
#include <gdk/gdkprivate.h>
|
||||
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
|
||||
#include "drawers.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsImageFrame, gfxIImageFrame)
|
||||
|
||||
nsImageFrame::nsImageFrame() :
|
||||
mAlphaData(nsnull),
|
||||
mInitalized(PR_FALSE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
/* member initializers and constructor code */
|
||||
}
|
||||
|
||||
nsImageFrame::~nsImageFrame()
|
||||
{
|
||||
/* destructor code */
|
||||
delete mAlphaData;
|
||||
}
|
||||
|
||||
/* void init (in nscoord aX, in nscoord aY, in nscoord aWidth, in nscoord aHeight, in gfx_format aFormat); */
|
||||
NS_IMETHODIMP nsImageFrame::Init(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, gfx_format aFormat)
|
||||
{
|
||||
if (aWidth <= 0 || aHeight <= 0) {
|
||||
printf("error - negative image size\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (mInitalized)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mInitalized = PR_TRUE;
|
||||
|
||||
mRect.SetRect(aX, aY, aWidth, aHeight);
|
||||
mFormat = aFormat;
|
||||
|
||||
// XXX this makes an assumption about what values these have and what is between them.. i'm being bad.
|
||||
if (mFormat >= gfxIFormats::RGB_A1 && mFormat <= gfxIFormats::BGR_A8)
|
||||
mAlphaData = new ImageData;
|
||||
|
||||
switch (aFormat) {
|
||||
case gfxIFormats::BGR:
|
||||
case gfxIFormats::RGB:
|
||||
mImageData.depth = 24;
|
||||
break;
|
||||
case gfxIFormats::BGRA:
|
||||
case gfxIFormats::RGBA:
|
||||
mImageData.depth = 32;
|
||||
break;
|
||||
|
||||
case gfxIFormats::BGR_A1:
|
||||
case gfxIFormats::RGB_A1:
|
||||
mImageData.depth = 24;
|
||||
mAlphaData->depth = 1;
|
||||
mAlphaData->bytesPerRow = (((mRect.width + 7) / 8) + 3) & ~0x3;
|
||||
break;
|
||||
case gfxIFormats::BGR_A8:
|
||||
case gfxIFormats::RGB_A8:
|
||||
mImageData.depth = 24;
|
||||
mAlphaData->depth = 8;
|
||||
mAlphaData->bytesPerRow = (mRect.width + 3) & ~0x3;
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("unsupposed gfx_format\n");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
mImageData.bytesPerRow = (mRect.width * mImageData.depth) >> 5;
|
||||
|
||||
if ((mRect.width * mImageData.depth) & 0x1F)
|
||||
mImageData.bytesPerRow++;
|
||||
mImageData.bytesPerRow <<= 2;
|
||||
|
||||
|
||||
mImageData.length = mImageData.bytesPerRow * mRect.height;
|
||||
mImageData.data = new PRUint8[mImageData.length];
|
||||
|
||||
if (mAlphaData) {
|
||||
mAlphaData->length = mAlphaData->bytesPerRow * mRect.height;
|
||||
mAlphaData->data = new PRUint8[mAlphaData->length];
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord x; */
|
||||
NS_IMETHODIMP nsImageFrame::GetX(nscoord *aX)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aX = mRect.x;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord y; */
|
||||
NS_IMETHODIMP nsImageFrame::GetY(nscoord *aY)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aY = mRect.y;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* readonly attribute nscoord width; */
|
||||
NS_IMETHODIMP nsImageFrame::GetWidth(nscoord *aWidth)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aWidth = mRect.width;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord height; */
|
||||
NS_IMETHODIMP nsImageFrame::GetHeight(nscoord *aHeight)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aHeight = mRect.height;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsRect rect; */
|
||||
NS_IMETHODIMP nsImageFrame::GetRect(nsRect **aRect)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
// *aRect = mRect;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute gfx_format format; */
|
||||
NS_IMETHODIMP nsImageFrame::GetFormat(gfx_format *aFormat)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aFormat = mFormat;
|
||||
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;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long imageBytesPerRow; */
|
||||
NS_IMETHODIMP nsImageFrame::GetImageBytesPerRow(PRUint32 *aBytesPerRow)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBytesPerRow = mImageData.bytesPerRow;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long imageDataLength; */
|
||||
NS_IMETHODIMP nsImageFrame::GetImageDataLength(PRUint32 *aBitsLength)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBitsLength = mImageData.length;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void getImageData([array, size_is(length)] out PRUint8 bits, out unsigned long length); */
|
||||
NS_IMETHODIMP nsImageFrame::GetImageData(PRUint8 **aData, PRUint32 *length)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aData = mImageData.data;
|
||||
*length = mImageData.length;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void setImageData ([array, size_is (length), const] in PRUint8 data, in unsigned long length, in long offset); */
|
||||
NS_IMETHODIMP nsImageFrame::SetImageData(const PRUint8 *data, PRUint32 length, PRInt32 offset)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
if (((PRUint32)offset + length) > mImageData.length)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
memcpy(mImageData.data + offset, data, length);
|
||||
|
||||
mImageData.dataChanged = PR_TRUE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long alphaBytesPerRow; */
|
||||
NS_IMETHODIMP nsImageFrame::GetAlphaBytesPerRow(PRUint32 *aBytesPerRow)
|
||||
{
|
||||
if (!mInitalized || !mAlphaData)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBytesPerRow = mAlphaData->bytesPerRow;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long alphaDataLength; */
|
||||
NS_IMETHODIMP nsImageFrame::GetAlphaDataLength(PRUint32 *aBitsLength)
|
||||
{
|
||||
if (!mInitalized || !mAlphaData)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBitsLength = mAlphaData->length;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void getAlphaData([array, size_is(length)] out PRUint8 bits, out unsigned long length); */
|
||||
NS_IMETHODIMP nsImageFrame::GetAlphaData(PRUint8 **aBits, PRUint32 *length)
|
||||
{
|
||||
if (!mInitalized || !mAlphaData)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBits = mAlphaData->data;
|
||||
*length = mAlphaData->length;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void setAlphaData ([array, size_is (length), const] in PRUint8 data, in unsigned long length, in long offset); */
|
||||
NS_IMETHODIMP nsImageFrame::SetAlphaData(const PRUint8 *data, PRUint32 length, PRInt32 offset)
|
||||
{
|
||||
if (!mInitalized || !mAlphaData)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
if (((PRUint32)offset + length) > mAlphaData->length)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
memcpy(mAlphaData->data + offset, data, length);
|
||||
|
||||
mAlphaData->dataChanged = PR_TRUE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
GdkBitmap *
|
||||
nsImageFrame::GetAlphaBitmap()
|
||||
{
|
||||
if (!mAlphaData)
|
||||
return nsnull;
|
||||
|
||||
if (!mAlphaData->pixmap)
|
||||
mAlphaData->pixmap = gdk_pixmap_new(nsnull, mRect.width, mRect.height, 1);
|
||||
|
||||
if (!mAlphaData->dataChanged)
|
||||
return gdk_pixmap_ref(mAlphaData->pixmap);
|
||||
|
||||
XImage *x_image = nsnull;
|
||||
Pixmap xpixmap = 0;
|
||||
Display *dpy = nsnull;
|
||||
Visual *visual = nsnull;
|
||||
|
||||
/* get the X primitives */
|
||||
dpy = GDK_WINDOW_XDISPLAY(mAlphaData->pixmap);
|
||||
|
||||
/* this is the depth of the pixmap that we are going to draw to.
|
||||
It's always a bitmap. We're doing alpha here folks. */
|
||||
visual = GDK_VISUAL_XVISUAL(gdk_rgb_get_visual());
|
||||
|
||||
// Make an image out of the alpha-bits created by the image library
|
||||
x_image = XCreateImage(dpy, visual,
|
||||
1, /* visual depth...1 for bitmaps */
|
||||
XYPixmap,
|
||||
0, /* x offset, XXX fix this */
|
||||
(char *)mAlphaData->data, /* cast away our sign. */
|
||||
mRect.width,
|
||||
mRect.height,
|
||||
32,/* bitmap pad */
|
||||
mAlphaData->bytesPerRow); /* bytes per line */
|
||||
|
||||
x_image->bits_per_pixel=1;
|
||||
|
||||
/* Image library always places pixels left-to-right MSB to LSB */
|
||||
x_image->bitmap_bit_order = MSBFirst;
|
||||
|
||||
/* This definition doesn't depend on client byte ordering
|
||||
because the image library ensures that the bytes in
|
||||
bitmask data are arranged left to right on the screen,
|
||||
low to high address in memory. */
|
||||
x_image->byte_order = MSBFirst;
|
||||
#if defined(IS_LITTLE_ENDIAN)
|
||||
// no, it's still MSB XXX check on this!!
|
||||
// x_image->byte_order = LSBFirst;
|
||||
#elif defined (IS_BIG_ENDIAN)
|
||||
x_image->byte_order = MSBFirst;
|
||||
#else
|
||||
#error ERROR! Endianness is unknown;
|
||||
#endif
|
||||
|
||||
// Write into the pixemap that is underneath gdk's mAlphaPixmap
|
||||
// the image we just created.
|
||||
xpixmap = GDK_WINDOW_XWINDOW(mAlphaData->pixmap);
|
||||
|
||||
GdkGC *gc1bit = gdk_gc_new(mAlphaData->pixmap);
|
||||
|
||||
XPutImage(dpy, xpixmap, GDK_GC_XGC(gc1bit), x_image, 0, 0, 0, 0,
|
||||
mRect.width, mRect.height);
|
||||
|
||||
gdk_gc_unref(gc1bit);
|
||||
|
||||
// Now we are done with the temporary image
|
||||
x_image->data = 0; /* Don't free the IL_Pixmap's bits. */
|
||||
XDestroyImage(x_image);
|
||||
|
||||
mAlphaData->dataChanged = PR_FALSE;
|
||||
|
||||
return gdk_pixmap_ref(mAlphaData->pixmap);
|
||||
}
|
||||
|
||||
|
||||
//#define USE_XIE 1
|
||||
#define USE_PIXBUF 1
|
||||
|
||||
nsresult nsImageFrame::DrawImage(GdkDrawable *aDest, const GdkGC *aGC, const nsRect * aSrcRect, const nsPoint * aDestPoint)
|
||||
{
|
||||
#ifdef USE_PIXBUF
|
||||
|
||||
if (!mImageData.pixbuf) {
|
||||
PRBool hasAlpha = (mFormat == gfxIFormats::RGBA);
|
||||
mImageData.pixbuf = gdk_pixbuf_new_from_data(mImageData.data,
|
||||
GDK_COLORSPACE_RGB,
|
||||
hasAlpha,
|
||||
8,
|
||||
mRect.width, mRect.height,
|
||||
mImageData.bytesPerRow,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
if (mFormat == gfxIFormats::RGBA) {
|
||||
GdkPixbuf *destPb =
|
||||
gdk_pixbuf_get_from_drawable(nsnull,
|
||||
aDest, gdk_rgb_get_cmap(),
|
||||
aDestPoint->x + aSrcRect->x,
|
||||
aDestPoint->y + aSrcRect->y,
|
||||
0, 0,
|
||||
aSrcRect->width, aSrcRect->height);
|
||||
|
||||
if (!destPb) {
|
||||
printf("get failed!\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
GdkPixbuf *tmpPb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, PR_TRUE, 8,
|
||||
aSrcRect->width, aSrcRect->height);
|
||||
|
||||
gdk_pixbuf_copy_area(mImageData.pixbuf,
|
||||
aSrcRect->x, aSrcRect->y,
|
||||
aSrcRect->width, aSrcRect->height,
|
||||
tmpPb,
|
||||
0, 0);
|
||||
|
||||
gdk_pixbuf_composite(tmpPb, destPb,
|
||||
0, 0,
|
||||
aSrcRect->width, aSrcRect->height,
|
||||
0.0, 0.0,
|
||||
1.0, 1.0, GDK_INTERP_NEAREST, 255);
|
||||
|
||||
gdk_pixbuf_render_to_drawable(destPb,
|
||||
aDest, NS_CONST_CAST(GdkGC*, aGC),
|
||||
0, 0,
|
||||
(aDestPoint->x + aSrcRect->x),
|
||||
(aDestPoint->y + aSrcRect->y),
|
||||
aSrcRect->width, aSrcRect->height,
|
||||
GDK_RGB_DITHER_MAX, 0, 0);
|
||||
|
||||
gdk_pixbuf_unref(tmpPb);
|
||||
gdk_pixbuf_unref(destPb);
|
||||
|
||||
} else if (mFormat == gfxIFormats::RGB) {
|
||||
|
||||
gdk_pixbuf_render_to_drawable(mImageData.pixbuf,
|
||||
aDest, NS_CONST_CAST(GdkGC*, aGC),
|
||||
aSrcRect->x, aSrcRect->y,
|
||||
(aDestPoint->x + aSrcRect->x),
|
||||
(aDestPoint->y + aSrcRect->y),
|
||||
aSrcRect->width, aSrcRect->height,
|
||||
GDK_RGB_DITHER_MAX, 0, 0);
|
||||
|
||||
} else if (mFormat == gfxIFormats::RGB_A1) {
|
||||
|
||||
GdkBitmap *alphaMask = GetAlphaBitmap();
|
||||
GdkGC *gc = nsnull;
|
||||
|
||||
if (alphaMask) {
|
||||
gc = gdk_gc_new(aDest);
|
||||
|
||||
gdk_gc_copy(gc, NS_CONST_CAST(GdkGC*, aGC));
|
||||
gdk_gc_set_clip_mask(gc, alphaMask);
|
||||
gdk_gc_set_clip_origin(gc,
|
||||
aDestPoint->x,
|
||||
aDestPoint->y);
|
||||
}
|
||||
|
||||
if (!gc) {
|
||||
gc = NS_CONST_CAST(GdkGC *, aGC);
|
||||
gdk_gc_ref(gc);
|
||||
}
|
||||
|
||||
gdk_pixbuf_render_to_drawable(mImageData.pixbuf,
|
||||
aDest, gc,
|
||||
aSrcRect->x, aSrcRect->y,
|
||||
(aDestPoint->x + aSrcRect->x),
|
||||
(aDestPoint->y + aSrcRect->y),
|
||||
aSrcRect->width, aSrcRect->height,
|
||||
GDK_RGB_DITHER_MAX, 0, 0);
|
||||
|
||||
if (alphaMask) gdk_pixmap_unref(alphaMask);
|
||||
gdk_gc_unref(gc);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
GdkBitmap *alphaMask = GetAlphaBitmap();
|
||||
GdkGC *gc = nsnull;
|
||||
|
||||
if (alphaMask) {
|
||||
gc = gdk_gc_new(aDest);
|
||||
|
||||
gdk_gc_copy(gc, NS_CONST_CAST(GdkGC*, aGC));
|
||||
gdk_gc_set_clip_mask(gc, alphaMask);
|
||||
gdk_gc_set_clip_origin(gc,
|
||||
aDestPoint->x + aSrcRect->x,
|
||||
aDestPoint->y + aSrcRect->y);
|
||||
}
|
||||
|
||||
if (!gc) {
|
||||
gc = NS_CONST_CAST(GdkGC *, aGC);
|
||||
gdk_gc_ref(gc);
|
||||
}
|
||||
|
||||
gdk_draw_rgb_image(aDest, gc,
|
||||
aDestPoint->x, (aDestPoint->y + aSrcRect->y),
|
||||
mRect.width, aSrcRect->height,
|
||||
GDK_RGB_DITHER_MAX,
|
||||
mImageData.data + (aSrcRect->y * mImageData.bytesPerRow),
|
||||
mImageData.bytesPerRow);
|
||||
|
||||
if (alphaMask) gdk_pixmap_unref(alphaMask);
|
||||
|
||||
gdk_gc_unref(gc);
|
||||
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsImageFrame::DrawScaledImage(GdkDrawable *aDrawable, const GdkGC *aGC, const nsRect * aSrcRect, const nsRect * aDestRect)
|
||||
{
|
||||
nsTransform2D trans;
|
||||
trans.SetToScale((float(mRect.width) / float(aDestRect->width)), (float(mRect.height) / float(aDestRect->height)));
|
||||
|
||||
nsRect source(*aSrcRect);
|
||||
nsRect dest(*aDestRect);
|
||||
|
||||
trans.TransformCoord(&source.x, &source.y, &source.width, &source.height);
|
||||
|
||||
|
||||
|
||||
#ifdef USE_XIE
|
||||
if (!mImageData.pixmap)
|
||||
mImageData.pixmap = gdk_pixmap_new(aDrawable, mRect.width, mRect.height, gdk_rgb_get_visual()->depth);
|
||||
|
||||
Display *display = GDK_WINDOW_XDISPLAY(aDrawable);
|
||||
|
||||
|
||||
|
||||
GdkGC *gdkgc = gdk_gc_new(aDrawable);
|
||||
gdk_draw_rgb_image(mImageData.pixmap, gdkgc,
|
||||
0, source.y,
|
||||
mRect.width, source.height,
|
||||
GDK_RGB_DITHER_MAX,
|
||||
mImageData.data,
|
||||
mImageData.bytesPerRow);
|
||||
|
||||
|
||||
GdkBitmap *alphaMask = GetAlphaBitmap();
|
||||
|
||||
DrawScaledImageXIE(display, aDrawable, NS_CONST_CAST(GdkGC*, aGC),
|
||||
mImageData.pixmap, alphaMask,
|
||||
mRect.width, mRect.height,
|
||||
source.x, source.y, source.width, source.height,
|
||||
dest.x, dest.y, dest.width, dest.height);
|
||||
|
||||
|
||||
if (alphaMask)
|
||||
gdk_pixmap_unref(alphaMask);
|
||||
|
||||
gdk_gc_unref(gdkgc);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef USE_PIXBUF
|
||||
|
||||
if (!mImageData.pixbuf)
|
||||
mImageData.pixbuf = gdk_pixbuf_new_from_data(mImageData.data,
|
||||
GDK_COLORSPACE_RGB,
|
||||
PR_FALSE,
|
||||
8,
|
||||
mRect.width, mRect.height,
|
||||
mImageData.bytesPerRow,
|
||||
NULL, NULL);
|
||||
|
||||
GdkPixbuf *npb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, PR_FALSE, 8, dest.width, dest.height);
|
||||
|
||||
gdk_pixbuf_scale(mImageData.pixbuf, npb,
|
||||
0, 0,
|
||||
dest.width, dest.height,
|
||||
0, 0,
|
||||
double(double(aDestRect->width) / double(mRect.width)),
|
||||
double(double(aDestRect->height) / double(mRect.height)),
|
||||
// GDK_INTERP_BILINEAR);
|
||||
GDK_INTERP_NEAREST);
|
||||
|
||||
|
||||
GdkBitmap *alphaMask = GetAlphaBitmap();
|
||||
|
||||
gdk_pixbuf_render_to_drawable(npb,
|
||||
aDrawable, NS_CONST_CAST(GdkGC*, aGC),
|
||||
aSrcRect->x, aSrcRect->y,
|
||||
aDestRect->x, aDestRect->y,
|
||||
aSrcRect->width, aSrcRect->height,
|
||||
GDK_RGB_DITHER_MAX,
|
||||
0, 0);
|
||||
|
||||
|
||||
gdk_pixbuf_unref(npb);
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
89
gfx2/src/gtk/nsImageFrame.h
Normal file
89
gfx2/src/gtk/nsImageFrame.h
Normal file
@ -0,0 +1,89 @@
|
||||
/* -*- 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) 2000-2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <pavlov@netscape.com>
|
||||
*/
|
||||
|
||||
#include "gfxIImageFrame.h"
|
||||
|
||||
#include "nsRect.h"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
|
||||
#define NS_IMAGEFRAME_CID \
|
||||
{ /* 3d25862e-1dd2-11b2-9d51-be9a25210304 */ \
|
||||
0x3d25862e, \
|
||||
0x1dd2, \
|
||||
0x11b2, \
|
||||
{0x9d, 0x51, 0xbe, 0x9a, 0x25, 0x21, 0x03, 0x04} \
|
||||
}
|
||||
|
||||
struct ImageData
|
||||
{
|
||||
ImageData() : bytesPerRow(0), data(nsnull), length(0), depth(0), dataChanged(PR_FALSE),
|
||||
pixmap(nsnull), pixbuf(nsnull) {}
|
||||
~ImageData() {
|
||||
delete[] data;
|
||||
if (pixmap) gdk_pixmap_unref(pixmap);
|
||||
if (pixbuf) gdk_pixbuf_unref(pixbuf);
|
||||
}
|
||||
PRUint32 bytesPerRow; // bytes per row
|
||||
PRUint8 *data;
|
||||
PRUint32 length; // length of the data in bytes
|
||||
gfx_depth depth;
|
||||
PRPackedBool dataChanged;
|
||||
|
||||
/* union? */
|
||||
GdkPixmap *pixmap;
|
||||
GdkPixbuf *pixbuf;
|
||||
};
|
||||
|
||||
class nsImageFrame : public gfxIImageFrame
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIIMAGEFRAME
|
||||
|
||||
nsImageFrame();
|
||||
virtual ~nsImageFrame();
|
||||
|
||||
// nsresult DrawImage(Display * display, Drawable dest, const GC gc, const nsRect * aSrcRect, const nsPoint * aDestPoint);
|
||||
nsresult DrawImage(GdkDrawable *dest, const GdkGC *gc, const nsRect * aSrcRect, const nsPoint * aDestPoint);
|
||||
|
||||
nsresult DrawScaledImage(GdkDrawable *dest, const GdkGC *gc, const nsRect * aSrcRect, const nsRect * aDestRect);
|
||||
|
||||
private:
|
||||
GdkBitmap *GetAlphaBitmap();
|
||||
|
||||
|
||||
/* additional members */
|
||||
nsRect mRect;
|
||||
|
||||
ImageData mImageData; // ... (ends with 16 bits)
|
||||
gfx_format mFormat; // 16 bits
|
||||
|
||||
ImageData *mAlphaData;
|
||||
|
||||
PRBool mInitalized;
|
||||
};
|
67
gfx2/src/gtk/nsPIImageContainerGtk.idl
Normal file
67
gfx2/src/gtk/nsPIImageContainerGtk.idl
Normal file
@ -0,0 +1,67 @@
|
||||
/** -*- 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 "nsISupports.idl"
|
||||
#include "gfxtypes.idl"
|
||||
|
||||
%{C++
|
||||
#include <X11/Xlib.h>
|
||||
#include <gdk/gdk.h>
|
||||
#include "nsRect.h"
|
||||
#include "nsPoint.h"
|
||||
%}
|
||||
|
||||
[ptr] native Display(Display);
|
||||
native Drawable(Drawable);
|
||||
native GC(GC);
|
||||
|
||||
[ptr] native GdkDrawable(GdkDrawable);
|
||||
[ptr] native GdkGC(GdkGC);
|
||||
|
||||
[ptr] native nsPoint(nsPoint);
|
||||
|
||||
/**
|
||||
* nsPIImageContainerGtk interface
|
||||
*
|
||||
* @author Stuart Parmenter <pavlov@netscape.com>
|
||||
* @version 0.1
|
||||
* @see "gfx2"
|
||||
*/
|
||||
[uuid(67ddea5a-1dd2-11b2-8051-997f7246444b)]
|
||||
interface nsPIImageContainerGtk : nsISupports
|
||||
{
|
||||
/**
|
||||
void drawImage(in Display display,
|
||||
in Drawable dest,
|
||||
[const] in GC gc,
|
||||
[const] in nsRect aSrcRect, [const] in nsPoint aDestPoint);
|
||||
*/
|
||||
void drawImage(in GdkDrawable dest,
|
||||
[const] in GdkGC gc, // XCopyGC if you are planning on changing it
|
||||
[const] in nsRect aSrcRect, [const] in nsPoint aDestPoint);
|
||||
|
||||
void drawScaledImage(in GdkDrawable dest,
|
||||
[const] in GdkGC gc, /* XCopyGC if you are
|
||||
planning on changing it */
|
||||
[const] in nsRect aSrcRect, [const] in nsRect aDestRect);
|
||||
};
|
55
gfx2/src/mac/Makefile.in
Normal file
55
gfx2/src/mac/Makefile.in
Normal file
@ -0,0 +1,55 @@
|
||||
#
|
||||
# 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) 2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Stuart Parmenter <pavlov@netscape.com>
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = gfx2
|
||||
LIBRARY_NAME = gfx2
|
||||
IS_COMPONENT = 1
|
||||
|
||||
CPPSRCS = \
|
||||
nsGfxFactory.cpp \
|
||||
nsImage.cpp \
|
||||
$(NULL)
|
||||
|
||||
SHARED_LIBRARY_LIBS = $(DIST)/lib/libgfx_base.a
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
EXTRA_DSO_LDOPTS += -L$(DIST)/bin
|
||||
EXTRA_DSO_LDOPTS += $(TK_LIBS)
|
||||
CXXFLAGS += $(TK_CFLAGS)
|
||||
|
||||
EXTRA_DSO_LDOPTS += \
|
||||
$(NSPR_LIBS) \
|
||||
-lxpcom \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(OS_ARCH), Linux)
|
||||
DEFINES += -D_BSD_SOURCE
|
||||
endif
|
||||
|
48
gfx2/src/mac/nsGfxFactory.cpp
Normal file
48
gfx2/src/mac/nsGfxFactory.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/* -*- 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) 2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <pavlov@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsIModule.h"
|
||||
|
||||
#include "nsImageContainer.h"
|
||||
#include "nsImageFrame.h"
|
||||
|
||||
// objects that just require generic constructors
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageContainer)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageFrame)
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ "windows image container",
|
||||
NS_IMAGECONTAINER_CID,
|
||||
"@mozilla.org/gfx/image;2",
|
||||
nsImageContainerConstructor, },
|
||||
{ "windows image frame",
|
||||
NS_IMAGEFRAME_CID,
|
||||
"@mozilla.org/gfx/image/frame;2",
|
||||
nsImageFrameConstructor, },
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("nsGfx2Module", components)
|
||||
|
245
gfx2/src/mac/nsImageContainer.cpp
Normal file
245
gfx2/src/mac/nsImageContainer.cpp
Normal file
@ -0,0 +1,245 @@
|
||||
/* -*- 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>
|
||||
* Chris Saari <saari@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsImageContainer.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "gfxIImageFrame.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsImageContainer, gfxIImageContainer)
|
||||
|
||||
nsImageContainer::nsImageContainer()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
/* member initializers and constructor code */
|
||||
mCurrentFrame = 0;
|
||||
mCurrentAnimationFrame = 0;
|
||||
mCurrentFrameIsFinishedDecoding = PR_FALSE;
|
||||
mDoneDecoding = PR_FALSE;
|
||||
}
|
||||
|
||||
nsImageContainer::~nsImageContainer()
|
||||
{
|
||||
/* destructor code */
|
||||
mFrames.Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* void init (in nscoord aWidth, in nscoord aHeight, in gfxIImageContainerObserver aObserver); */
|
||||
NS_IMETHODIMP nsImageContainer::Init(nscoord aWidth, nscoord aHeight, gfxIImageContainerObserver *aObserver)
|
||||
{
|
||||
if (aWidth <= 0 || aHeight <= 0) {
|
||||
printf("error - negative image size\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
mSize.SizeTo(aWidth, aHeight);
|
||||
|
||||
mObserver = aObserver;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute gfx_format preferredAlphaChannelFormat; */
|
||||
NS_IMETHODIMP nsImageContainer::GetPreferredAlphaChannelFormat(gfx_format *aFormat)
|
||||
{
|
||||
*aFormat = gfxIFormats::RGB_A8;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord width; */
|
||||
NS_IMETHODIMP nsImageContainer::GetWidth(nscoord *aWidth)
|
||||
{
|
||||
*aWidth = mSize.width;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord height; */
|
||||
NS_IMETHODIMP nsImageContainer::GetHeight(nscoord *aHeight)
|
||||
{
|
||||
*aHeight = mSize.height;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* readonly attribute gfxIImageFrame currentFrame; */
|
||||
NS_IMETHODIMP nsImageContainer::GetCurrentFrame(gfxIImageFrame * *aCurrentFrame)
|
||||
{
|
||||
return this->GetFrameAt(mCurrentFrame, aCurrentFrame);
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long numFrames; */
|
||||
NS_IMETHODIMP nsImageContainer::GetNumFrames(PRUint32 *aNumFrames)
|
||||
{
|
||||
return mFrames.Count(aNumFrames);
|
||||
}
|
||||
|
||||
/* gfxIImageFrame getFrameAt (in unsigned long index); */
|
||||
NS_IMETHODIMP nsImageContainer::GetFrameAt(PRUint32 index, gfxIImageFrame **_retval)
|
||||
{
|
||||
nsISupports *sup = mFrames.ElementAt(index);
|
||||
if (!sup)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*_retval = NS_REINTERPRET_CAST(gfxIImageFrame *, sup);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void appendFrame (in gfxIImageFrame item); */
|
||||
NS_IMETHODIMP nsImageContainer::AppendFrame(gfxIImageFrame *item)
|
||||
{
|
||||
// If this is our second frame, init a timer so we don't display
|
||||
// the next frame until the delay timer has expired for the current
|
||||
// frame.
|
||||
PRUint32 numFrames;
|
||||
this->GetNumFrames(&numFrames);
|
||||
if(!mTimer){
|
||||
if(numFrames) {
|
||||
// Since we have more than one frame we need a timer
|
||||
mTimer = do_CreateInstance("@mozilla.org/timer;1");
|
||||
|
||||
PRInt32 timeout;
|
||||
nsCOMPtr<gfxIImageFrame> currentFrame;
|
||||
this->GetFrameAt(mCurrentFrame, getter_AddRefs(currentFrame));
|
||||
currentFrame->GetTimeout(&timeout);
|
||||
if(timeout != -1 &&
|
||||
timeout >= 0) { // -1 means display this frame forever
|
||||
|
||||
mTimer->Init(
|
||||
sAnimationTimerCallback, this, timeout,
|
||||
NS_PRIORITY_NORMAL, NS_TYPE_ONE_SHOT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(numFrames) mCurrentFrame++;
|
||||
|
||||
mCurrentFrameIsFinishedDecoding = PR_FALSE;
|
||||
return mFrames.AppendElement(NS_REINTERPRET_CAST(nsISupports*, item));
|
||||
}
|
||||
|
||||
/* void removeFrame (in gfxIImageFrame item); */
|
||||
NS_IMETHODIMP nsImageContainer::RemoveFrame(gfxIImageFrame *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;
|
||||
}
|
||||
|
||||
/* void endFrameDecode (in gfxIImageFrame item, in unsigned long timeout); */
|
||||
NS_IMETHODIMP nsImageContainer::EndFrameDecode(PRUint32 aFrameNum, PRUint32 aTimeout)
|
||||
{
|
||||
// It is now okay to start the timer for the next frame in the animation
|
||||
mCurrentFrameIsFinishedDecoding = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void decodingComplete (); */
|
||||
NS_IMETHODIMP nsImageContainer::DecodingComplete(void)
|
||||
{
|
||||
mDoneDecoding = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsImageContainer::sAnimationTimerCallback(nsITimer *aTimer, void *aImageContainer)
|
||||
{
|
||||
nsImageContainer* self = NS_STATIC_CAST(nsImageContainer*, aImageContainer);
|
||||
nsCOMPtr<gfxIImageFrame> nextFrame;
|
||||
PRInt32 timeout = 100;
|
||||
|
||||
printf("timer callback ");
|
||||
|
||||
// If we're done decoding the next frame, go ahead and display it now and reinit
|
||||
// the timer with the next frame's delay time.
|
||||
if(self->mCurrentFrameIsFinishedDecoding && !self->mDoneDecoding) {
|
||||
// If we have the next frame in the sequence set the timer callback from it
|
||||
self->GetFrameAt(self->mCurrentAnimationFrame + 1, getter_AddRefs(nextFrame));
|
||||
if(nextFrame) {
|
||||
// Go to next frame in sequence
|
||||
nextFrame->GetTimeout(&timeout);
|
||||
self->mCurrentAnimationFrame++;
|
||||
} else if (self->mDoneDecoding) {
|
||||
// Go back to the beginning of the loop
|
||||
self->GetFrameAt(0, getter_AddRefs(nextFrame));
|
||||
nextFrame->GetTimeout(&timeout);
|
||||
self->mCurrentAnimationFrame = 0;
|
||||
} else {
|
||||
// twiddle our thumbs
|
||||
self->GetFrameAt(self->mCurrentAnimationFrame, getter_AddRefs(nextFrame));
|
||||
nextFrame->GetTimeout(&timeout);
|
||||
}
|
||||
} else if(self->mDoneDecoding){
|
||||
PRUint32 numFrames;
|
||||
self->GetNumFrames(&numFrames);
|
||||
if(numFrames == self->mCurrentAnimationFrame) {
|
||||
self->GetFrameAt(0, getter_AddRefs(nextFrame));
|
||||
self->mCurrentAnimationFrame = 0;
|
||||
self->mCurrentFrame = 0;
|
||||
nextFrame->GetTimeout(&timeout);
|
||||
} else {
|
||||
self->GetFrameAt(self->mCurrentAnimationFrame++, getter_AddRefs(nextFrame));
|
||||
self->mCurrentFrame = self->mCurrentAnimationFrame;
|
||||
nextFrame->GetTimeout(&timeout);
|
||||
}
|
||||
} else {
|
||||
self->GetFrameAt(self->mCurrentFrame, getter_AddRefs(nextFrame));
|
||||
nextFrame->GetTimeout(&timeout);
|
||||
}
|
||||
|
||||
printf(" mCurrentAnimationFrame = %d\n", self->mCurrentAnimationFrame);
|
||||
|
||||
// XXX do notification to FE to draw this frame
|
||||
nsRect* dirtyRect;
|
||||
nextFrame->GetRect(&dirtyRect);
|
||||
|
||||
printf("x=%d, y=%d, w=%d, h=%d\n", dirtyRect->x, dirtyRect->y, dirtyRect->width, dirtyRect->height);
|
||||
self->mObserver->FrameChanged(
|
||||
self, nsnull,
|
||||
nextFrame, dirtyRect);
|
||||
|
||||
|
||||
self->mTimer->Init(
|
||||
sAnimationTimerCallback, aImageContainer, timeout,
|
||||
NS_PRIORITY_NORMAL, NS_TYPE_ONE_SHOT);
|
||||
}
|
66
gfx2/src/mac/nsImageContainer.h
Normal file
66
gfx2/src/mac/nsImageContainer.h
Normal file
@ -0,0 +1,66 @@
|
||||
/* -*- 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>
|
||||
* Chris Saari <saari@netscape.com>
|
||||
*/
|
||||
|
||||
#include "gfxIImageContainer.h"
|
||||
|
||||
#include "gfxIImageContainerObserver.h"
|
||||
|
||||
#include "nsSize.h"
|
||||
|
||||
#include "nsSupportsArray.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsITimer.h"
|
||||
#define NS_IMAGECONTAINER_CID \
|
||||
{ /* aa699204-1dd1-11b2-84a9-a280c268e4fb */ \
|
||||
0xaa699204, \
|
||||
0x1dd1, \
|
||||
0x11b2, \
|
||||
{0x84, 0xa9, 0xa2, 0x80, 0xc2, 0x68, 0xe4, 0xfb} \
|
||||
}
|
||||
|
||||
class nsImageContainer : public gfxIImageContainer
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIIMAGECONTAINER
|
||||
|
||||
nsImageContainer();
|
||||
virtual ~nsImageContainer();
|
||||
|
||||
private:
|
||||
/* additional members */
|
||||
nsSupportsArray mFrames;
|
||||
nsSize mSize;
|
||||
PRUint32 mCurrentFrame;
|
||||
PRUint32 mCurrentAnimationFrame;
|
||||
PRBool mCurrentFrameIsFinishedDecoding;
|
||||
PRBool mDoneDecoding;
|
||||
|
||||
nsCOMPtr<nsITimer> mTimer;
|
||||
nsCOMPtr<gfxIImageContainerObserver> mObserver;
|
||||
|
||||
static void sAnimationTimerCallback ( nsITimer* aTimer, void* aListener );
|
||||
};
|
||||
|
271
gfx2/src/mac/nsImageFrame.cpp
Normal file
271
gfx2/src/mac/nsImageFrame.cpp
Normal file
@ -0,0 +1,271 @@
|
||||
/* -*- 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 "nsImageFrame.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsImageFrame, gfxIImageFrame)
|
||||
|
||||
nsImageFrame::nsImageFrame() :
|
||||
mInitalized(PR_FALSE),
|
||||
mAlphaData(nsnull),
|
||||
mTimeout(-1)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
/* member initializers and constructor code */
|
||||
}
|
||||
|
||||
nsImageFrame::~nsImageFrame()
|
||||
{
|
||||
/* destructor code */
|
||||
delete mAlphaData;
|
||||
}
|
||||
|
||||
/* void init (in nscoord aX, in nscoord aY, in nscoord aWidth, in nscoord aHeight, in gfx_format aFormat); */
|
||||
NS_IMETHODIMP nsImageFrame::Init(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, gfx_format aFormat)
|
||||
{
|
||||
if (aWidth <= 0 || aHeight <= 0) {
|
||||
printf("error - negative image size\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (mInitalized)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mInitalized = PR_TRUE;
|
||||
|
||||
mRect.SetRect(aX, aY, aWidth, aHeight);
|
||||
mFormat = aFormat;
|
||||
|
||||
// XXX this makes an assumption about what values these have and what is between them.. i'm being bad.
|
||||
if (mFormat >= gfxIFormats::RGB_A1 && mFormat <= gfxIFormats::BGR_A8)
|
||||
mAlphaData = new ImageData;
|
||||
|
||||
switch (aFormat) {
|
||||
case gfxIFormats::BGR:
|
||||
case gfxIFormats::RGB:
|
||||
mImageData.depth = 24;
|
||||
break;
|
||||
case gfxIFormats::BGRA:
|
||||
case gfxIFormats::RGBA:
|
||||
mImageData.depth = 32;
|
||||
break;
|
||||
|
||||
case gfxIFormats::BGR_A1:
|
||||
case gfxIFormats::RGB_A1:
|
||||
mImageData.depth = 24;
|
||||
mAlphaData->depth = 1;
|
||||
mAlphaData->bytesPerRow = (((mRect.width + 7) / 8) + 3) & ~0x3;
|
||||
break;
|
||||
case gfxIFormats::BGR_A8:
|
||||
case gfxIFormats::RGB_A8:
|
||||
mImageData.depth = 24;
|
||||
mAlphaData->depth = 8;
|
||||
mAlphaData->bytesPerRow = (mRect.width + 3) & ~0x3;
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("unsupposed gfx_format\n");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
mImageData.bytesPerRow = (mRect.width * mImageData.depth) >> 5;
|
||||
|
||||
if ((mRect.width * mImageData.depth) & 0x1F)
|
||||
mImageData.bytesPerRow++;
|
||||
mImageData.bytesPerRow <<= 2;
|
||||
|
||||
|
||||
mImageData.length = mImageData.bytesPerRow * mRect.height;
|
||||
mImageData.data = new PRUint8[mImageData.length];
|
||||
|
||||
if (mAlphaData) {
|
||||
mAlphaData->length = mAlphaData->bytesPerRow * mRect.height;
|
||||
mAlphaData->data = new PRUint8[mAlphaData->length];
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord x; */
|
||||
NS_IMETHODIMP nsImageFrame::GetX(nscoord *aX)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aX = mRect.x;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord y; */
|
||||
NS_IMETHODIMP nsImageFrame::GetY(nscoord *aY)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aY = mRect.y;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* readonly attribute nscoord width; */
|
||||
NS_IMETHODIMP nsImageFrame::GetWidth(nscoord *aWidth)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aWidth = mRect.width;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord height; */
|
||||
NS_IMETHODIMP nsImageFrame::GetHeight(nscoord *aHeight)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aHeight = mRect.height;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsRect rect; */
|
||||
NS_IMETHODIMP nsImageFrame::GetRect(nsRect **aRect)
|
||||
{
|
||||
*aRect = &mRect;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute gfx_format format; */
|
||||
NS_IMETHODIMP nsImageFrame::GetFormat(gfx_format *aFormat)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aFormat = mFormat;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute long timeout; */
|
||||
NS_IMETHODIMP nsImageFrame::GetTimeout(PRInt32 *aTimeout)
|
||||
{
|
||||
*aTimeout = mTimeout;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImageFrame::SetTimeout(PRInt32 aTimeout)
|
||||
{
|
||||
mTimeout = aTimeout;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long imageBytesPerRow; */
|
||||
NS_IMETHODIMP nsImageFrame::GetImageBytesPerRow(PRUint32 *aBytesPerRow)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBytesPerRow = mImageData.bytesPerRow;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long imageDataLength; */
|
||||
NS_IMETHODIMP nsImageFrame::GetImageDataLength(PRUint32 *aBitsLength)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBitsLength = mImageData.length;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void getImageData([array, size_is(length)] out PRUint8 bits, out unsigned long length); */
|
||||
NS_IMETHODIMP nsImageFrame::GetImageData(PRUint8 **aData, PRUint32 *length)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aData = mImageData.data;
|
||||
*length = mImageData.length;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void setImageData ([array, size_is (length), const] in PRUint8 data, in unsigned long length, in long offset); */
|
||||
NS_IMETHODIMP nsImageFrame::SetImageData(const PRUint8 *data, PRUint32 length, PRInt32 offset)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
if (((PRUint32)offset + length) > mImageData.length)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
memcpy(mImageData.data + offset, data, length);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long alphaBytesPerRow; */
|
||||
NS_IMETHODIMP nsImageFrame::GetAlphaBytesPerRow(PRUint32 *aBytesPerRow)
|
||||
{
|
||||
if (!mInitalized || !mAlphaData)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBytesPerRow = mAlphaData->bytesPerRow;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long alphaDataLength; */
|
||||
NS_IMETHODIMP nsImageFrame::GetAlphaDataLength(PRUint32 *aBitsLength)
|
||||
{
|
||||
if (!mInitalized || !mAlphaData)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBitsLength = mAlphaData->length;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void getAlphaData([array, size_is(length)] out PRUint8 bits, out unsigned long length); */
|
||||
NS_IMETHODIMP nsImageFrame::GetAlphaData(PRUint8 **aBits, PRUint32 *length)
|
||||
{
|
||||
if (!mInitalized || !mAlphaData)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBits = mAlphaData->data;
|
||||
*length = mAlphaData->length;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void setAlphaData ([array, size_is (length), const] in PRUint8 data, in unsigned long length, in long offset); */
|
||||
NS_IMETHODIMP nsImageFrame::SetAlphaData(const PRUint8 *data, PRUint32 length, PRInt32 offset)
|
||||
{
|
||||
if (!mInitalized || !mAlphaData)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
if (((PRUint32)offset + length) > mAlphaData->length)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
memcpy(mAlphaData->data + offset, data, length);
|
||||
|
||||
return NS_OK;
|
||||
}
|
69
gfx2/src/mac/nsImageFrame.h
Normal file
69
gfx2/src/mac/nsImageFrame.h
Normal file
@ -0,0 +1,69 @@
|
||||
/* -*- 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) 2000-2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <pavlov@netscape.com>
|
||||
*/
|
||||
|
||||
#include "gfxIImageFrame.h"
|
||||
|
||||
#include "nsRect.h"
|
||||
|
||||
#define NS_IMAGEFRAME_CID \
|
||||
{ /* 99b219ea-1dd1-11b2-aa87-cd48e7d50227 */ \
|
||||
0x99b219ea, \
|
||||
0x1dd1, \
|
||||
0x11b2, \
|
||||
{0xaa, 0x87, 0xcd, 0x48, 0xe7, 0xd5, 0x02, 0x27} \
|
||||
}
|
||||
|
||||
struct ImageData
|
||||
{
|
||||
ImageData() : bytesPerRow(0), data(nsnull), length(0), depth(0) {}
|
||||
~ImageData() {
|
||||
delete[] data;
|
||||
}
|
||||
PRUint32 bytesPerRow; // bytes per row
|
||||
PRUint8 *data;
|
||||
PRUint32 length; // length of the data in bytes
|
||||
gfx_depth depth;
|
||||
};
|
||||
|
||||
class nsImageFrame : public gfxIImageFrame
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIIMAGEFRAME
|
||||
|
||||
nsImageFrame();
|
||||
virtual ~nsImageFrame();
|
||||
|
||||
private:
|
||||
/* additional members */
|
||||
nsRect mRect;
|
||||
|
||||
PRPackedBool mInitalized; // 8 bits
|
||||
// ??? // 8 bits
|
||||
gfx_format mFormat; // 16 bits
|
||||
|
||||
ImageData mImageData;
|
||||
ImageData *mAlphaData;
|
||||
|
||||
PRInt32 mTimeout; // -1 means display forever
|
||||
};
|
51
gfx2/src/makefile.win
Normal file
51
gfx2/src/makefile.win
Normal file
@ -0,0 +1,51 @@
|
||||
#!nmake
|
||||
#
|
||||
# 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) 2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Stuart Parmenter <pavlov@netscape.com>
|
||||
#
|
||||
|
||||
DEPTH = ..\..
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
#MODULE = gfx2
|
||||
#LIBRARY_NAME= gfx2
|
||||
#DLL = $(OBJDIR)\$(LIBRARY_NAME).dll
|
||||
|
||||
#MAKE_OBJ_TYPE = DLL
|
||||
|
||||
DIRS = windows
|
||||
|
||||
#OBJS = \
|
||||
# .\$(OBJDIR)\nsRect.obj \
|
||||
# $(NULL)
|
||||
|
||||
#LLIBS = \
|
||||
# $(DIST)\lib\gfx2_s.lib \
|
||||
# $(DIST)\lib\xpcom.lib \
|
||||
# $(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
#install:: $(DLL)
|
||||
# $(MAKE_INSTALL) $(DLL) $(DIST)\bin\components
|
||||
|
||||
#clobber::
|
||||
# rm -f $(DIST)\bin\components\$(LIBRARY_NAME).dll
|
||||
# rm -f $(PDBFILE).pdb
|
57
gfx2/src/windows/makefile.win
Normal file
57
gfx2/src/windows/makefile.win
Normal file
@ -0,0 +1,57 @@
|
||||
#!nmake
|
||||
#
|
||||
# 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) 2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Stuart Parmenter <pavlov@netscape.com>
|
||||
#
|
||||
|
||||
DEPTH=..\..\..
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
MODULE = gfx2
|
||||
LIBRARY_NAME= gfx2
|
||||
DLL = $(OBJDIR)\$(LIBRARY_NAME).dll
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
|
||||
XPIDL_MODULE= gfx2win
|
||||
|
||||
XPIDLSRCS = \
|
||||
.\nsPIImageContainerWin.idl \
|
||||
$(NULL)
|
||||
OBJS = \
|
||||
.\$(OBJDIR)\nsImageContainer.obj \
|
||||
.\$(OBJDIR)\nsImageFrame.obj \
|
||||
.\$(OBJDIR)\nsGfxFactory.obj \
|
||||
$(NULL)
|
||||
|
||||
LLIBS = \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(DIST)\lib\gkgfxwin.lib \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) $(DLL) $(DIST)\bin\components
|
||||
|
||||
#install:: $(LIBRARY)
|
||||
# $(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib
|
48
gfx2/src/windows/nsGfxFactory.cpp
Normal file
48
gfx2/src/windows/nsGfxFactory.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/* -*- 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) 2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <pavlov@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsIModule.h"
|
||||
|
||||
#include "nsImageContainer.h"
|
||||
#include "nsImageFrame.h"
|
||||
|
||||
// objects that just require generic constructors
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageContainer)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageFrame)
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ "windows image container",
|
||||
NS_IMAGECONTAINER_CID,
|
||||
"@mozilla.org/gfx/image;2",
|
||||
nsImageContainerConstructor, },
|
||||
{ "windows image frame",
|
||||
NS_IMAGEFRAME_CID,
|
||||
"@mozilla.org/gfx/image/frame;2",
|
||||
nsImageFrameConstructor, },
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("nsGfx2Module", components)
|
||||
|
250
gfx2/src/windows/nsImageContainer.cpp
Normal file
250
gfx2/src/windows/nsImageContainer.cpp
Normal file
@ -0,0 +1,250 @@
|
||||
/* -*- 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 "nsImageFrame.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS3(nsImageContainer, gfxIImageContainer, nsPIImageContainerWin, nsITimerCallback)
|
||||
|
||||
nsImageContainer::nsImageContainer()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
/* member initializers and constructor code */
|
||||
mCurrentFrame = 0;
|
||||
mCurrentFrameIsFinishedDecoding = PR_FALSE;
|
||||
mDoneDecoding = PR_FALSE;
|
||||
}
|
||||
|
||||
nsImageContainer::~nsImageContainer()
|
||||
{
|
||||
/* destructor code */
|
||||
mFrames.Clear();
|
||||
|
||||
if (mTimer)
|
||||
mTimer->Cancel();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* void init (in nscoord aWidth, in nscoord aHeight, in gfxIImageContainerObserver aObserver); */
|
||||
NS_IMETHODIMP nsImageContainer::Init(nscoord aWidth, nscoord aHeight, gfxIImageContainerObserver *aObserver)
|
||||
{
|
||||
if (aWidth <= 0 || aHeight <= 0) {
|
||||
printf("error - negative image size\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
mSize.SizeTo(aWidth, aHeight);
|
||||
|
||||
mObserver = aObserver;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute gfx_format preferredAlphaChannelFormat; */
|
||||
NS_IMETHODIMP nsImageContainer::GetPreferredAlphaChannelFormat(gfx_format *aFormat)
|
||||
{
|
||||
*aFormat = gfxIFormats::RGB_A8;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord width; */
|
||||
NS_IMETHODIMP nsImageContainer::GetWidth(nscoord *aWidth)
|
||||
{
|
||||
*aWidth = mSize.width;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord height; */
|
||||
NS_IMETHODIMP nsImageContainer::GetHeight(nscoord *aHeight)
|
||||
{
|
||||
*aHeight = mSize.height;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* readonly attribute gfxIImageFrame currentFrame; */
|
||||
NS_IMETHODIMP nsImageContainer::GetCurrentFrame(gfxIImageFrame * *aCurrentFrame)
|
||||
{
|
||||
return this->GetFrameAt(mCurrentFrame, aCurrentFrame);
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long numFrames; */
|
||||
NS_IMETHODIMP nsImageContainer::GetNumFrames(PRUint32 *aNumFrames)
|
||||
{
|
||||
return mFrames.Count(aNumFrames);
|
||||
}
|
||||
|
||||
/* gfxIImageFrame getFrameAt (in unsigned long index); */
|
||||
NS_IMETHODIMP nsImageContainer::GetFrameAt(PRUint32 index, gfxIImageFrame **_retval)
|
||||
{
|
||||
nsISupports *sup = mFrames.ElementAt(index);
|
||||
if (!sup)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*_retval = NS_REINTERPRET_CAST(gfxIImageFrame *, sup);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void appendFrame (in gfxIImageFrame item); */
|
||||
NS_IMETHODIMP nsImageContainer::AppendFrame(gfxIImageFrame *item)
|
||||
{
|
||||
PRUint32 numFrames;
|
||||
this->GetNumFrames(&numFrames);
|
||||
if (!mTimer){
|
||||
if (numFrames) {
|
||||
// Since we have more than one frame we need a timer
|
||||
mTimer = do_CreateInstance("@mozilla.org/timer;1");
|
||||
|
||||
PRInt32 timeout;
|
||||
nsCOMPtr<gfxIImageFrame> currentFrame;
|
||||
this->GetFrameAt(mCurrentFrame, getter_AddRefs(currentFrame));
|
||||
currentFrame->GetTimeout(&timeout);
|
||||
if(timeout != -1 &&
|
||||
timeout >= 0) { // -1 means display this frame forever
|
||||
|
||||
mTimer->Init(NS_STATIC_CAST(nsITimerCallback*, this), timeout,
|
||||
NS_PRIORITY_NORMAL, NS_TYPE_REPEATING_PRECISE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mCurrentFrameIsFinishedDecoding = PR_FALSE;
|
||||
return mFrames.AppendElement(NS_REINTERPRET_CAST(nsISupports*, item));
|
||||
}
|
||||
|
||||
/* void removeFrame (in gfxIImageFrame item); */
|
||||
NS_IMETHODIMP nsImageContainer::RemoveFrame(gfxIImageFrame *item)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* nsIEnumerator enumerate (); */
|
||||
NS_IMETHODIMP nsImageContainer::Enumerate(nsIEnumerator **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void endFrameDecode (in gfxIImageFrame item, in unsigned long timeout); */
|
||||
NS_IMETHODIMP nsImageContainer::EndFrameDecode(PRUint32 aFrameNum, PRUint32 aTimeout)
|
||||
{
|
||||
// It is now okay to start the timer for the next frame in the animation
|
||||
mCurrentFrameIsFinishedDecoding = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void decodingComplete (); */
|
||||
NS_IMETHODIMP nsImageContainer::DecodingComplete(void)
|
||||
{
|
||||
mDoneDecoding = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** nsPIImageContainerWin methods **/
|
||||
|
||||
NS_IMETHODIMP nsImageContainer::DrawImage(HDC aDestDC, const nsRect * aSrcRect, const nsPoint * aDestPoint)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<gfxIImageFrame> img;
|
||||
rv = this->GetCurrentFrame(getter_AddRefs(img));
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return NS_REINTERPRET_CAST(nsImageFrame*, img.get())->DrawImage(aDestDC, aSrcRect, aDestPoint);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImageContainer::DrawScaledImage(HDC aDestDC, const nsRect * aSrcRect, const nsRect * aDestRect)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<gfxIImageFrame> img;
|
||||
rv = this->GetCurrentFrame(getter_AddRefs(img));
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return NS_REINTERPRET_CAST(nsImageFrame*, img.get())->DrawScaledImage(aDestDC, aSrcRect, aDestRect);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP_(void) nsImageContainer::Notify(nsITimer *aTimer)
|
||||
{
|
||||
++mCurrentFrame;
|
||||
|
||||
PRUint32 numFrames;
|
||||
GetNumFrames(&numFrames);
|
||||
if (mCurrentFrame > numFrames)
|
||||
mCurrentFrame = 0;
|
||||
|
||||
nsCOMPtr<gfxIImageFrame> nextFrame;
|
||||
GetFrameAt(mCurrentFrame, getter_AddRefs(nextFrame));
|
||||
|
||||
if (!nextFrame)
|
||||
return; // XXX thiss would suck.
|
||||
|
||||
// Go to next frame in sequence
|
||||
PRInt32 timeout;
|
||||
nextFrame->GetTimeout(&timeout);
|
||||
|
||||
// XXX do notification to FE to draw this frame
|
||||
nsRect* dirtyRect;
|
||||
nextFrame->GetRect(&dirtyRect);
|
||||
mObserver->FrameChanged(this, nsnull, nextFrame, dirtyRect);
|
||||
/*
|
||||
mTimer->Init(NS_STATIC_CAST(nsITimerCallback*, this), timeout,
|
||||
NS_PRIORITY_NORMAL, NS_TYPE_ONE_SHOT);
|
||||
*/
|
||||
}
|
75
gfx2/src/windows/nsImageContainer.h
Normal file
75
gfx2/src/windows/nsImageContainer.h
Normal file
@ -0,0 +1,75 @@
|
||||
/* -*- 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 "gfxIImageContainer.h"
|
||||
#include "nsPIImageContainerWin.h"
|
||||
#include "nsITimerCallback.h"
|
||||
|
||||
#include "nsSize.h"
|
||||
|
||||
#include "nsSupportsArray.h"
|
||||
|
||||
#include "gfxIImageContainerObserver.h"
|
||||
#include "nsITimer.h"
|
||||
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
|
||||
#define NS_IMAGECONTAINER_CID \
|
||||
{ /* aa699204-1dd1-11b2-84a9-a280c268e4fb */ \
|
||||
0xaa699204, \
|
||||
0x1dd1, \
|
||||
0x11b2, \
|
||||
{0x84, 0xa9, 0xa2, 0x80, 0xc2, 0x68, 0xe4, 0xfb} \
|
||||
}
|
||||
|
||||
class nsImageContainer : public gfxIImageContainer,
|
||||
public nsPIImageContainerWin,
|
||||
public nsITimerCallback
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIIMAGECONTAINER
|
||||
NS_DECL_NSPIIMAGECONTAINERWIN
|
||||
|
||||
NS_IMETHOD_(void) Notify(nsITimer *timer);
|
||||
|
||||
nsImageContainer();
|
||||
virtual ~nsImageContainer();
|
||||
|
||||
private:
|
||||
/* additional members */
|
||||
nsSupportsArray mFrames;
|
||||
nsSize mSize;
|
||||
PRUint32 mCurrentFrame;
|
||||
|
||||
PRPackedBool mCurrentFrameIsFinishedDecoding;
|
||||
PRPackedBool mDoneDecoding;
|
||||
|
||||
nsCOMPtr<nsITimer> mTimer;
|
||||
nsCOMPtr<gfxIImageContainerObserver> mObserver;
|
||||
|
||||
|
||||
};
|
||||
|
456
gfx2/src/windows/nsImageFrame.cpp
Normal file
456
gfx2/src/windows/nsImageFrame.cpp
Normal file
@ -0,0 +1,456 @@
|
||||
/* -*- 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 "nsImageFrame.h"
|
||||
|
||||
#include "nsTransform2D.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsImageFrame, gfxIImageFrame)
|
||||
|
||||
struct MONOBITMAPINFO {
|
||||
BITMAPINFOHEADER bmiHeader;
|
||||
RGBQUAD bmiColors[2];
|
||||
|
||||
MONOBITMAPINFO(LONG aWidth, LONG aHeight)
|
||||
{
|
||||
memset(&bmiHeader, 0, sizeof(bmiHeader));
|
||||
bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
bmiHeader.biWidth = aWidth;
|
||||
bmiHeader.biHeight = aHeight;
|
||||
bmiHeader.biPlanes = 1;
|
||||
bmiHeader.biBitCount = 1;
|
||||
|
||||
// Note that the palette is being set up so the DIB and the DDB have white and
|
||||
// black reversed. This is because we need the mask to have 0 for the opaque
|
||||
// pixels of the image, and 1 for the transparent pixels. This way the SRCAND
|
||||
// operation sets the opaque pixels to 0, and leaves the transparent pixels
|
||||
// undisturbed
|
||||
bmiColors[0].rgbBlue = 255;
|
||||
bmiColors[0].rgbGreen = 255;
|
||||
bmiColors[0].rgbRed = 255;
|
||||
bmiColors[0].rgbReserved = 0;
|
||||
bmiColors[1].rgbBlue = 0;
|
||||
bmiColors[1].rgbGreen = 0;
|
||||
bmiColors[1].rgbRed = 0;
|
||||
bmiColors[1].rgbReserved = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct ALPHA8BITMAPINFO {
|
||||
BITMAPINFOHEADER bmiHeader;
|
||||
RGBQUAD bmiColors[256];
|
||||
|
||||
ALPHA8BITMAPINFO(LONG aWidth, LONG aHeight)
|
||||
{
|
||||
memset(&bmiHeader, 0, sizeof(bmiHeader));
|
||||
bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
bmiHeader.biWidth = aWidth;
|
||||
bmiHeader.biHeight = aHeight;
|
||||
bmiHeader.biPlanes = 1;
|
||||
bmiHeader.biBitCount = 8;
|
||||
|
||||
/* fill in gray scale palette */
|
||||
int i;
|
||||
for(i=0; i < 256; i++){
|
||||
bmiColors[i].rgbBlue = 255-i;
|
||||
bmiColors[i].rgbGreen = 255-i;
|
||||
bmiColors[i].rgbRed = 255-i;
|
||||
bmiColors[1].rgbReserved = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct ALPHA24BITMAPINFO {
|
||||
BITMAPINFOHEADER bmiHeader;
|
||||
|
||||
ALPHA24BITMAPINFO(LONG aWidth, LONG aHeight)
|
||||
{
|
||||
memset(&bmiHeader, 0, sizeof(bmiHeader));
|
||||
bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
bmiHeader.biWidth = aWidth;
|
||||
bmiHeader.biHeight = aHeight;
|
||||
bmiHeader.biPlanes = 1;
|
||||
bmiHeader.biBitCount = 24;
|
||||
}
|
||||
};
|
||||
|
||||
struct ALPHA32BITMAPINFO {
|
||||
BITMAPINFOHEADER bmiHeader;
|
||||
|
||||
ALPHA32BITMAPINFO(LONG aWidth, LONG aHeight)
|
||||
{
|
||||
memset(&bmiHeader, 0, sizeof(bmiHeader));
|
||||
bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
bmiHeader.biWidth = aWidth;
|
||||
bmiHeader.biHeight = aHeight;
|
||||
bmiHeader.biPlanes = 1;
|
||||
bmiHeader.biBitCount = 32;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
nsImageFrame::nsImageFrame() :
|
||||
mTimeout(0),
|
||||
mInitalized(PR_FALSE),
|
||||
mAlphaData(nsnull)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
/* member initializers and constructor code */
|
||||
}
|
||||
|
||||
nsImageFrame::~nsImageFrame()
|
||||
{
|
||||
/* destructor code */
|
||||
delete mAlphaData;
|
||||
}
|
||||
|
||||
/* void init (in nscoord aX, in nscoord aY, in nscoord aWidth, in nscoord aHeight, in gfx_format aFormat); */
|
||||
NS_IMETHODIMP nsImageFrame::Init(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, gfx_format aFormat)
|
||||
{
|
||||
if (aWidth <= 0 || aHeight <= 0) {
|
||||
printf("error - negative image size\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (mInitalized)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mInitalized = PR_TRUE;
|
||||
|
||||
mRect.SetRect(aX, aY, aWidth, aHeight);
|
||||
mFormat = aFormat;
|
||||
|
||||
// XXX this makes an assumption about what values these have and what is between them.. i'm being bad.
|
||||
if (mFormat >= gfxIFormats::RGB_A1 && mFormat <= gfxIFormats::BGR_A8)
|
||||
mAlphaData = new ImageData;
|
||||
|
||||
switch (aFormat) {
|
||||
case gfxIFormats::BGR:
|
||||
case gfxIFormats::RGB:
|
||||
mImageData.depth = 24;
|
||||
break;
|
||||
case gfxIFormats::BGRA:
|
||||
case gfxIFormats::RGBA:
|
||||
mImageData.depth = 32;
|
||||
break;
|
||||
|
||||
case gfxIFormats::BGR_A1:
|
||||
case gfxIFormats::RGB_A1:
|
||||
mImageData.depth = 24;
|
||||
mAlphaData->depth = 1;
|
||||
mAlphaData->bytesPerRow = (((mRect.width + 7) / 8) + 3) & ~0x3;
|
||||
// mAlphaData->header = new MONOBITMAPINFO(mRect.width, mRect.height);
|
||||
break;
|
||||
case gfxIFormats::BGR_A8:
|
||||
case gfxIFormats::RGB_A8:
|
||||
mImageData.depth = 24;
|
||||
mAlphaData->depth = 8;
|
||||
mAlphaData->bytesPerRow = (mRect.width + 3) & ~0x3;
|
||||
// mAlphaData->header = new ALPHA8BITMAPINFO(mRect.width, mRect.height);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("unsupposed gfx_format\n");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
mImageData.bytesPerRow = (mRect.width * mImageData.depth) >> 5;
|
||||
|
||||
if ((mRect.width * mImageData.depth) & 0x1F)
|
||||
mImageData.bytesPerRow++;
|
||||
mImageData.bytesPerRow <<= 2;
|
||||
|
||||
mImageData.length = mImageData.bytesPerRow * mRect.height;
|
||||
mImageData.data = new PRUint8[mImageData.length];
|
||||
|
||||
if (mAlphaData) {
|
||||
mAlphaData->length = mAlphaData->bytesPerRow * mRect.height;
|
||||
mAlphaData->data = new PRUint8[mAlphaData->length];
|
||||
/*
|
||||
mAlphaData->bitmap = ::CreateDIBitmap(NULL, mAlphaData->header, CBM_INIT, NULL, (LPBITMAPINFO)mAlphaData->header,
|
||||
DIB_RGB_COLORS);
|
||||
*/
|
||||
}
|
||||
|
||||
mImageData.header = (LPBITMAPINFOHEADER)new char[sizeof(BITMAPINFO)];
|
||||
|
||||
LPBITMAPINFOHEADER header = mImageData.header;
|
||||
|
||||
header->biSize = sizeof(BITMAPINFOHEADER);
|
||||
header->biWidth = mRect.width;
|
||||
header->biHeight = -mRect.height;
|
||||
header->biPlanes = 1;
|
||||
header->biBitCount = mImageData.depth;
|
||||
header->biCompression = BI_RGB;
|
||||
header->biSizeImage = mImageData.length;
|
||||
header->biXPelsPerMeter = 0;
|
||||
header->biYPelsPerMeter = 0;
|
||||
header->biClrUsed = 0;
|
||||
header->biClrImportant = 0;
|
||||
|
||||
/*
|
||||
mImageData.bitmap = ::CreateDIBitmap(NULL, mImageData.header, CBM_INIT, NULL, (LPBITMAPINFO)mImageData.header,
|
||||
DIB_RGB_COLORS);
|
||||
*/
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord x; */
|
||||
NS_IMETHODIMP nsImageFrame::GetX(nscoord *aX)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aX = mRect.x;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord y; */
|
||||
NS_IMETHODIMP nsImageFrame::GetY(nscoord *aY)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aY = mRect.y;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* readonly attribute nscoord width; */
|
||||
NS_IMETHODIMP nsImageFrame::GetWidth(nscoord *aWidth)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aWidth = mRect.width;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord height; */
|
||||
NS_IMETHODIMP nsImageFrame::GetHeight(nscoord *aHeight)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aHeight = mRect.height;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsRect rect; */
|
||||
NS_IMETHODIMP nsImageFrame::GetRect(nsRect **aRect)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aRect = &mRect;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute gfx_format format; */
|
||||
NS_IMETHODIMP nsImageFrame::GetFormat(gfx_format *aFormat)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aFormat = mFormat;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute long timeout; */
|
||||
NS_IMETHODIMP nsImageFrame::GetTimeout(PRInt32 *aTimeout)
|
||||
{
|
||||
*aTimeout = mTimeout;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImageFrame::SetTimeout(PRInt32 aTimeout)
|
||||
{
|
||||
mTimeout = aTimeout;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long imageBytesPerRow; */
|
||||
NS_IMETHODIMP nsImageFrame::GetImageBytesPerRow(PRUint32 *aBytesPerRow)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBytesPerRow = mImageData.bytesPerRow;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long imageDataLength; */
|
||||
NS_IMETHODIMP nsImageFrame::GetImageDataLength(PRUint32 *aBitsLength)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBitsLength = mImageData.length;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void getImageData([array, size_is(length)] out PRUint8 bits, out unsigned long length); */
|
||||
NS_IMETHODIMP nsImageFrame::GetImageData(PRUint8 **aData, PRUint32 *length)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aData = mImageData.data;
|
||||
*length = mImageData.length;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void setImageData ([array, size_is (length), const] in PRUint8 data, in unsigned long length, in long offset); */
|
||||
NS_IMETHODIMP nsImageFrame::SetImageData(const PRUint8 *data, PRUint32 length, PRInt32 offset)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
if (((PRUint32)offset + length) > mImageData.length)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
memcpy(mImageData.data + offset, data, length);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long alphaBytesPerRow; */
|
||||
NS_IMETHODIMP nsImageFrame::GetAlphaBytesPerRow(PRUint32 *aBytesPerRow)
|
||||
{
|
||||
if (!mInitalized || !mAlphaData)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBytesPerRow = mAlphaData->bytesPerRow;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long alphaDataLength; */
|
||||
NS_IMETHODIMP nsImageFrame::GetAlphaDataLength(PRUint32 *aBitsLength)
|
||||
{
|
||||
if (!mInitalized || !mAlphaData)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBitsLength = mAlphaData->length;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void getAlphaData([array, size_is(length)] out PRUint8 bits, out unsigned long length); */
|
||||
NS_IMETHODIMP nsImageFrame::GetAlphaData(PRUint8 **aBits, PRUint32 *length)
|
||||
{
|
||||
if (!mInitalized || !mAlphaData)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBits = mAlphaData->data;
|
||||
*length = mAlphaData->length;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void setAlphaData ([array, size_is (length), const] in PRUint8 data, in unsigned long length, in long offset); */
|
||||
NS_IMETHODIMP nsImageFrame::SetAlphaData(const PRUint8 *data, PRUint32 length, PRInt32 offset)
|
||||
{
|
||||
if (!mInitalized || !mAlphaData)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
if (((PRUint32)offset + length) > mAlphaData->length)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
memcpy(mAlphaData->data + offset, data, length);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
nsresult nsImageFrame::DrawImage(HDC aDestDC, const nsRect * aSrcRect, const nsPoint * aDestPoint)
|
||||
{
|
||||
printf("%i, %i, %i, %i %i, %i\n", aSrcRect->x, aSrcRect->y, aSrcRect->width, aSrcRect->height,
|
||||
aDestPoint->x, aDestPoint->y);
|
||||
|
||||
// Translate to bottom-up coordinates for the source bitmap
|
||||
nscoord srcY = mRect.height - (aSrcRect->y + aSrcRect->height);
|
||||
|
||||
int rop = SRCCOPY;
|
||||
if (mAlphaData && mAlphaData->depth == 1) {
|
||||
MONOBITMAPINFO bmi(mRect.width, -mRect.height);
|
||||
bmi.bmiHeader.biSizeImage = mAlphaData->length;
|
||||
::StretchDIBits(aDestDC, (aDestPoint->x + aSrcRect->x), (aDestPoint->y + aSrcRect->y),
|
||||
aSrcRect->width, aSrcRect->height,
|
||||
aSrcRect->x, srcY, aSrcRect->width, aSrcRect->height,
|
||||
mAlphaData->data,
|
||||
(LPBITMAPINFO)&bmi, DIB_RGB_COLORS, SRCAND);
|
||||
rop = SRCPAINT;
|
||||
}
|
||||
|
||||
::StretchDIBits(aDestDC, (aDestPoint->x + aSrcRect->x), (aDestPoint->y + aSrcRect->y),
|
||||
aSrcRect->width, aSrcRect->height,
|
||||
aSrcRect->x, srcY, aSrcRect->width, aSrcRect->height,
|
||||
mImageData.data,
|
||||
(LPBITMAPINFO)mImageData.header, DIB_RGB_COLORS, rop);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsImageFrame::DrawScaledImage(HDC aDestDC, const nsRect * aSrcRect, const nsRect * aDestRect)
|
||||
{
|
||||
nsTransform2D trans;
|
||||
trans.SetToScale((float(mRect.width) / float(aDestRect->width)), (float(mRect.height) / float(aDestRect->height)));
|
||||
|
||||
nsRect source(*aSrcRect);
|
||||
nsRect dest(*aDestRect);
|
||||
|
||||
trans.TransformCoord(&source.x, &source.y, &source.width, &source.height);
|
||||
|
||||
int rop = SRCCOPY;
|
||||
if (mAlphaData && mAlphaData->depth == 1) {
|
||||
MONOBITMAPINFO bmi(mRect.width, -mRect.width);
|
||||
bmi.bmiHeader.biSizeImage = mAlphaData->length;
|
||||
::StretchDIBits(aDestDC, (aDestRect->x + aSrcRect->x), (aDestRect->y + aSrcRect->y), dest.width, dest.height,
|
||||
source.x, source.y, source.width, source.height,
|
||||
mAlphaData->data,
|
||||
(LPBITMAPINFO)&bmi, DIB_RGB_COLORS, SRCAND);
|
||||
rop = SRCPAINT;
|
||||
}
|
||||
|
||||
::StretchDIBits(aDestDC, (aDestRect->x + aSrcRect->x), (aDestRect->y + aSrcRect->y), dest.width, dest.height,
|
||||
source.x, source.y, source.width, source.height,
|
||||
mImageData.data,
|
||||
(LPBITMAPINFO)mImageData.header, DIB_RGB_COLORS, rop);
|
||||
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
79
gfx2/src/windows/nsImageFrame.h
Normal file
79
gfx2/src/windows/nsImageFrame.h
Normal file
@ -0,0 +1,79 @@
|
||||
/* -*- 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) 2000-2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <pavlov@netscape.com>
|
||||
*/
|
||||
|
||||
#include "gfxIImageFrame.h"
|
||||
|
||||
#include "nsRect.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#define NS_IMAGEFRAME_CID \
|
||||
{ /* 99b219ea-1dd1-11b2-aa87-cd48e7d50227 */ \
|
||||
0x99b219ea, \
|
||||
0x1dd1, \
|
||||
0x11b2, \
|
||||
{0xaa, 0x87, 0xcd, 0x48, 0xe7, 0xd5, 0x02, 0x27} \
|
||||
}
|
||||
|
||||
struct ImageData
|
||||
{
|
||||
ImageData() : header(nsnull), bitmap(0), bytesPerRow(0), data(nsnull), length(0), depth(0) {}
|
||||
~ImageData() {
|
||||
delete[] data;
|
||||
delete header;
|
||||
}
|
||||
LPBITMAPINFOHEADER header;
|
||||
HBITMAP bitmap;
|
||||
PRUint32 bytesPerRow; // bytes per row
|
||||
PRUint8 *data;
|
||||
PRUint32 length; // length of the data in bytes
|
||||
gfx_depth depth;
|
||||
};
|
||||
|
||||
class nsImageFrame : public gfxIImageFrame
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIIMAGEFRAME
|
||||
|
||||
nsImageFrame();
|
||||
virtual ~nsImageFrame();
|
||||
|
||||
|
||||
nsresult DrawImage(HDC aDestDC, const nsRect * aSrcRect, const nsPoint * aDestPoint);
|
||||
nsresult DrawScaledImage(HDC aDestDC, const nsRect * aSrcRect, const nsRect * aDestRect);
|
||||
|
||||
|
||||
private:
|
||||
/* additional members */
|
||||
nsRect mRect;
|
||||
PRInt32 mTimeout;
|
||||
|
||||
|
||||
PRPackedBool mInitalized; // 8 bits
|
||||
|
||||
ImageData mImageData;
|
||||
gfx_format mFormat; // 16 bits
|
||||
|
||||
ImageData *mAlphaData;
|
||||
};
|
50
gfx2/src/windows/nsPIImageContainerWin.idl
Normal file
50
gfx2/src/windows/nsPIImageContainerWin.idl
Normal file
@ -0,0 +1,50 @@
|
||||
/** -*- 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 "nsISupports.idl"
|
||||
#include "gfxtypes.idl"
|
||||
|
||||
%{C++
|
||||
#include <windows.h>
|
||||
#include "nsRect.h"
|
||||
#include "nsPoint.h"
|
||||
%}
|
||||
|
||||
native HDC(HDC);
|
||||
[ptr] native nsPoint(nsPoint);
|
||||
|
||||
/**
|
||||
* nsPIImageContainerWin interface
|
||||
*
|
||||
* @author Stuart Parmenter <pavlov@netscape.com>
|
||||
* @version 0.1
|
||||
* @see "gfx2"
|
||||
*/
|
||||
[uuid(3178bb28-1dd2-11b2-b42a-faa241c7a70e)]
|
||||
interface nsPIImageContainerWin : nsISupports
|
||||
{
|
||||
/**
|
||||
*/
|
||||
void drawImage(in HDC aDestDC, [const] in nsRect aSrcRect, [const] in nsPoint aDestPoint);
|
||||
void drawScaledImage(in HDC aDestDC, [const] in nsRect aSrcRect, [const] in nsRect aDestRect);
|
||||
};
|
61
gfx2/src/xlib/Makefile.in
Normal file
61
gfx2/src/xlib/Makefile.in
Normal file
@ -0,0 +1,61 @@
|
||||
#
|
||||
# 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) 2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Stuart Parmenter <pavlov@netscape.com>
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = gfx2
|
||||
XPIDL_MODULE = gfx2xlib
|
||||
LIBRARY_NAME = gfx2
|
||||
IS_COMPONENT = 1
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsPIImageContainerXlib.idl \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
nsGfxFactory.cpp \
|
||||
nsImageContainer.cpp \
|
||||
nsImageFrame.cpp \
|
||||
$(NULL)
|
||||
|
||||
#SHARED_LIBRARY_LIBS = $(DIST)/lib/libgfx_base.a
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
EXTRA_DSO_LDOPTS += -L$(DIST)/bin
|
||||
EXTRA_DSO_LDOPTS += $(TK_LIBS) -lgdk_pixbuf
|
||||
CXXFLAGS += $(TK_CFLAGS)
|
||||
|
||||
EXTRA_DSO_LDOPTS += \
|
||||
$(NSPR_LIBS) \
|
||||
-lxpcom \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(OS_ARCH), Linux)
|
||||
DEFINES += -D_BSD_SOURCE
|
||||
endif
|
||||
|
48
gfx2/src/xlib/nsGfxFactory.cpp
Normal file
48
gfx2/src/xlib/nsGfxFactory.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/* -*- 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) 2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <pavlov@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsIModule.h"
|
||||
|
||||
#include "nsImageContainer.h"
|
||||
#include "nsImageFrame.h"
|
||||
|
||||
// objects that just require generic constructors
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageContainer)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageFrame)
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ "xlib image container",
|
||||
NS_IMAGECONTAINER_CID,
|
||||
"@mozilla.org/gfx/image;2",
|
||||
nsImageContainerConstructor, },
|
||||
{ "xlib image frame",
|
||||
NS_IMAGEFRAME_CID,
|
||||
"@mozilla.org/gfx/image/frame;2",
|
||||
nsImageFrameConstructor, },
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("nsGfx2Module", components)
|
||||
|
162
gfx2/src/xlib/nsImageContainer.cpp
Normal file
162
gfx2/src/xlib/nsImageContainer.cpp
Normal file
@ -0,0 +1,162 @@
|
||||
/* -*- 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 "nsCOMPtr.h"
|
||||
|
||||
#include "nsImageFrame.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsImageContainer, nsIImageContainer, nsPIImageContainerXlib)
|
||||
|
||||
nsImageContainer::nsImageContainer()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
/* member initializers and constructor code */
|
||||
mCurrentFrame = 0;
|
||||
}
|
||||
|
||||
nsImageContainer::~nsImageContainer()
|
||||
{
|
||||
/* destructor code */
|
||||
mFrames.Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* void init (in nscoord aWidth, in nscoord aHeight); */
|
||||
NS_IMETHODIMP nsImageContainer::Init(nscoord aWidth, nscoord 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 nscoord width; */
|
||||
NS_IMETHODIMP nsImageContainer::GetWidth(nscoord *aWidth)
|
||||
{
|
||||
*aWidth = mSize.width;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord height; */
|
||||
NS_IMETHODIMP nsImageContainer::GetHeight(nscoord *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;
|
||||
}
|
||||
|
||||
|
||||
/** nsPIImageContainerXlib methods **/
|
||||
|
||||
NS_IMETHODIMP nsImageContainer::DrawImage(GdkDrawable *dest, const GdkGC *gc, const nsRect * aSrcRect, const nsPoint * aDestPoint)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIImageFrame> img;
|
||||
rv = this->GetCurrentFrame(getter_AddRefs(img));
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return NS_REINTERPRET_CAST(nsImageFrame*, img.get())->DrawImage(dest, gc, aSrcRect, aDestPoint);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImageContainer::DrawScaledImage(GdkDrawable *dest, const GdkGC *gc, const nsRect * aSrcRect, const nsRect * aDestRect)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIImageFrame> img;
|
||||
rv = this->GetCurrentFrame(getter_AddRefs(img));
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return NS_REINTERPRET_CAST(nsImageFrame*,
|
||||
img.get())->DrawScaledImage(dest, gc,
|
||||
aSrcRect, aDestRect);
|
||||
}
|
56
gfx2/src/xlib/nsImageContainer.h
Normal file
56
gfx2/src/xlib/nsImageContainer.h
Normal file
@ -0,0 +1,56 @@
|
||||
/* -*- 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 "nsPIImageContainerXlib.h"
|
||||
|
||||
#include "nsSize.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 nsPIImageContainerXlib
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIIMAGECONTAINER
|
||||
NS_DECL_NSPIIMAGECONTAINERXLIB
|
||||
|
||||
nsImageContainer();
|
||||
virtual ~nsImageContainer();
|
||||
|
||||
private:
|
||||
/* additional members */
|
||||
nsSupportsArray mFrames;
|
||||
nsSize mSize;
|
||||
PRUint32 mCurrentFrame;
|
||||
};
|
||||
|
379
gfx2/src/xlib/nsImageFrame.cpp
Normal file
379
gfx2/src/xlib/nsImageFrame.cpp
Normal file
@ -0,0 +1,379 @@
|
||||
/* -*- 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 "nsImageFrame.h"
|
||||
|
||||
#include "nsTransform2D.h"
|
||||
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsImageFrame, nsIImageFrame)
|
||||
|
||||
nsImageFrame::nsImageFrame() :
|
||||
mAlphaData(nsnull),
|
||||
mInitalized(PR_FALSE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
/* member initializers and constructor code */
|
||||
}
|
||||
|
||||
nsImageFrame::~nsImageFrame()
|
||||
{
|
||||
/* destructor code */
|
||||
delete mAlphaData;
|
||||
}
|
||||
|
||||
/* void init (in nscoord aX, in nscoord aY, in nscoord aWidth, in nscoord aHeight, in gfx_format aFormat); */
|
||||
NS_IMETHODIMP nsImageFrame::Init(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, gfx_format aFormat)
|
||||
{
|
||||
if (aWidth <= 0 || aHeight <= 0) {
|
||||
printf("error - negative image size\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (mInitalized)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mInitalized = PR_TRUE;
|
||||
|
||||
mRect.SetRect(aX, aY, aWidth, aHeight);
|
||||
mFormat = aFormat;
|
||||
|
||||
// XXX this makes an assumption about what values these have and what is between them.. i'm being bad.
|
||||
if (mFormat >= nsIGFXFormat::RGB_A1 && mFormat <= nsIGFXFormat::BGR_A8)
|
||||
mAlphaData = new ImageData;
|
||||
|
||||
switch (aFormat) {
|
||||
case nsIGFXFormat::BGR:
|
||||
case nsIGFXFormat::RGB:
|
||||
mImageData.depth = 24;
|
||||
break;
|
||||
case nsIGFXFormat::BGRA:
|
||||
case nsIGFXFormat::RGBA:
|
||||
mImageData.depth = 32;
|
||||
break;
|
||||
|
||||
case nsIGFXFormat::BGR_A1:
|
||||
case nsIGFXFormat::RGB_A1:
|
||||
mImageData.depth = 24;
|
||||
mAlphaData->depth = 1;
|
||||
mAlphaData->bytesPerRow = (((mRect.width + 7) / 8) + 3) & ~0x3;
|
||||
break;
|
||||
case nsIGFXFormat::BGR_A8:
|
||||
case nsIGFXFormat::RGB_A8:
|
||||
mImageData.depth = 24;
|
||||
mAlphaData->depth = 8;
|
||||
mAlphaData->bytesPerRow = (mRect.width + 3) & ~0x3;
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("unsupposed gfx_format\n");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
mImageData.bytesPerRow = (mRect.width * mImageData.depth) >> 5;
|
||||
|
||||
if ((mRect.width * mImageData.depth) & 0x1F)
|
||||
mImageData.bytesPerRow++;
|
||||
mImageData.bytesPerRow <<= 2;
|
||||
|
||||
|
||||
mImageData.length = mImageData.bytesPerRow * mRect.height;
|
||||
mImageData.data = new PRUint8[mImageData.length];
|
||||
|
||||
if (mAlphaData) {
|
||||
mAlphaData->length = mAlphaData->bytesPerRow * mRect.height;
|
||||
mAlphaData->data = new PRUint8[mAlphaData->length];
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord x; */
|
||||
NS_IMETHODIMP nsImageFrame::GetX(nscoord *aX)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aX = mRect.x;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord y; */
|
||||
NS_IMETHODIMP nsImageFrame::GetY(nscoord *aY)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aY = mRect.y;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* readonly attribute nscoord width; */
|
||||
NS_IMETHODIMP nsImageFrame::GetWidth(nscoord *aWidth)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aWidth = mRect.width;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nscoord height; */
|
||||
NS_IMETHODIMP nsImageFrame::GetHeight(nscoord *aHeight)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aHeight = mRect.height;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsRect rect; */
|
||||
NS_IMETHODIMP nsImageFrame::GetRect(nsRect **aRect)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
// *aRect = mRect;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute gfx_format format; */
|
||||
NS_IMETHODIMP nsImageFrame::GetFormat(gfx_format *aFormat)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aFormat = mFormat;
|
||||
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;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long imageBytesPerRow; */
|
||||
NS_IMETHODIMP nsImageFrame::GetImageBytesPerRow(PRUint32 *aBytesPerRow)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBytesPerRow = mImageData.bytesPerRow;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long imageDataLength; */
|
||||
NS_IMETHODIMP nsImageFrame::GetImageDataLength(PRUint32 *aBitsLength)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBitsLength = mImageData.length;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void getImageData([array, size_is(length)] out PRUint8 bits, out unsigned long length); */
|
||||
NS_IMETHODIMP nsImageFrame::GetImageData(PRUint8 **aData, PRUint32 *length)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aData = mImageData.data;
|
||||
*length = mImageData.length;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void setImageData ([array, size_is (length), const] in PRUint8 data, in unsigned long length, in long offset); */
|
||||
NS_IMETHODIMP nsImageFrame::SetImageData(const PRUint8 *data, PRUint32 length, PRInt32 offset)
|
||||
{
|
||||
if (!mInitalized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
if (((PRUint32)offset + length) > mImageData.length)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
memcpy(mImageData.data + offset, data, length);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long alphaBytesPerRow; */
|
||||
NS_IMETHODIMP nsImageFrame::GetAlphaBytesPerRow(PRUint32 *aBytesPerRow)
|
||||
{
|
||||
if (!mInitalized || !mAlphaData)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBytesPerRow = mAlphaData->bytesPerRow;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long alphaDataLength; */
|
||||
NS_IMETHODIMP nsImageFrame::GetAlphaDataLength(PRUint32 *aBitsLength)
|
||||
{
|
||||
if (!mInitalized || !mAlphaData)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBitsLength = mAlphaData->length;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void getAlphaData([array, size_is(length)] out PRUint8 bits, out unsigned long length); */
|
||||
NS_IMETHODIMP nsImageFrame::GetAlphaData(PRUint8 **aBits, PRUint32 *length)
|
||||
{
|
||||
if (!mInitalized || !mAlphaData)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBits = mAlphaData->data;
|
||||
*length = mAlphaData->length;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void setAlphaData ([array, size_is (length), const] in PRUint8 data, in unsigned long length, in long offset); */
|
||||
NS_IMETHODIMP nsImageFrame::SetAlphaData(const PRUint8 *data, PRUint32 length, PRInt32 offset)
|
||||
{
|
||||
if (!mInitalized || !mAlphaData)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
if (((PRUint32)offset + length) > mAlphaData->length)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
memcpy(mAlphaData->data + offset, data, length);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult nsImageFrame::DrawImage(GdkDrawable *dest, const GdkGC *gc, const nsRect * aSrcRect, const nsPoint * aDestPoint)
|
||||
{
|
||||
#if 0
|
||||
GdkPixmap *image = gdk_pixmap_new(mSurface->GetDrawable(), width, height, gdk_rgb_get_visual()->depth);
|
||||
#endif
|
||||
|
||||
gdk_draw_rgb_image(dest, NS_CONST_CAST(GdkGC *, gc),
|
||||
(aDestPoint->x + aSrcRect->x), (aDestPoint->y + aSrcRect->y),
|
||||
mRect.width, aSrcRect->height,
|
||||
GDK_RGB_DITHER_MAX,
|
||||
mImageData.data + (aSrcRect->y * mImageData.bytesPerRow),
|
||||
mImageData.bytesPerRow);
|
||||
|
||||
#if 0
|
||||
printf(" (%f, %f), (%i, %i), %i, %i\n}\n", pt.x, pt.y, x, y, width, height);
|
||||
|
||||
gdk_window_copy_area(GDK_ROOT_PARENT(), mGC, 0, 0,
|
||||
image, 0, 0, width, height);
|
||||
|
||||
gdk_window_copy_area(mSurface->GetDrawable(), mGC, pt.x + x, pt.y + y,
|
||||
image, sr.x, 0, sr.width, height);
|
||||
|
||||
gdk_pixmap_unref(image);
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsImageFrame::DrawScaledImage(GdkDrawable *drawable, const GdkGC *gc, const nsRect * aSrcRect, const nsRect * aDestRect)
|
||||
{
|
||||
nsTransform2D trans;
|
||||
trans.SetToScale((float(mRect.width) / float(aDestRect->width)), (float(mRect.height) / float(aDestRect->height)));
|
||||
|
||||
nsRect source(*aSrcRect);
|
||||
nsRect dest(*aDestRect);
|
||||
|
||||
trans.TransformCoord(&source.x, &source.y, &source.width, &source.height);
|
||||
// trans.TransformCoord(&dest.x, &dest.y, &dest.width, &dest.height);
|
||||
|
||||
|
||||
|
||||
GdkPixbuf *pb =
|
||||
gdk_pixbuf_new_from_data(mImageData.data + (source.y * mImageData.bytesPerRow),
|
||||
GDK_COLORSPACE_RGB,
|
||||
PR_FALSE,
|
||||
8,
|
||||
mRect.width, source.height,
|
||||
mImageData.bytesPerRow,
|
||||
NULL, NULL);
|
||||
|
||||
|
||||
GdkPixbuf *npb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, PR_FALSE, 8, dest.width, dest.height);
|
||||
|
||||
gdk_pixbuf_scale(pb, npb,
|
||||
0, 0,
|
||||
dest.width, dest.height,
|
||||
0, 0,
|
||||
double(double(aDestRect->width) / double(mRect.width)),
|
||||
double(double(aDestRect->height) / double(mRect.height)),
|
||||
GDK_INTERP_BILINEAR);
|
||||
|
||||
|
||||
gdk_pixbuf_unref(pb);
|
||||
|
||||
gdk_pixbuf_render_to_drawable(npb,
|
||||
drawable, gc,
|
||||
0, 0,
|
||||
(aDestRect->x + aSrcRect->x),
|
||||
(aDestRect->y + aSrcRect->y),
|
||||
dest.width, dest.height,
|
||||
GDK_RGB_DITHER_MAX,
|
||||
0, 0);
|
||||
|
||||
|
||||
gdk_pixbuf_unref(npb);
|
||||
|
||||
#if 0
|
||||
|
||||
gdk_draw_rgb_image(drawable, NS_CONST_CAST(GdkGC *, gc),
|
||||
(aDestRect->x + aSrcRect->x), (aDestRect->y + aSrcRect->y),
|
||||
mRect.width, source.height,
|
||||
GDK_RGB_DITHER_MAX,
|
||||
mImageData.data + (source.y * mImageData.bytesPerRow),
|
||||
mImageData.bytesPerRow);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
printf(" (%f, %f), (%i, %i), %i, %i\n}\n", pt.x, pt.y, x, y, width, height);
|
||||
|
||||
gdk_window_copy_area(GDK_ROOT_PARENT(), mGC, 0, 0,
|
||||
image, 0, 0, width, height);
|
||||
|
||||
gdk_window_copy_area(mSurface->GetDrawable(), mGC, pt.x + x, pt.y + y,
|
||||
image, sr.x, 0, sr.width, height);
|
||||
|
||||
gdk_pixmap_unref(image);
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
76
gfx2/src/xlib/nsImageFrame.h
Normal file
76
gfx2/src/xlib/nsImageFrame.h
Normal file
@ -0,0 +1,76 @@
|
||||
/* -*- 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) 2000-2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <pavlov@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsIImageFrame.h"
|
||||
|
||||
#include "nsRect.h"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
#define NS_IMAGEFRAME_CID \
|
||||
{ /* 27d55516-1dd2-11b2-9b33-d9a6328f49bd */ \
|
||||
0x27d55516, \
|
||||
0x1dd2, \
|
||||
0x11b2, \
|
||||
{0x9b, 0x33, 0xd9, 0xa6, 0x32, 0x8f, 0x49, 0xbd} \
|
||||
}
|
||||
|
||||
struct ImageData
|
||||
{
|
||||
ImageData() : bytesPerRow(0), data(nsnull), length(0), depth(0) {}
|
||||
~ImageData() {
|
||||
delete[] data;
|
||||
}
|
||||
PRUint32 bytesPerRow; // bytes per row
|
||||
PRUint8 *data;
|
||||
PRUint32 length; // length of the data in bytes
|
||||
gfx_depth depth;
|
||||
};
|
||||
|
||||
class nsImageFrame : public nsIImageFrame
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIIMAGEFRAME
|
||||
|
||||
nsImageFrame();
|
||||
virtual ~nsImageFrame();
|
||||
|
||||
// nsresult DrawImage(Display * display, Drawable dest, const GC gc, const nsRect * aSrcRect, const nsPoint * aDestPoint);
|
||||
nsresult DrawImage(GdkDrawable *dest, const GdkGC *gc, const nsRect * aSrcRect, const nsPoint * aDestPoint);
|
||||
|
||||
nsresult DrawScaledImage(GdkDrawable *dest, const GdkGC *gc, const nsRect * aSrcRect, const nsRect * aDestRect);
|
||||
|
||||
private:
|
||||
/* additional members */
|
||||
nsRect mRect;
|
||||
|
||||
ImageData mImageData; // ... (ends with 16 bits)
|
||||
gfx_format mFormat; // 16 bits
|
||||
|
||||
ImageData *mAlphaData;
|
||||
|
||||
PRBool mInitalized;
|
||||
};
|
67
gfx2/src/xlib/nsPIImageContainerXlib.idl
Normal file
67
gfx2/src/xlib/nsPIImageContainerXlib.idl
Normal file
@ -0,0 +1,67 @@
|
||||
/** -*- 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 "nsISupports.idl"
|
||||
#include "gfxtypes.idl"
|
||||
|
||||
%{C++
|
||||
#include <X11/Xlib.h>
|
||||
#include <gdk/gdk.h>
|
||||
#include "nsRect.h"
|
||||
#include "nsPoint.h"
|
||||
%}
|
||||
|
||||
[ptr] native Display(Display);
|
||||
native Drawable(Drawable);
|
||||
native GC(GC);
|
||||
|
||||
[ptr] native GdkDrawable(GdkDrawable);
|
||||
[ptr] native GdkGC(GdkGC);
|
||||
|
||||
[ptr] native nsPoint(nsPoint);
|
||||
|
||||
/**
|
||||
* nsPIImageContainerXlib interface
|
||||
*
|
||||
* @author Stuart Parmenter <pavlov@netscape.com>
|
||||
* @version 0.1
|
||||
* @see "gfx2"
|
||||
*/
|
||||
[uuid(2d49aaae-1dd2-11b2-8f78-ead44a022560)]
|
||||
interface nsPIImageContainerXlib : nsISupports
|
||||
{
|
||||
/**
|
||||
void drawImage(in Display display,
|
||||
in Drawable dest,
|
||||
[const] in GC gc,
|
||||
[const] in nsRect aSrcRect, [const] in nsPoint aDestPoint);
|
||||
*/
|
||||
void drawImage(in GdkDrawable dest,
|
||||
[const] in GdkGC gc, // XCopyGC if you are planning on changing it
|
||||
[const] in nsRect aSrcRect, [const] in nsPoint aDestPoint);
|
||||
|
||||
void drawScaledImage(in GdkDrawable dest,
|
||||
[const] in GdkGC gc, /* XCopyGC if you are
|
||||
planning on changing it */
|
||||
[const] in nsRect aSrcRect, [const] in nsRect aDestRect);
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user