Programming This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
06-24-2010, 06:10 PM
|
#1
|
|
Senior Member
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Rep:
|
Announcement: New *CUSTOMIZABLE* GTK RGBA module
|
|
|
|
06-24-2010, 06:31 PM
|
#2
|
|
Senior Member
Registered: May 2005
Posts: 4,387
|
Quote:
Originally Posted by Kenny_Strawn
|
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' ?
|
|
|
|
06-24-2010, 07:34 PM
|
#3
|
|
Senior Member
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Original Poster
Rep:
|
Quote:
Originally Posted by Sergei Steshenko
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.
|
|
|
|
06-24-2010, 07:42 PM
|
#4
|
|
Senior Member
Registered: May 2005
Posts: 4,387
|
Quote:
Originally Posted by Kenny_Strawn
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.
|
|
|
2 members found this post helpful.
|
06-24-2010, 07:52 PM
|
#5
|
|
Senior Member
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Original Poster
Rep:
|
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.
Last edited by Kenny_Strawn; 06-24-2010 at 07:59 PM.
|
|
|
0 members found this post helpful.
|
06-24-2010, 07:59 PM
|
#6
|
|
Senior Member
Registered: May 2005
Posts: 4,387
|
Quote:
Originally Posted by Kenny_Strawn
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.
|
|
|
1 members found this post helpful.
|
06-24-2010, 08:07 PM
|
#7
|
|
Senior Member
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Original Poster
Rep:
|
Quote:
Originally Posted by Sergei Steshenko
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.
|
|
|
0 members found this post helpful.
|
06-24-2010, 08:23 PM
|
#8
|
|
Senior Member
Registered: May 2005
Posts: 4,387
|
Quote:
Originally Posted by Kenny_Strawn
... 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.
|
|
|
1 members found this post helpful.
|
06-24-2010, 08:50 PM
|
#9
|
|
Member
Registered: Dec 2005
Location: Portugal
Distribution: Slackware64 13.0, Slackware64 13.1
Posts: 536
Rep:
|
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)
Last edited by easuter; 06-24-2010 at 08:56 PM.
|
|
|
1 members found this post helpful.
|
06-24-2010, 09:45 PM
|
#10
|
|
Senior Member
Registered: Jan 2010
Posts: 1,604
|
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
|
|
|
|
|
06-24-2010, 10:12 PM
|
#11
|
|
Senior Member
Registered: Sep 2009
Location: Washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 2,136
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;}
Kinda fixed.
|
|
|
|
06-25-2010, 03:35 AM
|
#12
|
|
Senior Member
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,375
Rep: 
|
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?
|
|
|
|
06-26-2010, 02:44 AM
|
#13
|
|
Senior Member
Registered: May 2005
Posts: 4,387
|
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 07:23 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|