Jump to content

I'm using codelab and need help...


Recommended Posts

This is my script:

#region UICode

byte Amount1=0; //[0,100]Slider 1 Description

byte Amount2=0; //[0,100]Slider 2 Description

byte Amount3=0; //[0,100]Slider 3 Description

#endregion

void Render(Surface dst, Surface src, Rectangle rect)

{

// Delete any of these lines you don't need

Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();

long CenterX = (long)(((selection.Right - selection.Left) / 2)+selection.Left);

long CenterY = (long)(((selection.Bottom - selection.Top) / 2)+selection.Top);

ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;

ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;

int BrushWidth = (int)EnvironmentParameters.BrushWidth;

ColorBgra CurrentPixel;

for (int y = rect.Top; y < rect.Bottom; y++)

{

for (int x = rect.Left; x < rect.Right; x++)

{

CurrentPixel = src[x,y];

// TODO: Add pixel processing code here

// Access RGBA values this way, for example:

CurrentPixel.R = (byte)Amount1;

CurrentPixel.G = (byte)Amount2;

CurrentPixel.B = (byte)Amount3;

CurrentPixel.A = (byte)PrimaryColor.A;

dst[x,y] = CurrentPixel;

}

}

}

I keep getting a error saying it can't change an int into a byte, but It shouldn't have to.. I need help!

Link to comment
Share on other sites

#region UICode

byte Amount1=0; //[0,100]Slider 1 Description

byte Amount2=0; //[0,100]Slider 2 Description

byte Amount3=0; //[0,100]Slider 3 Description

#endregion

void Render(Surface dst, Surface src, Rectangle rect)

{

// Delete any of these lines you don't need

Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();

long CenterX = (long)(((selection.Right - selection.Left) / 2)+selection.Left);

long CenterY = (long)(((selection.Bottom - selection.Top) / 2)+selection.Top);

ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;

ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;

int BrushWidth = (int)EnvironmentParameters.BrushWidth;

ColorBgra CurrentPixel;

for (int y = rect.Top; y < rect.Bottom; y++)

{

for (int x = rect.Left; x < rect.Right; x++)

{

CurrentPixel = src[x,y];

// TODO: Add pixel processing code here

// Access RGBA values this way, for example:

CurrentPixel.R = Amount1;

CurrentPixel.G = Amount2;

CurrentPixel.B = Amount3;

CurrentPixel.A = PrimaryColor.A;

dst[x,y] = CurrentPixel;

}

}

}

still giving me that same error.

Link to comment
Share on other sites

If you are using codelab, you can't just retype the variables in the UICode block and expect it to work.

I think this is what you're after:

#region UICode
int Amount1=0;	//[0,255]Slider 1 Description
int Amount2=0;	//[0,255]Slider 2 Description
int Amount3=0;	//[0,255]Slider 3 Description
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
   ColorBgra CurrentPixel;
   for (int y = rect.Top; y     {
       for (int x = rect.Left; x         {
           CurrentPixel = src[x,y];
           // TODO: Add pixel processing code here
           // Access RGBA values this way, for example:
           CurrentPixel.R = (byte)Amount1;
           CurrentPixel.G = (byte)Amount2;
           CurrentPixel.B = (byte)Amount3;
           // CurrentPixel.A = (byte)PrimaryColor.A;
           dst[x,y] = CurrentPixel;
       }
   }
}

You see, CodeLab writes a bunch of code for you for the UI stuff all based on the types of variables in the UICode block. Don't edit those unless you know what you're doing. It is probably best if you stick to using CodeLab's built-in UI designer (Ctrl-I).

Link to comment
Share on other sites

Try using ints instead of bytes for the sliders.

#region UICode
int Amount1=0; //[0,100]Slider 1 Description
int Amount2=0; //[0,100]Slider 2 Description
int Amount3=0; //[0,100]Slider 3 Description
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
// Delete any of these lines you don't need
Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
long CenterX = (long)(((selection.Right - selection.Left) / 2)+selection.Left);
long CenterY = (long)(((selection.Bottom - selection.Top) / 2)+selection.Top);
ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;
int BrushWidth = (int)EnvironmentParameters.BrushWidth;

ColorBgra CurrentPixel;
for (int y = rect.Top; y < rect.Bottom; y++)
{
for (int x = rect.Left; x < rect.Right; x++)
{
CurrentPixel = src[x,y];
// TODO: Add pixel processing code here
// Access RGBA values this way, for example:
CurrentPixel.R = (byte)Amount1;
CurrentPixel.G = (byte)Amount2;
CurrentPixel.B = (byte)Amount3;
CurrentPixel.A = (byte)PrimaryColor.A;
dst[x,y] = CurrentPixel;
}
}
}

Edit: Beaten.

KaHuc.png
Link to comment
Share on other sites

  • 2 weeks later...

Hey guys maybe you can help me too. I'm getting the same error messages as VoidWhisper, and I've tried everything I can think of to get rid of them, no so far I've done nothing. Maybe you can help.

Here's my code:

#region UICode
int rbc = 0; // [-255,255] Red Boost/Cut
int gbc = 0; // [-255,255] Green Boost/Cut
int bbc = 0; // [-255,255] Blue Boost/Cut
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
   ColorBgra CurrentPixel;
   for (int y = rect.Top; y < rect.Bottom; y++)
   {
       for (int x = rect.Left; x < rect.Right; x++)
       {
           CurrentPixel = src[x,y];
           // TODO: Add pixel processing code here
           // Access RGBA values this way, for example:
           CurrentPixel.R = (byte)CurrentPixel.R + (byte)rbc;
           CurrentPixel.G = (byte)CurrentPixel.G + (byte)gbc;
           CurrentPixel.B = (byte)CurrentPixel.B + (byte)bbc;
           dst[x,y] = CurrentPixel;
       }
   }
}

Link to comment
Share on other sites

Stay out of the UICode block.

You can't just start editing those lines if you don't know what CodeLab is going to do with them.

The variable names MUST be Amount1, Amount2, Amount3...

Also, you're going to quickly overflow your R, G, and B values. Better to clamp them to a byte range:

#region UICode
int Amount1 = 0; // [-255,255] Red Boost/Cut
int Amount2 = 0; // [-255,255] Green Boost/Cut
int Amount3 = 0; // [-255,255] Blue Boost/Cut
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
   ColorBgra CurrentPixel;
   for (int y = rect.Top; y     {
       for (int x = rect.Left; x         {
           CurrentPixel = src[x,y];
           // TODO: Add pixel processing code here
           // Access RGBA values this way, for example:
           CurrentPixel.R = Utility.ClampToByte(CurrentPixel.R + Amount1);
           CurrentPixel.G = Utility.ClampToByte(CurrentPixel.G + Amount2);
           CurrentPixel.B = Utility.ClampToByte(CurrentPixel.B + Amount3);
           dst[x,y] = CurrentPixel;
       }
   }
}

There! That should work.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...