Function from OpenSceneGraph (originally called getdata in their sources): http://openscenegraph.sourcearchive.com/documentation/2.2.0/ReaderWriterJP2_8cpp-source.html
| 590 | // Function from OpenSceneGraph (originally called getdata in their sources): |
| 591 | // http://openscenegraph.sourcearchive.com/documentation/2.2.0/ReaderWriterJP2_8cpp-source.html |
| 592 | ILint Jp2ConvertData(jas_stream_t *in, jas_image_t *image) |
| 593 | { |
| 594 | int ret; |
| 595 | int numcmpts; |
| 596 | int cmptno; |
| 597 | jas_matrix_t *data[4]; |
| 598 | int x; |
| 599 | int y; |
| 600 | int width, height; |
| 601 | |
| 602 | width = jas_image_cmptwidth(image, 0); |
| 603 | height = jas_image_cmptheight(image, 0); |
| 604 | numcmpts = jas_image_numcmpts(image); |
| 605 | |
| 606 | ret = -1; |
| 607 | |
| 608 | data[0] = 0; |
| 609 | data[1] = 0; |
| 610 | data[2] = 0; |
| 611 | data[3] = 0; |
| 612 | for (cmptno = 0; cmptno < numcmpts; ++cmptno) { |
| 613 | if (!(data[cmptno] = jas_matrix_create(1, width))) { |
| 614 | goto done; |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | for (y = height - 1; y >= 0; --y) |
| 619 | // for (y = 0; y < height; ++y) |
| 620 | { |
| 621 | for (x = 0; x < width; ++x) |
| 622 | { |
| 623 | for (cmptno = 0; cmptno < numcmpts; ++cmptno) |
| 624 | { |
| 625 | // The sample data is unsigned. |
| 626 | int c; |
| 627 | if ((c = jas_stream_getc(in)) == EOF) { |
| 628 | return -1; |
| 629 | } |
| 630 | jas_matrix_set(data[cmptno], 0, x, c); |
| 631 | } |
| 632 | } |
| 633 | for (cmptno = 0; cmptno < numcmpts; ++cmptno) { |
| 634 | if (jas_image_writecmpt(image, cmptno, 0, y, width, 1, |
| 635 | data[cmptno])) { |
| 636 | goto done; |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | jas_stream_flush(in); |
| 642 | ret = 0; |
| 643 | |
| 644 | done: |
| 645 | for (cmptno = 0; cmptno < numcmpts; ++cmptno) { |
| 646 | if (data[cmptno]) { |
| 647 | jas_matrix_destroy(data[cmptno]); |
| 648 | } |
| 649 | } |