670 | | for (int t=0; t<_t; ++t) |
671 | | { |
672 | | unsigned char* rowData = _data+t*getRowSizeInBytes()+image*getImageSizeInBytes(); |
673 | | unsigned char* left = rowData ; |
674 | | unsigned char* right = rowData + ((_s-1)*getPixelSizeInBits())/8; |
675 | | |
676 | | while (left < right) |
677 | | { |
678 | | char tmp[32]; // max elem size is four floats |
679 | | memcpy(tmp, left, elemSize); |
680 | | memcpy(left, right, elemSize); |
681 | | memcpy(right, tmp, elemSize); |
682 | | left += elemSize; |
683 | | right -= elemSize; |
684 | | } |
685 | | } |
686 | | |
| 671 | for(int r=0;r<_r;++r) |
| 672 | { |
| 673 | for (int t=0; t<_t; ++t) |
| 674 | { |
| 675 | unsigned char* rowData = _data+t*getRowSizeInBytes()+r*getImageSizeInBytes(); |
| 676 | unsigned char* left = rowData ; |
| 677 | unsigned char* right = rowData + ((_s-1)*getPixelSizeInBits())/8; |
| 678 | |
| 679 | while (left < right) |
| 680 | { |
| 681 | char tmp[32]; // max elem size is four floats |
| 682 | memcpy(tmp, left, elemSize); |
| 683 | memcpy(left, right, elemSize); |
| 684 | memcpy(right, tmp, elemSize); |
| 685 | left += elemSize; |
| 686 | right -= elemSize; |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | |
699 | | unsigned int rowSizeInBytes = getRowSizeInBytes(); |
700 | | unsigned int imageSizeInBytes = getImageSizeInBytes(); |
701 | | unsigned char* imageData = _data+image*imageSizeInBytes; |
702 | | |
703 | | // make temp. buffer for one image |
704 | | unsigned char *tmpData = new unsigned char [imageSizeInBytes]; |
705 | | |
706 | | for (int t=0; t<_t; ++t) |
707 | | { |
708 | | unsigned char* srcRowData = imageData+t*rowSizeInBytes; |
709 | | unsigned char* dstRowData = tmpData+(_t-1-t)*rowSizeInBytes; |
710 | | memcpy(dstRowData, srcRowData, rowSizeInBytes); |
711 | | } |
712 | | |
713 | | // insert fliped image |
714 | | memcpy(imageData, tmpData, imageSizeInBytes); |
715 | | |
716 | | delete [] tmpData; |
717 | | |
| 717 | if (!_mipmapData.empty() && _r>1) |
| 718 | { |
| 719 | notify(WARN) << "Error Image::flipVertical() do not succeed : flipping of mipmap 3d textures not yet supported."<<std::endl; |
| 720 | return; |
| 721 | } |
| 722 | |
| 723 | if (_mipmapData.empty()) |
| 724 | { |
| 725 | // no mipmaps, |
| 726 | // so we can safely handle 3d textures |
| 727 | for(int r=0;r<_r;++r) |
| 728 | { |
| 729 | if (!dxtc_tool::VerticalFlip(_s,_t,_pixelFormat,data(0,0,r))) |
| 730 | { |
| 731 | // its not a compressed image, so implement flip oursleves. |
| 732 | |
| 733 | unsigned int rowSize = computeRowWidthInBytes(_s,_pixelFormat,_dataType,_packing); |
| 734 | unsigned char* top = data(0,0,r); |
| 735 | unsigned char* bottom = top + (_t-1)*rowSize; |
| 736 | |
| 737 | flipImageVertical(top, bottom, rowSize); |
| 738 | } |
| 739 | } |
| 740 | } |
| 741 | else if (_r==1) |
| 742 | { |
| 743 | if (!dxtc_tool::VerticalFlip(_s,_t,_pixelFormat,_data)) |
| 744 | { |
| 745 | // its not a compressed image, so implement flip oursleves. |
| 746 | unsigned int rowSize = computeRowWidthInBytes(_s,_pixelFormat,_dataType,_packing); |
| 747 | unsigned char* top = data(0,0,0); |
| 748 | unsigned char* bottom = top + (_t-1)*rowSize; |
| 749 | |
| 750 | flipImageVertical(top, bottom, rowSize); |
| 751 | } |
| 752 | |
| 753 | int s = _s; |
| 754 | int t = _t; |
| 755 | //int r = _r; |
| 756 | |
| 757 | for(unsigned int i=0;i<_mipmapData.size() && _mipmapData[i];++i) |
| 758 | { |
| 759 | s >>= 1; |
| 760 | t >>= 1; |
| 761 | if (s==0) s=1; |
| 762 | if (t==0) t=1; |
| 763 | if (!dxtc_tool::VerticalFlip(s,t,_pixelFormat,_data+_mipmapData[i])) |
| 764 | { |
| 765 | // its not a compressed image, so implement flip oursleves. |
| 766 | unsigned int rowSize = computeRowWidthInBytes(s,_pixelFormat,_dataType,_packing); |
| 767 | unsigned char* top = _data+_mipmapData[i]; |
| 768 | unsigned char* bottom = top + (t-1)*rowSize; |
| 769 | |
| 770 | flipImageVertical(top, bottom, rowSize); |
| 771 | } |
| 772 | } |
| 773 | } |
| 774 | |