LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Announcement: New *CUSTOMIZABLE* GTK RGBA module (http://www.linuxquestions.org/questions/programming-9/announcement-new-%2Acustomizable%2A-gtk-rgba-module-816223/)

Kenny_Strawn 06-24-2010 06:10 PM

Announcement: New *CUSTOMIZABLE* GTK RGBA module
 
http://gnome-look.org/content/show.p...content=126653

Look at the reply entitled "Syntax".

Sergei Steshenko 06-24-2010 06:31 PM

Quote:

Originally Posted by Kenny_Strawn (Post 4014104)
http://gnome-look.org/content/show.p...content=126653

Look at the reply entitled "Syntax".

Just curious regarding the code:

http://gnome-look.org/CONTENT/conten...gba-advanced.c :


Code:

#include <glib.h>
#include <glib/gtypes.h>
#include <gtk/gtk.h>

float rgba (unsigned long Red, unsigned long Green, unsigned long Blue, float Alpha) {

        /* Set margins on the color map */
        Red <= 255;
        Green <= 255;
        Blue <= 255;
       
        /* Set parameters for RGB cube */
        Red * Green * Blue;
       
        /* Set margins for Alpha value */
        Alpha <= 1;
        Alpha >= 0;
       
        /* Multiply the colors by the Alpha value */
        int aRed = Alpha*(Red);
        int aGreen = Alpha*(Green);
        int aBlue = Alpha*(Blue);
       
        /* Blend the multiplied colors into their static versions */
        int rBlend = (1 - Alpha)*(Red) + Alpha*(aRed);
        int gBlend = (1 - Alpha)*(Green) + Alpha*(aGreen);
        int bBlend = (1 - Alpha)*(Blue) + Alpha*(aBlue);

}

- the function is supposed to return a float value, since you've written 'float rgba'.

So, where is the return statement and where is the return value of 'float' type.

To me the code makes no sense. Have you tried to compile it with '-Wall -Wextra' ?

Kenny_Strawn 06-24-2010 07:34 PM

Quote:

Originally Posted by Sergei Steshenko (Post 4014120)
Just curious regarding the code:

http://gnome-look.org/CONTENT/conten...gba-advanced.c :


Code:

#include <glib.h>
#include <glib/gtypes.h>
#include <gtk/gtk.h>

float rgba (unsigned long Red, unsigned long Green, unsigned long Blue, float Alpha) {

        /* Set margins on the color map */
        Red <= 255;
        Green <= 255;
        Blue <= 255;
       
        /* Set parameters for RGB cube */
        Red * Green * Blue;
       
        /* Set margins for Alpha value */
        Alpha <= 1;
        Alpha >= 0;
       
        /* Multiply the colors by the Alpha value */
        int aRed = Alpha*(Red);
        int aGreen = Alpha*(Green);
        int aBlue = Alpha*(Blue);
       
        /* Blend the multiplied colors into their static versions */
        int rBlend = (1 - Alpha)*(Red) + Alpha*(aRed);
        int gBlend = (1 - Alpha)*(Green) + Alpha*(aGreen);
        int bBlend = (1 - Alpha)*(Blue) + Alpha*(aBlue);

}

- the function is supposed to return a float value, since you've written 'float rgba'.

So, where is the return statement and where is the return value of 'float' type.

To me the code makes no sense. Have you tried to compile it with '-Wall -Wextra' ?

I have tried compiling it the usual way, and it compiled successfully:

Code:

[kenny-strawn@ubuntu:~]$ gcc -fPIC -shared librgba-advanced.c -o librgba-advanced.so `pkg-config --cflags --libs gtk+-2.0`
There also is a precompiled binary on the gnome-look.org post to prove that it compiled successfully this way.

Sergei Steshenko 06-24-2010 07:42 PM

Quote:

Originally Posted by Kenny_Strawn (Post 4014164)
I have tried compiling it the usual way ...

Where are '-Wall -Wextra' ?

This is, for example a line from 'gtk+' compilation performed by its own Makefile:

Code:

    36 libtool: compile:  gcc -DGDK_PIXBUF_DISABLE_DEPRECATED -g -O2 -Wall -c have_mmx.S  -fPIC -DPIC -o .libs/have_mmx.o
.

You haven't answered my question:

Quote:

So, where is the return statement and where is the return value of 'float' type.
.

Your code make absolutely no sense to me. Beginning from

Code:

        Red <= 255;
        Green <= 255;
        Blue <= 255;

lines. IMO your code shows no understanding on you side of fundamental "C" issues/approaches.

Kenny_Strawn 06-24-2010 07:52 PM

Okay, minor change to the code:

Code:

#include <glib.h>
#include <glib/gtypes.h>
#include <gtk/gtk.h>

void rgba (unsigned long Red, unsigned long Green, unsigned long Blue, float Alpha) {

        /* Set margins on the color map */
        Red <= 255;
        Green <= 255;
        Blue <= 255;
       
        /* Set parameters for RGB cube */
        Red * Green * Blue;
       
        /* Set margins for Alpha value */
        Alpha <= 1;
        Alpha >= 0;
       
        /* Multiply the colors by the Alpha value */
        int aRed = Alpha*(Red);
        int aGreen = Alpha*(Green);
        int aBlue = Alpha*(Blue);
       
        /* Blend the multiplied colors into their static versions */
        int rBlend = (1 - Alpha)*(Red) + Alpha*(aRed);
        int gBlend = (1 - Alpha)*(Green) + Alpha*(aGreen);
        int bBlend = (1 - Alpha)*(Blue) + Alpha*(aBlue);

}

I used a void instead of a float for the main function, so the 'return' value is no longer needed. And the code in the function eventually defines a mathematical formula for the alpha blend. And yes, I also updated the gnome-look page.

Edit: The first values define the how high the "Red", "Green", and "Blue" values go. The next values multiply the values together to come up with the RGB cube. The values after that are limits on the Alpha value. After that, the next values multiply the color values by Alpha. And the next values then use a mathematical formula from here to do the alpha blending.

Sergei Steshenko 06-24-2010 07:59 PM

Quote:

Originally Posted by Kenny_Strawn (Post 4014182)
Okay, minor change to the code:

Code:

#include <glib.h>
#include <glib/gtypes.h>
#include <gtk/gtk.h>

void rgba (unsigned long Red, unsigned long Green, unsigned long Blue, float Alpha) {

        /* Set margins on the color map */
        Red <= 255;
        Green <= 255;
        Blue <= 255;
       
        /* Set parameters for RGB cube */
        Red * Green * Blue;
       
        /* Set margins for Alpha value */
        Alpha <= 1;
        Alpha >= 0;
       
        /* Multiply the colors by the Alpha value */
        int aRed = Alpha*(Red);
        int aGreen = Alpha*(Green);
        int aBlue = Alpha*(Blue);
       
        /* Blend the multiplied colors into their static versions */
        int rBlend = (1 - Alpha)*(Red) + Alpha*(aRed);
        int gBlend = (1 - Alpha)*(Green) + Alpha*(aGreen);
        int bBlend = (1 - Alpha)*(Blue) + Alpha*(aBlue);

}

I used a void instead of a float for the main function, so the 'return' value is no longer needed. And the code in the function eventually defines a mathematical formula for the alpha blend. And yes, I also updated the gnome-look page.

So, you continue to show complete lack of understanding of how things work in "C". Your function now after being called changes absolutely nothing in the calling context. I.e. the only effect of your function being called is wasted CPU cycles.

Your

Code:

        Red <= 255;
        Green <= 255;
        Blue <= 255;
...
        Alpha <= 1;
        Alpha >= 0;

code is still senseless - on top of senselessness of your whole void function.

Kenny_Strawn 06-24-2010 08:07 PM

Quote:

Originally Posted by Sergei Steshenko (Post 4014189)
So, you continue to show complete lack of understanding of how things work in "C". Your function now after being called changes absolutely nothing in the calling context. I.e. the only effect of your being called is wasted CPU cycles.

Your

Code:

        Red <= 255;
        Green <= 255;
        Blue <= 255;
...
        Alpha <= 1;
        Alpha >= 0;

code is still senseless - on top of senselessness of your whole void function.

IMHO, I was editing the post to explain the code when you replied. I'll say it again: The first values set limits on the height of the values of the colors. The second value multiplies the colors together to complete the RGB cube. The third values set limits on how high or how low the Alpha value can go. The fourth values multiply the colors by their Alpha values, and finally the fifth values use a mathematical formula to finally do the Alpha blending.

Sergei Steshenko 06-24-2010 08:23 PM

Quote:

Originally Posted by Kenny_Strawn (Post 4014204)
... I'll say it again: The first values set limits on the height of the values of the colors. ...

You may say whatever you want. The question is what "C" compiler thinks about it.

So, write a small 'main' program which calls your 'rgba' function, insert into your 'rgba' function 'pritntf' statements which show values of Red, Green, Blue, call your 'rgba' function with Red, Green, Blue values intentionally outside the limits and see that your code in no way limits the values - despite what you are saying.

easuter 06-24-2010 08:50 PM

Quote:

Code:


Red <= 255;
Green <= 255;
Blue <= 255;

Alpha <= 1;
Alpha >= 0;

Red * Green * Blue;


Erm...AFAIK this doesn't do anything. The values of the expressions aren't attributed to any variable, so it's "lost". I'm pretty sure that GCC won't even turn those lines into assembly...

EDIT: And without a return value all the work you've done in that function is pointless _

EDIT 2: sorry, I should probably read the thread right to the end before posting advice (already given by Sergei Steshenko)

crts 06-24-2010 09:45 PM

Hi,

can you link some documentation that supports your statement
Quote:

The first values set limits on the height of the values of the colors

smeezekitty 06-24-2010 10:12 PM

[code]
/* Set margins on the color map */
Red <= 255;
Green <= 255;
Blue <= 255;

/* Set parameters for RGB cube */
Red * Green * Blue;

/* Set margins for Alpha value */
Alpha <= 1;
Alpha >= 0;

[/quote]
W
T
F?
Code:

/* Set margins on the color map */
        if(Red > 255){Red=255;}
        if(Green > 255){Green=255;}
        if(Blue > 255){Blue=255;}
       
        /* Set parameters for RGB cube */
        Red * Green * Blue; //WTF?
       
        /* Set margins for Alpha value */
        if(Alpha > 1.0){Alpha=1.0;}
        if(Alpha < 0.0){Alpha=0.0;}

Kinda fixed.

graemef 06-25-2010 03:35 AM

We've seen this before - kind of - and you don't appear to have learnt much.

First compiling code and checking all the warnings is important see Sergei Steshenko's first post in this thread.

However, if something compiles even without any warnings then it doesn't mean that it works as you had hoped. For that you need to test it. To test it you need to have a clear idea of what output you would expect to receive given certain input.

So if I passed in the values (128, 64, 192, 0.5) to your function what should the output be?

Sergei Steshenko 06-26-2010 02:44 AM

And, FWIW, the very first lines of this particular piece of code:

Code:

#include <glib.h>
#include <glib/gtypes.h>
#include <gtk/gtk.h>

are senseless - again, for/in this piece of code.


Kenny_Strawn, the thread name: "Announcement: New *CUSTOMIZABLE* GTK RGBA module", is mostly senseless. I.e. the "Announcement: New" part makes sense; "CUSTOMIZABLE" is irrelevant - your piece of code has no customization whatsoever; "module" is senseless - it's a single senseless and useless function.

I personally consider your announcements of that 'rgba' as pure SPAM.


All times are GMT -5. The time now is 10:58 AM.