January 20, 2020, 07:25:37 am

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Sorting Colors

Started by billhsln, July 14, 2019, 08:43:07 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

fasecero

I can't run this file, it seems you changed the format of colors.txt. I'm getting the "Problem" messsagebox. By looking at it you have

Code Select
SUB cmpFuncDE(a:POINTER,b:POINTER),DOUBLE
qsort accept only this format for the comp func

Code Select
SUB cmpFunc(a:POINTER,b:POINTER),INT
so you must return an INT, not a DOUBLE. I'm just guessing this is the error you are getting.

One more thing, you are doing this

Code Select
SUB cmpFuncDE(a:POINTER,b:POINTER),DOUBLE
DEF temp:STRING
DEF laba,labb:CieLABtype

temp = *<string>a
laba.l = VAL(MID$(temp,112,11))
laba.a = VAL(MID$(temp,124,11))
laba.b = VAL(MID$(temp,136,11))

temp = *<string>b
labb.l = VAL(MID$(temp,112,11))
labb.a = VAL(MID$(temp,124,11))
labb.b = VAL(MID$(temp,136,11))

RETURN Ciede2000(laba,labb)
ENDSUB

since deltaE is always > 0 you are telling that the first element is always "more" than the second. You must always return a difference between 2 values to determine wich one is going first. Something like this

Code Select
DEF temp:STRING
DEF laba,labb,lref:CieLABtype

temp = *<string>a
laba.l = VAL(MID$(temp,112,11))
laba.a = VAL(MID$(temp,124,11))
laba.b = VAL(MID$(temp,136,11))

temp = *<string>b
labb.l = VAL(MID$(temp,112,11))
labb.a = VAL(MID$(temp,124,11))
labb.b = VAL(MID$(temp,136,11))

lref.l = 0
lref.a = 0
lref.b = 0

sortValuea = Ciede2000(laba,lref)
sortValueb = Ciede2000(labb,lref)

RETURN sortValueb - sortValuea

BTW I have replaced in my example CIELABColorDistance by Ciede2000 and not getting a good layout.


billhsln

You are right, I added another header line and may have moved some stuff.  Will upload all needed files as soon as I fix the problem with Qsort (which you have explained).  Now I know what I am doing wrong and will fix.

Thanks,
Bill
When all else fails, get a bigger hammer.

billhsln

July 20, 2019, 05:43:13 pm #27 Last Edit: July 20, 2019, 05:46:19 pm by billhsln
Here are all the current versions of the files and programs.

Bill

ColorsS.txt is the current format in the HSV sort order.  When I click on *All it aborts.
When all else fails, get a bigger hammer.

fasecero

Strange, If I replace

Code Select
qsort(v, count, 255, &cmpFuncDE)
with

Code Select
qsort(v, count, 255, &cmpFunc)
works fine. The problem is cmpFuncDE.. but it crash even with an empty one

Code Select
SUB cmpFuncDE(pointer a, pointer b),INT
RETURN 1
ENDSUB

no idea what's going on.

fasecero

Ah, of course... add this at the top of the file

Code Select
DECLARE CDECL cmpFuncDE(a:POINTER,b:POINTER),INT

billhsln

That made it work, however, HSV is still the best looking sort.  I am going to stick with that one and use it as a starting point and see what I can come up with what I call a base color (ignoring base and using base2).

Thanks for all the help,
Bill
When all else fails, get a bigger hammer.