ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#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' ?
#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:
#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.
Last edited by Kenny_Strawn; 06-24-2010 at 07:59 PM.
#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.
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.
... 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.
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)
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339
Rep:
[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;}
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?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.