21#include "../lout/msg.h"
22#include "../lout/misc.hh"
24#include <FL/fl_draw.H>
27#define IMAGE_MAX_AREA (6000 * 6000)
29#define MAX_WIDTH 0x8000
30#define MAX_HEIGHT 0x8000
41 =
new Vector <FltkImgbuf::GammaCorrectionTable> (
true, 2);
54 _MSG(
"Creating new table for gamma = %g\n",
gamma);
59 for (
int i = 0; i < 256; i++)
60 gct->
map[i] = 255 * pow((
double)i / 255,
gamma);
74 _MSG(
"Deleting gammaCorrectionTables\n");
83 _MSG (
"FltkImgbuf::FltkImgbuf: new root %p\n",
this);
92 _MSG (
"FltkImgbuf::FltkImgbuf: new scaled %p, root is %p\n",
this,
root);
104 MSG(
"FltkImgbuf::init: suspicious image size request %d x %d\n",
114 MSG(
"FltkImgbuf::init: cannot handle large width %d\n",
width);
117 MSG(
"FltkImgbuf::init: cannot handle large height %d\n",
height);
119 }
else if (
gamma <= 0) {
120 MSG(
"FltkImgbuf::init: non-positive gamma %g\n",
gamma);
136 default:
bpp = 1;
break;
138 _MSG(
"FltkImgbuf::init this=%p width=%d height=%d bpp=%d gamma=%g\n",
156 scaledBuffers =
new lout::container::typed::List <FltkImgbuf> (
true);
162 for (
int row = 0; row <
root->
height; row++) {
172 _MSG (
"FltkImgbuf::~FltkImgbuf\n");
194 _MSG(
"FltkImgbuf[root %p]: scaled buffer %p is detached, %d left\n",
223 for (
int sr = sr1; sr < sr2; sr++) {
236 for (
int px = 0; px <
root->
width; px++) {
239 for (
int sp = px1; sp < px2; sp++) {
253 bool allRootRows =
false;
263 for (
int sr = sr1; sr < sr2 || sr == sr1; sr++)
272 assert (sr1 == sr2 || sr1 + 1 == sr2);
317 int destWidth,
int destHeight,
int bpp,
320 uchar *gammaMap1, *gammaMap2;
327 int *v =
new int[
bpp];
328 for(
int x = 0; x < destWidth; x++) {
329 for(
int y = 0; y < destHeight; y++) {
330 int xo1 = x * srcWidth / destWidth;
332 int yo1 = y * srcHeight / destHeight;
334 int n = (xo2 - xo1) * (yo2 - yo1);
336 for(
int i = 0; i <
bpp; i++)
339 for(
int xo = xo1; xo < xo2; xo++)
340 for(
int yo = yo1; yo < yo2; yo++) {
342 for(
int i = 0; i <
bpp; i++)
348 for(
int i = 0; i <
bpp; i++)
404 MSG(
"FltkImgbuf::getScaledBuf: cannot handle large width %d\n",
width);
408 MSG(
"FltkImgbuf::getScaledBuf: cannot handle large height %d\n",
height);
412 if (
width == this->width &&
height == this->height) {
417 for (Iterator <FltkImgbuf> it =
scaledBuffers->iterator(); it.hasNext(); ) {
429 MSG(
"FltkImgbuf::getScaledBuf: suspicious image size request %d x %d\n",
453 _MSG(
"::getRowArea: area x=%d y=%d width=%d height=%d\n",
467 _MSG(
"::getRowArea: area x=%d y=%d width=%d height=%d\n",
489 int xSrc,
int ySrc,
int widthSrc,
int heightSrc)
492 assert (
bpp == fDest->
bpp);
502 for (
int x = xSrc; x < xSrc2; x++)
503 for (
int y = ySrc; y < ySrc2; y++) {
504 int iSrc = x +
width * y;
505 int iDest = xDestRoot + x + fDest->
width * (yDestRoot + y);
509 for (
int b = 0; b <
bpp; b++)
540 _MSG(
"FltkImgbuf[root %p]: not deleted. numScaled=%d\n",
571 assert (
root != NULL);
577 assert (
root != NULL);
587 int x,
int y,
int width,
int height)
592 _MSG(
"::draw: xRoot=%d x=%d yRoot=%d y=%d width=%d height=%d\n"
593 " this->width=%d this->height=%d\n",
594 xRoot, x, yRoot, y,
width,
height, this->width, this->height);
596 if (x > this->width || y > this->height) {
600 if (x +
width > this->width) {
601 width = this->width - x;
604 if (y +
height > this->height) {
605 height = this->height - y;
608 fl_draw_image(
rawdata+
bpp*(y*this->width + x), xRoot + x, yRoot + y,
width,
The platform independent interface for image buffers.
dw::core::Shape implemtation for simple rectangles.
void setCMap(int *colors, int num_colors)
void getRowArea(int row, dw::core::Rectangle *area)
FltkImgbuf(Type type, int width, int height, double gamma, FltkImgbuf *root)
void draw(Fl_Widget *target, int xRoot, int yRoot, int x, int y, int width, int height)
void copyTo(Imgbuf *dest, int xDestRoot, int yDestRoot, int xSrc, int ySrc, int widthSrc, int heightSrc)
static uchar * findGammaCorrectionTable(double gamma)
static bool excessiveImageDimensions(int width, int height)
void copyRow(int row, const core::byte *data)
void setDeleteOnUnref(bool deleteOnUnref)
static void scaleBuffer(const core::byte *src, int srcWidth, int srcHeight, core::byte *dest, int destWidth, int destHeight, int bpp, double gamma)
General method to scale an image buffer.
void scaleRow(int row, const core::byte *data)
core::Imgbuf * createSimilarBuf(int width, int height)
Creates an image buffer with same parameters (type, gamma etc.) except size.
core::Imgbuf * getScaledBuf(int width, int height)
static lout::container::typed::Vector< GammaCorrectionTable > * gammaCorrectionTables
void detachScaledBuf(FltkImgbuf *scaledBuf)
This method is called for the root buffer, when a scaled buffer removed.
lout::container::typed::List< FltkImgbuf > * scaledBuffers
void scaleRowBeautiful(int row, const core::byte *data)
int backscaledY(int yScaled)
void scaleRowSimple(int row, const core::byte *data)
lout::misc::BitSet * copiedRows
void init(Type type, int width, int height, double gamma, FltkImgbuf *root)
Typed version of container::untyped::Iterator.
A bit set, which automatically reallocates when needed.
void intoStringBuffer(misc::StringBuffer *sb)
void set(int i, bool val)
A class for fast concatenation of a large number of strings.
const char * getChars()
Return a NUL-terminated strings containing all appended strings.
#define DBG_OBJ_CREATE(klass)
#define DBG_OBJ_SET_SYM(var, val)
#define DBG_OBJ_SET_NUM(var, val)
#define DBG_OBJ_ASSOC_CHILD(child)
enum dw::fltk::ScaleMode scaleMode
Dw is in this namespace, or sub namespaces of this one.
This namespace provides thin wrappers, implemented as C++ templates, to gain type-safety.