aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJorge Arellano Cid <jcid@dillo.org>2008-12-25 09:57:55 -0300
committerJorge Arellano Cid <jcid@dillo.org>2008-12-25 09:57:55 -0300
commit5486bedf18450ae4de413c4174a0175948c95c3e (patch)
tree2f7bcdd68df40a36e4f8f3f67c70ce108bf321df
parenta821e0e87480e8b812ab5975c1031d5ee5eb2587 (diff)
Started code cleanup of the image code mainly in dicache.c. part#1
-rw-r--r--ChangeLog1
-rw-r--r--src/dicache.c18
-rw-r--r--src/dicache.h3
-rw-r--r--src/image.cc3
-rw-r--r--src/image.hh1
-rw-r--r--src/nav.c7
-rw-r--r--src/png.c138
7 files changed, 88 insertions, 83 deletions
diff --git a/ChangeLog b/ChangeLog
index 69aafba9..db61b047 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -46,6 +46,7 @@ dillo-2.1
? Trying a new iconv() test in configure.in.
- Allowed the rc parser to skip whitespace around the equal sign.
- Fixed the parser not to call Html_tag_close_* functions twice.
+!- Started code cleanup of the image code mainly in dicache.c.
Patches: Jorge Arellano Cid
dw
diff --git a/src/dicache.c b/src/dicache.c
index 97ed1915..fb1a0c8c 100644
--- a/src/dicache.c
+++ b/src/dicache.c
@@ -33,9 +33,9 @@ struct _DICacheNode {
*/
static Dlist *CachedIMGs = NULL;
-static int dicache_size_total; /* invariant: dicache_size_total is
- * the sum of the image sizes (3*w*h)
- * of all the images in the dicache. */
+static uint_t dicache_size_total; /* invariant: dicache_size_total is
+ * the sum of the image sizes (3*w*h)
+ * of all the images in the dicache. */
/*
* Compare two dicache nodes
@@ -87,6 +87,7 @@ static DICacheEntry *Dicache_entry_new(void)
entry->BitVec = NULL;
entry->State = DIC_Empty;
entry->version = 0;
+
entry->next = NULL;
return entry;
@@ -223,7 +224,6 @@ void a_Dicache_unref(const DilloUrl *Url, int version)
/*
* Refs the counter of a dicache entry.
*/
-
DICacheEntry* a_Dicache_ref(const DilloUrl *Url, int version)
{
DICacheEntry *entry;
@@ -255,7 +255,6 @@ void a_Dicache_invalidate_entry(const DilloUrl *Url)
*/
void a_Dicache_callback(int Op, CacheClient_t *Client)
{
- /* TODO: Handle Op = CA_Abort (to show what was got) --Jcid */
uint_t i;
DilloWeb *Web = Client->Web;
DilloImage *Image = Web->Image;
@@ -294,7 +293,7 @@ void a_Dicache_callback(int Op, CacheClient_t *Client)
}
}
} else if (Op == CA_Close || Op == CA_Abort) {
- a_Image_close(Web->Image);
+ a_Image_close(Image);
a_Bw_close_client(Web->bw, Client->Key);
}
}
@@ -309,12 +308,13 @@ void a_Dicache_set_parms(DilloUrl *url, int version, DilloImage *Image,
uint_t width, uint_t height, DilloImgType type)
{
DICacheEntry *DicEntry;
- size_t Size = width * height * 3;
dReturn_if_fail ( Image != NULL && width && height );
/* Find the DicEntry for this Image */
DicEntry = Dicache_get_entry_version(url, version);
dReturn_if_fail ( DicEntry != NULL );
+ /* Parameters already set? */
+ dReturn_if_fail ( DicEntry->State < DIC_SetParms );
/* Initialize the DicEntry */
DicEntry->linebuf = dNew(uchar_t, width * 3);
@@ -328,14 +328,14 @@ void a_Dicache_set_parms(DilloUrl *url, int version, DilloImage *Image,
* Extra code is necessary in Imgbuf to be able to free it */
//a_Image_imgbuf_ref(DicEntry->v_imgbuf);
- DicEntry->TotalSize = Size;
+ DicEntry->TotalSize = width * height * 3;
DicEntry->width = width;
DicEntry->height = height;
DicEntry->type = type;
DicEntry->BitVec = a_Bitvec_new((int)height);
DicEntry->State = DIC_SetParms;
- dicache_size_total += Size;
+ dicache_size_total += DicEntry->TotalSize;
/* Allocate and initialize this image */
a_Image_set_parms(Image, DicEntry->v_imgbuf, url, version,
diff --git a/src/dicache.h b/src/dicache.h
index 6cbcf3a5..c78d0953 100644
--- a/src/dicache.h
+++ b/src/dicache.h
@@ -29,7 +29,7 @@ struct _DICacheEntry {
uchar_t *cmap; /* Color map */
uchar_t *linebuf; /* Decompressed RGB buffer for one line */
void *v_imgbuf; /* Void pointer to an Imgbuf object */
- size_t TotalSize; /* Amount of memory the image takes up */
+ uint_t TotalSize; /* Amount of memory the image takes up */
int Y; /* Current decoding row */
uint_t ScanNumber; /* Current decoding scan */
bitvec_t *BitVec; /* Bit vector for decoded rows */
@@ -37,7 +37,6 @@ struct _DICacheEntry {
int RefCount; /* Reference Counter */
int version; /* Version number, used for different
versions of the same URL image */
-
DICacheEntry *next; /* Link to the next "newer" version */
};
diff --git a/src/image.cc b/src/image.cc
index 54eb4710..462ec90c 100644
--- a/src/image.cc
+++ b/src/image.cc
@@ -54,7 +54,6 @@ DilloImage *a_Image_new(int width,
Image->cmap = NULL;
Image->in_type = DILLO_IMG_TYPE_NOTSET;
Image->bg_color = bg_color;
- Image->ProcessedBytes = 0;
Image->ScanNumber = 0;
Image->BitVec = NULL;
Image->State = IMG_Empty;
@@ -172,7 +171,7 @@ void a_Image_new_scan(DilloImage *Image, void *v_imgbuf)
void a_Image_write(DilloImage *Image, void *v_imgbuf,
const uchar_t *buf, uint_t y, int decode)
{
- uchar_t *newbuf;
+ const uchar_t *newbuf;
dReturn_if_fail ( y < Image->height );
diff --git a/src/image.hh b/src/image.hh
index 73b0e5e7..ce906c74 100644
--- a/src/image.hh
+++ b/src/image.hh
@@ -42,7 +42,6 @@ struct _DilloImage {
DilloImgType in_type; /* Image Type */
int32_t bg_color; /* Background color */
- int ProcessedBytes; /* Amount of bytes already decoded */
bitvec_t *BitVec; /* Bit vector for decoded rows */
uint_t ScanNumber; /* Current decoding scan */
ImageState State; /* Processing status */
diff --git a/src/nav.c b/src/nav.c
index 2433d7b2..8acf9130 100644
--- a/src/nav.c
+++ b/src/nav.c
@@ -194,12 +194,13 @@ static void Nav_stack_clean(BrowserWindow *bw)
static void Nav_open_url(BrowserWindow *bw, const DilloUrl *url, int offset)
{
DilloUrl *old_url;
- bool_t MustLoad, ForceReload;
+ bool_t MustLoad, ForceReload, Repush;
int x, y, idx, ClientKey;
DilloWeb *Web;
MSG("Nav_open_url: new url='%s'\n", URL_STR_(url));
+ Repush = (URL_FLAGS(url) & URL_ReloadFromCache) != 0;
ForceReload = (URL_FLAGS(url) & (URL_E2EQuery + URL_ReloadFromCache)) != 0;
/* Get the url of the current page */
@@ -207,8 +208,8 @@ static void Nav_open_url(BrowserWindow *bw, const DilloUrl *url, int offset)
old_url = a_History_get_url(NAV_UIDX(bw, idx));
_MSG("Nav_open_url: old_url='%s' idx=%d\n", URL_STR(old_url), idx);
/* Record current scrolling position */
- if (URL_FLAGS(url) & URL_ReloadFromCache) {
- /* Repush operation, don't change scroll position */
+ if (Repush) {
+ /* Don't change scroll position */
} else if (old_url) {
a_UIcmd_get_scroll_xy(bw, &x, &y);
Nav_save_scroll_pos(bw, idx, x, y);
diff --git a/src/png.c b/src/png.c
index fa07e781..e9b0b843 100644
--- a/src/png.c
+++ b/src/png.c
@@ -4,6 +4,7 @@
*
* Geoff Lane nov 1999 zzassgl@twirl.mcc.ac.uk
* Luca Rota, Jorge Arellano Cid, Eric Gaudet 2000
+ * Jorge Arellano Cid 2009
*
* "PNG: The Definitive Guide" by Greg Roelofs, O'Reilly
* ISBN 1-56592-542-4
@@ -67,19 +68,19 @@ typedef
struct _DilloPng {
DilloImage *Image; /* Image meta data */
DilloUrl *url; /* Primary Key for the dicache */
- int version; /* Secondary Key for the dicache */
+ int version; /* Secondary Key for the dicache */
double display_exponent; /* gamma correction */
- ulong_t width; /* png image width */
- ulong_t height; /* png image height */
+ ulong_t width; /* png image width */
+ ulong_t height; /* png image height */
png_structp png_ptr; /* libpng private data */
png_infop info_ptr; /* libpng private info */
- uchar_t *image_data; /* decoded image data */
- uchar_t **row_pointers; /* pntr to row starts */
+ uchar_t *image_data; /* decoded image data */
+ uchar_t **row_pointers; /* pntr to row starts */
jmp_buf jmpbuf; /* png error processing */
- int error; /* error flag */
+ int error; /* error flag */
png_uint_32 previous_row;
- int rowbytes; /* No. bytes in image row */
+ int rowbytes; /* No. bytes in image row */
short passes;
short channels; /* No. image channels */
@@ -92,13 +93,13 @@ struct _DilloPng {
* ipbuf ipbufstart ipbufsize
*/
- uchar_t *ipbuf; /* image data in buffer */
- int ipbufstart; /* first valid image byte */
- int ipbufsize; /* size of valid data in */
+ uchar_t *ipbuf; /* image data in buffer */
+ int ipbufstart; /* first valid image byte */
+ int ipbufsize; /* size of valid data in */
enum prog_state state; /* FSM current state */
- uchar_t *linebuf; /* o/p raster data */
+ uchar_t *linebuf; /* o/p raster data */
} DilloPng;
@@ -297,57 +298,37 @@ static void
png->state = IS_finished;
}
-
/*
- * Op: Operation to perform.
- * If (Op == 0)
- * start or continue processing an image if image data exists.
- * else
- * terminate processing, cleanup any allocated memory,
- * close down the decoding process.
- *
- * Client->CbData : pointer to previously allocated DilloPng work area.
- * This holds the current state of the image processing and is saved
- * across calls to this routine.
- * Client->Buf : Pointer to data start.
- * Client->BufSize : the size of the data buffer.
- *
- * You have to keep track of where you are in the image data and
- * how much has been processed.
- *
- * It's entirely possible that you will not see the end of the data. The
- * user may terminate transfer via a Stop button or there may be a network
- * failure. This means that you can't just wait for all the data to be
- * presented before starting conversion and display.
+ * Finish the decoding process (and free the memory)
*/
-static void Png_callback(int Op, CacheClient_t *Client)
+static void Png_close(DilloPng *png, CacheClient_t *Client)
{
- DilloPng *png = Client->CbData;
-
- if (Op) {
- /* finished - free up the resources for this image */
- a_Dicache_close(png->url, png->version, Client);
- dFree(png->image_data);
- dFree(png->row_pointers);
- dFree(png->linebuf);
-
- if (setjmp(png->jmpbuf))
- MSG_WARN("PNG: can't destroy read structure\n");
- else if (png->png_ptr)
- png_destroy_read_struct(&png->png_ptr, &png->info_ptr, NULL);
- dFree(png);
- return;
- }
+ /* Free up the resources for this image */
+ a_Dicache_close(png->url, png->version, Client);
+ dFree(png->image_data);
+ dFree(png->row_pointers);
+ dFree(png->linebuf);
+
+ if (setjmp(png->jmpbuf))
+ MSG_WARN("PNG: can't destroy read structure\n");
+ else if (png->png_ptr)
+ png_destroy_read_struct(&png->png_ptr, &png->info_ptr, NULL);
+ dFree(png);
+}
- /* Let's make some sound if we have been called with no data */
- dReturn_if_fail ( Client->Buf != NULL && Client->BufSize > 0 );
+/*
+ * Receive and process new chunks of PNG image data
+ */
+static void Png_write(DilloPng *png, void *Buf, uint_t BufSize)
+{
+ dReturn_if_fail ( Buf != NULL && BufSize > 0 );
- _MSG("Png_callback BufSize = %d\n", Client->BufSize);
+ _MSG("Png_callback BufSize = %d\n", BufSize);
/* Keep local copies so we don't have to pass multiple args to
* a number of functions. */
- png->ipbuf = Client->Buf;
- png->ipbufsize = Client->BufSize;
+ png->ipbuf = Buf;
+ png->ipbufsize = BufSize;
/* start/resume the FSM here */
while (png->state != IS_finished && DATASIZE) {
@@ -408,6 +389,37 @@ static void Png_callback(int Op, CacheClient_t *Client)
}
/*
+ * Op: Operation to perform.
+ * If (Op == 0)
+ * start or continue processing an image if image data exists.
+ * else
+ * terminate processing, cleanup any allocated memory,
+ * close down the decoding process.
+ *
+ * Client->CbData : pointer to previously allocated DilloPng work area.
+ * This holds the current state of the image processing and is kept
+ * across calls to this routine.
+ * Client->Buf : Pointer to data start.
+ * Client->BufSize : the size of the data buffer.
+ *
+ * You have to keep track of where you are in the image data and
+ * how much has been processed.
+ *
+ * It's entirely possible that you will not see the end of the data. The
+ * user may terminate transfer via a Stop button or there may be a network
+ * failure. This means that you can't just wait for all the data to be
+ * presented before starting conversion and display.
+ */
+static void Png_callback(int Op, CacheClient_t *Client)
+{
+ if (Op) { /* EOF */
+ Png_close(Client->CbData, Client);
+ } else {
+ Png_write(Client->CbData, Client->Buf, Client->BufSize);
+ }
+}
+
+/*
* Create the image state data that must be kept between calls
*/
static DilloPng *Png_new(DilloImage *Image, DilloUrl *url, int version)
@@ -433,25 +445,19 @@ static DilloPng *Png_new(DilloImage *Image, DilloUrl *url, int version)
/*
* MIME handler for "image/png" type
* (Sets Png_callback or a_Dicache_callback as the cache-client)
+ *
+ * Parameters:
+ * Type: MIME type
+ * Ptr: points to a Web structure
+ * Call: Dillo calls this with more data/eod
+ * Data: Decoding data structure
*/
void *a_Png_image(const char *Type, void *Ptr, CA_Callback_t *Call,
void **Data)
{
-/*
- * Type: MIME type
- * Ptr: points to a Web structure
- * Call: Dillo calls this with more data/eod
- * Data: raw image data
- */
-
DilloWeb *web = Ptr;
DICacheEntry *DicEntry;
- _MSG("a_Png_image: Type = %s\n"
- "a_Png_image: libpng - Compiled %s; using %s.\n"
- "a_Png_image: zlib - Compiled %s; using %s.\n",
- Type, PNG_LIBPNG_VER_STRING, png_libpng_ver,ZLIB_VERSION,zlib_version);
-
if (!web->Image)
web->Image = a_Image_new(0, 0, NULL, prefs.bg_color);