Jump to content

How do you make a plugin?


Recommended Posts

You're right, except for the "selecting pixel".

ColorBgra CurrentPixel;

simply creates a pixel.

Nearly right, but not quite :wink:. The line sets up a variable called CurrentPixel.

ColorBgra defines the type of variable that we are setting up, CurrentPixel is the name of that variable. Later when we use CurrentPixel in our code we know that it has been setup as a variable which holds color data [ColorBgra = ColorB(lue)g(reen)r(ed)a(lpha)].

In the original code see how ColorBgra is used to define the same variable type when we set the two variables PrimaryColor and SecondaryColor to the currently selected Primary and Secondary colors?

Link to comment
Share on other sites

:? when I said this:

ColorBgra CurrentPixel; selecting the pixel, using C if im not mistaken

I meant this whole part

ColorBgra CurrentPixel; selecting the pixel, using C if im not mistaken

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

{

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

{

CurrentPixel = src[x,y];

if ((y == CenterY) && (x == CenterX))

{

I think im still wrong, but just wanted to clarify that. Im hoping we learn this kind of stuff next year in Grade 10 (or at least something applicable)

Link to comment
Share on other sites

:? when I said this:

ColorBgra CurrentPixel; selecting the pixel, using C if im not mistaken

I meant this whole part

ColorBgra CurrentPixel; selecting the pixel, using C if im not mistaken

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

{

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

{

CurrentPixel = src[x,y];

if ((y == CenterY) && (x == CenterX))

{

I think im still wrong, but just wanted to clarify that. Im hoping we learn this kind of stuff next year in Grade 10 (or at least something applicable)

Link to comment
Share on other sites

EER >> Yeah, I said it wrong, but I know what you said :)

Ndshacker >> No.

CurrentPixel is just a name, your variable name can be "StupidPixel", or "hahahaha", or whatever you want.

The first for() creates an variable named X (it's an int, or Int32, which mean an integer number in 32 bits) and do something (here it is the second for () ) while X is smaller than the current image's height.

The second creates an Y variable (an int too) and do something (your code) while Y is smaller than the current image's width.

Then it "fills" the variable CurrentPixel with the color values of the pixel in the X and Y location (now CurrentPixel contains the values of the current pixel)

Link to comment
Share on other sites

EER >> Yeah, I said it wrong, but I know what you said :)

Ndshacker >> No.

CurrentPixel is just a name, your variable name can be "StupidPixel", or "hahahaha", or whatever you want.

The first for() creates an variable named X (it's an int, or Int32, which mean an integer number in 32 bits) and do something (here it is the second for () ) while X is smaller than the current image's height.

The second creates an Y variable (an int too) and do something (your code) while Y is smaller than the current image's width.

Then it "fills" the variable CurrentPixel with the color values of the pixel in the X and Y location (now CurrentPixel contains the values of the current pixel)

Link to comment
Share on other sites

So much discussion about what "int x = rect.Left" does lol

Well let's try to say exactly what it does..

It tells the C# compiler to emit:

A slot for a local variable of the type "int32" in the .locals init part of the function

ldloca.s rectangle //where "rectangle" refers to a local variable slot index at which the current rois is stored

call instance int32 [system.Drawing]System.Drawing.Rectangle::get_Left() //call the get part of the Left property

stloc.s num8 //where num8 refers to the local variable slot index for the variable x

Then what the JIT compiler (or NGEN) does with this is probably along the lines of:

During the register allocation phase, find that the variable x is:

case 1: important - it will be held in a register (and might still get some stack space allocated for it, but maybe not?)

case 2: not so important - it will get a place on the stack (will add 4 to the stack reservation value, possibly affecting alignment so might cause up to 12 extra bytes to be allocated on 64bit)

The 64bit JIT will probably give different results than the 32bit JIT since it has more available registers and 64bit calling conventions are very different (fastcall by default). NGEN will give different results also, and 64bit NGEN yet other results.

The get_Left() code is likely to be inlined since it's body is small, thus turning x=rect.Left into something like mov x,rect.x if x is in a register, rect.x refers to a place on the stack. Or 2 mov's if x is not in a register (first into a temporary register). But who knows? I can't test this.

So. "int x = rect.Left" turned into something quite .. different.

note: I don't guarantee I made no mistakes. Please correct me - I like to learn :)

I would write plugins, if I knew what kind of plugins were needed.. :(

Link to comment
Share on other sites

I meant this whole part
ColorBgra CurrentPixel; selecting the pixel, using C if im not mistaken

for(int y = rect.Top; y

{

for (int x = rect.Left; x

{

CurrentPixel = src[x,y];

if ((y == CenterY) && (x == CenterX))

{

I think im still wrong, but just wanted to clarify that. Im hoping we learn this kind of stuff next year in Grade 10 (or at least something applicable)

Nope, you're pretty well right there.

This (and the few lines after) generate two nested loops (like for...next loops).

The outer loop cycles y through each line of image data from rect(rectangle).Top to rect.Bottom.

The inner loop cycles x through the rect.Left to rect.Right locations.

At each ineration of the inner loop, CurrentPixel is set to the value of the source image data from the location [x,y] (think of this as a cartesian coordinate system counting from top left of your screen). SRC = source = your current selection

Next, the comparison to screen centre is made: if ((y == CenterY) && (x == CenterX)). == reads IS EQUAL TO while && reads AND (actually the second comparison is only made if the first comparison is TRUE).

If the values of x & y are at the screen centre, we plug the values found in the PrimaryColor variable into CurrentPixel variable.

Lastly the Destination canvas (dst) at the current location [x,y] is set to the value of CurrentPixel.

In summary: We cycle through all the pixels in the current selection, looking for one that is at the screen centre. If found we set that to the Primary Color. That's it. :wink:

I don't know a whole lot about C#, but there seems to be some redundant code in this example, so best not to take it as an example of "best practice".

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...