It is currently Wed Jan 27, 2021 1:25 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Hue, luma and color mix procedures
PostPosted: Thu Jul 21, 2016 5:36 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3710
Location: Netherlands
Asm routine for hue calculation using a lookup table.
Output is an integer from 0 - 359
Code:
Procedure Hue(Color.l); Hue [0-359]
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !lea r8, [hue_lut]
  CompilerEndIf
 
  !movzx eax, byte [p.v_Color    ]  ; r
  !movzx ecx, byte [p.v_Color + 1]  ; g
  !movzx edx, byte [p.v_Color + 2]  ; b
 
  !cmp eax, ecx; r >= g
  !jc hue_l3
  !cmp ecx, edx; g >= b
  !jc hue_l0
 
  ; max = r, min = b; hue = 60*(g-b)/(r-b)
  !sub eax, edx; r-b
  !sub ecx, edx; g-b
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !mov eax, [r8 + rax * 4]
  CompilerElse
    !mov eax, [hue_lut + eax * 4]
  CompilerEndIf
  !imul eax, ecx
  !add eax, 0x008000
  !shr eax, 16
  ProcedureReturn 
   
  !hue_l0:
  !cmp eax, edx; r >= b
  !jc hue_l2
 
  ; max = r, min = g; hue = 60*(g-b)/(r-g)
  !sub eax, ecx; r-g
  !sub ecx, edx; g-b
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !mov eax, [r8 + rax * 4]
  CompilerElse
    !mov eax, [hue_lut + eax * 4]
  CompilerEndIf
  !imul eax, ecx
  !add eax, 0x008000
  !jc hue_l1
  !add eax, 0x1680000
  !hue_l1:
  !shr eax, 16
  ProcedureReturn
 
  !hue_l2:
 
  ; max = b, min = g; hue = 240+60*(r-g)/(b-g)
  !sub eax, ecx; r-g
  !sub edx, ecx; b-g
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !mov ecx, [r8 + rdx * 4]
  CompilerElse
    !mov ecx, [hue_lut + edx * 4]
  CompilerEndIf
  !imul eax, ecx
  !add eax, 0xf08000
  !shr eax, 16
  ProcedureReturn
 
  !hue_l3:
  !cmp ecx, edx; g >= b
  !jc hue_l5
  !cmp eax, edx; r >= b
  !jc hue_l4
 
  ; max = g, min = b; hue = 120+60*(b-r)/(g-b)
  !sub ecx, edx; g-b
  !sub edx, eax; b-r
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !mov eax, [r8 + rcx * 4]
  CompilerElse
    !mov eax, [hue_lut + ecx * 4]
  CompilerEndIf
  !imul eax, edx
  !add eax, 0x788000
  !shr eax, 16
  ProcedureReturn
 
  !hue_l4:
 
  ; max = g, min = r; hue = 120+60*(b-r)/(g-r)
  !sub ecx, eax; g-r
  !sub edx, eax; b-r
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !mov eax, [r8 + rcx * 4]
  CompilerElse
    !mov eax, [hue_lut + ecx * 4]
  CompilerEndIf
  !imul eax, edx
  !add eax, 0x788000
  !shr eax, 16
  ProcedureReturn
 
  !hue_l5:
 
  ; max = b, min = r; hue = 240+60*(r-g)/(b-r)
  !sub edx, eax; b-r
  !sub eax, ecx; r-g
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !mov ecx, [r8 + rdx * 4]
  CompilerElse
    !mov ecx, [hue_lut + edx * 4]
  CompilerEndIf
  !imul eax, ecx
  !add eax, 0xf08000
  !shr eax, 16
  ProcedureReturn
 
  ; hue lookup table
  !hue_lut:
  !dd 0,3932160,1966080,1310720,983040,786432,655360,561737,491520,436906,393216,357469,327680,302473,280868,262144
  !dd 245760,231303,218453,206955,196608,187245,178734,170963,163840,157286,151236,145635,140434,135591,131072,126843
  !dd 122880,119156,115651,112347,109226,106274,103477,100824,98304,95906,93622,91445,89367,87381,85481,83662
  !dd 81920,80248,78643,77101,75618,74191,72817,71493,70217,68985,67795,66646,65536,64461,63421,62415
  !dd 61440,60494,59578,58688,57825,56987,56173,55382,54613,53865,53137,52428,51738,51067,50412,49774
  !dd 49152,48545,47953,47375,46811,46260,45722,45197,44683,44181,43690,43210,42740,42281,41831,41391
  !dd 40960,40537,40124,39718,39321,38932,38550,38176,37809,37449,37095,36749,36408,36074,35746,35424
  !dd 35108,34797,34492,34192,33897,33608,33323,33043,32768,32497,32230,31968,31710,31457,31207,30961
  !dd 30720,30481,30247,30016,29789,29565,29344,29127,28912,28701,28493,28288,28086,27887,27691,27497
  !dd 27306,27118,26932,26749,26568,26390,26214,26040,25869,25700,25533,25368,25206,25045,24887,24730
  !dd 24576,24423,24272,24123,23976,23831,23687,23545,23405,23267,23130,22995,22861,22729,22598,22469
  !dd 22341,22215,22090,21967,21845,21724,21605,21487,21370,21254,21140,21027,20915,20805,20695,20587
  !dd 20480,20373,20268,20164,20062,19960,19859,19759,19660,19562,19466,19370,19275,19181,19088,18995
  !dd 18904,18814,18724,18635,18547,18460,18374,18289,18204,18120,18037,17955,17873,17792,17712,17633
  !dd 17554,17476,17398,17322,17246,17171,17096,17022,16948,16876,16804,16732,16661,16591,16521,16452
  !dd 16384,16316,16248,16181,16115,16049,15984,15919,15855,15791,15728,15665,15603,15542,15480,15420
EndProcedure



Alternative version with range scaled to [0,255] instead of [0,359]
Code:
Procedure Hue256(Color.l); Hue [0-255]
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !lea r8, [hue256_lut]
  CompilerEndIf
 
  !movzx eax, byte [p.v_Color    ]  ; r
  !movzx ecx, byte [p.v_Color + 1]  ; g
  !movzx edx, byte [p.v_Color + 2]  ; b
 
  !cmp eax, ecx; r >= g
  !jc hue256_l2
  !cmp ecx, edx; g >= b
  !jc hue256_l0
 
  ; max = r, min = b; hue = 42.67 * (g-b)/(r-b)
  !sub eax, edx; r-b
  !sub ecx, edx; g-b
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !mov eax, [r8 + rax * 4]
  CompilerElse
    !mov eax, [hue256_lut + eax * 4]
  CompilerEndIf
  !imul eax, ecx
  !add eax, 0x00800000
  !shr eax, 24
  ProcedureReturn 
   
  !hue256_l0:
  !cmp eax, edx; r >= b
  !jc hue256_l1
 
  ; max = r, min = g; hue = 42.67 * (g-b)/(r-g)
  !sub eax, ecx; r-g
  !sub ecx, edx; g-b
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !mov eax, [r8 + rax * 4]
  CompilerElse
    !mov eax, [hue256_lut + eax * 4]
  CompilerEndIf
  !imul eax, ecx
  !add eax, 0x00800000
  !shr eax, 24
  ProcedureReturn
 
  !hue256_l1:
 
  ; max = b, min = g; hue = 170.67 + 42.67 * (r-g)/(b-g)
  !sub eax, ecx; r-g
  !sub edx, ecx; b-g
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !mov ecx, [r8 + rdx * 4]
  CompilerElse
    !mov ecx, [hue256_lut + edx * 4]
  CompilerEndIf
  !imul eax, ecx
  !add eax, 0xab2aaaaa
  !shr eax, 24
  ProcedureReturn
 
  !hue256_l2:
  !cmp ecx, edx; g >= b
  !jc hue256_l4
  !cmp eax, edx; r >= b
  !jc hue256_l3
 
  ; max = g, min = b; hue = 85.33 + 42.67 * (b-r)/(g-b)
  !sub ecx, edx; g-b
  !sub edx, eax; b-r
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !mov eax, [r8 + rcx * 4]
  CompilerElse
    !mov eax, [hue256_lut + ecx * 4]
  CompilerEndIf
  !imul eax, edx
  !add eax, 0x55d55555
  !shr eax, 24
  ProcedureReturn
 
  !hue256_l3:
 
  ; max = g, min = r; hue = 85.33 + 42.67 * (b-r)/(g-r)
  !sub ecx, eax; g-r
  !sub edx, eax; b-r
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !mov eax, [r8 + rcx * 4]
  CompilerElse
    !mov eax, [hue256_lut + ecx * 4]
  CompilerEndIf
  !imul eax, edx
  !add eax, 0x55d55555
  !shr eax, 24
  ProcedureReturn
 
  !hue256_l4:
 
  ; max = b, min = r; hue = 170.67 + 42.67 * (r-g)/(b-r)
  !sub edx, eax; b-r
  !sub eax, ecx; r-g
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !mov ecx, [r8 + rdx * 4]
  CompilerElse
    !mov ecx, [hue256_lut + edx * 4]
  CompilerEndIf
  !imul eax, ecx
  !add eax, 0xab2aaaaa
  !shr eax, 24
  ProcedureReturn
 
  ; hue lookup table
  !hue256_lut:
  !dd 0x00000000,0x2aaaaaaa,0x15555555,0x0e38e38e,0x0aaaaaaa,0x08888888,0x071c71c7,0x06186186
  !dd 0x05555555,0x04bda12f,0x04444444,0x03e0f83e,0x038e38e3,0x03483483,0x030c30c3,0x02d82d82
  !dd 0x02aaaaaa,0x02828282,0x025ed097,0x023ee08f,0x02222222,0x02082082,0x01f07c1f,0x01dae607
  !dd 0x01c71c71,0x01b4e81b,0x01a41a41,0x01948b0f,0x01861861,0x0178a4c8,0x016c16c1,0x01605816
  !dd 0x01555555,0x014afd6a,0x01414141,0x01381381,0x012f684b,0x0127350b,0x011f7047,0x01181181
  !dd 0x01111111,0x010a6810,0x01041041,0x00fe03f8,0x00f83e0f,0x00f2b9d6,0x00ed7303,0x00e865ac
  !dd 0x00e38e38,0x00dee95c,0x00da740d,0x00d62b80,0x00d20d20,0x00ce168a,0x00ca4587,0x00c6980c
  !dd 0x00c30c30,0x00bfa02f,0x00bc5264,0x00b92143,0x00b60b60,0x00b30f63,0x00b02c0b,0x00ad602b
  !dd 0x00aaaaaa,0x00a80a80,0x00a57eb5,0x00a3065e,0x00a0a0a0,0x009e4cad,0x009c09c0,0x0099d722
  !dd 0x0097b425,0x0095a025,0x00939a85,0x0091a2b3,0x008fb823,0x008dda52,0x008c08c0,0x008a42f8
  !dd 0x00888888,0x0086d905,0x00853408,0x00839930,0x00820820,0x00808080,0x007f01fc,0x007d8c42
  !dd 0x007c1f07,0x007aba01,0x00795ceb,0x00780780,0x0076b981,0x007572b2,0x007432d6,0x0072f9b6
  !dd 0x0071c71c,0x00709ad4,0x006f74ae,0x006e5478,0x006d3a06,0x006c252c,0x006b15c0,0x006a0b99
  !dd 0x00690690,0x00680680,0x00670b45,0x006614bc,0x006522c3,0x0064353c,0x00634c06,0x00626703
  !dd 0x00618618,0x0060a928,0x005fd017,0x005eface,0x005e2932,0x005d5b2b,0x005c90a1,0x005bc980
  !dd 0x005b05b0,0x005a451c,0x005987b1,0x0058cd5a,0x00581605,0x0057619f,0x0056b015,0x00560158
  !dd 0x00555555,0x0054abfd,0x00540540,0x0053610e,0x0052bf5a,0x00522014,0x0051832f,0x0050e89c
  !dd 0x00505050,0x004fba3d,0x004f2656,0x004e9490,0x004e04e0,0x004d7739,0x004ceb91,0x004c61dd
  !dd 0x004bda12,0x004b5428,0x004ad012,0x004a4dc9,0x0049cd42,0x00494e75,0x0048d159,0x004855e6
  !dd 0x0047dc11,0x004763d5,0x0046ed29,0x00467804,0x00460460,0x00459235,0x0045217c,0x0044b22e
  !dd 0x00444444,0x0043d7b7,0x00436c82,0x0043029e,0x00429a04,0x004232ae,0x0041cc98,0x004167ba
  !dd 0x00410410,0x0040a193,0x00404040,0x003fe00f,0x003f80fe,0x003f2305,0x003ec621,0x003e6a4d
  !dd 0x003e0f83,0x003db5c1,0x003d5d00,0x003d053e,0x003cae75,0x003c58a2,0x003c03c0,0x003bafcb
  !dd 0x003b5cc0,0x003b0a9b,0x003ab959,0x003a68f4,0x003a196b,0x0039cab9,0x00397cdb,0x00392fcd
  !dd 0x0038e38e,0x00389818,0x00384d6a,0x00380380,0x0037ba57,0x003771ec,0x00372a3c,0x0036e345
  !dd 0x00369d03,0x00365774,0x00361296,0x0035ce65,0x00358ae0,0x00354803,0x003505cc,0x0034c439
  !dd 0x00348348,0x003442f5,0x00340340,0x0033c425,0x003385a2,0x003347b6,0x00330a5e,0x0032cd98
  !dd 0x00329161,0x003255ba,0x00321a9e,0x0031e00c,0x0031a603,0x00316c80,0x00313381,0x0030fb06
  !dd 0x0030c30c,0x00308b91,0x00305494,0x00301e12,0x002fe80b,0x002fb27d,0x002f7d67,0x002f48c6
  !dd 0x002f1499,0x002ee0de,0x002ead95,0x002e7abc,0x002e4850,0x002e1652,0x002de4c0,0x002db397
  !dd 0x002d82d8,0x002d5280,0x002d228e,0x002cf301,0x002cc3d8,0x002c9512,0x002c66ad,0x002c38a8
  !dd 0x002c0b02,0x002bddba,0x002bb0cf,0x002b843f,0x002b580a,0x002b2c2f,0x002b00ac,0x002ad580
EndProcedure



Luma with lookup table
Code:
Procedure Luma(Color.l)
  !movzx eax, byte [p.v_Color]; r
  !movzx ecx, byte [p.v_Color + 1]; g
  !movzx edx, byte [p.v_Color + 2]; b
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !lea r8, [luma_lut]
    !mov ax, [r8 + rax*2]
    !add ax, [r8 + rcx*2 + 512]
    !add ax, [r8 + rdx*2 + 1024]
    !movzx eax, byte [r8 + rax + 1536]
  CompilerElse
    !mov ax, [luma_lut + eax*2]
    !add ax, [luma_lut + ecx*2 + 512]
    !add ax, [luma_lut + edx*2 + 1024]
    !movzx eax, byte [luma_lut + eax + 1536]   
  CompilerEndIf
  ProcedureReturn
  !luma_lut:
  !dd 0x00000000,0x00010001,0x00010001,0x00020002,0x00020002,0x00030003,0x00040003,0x00040004
  !dd 0x00050005,0x00060005,0x00070006,0x00070007,0x00080008,0x000a0009,0x000b000a,0x000c000b
  !dd 0x000d000d,0x000f000e,0x0010000f,0x00120011,0x00130012,0x00150014,0x00170016,0x00190018
  !dd 0x001b001a,0x001d001c,0x001f001e,0x00210020,0x00240022,0x00260025,0x00290027,0x002b002a
  !dd 0x002e002d,0x0031002f,0x00340032,0x00370035,0x003a0038,0x003d003c,0x0041003f,0x00440042
  !dd 0x00480046,0x004b0049,0x004f004d,0x00530051,0x00570055,0x005b0059,0x005f005d,0x00640061
  !dd 0x00680066,0x006d006a,0x0071006f,0x00760074,0x007b0079,0x0080007d,0x00850083,0x008a0088
  !dd 0x0090008d,0x00950092,0x009b0098,0x00a1009e,0x00a600a4,0x00ac00a9,0x00b300af,0x00b900b6
  !dd 0x00bf00bc,0x00c600c2,0x00cc00c9,0x00d300d0,0x00da00d6,0x00e100dd,0x00e800e4,0x00ef00eb
  !dd 0x00f700f3,0x00fe00fa,0x01060102,0x010d010a,0x01150111,0x011d0119,0x01260121,0x012e012a
  !dd 0x01360132,0x013f013b,0x01480143,0x0150014c,0x01590155,0x0163015e,0x016c0167,0x01750170
  !dd 0x017f017a,0x01880184,0x0192018d,0x019c0197,0x01a601a1,0x01b101ab,0x01bb01b6,0x01c601c0
  !dd 0x01d001cb,0x01db01d6,0x01e601e1,0x01f101ec,0x01fc01f7,0x02080202,0x0213020e,0x021f0219
  !dd 0x022b0225,0x02370231,0x0243023d,0x02500249,0x025c0256,0x02690262,0x0275026f,0x0282027c
  !dd 0x02900289,0x029d0296,0x02aa02a3,0x02b802b1,0x02c502bf,0x02d302cc,0x02e102da,0x02ef02e8
  !dd 0x02fe02f7,0x030c0305,0x031b0314,0x032a0322,0x03390331,0x03480340,0x0357034f,0x0366035f
  !dd 0x00010000,0x00030002,0x00040004,0x00060005,0x00080007,0x000a0009,0x000c000b,0x000e000d
  !dd 0x0010000f,0x00130012,0x00160014,0x00190017,0x001c001b,0x0020001e,0x00240022,0x00280026
  !dd 0x002d002a,0x0031002f,0x00360034,0x003b0039,0x0041003e,0x00470044,0x004d004a,0x00530050
  !dd 0x005a0057,0x0061005d,0x00680065,0x0070006c,0x00780074,0x0080007c,0x00890084,0x0092008d
  !dd 0x009b0096,0x00a400a0,0x00ae00a9,0x00b900b3,0x00c300be,0x00ce00c9,0x00d900d4,0x00e500df
  !dd 0x00f100eb,0x00fd00f7,0x010a0104,0x01170111,0x0125011e,0x0132012b,0x01410139,0x014f0148
  !dd 0x015e0157,0x016d0166,0x017d0175,0x018d0185,0x019e0195,0x01af01a6,0x01c001b7,0x01d201c9
  !dd 0x01e401db,0x01f601ed,0x020901ff,0x021c0213,0x02300226,0x0244023a,0x0259024e,0x026e0263
  !dd 0x02830278,0x0299028e,0x02af02a4,0x02c602ba,0x02dd02d1,0x02f402e8,0x030c0300,0x03240318
  !dd 0x033d0331,0x0357034a,0x03700363,0x038a037d,0x03a50398,0x03c003b2,0x03db03ce,0x03f703e9
  !dd 0x04140406,0x04310422,0x044e043f,0x046c045d,0x048a047b,0x04a90499,0x04c804b8,0x04e804d8
  !dd 0x050804f8,0x05280518,0x05490539,0x056b055a,0x058d057c,0x05af059e,0x05d205c1,0x05f605e4
  !dd 0x061a0608,0x063e062c,0x06630651,0x06890676,0x06af069c,0x06d506c2,0x06fc06e8,0x07230710
  !dd 0x074b0737,0x07740760,0x079d0788,0x07c607b1,0x07f007db,0x081b0805,0x08460830,0x0871085b
  !dd 0x089d0887,0x08ca08b3,0x08f708e0,0x0924090e,0x0952093b,0x0981096a,0x09b00999,0x09e009c8
  !dd 0x0a1009f8,0x0a410a28,0x0a720a5a,0x0aa40a8b,0x0ad60abd,0x0b090af0,0x0b3d0b23,0x0b710b57
  !dd 0x00000000,0x00000000,0x00010000,0x00010001,0x00010001,0x00010001,0x00010001,0x00010001
  !dd 0x00020002,0x00020002,0x00020002,0x00030002,0x00030003,0x00030003,0x00040003,0x00040004
  !dd 0x00040004,0x00050005,0x00050005,0x00060006,0x00070006,0x00070007,0x00080007,0x00080008
  !dd 0x00090009,0x000a0009,0x000b000a,0x000b000b,0x000c000c,0x000d000d,0x000e000d,0x000f000e
  !dd 0x0010000f,0x00110010,0x00120011,0x00130012,0x00140013,0x00150014,0x00160015,0x00170017
  !dd 0x00180018,0x001a0019,0x001b001a,0x001c001c,0x001e001d,0x001f001e,0x00200020,0x00220021
  !dd 0x00230023,0x00250024,0x00260026,0x00280027,0x002a0029,0x002b002b,0x002d002c,0x002f002e
  !dd 0x00310030,0x00330032,0x00350034,0x00370036,0x00390038,0x003b003a,0x003d003c,0x003f003e
  !dd 0x00410040,0x00430042,0x00450044,0x00480046,0x004a0049,0x004c004b,0x004f004e,0x00510050
  !dd 0x00540052,0x00560055,0x00590058,0x005b005a,0x005e005d,0x00610060,0x00640062,0x00670065
  !dd 0x00690068,0x006c006b,0x006f006e,0x00720071,0x00750074,0x00780077,0x007c007a,0x007f007d
  !dd 0x00820080,0x00850084,0x00890087,0x008c008a,0x008f008e,0x00930091,0x00960095,0x009a0098
  !dd 0x009e009c,0x00a100a0,0x00a500a3,0x00a900a7,0x00ad00ab,0x00b100af,0x00b400b3,0x00b800b6
  !dd 0x00bd00ba,0x00c100bf,0x00c500c3,0x00c900c7,0x00cd00cb,0x00d100cf,0x00d600d4,0x00da00d8
  !dd 0x00df00dc,0x00e300e1,0x00e800e5,0x00ec00ea,0x00f100ef,0x00f600f3,0x00fa00f8,0x00ff00fd
  !dd 0x01040102,0x01090107,0x010e010b,0x01130110,0x01180116,0x011d011b,0x01220120,0x01280125
  !dd 0x02020100,0x06050403,0x09080706,0x0c0b0a0a,0x0f0e0d0d,0x1110100f,0x13131212,0x15151414
  !dd 0x17171616,0x19181817,0x1a1a1919,0x1c1b1b1b,0x1d1d1d1c,0x1f1e1e1e,0x20201f1f,0x21212120
  !dd 0x22222222,0x24232323,0x25252424,0x26262525,0x27272626,0x28282827,0x29292928,0x2a2a2a29
  !dd 0x2b2b2b2a,0x2c2c2b2b,0x2d2d2c2c,0x2e2e2d2d,0x2f2e2e2e,0x302f2f2f,0x30303030,0x31313131
  !dd 0x32323231,0x33333232,0x34333333,0x34343434,0x35353535,0x36363635,0x37373636,0x37373737
  !dd 0x38383838,0x39393938,0x3a393939,0x3a3a3a3a,0x3b3b3b3a,0x3c3b3b3b,0x3c3c3c3c,0x3d3d3d3c
  !dd 0x3e3d3d3d,0x3e3e3e3e,0x3f3f3f3e,0x403f3f3f,0x40404040,0x41414040,0x41414141,0x42424242
  !dd 0x43424242,0x43434343,0x44444343,0x44444444,0x45454544,0x45454545,0x46464646,0x47464646
  !dd 0x47474747,0x48484747,0x48484848,0x49494848,0x49494949,0x4a4a4a49,0x4a4a4a4a,0x4b4b4b4a
  !dd 0x4b4b4b4b,0x4c4c4c4b,0x4c4c4c4c,0x4d4d4d4d,0x4d4d4d4d,0x4e4e4e4e,0x4e4e4e4e,0x4f4f4f4e
  !dd 0x4f4f4f4f,0x5050504f,0x50505050,0x51515150,0x51515151,0x52525151,0x52525252,0x53535252
  !dd 0x53535353,0x54535353,0x54545454,0x54545454,0x55555555,0x55555555,0x56565655,0x56565656
  !dd 0x57575656,0x57575757,0x58575757,0x58585858,0x58585858,0x59595958,0x59595959,0x5a5a5959
  !dd 0x5a5a5a5a,0x5a5a5a5a,0x5b5b5b5b,0x5b5b5b5b,0x5c5c5b5b,0x5c5c5c5c,0x5c5c5c5c,0x5d5d5d5d
  !dd 0x5d5d5d5d,0x5e5e5d5d,0x5e5e5e5e,0x5e5e5e5e,0x5f5f5f5f,0x5f5f5f5f,0x60605f5f,0x60606060
  !dd 0x60606060,0x61616160,0x61616161,0x62616161,0x62626262,0x62626262,0x63636262,0x63636363
  !dd 0x63636363,0x64646463,0x64646464,0x64646464,0x65656565,0x65656565,0x66656565,0x66666666
  !dd 0x66666666,0x67676666,0x67676767,0x67676767,0x68686767,0x68686868,0x68686868,0x69696968
  !dd 0x69696969,0x69696969,0x6a6a6a69,0x6a6a6a6a,0x6a6a6a6a,0x6b6b6b6a,0x6b6b6b6b,0x6b6b6b6b
  !dd 0x6c6c6c6b,0x6c6c6c6c,0x6c6c6c6c,0x6d6d6d6c,0x6d6d6d6d,0x6d6d6d6d,0x6e6e6e6d,0x6e6e6e6e
  !dd 0x6e6e6e6e,0x6f6f6f6e,0x6f6f6f6f,0x6f6f6f6f,0x70706f6f,0x70707070,0x70707070,0x71717070
  !dd 0x71717171,0x71717171,0x72717171,0x72727272,0x72727272,0x72727272,0x73737373,0x73737373
  !dd 0x73737373,0x74747473,0x74747474,0x74747474,0x75757474,0x75757575,0x75757575,0x75757575
  !dd 0x76767676,0x76767676,0x76767676,0x77777776,0x77777777,0x77777777,0x78777777,0x78787878
  !dd 0x78787878,0x78787878,0x79797978,0x79797979,0x79797979,0x7a7a7979,0x7a7a7a7a,0x7a7a7a7a
  !dd 0x7a7a7a7a,0x7b7b7b7a,0x7b7b7b7b,0x7b7b7b7b,0x7c7b7b7b,0x7c7c7c7c,0x7c7c7c7c,0x7c7c7c7c
  !dd 0x7d7d7d7c,0x7d7d7d7d,0x7d7d7d7d,0x7d7d7d7d,0x7e7e7e7e,0x7e7e7e7e,0x7e7e7e7e,0x7f7f7e7e
  !dd 0x7f7f7f7f,0x7f7f7f7f,0x7f7f7f7f,0x8080807f,0x80808080,0x80808080,0x80808080,0x81818181
  !dd 0x81818181,0x81818181,0x82818181,0x82828282,0x82828282,0x82828282,0x83838282,0x83838383
  !dd 0x83838383,0x83838383,0x84848383,0x84848484,0x84848484,0x84848484,0x85858584,0x85858585
  !dd 0x85858585,0x85858585,0x86868685,0x86868686,0x86868686,0x86868686,0x87878786,0x87878787
  !dd 0x87878787,0x87878787,0x88888887,0x88888888,0x88888888,0x88888888,0x89898988,0x89898989
  !dd 0x89898989,0x89898989,0x8a8a8a89,0x8a8a8a8a,0x8a8a8a8a,0x8a8a8a8a,0x8b8b8b8a,0x8b8b8b8b
  !dd 0x8b8b8b8b,0x8b8b8b8b,0x8c8c8b8b,0x8c8c8c8c,0x8c8c8c8c,0x8c8c8c8c,0x8d8c8c8c,0x8d8d8d8d
  !dd 0x8d8d8d8d,0x8d8d8d8d,0x8d8d8d8d,0x8e8e8e8e,0x8e8e8e8e,0x8e8e8e8e,0x8e8e8e8e,0x8f8f8f8e
  !dd 0x8f8f8f8f,0x8f8f8f8f,0x8f8f8f8f,0x90908f8f,0x90909090,0x90909090,0x90909090,0x91909090
  !dd 0x91919191,0x91919191,0x91919191,0x91919191,0x92929291,0x92929292,0x92929292,0x92929292
  !dd 0x93939292,0x93939393,0x93939393,0x93939393,0x93939393,0x94949494,0x94949494,0x94949494
  !dd 0x94949494,0x95959494,0x95959595,0x95959595,0x95959595,0x95959595,0x96969696,0x96969696
  !dd 0x96969696,0x96969696,0x97969696,0x97979797,0x97979797,0x97979797,0x97979797,0x98989897
  !d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a,0xaaaaaaaa,0xaaaaaaaa,0xabababaa,0xabababab
  !dd 0xabababab,0xabababab,0xabababab,0xacababab,0xacacacac,0xacacacac,0xacacacac,0xacacacac
  !dd 0xacacacac,0xadadadac,0xadadadad,0xadadadad,0xadadadad,0xadadadad,0xaeadadad,0xaeaeaeae
  !dd 0xaeaeaeae,0xaeaeaeae,0xaeaeaeae,0xaeaeaeae,0xafafafae,0xafafafaf,0xafafafaf,0xafafafaf
  !dd 0xafafafaf,0xb0afafaf,0xb0b0b0b0,0xb0b0b0b0,0xb0b0b0b0,0xb0b0b0b0,0xb0b0b0b0,0xb1b1b0b0
  !dd 0xb1b1b1b1,0xb1b1b1b1,0xb1b1b1b1,0xb1b1b1b1,0xb1b1b1b1,0xb2b2b2b2,0xb2b2b2b2,0xb2b2b2b2
  !dd 0xb2b2b2b2,0xb2b2b2b2,0xb3b2b2b2,0xb3b3b3b3,0xb3b3b3b3,0xb3b3b3b3,0xb3b3b3b3,0xb3b3b3b3
  !dd 0xb4b4b3b3,0xb4b4b4b4,0xb4b4b4b4,0xb4b4b4b4,0xb4b4b4b4,0xb4b4b4b4,0xb5b5b5b4,0xb5b5b5b5
  !dd 0xb5b5b5b5,0xb5b5b5b5,0xb5b5b5b5,0xb5b5b5b5,0xb6b6b6b6,0xb6b6b6b6,0xb6b6b6b6,0xb6b6b6b6
  !dd 0xb6b6b6b6,0xb6b6b6b6,0xb7b7b7b7,0xb7b7b7b7,0xb7b7b7b7,0xb7b7b7b7,0xb7b7b7b7,0xb8b7b7b7
  !dd 0xb8b8b8b8,0xb8b8b8b8,0xb8b8b8b8,0xb8b8b8b8,0xb8b8b8b8,0xb9b8b8b8,0xb9b9b9b9,0xb9b9b9b9
  !dd 0xb9b9b9b9,0xb9b9b9b9,0xb9b9b9b9,0xbab9b9b9,0xbabababa,0xbabababa,0xbabababa,0xbabababa
  !dd 0xbabababa,0xbbbababa,0xbbbbbbbb,0xbbbbbbbb,0xbbbbbbbb,0xbbbbbbbb,0xb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e4e3e3,0xe4e4e4e4
  !dd 0xe4e4e4e4,0xe4e4e4e4,0xe4e4e4e4,0xe4e4e4e4,0xe4e4e4e4,0xe4e4e4e4,0xe5e5e5e4,0xe5e5e5e5
  !dd 0xe5e5e5e5,0xe5e5e5e5,0xe5e5e5e5,0xe5e5e5e5,0xe5e5e5e5,0xe5e5e5e5,0xe6e6e6e5,0xe6e6e6e6
  !dd 0xe6e6e6e6,0xe6e6e6e6,0xe6e6e6e6,0xe6e6e6e6,0xe6e6e6e6,0xe6e6e6e6,0xe7e7e7e6,0xe7e7e7e7
  !dd 0xe7e7e7e7,0xe7e7e7e7,0xe7e7e7e7,0xe7e7e7e7,0xe7e7e7e7,0xe7e7e7e7,0xe8e8e8e7,0xe8e8e8e8
  !dd 0xe8e8e8e8,0xe8e8e8e8,0xe8e8e8e8,0xe8e8e8e8,0xe8e8e8e8,0xe8e8e8e8,0xe9e9e9e8,0xe9e9e9e9
  !dd 0xe9e9e9e9,0xe9e9e9e9,0xe9e9e9e9,0xe9e9e9e9,0xe9e9e9e9,0xe9e9e9e9,0xeaeae9e9,0xeaeaeaea
  !dd 0xeaeaeaea,0xeaeaeaea,0xeaeaeaea,0xeaeaeaea,0xeaeaeaea,0xeaeaeaea,0xebebeaea,0xebebebeb
  !dd 0xebebebeb,0xebebebeb,0xebebebeb,0xebebebeb,0xebebebeb,0xebebebeb,0xecebebeb,0xecececec
  !dd 0xecececec,0xecececec,0xecececec,0xecececec,0xecececec,0xecececec,0xecececec,0xedededed
  !dd 0xedededed,0xedededed,0xedededed,0xedededed,0xedededed,0xedededed,0xedededed,0xeeeeeeed
  !dd 0xeeeeeeee,0xeeeeeeee,0xeeeeeeee,0xeeeeeeee,0xeeeeeeee,0xeeeeeeee,0xeeeeeeee,0xefefeeee
  !dd 0xefefefef,0xefefefef,0xefefefef,0xefefefef,0xefefefef,0xefefefef,0xefefefef,0xefefefef
  !dd 0xf0f0f0f0,0xf0f0f0f0,0xf0f0f0f0,0xf0f0f0f0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xfafafafa,0xfbfbfbfa
  !dd 0xfbfbfbfb,0xfbfbfbfb,0xfbfbfbfb,0xfbfbfbfb,0xfbfbfbfb,0xfbfbfbfb,0xfbfbfbfb,0xfbfbfbfb
  !dd 0xfcfcfcfb,0xfcfcfcfc,0xfcfcfcfc,0xfcfcfcfc,0xfcfcfcfc,0xfcfcfcfc,0xfcfcfcfc,0xfcfcfcfc
  !dd 0xfcfcfcfc,0xfdfdfdfc,0xfdfdfdfd,0xfdfdfdfd,0xfdfdfdfd,0xfdfdfdfd,0xfdfdfdfd,0xfdfdfdfd
  !dd 0xfdfdfdfd,0xfdfdfdfd,0xfefefefd,0xfefefefe,0xfefefefe,0xfefefefe,0xfefefefe,0xfefefefe
  !dd 0xfefefefe,0xfefefefe,0xfefefefe,0xfffffffe,0xffffffff,0xffffffff,0xffffffff,0xffffffff
EndProcedure



Mix two colors
Code:
Procedure MixColors(c1, c2, mix); mix [0, 255]
  !movzx ecx, byte [p.v_mix]
  !mov eax, [p.v_c1]
  !bt ecx, 7
  !adc ecx, 0
  !jz mix_colors_l0
  !mov edx, eax
  !mov eax, [p.v_c2]
  !cmp ecx, 256
  !jz mix_colors_l0
  !and eax, 0x00ff00ff
  !imul eax, ecx
  !mov [p.v_mix], ecx
  !neg ecx
  !add ecx, 256
  !and edx, 0x00ff00ff
  !imul edx, ecx
  !lea eax, [eax + edx + 0x00800080]
  !and eax, 0xff00ff00
  !shr eax, 8
  !mov edx, [p.v_c1]
  !mov [p.v_c1], eax
  !shr edx, 8
  !and edx, 0x00ff00ff
  !imul edx, ecx
  !mov eax, [p.v_c2]
  !shr eax, 8
  !and eax, 0x00ff00ff
  !imul eax, [p.v_mix]
  !lea eax, [eax + edx + 0x00800080]
  !and eax, 0xff00ff00
  !or eax, [p.v_c1]
  !mix_colors_l0:
  ProcedureReturn
EndProcedure



Mix two colors, SSE2 version
Code:
Procedure MixColorsSSE2(c1, c2, mix); mix [0, 255]
  !movd xmm0, [p.v_c1]
  !movd xmm1, [p.v_c2]
  !movd xmm2, [p.v_mix]
  !punpcklbw xmm0, xmm0
  !punpcklbw xmm1, xmm1
  !punpcklbw xmm2, xmm2
  !pcmpeqw xmm3, xmm3
  !pshuflw xmm2, xmm2, 0
  !pxor xmm3, xmm2
  !pmulhuw xmm1, xmm2
  !pmulhuw xmm0, xmm3
  !paddw xmm0, xmm1
  !psrlw xmm0, 8
  !packuswb xmm0, xmm0
  !movd eax, xmm0
  ProcedureReturn
EndProcedure



White blend (remove alpha as if composited onto white background)
Code:
Procedure WhiteBlend(Color.l)
  !mov eax, [p.v_Color]
  !xor eax, 0x00ffffff
  !mov ecx, eax
  !mov edx, eax
  !and eax, 0x00ff00ff
  !and ecx, 0x0000ff00
  !shr edx, 24
  !bt edx, 7
  !adc edx, 0
  !imul eax, edx
  !imul ecx, edx
  !and eax, 0xff00ff00
  !and ecx, 0x00ff0000
  !or eax, ecx
  !shr eax, 8 
  !not eax
  ProcedureReturn
EndProcedure

_________________
macOS 10.15 Catalina, Windows 10


Last edited by wilbert on Mon Sep 19, 2016 12:42 pm, edited 10 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Hue calculation
PostPosted: Fri Jul 22, 2016 11:52 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon May 12, 2008 1:25 pm
Posts: 374
Location: The Netherlands
Thanks for sharing!

_________________
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!


Top
 Profile  
Reply with quote  
 Post subject: Re: Hue, luma and color mix procedures
PostPosted: Thu Jul 28, 2016 2:32 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3710
Location: Netherlands
I added a procedure MixColors(c1, c2, mix) to my first post to mix two colors based on a mixing value (0-255).
It's fast and pretty accurate :)

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: Hue, luma and color mix procedures
PostPosted: Mon Aug 01, 2016 8:42 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon May 12, 2008 1:25 pm
Posts: 374
Location: The Netherlands
wilbert wrote:
I added a procedure MixColors(c1, c2, mix) to my first post to mix two colors based on a mixing value (0-255).
It's fast and pretty accurate :)


Very valuable to me, thanks!

_________________
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye