зеркало из https://github.com/mozilla/gecko-dev.git
Bug 217025 - GIF decoder cleanup. r=pavlov, sr=darin
This commit is contained in:
Родитель
47182cc148
Коммит
984e645620
|
@ -428,18 +428,6 @@ static int do_lzw(gif_struct *gs, const PRUint8 *q)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRBool gif_create(gif_struct **gs)
|
|
||||||
{
|
|
||||||
gif_struct *ret = PR_NEWZAP(gif_struct);
|
|
||||||
|
|
||||||
if (!ret)
|
|
||||||
return PR_FALSE;
|
|
||||||
|
|
||||||
*gs = ret;
|
|
||||||
|
|
||||||
return PR_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void *gif_calloc(size_t n, size_t s)
|
static inline void *gif_calloc(size_t n, size_t s)
|
||||||
{
|
{
|
||||||
if (!gGifAllocator)
|
if (!gGifAllocator)
|
||||||
|
@ -930,11 +918,9 @@ PRStatus gif_write(gif_struct *gs, const PRUint8 *buf, PRUint32 len)
|
||||||
gs->local_colormap_size = num_colors;
|
gs->local_colormap_size = num_colors;
|
||||||
|
|
||||||
/* Switch to the new local palette after it loads */
|
/* Switch to the new local palette after it loads */
|
||||||
gs->is_local_colormap_defined = PR_TRUE;
|
|
||||||
GETN(gs->local_colormap_size * 3, gif_image_colormap);
|
GETN(gs->local_colormap_size * 3, gif_image_colormap);
|
||||||
} else {
|
} else {
|
||||||
/* Switch back to the global palette */
|
/* Switch back to the global palette */
|
||||||
gs->is_local_colormap_defined = PR_FALSE;
|
|
||||||
GETN(1, gif_lzw_start);
|
GETN(1, gif_lzw_start);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,6 @@ typedef struct gif_struct {
|
||||||
/* Parsing state machine */
|
/* Parsing state machine */
|
||||||
gstate state; /* Curent decoder master state */
|
gstate state; /* Curent decoder master state */
|
||||||
PRUint8 *hold; /* Accumulation buffer */
|
PRUint8 *hold; /* Accumulation buffer */
|
||||||
int32 hold_size; /* Capacity, in bytes, of accumulation buffer */
|
|
||||||
PRUint8 *gather_head; /* Next byte to read in accumulation buffer */
|
PRUint8 *gather_head; /* Next byte to read in accumulation buffer */
|
||||||
int32 gather_request_size; /* Number of bytes to accumulate */
|
int32 gather_request_size; /* Number of bytes to accumulate */
|
||||||
int32 gathered; /* bytes accumulated so far*/
|
int32 gathered; /* bytes accumulated so far*/
|
||||||
|
@ -122,15 +121,11 @@ typedef struct gif_struct {
|
||||||
/* Parameters for image frame currently being decoded*/
|
/* Parameters for image frame currently being decoded*/
|
||||||
PRUintn x_offset, y_offset; /* With respect to "screen" origin */
|
PRUintn x_offset, y_offset; /* With respect to "screen" origin */
|
||||||
PRUintn height, width;
|
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 interlaced; /* TRUE, if scanlines arrive interlaced order */
|
||||||
int tpixel; /* Index of transparent pixel */
|
int tpixel; /* Index of transparent pixel */
|
||||||
int is_transparent; /* TRUE, if tpixel is valid */
|
int is_transparent; /* TRUE, if tpixel is valid */
|
||||||
int control_extension; /* TRUE, if image control extension present */
|
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 disposal_method; /* Restore to background, leave in place, etc.*/
|
||||||
gdispose last_disposal_method;
|
|
||||||
PRUint8 *local_colormap; /* Per-image colormap */
|
PRUint8 *local_colormap; /* Per-image colormap */
|
||||||
int local_colormap_size; /* Size of local colormap array. */
|
int local_colormap_size; /* Size of local colormap array. */
|
||||||
PRUint32 delay_time; /* Display time, in milliseconds,
|
PRUint32 delay_time; /* Display time, in milliseconds,
|
||||||
|
@ -144,30 +139,21 @@ typedef struct gif_struct {
|
||||||
PRUint8 *global_colormap; /* Default colormap if local not supplied */
|
PRUint8 *global_colormap; /* Default colormap if local not supplied */
|
||||||
int global_colormap_size; /* Size of global colormap array. */
|
int global_colormap_size; /* Size of global colormap array. */
|
||||||
int images_decoded; /* Counts images for multi-part GIFs */
|
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 progressive_display; /* If TRUE, do Haeberli interlace hack */
|
||||||
int loop_count; /* Netscape specific extension block to control
|
int loop_count; /* Netscape specific extension block to control
|
||||||
the number of animation loops a GIF renders. */
|
the number of animation loops a GIF renders. */
|
||||||
} gif_struct;
|
} gif_struct;
|
||||||
|
|
||||||
|
|
||||||
/* Create a new gif_struct */
|
|
||||||
extern PRBool gif_create(gif_struct **gs);
|
|
||||||
|
|
||||||
/* These are the APIs that the client calls to intialize,
|
/* These are the APIs that the client calls to intialize,
|
||||||
push data to, and shut down the GIF decoder. */
|
push data to, and shut down the GIF decoder. */
|
||||||
PRBool GIFInit(gif_struct* gs, void* aClientData);
|
PRBool GIFInit(gif_struct* gs, void* aClientData);
|
||||||
|
|
||||||
extern void gif_destroy(gif_struct* aGIFStruct);
|
void gif_destroy(gif_struct* aGIFStruct);
|
||||||
|
|
||||||
PRStatus gif_write(gif_struct* aGIFStruct, const PRUint8 * buf, PRUint32 numbytes);
|
PRStatus gif_write(gif_struct* aGIFStruct, const PRUint8 * buf, PRUint32 numbytes);
|
||||||
|
|
||||||
PRBool gif_write_ready(const gif_struct* aGIFStruct);
|
PRBool gif_write_ready(const gif_struct* aGIFStruct);
|
||||||
|
|
||||||
extern void gif_complete(gif_struct** aGIFStruct);
|
|
||||||
extern void gif_delay_time_callback(/* void *closure */);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -83,9 +83,9 @@ NS_IMETHODIMP nsGIFDecoder2::Init(imgILoad *aLoad)
|
||||||
/* do gif init stuff */
|
/* do gif init stuff */
|
||||||
/* Always decode to 24 bit pixdepth */
|
/* Always decode to 24 bit pixdepth */
|
||||||
|
|
||||||
PRBool created = gif_create(&mGIFStruct);
|
mGIFStruct = (gif_struct *)PR_CALLOC(sizeof(gif_struct));
|
||||||
NS_ASSERTION(created, "gif_create failed");
|
NS_ASSERTION(mGIFStruct, "gif_create failed");
|
||||||
if (!created)
|
if (!mGIFStruct)
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
// Call GIF decoder init routine
|
// Call GIF decoder init routine
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
};
|
|
Загрузка…
Ссылка в новой задаче