Fix for issue #427: Problems with data_w, data_h, w, h of Fl_Image.

This commit is contained in:
ManoloFLTK 2022-04-12 15:06:21 +02:00
parent fad867a5d3
commit bfae813c4e
4 changed files with 32 additions and 31 deletions

View File

@ -1,7 +1,7 @@
//
// Image header file for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2017 by Bill Spitzak and others.
// Copyright 1998-2022 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -247,7 +247,7 @@ public:
\see Fl_Image::release()
\see Fl_Image::copy(int w, int h)
*/
Fl_Image *copy() { Fl_Image *img = copy(data_w(), data_h()); img->scale(w(), h(), 0, 1); return img;}
Fl_Image *copy() { Fl_Image *img = copy(w(), h()); img->scale(w(), h(), 0, 1); return img;}
virtual void color_average(Fl_Color c, float i);
/**
The inactive() method calls

View File

@ -1,7 +1,7 @@
//
// Bitmap drawing routines for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2016 by Bill Spitzak and others.
// Copyright 1998-2022 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -60,13 +60,13 @@ Fl_Image *Fl_Bitmap::copy(int W, int H) {
uchar *new_array; // New array for image data
// Optimize the simple copy where the width and height are the same...
if (W == data_w() && H == data_h()) {
new_array = new uchar [H * ((W + 7) / 8)];
memcpy(new_array, array, H * ((W + 7) / 8));
if (W == w() && H == h()) {
new_array = new uchar [data_h() * ((data_w() + 7) / 8)];
memcpy(new_array, array, data_h() * ((data_w() + 7) / 8));
new_image = new Fl_Bitmap(new_array, W, H);
new_image = new Fl_Bitmap(new_array, data_w(), data_h());
new_image->alloc_array = 1;
new_image->scale(w(), h(), 0, 1);
return new_image;
}
if (W <= 0 || H <= 0) return 0;

View File

@ -1,7 +1,7 @@
//
// Image drawing code for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2017 by Bill Spitzak and others.
// Copyright 1998-2022 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -407,7 +407,7 @@ Fl_Image *Fl_RGB_Image::copy(int W, int H) {
// Optimize the simple copy where the width and height are the same,
// or when we are copying an empty image...
if ((W == data_w() && H == data_h()) ||
if ((W == w() && H == h()) ||
!w() || !h() || !d() || !array) {
if (array) {
// Make a copy of the image data and return a new Fl_RGB_Image...
@ -415,7 +415,7 @@ Fl_Image *Fl_RGB_Image::copy(int W, int H) {
if (ld() && ld()!=data_w()*d()) {
const uchar *src = array;
uchar *dst = new_array;
int dy, dh = h(), wd = data_w()*d(), wld = ld();
int dy, dh = data_h(), wd = data_w()*d(), wld = ld();
for (dy=0; dy<dh; dy++) {
memcpy(dst, src, wd);
src += wld;
@ -426,11 +426,11 @@ Fl_Image *Fl_RGB_Image::copy(int W, int H) {
}
new_image = new Fl_RGB_Image(new_array, data_w(), data_h(), d());
new_image->alloc_array = 1;
return new_image;
} else {
return new Fl_RGB_Image(array, data_w(), data_h(), d(), ld());
new_image = new Fl_RGB_Image(array, data_w(), data_h(), d(), ld());
}
new_image->scale(w(), h(), 0, 1);
return new_image;
}
if (W <= 0 || H <= 0) return 0;
@ -560,7 +560,7 @@ void Fl_RGB_Image::color_average(Fl_Color c, float i) {
uchar *new_array,
*new_ptr;
if (!alloc_array) new_array = new uchar[h() * w() * d()];
if (!alloc_array) new_array = new uchar[data_h() * data_w() * d()];
else new_array = (uchar *)array;
// Get the color to blend with...
@ -579,19 +579,19 @@ void Fl_RGB_Image::color_average(Fl_Color c, float i) {
// Update the image data to do the blend...
const uchar *old_ptr;
int x, y;
int line_i = ld() ? ld() - (w()*d()) : 0; // increment from line end to beginning of next line
int line_i = ld() ? ld() - (data_w()*d()) : 0; // increment from line end to beginning of next line
if (d() < 3) {
ig = (r * 31 + g * 61 + b * 8) / 100 * (256 - ia);
for (new_ptr = new_array, old_ptr = array, y = 0; y < h(); y ++, old_ptr += line_i)
for (x = 0; x < w(); x ++) {
for (new_ptr = new_array, old_ptr = array, y = 0; y < data_h(); y ++, old_ptr += line_i)
for (x = 0; x < data_w(); x ++) {
*new_ptr++ = (*old_ptr++ * ia + ig) >> 8;
if (d() > 1) *new_ptr++ = *old_ptr++;
}
} else {
for (new_ptr = new_array, old_ptr = array, y = 0; y < h(); y ++, old_ptr += line_i)
for (x = 0; x < w(); x ++) {
for (new_ptr = new_array, old_ptr = array, y = 0; y < data_h(); y ++, old_ptr += line_i)
for (x = 0; x < data_w(); x ++) {
*new_ptr++ = (*old_ptr++ * ia + ir) >> 8;
*new_ptr++ = (*old_ptr++ * ia + ig) >> 8;
*new_ptr++ = (*old_ptr++ * ia + ib) >> 8;
@ -624,15 +624,15 @@ void Fl_RGB_Image::desaturate() {
int new_d;
new_d = d() - 2;
new_array = new uchar[h() * w() * new_d];
new_array = new uchar[data_h() * data_w() * new_d];
// Copy the image data, converting to grayscale...
const uchar *old_ptr;
int x, y;
int line_i = ld() ? ld() - (w()*d()) : 0; // increment from line end to beginning of next line
int line_i = ld() ? ld() - (data_w()*d()) : 0; // increment from line end to beginning of next line
for (new_ptr = new_array, old_ptr = array, y = 0; y < h(); y ++, old_ptr += line_i)
for (x = 0; x < w(); x ++, old_ptr += d()) {
for (new_ptr = new_array, old_ptr = array, y = 0; y < data_h(); y ++, old_ptr += line_i)
for (x = 0; x < data_w(); x ++, old_ptr += d()) {
*new_ptr++ = (uchar)((31 * old_ptr[0] + 61 * old_ptr[1] + 8 * old_ptr[2]) / 100);
if (d() > 3) *new_ptr++ = old_ptr[3];
}

View File

@ -1,7 +1,7 @@
//
// Pixmap drawing code for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2018 by Bill Spitzak and others.
// Copyright 1998-2022 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -88,11 +88,11 @@ void Fl_Pixmap::copy_data() {
// Figure out how many colors there are, and how big they are...
sscanf(data()[0],"%*d%*d%d%d", &ncolors, &chars_per_pixel);
chars_per_line = chars_per_pixel * w() + 1;
chars_per_line = chars_per_pixel * data_w() + 1;
// Allocate memory for the new array...
if (ncolors < 0) new_data = new char *[h() + 2];
else new_data = new char *[h() + ncolors + 1];
if (ncolors < 0) new_data = new char *[data_h() + 2];
else new_data = new char *[data_h() + ncolors + 1];
new_data[0] = new char[strlen(data()[0]) + 1];
strcpy(new_data[0], data()[0]);
@ -115,13 +115,13 @@ void Fl_Pixmap::copy_data() {
}
// Copy image data...
for (i = 0; i < h(); i ++, new_row ++) {
for (i = 0; i < data_h(); i ++, new_row ++) {
*new_row = new char[chars_per_line];
memcpy(*new_row, data()[i + ncolors + 1], chars_per_line);
}
// Update pointers...
data((const char **)new_data, h() + ncolors + 1);
data((const char **)new_data, data_h() + ncolors + 1);
alloc_data = 1;
}
@ -131,10 +131,11 @@ Fl_Image *Fl_Pixmap::copy(int W, int H) {
return new Fl_Pixmap((char *const*)0);
}
// Optimize the simple copy where the width and height are the same...
if (W == data_w() && H == data_h()) {
if (W == w() && H == h()) {
// Make an exact copy of the image and return it...
new_image = new Fl_Pixmap(data());
new_image->copy_data();
new_image->scale(W, H, 0, 1);
return new_image;
}
if (W <= 0 || H <= 0) return 0;