libpng - Does PNG_COLOR_MASK_ALPHA map to a particular OpenGL color format? -


i'm little confused after running png gauntlet on png texture assets. of them either png_color_type_rgb or png_color_type_rgba , therefore mapping them appropriate gl color format simple enough. full disclosure, i'm not graphics master.

after running png gauntlet optimize textures, calling png_get_ihdr() returns color type png_color_mask_alpha , i'm little confused whether or not can map directly color format use when passing glteximage2d().

the particular texture image behaves way sprite composed of whites , grays varying alpha values. best guess here optimization determined kind of gray scale alpha , therefore need detect in texture loading code.

i think perhaps appropriate color type gl_luminance_alpha, since it's 1 uses luminance value r,g, , b components, gray scale alpha channel.

the color png masks defined in libpng's png.h:

/* color type masks */ #define png_color_mask_palette    1 #define png_color_mask_color      2 #define png_color_mask_alpha      4  /* color types.  note not combinations legal */ #define png_color_type_gray 0 #define png_color_type_palette  (png_color_mask_color | png_color_mask_palette) #define png_color_type_rgb        (png_color_mask_color) #define png_color_type_rgb_alpha  (png_color_mask_color | png_color_mask_alpha) #define png_color_type_gray_alpha (png_color_mask_alpha) /* aliases */ #define png_color_type_rgba  png_color_type_rgb_alpha 

these relate color types defined in png specification, are

0: gray (1 channel) 2: rgb  (3 channels) 3: color palette (1 channel) 4: gray-alpha (2 channels) 6: rgba (4 channels) 

in glteximage2d version 1.1, png colortype 0 equivalent gl_luminance_alpha. in glteximage2d version 3 png colortype 0 not have direct equivalence. one-channel gl format gl_red, means samples put in red channel while green , blue channels set 0.

the safest way handle conversion, think, use (after png_get_ihdr(...))

png_set_gray_to_rgb(png_ptr); png_set_palette_to_rgb(png_ptr); png_read_update_info(png_ptr); 

this guarantee receive colortype 2 (rgb) or 6 (rgba), both of have direct equivalence gl formats gl_rgb or gl_rgba in either glteximage2d version 1.1 or version 3. in particular, png_set_gray_to_rgb() copies gray channel green , blue channels, , uses gray channel red channel.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -