LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 06-24-2010, 06:10 PM   #1
Kenny_Strawn
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
Blog Entries: 62

Rep: Reputation: 56
Announcement: New *CUSTOMIZABLE* GTK RGBA module


http://gnome-look.org/content/show.p...content=126653

Look at the reply entitled "Syntax".
 
Old 06-24-2010, 06:31 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Kenny_Strawn View Post
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' ?
 
Old 06-24-2010, 07:34 PM   #3
Kenny_Strawn
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
Blog Entries: 62

Rep: Reputation: 56
Quote:
Originally Posted by Sergei Steshenko View Post
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.
 
Old 06-24-2010, 07:42 PM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Kenny_Strawn View Post
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.
Old 06-24-2010, 07:52 PM   #5
Kenny_Strawn
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
Blog Entries: 62

Rep: Reputation: 56
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.
Old 06-24-2010, 07:59 PM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Kenny_Strawn View Post
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.
Old 06-24-2010, 08:07 PM   #7
Kenny_Strawn
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
Blog Entries: 62

Rep: Reputation: 56
Quote:
Originally Posted by Sergei Steshenko View Post
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.
Old 06-24-2010, 08:23 PM   #8
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Kenny_Strawn View Post
... 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.
Old 06-24-2010, 08:50 PM   #9
easuter
Member
 
Registered: Dec 2005
Location: Portugal
Distribution: Slackware64 13.0, Slackware64 13.1
Posts: 538

Rep: Reputation: 62
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.
Old 06-24-2010, 09:45 PM   #10
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
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
 
Old 06-24-2010, 10:12 PM   #11
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
[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.
 
Old 06-25-2010, 03:35 AM   #12
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
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?
 
Old 06-26-2010, 02:44 AM   #13
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Lucid update ties gtk2-module-rgba to ubuntu-desktop. Please help! Kenny_Strawn Ubuntu 1 06-24-2010 04:58 AM
RGBA in GNOME Shell Kenny_Strawn Linux - Desktop 3 06-16-2010 09:34 AM
Now hosting the new Gtk RGBA module I created on Launchpad Kenny_Strawn Programming 14 03-12-2010 07:37 PM
The 'A' in RGBA: What does it mean? Kenny_Strawn Programming 5 03-10-2010 10:43 PM
need gtk module Xris718 Linux - General 3 02-01-2006 12:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration