Ooops
July 09, 2020, 10:32:12 AM

Author Topic: Ill-Defined Compilation Error  (Read 202 times)

Offline _PJ_

  • Jr. Member
  • **
  • Posts: 77
Ill-Defined Compilation Error
« on: June 16, 2020, 04:33:58 PM »
I extracted the relevant parts from my code, and the compilation error still appears.
The error suggests there is a "â" character although this does not appear anywhere in the code.

Commmenting out the supposedly offending line (for investigation only) simply returns another copmpilation error which seems to be referencing incorrect line.

_

I'm experienced enough to know that other issues can confuse the compiler, and that some missing brackets or improper syntax earlier may result in the warning being given at a later line etc... However, in this case, the compiler feedback is really unhelpful and I cannot identify the issue.

_____

I SUSPECT that there may be some issue related to being unable to update the field content of STRUCTs - although I am not intending to do this directly, perhaps in the calculation between these values, the struct value goes out of scope and dereferenced???

Otherwise, I'm very puzzled by this.

________

A secondary issue is that I wrote the function based on the popular linked site: www.niwa.nu > 2013/05 > math-behind-colorspace-conversions-rgb-hsl

However, there is some ambiguity concerning the operational ordering such as::
Quote
R = MagentaBalance + ( YellowBalance - MagentaBalance ) * ( 0.6666 – R ) * 6
My gut instinct would be to consider the BEMDAS (Bracket, Exponent, Mult, Divi, Add, Subtract etc.) rules...
until I get this sorted, I cannot begin to refactor how this is working.

So if anyone has an alternative, working HSL - RGB converter algorithm I'd be very grateful!

__________

Here's the sample of relevant code - I included some other functions and struct definition for completeness:
Code: [Select]
Function ConvertHSLToRGBa:Int(HSL:HSLPixel)
' Identify Yellow Balance
Local YellowBalance:Float

If (HSL.L < 0.5)
YellowBalance = HSL.L * (1.0 + HSL.S)
Else
YellowBalance = (HSL.L + HSL.S) – (HSL.L * HSL.S)
End If

' Identify Magenta Balance
Local MagentaBalance:Float = (2.0 * HSL.L ) - YellowBalance

' Identify Hue as ratio
Local HRatio:Float = HSL.H / 360.0

' Set standard RGB Values as ratios relative to Green
Local R:Float = HRatio + 0.3333
Local G:Float = HRatio
Local B:Float = HRatio - 0.3333

' Constrain the standard values
If (R > 1.0 ) Then R:-1
If (G > 1.0 ) Then G:-1
If (B > 1.0 ) Then B:-1

If (R < 0.0 ) Then R:+1
If (G < 0.0 ) Then G:+1
If (B < 0.0 ) Then B:+1

' Identify Red component as Ratio
If ((R * 6.0) < 1.0)
R = MagentaBalance + ( (YellowBalance - MagentaBalance) * 6.0 * R )
Else
If ((R * 2.0) < 1.0)
R = YellowBalance
Else
If ((R * 3.0) < 2.0)
R = MagentaBalance + ( YellowBalance - MagentaBalance ) * ( 0.6666 – R ) * 6
Else
R = MagentaBalance
End If
End If
End If

' Identify Green component as Ratio
If ((G * 6.0) < 1.0)
G = MagentaBalance + ( (YellowBalance - MagentaBalance) * 6.0 * G )
Else
If ((G * 2.0) < 1.0)
G = YellowBalance
Else
If ((G * 3.0) < 2.0)
G = MagentaBalance + ( YellowBalance - MagentaBalance ) * ( 0.6666 – G ) * 6
Else
G = MagentaBalance
End If
End If
End If

' Identify Blue component as Ratio
If ((B * 6.0) < 1.0)
B = MagentaBalance + ( (YellowBalance - MagentaBalance) * 6.0 * B )
Else
If ((B * 2.0) < 1.0)
B = YellowBalance
Else
If ((B * 3.0) < 2.0)
B = MagentaBalance + ( YellowBalance - MagentaBalance ) * ( 0.6666 – B ) * 6
Else
B = MagentaBalance
End If
End If
End If

' Concert to 8bit byte
Local Red:Byte = Int(R * 255.0) & 255
Local Green:Byte = Int(G * 255.0) & 255
Local Blue:Byte = Int(B * 255.0) & 255

' Return Int
Local RGB:Int = ComponentPixel(Red,Green,Blue)

' Remember - alpha channel is not rpreserved in HSL format!
Return RGB
End Function

Offline Derron

  • Hero Member
  • *****
  • Posts: 3034
Re: Ill-Defined Compilation Error
« Reply #1 on: June 16, 2020, 04:55:48 PM »
My color helper stuff (github.com/gwron/dig) contains hsl rgb cielab functions.


Bye
Ron

Offline _PJ_

  • Jr. Member
  • **
  • Posts: 77
Re: Ill-Defined Compilation Error
« Reply #2 on: June 16, 2020, 06:30:36 PM »
Thanks Ron,
I had a look at the base.util.color.bmx and made some slight amendments for the brackets in my code - so the math operations should be correct.

Unfortunately there's too much interdependency for me to make use of the dig framework or even just the color helper library as it is and I'm not really keen on having nested functions within methods, especially whern those functions can have more general application if exposed.

So I am continuing to try to understand why the compiler is imagining "â" charatcers, but at least you've helped me to ensure the math operations are correct!

Offline _PJ_

  • Jr. Member
  • **
  • Posts: 77
Re: Ill-Defined Compilation Error
« Reply #3 on: June 16, 2020, 06:41:45 PM »
Update:

If I replace the entire function
Code: [Select]
Function ConvertHSLToRGBa:Int(HSL:HSLPixel)
Return 0
End Function
Then it compiles okay. So at least I know the issue is DEFINITELY within this function.
But I've looked many times and cannot see the problem. (( I am extremely prone to silly obvious mistakes though! ))

I am still thinking along the lines of something to do with operations on the Struct fields - but as to what's acceptable to the compiler or why it's not working I am still none the wiser...

The documentation regarding "Struct" is (in entirety)::

Quote
Struct
Description Begin a user defined structure declaration


EndStruct
Description End a user defined structure declaration


Which does not offer particular clues in this regard.

Offline _PJ_

  • Jr. Member
  • **
  • Posts: 77
Re: Ill-Defined Compilation Error
« Reply #4 on: June 16, 2020, 06:54:06 PM »
Some arithmetical operators are not defined well for Struct fields?

The error does consistently reference the same line. It seems to relate to the * of the fields.



If I completely change
Code: [Select]

YellowBalance = (HSL.L + HSL.S) – (HSL.L * HSL.S)


Code: [Select]

Local Bugfix1:Float = HSL.L
Local Bugfix2:Float = HSL.S
Local Bugfix3:Float = Bugfix1 + Bugfix2

Local Bugfix4:Float = Bugfix1 * Bugfix2

YellowBalance = Bugfix3 – Bugfix4
I still receive the SAME ''expected expression but encountered "â" '' error
___________________________________________________________

If anyone can please help with this syntax?

Offline Brucey

  • Full Member
  • ***
  • Posts: 132
Re: Ill-Defined Compilation Error
« Reply #5 on: June 17, 2020, 02:35:17 PM »
Hallo. You have invalid subtraction/minus/hyphen (-) characters - presumably copied from some other source (website / document).

They appear as slightly longer than the correct symbol.

Offline Brucey

  • Full Member
  • ***
  • Posts: 132
Re: Ill-Defined Compilation Error
« Reply #6 on: June 17, 2020, 02:36:16 PM »
I agree that it would be nice if the error happened to point to the particular symbol in question.

Offline _PJ_

  • Jr. Member
  • **
  • Posts: 77
Re: Ill-Defined Compilation Error
« Reply #7 on: June 17, 2020, 05:07:39 PM »
Hallo. You have invalid subtraction/minus/hyphen (-) characters - presumably copied from some other source (website / document).

They appear as slightly longer than the correct symbol.

Got it!
You're right, I had copied the example text and then modified only the variable names and a little cleanup.
I replaced the offending "–" characters with "-" and it now compiles perfectly!

Thanks very much for your help. It's a great relief and I've very grateful!

Something to keep an eye out for in future!


Offline Derron

  • Hero Member
  • *****
  • Posts: 3034
Re: Ill-Defined Compilation Error
« Reply #8 on: June 17, 2020, 07:16:36 PM »
I think it pointed to that character ... somehow, but maybe not the utf8-incarnation but only the first half of it ?


bye
Ron

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal