Hue Shift (like photoshop) Effect

Blitz3D Forums/Blitz3D Programming/Hue Shift (like photoshop) Effect

Graphics3D 640,480,0,2

pivot = CreatePivot()
cam = CreateCamera(pivot)
PositionEntity cam,0,0,30
PointEntity cam,pivot

Type col
	Field image
	Field red
	Field green
	Field blue
	Field state
End Type

Function makecol(file$,red,green,blue,state)
	c.col = New col
	c\image = LoadSprite(file)
	ScaleSprite c\image,20,20
	EntityFX c\image,1
	EntityBlend c\image,3

	c\red = red
	c\green = green
	c\blue = blue
	c\state = state
	
	EntityColor c\image,c\red,c\green,c\blue
	
End Function


makecol("red.jpg",255,0,0,1)
makecol("green.jpg",0,255,0,3)
makecol("blue.jpg",0,0,255,5)

speed = 1;10

RenderWorld()
WaitKey()

While Not KeyHit(1)

	For c.col= Each col
	
		Select c\state
		
			Case 1
			c\green = c\green+speed
			If c\green=255 Then c\state = 2
			
			Case 2
			c\red = c\red-speed
			If c\red = 0  Then c\state = 3
			
			Case 3
			c\blue = c\blue+speed
			If c\blue = 255 Then c\state = 4
			
			Case 4
			c\green = c\green-speed
			If c\green = 0 Then c\state = 5	
			
			Case 5
			c\red = c\red+speed
			If c\red = 255 Then c\state = 6				

			Case 6
			c\blue = c\blue -speed
			If c\blue = 0 Then c\state = 1	
				
		
		End Select	
	
		EntityColor c\image,c\red,c\green,c\blue
	
		If c\red < 0 Then c\red = 0
		If c\green < 0 Then c\green = 0
		If c\blue < 0 Then c\blue = 0
	
	
	Next

RenderWorld()

c.col = First col

Text 0,0,c\red
Text 0,14,c\green
Text 0,28,c\blue

Text 0,50,c\red+c\green+c\blue

Flip

Wend


I noticed you're still going up to 260 on your color channels, so I modified your code to not only make sure it doesn't go over 255, but so that it goes slower so you can see what's going on, and so it displays the original image and waits for you to hit a key before starting so you can get a better idea of where the bright spots are occuring.

And it looks like the bright spots are occuring where your secondary colors, magenta, yellow, and cyan are, which is not surprising.

Hm...

Well, I know what's happening, but I don't know how to solve it.

Let's say the color you're looking at in the image is yellow. You get yellow where both the red and green images are white.

Now you start sliding the hue. The red layer starts becoming yellow, the green layer starts becoming cyan, and the blue layer starts becoming magenta.

Yellow and cyan together contain all three primary colors, so you end up with white wherever your original image had both red and greem or green and blue, or blue and red.