Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discrepancy between Windows and Linux when setting RGB scaling #742

Closed
MoAlyousef opened this issue Jul 4, 2023 · 2 comments
Closed

Discrepancy between Windows and Linux when setting RGB scaling #742

MoAlyousef opened this issue Jul 4, 2023 · 2 comments

Comments

@MoAlyousef
Copy link
Contributor

Describe the bug
Setting an RGB scaling algorithm doesn't seem to work on windows unless calling Fl_Image::copy(W, H). However on Linux it appears that isn't needed.

To Reproduce
The following program produces different results when setting the scaling to Bilinear or Nearest on Linux. However on Windows it doesn't appear to change things.
Tried with both RGB_scaling and scaling_algorithm.

#include <FL/Fl_Image.H>
#include <FL/Fl_PNG_Image.H>
#include <FL/Fl_RGB_Image.H>
#include <FL/Fl_Double_Window.H>

class MyWin: public Fl_Double_Window {
    Fl_RGB_Image *image = 0;
    public:
    MyWin(int w, int h, const char *label = 0): Fl_Double_Window(w, h, label) {}
    void set_image(Fl_RGB_Image *i) {
        image = i;
    }
    void draw() override {
        Fl_Double_Window::draw();
        if (image) {
            image->scale(w(), h(), false, true);
            image->draw(0, 0, w(), h());
        }
    }
};

int main() {
    Fl_RGB_Image::RGB_scaling(FL_RGB_SCALING_NEAREST);
    auto image = new Fl_PNG_Image("example.png");
    auto win = new MyWin(640, 480);
    win->set_image(image);
    win->fullscreen();
    win->end();
    win->show();

    return Fl::run();
}

Steps to reproduce the behavior:

  • Download the png image:
    image
  • Rename to example.png.
  • Build with current master, with images support.
  • Run the application.
  • Rebuild while changing FL_RGB_SCALING_NEAREST to FL_RGB_SCALING_BILINEAR. Also try with scaling_algorithm.

Expected behavior
The behavior on windows should mimic Linux in this case.

FLTK Version
Please complete the following information and delete non-applicable lines:

  • Version: 1.4.0
  • master branch.
  • Built from source via git clone.

FLTK Configure / Build Options

  • cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -Bbin
  • cmake --build bin

Operating System / Platform:
Please be as precise as possible, e.g. "Linux: Ubuntu 20.04"

  • OS: Windows 11
  • x86_64

Additional context
Calling Fl_Image::copy(W, H) seems to fix this issue on windows:

            auto i2 = image->copy(w(), h());
            i2->scale(w(), h(), false, true);
            i2->draw(0, 0, w(), h());
            delete i2;

But it doesn't appear to be necessary on Linux.

@ManoloFLTK
Copy link
Contributor

FLTK 1.4 contains two flags to control image resizing operations

  1. Fl_Image::RGB_scaling(Fl_RGB_Scaling) is used only when Fl_RGB_Image::copy() runs
  2. Fl_Image::scaling_algorithm(Fl_RGB_Scaling) is used only when drawing the image requires it to be scaled by FLTK. This does not occur under Windows 10. Under X11, it does not occur when the Xrender extension is available.

Therefore, if no Fl_RGB_Image::copy() operation is performed, neither of the 2 flags has any effect on image drawing,
unless FLTK was built without the Xrender option.

@MoAlyousef
Copy link
Contributor Author

Thanks for the clarification Manolo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants