User Tag List

Results 1 to 4 of 4

Thread: C++ problem while adding Hue and HSL mode

  1. #1
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export ModuleUnicode Add-on
    LIJI's Avatar
    Join Date
    Jun 2006
    Location
    Israel
    Posts
    1,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    C++ problem while adding Hue and HSL mode

    I got this problem while adding Hue and HSL mode to colorizer.
    The code simply does nothing.
    From the code:
    Code:
    	if(rdPtr->mode=1) // Hue Mode
    	{
    		float H,S,L;
    		RGB2HSL(r,g,b,H,S,L);
    		HSL2RGB(H+rdPtr->h/360.0,S,L,newr,newg,newb);
    
    	}
    	if(rdPtr->mode=2) //HSL mode
    	{
    		float H,S,L;
    		RGB2HSL(r,g,b,H,S,L);
    		HSL2RGB(H+rdPtr->h/360.0,S+rdPtr->s/240.0,+rdPtr->l/240.0,newr,newg,newb);
    
    	}
    Functions I made for this code:
    Code:
    void RGB2HSL(byte r,byte g,byte b,float &h,float &s,float &l) 
    {
    	float fr,fg,fb,min,max;
    	fr=r/255.0;
    	fg=g/255.0;
    	fb=b/255.0;
    	min=max(max(fr,fg),fb);
    	max=min(min(fr,fg),fb);
    	l=(max+min)/2;
    	if(min==max)
    	{
    		s=0;
    		h=0;
    	}
    	else
    	{
    		if(l>0.5)
    			s=(max-min)/(max+min);
    		else
    			s=(max-min)/(2.0-max-min);
    	}
    	if (r==max)
    		h = (g-b)/(max-min);
    	if (g==max)
    		h = 2.0 + (b-r)/(max-min);
    	if (b==max)
    		h = 4.0 + (r-g)/(max-min);
    	h=h/6.0;
    }
    
    void HSL2RGB(float h, float s, float l,int &r, int &g, int &b)
    {
    	float temp1,temp2,tempr,tempg,tempb;
        h=((((int)(h*360))%360+360)%360)/360.0;
        s=min(max(0,s),1);
        l=min(max(0,l),1);
    	if(s==0)
    	{
    		r=(byte)l*255;
    		g=(byte)l*255;
    		b=(byte)l*255;
    	}
    	else
    	{
    		if(l<0.5)
    			temp2=l*(1.0+s);
    		else
    			temp2=l+s - l*s;
    		temp1=2.0*l - temp2;
    		        tempr = h + 1.0 / 3.0;    
            if(tempr > 1) tempr--;
            tempg = h;     
            tempb = h - 1.0 / 3.0;
            if(tempb < 0) tempb++; 
            
            //Red     
            if(tempr < 1.0 / 6.0) r = (temp1 + (temp2 - temp1) * 6.0 * tempr)*255;      
            else if(tempr < 0.5) r = (temp2)*255;   
            else if(tempr < 2.0 / 3.0) r = (temp1 + (temp2 - temp1) * ((2.0 / 3.0) - tempr) * 6.0)*255;
            else r = (temp1)*255; 
            
            //Green       
            if(tempg < 1.0 / 6.0) g = (temp1 + (temp2 - temp1) * 6.0 * tempg)*255;    
            else if(tempg < 0.5) g = temp2*255;
            else if(tempg < 2.0 / 3.0) g = (temp1 + (temp2 - temp1) * ((2.0 / 3.0) - tempg) * 6.0)*255;
            else g = (temp1*255); 
            
            //Blue    
            if(tempb < 1.0 / 6.0) b = (temp1 + (temp2 - temp1) * 6.0 * tempb)*255;   
            else if(tempb < 0.5) b = (temp2)*255; 
            else if(tempb < 2.0 / 3.0) b = (temp1 + (temp2 - temp1) * ((2.0 / 3.0) - tempb) * 6.0)*255;    
            else b = temp1*255;
    	}
     }
    Also, If I add this code for debugging, the extension crashes at runtime:
    Code:
    		char debuging[150];
    		sprintf(debuging,"H=%d S=%d L=%d",(int)H*360,(int)S*360,(int)L*360);
    		MessageBox(NULL,debuging, "Colorizer", MB_OK);
    Can anyone please help me?

  2. #2
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Jun 2006
    Posts
    6,773
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: C++ problem while adding Hue and HSL mode

    I don't have time to proof read it but --

    if(rdPtr->mode=1)
    should be ==1, and the same for 2.

    As for the debugging code, I'm not sure if those typecasts are safe and you should probably use std::string.

    And what is that code supposed to do anyway?

  3. #3
    Clickteam Clickteam

    Join Date
    Jun 2006
    Location
    France
    Posts
    14,022
    Mentioned
    279 Post(s)
    Tagged
    3 Thread(s)

    Re: C++ problem while adding Hue and HSL mode

    For the debugging code I've no idea why it crashes. Maybe try to use wsprintf instead of sprintf?

    Yves.

  4. #4
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export ModuleUnicode Add-on
    LIJI's Avatar
    Join Date
    Jun 2006
    Location
    Israel
    Posts
    1,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: C++ problem while adding Hue and HSL mode

    K, I rewrote the code and it seems to fix few things, Thanks anyway!

Similar Threads

  1. Ink effects problem in D3D8 mode
    By ASD in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 6th June 2013, 02:44 PM
  2. Problem with the Landscape mode on IOS 6
    By Diego in forum iOS Export Module Version 2.0
    Replies: 1
    Last Post: 7th December 2012, 08:37 PM
  3. Problem adding Sounds from the Bonus CD
    By jbrown2177 in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 16th August 2012, 03:19 PM
  4. Problem with Standard Display Mode?
    By King_Cool in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 13th May 2012, 12:04 AM
  5. Fullscreen Mode switching problem
    By Shawn in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 22nd December 2008, 12:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •