out must be buffer big enough to contain uncompressed IDAT chunk data, and in must contain the full image. return value is error**/
| 5382 | /*out must be buffer big enough to contain uncompressed IDAT chunk data, and in must contain the full image. |
| 5383 | return value is error**/ |
| 5384 | static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const unsigned char* in, |
| 5385 | unsigned w, unsigned h, |
| 5386 | const LodePNGInfo* info_png, const LodePNGEncoderSettings* settings) |
| 5387 | { |
| 5388 | /* |
| 5389 | This function converts the pure 2D image with the PNG's colortype, into filtered-padded-interlaced data. Steps: |
| 5390 | *) if no Adam7: 1) add padding bits (= posible extra bits per scanline if bpp < 8) 2) filter |
| 5391 | *) if adam7: 1) Adam7_interlace 2) 7x add padding bits 3) 7x filter |
| 5392 | */ |
| 5393 | unsigned bpp = lodepng_get_bpp(&info_png->color); |
| 5394 | unsigned error = 0; |
| 5395 | |
| 5396 | if(info_png->interlace_method == 0) |
| 5397 | { |
| 5398 | *outsize = h + (h * ((w * bpp + 7) / 8)); /*image size plus an extra byte per scanline + possible padding bits*/ |
| 5399 | *out = (unsigned char*)lodepng_malloc(*outsize); |
| 5400 | if(!(*out) && (*outsize)) error = 83; /*alloc fail*/ |
| 5401 | |
| 5402 | if(!error) |
| 5403 | { |
| 5404 | /*non multiple of 8 bits per scanline, padding bits needed per scanline*/ |
| 5405 | if(bpp < 8 && w * bpp != ((w * bpp + 7) / 8) * 8) |
| 5406 | { |
| 5407 | unsigned char* padded = (unsigned char*)lodepng_malloc(h * ((w * bpp + 7) / 8)); |
| 5408 | if(!padded) error = 83; /*alloc fail*/ |
| 5409 | if(!error) |
| 5410 | { |
| 5411 | addPaddingBits(padded, in, ((w * bpp + 7) / 8) * 8, w * bpp, h); |
| 5412 | error = filter(*out, padded, w, h, &info_png->color, settings); |
| 5413 | } |
| 5414 | lodepng_free(padded); |
| 5415 | } |
| 5416 | else |
| 5417 | { |
| 5418 | /*we can immediatly filter into the out buffer, no other steps needed*/ |
| 5419 | error = filter(*out, in, w, h, &info_png->color, settings); |
| 5420 | } |
| 5421 | } |
| 5422 | } |
| 5423 | else /*interlace_method is 1 (Adam7)*/ |
| 5424 | { |
| 5425 | unsigned passw[7], passh[7]; |
| 5426 | size_t filter_passstart[8], padded_passstart[8], passstart[8]; |
| 5427 | unsigned char* adam7; |
| 5428 | |
| 5429 | Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp); |
| 5430 | |
| 5431 | *outsize = filter_passstart[7]; /*image size plus an extra byte per scanline + possible padding bits*/ |
| 5432 | *out = (unsigned char*)lodepng_malloc(*outsize); |
| 5433 | if(!(*out)) error = 83; /*alloc fail*/ |
| 5434 | |
| 5435 | adam7 = (unsigned char*)lodepng_malloc(passstart[7]); |
| 5436 | if(!adam7 && passstart[7]) error = 83; /*alloc fail*/ |
| 5437 | |
| 5438 | if(!error) |
| 5439 | { |
| 5440 | unsigned i; |
| 5441 |
no test coverage detected