Load uncompressed image pixels for 1-, 4-, 8-, 16-, 24- and 32-bit dib @param io FreeImage IO @param handle FreeImage IO handle @param dib Image to be loaded @param height Image height @param pitch Image pitch @param bit_count Image bit-depth (1-, 4-, 8-, 16-, 24- or 32-bit) @return Returns TRUE if successful, returns FALSE otherwise */
| 148 | @return Returns TRUE if successful, returns FALSE otherwise |
| 149 | */ |
| 150 | static BOOL |
| 151 | LoadPixelData(FreeImageIO *io, fi_handle handle, FIBITMAP *dib, int height, unsigned pitch, unsigned bit_count) { |
| 152 | unsigned count = 0; |
| 153 | |
| 154 | // Load pixel data |
| 155 | // NB: height can be < 0 for BMP data |
| 156 | if (height > 0) { |
| 157 | count = io->read_proc((void *)FreeImage_GetBits(dib), height * pitch, 1, handle); |
| 158 | if(count != 1) { |
| 159 | return FALSE; |
| 160 | } |
| 161 | } else { |
| 162 | int positiveHeight = abs(height); |
| 163 | for (int c = 0; c < positiveHeight; ++c) { |
| 164 | count = io->read_proc((void *)FreeImage_GetScanLine(dib, positiveHeight - c - 1), pitch, 1, handle); |
| 165 | if(count != 1) { |
| 166 | return FALSE; |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | // swap as needed |
| 172 | #ifdef FREEIMAGE_BIGENDIAN |
| 173 | if (bit_count == 16) { |
| 174 | for(unsigned y = 0; y < FreeImage_GetHeight(dib); y++) { |
| 175 | WORD *pixel = (WORD *)FreeImage_GetScanLine(dib, y); |
| 176 | for(unsigned x = 0; x < FreeImage_GetWidth(dib); x++) { |
| 177 | SwapShort(pixel); |
| 178 | pixel++; |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | #endif |
| 183 | #if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_RGB |
| 184 | if (bit_count == 24 || bit_count == 32) { |
| 185 | for(unsigned y = 0; y < FreeImage_GetHeight(dib); y++) { |
| 186 | BYTE *pixel = FreeImage_GetScanLine(dib, y); |
| 187 | for(unsigned x = 0; x < FreeImage_GetWidth(dib); x++) { |
| 188 | INPLACESWAP(pixel[0], pixel[2]); |
| 189 | pixel += (bit_count >> 3); |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | #endif |
| 194 | |
| 195 | return TRUE; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | Load image pixels for 4-bit RLE compressed dib |
no test coverage detected