Compare commits
10 Commits
GIF_CLEANU
...
jnance_str
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5efdd75081 | ||
|
|
bb4d583501 | ||
|
|
87f2b425c5 | ||
|
|
e6beef1883 | ||
|
|
86e80f88cd | ||
|
|
a6b3ccc7c5 | ||
|
|
1c214c2fab | ||
|
|
806cb0a4d6 | ||
|
|
1baf4456fb | ||
|
|
f5ac20ebb4 |
5120
mozilla/gfx/src/gtk/nsFontMetricsGTK.cpp
Normal file
5120
mozilla/gfx/src/gtk/nsFontMetricsGTK.cpp
Normal file
File diff suppressed because it is too large
Load Diff
219
mozilla/gfx/src/gtk/nsFontMetricsGTK.h
Normal file
219
mozilla/gfx/src/gtk/nsFontMetricsGTK.h
Normal file
@@ -0,0 +1,219 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab:
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsFontMetricsGTK_h__
|
||||
#define nsFontMetricsGTK_h__
|
||||
|
||||
#include "nsDeviceContextGTK.h"
|
||||
#include "nsIFontMetrics.h"
|
||||
#include "nsIFontEnumerator.h"
|
||||
#include "nsFont.h"
|
||||
#include "nsString.h"
|
||||
#include "nsUnitConversion.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsRenderingContextGTK.h"
|
||||
#include "nsICharRepresentable.h"
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
#undef FONT_HAS_GLYPH
|
||||
#define FONT_HAS_GLYPH(map, char) IS_REPRESENTABLE(map, char)
|
||||
|
||||
typedef struct nsFontCharSetInfo nsFontCharSetInfo;
|
||||
|
||||
typedef gint (*nsFontCharSetConverter)(nsFontCharSetInfo* aSelf,
|
||||
XFontStruct* aFont, const PRUnichar* aSrcBuf, PRInt32 aSrcLen,
|
||||
char* aDestBuf, PRInt32 aDestLen);
|
||||
|
||||
struct nsFontCharSet;
|
||||
struct nsFontFamily;
|
||||
struct nsFontNode;
|
||||
struct nsFontStretch;
|
||||
|
||||
class nsFontGTKUserDefined;
|
||||
class nsFontMetricsGTK;
|
||||
|
||||
class nsFontGTK
|
||||
{
|
||||
public:
|
||||
nsFontGTK();
|
||||
virtual ~nsFontGTK();
|
||||
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
||||
|
||||
void LoadFont(void);
|
||||
PRBool IsEmptyFont(GdkFont*);
|
||||
|
||||
inline int SupportsChar(PRUnichar aChar)
|
||||
{ return mFont && FONT_HAS_GLYPH(mMap, aChar); };
|
||||
|
||||
virtual GdkFont* GetGDKFont(void);
|
||||
virtual PRBool GetGDKFontIs10646(void);
|
||||
virtual gint GetWidth(const PRUnichar* aString, PRUint32 aLength) = 0;
|
||||
virtual gint DrawString(nsRenderingContextGTK* aContext,
|
||||
nsDrawingSurfaceGTK* aSurface, nscoord aX,
|
||||
nscoord aY, const PRUnichar* aString,
|
||||
PRUint32 aLength) = 0;
|
||||
#ifdef MOZ_MATHML
|
||||
// bounding metrics for a string
|
||||
// remember returned values are not in app units
|
||||
// - to emulate GetWidth () above
|
||||
virtual nsresult
|
||||
GetBoundingMetrics(const PRUnichar* aString,
|
||||
PRUint32 aLength,
|
||||
nsBoundingMetrics& aBoundingMetrics) = 0;
|
||||
#endif
|
||||
|
||||
PRUint32* mMap;
|
||||
nsFontCharSetInfo* mCharSetInfo;
|
||||
char* mName;
|
||||
nsFontGTKUserDefined* mUserDefinedFont;
|
||||
PRUint16 mSize;
|
||||
PRInt16 mBaselineAdjust;
|
||||
|
||||
protected:
|
||||
GdkFont* mFont;
|
||||
PRBool mAlreadyCalledLoadFont;
|
||||
};
|
||||
|
||||
class nsFontMetricsGTK : public nsIFontMetrics
|
||||
{
|
||||
public:
|
||||
nsFontMetricsGTK();
|
||||
virtual ~nsFontMetricsGTK();
|
||||
|
||||
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Init(const nsFont& aFont, nsIAtom* aLangGroup,
|
||||
nsIDeviceContext* aContext);
|
||||
NS_IMETHOD Destroy();
|
||||
|
||||
NS_IMETHOD GetXHeight(nscoord& aResult);
|
||||
NS_IMETHOD GetSuperscriptOffset(nscoord& aResult);
|
||||
NS_IMETHOD GetSubscriptOffset(nscoord& aResult);
|
||||
NS_IMETHOD GetStrikeout(nscoord& aOffset, nscoord& aSize);
|
||||
NS_IMETHOD GetUnderline(nscoord& aOffset, nscoord& aSize);
|
||||
|
||||
NS_IMETHOD GetHeight(nscoord &aHeight);
|
||||
NS_IMETHOD GetNormalLineHeight(nscoord &aHeight);
|
||||
NS_IMETHOD GetLeading(nscoord &aLeading);
|
||||
NS_IMETHOD GetEmHeight(nscoord &aHeight);
|
||||
NS_IMETHOD GetEmAscent(nscoord &aAscent);
|
||||
NS_IMETHOD GetEmDescent(nscoord &aDescent);
|
||||
NS_IMETHOD GetMaxHeight(nscoord &aHeight);
|
||||
NS_IMETHOD GetMaxAscent(nscoord &aAscent);
|
||||
NS_IMETHOD GetMaxDescent(nscoord &aDescent);
|
||||
NS_IMETHOD GetMaxAdvance(nscoord &aAdvance);
|
||||
NS_IMETHOD GetFont(const nsFont *&aFont);
|
||||
NS_IMETHOD GetLangGroup(nsIAtom** aLangGroup);
|
||||
NS_IMETHOD GetFontHandle(nsFontHandle &aHandle);
|
||||
|
||||
virtual nsresult GetSpaceWidth(nscoord &aSpaceWidth);
|
||||
|
||||
nsFontGTK* FindFont(PRUnichar aChar);
|
||||
nsFontGTK* FindUserDefinedFont(PRUnichar aChar);
|
||||
nsFontGTK* FindStyleSheetSpecificFont(PRUnichar aChar);
|
||||
nsFontGTK* FindStyleSheetGenericFont(PRUnichar aChar);
|
||||
nsFontGTK* FindLangGroupPrefFont(nsIAtom* aLangGroup, PRUnichar aChar);
|
||||
nsFontGTK* FindLangGroupFont(nsIAtom* aLangGroup, PRUnichar aChar, nsCString* aName);
|
||||
nsFontGTK* FindAnyFont(PRUnichar aChar);
|
||||
nsFontGTK* FindSubstituteFont(PRUnichar aChar);
|
||||
|
||||
nsFontGTK* SearchNode(nsFontNode* aNode, PRUnichar aChar);
|
||||
nsFontGTK* TryAliases(nsCString* aName, PRUnichar aChar);
|
||||
nsFontGTK* TryFamily(nsCString* aName, PRUnichar aChar);
|
||||
nsFontGTK* TryNode(nsCString* aName, PRUnichar aChar);
|
||||
nsFontGTK* TryNodes(nsAWritableCString &aFFREName, PRUnichar aChar);
|
||||
nsFontGTK* TryLangGroup(nsIAtom* aLangGroup, nsCString* aName, PRUnichar aChar);
|
||||
|
||||
nsFontGTK* AddToLoadedFontsList(nsFontGTK* aFont);
|
||||
nsFontGTK* PickASizeAndLoad(nsFontStretch* aStretch,
|
||||
nsFontCharSetInfo* aCharSet,
|
||||
PRUnichar aChar,
|
||||
const char *aName);
|
||||
|
||||
static nsresult FamilyExists(const nsString& aFontName);
|
||||
|
||||
//friend struct nsFontGTK;
|
||||
|
||||
nsFontGTK **mLoadedFonts;
|
||||
PRUint16 mLoadedFontsAlloc;
|
||||
PRUint16 mLoadedFontsCount;
|
||||
|
||||
nsFontGTK *mSubstituteFont;
|
||||
|
||||
nsCStringArray mFonts;
|
||||
PRUint16 mFontsIndex;
|
||||
nsVoidArray mFontIsGeneric;
|
||||
|
||||
nsCAutoString mDefaultFont;
|
||||
nsCString *mGeneric;
|
||||
nsCOMPtr<nsIAtom> mLangGroup;
|
||||
nsCAutoString mUserDefined;
|
||||
|
||||
PRUint8 mTriedAllGenerics;
|
||||
PRUint8 mIsUserDefined;
|
||||
|
||||
protected:
|
||||
void RealizeFont();
|
||||
|
||||
nsIDeviceContext *mDeviceContext;
|
||||
nsFont *mFont;
|
||||
nsFontGTK *mWesternFont;
|
||||
|
||||
nscoord mLeading;
|
||||
nscoord mEmHeight;
|
||||
nscoord mEmAscent;
|
||||
nscoord mEmDescent;
|
||||
nscoord mMaxHeight;
|
||||
nscoord mMaxAscent;
|
||||
nscoord mMaxDescent;
|
||||
nscoord mMaxAdvance;
|
||||
nscoord mXHeight;
|
||||
nscoord mSuperscriptOffset;
|
||||
nscoord mSubscriptOffset;
|
||||
nscoord mStrikeoutSize;
|
||||
nscoord mStrikeoutOffset;
|
||||
nscoord mUnderlineSize;
|
||||
nscoord mUnderlineOffset;
|
||||
nscoord mSpaceWidth;
|
||||
|
||||
PRUint16 mPixelSize;
|
||||
PRUint8 mStretchIndex;
|
||||
PRUint8 mStyleIndex;
|
||||
nsFontCharSetConverter mDocConverterType;
|
||||
};
|
||||
|
||||
class nsFontEnumeratorGTK : public nsIFontEnumerator
|
||||
{
|
||||
public:
|
||||
nsFontEnumeratorGTK();
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIFONTENUMERATOR
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,338 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef _GIF_H_
|
||||
#define _GIF_H_
|
||||
|
||||
/* gif2.h
|
||||
The interface for the GIF87/89a decoder.
|
||||
*/
|
||||
// List of possible parsing states
|
||||
typedef enum {
|
||||
gif_gather,
|
||||
gif_init, //1
|
||||
gif_type,
|
||||
gif_version,
|
||||
gif_global_header,
|
||||
gif_global_colormap,
|
||||
gif_image_start, //6
|
||||
gif_image_header,
|
||||
gif_image_colormap,
|
||||
gif_image_body,
|
||||
gif_lzw_start,
|
||||
gif_lzw, //11
|
||||
gif_sub_block,
|
||||
gif_extension,
|
||||
gif_control_extension,
|
||||
gif_consume_block,
|
||||
gif_skip_block,
|
||||
gif_done, //17
|
||||
gif_oom,
|
||||
gif_error,
|
||||
gif_comment_extension,
|
||||
gif_application_extension,
|
||||
gif_netscape_extension_block,
|
||||
gif_consume_netscape_extension,
|
||||
gif_consume_comment,
|
||||
gif_delay,
|
||||
gif_wait_for_buffer_full,
|
||||
gif_stop_animating //added for animation stop
|
||||
} gstate;
|
||||
|
||||
/* "Disposal" method indicates how the image should be handled in the
|
||||
framebuffer before the subsequent image is displayed. */
|
||||
typedef enum
|
||||
{
|
||||
DISPOSE_NOT_SPECIFIED = 0,
|
||||
DISPOSE_KEEP = 1, /* Leave it in the framebuffer */
|
||||
DISPOSE_OVERWRITE_BGCOLOR = 2, /* Overwrite with background color */
|
||||
DISPOSE_OVERWRITE_PREVIOUS = 4 /* Save-under */
|
||||
} gdispose;
|
||||
|
||||
/* A RGB triplet representing a single pixel in the image's colormap
|
||||
(if present.) */
|
||||
typedef struct _GIF_RGB
|
||||
{
|
||||
PRUint8 red, green, blue, pad; /* Windows requires the fourth byte &
|
||||
many compilers pad it anyway. */
|
||||
|
||||
/* XXX: hist_count appears to be unused */
|
||||
//PRUint16 hist_count; /* Histogram frequency count. */
|
||||
} GIF_RGB;
|
||||
|
||||
/* Colormap information. */
|
||||
typedef struct _GIF_ColorMap {
|
||||
int32 num_colors; /* Number of colors in the colormap.
|
||||
A negative value can be used to denote a
|
||||
possibly non-unique set. */
|
||||
GIF_RGB *map; /* Colormap colors. */
|
||||
PRUint8 *index; /* NULL, if map is in index order. Otherwise
|
||||
specifies the indices of the map entries. */
|
||||
void *table; /* Lookup table for this colormap. Private to
|
||||
the Image Library. */
|
||||
} GIF_ColorMap;
|
||||
|
||||
/* An indexed RGB triplet. */
|
||||
typedef struct _GIF_IRGB {
|
||||
PRUint8 index;
|
||||
PRUint8 red, green, blue;
|
||||
} GIF_IRGB;
|
||||
|
||||
/* A GIF decoder's state */
|
||||
typedef struct gif_struct {
|
||||
void* clientptr;
|
||||
/* Callbacks for this decoder instance*/
|
||||
int (PR_CALLBACK *GIFCallback_NewPixmap)();
|
||||
int (PR_CALLBACK *GIFCallback_BeginGIF)(
|
||||
void* aClientData,
|
||||
PRUint32 aLogicalScreenWidth,
|
||||
PRUint32 aLogicalScreenHeight,
|
||||
PRUint8 aLogicalScreenBackgroundRGBIndex);
|
||||
|
||||
int (PR_CALLBACK* GIFCallback_EndGIF)(
|
||||
void* aClientData,
|
||||
int aAnimationLoopCount);
|
||||
|
||||
int (PR_CALLBACK* GIFCallback_BeginImageFrame)(
|
||||
void* aClientData,
|
||||
PRUint32 aFrameNumber, /* Frame number, 1-n */
|
||||
PRUint32 aFrameXOffset, /* X offset in logical screen */
|
||||
PRUint32 aFrameYOffset, /* Y offset in logical screen */
|
||||
PRUint32 aFrameWidth,
|
||||
PRUint32 aFrameHeight,
|
||||
GIF_RGB* aTransparencyChromaKey);
|
||||
int (PR_CALLBACK* GIFCallback_EndImageFrame)(
|
||||
void* aClientData,
|
||||
PRUint32 aFrameNumber,
|
||||
PRUint32 aDelayTimeout,
|
||||
PRUint32 aDisposal);
|
||||
int (PR_CALLBACK* GIFCallback_SetupColorspaceConverter)();
|
||||
int (PR_CALLBACK* GIFCallback_ResetPalette)();
|
||||
int (PR_CALLBACK* GIFCallback_InitTransparentPixel)();
|
||||
int (PR_CALLBACK* GIFCallback_DestroyTransparentPixel)();
|
||||
int (PR_CALLBACK* GIFCallback_HaveDecodedRow)(
|
||||
void* aClientData,
|
||||
PRUint8* aRowBufPtr, /* Pointer to single scanline temporary buffer */
|
||||
int aXOffset, /* With respect to GIF logical screen origin */
|
||||
int aLength, /* Length of the row? */
|
||||
int aRow, /* Row number? */
|
||||
int aDuplicateCount, /* Number of times to duplicate the row? */
|
||||
PRUint8 aDrawMode, /* il_draw_mode */
|
||||
int aInterlacePass);
|
||||
int (PR_CALLBACK *GIFCallback_HaveImageAll)(
|
||||
void* aClientData);
|
||||
|
||||
/* Parsing state machine */
|
||||
gstate state; /* Curent decoder master state */
|
||||
PRUint8 *hold; /* Accumulation buffer */
|
||||
int32 hold_size; /* Capacity, in bytes, of accumulation buffer */
|
||||
PRUint8 *gather_head; /* Next byte to read in accumulation buffer */
|
||||
int32 gather_request_size; /* Number of bytes to accumulate */
|
||||
int32 gathered; /* bytes accumulated so far*/
|
||||
gstate post_gather_state; /* State after requested bytes accumulated */
|
||||
int32 requested_buffer_fullness; /* For netscape application extension */
|
||||
|
||||
/* LZW decoder state machine */
|
||||
PRUint8 *stack; /* Base of decoder stack */
|
||||
PRUint8 *stackp; /* Current stack pointer */
|
||||
PRUint16 *prefix;
|
||||
PRUint8 *suffix;
|
||||
int datasize;
|
||||
int codesize;
|
||||
int codemask;
|
||||
int clear_code; /* Codeword used to trigger dictionary reset */
|
||||
int avail; /* Index of next available slot in dictionary */
|
||||
int oldcode;
|
||||
PRUint8 firstchar;
|
||||
int count; /* Remaining # bytes in sub-block */
|
||||
int bits; /* Number of unread bits in "datum" */
|
||||
int32 datum; /* 32-bit input buffer */
|
||||
|
||||
/* Output state machine */
|
||||
int ipass; /* Interlace pass; Ranges 1-4 if interlaced. */
|
||||
PRUintn rows_remaining; /* Rows remaining to be output */
|
||||
PRUintn irow; /* Current output row, starting at zero */
|
||||
PRUint8 *rowbuf; /* Single scanline temporary buffer */
|
||||
PRUint8 *rowend; /* Pointer to end of rowbuf */
|
||||
PRUint8 *rowp; /* Current output pointer */
|
||||
|
||||
/* Parameters for image frame currently being decoded*/
|
||||
PRUintn x_offset, y_offset; /* With respect to "screen" origin */
|
||||
PRUintn height, width;
|
||||
PRUintn last_x_offset, last_y_offset; /* With respect to "screen" origin */
|
||||
PRUintn last_height, last_width;
|
||||
int interlaced; /* TRUE, if scanlines arrive interlaced order */
|
||||
int tpixel; /* Index of transparent pixel */
|
||||
GIF_IRGB* transparent_pixel;
|
||||
int is_transparent; /* TRUE, if tpixel is valid */
|
||||
int control_extension; /* TRUE, if image control extension present */
|
||||
int is_local_colormap_defined;
|
||||
gdispose disposal_method; /* Restore to background, leave in place, etc.*/
|
||||
gdispose last_disposal_method;
|
||||
GIF_RGB *local_colormap; /* Per-image colormap */
|
||||
int local_colormap_size; /* Size of local colormap array. */
|
||||
PRUint32 delay_time; /* Display time, in milliseconds,
|
||||
for this image in a multi-image GIF */
|
||||
|
||||
/* Global (multi-image) state */
|
||||
int screen_bgcolor; /* Logical screen background color */
|
||||
int version; /* Either 89 for GIF89 or 87 for GIF87 */
|
||||
PRUintn screen_width; /* Logical screen width & height */
|
||||
PRUintn screen_height;
|
||||
GIF_RGB *global_colormap; /* Default colormap if local not supplied */
|
||||
int global_colormap_size; /* Size of global colormap array. */
|
||||
int images_decoded; /* Counts images for multi-part GIFs */
|
||||
int destroy_pending; /* Stream has ended */
|
||||
int progressive_display; /* If TRUE, do Haeberli interlace hack */
|
||||
int loop_count; /* Netscape specific extension block to control
|
||||
the number of animation loops a GIF renders. */
|
||||
} gif_struct;
|
||||
|
||||
|
||||
/* Create a new gif_struct */
|
||||
extern PRBool gif_create(gif_struct **gs);
|
||||
|
||||
/* These are the APIs that the client calls to intialize,
|
||||
push data to, and shut down the GIF decoder. */
|
||||
PRBool GIFInit(
|
||||
gif_struct* gs,
|
||||
|
||||
void* aClientData,
|
||||
|
||||
int (*PR_CALLBACK GIFCallback_NewPixmap)(),
|
||||
|
||||
int (*PR_CALLBACK GIFCallback_BeginGIF)(
|
||||
void* aClientData,
|
||||
PRUint32 aLogicalScreenWidth,
|
||||
PRUint32 aLogicalScreenHeight,
|
||||
PRUint8 aBackgroundRGBIndex),
|
||||
|
||||
int (*PR_CALLBACK GIFCallback_EndGIF)(
|
||||
void* aClientData,
|
||||
int aAnimationLoopCount),
|
||||
|
||||
int (*PR_CALLBACK GIFCallback_BeginImageFrame)(
|
||||
void* aClientData,
|
||||
PRUint32 aFrameNumber, /* Frame number, 1-n */
|
||||
PRUint32 aFrameXOffset, /* X offset in logical screen */
|
||||
PRUint32 aFrameYOffset, /* Y offset in logical screen */
|
||||
PRUint32 aFrameWidth,
|
||||
PRUint32 aFrameHeight,
|
||||
GIF_RGB* aTransparencyChromaKey),
|
||||
|
||||
int (*PR_CALLBACK GIFCallback_EndImageFrame)(
|
||||
void* aClientData,
|
||||
PRUint32 aFrameNumber,
|
||||
PRUint32 aDelayTimeout,
|
||||
PRUint32 aDisposal),
|
||||
|
||||
int (*PR_CALLBACK GIFCallback_SetupColorspaceConverter)(),
|
||||
|
||||
int (*PR_CALLBACK GIFCallback_ResetPalette)(),
|
||||
|
||||
int (*PR_CALLBACK GIFCallback_InitTransparentPixel)(),
|
||||
|
||||
int (*PR_CALLBACK GIFCallback_DestroyTransparentPixel)(),
|
||||
|
||||
int (*PR_CALLBACK GIFCallback_HaveDecodedRow)(
|
||||
void* aClientData,
|
||||
PRUint8* aRowBufPtr, /* Pointer to single scanline temporary buffer */
|
||||
int aXOffset, /* With respect to GIF logical screen origin */
|
||||
int aLength, /* Length of the row? */
|
||||
int aRow, /* Row number? */
|
||||
int aDuplicateCount, /* Number of times to duplicate the row? */
|
||||
PRUint8 aDrawMode, /* il_draw_mode */
|
||||
int aInterlacePass),
|
||||
|
||||
int (*PR_CALLBACK GIFCallback_HaveImageAll)(
|
||||
void* aClientData)
|
||||
);
|
||||
|
||||
extern void gif_destroy(gif_struct* aGIFStruct);
|
||||
|
||||
PRStatus gif_write(gif_struct* aGIFStruct, const PRUint8 * buf, PRUint32 numbytes);
|
||||
|
||||
PRBool gif_write_ready(const gif_struct* aGIFStruct);
|
||||
|
||||
extern void gif_complete(gif_struct** aGIFStruct);
|
||||
extern void gif_delay_time_callback(/* void *closure */);
|
||||
|
||||
|
||||
/* Callback functions that the client must implement and pass in
|
||||
pointers for during the GIFInit call. These will be called back
|
||||
when the decoder has a decoded rows, frame size information, etc.*/
|
||||
|
||||
/* GIFCallback_LogicalScreenSize is called only once to notify the client
|
||||
of the logical screen size, which will be the size of the total image. */
|
||||
typedef int (*PR_CALLBACK BEGINGIF_CALLBACK)(
|
||||
void* aClientData,
|
||||
PRUint32 aLogicalScreenWidth,
|
||||
PRUint32 aLogicalScreenHeight,
|
||||
PRUint8 aLogicalScreenBackgroundRGBIndex);
|
||||
|
||||
typedef int (PR_CALLBACK *GIFCallback_EndGIF)(
|
||||
void* aClientData,
|
||||
int aAnimationLoopCount);
|
||||
|
||||
/* GIFCallback_BeginImageFrame is called at the beginning of each frame of
|
||||
a GIF.*/
|
||||
typedef int (PR_CALLBACK *GIFCallback_BeginImageFrame)(
|
||||
void* aClientData,
|
||||
PRUint32 aFrameNumber, /* Frame number, 1-n */
|
||||
PRUint32 aFrameXOffset, /* X offset in logical screen */
|
||||
PRUint32 aFraqeYOffset, /* Y offset in logical screen */
|
||||
PRUint32 aFrameWidth,
|
||||
PRUint32 aFrameHeight);
|
||||
|
||||
extern int GIFCallback_EndImageFrame(
|
||||
void* aClientData,
|
||||
PRUint32 aFrameNumber,
|
||||
PRUint32 aDelayTimeout,
|
||||
PRUint32 aDisposal); /* Time in milliseconds this frame should be displayed before the next frame.
|
||||
This information appears in a sub control block, so we don't
|
||||
transmit it back to the client until we're done with the frame. */
|
||||
|
||||
/*
|
||||
extern int GIFCallback_SetupColorspaceConverter();
|
||||
extern int GIFCallback_ResetPalette();
|
||||
extern int GIFCallback_InitTransparentPixel();
|
||||
extern int GIFCallback_DestroyTransparentPixel();
|
||||
*/
|
||||
extern int GIFCallback_HaveDecodedRow();
|
||||
extern int GIFCallback_HaveImageAll();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,53 +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) 2001 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = imggif
|
||||
LIBRARY_NAME = imggif
|
||||
EXPORT_LIBRARY = 1
|
||||
IS_COMPONENT = 1
|
||||
MODULE_NAME = nsGIFModule2
|
||||
|
||||
ifeq ($(OS_ARCH),WINNT)
|
||||
EXTRA_DSO_LIBS = gkgfx
|
||||
endif
|
||||
|
||||
REQUIRES = xpcom \
|
||||
gfx \
|
||||
gfx2 \
|
||||
imglib2 \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = GIF2.cpp nsGIFDecoder2.cpp nsGIFModule.cpp
|
||||
|
||||
EXTRA_DSO_LDOPTS = $(GIF_LIBS) \
|
||||
$(EXTRA_DSO_LIBS) \
|
||||
$(MOZ_COMPONENT_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
@@ -1,48 +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) 2001 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Stuart Parmenter <pavlov@netscape.com>
|
||||
#
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
MODULE = imggif
|
||||
REQUIRES = xpcom \
|
||||
gfx \
|
||||
gfx2 \
|
||||
imglib2 \
|
||||
$(NULL)
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
LIBRARY_NAME = imggif
|
||||
MODULE_NAME = nsGIFModule2
|
||||
|
||||
OBJS = \
|
||||
.\$(OBJDIR)\nsGIFDecoder2.obj \
|
||||
.\$(OBJDIR)\GIF2.obj \
|
||||
.\$(OBJDIR)\nsGIFModule.obj \
|
||||
$(NULL)
|
||||
|
||||
LLIBS=\
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(DIST)\lib\gkgfx.lib \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
@@ -1,555 +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) 2001 Netscape Communications Corporation.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Chris Saari <saari@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsGIFDecoder2.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIImage.h"
|
||||
#include "nsMemory.h"
|
||||
|
||||
#include "imgIContainerObserver.h"
|
||||
|
||||
#include "imgILoad.h"
|
||||
|
||||
#include "nsRect.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// GIF Decoder Implementation
|
||||
// This is an adaptor between GIF2 and imgIDecoder
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsGIFDecoder2, imgIDecoder);
|
||||
|
||||
nsGIFDecoder2::nsGIFDecoder2()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mImageFrame = nsnull;
|
||||
|
||||
mGIFStruct = nsnull;
|
||||
|
||||
mAlphaLine = nsnull;
|
||||
mRGBLine = nsnull;
|
||||
mBackgroundRGBIndex = 0;
|
||||
|
||||
mCurrentRow = -1;
|
||||
mLastFlushedRow = -1;
|
||||
|
||||
mCurrentPass = 0;
|
||||
mLastFlushedPass = 0;
|
||||
}
|
||||
|
||||
nsGIFDecoder2::~nsGIFDecoder2(void)
|
||||
{
|
||||
if (mAlphaLine)
|
||||
nsMemory::Free(mAlphaLine);
|
||||
|
||||
if (mRGBLine)
|
||||
nsMemory::Free(mRGBLine);
|
||||
|
||||
if (mGIFStruct) {
|
||||
gif_destroy(mGIFStruct);
|
||||
mGIFStruct = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/** imgIDecoder methods **/
|
||||
//******************************************************************************
|
||||
|
||||
//******************************************************************************
|
||||
/* void init (in imgILoad aLoad); */
|
||||
NS_IMETHODIMP nsGIFDecoder2::Init(imgILoad *aLoad)
|
||||
{
|
||||
mObserver = do_QueryInterface(aLoad);
|
||||
|
||||
mImageContainer = do_CreateInstance("@mozilla.org/image/container;1");
|
||||
aLoad->SetImage(mImageContainer);
|
||||
|
||||
/* do gif init stuff */
|
||||
/* Always decode to 24 bit pixdepth */
|
||||
|
||||
PRBool created = gif_create(&mGIFStruct);
|
||||
|
||||
NS_ASSERTION(created, "gif_create failed");
|
||||
|
||||
// Call GIF decoder init routine
|
||||
GIFInit(
|
||||
mGIFStruct,
|
||||
this,
|
||||
NewPixmap,
|
||||
BeginGIF,
|
||||
EndGIF,
|
||||
BeginImageFrame,
|
||||
EndImageFrame,
|
||||
SetupColorspaceConverter,
|
||||
ResetPalette,
|
||||
InitTransparentPixel,
|
||||
DestroyTransparentPixel,
|
||||
HaveDecodedRow,
|
||||
HaveImageAll);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//******************************************************************************
|
||||
/** nsIOutputStream methods **/
|
||||
//******************************************************************************
|
||||
|
||||
//******************************************************************************
|
||||
/* void close (); */
|
||||
NS_IMETHODIMP nsGIFDecoder2::Close()
|
||||
{
|
||||
if (mGIFStruct) {
|
||||
gif_destroy(mGIFStruct);
|
||||
mGIFStruct = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/* void flush (); */
|
||||
NS_IMETHODIMP nsGIFDecoder2::Flush()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/* static callback from nsIInputStream::ReadSegments */
|
||||
static NS_METHOD ReadDataOut(nsIInputStream* in,
|
||||
void* closure,
|
||||
const char* fromRawSegment,
|
||||
PRUint32 toOffset,
|
||||
PRUint32 count,
|
||||
PRUint32 *writeCount)
|
||||
{
|
||||
nsGIFDecoder2 *decoder = NS_STATIC_CAST(nsGIFDecoder2*, closure);
|
||||
nsresult rv = decoder->ProcessData((unsigned char*)fromRawSegment, count, writeCount);
|
||||
if (NS_FAILED(rv)) {
|
||||
*writeCount = 0;
|
||||
return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Push any new rows according to mCurrentPass/mLastFlushedPass and
|
||||
// mCurrentRow/mLastFlushedRow. Note: caller is responsible for
|
||||
// updating mlastFlushed{Row,Pass}.
|
||||
NS_METHOD
|
||||
nsGIFDecoder2::FlushImageData()
|
||||
{
|
||||
PRInt32 width;
|
||||
PRInt32 height;
|
||||
mImageFrame->GetWidth(&width);
|
||||
mImageFrame->GetHeight(&height);
|
||||
switch (mCurrentPass - mLastFlushedPass) {
|
||||
case 0: { // same pass
|
||||
PRInt32 remainingRows = mCurrentRow - mLastFlushedRow;
|
||||
if (remainingRows) {
|
||||
nsRect r(0, mLastFlushedRow+1, width, remainingRows);
|
||||
mObserver->OnDataAvailable(nsnull, nsnull, mImageFrame, &r);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 1: { // one pass on - need to handle bottom & top rects
|
||||
nsRect r(0, 0, width, mCurrentRow+1);
|
||||
mObserver->OnDataAvailable(nsnull, nsnull, mImageFrame, &r);
|
||||
nsRect r2(0, mLastFlushedRow+1, width, height-mLastFlushedRow-1);
|
||||
mObserver->OnDataAvailable(nsnull, nsnull, mImageFrame, &r2);
|
||||
}
|
||||
break;
|
||||
|
||||
default: { // more than one pass on - push the whole frame
|
||||
nsRect r(0, 0, width, height);
|
||||
mObserver->OnDataAvailable(nsnull, nsnull, mImageFrame, &r);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
nsresult nsGIFDecoder2::ProcessData(unsigned char *data, PRUint32 count, PRUint32 *_retval)
|
||||
{
|
||||
// Push the data to the GIF decoder
|
||||
|
||||
// First we ask if the gif decoder is ready for more data, and if so, push it.
|
||||
// In the new decoder, we should always be able to process more data since
|
||||
// we don't wait to decode each frame in an animation now.
|
||||
if (gif_write_ready(mGIFStruct)) {
|
||||
PRStatus result = gif_write(mGIFStruct, data, count);
|
||||
if (result != PR_SUCCESS)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (mImageFrame && mObserver) {
|
||||
FlushImageData();
|
||||
mLastFlushedRow = mCurrentRow;
|
||||
mLastFlushedPass = mCurrentPass;
|
||||
}
|
||||
|
||||
*_retval = count;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/* unsigned long writeFrom (in nsIInputStream inStr, in unsigned long count); */
|
||||
NS_IMETHODIMP nsGIFDecoder2::WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval)
|
||||
{
|
||||
return inStr->ReadSegments(ReadDataOut, this, count, _retval);
|
||||
}
|
||||
|
||||
|
||||
//******************************************************************************
|
||||
// GIF decoder callback methods. Part of pulic API for GIF2
|
||||
//******************************************************************************
|
||||
|
||||
//******************************************************************************
|
||||
int BeginGIF(
|
||||
void* aClientData,
|
||||
PRUint32 aLogicalScreenWidth,
|
||||
PRUint32 aLogicalScreenHeight,
|
||||
PRUint8 aBackgroundRGBIndex)
|
||||
{
|
||||
// If we have passed an illogical screen size, bail and hope that we'll get
|
||||
// set later by the first frame's local image header.
|
||||
if(aLogicalScreenWidth == 0 || aLogicalScreenHeight == 0)
|
||||
return 0;
|
||||
|
||||
// copy GIF info into imagelib structs
|
||||
nsGIFDecoder2 *decoder = NS_STATIC_CAST(nsGIFDecoder2*, aClientData);
|
||||
|
||||
decoder->mBackgroundRGBIndex = aBackgroundRGBIndex;
|
||||
|
||||
if (decoder->mObserver)
|
||||
decoder->mObserver->OnStartDecode(nsnull, nsnull);
|
||||
|
||||
decoder->mImageContainer->Init(aLogicalScreenWidth, aLogicalScreenHeight, decoder->mObserver);
|
||||
|
||||
if (decoder->mObserver)
|
||||
decoder->mObserver->OnStartContainer(nsnull, nsnull, decoder->mImageContainer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
int EndGIF(
|
||||
void* aClientData,
|
||||
int aAnimationLoopCount)
|
||||
{
|
||||
nsGIFDecoder2 *decoder = NS_STATIC_CAST(nsGIFDecoder2*, aClientData);
|
||||
if (decoder->mObserver) {
|
||||
decoder->mObserver->OnStopContainer(nsnull, nsnull, decoder->mImageContainer);
|
||||
decoder->mObserver->OnStopDecode(nsnull, nsnull, NS_OK, nsnull);
|
||||
}
|
||||
|
||||
decoder->mImageContainer->SetLoopCount(aAnimationLoopCount);
|
||||
decoder->mImageContainer->DecodingComplete();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
int BeginImageFrame(
|
||||
void* aClientData,
|
||||
PRUint32 aFrameNumber, /* Frame number, 1-n */
|
||||
PRUint32 aFrameXOffset, /* X offset in logical screen */
|
||||
PRUint32 aFrameYOffset, /* Y offset in logical screen */
|
||||
PRUint32 aFrameWidth,
|
||||
PRUint32 aFrameHeight,
|
||||
GIF_RGB* aTransparencyChromaKey) /* don't have this info yet */
|
||||
{
|
||||
nsGIFDecoder2* decoder = NS_STATIC_CAST(nsGIFDecoder2*, aClientData);
|
||||
|
||||
decoder->mImageFrame = nsnull; // clear out our current frame reference
|
||||
decoder->mGIFStruct->x_offset = aFrameXOffset;
|
||||
decoder->mGIFStruct->y_offset = aFrameYOffset;
|
||||
decoder->mGIFStruct->width = aFrameWidth;
|
||||
decoder->mGIFStruct->height = aFrameHeight;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
int EndImageFrame(
|
||||
void* aClientData,
|
||||
PRUint32 aFrameNumber,
|
||||
PRUint32 aDelayTimeout,
|
||||
PRUint32 aDisposal) /* Time this frame should be displayed before the next frame
|
||||
we can't have this in the image frame init because it doesn't
|
||||
show up in the GIF frame header, it shows up in a sub control
|
||||
block.*/
|
||||
{
|
||||
nsGIFDecoder2* decoder = NS_STATIC_CAST(nsGIFDecoder2*, aClientData);
|
||||
|
||||
// We actually have the timeout information before we get the lzw encoded image
|
||||
// data, at least according to the spec, but we delay in setting the timeout for
|
||||
// the image until here to help ensure that we have the whole image frame decoded before
|
||||
// we go off and try to display another frame.
|
||||
decoder->mImageContainer->EndFrameDecode(aFrameNumber, aDelayTimeout);
|
||||
|
||||
if (decoder->mObserver && decoder->mImageFrame) {
|
||||
decoder->mImageFrame->SetFrameDisposalMethod(aDisposal);
|
||||
|
||||
decoder->FlushImageData();
|
||||
|
||||
decoder->mCurrentRow = decoder->mLastFlushedRow = -1;
|
||||
decoder->mCurrentPass = decoder->mLastFlushedPass = 0;
|
||||
|
||||
decoder->mObserver->OnStopFrame(nsnull, nsnull, decoder->mImageFrame);
|
||||
}
|
||||
|
||||
decoder->mImageFrame = nsnull;
|
||||
decoder->mGIFStruct->local_colormap = nsnull;
|
||||
decoder->mGIFStruct->is_transparent = PR_FALSE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//******************************************************************************
|
||||
// GIF decoder callback
|
||||
int HaveImageAll(
|
||||
void* aClientData)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
// GIF decoder callback notification that it has decoded a row
|
||||
int HaveDecodedRow(
|
||||
void* aClientData,
|
||||
PRUint8* aRowBufPtr, // Pointer to single scanline temporary buffer
|
||||
int aXOffset, // With respect to GIF logical screen origin
|
||||
int aLength, // Length of the row?
|
||||
int aRowNumber, // Row number?
|
||||
int aDuplicateCount, // Number of times to duplicate the row?
|
||||
PRUint8 aDrawMode, // il_draw_mode
|
||||
int aInterlacePass) // interlace pass (1-4)
|
||||
{
|
||||
nsGIFDecoder2* decoder = NS_STATIC_CAST(nsGIFDecoder2*, aClientData);
|
||||
PRUint32 bpr, abpr;
|
||||
// We have to delay allocation of the image frame until now because
|
||||
// we won't have control block info (transparency) until now. The conrol
|
||||
// block of a GIF stream shows up after the image header since transparency
|
||||
// is added in GIF89a and control blocks are how the extensions are done.
|
||||
// How annoying.
|
||||
if(! decoder->mImageFrame) {
|
||||
gfx_format format = gfxIFormats::RGB;
|
||||
if (decoder->mGIFStruct->is_transparent) {
|
||||
format = gfxIFormats::RGB_A1;
|
||||
}
|
||||
|
||||
#if defined(XP_PC) || defined(XP_BEOS) || defined(MOZ_WIDGET_PHOTON)
|
||||
// XXX this works...
|
||||
format += 1; // RGB to BGR
|
||||
#endif
|
||||
|
||||
// initalize the frame and append it to the container
|
||||
decoder->mImageFrame = do_CreateInstance("@mozilla.org/gfx/image/frame;2");
|
||||
decoder->mImageFrame->Init(
|
||||
decoder->mGIFStruct->x_offset, decoder->mGIFStruct->y_offset,
|
||||
decoder->mGIFStruct->width, decoder->mGIFStruct->height, format);
|
||||
|
||||
decoder->mImageContainer->AppendFrame(decoder->mImageFrame);
|
||||
|
||||
if (decoder->mObserver)
|
||||
decoder->mObserver->OnStartFrame(nsnull, nsnull, decoder->mImageFrame);
|
||||
|
||||
decoder->mImageFrame->GetImageBytesPerRow(&bpr);
|
||||
decoder->mImageFrame->GetAlphaBytesPerRow(&abpr);
|
||||
|
||||
decoder->mRGBLine = (PRUint8 *)nsMemory::Realloc(decoder->mRGBLine, bpr);
|
||||
|
||||
if (format == gfxIFormats::RGB_A1 || format == gfxIFormats::BGR_A1) {
|
||||
decoder->mAlphaLine = (PRUint8 *)nsMemory::Realloc(decoder->mAlphaLine, abpr);
|
||||
}
|
||||
} else {
|
||||
decoder->mImageFrame->GetImageBytesPerRow(&bpr);
|
||||
decoder->mImageFrame->GetAlphaBytesPerRow(&abpr);
|
||||
}
|
||||
|
||||
if (aRowBufPtr) {
|
||||
nscoord width;
|
||||
|
||||
decoder->mImageFrame->GetWidth(&width);
|
||||
PRUint32 iwidth = width;
|
||||
|
||||
gfx_format format;
|
||||
decoder->mImageFrame->GetFormat(&format);
|
||||
|
||||
// XXX map the data into colors
|
||||
int cmapsize;
|
||||
GIF_RGB* cmap;
|
||||
cmapsize = decoder->mGIFStruct->global_colormap_size;
|
||||
cmap = decoder->mGIFStruct->global_colormap;
|
||||
|
||||
if(decoder->mGIFStruct->global_colormap &&
|
||||
decoder->mGIFStruct->screen_bgcolor < cmapsize) {
|
||||
gfx_color bgColor = 0;
|
||||
bgColor |= cmap[decoder->mGIFStruct->screen_bgcolor].red;
|
||||
bgColor |= cmap[decoder->mGIFStruct->screen_bgcolor].green << 8;
|
||||
bgColor |= cmap[decoder->mGIFStruct->screen_bgcolor].blue << 16;
|
||||
decoder->mImageFrame->SetBackgroundColor(bgColor);
|
||||
}
|
||||
if(decoder->mGIFStruct->local_colormap) {
|
||||
cmapsize = decoder->mGIFStruct->local_colormap_size;
|
||||
cmap = decoder->mGIFStruct->local_colormap;
|
||||
}
|
||||
|
||||
PRUint8* rgbRowIndex = decoder->mRGBLine;
|
||||
PRUint8* rowBufIndex = aRowBufPtr;
|
||||
|
||||
switch (format) {
|
||||
case gfxIFormats::RGB:
|
||||
{
|
||||
while(rowBufIndex != decoder->mGIFStruct->rowend) {
|
||||
#if defined(XP_MAC) || defined(XP_MACOSX)
|
||||
*rgbRowIndex++ = 0; // Mac is always 32bits per pixel, this is pad
|
||||
#endif
|
||||
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].red;
|
||||
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].green;
|
||||
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].blue;
|
||||
++rowBufIndex;
|
||||
}
|
||||
|
||||
for (int i=0; i<aDuplicateCount; i++)
|
||||
decoder->mImageFrame->SetImageData(decoder->mRGBLine,
|
||||
bpr, (aRowNumber+i)*bpr);
|
||||
}
|
||||
break;
|
||||
case gfxIFormats::BGR:
|
||||
{
|
||||
while(rowBufIndex != decoder->mGIFStruct->rowend) {
|
||||
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].blue;
|
||||
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].green;
|
||||
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].red;
|
||||
++rowBufIndex;
|
||||
}
|
||||
|
||||
for (int i=0; i<aDuplicateCount; i++)
|
||||
decoder->mImageFrame->SetImageData(decoder->mRGBLine,
|
||||
bpr, (aRowNumber+i)*bpr);
|
||||
}
|
||||
break;
|
||||
case gfxIFormats::RGB_A1:
|
||||
case gfxIFormats::BGR_A1:
|
||||
{
|
||||
if (decoder->mGIFStruct->is_transparent &&
|
||||
(decoder->mGIFStruct->tpixel < cmapsize)) {
|
||||
gfx_color transColor = 0;
|
||||
transColor |= cmap[decoder->mGIFStruct->tpixel].red;
|
||||
transColor |= cmap[decoder->mGIFStruct->tpixel].green << 8;
|
||||
transColor |= cmap[decoder->mGIFStruct->tpixel].blue << 16;
|
||||
decoder->mImageFrame->SetTransparentColor(transColor);
|
||||
}
|
||||
|
||||
memset(decoder->mRGBLine, 0, bpr);
|
||||
memset(decoder->mAlphaLine, 0, abpr);
|
||||
PRUint32 iwidth = (PRUint32)width;
|
||||
for (PRUint32 x=0; x<iwidth; x++) {
|
||||
if (*rowBufIndex != decoder->mGIFStruct->tpixel) {
|
||||
#if defined(XP_PC) || defined(XP_BEOS) || defined(MOZ_WIDGET_PHOTON)
|
||||
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].blue;
|
||||
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].green;
|
||||
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].red;
|
||||
#else
|
||||
#if defined(XP_MAC) || defined(XP_MACOSX)
|
||||
*rgbRowIndex++ = 0; // Mac is always 32bits per pixel, this is pad
|
||||
#endif
|
||||
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].red;
|
||||
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].green;
|
||||
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].blue;
|
||||
#endif
|
||||
decoder->mAlphaLine[x>>3] |= 1<<(7-x&0x7);
|
||||
} else {
|
||||
#if defined(XP_MAC) || defined(XP_MACOSX)
|
||||
rgbRowIndex+=4;
|
||||
#else
|
||||
rgbRowIndex+=3;
|
||||
#endif
|
||||
}
|
||||
|
||||
++rowBufIndex;
|
||||
}
|
||||
for (int i=0; i<aDuplicateCount; i++) {
|
||||
decoder->mImageFrame->SetAlphaData(decoder->mAlphaLine,
|
||||
abpr, (aRowNumber+i)*abpr);
|
||||
decoder->mImageFrame->SetImageData(decoder->mRGBLine,
|
||||
bpr, (aRowNumber+i)*bpr);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
decoder->mCurrentRow = aRowNumber+aDuplicateCount-1;
|
||||
decoder->mCurrentPass = aInterlacePass;
|
||||
if (aInterlacePass == 1)
|
||||
decoder->mLastFlushedPass = aInterlacePass; // interlaced starts at 1
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
int ResetPalette()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
int SetupColorspaceConverter()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
int EndImageFrame()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
int NewPixmap()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
int InitTransparentPixel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
int DestroyTransparentPixel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -1,117 +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) 2001 Netscape Communications Corporation.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Chris Saari <saari@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _nsGIFDecoder2_h
|
||||
#define _nsGIFDecoder2_h
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "imgIDecoder.h"
|
||||
#include "imgIContainer.h"
|
||||
#include "imgIDecoderObserver.h"
|
||||
#include "gfxIImageFrame.h"
|
||||
|
||||
#include "GIF2.h"
|
||||
|
||||
#define NS_GIFDECODER2_CID \
|
||||
{ /* 797bec5a-1dd2-11b2-a7f8-ca397e0179c4 */ \
|
||||
0x797bec5a, \
|
||||
0x1dd2, \
|
||||
0x11b2, \
|
||||
{0xa7, 0xf8, 0xca, 0x39, 0x7e, 0x01, 0x79, 0xc4} \
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// nsGIFDecoder2 Definition
|
||||
|
||||
class nsGIFDecoder2 : public imgIDecoder
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_IMGIDECODER
|
||||
|
||||
nsGIFDecoder2();
|
||||
virtual ~nsGIFDecoder2();
|
||||
|
||||
nsresult ProcessData(unsigned char *data, PRUint32 count, PRUint32 *_retval);
|
||||
|
||||
NS_METHOD FlushImageData();
|
||||
|
||||
nsCOMPtr<imgIContainer> mImageContainer;
|
||||
nsCOMPtr<gfxIImageFrame> mImageFrame;
|
||||
nsCOMPtr<imgIDecoderObserver> mObserver; // this is just qi'd from mRequest for speed
|
||||
PRInt32 mCurrentRow;
|
||||
PRInt32 mLastFlushedRow;
|
||||
|
||||
gif_struct *mGIFStruct;
|
||||
|
||||
PRUint8 *mAlphaLine;
|
||||
PRUint8 *mRGBLine;
|
||||
PRUint8 mBackgroundRGBIndex;
|
||||
PRUint8 mCurrentPass;
|
||||
PRUint8 mLastFlushedPass;
|
||||
};
|
||||
|
||||
// static callbacks for the GIF decoder
|
||||
static int PR_CALLBACK BeginGIF(
|
||||
void* aClientData,
|
||||
PRUint32 aLogicalScreenWidth,
|
||||
PRUint32 aLogicalScreenHeight,
|
||||
PRUint8 aBackgroundRGBIndex);
|
||||
|
||||
static int PR_CALLBACK HaveDecodedRow(
|
||||
void* aClientData,
|
||||
PRUint8* aRowBufPtr, // Pointer to single scanline temporary buffer
|
||||
int aXOffset, // With respect to GIF logical screen origin
|
||||
int aLength, // Length of the row?
|
||||
int aRow, // Row number?
|
||||
int aDuplicateCount, // Number of times to duplicate the row?
|
||||
PRUint8 aDrawMode, // il_draw_mode
|
||||
int aInterlacePass);
|
||||
|
||||
static int PR_CALLBACK NewPixmap();
|
||||
|
||||
static int PR_CALLBACK EndGIF(
|
||||
void* aClientData,
|
||||
int aAnimationLoopCount);
|
||||
|
||||
static int PR_CALLBACK BeginImageFrame(
|
||||
void* aClientData,
|
||||
PRUint32 aFrameNumber, /* Frame number, 1-n */
|
||||
PRUint32 aFrameXOffset, /* X offset in logical screen */
|
||||
PRUint32 aFrameYOffset, /* Y offset in logical screen */
|
||||
PRUint32 aFrameWidth,
|
||||
PRUint32 aFrameHeight,
|
||||
GIF_RGB* aTransparencyChromaKey);
|
||||
static int PR_CALLBACK EndImageFrame(
|
||||
void* aClientData,
|
||||
PRUint32 aFrameNumber,
|
||||
PRUint32 aDelayTimeout,
|
||||
PRUint32 aDisposal);
|
||||
static int PR_CALLBACK SetupColorspaceConverter();
|
||||
static int PR_CALLBACK ResetPalette();
|
||||
static int PR_CALLBACK InitTransparentPixel();
|
||||
static int PR_CALLBACK DestroyTransparentPixel();
|
||||
|
||||
static int PR_CALLBACK HaveImageAll(
|
||||
void* aClientData);
|
||||
#endif
|
||||
@@ -1,64 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Chris Saari <saari@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsGIFDecoder2.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsGifAllocator.h"
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsGIFDecoder2)
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ "GIF Decoder",
|
||||
NS_GIFDECODER2_CID,
|
||||
"@mozilla.org/image/decoder;2?type=image/gif",
|
||||
nsGIFDecoder2Constructor, },
|
||||
};
|
||||
|
||||
// GIF module shutdown hook
|
||||
static void PR_CALLBACK nsGifShutdown(nsIModule *module)
|
||||
{
|
||||
// Release cached buffers from zlib allocator
|
||||
delete gGifAllocator;
|
||||
}
|
||||
|
||||
NS_IMPL_NSGETMODULE_WITH_DTOR(nsGIFModule2, components, nsGifShutdown);
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/*
|
||||
* Allocator optimized for use with gif decoder
|
||||
*
|
||||
* For every image that gets loaded, we allocate
|
||||
* 4097 x 2 : gs->prefix
|
||||
* 4097 x 1 : gs->suffix
|
||||
* 4097 x 1 : gs->stack
|
||||
* for lzw to operate on the data. These are held for a very short interval
|
||||
* and freed. This allocator tries to keep one set of these around
|
||||
* and reuses them; automatically fails over to use calloc/free when all
|
||||
* buckets are full.
|
||||
*/
|
||||
|
||||
#include "prlock.h"
|
||||
#include "prlog.h"
|
||||
|
||||
class nsGifAllocator;
|
||||
extern nsGifAllocator *gGifAllocator;
|
||||
|
||||
const PRInt32 kNumBuckets = 3;
|
||||
|
||||
class nsGifAllocator {
|
||||
protected:
|
||||
void *mMemBucket[kNumBuckets];
|
||||
PRUint32 mSize[kNumBuckets];
|
||||
PRLock *mLock;
|
||||
PRUint32 mFlag;
|
||||
|
||||
public:
|
||||
nsGifAllocator() : mFlag(0), mLock(nsnull)
|
||||
{
|
||||
memset(mMemBucket, 0, sizeof mMemBucket);
|
||||
memset(mSize, 0, sizeof mSize);
|
||||
mLock = PR_NewLock();
|
||||
PR_ASSERT(mLock != NULL);
|
||||
}
|
||||
|
||||
~nsGifAllocator()
|
||||
{
|
||||
ClearBuckets();
|
||||
if (mLock)
|
||||
PR_DestroyLock(mLock);
|
||||
}
|
||||
|
||||
// Gif allocators
|
||||
void* Calloc(PRUint32 items, PRUint32 size);
|
||||
void Free(void *ptr);
|
||||
// Clear all buckets of memory
|
||||
void ClearBuckets();
|
||||
|
||||
// in-use flag getters/setters
|
||||
inline PRBool IsUsed(PRUint32 i)
|
||||
{
|
||||
PR_ASSERT(i <= 31);
|
||||
return mFlag & (1 << i);
|
||||
}
|
||||
inline void MarkUsed(PRUint32 i)
|
||||
{
|
||||
PR_ASSERT(i <= 31);
|
||||
mFlag |= (1 << i);
|
||||
}
|
||||
inline void ClearUsed(PRUint32 i)
|
||||
{
|
||||
PR_ASSERT(i <= 31);
|
||||
mFlag &= ~(1 << i);
|
||||
}
|
||||
};
|
||||
@@ -1,18 +0,0 @@
|
||||
?Release@nsGIFDecoder2@@UAGKXZ ; 9300
|
||||
?AddRef@nsGIFDecoder2@@UAGKXZ ; 9300
|
||||
?ProcessData@nsGIFDecoder2@@QAGIPAEI@Z ; 6722
|
||||
?gif_write_ready@@YAEPAUgif_struct@@@Z ; 6722
|
||||
?gif_write@@YAHPAUgif_struct@@PBEI@Z ; 6722
|
||||
?WriteFrom@nsGIFDecoder2@@UAGIPAVnsIInputStream@@IPAI@Z ; 4869
|
||||
?gif_destroy@@YAXPAUgif_struct@@@Z ; 4650
|
||||
?QueryInterface@nsGIFDecoder2@@UAGIABUnsID@@PAPAX@Z ; 4650
|
||||
?Init@nsGIFDecoder2@@UAGIPAVimgIRequest@@@Z ; 4650
|
||||
??_EnsGIFDecoder2@@UAEPAXI@Z ; 4650
|
||||
?Close@nsGIFDecoder2@@UAGIXZ ; 4650
|
||||
??0nsGIFDecoder2@@QAE@XZ ; 4650
|
||||
??1nsGIFDecoder2@@UAE@XZ ; 4650
|
||||
?GIFInit@@YAHPAUgif_struct@@PAXP6AHXZP6AH1IIE@ZP6AH1H@ZP6AH1IIIIIPAU_GIF_RGB@@@ZP6AH1III@Z2222P6AH1PAE8HHHHEH@ZP6AH1@Z@Z ; 4650
|
||||
?gif_create@@YAHPAPAUgif_struct@@@Z ; 4650
|
||||
?Flush@nsGIFDecoder2@@UAGIXZ ; 4650
|
||||
?il_BACat@@YAPADPAPADIPBDI@Z ; 4124
|
||||
NSGetModule ; 1
|
||||
134
mozilla/xpcom/ds/Makefile.in
Normal file
134
mozilla/xpcom/ds/Makefile.in
Normal file
@@ -0,0 +1,134 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = xpcom
|
||||
XPIDL_MODULE = xpcom_ds
|
||||
LIBRARY_NAME = xpcomds_s
|
||||
REQUIRES = unicharutil string
|
||||
|
||||
CSRCS = \
|
||||
pldhash.c \
|
||||
plvector.c \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
nsArena.cpp \
|
||||
nsAtomTable.cpp \
|
||||
nsAtomService.cpp \
|
||||
nsAVLTree.cpp \
|
||||
nsByteBuffer.cpp \
|
||||
nsCRT.cpp \
|
||||
nsConjoiningEnumerator.cpp \
|
||||
nsDeque.cpp \
|
||||
nsEmptyEnumerator.cpp \
|
||||
nsEnumeratorUtils.cpp \
|
||||
nsFixedSizeAllocator.cpp \
|
||||
nsHashtable.cpp \
|
||||
nsHashtableEnumerator.cpp \
|
||||
nsObserver.cpp \
|
||||
nsObserverList.cpp \
|
||||
nsObserverService.cpp \
|
||||
nsProperties.cpp \
|
||||
nsPersistentProperties.cpp \
|
||||
nsQuickSort.cpp \
|
||||
nsSizeOfHandler.cpp \
|
||||
nsStaticNameTable.cpp \
|
||||
nsStatistics.cpp \
|
||||
nsStringMap.cpp \
|
||||
nsSupportsArray.cpp \
|
||||
nsSupportsArrayEnumerator.cpp \
|
||||
nsSupportsPrimitives.cpp \
|
||||
nsUnicharBuffer.cpp \
|
||||
nsVoidArray.cpp \
|
||||
nsVoidBTree.cpp \
|
||||
nsTextFormatter.cpp \
|
||||
nsTimelineService.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
nsAVLTree.h \
|
||||
nsAtomService.h \
|
||||
nsCppSharedAllocator.h \
|
||||
nsCRT.h \
|
||||
nsDeque.h \
|
||||
nsEnumeratorUtils.h \
|
||||
nsFixedSizeAllocator.h \
|
||||
nsHashtable.h \
|
||||
nsHashtableEnumerator.h \
|
||||
nsIArena.h \
|
||||
nsIByteBuffer.h \
|
||||
nsIObserverList.h \
|
||||
nsISimpleEnumerator.h \
|
||||
nsISizeOfHandler.h \
|
||||
nsIUnicharBuffer.h \
|
||||
nsInt64.h \
|
||||
nsQuickSort.h \
|
||||
nsStaticNameTable.h \
|
||||
nsStatistics.h \
|
||||
nsStringMap.h \
|
||||
nsSupportsArray.h \
|
||||
nsSupportsPrimitives.h \
|
||||
nsTime.h \
|
||||
nsUnitConversion.h \
|
||||
nsVector.h \
|
||||
nsVoidArray.h \
|
||||
nsVoidBTree.h \
|
||||
pldhash.h \
|
||||
plvector.h \
|
||||
nsTextFormatter.h \
|
||||
$(NULL)
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsIAtom.idl \
|
||||
nsIAtomService.idl \
|
||||
nsICollection.idl \
|
||||
nsIEnumerator.idl \
|
||||
nsIObserver.idl \
|
||||
nsIObserverService.idl \
|
||||
nsIPersistentProperties2.idl \
|
||||
nsIProperties.idl \
|
||||
nsISerializable.idl \
|
||||
nsIStopwatch.idl \
|
||||
nsISupportsArray.idl \
|
||||
nsISupportsIterators.idl \
|
||||
nsISupportsPrimitives.idl \
|
||||
nsITimelineService.idl \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a static lib.
|
||||
FORCE_STATIC_LIB = 1
|
||||
|
||||
# Force use of PIC
|
||||
FORCE_USE_PIC = 1
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
DEFINES += -D_IMPL_NS_COM -D_IMPL_NS_BASE
|
||||
|
||||
300
mozilla/xpcom/ds/nsStringMap.cpp
Normal file
300
mozilla/xpcom/ds/nsStringMap.cpp
Normal file
@@ -0,0 +1,300 @@
|
||||
/*
|
||||
* 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 Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is James L. Nance
|
||||
* Portions created by James L. Nance are Copyright (C) 2001
|
||||
* James L. Nance. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Patricia Jewell Nance, Jesse Jacob Nance
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
|
||||
// #define TEST_PATRICIA
|
||||
|
||||
#if defined(TEST_PATRICIA)
|
||||
# include "stdlib.h"
|
||||
# include "stdio.h"
|
||||
# include "string.h"
|
||||
# define PRBool bool
|
||||
# define PRUint32 unsigned int
|
||||
# define PRInt32 int
|
||||
# define PR_CALLBACK
|
||||
# define PLArenaPool int
|
||||
# define PL_FinishArenaPool(a)
|
||||
# define PL_InitArenaPool(a, b, c, d)
|
||||
# define PL_ArenaAllocate(a, size) malloc(size)
|
||||
# define PR_TRUE true
|
||||
# define PR_FALSE false
|
||||
|
||||
struct nsCRT {
|
||||
static int strlen(const char *a) {return ::strlen(a);}
|
||||
static int memcmp(const void *a, const void *b, PRUint32 c) {
|
||||
return ::memcmp(a,b,c);
|
||||
}
|
||||
};
|
||||
#else
|
||||
# include "nsCRT.h"
|
||||
#endif
|
||||
|
||||
#include "nsStringMap.h"
|
||||
|
||||
const char nsStringMap::zero_str[] = "\0";
|
||||
|
||||
nsStringMap::~nsStringMap()
|
||||
{
|
||||
// Get rid of the arena memory
|
||||
PL_FinishArenaPool(&mPool);
|
||||
}
|
||||
|
||||
nsStringMap::nsStringMap() : numEntries(0)
|
||||
{
|
||||
// Initialize the head
|
||||
head.l = head.r = &head;
|
||||
head.bit = ~0;
|
||||
head.key = zero_str;
|
||||
head.len = 1;
|
||||
head.obj = 0;
|
||||
|
||||
// Initialize the arena. Guess that a 512 byte block size is good
|
||||
PL_InitArenaPool(&mPool, "nsStringMap", 512, sizeof(void*));
|
||||
}
|
||||
|
||||
void
|
||||
nsStringMap::Reset()
|
||||
{
|
||||
// Initialize the head
|
||||
head.l = head.r = &head;
|
||||
head.bit = ~0;
|
||||
head.key = zero_str;
|
||||
head.len = 1;
|
||||
head.obj = 0;
|
||||
|
||||
// Reinitialize the Arena
|
||||
PL_FinishArenaPool(&mPool);
|
||||
PL_InitArenaPool(&mPool, "nsStringMap", 512, sizeof(void*));
|
||||
}
|
||||
|
||||
void
|
||||
nsStringMap::Reset(nsStringMapEnumFunc destroyFunc, void *aClosure)
|
||||
{
|
||||
Enumerate(destroyFunc, aClosure);
|
||||
Reset();
|
||||
}
|
||||
|
||||
nsStringMap::Patricia *
|
||||
nsStringMap::newNode()
|
||||
{
|
||||
return (Patricia*) PL_ArenaAllocate(&mPool, sizeof(Patricia));
|
||||
}
|
||||
|
||||
nsStringMap::Patricia *
|
||||
nsStringMap::searchDown(BitTester &key)
|
||||
{
|
||||
// The head node only branches to the left, so we can optimize here.
|
||||
Patricia *x = head.l;
|
||||
|
||||
PRUint32 lastBits;
|
||||
|
||||
do {
|
||||
lastBits = x->bit;
|
||||
|
||||
if(key.isset(lastBits))
|
||||
x = x->r;
|
||||
else
|
||||
x = x->l;
|
||||
|
||||
} while(lastBits > x->bit);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
void*
|
||||
nsStringMap::Get(const char *str, PRUint32 slen)
|
||||
{
|
||||
BitTester key(str, slen);
|
||||
|
||||
Patricia *t = searchDown(key);
|
||||
|
||||
if(!key.memcmp(t->key, t->len)) {
|
||||
return t->obj;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void*
|
||||
nsStringMap::Get(const char *str)
|
||||
{
|
||||
BitTester key(str);
|
||||
|
||||
Patricia *t = searchDown(key);
|
||||
|
||||
if(!key.memcmp(t->key, t->len)) {
|
||||
return t->obj;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsStringMap::Put(const char *str, void *obj, PRBool copy)
|
||||
{
|
||||
PRUint32 slen = nsCRT::strlen(str);
|
||||
return Put(str, slen, obj, copy);
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsStringMap::Put(const char *str, PRUint32 slen, void *obj, PRBool copy)
|
||||
{
|
||||
if(copy) {
|
||||
PRUint32 mask = sizeof(double) - 1;
|
||||
PRUint32 asize = (slen+mask) & ~mask;
|
||||
char *tstr = (char*) PL_ArenaAllocate(&mPool, asize);
|
||||
memcpy(tstr, str, slen);
|
||||
str = tstr;
|
||||
}
|
||||
|
||||
BitTester key(str, slen);
|
||||
|
||||
Patricia *t = searchDown(key);
|
||||
|
||||
if(!key.memcmp(t->key, t->len)) {
|
||||
t->obj = obj;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// This is somewhat ugly. We need to find the maximum bit position that
|
||||
// differs, but this is complicated by the fact that we have random length
|
||||
// data. Assume that data past the end of the string is 0.
|
||||
const PRUint32 klen = key.datalen();
|
||||
const PRUint32 tlen = t->len;
|
||||
PRUint32 bpos;
|
||||
if(klen>tlen) {
|
||||
bpos = 8 * klen - 1;
|
||||
while(!BitTester::isset_checked(str, bpos)) --bpos;
|
||||
} else if(tlen>klen) {
|
||||
bpos = 8 * tlen - 1;
|
||||
while(!BitTester::isset_checked(t->key, bpos)) --bpos;
|
||||
} else /* equal */ {
|
||||
bpos = 8 * tlen - 1;
|
||||
while(BitTester::bitsequal(t->key, str, bpos)) --bpos;
|
||||
}
|
||||
|
||||
Patricia *p, *x = &head;
|
||||
|
||||
do {
|
||||
p = x;
|
||||
x = key.isset(x->bit) ? x->r : x->l;
|
||||
} while(x->bit > bpos && p->bit > x->bit);
|
||||
|
||||
t = newNode();
|
||||
|
||||
if(!t) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
t->key = str;
|
||||
t->len = key.datalen();
|
||||
t->obj = obj;
|
||||
t->bit = bpos;
|
||||
|
||||
if(key.isset(t->bit)) {
|
||||
t->r = t;
|
||||
t->l = x;
|
||||
} else {
|
||||
t->r = x;
|
||||
t->l = t;
|
||||
}
|
||||
|
||||
if(key.isset(p->bit)) {
|
||||
p->r = t;
|
||||
} else {
|
||||
p->l = t;
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
nsStringMap::enumerate_recurse(
|
||||
nsStringMapEnumFunc aEnumFunc, void* aClosure, Patricia *node)
|
||||
{
|
||||
aEnumFunc(node->key, node->obj, aClosure);
|
||||
if(node->l && node->l->bit<node->bit)
|
||||
enumerate_recurse(aEnumFunc, aClosure, node->l);
|
||||
if(node->r && node->r->bit<node->bit)
|
||||
enumerate_recurse(aEnumFunc, aClosure, node->r);
|
||||
}
|
||||
|
||||
void
|
||||
nsStringMap::Enumerate(nsStringMapEnumFunc aEnumFunc, void *aClosure)
|
||||
{
|
||||
// We dont want to process head, its a sentinal
|
||||
if(head.l && head.l->bit<head.bit)
|
||||
enumerate_recurse(aEnumFunc, aClosure, head.l);
|
||||
if(head.r && head.r->bit<head.bit)
|
||||
enumerate_recurse(aEnumFunc, aClosure, head.r);
|
||||
}
|
||||
|
||||
#if defined(TEST_PATRICIA)
|
||||
|
||||
PRBool etest(const char *key, void *data, void *closure)
|
||||
{
|
||||
printf("%s\n", key);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
nsStringMap map;
|
||||
const char *strings[] = {
|
||||
"I am number 1 string",
|
||||
"I am number 2 string",
|
||||
"I am number 3 string",
|
||||
"a different string",
|
||||
"a similar string",
|
||||
"I am a very long string and I want to make sure we can handle this",
|
||||
"I am a very long string and I want to make sure we can handle this too",
|
||||
0
|
||||
};
|
||||
|
||||
int idx;
|
||||
for(idx=0; strings[idx]; ++idx) {
|
||||
map.Put(strings[idx], (void*)(1+idx));
|
||||
}
|
||||
|
||||
printf("Lookup Test\n");
|
||||
while(--idx>=0) {
|
||||
void *ptr = map.Get(strings[idx]);
|
||||
printf("%d: %s\n", (long)ptr, strings[idx]);
|
||||
}
|
||||
|
||||
printf("\nEnumeration Test\n");
|
||||
|
||||
map.Enumerate(etest, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
112
mozilla/xpcom/ds/nsStringMap.h
Normal file
112
mozilla/xpcom/ds/nsStringMap.h
Normal file
@@ -0,0 +1,112 @@
|
||||
#ifndef nsStringMap_h__
|
||||
#define nsStringMap_h__
|
||||
|
||||
/*
|
||||
* 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 Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is James L. Nance
|
||||
* Portions created by James L. Nance are Copyright (C) 2001
|
||||
* James L. Nance. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Patricia Jewell Nance, Jesse Jacob Nance
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
|
||||
#if !defined(TEST_PATRICIA)
|
||||
# include "nscore.h"
|
||||
# include "prtypes.h"
|
||||
# include "plarena.h"
|
||||
#endif
|
||||
|
||||
typedef PRBool (*PR_CALLBACK nsStringMapEnumFunc) (
|
||||
const char *aKey, void *aData, void *aClosure);
|
||||
|
||||
class nsStringMap
|
||||
{
|
||||
public:
|
||||
nsStringMap();
|
||||
~nsStringMap();
|
||||
PRBool Put(const char *str, PRUint32 slen, void *obj, PRBool copy=PR_FALSE);
|
||||
PRBool Put(const char *str, void *obj, PRBool copy=PR_FALSE);
|
||||
void* Get(const char *str);
|
||||
void* Get(const char *str, PRUint32 slen);
|
||||
void Reset();
|
||||
void Reset(nsStringMapEnumFunc destroyFunc, void *aClosure = 0);
|
||||
void Enumerate(nsStringMapEnumFunc aEnumFunc, void *aClosure = 0);
|
||||
|
||||
struct Patricia {
|
||||
Patricia *l, *r;
|
||||
PRUint32 bit; // Bit position for l/r comp
|
||||
const char *key;
|
||||
PRUint32 len;
|
||||
void *obj;
|
||||
};
|
||||
|
||||
// The BitTester class is used to test a particular bit position in an
|
||||
// array of characters. It does not assign any special meaning to 0
|
||||
// characters. Bits past the end of the array are treated as 0
|
||||
class BitTester {
|
||||
const PRUint32 slen;
|
||||
const char *cstr;
|
||||
public:
|
||||
BitTester(const char *s) : slen(nsCRT::strlen(s)), cstr(s) {}
|
||||
BitTester(const char *s, PRUint32 l) : slen(l), cstr(s) {}
|
||||
|
||||
PRInt32 memcmp(const char *ostr, PRUint32 olen) {
|
||||
if(olen==slen) {
|
||||
return ::memcmp((void*)cstr, ostr, slen);
|
||||
} else {
|
||||
return olen - slen;
|
||||
}
|
||||
}
|
||||
|
||||
PRUint32 datalen() const {return slen;}
|
||||
|
||||
static PRBool isset_checked(const char *str, PRUint32 idx) {
|
||||
return (str[idx/8] & (1<<(idx & 7))) != 0;
|
||||
}
|
||||
|
||||
static PRBool
|
||||
bitsequal(const char *str1, const char*str2, PRUint32 idx) {
|
||||
return (str1[idx/8] & (1<<(idx&7)))==(str2[idx/8] & (1<<(idx&7)));
|
||||
}
|
||||
|
||||
PRBool isset(PRUint32 idx) {
|
||||
const PRUint32 base = idx/8;
|
||||
if(base>=slen) return 0;
|
||||
return (cstr[base] & (1<<(idx & 7))) != 0;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
PLArenaPool mPool;
|
||||
Patricia *newNode();
|
||||
Patricia *searchDown(BitTester&);
|
||||
void enumerate_recurse(nsStringMapEnumFunc, void*, Patricia*);
|
||||
Patricia head; // Sentinal node
|
||||
PRInt32 numEntries;
|
||||
static const char zero_str[];
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user