QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

Convert Pixel to Alpha

This is a discussion on Convert Pixel to Alpha within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; I use graphics.h for this. I do not want to open Jasc Paint Shop Pro every time I need to ...

Reply
 
LinkBack Thread Tools
Old 05-28-2007, 05:29 PM   #1
 
pspballer07's Avatar
 
Join Date: Feb 2007
Posts: 315
Trader Feedback: 0
Default Convert Pixel to Alpha

I use graphics.h for this. I do not want to open Jasc Paint Shop Pro every time I need to make the bg of an image alpha transparent. My question is:
Is there a code I can use that will convert all the pixels of a certain color to the Alpha pixel?
pspballer07 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-28-2007, 05:35 PM   #2

Developer
 
Raphael's Avatar
 
Join Date: Jan 2006
Location: Germany
Posts: 919
Trader Feedback: 0
Default

Code:
sceGuEnable(GU_COLOR_TEST);
sceGuColorFunc(GU_NOTEQUAL,color,0xFFFFFFFF);
__________________
Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.
Raphael is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-28-2007, 05:46 PM   #3

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

In the graphics library that comes with yeldarb's tutorials, no.

You can, however use other graphic libraries to do just that. Old School Library, for example, you do this when loading the image:
Code:
oslSetTransparentColor(RGB(255,255,255));
// load image
oslDisableTransparentColor();
That makes any image loaded with any '255,255,255' / white pixels transparent when rendered.
__________________
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-28-2007, 05:57 PM   #4
 
flatmush's Avatar
 
Join Date: Mar 2007
Location: England
Posts: 87
Trader Feedback: 0
Default

Or you can just edit graphics.c to incorporate this, I did it when I first started it's pretty obvious. I would however advise against prolonged use of graphic.c as it is very slow.
I made an improved version of graphics.c on psp-programming which includes this function, but as I said it's very slow.
flatmush is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-28-2007, 06:16 PM   #5
 
pspballer07's Avatar
 
Join Date: Feb 2007
Posts: 315
Trader Feedback: 0
Default

How would I edit it?

How would the RGB be defined because I have a couple different RGB macros?
pspballer07 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-28-2007, 06:38 PM   #6
 
flatmush's Avatar
 
Join Date: Mar 2007
Location: England
Posts: 87
Trader Feedback: 0
Default

This is how I did it, keep in mind that some of the member variables of the struct are named differently to the graphics.c as I did a full edit, also Raphael's method is much better if you know how to implement it.

Code:
void imageReplaceColor(Color inReplace, Color inColor, Image* inImage) {
     int i, j;
     for(j = 0; j < inImage->imageHeight; j++) {
          for(i = 0; i < inImage->imageWidth; i++) {
               if((inImage->imageData[(j * inImage->imageTextureWidth) + i] & 0x00FFFFFF) == (inReplace & 0x00FFFFFF))
                    inImage->imageData[(j * inImage->imageTextureWidth) + i] = inColor;
          }
     }
}
flatmush is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-28-2007, 06:42 PM   #7
 
pspballer07's Avatar
 
Join Date: Feb 2007
Posts: 315
Trader Feedback: 0
Default

that is very similar to my attempt except my if check was different and didn't work, thanks
pspballer07 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-29-2007, 06:12 AM   #8

Developer
 
Raphael's Avatar
 
Join Date: Jan 2006
Location: Germany
Posts: 919
Trader Feedback: 0
Default

Quote:
Originally Posted by SG57
In the graphics library that comes with yeldarb's tutorials, no.

You can, however use other graphic libraries to do just that. Old School Library, for example, you do this when loading the image:
Code:
oslSetTransparentColor(RGB(255,255,255));
// load image
oslDisableTransparentColor();
That makes any image loaded with any '255,255,255' / white pixels transparent when rendered.
That's the same as my code, only with osl naming scheme which he doesn't use. So it's not that helpfull. Also, you CAN use color testing with graphics.c, but only together with the blitAlphaImageToScreen function.

@pspballer7: Try adding my two lines after a guStart() and before drawing an image with blitAlphaImageToScreen(). You can use the GU_COLOR() or equivalent macro to set the source color.
If you want to disable color-keying, just call sceGuDisable(GU_COLOR_TES T);
__________________
Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.
Raphael is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-29-2007, 12:39 PM   #9
 
pspballer07's Avatar
 
Join Date: Feb 2007
Posts: 315
Trader Feedback: 0
Default

one more question...what is the proper RGB macro in my case?
pspballer07 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-29-2007, 12:44 PM   #10
 
PSPJunkie_'s Avatar
 
Join Date: Dec 2006
Location: main();
Posts: 1,071
Trader Feedback: 0
Default

GU_RGBA(r, g, b, a)
__________________
YEAH!

[center][COLOR="DimGray"][SIZE="2"][FONT="Times New Roman"]Julius Parishy
[[URL="http://jparishy.com"]Homepage[/URL]][/FONT][/COLOR]

Affiliates:
[url=http://xfacter.jparishy.com/]Xfacter[/url] | [url=http://flatmush.jparishy.com/]Flatmush[/url] | [url=http://yaustar.jparishy.com/]Yaustar[/url]

[url=http://jparishy.com/wp/source-code/]Soure Code[/url]

[/center]
[/size]
PSPJunkie_ is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-29-2007, 01:15 PM   #11
 
pspballer07's Avatar
 
Join Date: Feb 2007
Posts: 315
Trader Feedback: 0
Default

What would I set alpha(a) to?
pspballer07 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-29-2007, 01:38 PM   #12
 
PSPJunkie_'s Avatar
 
Join Date: Dec 2006
Location: main();
Posts: 1,071
Trader Feedback: 0
Default

Fully visible red.
Code:
GU_RGBA(255, 0, 0, 255)
About half visible red.
Code:
GU_RGBA(255, 0, 0, 130)
__________________
YEAH!

[center][COLOR="DimGray"][SIZE="2"][FONT="Times New Roman"]Julius Parishy
[[URL="http://jparishy.com"]Homepage[/URL]][/FONT][/COLOR]

Affiliates:
[url=http://xfacter.jparishy.com/]Xfacter[/url] | [url=http://flatmush.jparishy.com/]Flatmush[/url] | [url=http://yaustar.jparishy.com/]Yaustar[/url]

[url=http://jparishy.com/wp/source-code/]Soure Code[/url]

[/center]
[/size]
PSPJunkie_ is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-29-2007, 02:45 PM   #13

Developer
 
Raphael's Avatar
 
Join Date: Jan 2006
Location: Germany
Posts: 919
Trader Feedback: 0
Default

The alpha component doesn't matter, since the color test only tests the RGB channels. So you can set it to 0 or 255.
__________________
Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.
Raphael is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-29-2007, 05:50 PM   #14
 
pspballer07's Avatar
 
Join Date: Feb 2007
Posts: 315
Trader Feedback: 0
Default

Thanks guys, it works!
pspballer07 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
alpha , convert , pixel

Thread Tools

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 08:39 PM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us