[1.0.1] Linux: Matching preview not working

Bug #1220575 reported by shi.zhao
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
SikuliX
In Progress
Medium
RaiMan

Bug Description

This is a Linux only issue (java version "1.7.0_25")

Open IDE editor, click a image saved before. Click "Matching Preview", it will not work. You can got error message from console:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Color parameter outside of expected range: Alpha
at java.awt.Color.testColorValueRange(Unknown Source)
at java.awt.Color.<init>(Unknown Source)
at org.sikuli.ide.PatternSimilaritySlider.getScoreColor(PatternSimilaritySlider.java:59)
at org.sikuli.ide.PatternSimilaritySlider.paintComponent(PatternSimilaritySlider.java:37)
at javax.swing.JComponent.paint(Unknown Source)
... more

RaiMan (raimund-hocke)
description: updated
Changed in sikuli:
status: New → In Progress
importance: Undecided → Medium
assignee: nobody → RaiMan (raimund-hocke)
milestone: none → 1.1.0
summary: - Matching preview error: java.lang.IllegalArgumentException
+ [1.0.1] Linux: Matching preview not working
Revision history for this message
Luciana Moreira Sá de Souza (lso) wrote :

Hello RaiMan,

This issue is also affecting me. I did some debugging and found the origin of the problem.

In the method org.sikuli.ide.PatternSimilaritySlider.getScoreColor(double score) there is the following:

// map alpha to 20~150
  Color cMask = new Color(
      c.getRed(), c.getGreen(), c.getBlue(), 20 + (int) (score * 130));

The values passed in here for the new color are:
0, 255, 128, 258.

The 258 is the problem as the maximum allowed is 255.

In my case, the score is 1.8333333730697632. I am not entirely sure yet how the Similarity works, so I cannot really tell if this score is correct or not.

Revision history for this message
RaiMan (raimund-hocke) wrote :

@ Luciana

a score value of 1.8333333730697632 ???

How did you get that? and where?

a score value should be between 0 and 1, hence the above formula is correct if the score is correct.

Revision history for this message
Luciana Moreira Sá de Souza (lso) wrote :

Hey RaiMan,

I got this value from the debugger in eclipse. I put a breakpoint for the exception and could see the provided values when the issue occurs.

1.83 was available in the method org.sikuli.ide.PatternSimilaritySlider.getScoreColor(double score)

This value is calculated in org.sikuli.ide.PatternSimilaritySlider.paintComponent(Graphics g). In this method I have the following values for the variables:

i=22
w=38
margin=13
y1=20
y2=30

Does this help?

Revision history for this message
RaiMan (raimund-hocke) wrote :

thanks, I will check it.

Revision history for this message
Luciana Moreira Sá de Souza (lso) wrote :

Hey RainMan,

I believe I fixed one part of the problem on my machine. The score calculation was incorrect. I don't know how this can work in windows...

Here is the new code which calculates correctly a value from 0 to 1 in org.sikuli.ide.PatternSimilaritySlider.paintComponent:

     @Override
 protected void paintComponent(Graphics g) {
  int w = getWidth();
  final int margin = 13;
  final int y1 = 20, y2 = 30;
  for (int i = 0; i < w - (margin *2); i++) {
   float score = (float) i / (w - margin);
   g.setColor(getScoreColor(score));
   g.drawLine(i + margin, y1, i + margin, y2);
  }
  if (getValue() != curVal) {
   curVal = getValue();
   showValue(lblVal, curVal);
  }
  super.paintComponent(g);
 }

Only problem is that the slider is not taking over the space it should on the screen, so at first everything on the slider is squeezed. After I maximize the window, the slide shows correctly with the colors.

Revision history for this message
Luciana Moreira Sá de Souza (lso) wrote :

I fixed locally the other problem with the slider being squeezed:

org.sikuli.ide.PatternPaneScreenshot.createControls()

The GridBagConstraints were not ideal. I only tested this on Linux.

GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.fill = GridBagConstraints.BOTH;
gridBagConstraints1.gridy = 0;
pane.add(btnSimilar, gridBagConstraints1);

GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
gridBagConstraints2.fill = GridBagConstraints.BOTH;
gridBagConstraints2.weightx = 1.0;
gridBagConstraints2.gridy = 1;
pane.add(sldSimilar, gridBagConstraints2);

Could you add these fixes to 1.0.1? My team will be working with this version until you release the next version.

Revision history for this message
RaiMan (raimund-hocke) wrote :

uups, now we worked in parallel ;-)

In my opinion the problem was, that the JSlider control does not have a PreferredSize before being packed into the layout, which only seems to be a problem in Linux

So I added the following in PatternSimilaritySlider::init()

 private void init() {
     showValue(lblVal, curVal);
            setPreferredSize(new Dimension(250, 54));
 }

In the layout part of PatternPaneScreenshot I simplified the layout this way

    GridBagConstraints c = new GridBagConstraints();

    c.fill = GridBagConstraints.BOTH;
    c.gridwidth = GridBagConstraints.REMAINDER;
    pane.add(btnSimilar, c);
    pane.add(sldSimilar, c);

which makes this ugly stuff look a bit better.

So I would really appreciate, if you could test my version as well (not urgent though).

BTW: the update of the formula is correct. The problem is simply the width value returned at the beginning of paintComponent:
in your case it seems to be the sliders minimum size of 38 (left and right margin of 13 and the knob size of 12), which reveals, that the formula is wrong.
On Mac and Windows, I get a width of around 200, so the max calculated score is 187/174 = 1,07, which does not lead to the problem.

Many thanks for your efforts and contribution.

Revision history for this message
RaiMan (raimund-hocke) wrote :

Just had a look at the score formula again and I think this is the correct version:

int span = w - margin * 2;
for (int i = 0; i < span; i++) {
  float score = (float) i / span;
  g.setColor(getScoreColor(score));
  g.drawLine(margin + i, y1, margin + i, y2);
}

Revision history for this message
Luciana Moreira Sá de Souza (lso) wrote :

Works on my machine :)

From what I understand this is a fix done in the develop branch (1.1.0). Will the installer, available on Sikuli website, also have the fix?

Revision history for this message
RaiMan (raimund-hocke) wrote :

Thanks for feedback.

Currently I do not plan, to add further fixes to the 1.0.1.

In a few days I will start with weekly beta versions of 1.1

Come back, if this is not suitable for you.

BTW: are you able to produce a sikuli-ide.jar, like it is downloaded for offline install? (faq 2363)
If yes, simply put your modified version in the setup-folder/Downloads and you can use your version for setup.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.