| 514 | typename image_type |
| 515 | > |
| 516 | void load_dng ( |
| 517 | image_type& image_, |
| 518 | std::istream& in |
| 519 | ) |
| 520 | { |
| 521 | image_view<image_type> image(image_); |
| 522 | using namespace dng_helpers_namespace; |
| 523 | try |
| 524 | { |
| 525 | if (in.get() != 'D' || in.get() != 'N' || in.get() != 'G') |
| 526 | throw image_load_error("the stream does not contain a dng image file"); |
| 527 | |
| 528 | unsigned long version; |
| 529 | deserialize(version,in); |
| 530 | if (version != 1) |
| 531 | throw image_load_error("You need the new version of the dlib library to read this dng file"); |
| 532 | |
| 533 | unsigned long type; |
| 534 | deserialize(type,in); |
| 535 | |
| 536 | long width, height; |
| 537 | deserialize(width,in); |
| 538 | deserialize(height,in); |
| 539 | |
| 540 | if (width > 0 && height > 0) |
| 541 | image.set_size(height,width); |
| 542 | else |
| 543 | image.clear(); |
| 544 | |
| 545 | if (type != grayscale_float) |
| 546 | { |
| 547 | typedef entropy_decoder::kernel_2a decoder_type; |
| 548 | decoder_type decoder; |
| 549 | decoder.set_stream(in); |
| 550 | |
| 551 | entropy_decoder_model<256,decoder_type>::kernel_5a edm(decoder); |
| 552 | unsigned long symbol; |
| 553 | rgb_pixel p_rgb; |
| 554 | rgb_alpha_pixel p_rgba; |
| 555 | hsi_pixel p_hsi; |
| 556 | switch (type) |
| 557 | { |
| 558 | case rgb_alpha_paeth: |
| 559 | |
| 560 | for (long r = 0; r < image.nr(); ++r) |
| 561 | { |
| 562 | for (long c = 0; c < image.nc(); ++c) |
| 563 | { |
| 564 | p_rgba = predictor_rgb_alpha_paeth(image,r,c); |
| 565 | edm.decode(symbol); |
| 566 | p_rgba.red += static_cast<unsigned char>(symbol); |
| 567 | |
| 568 | edm.decode(symbol); |
| 569 | p_rgba.green += static_cast<unsigned char>(symbol); |
| 570 | |
| 571 | edm.decode(symbol); |
| 572 | p_rgba.blue += static_cast<unsigned char>(symbol); |
| 573 | |