Jump to content

boolean color rotation


Ontosy
 Share

Recommended Posts

BitRotate not have 24 bits option

No

When you rotate 32 bits you will lose information. Perhaps what you need fior this is Actually the code is a little untidy, but it works perfectly well and was designed for this very job. You may be the first person to ever use it (or maybe not). In any case, the answer to your question is within the text description on the page linked to above (that's if I understood your question correctly).

Edited by czardas
Link to comment
Share on other sites

This example rotates the color channels of a 24 bit color.

Local $iPixelColor = PixelGetColor(300, 300)
ConsoleWrite("0x" & Hex($iPixelColor, 6) & " = " & $iPixelColor & @LF) ; Pixel color at start

Local $iColorRotate1 = ColorChannelRotate($iPixelColor)
ConsoleWrite("0x" & Hex($iColorRotate1, 6) & " = " & $iColorRotate1 & @LF); Pixel color channels rotated once.

Local $iColorRotate2 = ColorChannelRotate($iColorRotate1)
ConsoleWrite("0x" & Hex($iColorRotate2, 6) & " = " & $iColorRotate2 & @LF); Pixel color channels rotated twice.

Local $iColorRotate3 = ColorChannelRotate($iColorRotate2)
ConsoleWrite("0x" & Hex($iColorRotate3, 6) & " = " & $iColorRotate3 & @LF); Pixel color channels rotated third time, back to original color.


Func ColorChannelRotate($iColor)
    Return Number("0x" & StringRegExpReplace(Hex($iColor, 6), "(.{2})(.{2})(.{2})", "312"))
EndFunc   ;==>ColorChannelRotate
Link to comment
Share on other sites

After you posted that Malkey, I just had to test my function against your results. I'm happy to say the results are exactly the same. :)

Local $iPixelColor = PixelGetColor(300, 300)

For $i = 0 To -24 Step -8
    ConsoleWrite(_bitModalSpin($iPixelColor, $i, 24) & @LF)
Next

Func _bitModalSpin($iVal, $iShift, $iLoopSize)
    If (Not IsInt($iVal)) Or ($iVal < 0 - 2^31) Or ($iVal > 2^31 -1) Then Return SetError(1, 0, 0)
    If (Not IsInt($iLoopSize)) Or $iLoopSize > 32 Or $iLoopSize < 0 Then Return SetError(2, 0, 0)
    If Not IsInt($iShift) Then Return SetError(3, 0, 0)

    If $iLoopSize < 2 Then Return $iVal
    $iShift = Mod($iShift, $iLoopSize)
    If $iShift = 0 Then Return $iVal
    If $iLoopSize = 32 Then Return BitRotate($iVal, $iShift, "D") ; Spin all 32 bits

    If $iShift > 0 Then $iShift = $iShift - $iLoopSize

    Local $dLeft, $dLoop, $dRight, $dMid
    $dLeft = BitShift( BitShift($iVal, $iLoopSize), -$iLoopSize)
    $dLoop = BitXOR($dLeft, $iVal)
    $dRight = BitShift($dLoop, -$iShift)
    $dMid = BitShift( BitXOR( BitShift($dRight, $iShift), $dLoop), -$iShift -$iLoopSize)
    Return BitOR($dLeft, $dMid, $dRight)
EndFunc
Edited by czardas
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...