summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dw/fltkimgbuf.cc27
-rw-r--r--dw/fltkimgbuf.hh8
-rw-r--r--dw/fltkplatform.cc4
-rw-r--r--dw/fltkplatform.hh3
-rw-r--r--dw/layout.hh5
-rw-r--r--dw/platform.hh12
-rw-r--r--src/dicache.c5
-rw-r--r--src/dicache.h3
-rw-r--r--src/gif.c3
-rw-r--r--src/imgbuf.cc5
-rw-r--r--src/imgbuf.hh3
-rw-r--r--src/jpeg.c3
-rw-r--r--src/png.c3
-rw-r--r--test/dw_images_scaled.cc2
-rw-r--r--test/dw_images_scaled2.cc2
-rw-r--r--test/dw_images_simple.cc2
-rw-r--r--test/dw_imgbuf_mem_test.cc6
17 files changed, 58 insertions, 38 deletions
diff --git a/dw/fltkimgbuf.cc b/dw/fltkimgbuf.cc
index a63a9a89..4b93601f 100644
--- a/dw/fltkimgbuf.cc
+++ b/dw/fltkimgbuf.cc
@@ -39,19 +39,21 @@ static bool excessiveImageDimensions (int width, int height)
width > IMAGE_MAX_AREA / height;
}
-FltkImgbuf::FltkImgbuf (Type type, int width, int height)
+FltkImgbuf::FltkImgbuf (Type type, int width, int height, double gamma)
{
_MSG("FltkImgbuf: new root %p\n", this);
- init (type, width, height, NULL);
+ init (type, width, height, gamma, NULL);
}
-FltkImgbuf::FltkImgbuf (Type type, int width, int height, FltkImgbuf *root)
+FltkImgbuf::FltkImgbuf (Type type, int width, int height, double gamma,
+ FltkImgbuf *root)
{
_MSG("FltkImgbuf: new scaled %p, root is %p\n", this, root);
- init (type, width, height, root);
+ init (type, width, height, gamma, root);
}
-void FltkImgbuf::init (Type type, int width, int height, FltkImgbuf *root)
+void FltkImgbuf::init (Type type, int width, int height, double gamma,
+ FltkImgbuf *root)
{
if (excessiveImageDimensions (width, height)) {
// Excessive image sizes which would cause crashes due to too
@@ -60,7 +62,7 @@ void FltkImgbuf::init (Type type, int width, int height, FltkImgbuf *root)
// 1 size.
MSG("FltkImgbuf::init: suspicious image size request %d x %d\n",
width, height);
- init (type, 1, 1, root);
+ init (type, 1, 1, gamma, root);
} else if (width > MAX_WIDTH) {
// Too large dimensions cause dangerous overflow errors, so we
// limit dimensions to harmless values.
@@ -69,15 +71,19 @@ void FltkImgbuf::init (Type type, int width, int height, FltkImgbuf *root)
// the negative value -1.
MSG("FltkImgbuf::init: cannot handle large width %d\n", width);
- init (type, MAX_WIDTH, height, root);
+ init (type, MAX_WIDTH, height, gamma, root);
} else if (height > MAX_HEIGHT) {
MSG("FltkImgbuf::init: cannot handle large height %d\n", height);
- init (type, width, MAX_HEIGHT, root);
+ init (type, width, MAX_HEIGHT, gamma, root);
+ } else if (gamma <= 0) {
+ MSG("FltkImgbuf::init: non-positive gamma %g\n", gamma);
+ init (type, width, height, 1, root);
} else {
this->root = root;
this->type = type;
this->width = width;
this->height = height;
+ this->gamma = gamma;
// TODO: Maybe this is only for root buffers
switch (type) {
@@ -85,7 +91,8 @@ void FltkImgbuf::init (Type type, int width, int height, FltkImgbuf *root)
case RGB: bpp = 3; break;
default: bpp = 1; break;
}
- _MSG("FltkImgbuf::init width=%d height=%d bpp=%d\n", width, height, bpp);
+ _MSG("FltkImgbuf::init width=%d height=%d bpp=%d gamma=%g\n",
+ width, height, bpp, gamma);
rawdata = new uchar[bpp * width * height];
// Set light-gray as interim background color.
memset(rawdata, 222, width*height*bpp);
@@ -323,7 +330,7 @@ core::Imgbuf* FltkImgbuf::getScaledBuf (int width, int height)
}
// This size is not yet used, so a new buffer has to be created.
- FltkImgbuf *sb = new FltkImgbuf (type, width, height, this);
+ FltkImgbuf *sb = new FltkImgbuf (type, width, height, gamma, this);
scaledBuffers->append (sb);
return sb;
}
diff --git a/dw/fltkimgbuf.hh b/dw/fltkimgbuf.hh
index d862eece..f7455807 100644
--- a/dw/fltkimgbuf.hh
+++ b/dw/fltkimgbuf.hh
@@ -18,6 +18,7 @@ private:
int width, height;
Type type;
+ double gamma;
//{
int bpp;
@@ -28,8 +29,9 @@ private:
// the image buffer.
lout::misc::BitSet *copiedRows;
- FltkImgbuf (Type type, int width, int height, FltkImgbuf *root);
- void init (Type type, int width, int height, FltkImgbuf *root);
+ FltkImgbuf (Type type, int width, int height, double gamma,
+ FltkImgbuf *root);
+ void init (Type type, int width, int height, double gamma, FltkImgbuf *root);
int scaledY(int ySrc);
int backscaledY(int yScaled);
int isRoot() { return (root == NULL); }
@@ -39,7 +41,7 @@ protected:
~FltkImgbuf ();
public:
- FltkImgbuf (Type type, int width, int height);
+ FltkImgbuf (Type type, int width, int height, double gamma);
void setCMap (int *colors, int num_colors);
inline void scaleRow (int row, const core::byte *data);
diff --git a/dw/fltkplatform.cc b/dw/fltkplatform.cc
index 7dd87a18..1d77e289 100644
--- a/dw/fltkplatform.cc
+++ b/dw/fltkplatform.cc
@@ -704,9 +704,9 @@ void FltkPlatform::copySelection(const char *text)
}
core::Imgbuf *FltkPlatform::createImgbuf (core::Imgbuf::Type type,
- int width, int height)
+ int width, int height, double gamma)
{
- return new FltkImgbuf (type, width, height);
+ return new FltkImgbuf (type, width, height, gamma);
}
core::ui::ResourceFactory *FltkPlatform::getResourceFactory ()
diff --git a/dw/fltkplatform.hh b/dw/fltkplatform.hh
index 64605b68..2fb95633 100644
--- a/dw/fltkplatform.hh
+++ b/dw/fltkplatform.hh
@@ -169,7 +169,8 @@ public:
core::style::Tooltip *createTooltip (const char *text);
void cancelTooltip();
- core::Imgbuf *createImgbuf (core::Imgbuf::Type type, int width, int height);
+ core::Imgbuf *createImgbuf (core::Imgbuf::Type type, int width, int height,
+ double gamma);
void copySelection(const char *text);
diff --git a/dw/layout.hh b/dw/layout.hh
index d3ace03a..51d764a4 100644
--- a/dw/layout.hh
+++ b/dw/layout.hh
@@ -358,9 +358,10 @@ public:
return platform->cancelTooltip ();
}
- inline Imgbuf *createImgbuf (Imgbuf::Type type, int width, int height)
+ inline Imgbuf *createImgbuf (Imgbuf::Type type, int width, int height,
+ double gamma)
{
- return platform->createImgbuf (type, width, height);
+ return platform->createImgbuf (type, width, height, gamma);
}
inline void copySelection(const char *text)
diff --git a/dw/platform.hh b/dw/platform.hh
index 1e16dcfe..532f4cf9 100644
--- a/dw/platform.hh
+++ b/dw/platform.hh
@@ -146,12 +146,14 @@ public:
*/
virtual void cancelTooltip () = 0;
- /*
- * --------------------
- * Image Buffers
- * --------------------
+ /**
+ * \brief Create a (platform speficic) image buffer.
+ *
+ * "gamma" is the value by which the image data is already
+ * corrected.
*/
- virtual Imgbuf *createImgbuf (Imgbuf::Type type, int width, int height) = 0;
+ virtual Imgbuf *createImgbuf (Imgbuf::Type type, int width, int height,
+ double gamma) = 0;
/**
* \brief Copy selected text (0-terminated).
diff --git a/src/dicache.c b/src/dicache.c
index 23721685..55232846 100644
--- a/src/dicache.c
+++ b/src/dicache.c
@@ -259,7 +259,8 @@ void a_Dicache_invalidate_entry(const DilloUrl *Url)
* (By now, we'll use the image information despite the html tags --Jcid)
*/
void a_Dicache_set_parms(DilloUrl *url, int version, DilloImage *Image,
- uint_t width, uint_t height, DilloImgType type)
+ uint_t width, uint_t height, DilloImgType type,
+ double gamma)
{
DICacheEntry *DicEntry;
@@ -275,7 +276,7 @@ void a_Dicache_set_parms(DilloUrl *url, int version, DilloImage *Image,
/* BUG: there's just one image-type now */
#define I_RGB 0
- DicEntry->v_imgbuf = a_Imgbuf_new(Image->dw, I_RGB, width, height);
+ DicEntry->v_imgbuf = a_Imgbuf_new(Image->dw, I_RGB, width, height, gamma);
DicEntry->TotalSize = width * height * 3;
DicEntry->width = width;
diff --git a/src/dicache.h b/src/dicache.h
index 76fdba92..df8a8b89 100644
--- a/src/dicache.h
+++ b/src/dicache.h
@@ -59,7 +59,8 @@ void *a_Dicache_jpeg_image(const char *Type, void *Ptr, CA_Callback_t *Call,
void a_Dicache_callback(int Op, CacheClient_t *Client);
void a_Dicache_set_parms(DilloUrl *url, int version, DilloImage *Image,
- uint_t width, uint_t height, DilloImgType type);
+ uint_t width, uint_t height, DilloImgType type,
+ double gamma);
void a_Dicache_set_cmap(DilloUrl *url, int version, DilloImage *Image,
const uchar_t *cmap, uint_t num_colors,
int num_colors_max, int bg_index);
diff --git a/src/gif.c b/src/gif.c
index 554ffa83..a4233267 100644
--- a/src/gif.c
+++ b/src/gif.c
@@ -814,8 +814,9 @@ static size_t Gif_do_img_desc(DilloGif *gif, void *Buf,
return 0;
}
+ /** \todo Gamma for GIF? */
a_Dicache_set_parms(gif->url, gif->version, gif->Image,
- gif->Width, gif->Height, DILLO_IMG_TYPE_INDEXED);
+ gif->Width, gif->Height, DILLO_IMG_TYPE_INDEXED, 2.2);
Flags = buf[8];
diff --git a/src/imgbuf.cc b/src/imgbuf.cc
index 51f86b74..16eb5c31 100644
--- a/src/imgbuf.cc
+++ b/src/imgbuf.cc
@@ -90,7 +90,8 @@ void a_Imgbuf_unref(void *v_imgbuf)
/*
* Create a new Imgbuf
*/
-void *a_Imgbuf_new(void *v_dw, int img_type, uint_t width, uint_t height)
+void *a_Imgbuf_new(void *v_dw, int img_type, uint_t width, uint_t height,
+ double gamma)
{
Layout *layout = ((Widget*)v_dw)->getLayout();
if (!layout) {
@@ -103,7 +104,7 @@ void *a_Imgbuf_new(void *v_dw, int img_type, uint_t width, uint_t height)
linebuf = (uchar_t*) dRealloc(linebuf, linebuf_size);
}
- return (void*)layout->createImgbuf(Imgbuf::RGB, width, height);
+ return (void*)layout->createImgbuf(Imgbuf::RGB, width, height, gamma);
}
/*
diff --git a/src/imgbuf.hh b/src/imgbuf.hh
index 9a6e3ff7..af0bf9a6 100644
--- a/src/imgbuf.hh
+++ b/src/imgbuf.hh
@@ -16,7 +16,8 @@ extern "C" {
*/
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);
+void *a_Imgbuf_new(void *v_dw, int img_type, uint_t width, uint_t height,
+ double gamma);
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);
diff --git a/src/jpeg.c b/src/jpeg.c
index c81afe1d..7efdbfbb 100644
--- a/src/jpeg.c
+++ b/src/jpeg.c
@@ -299,10 +299,11 @@ static void Jpeg_write(DilloJpeg *jpeg, void *Buf, uint_t BufSize)
return;
}
+ /** \todo Gamma for JPEG? */
a_Dicache_set_parms(jpeg->url, jpeg->version, jpeg->Image,
(uint_t)jpeg->cinfo.image_width,
(uint_t)jpeg->cinfo.image_height,
- type);
+ type, 2.2);
/* decompression step 4 (see libjpeg.doc) */
jpeg->state = DILLO_JPEG_STARTING;
diff --git a/src/png.c b/src/png.c
index 995725cd..767df994 100644
--- a/src/png.c
+++ b/src/png.c
@@ -201,9 +201,10 @@ Png_datainfo_callback(png_structp png_ptr, png_infop info_ptr)
png->linebuf = dMalloc(3 * png->width);
/* Initialize the dicache-entry here */
+ /** \todo Gamma for PNG? */
a_Dicache_set_parms(png->url, png->version, png->Image,
(uint_t)png->width, (uint_t)png->height,
- DILLO_IMG_TYPE_RGB);
+ DILLO_IMG_TYPE_RGB, 2.2);
}
static void
diff --git a/test/dw_images_scaled.cc b/test/dw_images_scaled.cc
index 34a72c21..e31abfaa 100644
--- a/test/dw_images_scaled.cc
+++ b/test/dw_images_scaled.cc
@@ -41,7 +41,7 @@ static int imgRow = 0;
static void imageInitTimeout (void *data)
{
//imgbuf = layout->createImgbuf (Imgbuf::RGBA, 400, 200);
- imgbuf = layout->createImgbuf (Imgbuf::RGB, 400, 200);
+ imgbuf = layout->createImgbuf (Imgbuf::RGB, 400, 200, 1);
image->setBuffer (imgbuf);
}
diff --git a/test/dw_images_scaled2.cc b/test/dw_images_scaled2.cc
index 81cdd2e8..01a55bcf 100644
--- a/test/dw_images_scaled2.cc
+++ b/test/dw_images_scaled2.cc
@@ -40,7 +40,7 @@ static int imgRow = 0;
static void imageInitTimeout (void *data)
{
- imgbuf = layout->createImgbuf (Imgbuf::RGB, 400, 200);
+ imgbuf = layout->createImgbuf (Imgbuf::RGB, 400, 200, 1);
image1->setBuffer (imgbuf);
image2->setBuffer (imgbuf);
}
diff --git a/test/dw_images_simple.cc b/test/dw_images_simple.cc
index 34de20ea..361ede68 100644
--- a/test/dw_images_simple.cc
+++ b/test/dw_images_simple.cc
@@ -42,7 +42,7 @@ static void imageInitTimeout (void *data)
{
const bool resize = true;
//imgbuf = layout->createImgbuf (Imgbuf::RGBA, 400, 200);
- imgbuf = layout->createImgbuf (Imgbuf::RGB, 400, 200);
+ imgbuf = layout->createImgbuf (Imgbuf::RGB, 400, 200, 1);
image->setBuffer (imgbuf, resize);
}
diff --git a/test/dw_imgbuf_mem_test.cc b/test/dw_imgbuf_mem_test.cc
index 45beef8b..e2532ea7 100644
--- a/test/dw_imgbuf_mem_test.cc
+++ b/test/dw_imgbuf_mem_test.cc
@@ -29,7 +29,7 @@ void solution1 ()
FltkPlatform *platform = new FltkPlatform ();
Layout *layout = new Layout (platform);
- Imgbuf *rootbuf = layout->createImgbuf (Imgbuf::RGB, 100, 100);
+ Imgbuf *rootbuf = layout->createImgbuf (Imgbuf::RGB, 100, 100, 1);
rootbuf->ref (); // Extra reference by the dicache.
printf ("=== Can be deleted? %s.\n",
rootbuf->lastReference () ? "Yes" : "No");
@@ -52,7 +52,7 @@ void solution2 ()
FltkPlatform *platform = new FltkPlatform ();
Layout *layout = new Layout (platform);
- Imgbuf *rootbuf = layout->createImgbuf (Imgbuf::RGB, 100, 100);
+ Imgbuf *rootbuf = layout->createImgbuf (Imgbuf::RGB, 100, 100, 1);
rootbuf->setDeleteOnUnref (false);
printf ("=== Can be deleted? %s.\n",
!rootbuf->isReferred () ? "Yes" : "No");
@@ -86,7 +86,7 @@ void solution3 ()
FltkPlatform *platform = new FltkPlatform ();
Layout *layout = new Layout (platform);
- Imgbuf *rootbuf = layout->createImgbuf (Imgbuf::RGB, 100, 100);
+ Imgbuf *rootbuf = layout->createImgbuf (Imgbuf::RGB, 100, 100, 1);
rootbuf->connectDeletion (new RootbufDeletionReceiver ());
Imgbuf *scaledbuf = rootbuf->getScaledBuf (50, 50);
rootbuf->unref ();