зеркало из https://github.com/mozilla/pjs.git
added nsIImageContainer and nsIImageFrame and removed nsIImage2
This commit is contained in:
Родитель
f16869f798
Коммит
1ed948da56
|
@ -1,49 +0,0 @@
|
|||
#
|
||||
# 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 = gfx2
|
||||
|
||||
XPIDLSRCS = \
|
||||
gfxtypes.idl \
|
||||
nsIImage2.idl \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
gfxcompat.h \
|
||||
nsMargin2.h \
|
||||
nsPoint2.h \
|
||||
nsRect2.h \
|
||||
nsSize2.h \
|
||||
nsUnitConverters.h \
|
||||
$(NULL)
|
||||
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
#
|
||||
# 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
|
||||
XPIDL_MODULE = gfx2
|
||||
|
||||
XPIDLSRCS = \
|
||||
.\gfxtypes.idl \
|
||||
.\nsIImage2.idl \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
.\gfxcompat.h \
|
||||
.\nsMargin2.h \
|
||||
.\nsPoint2.h \
|
||||
.\nsRect2.h \
|
||||
.\nsSize2.h \
|
||||
.\nsUnitConverters.h \
|
||||
$(NULL)
|
||||
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
|
@ -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 "nsISupports.idl"
|
||||
#include "gfxtypes.idl"
|
||||
|
||||
interface nsIDrawable;
|
||||
interface nsIImageFrame;
|
||||
interface nsIEnumerator;
|
||||
|
||||
/**
|
||||
* nsIImage interface
|
||||
*
|
||||
* @author Tim Rowley <tor@cs.brown.edu>
|
||||
* @author Stuart Parmenter <pavlov@netscape.com>
|
||||
* @version 1.2
|
||||
* @see "gfx2"
|
||||
*/
|
||||
[scriptable, uuid(5e8405a4-1dd2-11b2-8385-bc8e3446cad3)]
|
||||
interface nsIImageContainer : nsISupports
|
||||
{
|
||||
/**
|
||||
* Create a new \a aWidth x \a aHeight sized image container.
|
||||
*
|
||||
* @param aWidth The width of the container in which all the nsIImageFrame children will fit.
|
||||
* @param aHeight The height of the container in which all the nsIImageFrame children will fit.
|
||||
*/
|
||||
void init(in gfx_dimension aWidth,
|
||||
in gfx_dimension aHeight);
|
||||
|
||||
/**
|
||||
* The width of the image.
|
||||
*/
|
||||
readonly attribute gfx_dimension width;
|
||||
|
||||
/**
|
||||
* The height of the image.
|
||||
*/
|
||||
readonly attribute gfx_dimension height;
|
||||
|
||||
|
||||
/**
|
||||
* Get the current frame that would be drawn if the image was to be drawn now
|
||||
*/
|
||||
readonly attribute nsIImageFrame currentFrame;
|
||||
|
||||
|
||||
|
||||
readonly attribute unsigned long numFrames;
|
||||
nsIImageFrame getFrameAt(in unsigned long index);
|
||||
|
||||
void appendFrame(in nsIImageFrame item);
|
||||
void removeFrame(in nsIImageFrame item);
|
||||
|
||||
nsIEnumerator enumerate();
|
||||
|
||||
void clear();
|
||||
|
||||
};
|
|
@ -0,0 +1,110 @@
|
|||
/** -*- 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"
|
||||
|
||||
/**
|
||||
* nsIImage interface
|
||||
*
|
||||
* @author Tim Rowley <tor@cs.brown.edu>
|
||||
* @author Stuart Parmenter <pavlov@netscape.com>
|
||||
* @version 1.2
|
||||
* @see "gfx2"
|
||||
*/
|
||||
[scriptable, uuid(51cc27a8-1dd2-11b2-a1aa-dad33ab193b4)]
|
||||
interface nsIImageFrame : nsISupports
|
||||
{
|
||||
/**
|
||||
* Create a new \a aWidth x \a aHeight sized image.
|
||||
*
|
||||
* @param aX The offset from the nsIImageContainer parent at (0,0)
|
||||
* @param aY The offset from the nsIImageContainer parent at (0,0)
|
||||
* @param aWidth The width of the image to create.
|
||||
* @param aHeight The height of the image to create.
|
||||
* @param aFormat the width of the image to create.
|
||||
*
|
||||
* @note The data of a new image is unspecified (Whats the word i'm looking for here?).
|
||||
*/
|
||||
void init(in gfx_coord aX,
|
||||
in gfx_coord aY,
|
||||
in gfx_dimension aWidth,
|
||||
in gfx_dimension aHeight,
|
||||
in gfx_format aFormat);
|
||||
|
||||
|
||||
/**
|
||||
* The width of the image.
|
||||
*/
|
||||
readonly attribute gfx_coord x;
|
||||
|
||||
/**
|
||||
* The width of the image.
|
||||
*/
|
||||
readonly attribute gfx_coord y;
|
||||
|
||||
/**
|
||||
* The width of the image.
|
||||
*/
|
||||
readonly attribute gfx_dimension width;
|
||||
|
||||
/**
|
||||
* The height of the image.
|
||||
*/
|
||||
readonly attribute gfx_dimension height;
|
||||
|
||||
/**
|
||||
* The width of the image.
|
||||
*/
|
||||
[noscript] readonly attribute nsRect2 rect;
|
||||
|
||||
|
||||
/**
|
||||
* The image data format the image was created with.
|
||||
* @see nsIGFXFormat
|
||||
*/
|
||||
readonly attribute gfx_format format;
|
||||
|
||||
readonly attribute unsigned long bytesPerRow;
|
||||
|
||||
/**
|
||||
* returns the number of bytes allocated for the image
|
||||
*/
|
||||
readonly attribute unsigned long bitsLength;
|
||||
|
||||
// XXX do we copy here? lets not...
|
||||
void getBits([array, size_is(length)] out PRUint8 bits, out unsigned long length);
|
||||
|
||||
/**
|
||||
* Sets \a length bytes of \a data in this object.
|
||||
* @param offset The offset from the first pixel in bytes. To set
|
||||
* data beginning with the first (top left) pixel in the image, \a offset
|
||||
* should be 0; to set data beginning with, for example, the sixth pixel in
|
||||
* the first row of a RGBA32 image, the offset should be 20.
|
||||
* @attension should we use PRUint32 instead?
|
||||
*/
|
||||
void setBits([array, size_is(length), const] in PRUint8 data,
|
||||
in unsigned long length,
|
||||
in long offset);
|
||||
|
||||
};
|
|
@ -1,51 +0,0 @@
|
|||
#!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 #_s
|
||||
DLL = $(OBJDIR)\$(LIBRARY_NAME).dll
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
|
||||
OBJS = \
|
||||
.\$(OBJDIR)\nsRect.obj \
|
||||
.\$(OBJDIR)\nsImage.obj \
|
||||
.\$(OBJDIR)\nsGfxFactory.obj \
|
||||
$(NULL)
|
||||
|
||||
LLIBS = \
|
||||
$(DIST)\lib\xpcom.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
|
|
@ -1,42 +0,0 @@
|
|||
/* -*- 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 "nsImage.h"
|
||||
|
||||
// objects that just require generic constructors
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImage)
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ "windows image",
|
||||
NS_IMAGE_CID,
|
||||
"@mozilla.org/gfx/image;2",
|
||||
nsImageConstructor, },
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("nsGfx2Module", components)
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
/* -*- 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 "nsImageContainer.h"
|
||||
|
||||
#include "nsUnitConverters.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsImageContainer, nsIImageContainer)
|
||||
|
||||
nsImageContainer::nsImageContainer()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
/* member initializers and constructor code */
|
||||
}
|
||||
|
||||
nsImageContainer::~nsImageContainer()
|
||||
{
|
||||
/* destructor code */
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* void init (in gfx_dimension aWidth, in gfx_dimension aHeight); */
|
||||
NS_IMETHODIMP nsImageContainer::Init(gfx_dimension aWidth, gfx_dimension aHeight)
|
||||
{
|
||||
if (aWidth <= 0 || aHeight <= 0) {
|
||||
printf("error - negative image size\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
mSize.SizeTo(aWidth, aHeight);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute gfx_dimension width; */
|
||||
NS_IMETHODIMP nsImageContainer::GetWidth(gfx_dimension *aWidth)
|
||||
{
|
||||
*aWidth = mSize.width;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute gfx_dimension height; */
|
||||
NS_IMETHODIMP nsImageContainer::GetHeight(gfx_dimension *aHeight)
|
||||
{
|
||||
*aHeight = mSize.height;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* readonly attribute nsIImageFrame currentFrame; */
|
||||
NS_IMETHODIMP nsImageContainer::GetCurrentFrame(nsIImageFrame * *aCurrentFrame)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long numFrames; */
|
||||
NS_IMETHODIMP nsImageContainer::GetNumFrames(PRUint32 *aNumFrames)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* nsIImageFrame getFrameAt (in unsigned long index); */
|
||||
NS_IMETHODIMP nsImageContainer::GetFrameAt(PRUint32 index, nsIImageFrame **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void appendFrame (in nsIImageFrame item); */
|
||||
NS_IMETHODIMP nsImageContainer::AppendFrame(nsIImageFrame *item)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* 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 NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
|
@ -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 "nsIImageContainer.h"
|
||||
|
||||
#include "nsSize2.h"
|
||||
|
||||
#define NS_IMAGECONTAINER_CID \
|
||||
{ /* aa699204-1dd1-11b2-84a9-a280c268e4fb */ \
|
||||
0xaa699204, \
|
||||
0x1dd1, \
|
||||
0x11b2, \
|
||||
{0x84, 0xa9, 0xa2, 0x80, 0xc2, 0x68, 0xe4, 0xfb} \
|
||||
}
|
||||
|
||||
class nsImageContainer : public nsIImageContainer
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIIMAGECONTAINER
|
||||
|
||||
nsImageContainer();
|
||||
virtual ~nsImageContainer();
|
||||
|
||||
private:
|
||||
/* additional members */
|
||||
nsSize2 mSize;
|
||||
};
|
||||
|
|
@ -0,0 +1,316 @@
|
|||
/* -*- 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 "nsUnitConverters.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsImageFrame, nsIImageFrame)
|
||||
|
||||
nsImageFrame::nsImageFrame() :
|
||||
mBits(nsnull)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
/* member initializers and constructor code */
|
||||
}
|
||||
|
||||
nsImageFrame::~nsImageFrame()
|
||||
{
|
||||
/* destructor code */
|
||||
delete[] mBits;
|
||||
mBits = nsnull;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
void errhandler(char *foo, void *a) {}
|
||||
|
||||
void CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi,
|
||||
HBITMAP hBMP, HDC hDC)
|
||||
{
|
||||
HANDLE hf; // file handle
|
||||
BITMAPFILEHEADER hdr; // bitmap file-header
|
||||
PBITMAPINFOHEADER pbih; // bitmap info-header
|
||||
LPBYTE lpBits; // memory pointer
|
||||
DWORD dwTotal; // total count of bytes
|
||||
DWORD cb; // incremental count of bytes
|
||||
BYTE *hp; // byte pointer
|
||||
DWORD dwTmp;
|
||||
|
||||
pbih = (PBITMAPINFOHEADER) pbi;
|
||||
lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);
|
||||
|
||||
if (!lpBits)
|
||||
errhandler("GlobalAlloc", hwnd);
|
||||
|
||||
// Retrieve the color table (RGBQUAD array) and the bits
|
||||
// (array of palette indices) from the DIB.
|
||||
if (!GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi,
|
||||
DIB_RGB_COLORS))
|
||||
{
|
||||
errhandler("GetDIBits", hwnd);
|
||||
}
|
||||
|
||||
// Create the .BMP file.
|
||||
hf = CreateFile(pszFile,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
(DWORD) 0,
|
||||
NULL,
|
||||
CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
(HANDLE) NULL);
|
||||
if (hf == INVALID_HANDLE_VALUE)
|
||||
errhandler("CreateFile", hwnd);
|
||||
hdr.bfType = 0x4d42; // 0x42 = "B" 0x4d = "M"
|
||||
// Compute the size of the entire file.
|
||||
hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) +
|
||||
pbih->biSize + pbih->biClrUsed
|
||||
* sizeof(RGBQUAD) + pbih->biSizeImage);
|
||||
hdr.bfReserved1 = 0;
|
||||
hdr.bfReserved2 = 0;
|
||||
|
||||
// Compute the offset to the array of color indices.
|
||||
hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) +
|
||||
pbih->biSize + pbih->biClrUsed
|
||||
* sizeof (RGBQUAD);
|
||||
|
||||
// Copy the BITMAPFILEHEADER into the .BMP file.
|
||||
if (!WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER),
|
||||
(LPDWORD) &dwTmp, NULL))
|
||||
{
|
||||
errhandler("WriteFile", hwnd);
|
||||
}
|
||||
|
||||
// Copy the BITMAPINFOHEADER and RGBQUAD array into the file.
|
||||
if (!WriteFile(hf, (LPVOID) pbih,
|
||||
sizeof(BITMAPINFOHEADER) + pbih->biClrUsed * sizeof (RGBQUAD),
|
||||
(LPDWORD) &dwTmp,
|
||||
(NULL)
|
||||
)
|
||||
)
|
||||
errhandler("WriteFile", hwnd);
|
||||
|
||||
// Copy the array of color indices into the .BMP file.
|
||||
dwTotal = cb = pbih->biSizeImage;
|
||||
hp = lpBits;
|
||||
if (!WriteFile(hf, (LPSTR) hp, (int) cb, (LPDWORD) &dwTmp,NULL))
|
||||
errhandler("WriteFile", hwnd);
|
||||
|
||||
// Close the .BMP file.
|
||||
if (!CloseHandle(hf))
|
||||
errhandler("CloseHandle", hwnd);
|
||||
|
||||
// Free memory.
|
||||
GlobalFree((HGLOBAL)lpBits);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* void init (in gfx_coord aX, in gfx_coord aY, in gfx_dimension aWidth, in gfx_dimension aHeight, in gfx_format aFormat); */
|
||||
NS_IMETHODIMP nsImageFrame::Init(gfx_coord aX, gfx_coord aY, gfx_dimension aWidth, gfx_dimension aHeight, gfx_format aFormat)
|
||||
{
|
||||
if (aWidth <= 0 || aHeight <= 0) {
|
||||
printf("error - negative image size\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
delete[] mBits;
|
||||
|
||||
mRect.SetRect(aX, aY, aWidth, aHeight);
|
||||
mFormat = aFormat;
|
||||
|
||||
switch (aFormat) {
|
||||
case nsIGFXFormat::RGB:
|
||||
case nsIGFXFormat::RGB_A1:
|
||||
case nsIGFXFormat::RGB_A8:
|
||||
mDepth = 24;
|
||||
break;
|
||||
case nsIGFXFormat::RGBA:
|
||||
mDepth = 32;
|
||||
break;
|
||||
default:
|
||||
printf("unsupposed gfx_format\n");
|
||||
break;
|
||||
}
|
||||
|
||||
PRInt32 ceilWidth(GFXCoordToIntCeil(mRect.width));
|
||||
|
||||
mBytesPerRow = (ceilWidth * mDepth) >> 5;
|
||||
|
||||
if ((ceilWidth * mDepth) & 0x1F)
|
||||
mBytesPerRow++;
|
||||
mBytesPerRow <<= 2;
|
||||
|
||||
mBitsLength = mBytesPerRow * GFXCoordToIntCeil(mRect.height);
|
||||
|
||||
mBits = new PRUint8[mBitsLength];
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute gfx_coord x; */
|
||||
NS_IMETHODIMP nsImageFrame::GetX(gfx_coord *aX)
|
||||
{
|
||||
if (!mBits)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aX = mRect.x;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute gfx_coord y; */
|
||||
NS_IMETHODIMP nsImageFrame::GetY(gfx_coord *aY)
|
||||
{
|
||||
if (!mBits)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aY = mRect.y;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* readonly attribute gfx_dimension width; */
|
||||
NS_IMETHODIMP nsImageFrame::GetWidth(gfx_dimension *aWidth)
|
||||
{
|
||||
if (!mBits)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aWidth = mRect.width;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute gfx_dimension height; */
|
||||
NS_IMETHODIMP nsImageFrame::GetHeight(gfx_dimension *aHeight)
|
||||
{
|
||||
if (!mBits)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aHeight = mRect.height;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsRect2 rect; */
|
||||
NS_IMETHODIMP nsImageFrame::GetRect(nsRect2 **aRect)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
if (!mBits)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
// *aRect = mRect;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute gfx_format format; */
|
||||
NS_IMETHODIMP nsImageFrame::GetFormat(gfx_format *aFormat)
|
||||
{
|
||||
if (!mBits)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
#if 0
|
||||
|
||||
HWND bg = GetDesktopWindow();
|
||||
HDC memDC = GetDC(NULL);
|
||||
|
||||
LPBITMAPINFOHEADER mBHead = (LPBITMAPINFOHEADER)new char[sizeof(BITMAPINFO)];
|
||||
|
||||
mBHead->biSize = sizeof(BITMAPINFOHEADER);
|
||||
mBHead->biWidth = GFXCoordToIntCeil(mRect.width);
|
||||
mBHead->biHeight = -GFXCoordToIntCeil(mRect.height);
|
||||
mBHead->biPlanes = 1;
|
||||
mBHead->biBitCount = mDepth;
|
||||
mBHead->biCompression = BI_RGB;
|
||||
mBHead->biSizeImage = mBitsLength; // not compressed, so we dont need this to be set
|
||||
mBHead->biXPelsPerMeter = 0;
|
||||
mBHead->biYPelsPerMeter = 0;
|
||||
mBHead->biClrUsed = 0;
|
||||
mBHead->biClrImportant = 0;
|
||||
|
||||
HBITMAP memBM = ::CreateDIBitmap(memDC,mBHead,CBM_INIT,mBits,(LPBITMAPINFO)mBHead,
|
||||
DIB_RGB_COLORS);
|
||||
|
||||
SelectObject(memDC, memBM);
|
||||
|
||||
|
||||
mBHead->biHeight = -mBHead->biHeight;
|
||||
|
||||
CreateBMPFile(bg, "c:\\whatever.bmp", (LPBITMAPINFO)mBHead,
|
||||
memBM, memDC) ;
|
||||
|
||||
ReleaseDC(NULL, memDC);
|
||||
|
||||
DeleteObject(memBM);
|
||||
|
||||
#endif
|
||||
*aFormat = mFormat;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long bytesPerRow; */
|
||||
NS_IMETHODIMP nsImageFrame::GetBytesPerRow(PRUint32 *aBytesPerRow)
|
||||
{
|
||||
if (!mBits)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBytesPerRow = mBytesPerRow;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long bitsLength; */
|
||||
NS_IMETHODIMP nsImageFrame::GetBitsLength(PRUint32 *aBitsLength)
|
||||
{
|
||||
if (!mBits)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBitsLength = mBitsLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void getBits([array, size_is(length)] out PRUint8 bits, out unsigned long length); */
|
||||
NS_IMETHODIMP nsImageFrame::GetBits(PRUint8 **aBits, PRUint32 *length)
|
||||
{
|
||||
if (!mBits)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
*aBits = mBits;
|
||||
*length = mBitsLength;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void setBits ([array, size_is (length), const] in PRUint8 data, in unsigned long length, in long offset); */
|
||||
NS_IMETHODIMP nsImageFrame::SetBits(const PRUint8 *data, PRUint32 length, PRInt32 offset)
|
||||
{
|
||||
if (!mBits)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
if (((PRUint32)offset + length) > mBitsLength)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
memcpy(mBits + offset, data, length);
|
||||
|
||||
return NS_OK;
|
||||
}
|
Загрузка…
Ссылка в новой задаче