changeset 707:bf52c025c058

imported patch dicache-cleanup2
author Jorge Arellano Cid <jcid@dillo.org>
date Mon, 29 Dec 2008 12:36:50 -0300
parents d2e393cb71cd
children 697145062347
files src/dicache.c src/imgbuf.cc src/imgbuf.hh
diffstat 3 files changed, 146 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/dicache.c	Mon Dec 29 12:36:14 2008 -0300
+++ b/src/dicache.c	Mon Dec 29 12:36:50 2008 -0300
@@ -336,10 +336,6 @@
    #define I_RGB 0
    DicEntry->v_imgbuf = a_Imgbuf_new(Image->dw, I_RGB, width, height);
 
-   /* This extra reference activates the dicache ALWAYS.
-    * Extra code is necessary in Imgbuf to be able to free it */
-   //a_Imgbuf_ref(DicEntry->v_imgbuf);
-
    DicEntry->TotalSize = width * height * 3;
    DicEntry->width = width;
    DicEntry->height = height;
@@ -348,12 +344,6 @@
    DicEntry->State = DIC_SetParms;
 
    dicache_size_total += DicEntry->TotalSize;
-
-#if 0
-   /* Allocate and initialize this image */
-   a_Image_set_parms(Image, DicEntry->v_imgbuf, url, version,
-                     width, height, type);
-#endif
 }
 
 /*
@@ -376,7 +366,6 @@
       DicEntry->cmap[bg_index * 3 + 2] = (Image->bg_color) & 0xff;
    }
 
-   //a_Image_set_cmap(Image, DicEntry->cmap);
    DicEntry->State = DIC_SetCmap;
 }
 
@@ -397,7 +386,6 @@
    }
    a_Bitvec_clear(DicEntry->BitVec);
    DicEntry->ScanNumber++;
-   //a_Image_new_scan(image, DicEntry->v_imgbuf);
 }
 
 /*
@@ -420,7 +408,6 @@
    /* update the common buffer in the imgbuf */
    a_Imgbuf_update(DicEntry->v_imgbuf, buf, DicEntry->type,
                    DicEntry->cmap, DicEntry->width, DicEntry->height, Y);
-   //a_Image_write(Image, DicEntry->v_imgbuf, buf, Y, TRUE);
 
    DicEntry->Y = Y;
    a_Bitvec_set_bit(DicEntry->BitVec, (int)Y);
@@ -443,7 +430,6 @@
    DicEntry->cmap = NULL;
    dFree(DicEntry->linebuf);
    DicEntry->linebuf = NULL;
-   //a_Image_close(Web->Image);
    a_Bw_close_client(Web->bw, Client->Key);
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/imgbuf.cc	Mon Dec 29 12:36:50 2008 -0300
@@ -0,0 +1,116 @@
+/*
+ * File: imgbuf.cc
+ *
+ * Copyright (C) 2008 Jorge Arellano Cid <jcid@dillo.org>,
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ */
+
+#include "msg.h"
+#include "imgbuf.hh"
+#include "dw/core.hh"
+#include "dw/image.hh"
+
+using namespace dw::core;
+
+/*
+ * Local data
+ */
+static size_t linebuf_size = 0;
+static uchar_t *linebuf = NULL;
+
+
+/*
+ * Decode 'buf' (an image line) into RGB format.
+ */
+static uchar_t *Imgbuf_rgb_line(const uchar_t *buf,
+                                DilloImgType type, uchar_t *cmap,
+                                uint_t width, uint_t y)
+{
+   uint_t x;
+
+   switch (type) {
+   case DILLO_IMG_TYPE_INDEXED:
+      if (cmap) {
+         for (x = 0; x < width; x++)
+            memcpy(linebuf + x * 3, cmap + buf[x] * 3, 3);
+      } else {
+         MSG("Gif:: WARNING, image lacks a color map\n");
+      }
+      break;
+   case DILLO_IMG_TYPE_GRAY:
+      for (x = 0; x < width; x++)
+         memset(linebuf + x * 3, buf[x], 3);
+      break;
+   case DILLO_IMG_TYPE_RGB:
+      /* avoid a memcpy here!  --Jcid */
+      return (uchar_t *)buf;
+   case DILLO_IMG_TYPE_NOTSET:
+      MSG_ERR("Imgbuf_rgb_line: type not set...\n");
+      break;
+   }
+   return linebuf;
+}
+
+// Wrappers for Imgbuf -------------------------------------------------------
+
+/*
+ * Increment reference count for an Imgbuf
+ */
+void a_Imgbuf_ref(void *v_imgbuf)
+{
+   ((Imgbuf*)v_imgbuf)->ref();
+}
+
+/*
+ * Decrement reference count for an Imgbuf
+ */
+void a_Imgbuf_unref(void *v_imgbuf)
+{
+   ((Imgbuf*)v_imgbuf)->unref();
+}
+
+/*
+ * Create a new Imgbuf
+ */
+void *a_Imgbuf_new(void *v_dw, int img_type, uint_t width, uint_t height)
+{
+   Layout *layout = ((Widget*)v_dw)->getLayout();
+   if (!layout) {
+      MSG_ERR("a_Imgbuf_new: layout is NULL.\n");
+      exit(1);
+   }
+   // Assert linebuf is wide enough.
+   if (3 * width > linebuf_size) {
+      linebuf_size = 3 * width;
+      linebuf = (uchar_t*) dRealloc(linebuf, linebuf_size);
+   }
+
+   return (void*)layout->createImgbuf(Imgbuf::RGB, width, height);
+}
+
+/*
+ * Last reference for this Imgbuf?
+ */
+int a_Imgbuf_last_reference(void *v_imgbuf)
+{
+   return ((Imgbuf*)v_imgbuf)->lastReference () ? 1 : 0;
+}
+
+/*
+ * Update the root buffer of an imgbuf.
+ */
+void a_Imgbuf_update(void *v_imgbuf, const uchar_t *buf, DilloImgType type,
+                     uchar_t *cmap, uint_t width, uint_t height, uint_t y)
+
+{
+   dReturn_if_fail ( y < height );
+
+   /* Decode 'buf' and copy it into the imgbuf */
+   uchar_t *newbuf = Imgbuf_rgb_line(buf, type, cmap, width, y);
+   ((Imgbuf*)v_imgbuf)->copyRow(y, (byte *)newbuf);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/imgbuf.hh	Mon Dec 29 12:36:50 2008 -0300
@@ -0,0 +1,30 @@
+#ifndef __IMGBUF_HH__
+#define __IMGBUF_HH__
+
+// Imgbuf wrappers
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+#include "image.hh"
+
+/*
+ * Function prototypes
+ */
+void a_Imgbuf_ref(void *v_imgbuf);
+void a_Imgbuf_unref(void *v_imgbuf);
+void *a_Imgbuf_new(void *v_dw, int img_type, uint_t width, uint_t height);
+int a_Imgbuf_last_reference(void *v_imgbuf);
+void a_Imgbuf_update(void *v_imgbuf, const uchar_t *buf, DilloImgType type,
+                     uchar_t *cmap, uint_t width, uint_t height, uint_t y);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __IMGBUF_HH__ */
+