part of this being separated allows for us to play nicely with the setjmp of libpng
| 102 | |
| 103 | // part of this being separated allows for us to play nicely with the setjmp of libpng |
| 104 | bool ImageSourcePng::loadHeader() |
| 105 | { |
| 106 | bool success = true; |
| 107 | |
| 108 | if( setjmp( png_jmpbuf(mPngPtr) ) ) { |
| 109 | success = false; |
| 110 | } |
| 111 | else { |
| 112 | png_read_info( mPngPtr, mInfoPtr ); |
| 113 | |
| 114 | png_uint_32 width, height; |
| 115 | int bitDepth, colorType, interlaceType, compressionType, filterMethod; |
| 116 | |
| 117 | if( ! png_get_IHDR( mPngPtr, mInfoPtr, &width, &height, &bitDepth, &colorType, &interlaceType, &compressionType, &filterMethod ) ) { |
| 118 | png_destroy_read_struct( &mPngPtr, &mInfoPtr, (png_infopp)NULL ); |
| 119 | mPngPtr = 0; |
| 120 | return false; |
| 121 | } |
| 122 | |
| 123 | setSize( width, height ); |
| 124 | setDataType( ( bitDepth == 16 ) ? ImageIo::UINT16 : ImageIo::UINT8 ); |
| 125 | |
| 126 | #ifdef CINDER_LITTLE_ENDIAN |
| 127 | png_set_swap( mPngPtr ); |
| 128 | #endif |
| 129 | |
| 130 | switch( colorType ) { |
| 131 | case PNG_COLOR_TYPE_GRAY: |
| 132 | setColorModel( ImageIo::CM_GRAY ); |
| 133 | setChannelOrder( ImageIo::Y ); |
| 134 | break; |
| 135 | case PNG_COLOR_TYPE_GRAY_ALPHA: |
| 136 | setColorModel( ImageIo::CM_GRAY ); |
| 137 | setChannelOrder( ImageIo::YA ); |
| 138 | break; |
| 139 | case PNG_COLOR_TYPE_RGB: |
| 140 | case PNG_COLOR_TYPE_PALETTE: |
| 141 | setColorModel( ImageIo::CM_RGB ); |
| 142 | setChannelOrder( ImageIo::RGB ); |
| 143 | break; |
| 144 | case PNG_COLOR_TYPE_RGB_ALPHA: |
| 145 | setColorModel( ImageIo::CM_RGB ); |
| 146 | setChannelOrder( ImageIo::RGBA ); |
| 147 | break; |
| 148 | default: |
| 149 | throw ImageSourcePngException( "Unexpected png color type." ); |
| 150 | } |
| 151 | |
| 152 | png_set_expand_gray_1_2_4_to_8( mPngPtr ); |
| 153 | png_set_palette_to_rgb( mPngPtr ); |
| 154 | png_set_tRNS_to_alpha( mPngPtr ); |
| 155 | |
| 156 | png_read_update_info( mPngPtr, mInfoPtr ); |
| 157 | } |
| 158 | |
| 159 | return success; |
| 160 | } |
| 161 |
nothing calls this directly
no test coverage detected