How to load RGB and ALPHA separatelly?
  • VladusVladus May 2005
    Hi to all,

    is there a possibility to load rgb and alpha image separatelly and then combine them in game?

    I'm asking this, because I would like to use 256 color image with 256 levels of alpha, but I think there is no file format that supports this.

    This way I could make my texture files smaller. Most of my images can be nicely dithered to 8bit paletted format, but I need high quality 8-bit alpha channel.

    Do you know of any method how to pull this off?


    Thanks
    Vlado
  • You might want to try using the PNG 32-bit format and then using pngquant to convert it down to 8-bit with alpha channel.
  • VladusVladus May 2005

    You might want to try using the PNG 32-bit format and then using pngquant to convert it down to 8-bit with alpha channel.



    Thanks!

    I'll give it a try.



    Vlado
  • VladusVladus May 2005
    Hi,

    pngquant didn't help, because it makes just one bit alpha.


    What I need is 8bit paletted RGB plus 8bit alpha, and this seems possible just by separating it. The problem is how to put it together in HGE.

    ???



    Vlado
  • Pedro+LMPedro LM May 2005
    You could make two separate images:

    - One with the "color" channel, palettized;
    - One with the alpha channel in the form of an 8-bit grayscale image.

    Then you load those two textures. Lock the color-channel texture, copy the colors from the alpha-channel image into the alpha of the color-channel texture, and free the alpha-channel texture.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    		// Load the color and grayscale textures:
    HTEXTURE grayscaleTex = hge->Texture_Load( "Grayscale.png" );
    HTEXTURE colorTex = hge->Texture_Load( "Color.png" );
     
    // I'll assume they have both the same dimensions...
    int width = hge->Texture_GetWidth( colorTex );
    int height = hge->Texture_GetHeight( colorTex );
     
    // Need direct access to pixel data...
    // I'll be writing to the color channel, but only reading from the
    // grayscale (alpha) channel:
    DWORD * alphaChannel = hge->Texture_Lock( grayscaleTex, true );
    DWORD * colorChannel = hge->Texture_Lock( colorTex, false );
     
    for ( int x = 0; x < width; x++ ) {
    for ( int y = 0; y < height; y++ ) {
    DWORD color = colorChannel[y * width + x];
    DWORD gray = alphaChannel[y * width + x];
     
    // R, G, and B are equal in the grayscale image, so it doesn't
    // matter which one I get:
    unsigned char alpha = (unsigned char) GETR( gray );
     
    // Set this as the color texture's alpha channel:
    color = SETA( color, alpha );
     
    // Put it back into the texture:
    colorChannel[y * width + x] = color;
    }
    }
     
    hge->Texture_Unlock( colorTex );
    hge->Texture_Unlock( grayscaleTex );
     
    // Don't need this anymore:
    hge->Texture_Free( grayscaleTex );
  • VladusVladus May 2005
    Perfect!

    Thanks a lot. You're good, I didn't think of this.



    Vlado
  • Vladus said:

    Hi,

    pngquant didn't help, because it makes just one bit alpha.


    What I need is 8bit paletted RGB plus 8bit alpha, and this seems possible just by separating it. The problem is how to put it together in HGE.

    ???



    Vlado



    That's strange because, according to GUI for Pngquant, pngquant is able to reduce the size of the image file while maintaining full 8-bit transparency. Oh, well. Sorry it didn't work for you.
  • DimaDima May 2005
    I think once you load the image into a texture it makes no difference how optimized it was before that. If texture is 32bit, your image becomes 32bit. You can use the compressed texture format to save memory space, but I would not spend too much time trying to make PNGs smaller on disk, as it wont make a difference in memory. Also, I don't think you can have palletized textures in DX8, so compressed is prolly the best way to go if you need to save memory.
  • AnonymousAnonymous May 2005
    Yes and the only way to use compressed texture memory is to use a compressed DDS format.. AFAIK no PNG formats will do it.
    :shock:
  • Pedro+LMPedro LM May 2005
    Making the image files smaller on disk would cut down on the download times and bandwidth requirements, though!
  • VladusVladus October 2006
    [quote="Pedro LM"]Making the image files smaller on disk would cut down on the download times and bandwidth requirements, though!

    That's the point. After creating all the grafix, I realized installer was 20megs. On some images, you can't see difference between 24bit and 8bit, so there's no reason to store extra 16bits per pixel... Sometimes, it even get's such an artistic look to it, because of dithering.


    Vlado

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion

Who's Online (0)