Welcome! Log In Create A New Profile

Advanced

Question about libwiisprite transparency

Posted by Arikado 
Re: Question about libwiisprite transparency
August 04, 2008 06:52AM
I prefer working with bitmap (not interlaced), I don't know a lot about programming with png interms of bitwise manipulations.
Re: Question about libwiisprite transparency
August 04, 2008 10:19PM
I just recieved the source. I'm analyzing it now. More later.

UPDATE:

Here's a piece from the letter:

Quote
chaosteils letter
If you look closely at the image.h header file, _pixels, _CreateImage etc. are protected. That means you would have to create a class called "DrawableImage : public Image" and then you could access all these protected members and actually alter image data. (pixels are RGBA tiled, just for your information)

However, if you just want to implement some clipping, please look more closely at the LayerManagers ViewWindow functions, that may also help you.

I believe the A in RGBA stands for alpha. Using that as well as the source, I'm working on writing what he recommended. I'll let everyone know how it turned out.



Edited 1 time(s). Last edit at 08/04/2008 11:27PM by Arikado.
Re: Question about libwiisprite transparency
August 05, 2008 03:07AM
A always stands for a sometimes they write is as XRGB, this means that alpha stays constant at 255 while the other colours in the colour mode are variable. I don't think it would be hard at all, I wrote a small colour key from scratch that checks only a 32 bit colour display. It moves through the red of a pixel, if it == 250 it moves to the next (green), if green == 0 then it checks the next, if it doesn't then it continues to the next pixel, if theres a match for all the red green and blue as (255,0,255), It removes that pixel from the buffer and continues to the next pixel while keeping them all in the same area, I can kinda draw it after hacking the graphics hardware a bit, although I'm more used to nVidia and ATI.
Re: Question about libwiisprite transparency
August 05, 2008 04:51AM
When I write the class I'll use inheritance so I don't have to rewrite the functions in Image.
Re: Question about libwiisprite transparency
August 05, 2008 05:10AM
When you have done the class post it here and I'll tell you if it needs anything else.
Re: Question about libwiisprite transparency
August 05, 2008 07:06PM
I'll have the header file for my new class done in about several hours. What's taking so long is finding the correct typedefs to declare each variable and function.

EDIT: Several hours? What was I thinking? I'll have the header done tomorrow for sure. Unfortunately, I can't spend all my time at the computer.



Edited 1 time(s). Last edit at 08/05/2008 11:07PM by Arikado.
Re: Question about libwiisprite transparency
August 06, 2008 10:11PM
Sorry for the double post. Here's the header:

drawableimage.h
#ifndef LIBWIISPRITE_DRAWABLEIMAGE
#define LIBWIISPRITE_DRAWABLEIMAGE
 
#include

 namespace wsp{ //The namespace used in libwiisprite

  class DrawableImage : public Image{

      public:

	DrawableImage(); //Constructor
	virtual ~DrawableImage(); //Destructor

     int GetRed(int x, int y);//Retrieve the red value of a designated pixel on the DrawableImage
     int GetGreen(int x, int y);//Retrieve the blue value of a designated pixel on the DrawableImage
     int GetBlue(int x, int y);//Retrieve the green value of a designated pixel on the DrawableImage
      u8 GetAlpha(int x, int y);//Retrieve the alpha value of a designated pixel on the DrawableImage

     void SetRed(int x, int y, int r);//Sets the red value of a designated pixel on the DrawableImage
     void SetGreen(int x, int y, int g);//Sets the blue value of a designated pixel on the DrawableImage
     void SetBlue(int x, int y, int b);//Sets the green value of a designated pixel on the DrawableImage
     void SetAlpha(int x, int y, u8 a);//Sets the alpha value of a designated pixel on the DrawableImage

     bool CheckPixel(int x, int y, int r, int g, int b, u8 a);/*Compares the designated pixel on the DrawableImage with the values given to call the function*/

     void SetPixel(int x, int y, int r, int g, int b, u8 a);//Sets the color values of the designated pixel on the DrawableImage

     void MakeTransparent(int r, int g, int b, u8 a);//Makes all pixels that match those values in the DrawableImage transparent

    private:

                u8* _pixels;
	u32 _width, _height;
	bool _initialized;
	GXTexObj _texObj;

  };
 };


 #endif

EDIT: drawableimage.cpp is almost done. I just need to locate and then insert a couple variables from the libwiisprite source.



Edited 2 time(s). Last edit at 08/07/2008 12:55AM by Arikado.
Re: Question about libwiisprite transparency
August 07, 2008 02:15AM
Seems to be coming along nicely, well done.
Re: Question about libwiisprite transparency
August 07, 2008 02:22AM
Thank you. I just got drawableimage.cpp to compile.

drawableimage.cpp

include
#include "drawableimage.h"
#include 
#include 
#include 

 namespace wsp{ //Libwiisprite namespace

  DrawableImage::DrawableImage() : _pixels(NULL), _width(0), _height(0), _initialized(false){
  }

  DrawableImage::~DrawableImage(){

    DestroyImage();
  }

  int DrawableImage::GetRed(int x, int y){
  
   int Red;

   //Red = _pixels(x, y, Red Value);
  
   return Red;
  }

  int DrawableImage::GetGreen(int x, int y){
  
   int Green;

   //Green = _pixels(x, y, Green value);
  
   return Green;
  }

  int DrawableImage::GetBlue(int x, int y){
  
   int Blue;

   //int Blue = _pixels(x, y, Blue value);
  
   return Blue;
  }

  u8 DrawableImage::GetAlpha(int x, int y){
  
   u8 Alpha;

   //u8 Alpha = _pixels(x, y, Alpha value);
  
   return Alpha;
  }

  void DrawableImage::SetRed(int x, int y, int r){

   /*_pixels(x, y, Red value) = _pixels(x, y, r);*/

  }

  void DrawableImage::SetGreen(int x, int y, int g){

  //_pixels(x, y, Green value) = _pixels(x, y, g);

  }

  void DrawableImage::SetBlue(int x, int y, int b){

   //_pixels(x, y, Blue value) = _pixels(x, y, b);

  }

  void DrawableImage::SetAlpha(int x, int y, u8 a){

   //_pixels(x, y, Alpha value) = _pixels(x, y, a);

  }

  bool DrawableImage::CheckPixel(int x, int y, int r, int g, int b, u8 a){

   if(GetRed(x, y) == r && GetGreen(x, y) == g && GetBlue(x, y) == b && GetAlpha(x, y) == a)
     return true;

    else
     return false;

  }

  void DrawableImage::SetPixel(int x, int y, int r, int g, int b, u8 a){

     SetRed(x, y, r);
     SetGreen(x, y, g);
     SetBlue(x, y, b);
     SetAlpha(x, y, a);

   }

   void DrawableImage::MakeTransparent(int r, int g, int b, u8 a){

    int height = GetHeight();
    int width = GetWidth();

     for(int y = 0; y < Height; y++){

      for(int x = 0; x < width; x++){

        if(CheckPixel(x, y, r, g, b, a))
         SetPixel(x, y, r, g, b, 0);

      }
     }
    }

   }

Clearly, it doesn't work yet. But it will. If you have any ideas on returning a specific pixel's RGBA values or changing them for that matter, please share them. That's the only thing that is holding me back.



Edited 2 time(s). Last edit at 08/07/2008 03:08PM by Arikado.
Re: Question about libwiisprite transparency
August 07, 2008 03:06AM
several of the functions here do nothing...
Re: Question about libwiisprite transparency
August 07, 2008 08:38AM
Arikado, in that for-loop, for performance, you may need to save GetHeight() and GetWidth() in a variable, because now, there is on every loop, a call to that function.
Re: Question about libwiisprite transparency
August 07, 2008 08:41AM
Yeah change it to something like


void DrawableImage::MakeTransparent(int r, int g, int b, u8 a){
height = GetHeight();
Width = GetWidth();

for(int y = 0; y < height(); y++){

for(int x = 0; x < width(); x++){

if(CheckPixel(x, y, r, g, b, a))
SetPixel(x, y, r, g, b, a);

}
}
}
Re: Question about libwiisprite transparency
August 07, 2008 08:48AM
Not heigth() and width()... must be heigth an width.
Re: Question about libwiisprite transparency
August 07, 2008 08:49AM
sorry, just copied over the words :p doesn't count the brackets.
Re: Question about libwiisprite transparency
August 07, 2008 08:52AM
Another error in the code if you do SetPixel(x,y,r,g,b,a)... you get the same color again... do SetPixel(x,y,r,g,b,0)...com i think.



Edited 1 time(s). Last edit at 08/07/2008 08:52AM by Dykam.
Re: Question about libwiisprite transparency
August 07, 2008 03:17PM
Yeah, I was just trying to get it to compile. So I had to comment out what wasn't working (those several functions that do nothing). Also I hadn't been able to get the time to go on one of my "debugging rewrites". I just posted it as soon as soon as it compiled.

Thanks for catching the errors for me :) I changed the code post.

EDIT: Right now I'm working on getting working properly. I'll post the code when its done.



Edited 1 time(s). Last edit at 08/07/2008 08:25PM by Arikado.
Re: Question about libwiisprite transparency
August 08, 2008 03:02AM
.png files have the option of making a pixel transparent

libwiisprite doesn't show those pixels in the game
Re: Question about libwiisprite transparency
August 08, 2008 10:01AM
You can also have every alpha-value, visible to half-visible to invisible.
Re: Question about libwiisprite transparency
August 08, 2008 04:36PM
Yeah, chaosteil just told me how to access pixel data. Everything compiled fine, but when I ran the program the screen was black and the wiimote wouldn't sync. I found the problem lines and I'm now playing around with it to get them working. It should be done soon.

EDIT:
Quote
chaosteil
Why, that's easy. I already told you that _pixels is an array of colors, so to access for example the first pixel, the values would be these:
R: _pixels[0], G: _pixels[1], B: _pixels[2], A: _pixels[3]
To convert a (x;y) to an image location, use this: loc = (y*imagewidth)+x, so to get RGBA values, it would be this: _pixels[loc], _pixels[loc+1], _pixels[loc+2], _pixels[loc+3]
I hope that helped ;)



Edited 1 time(s). Last edit at 08/08/2008 04:40PM by Arikado.
Re: Question about libwiisprite transparency
August 08, 2008 06:47PM
Sound very logically... 32Bits pixelvalues... so _pixel is a u8[]?
Sorry, only registered users may post in this forum.

Click here to login