Mercurial > octave-libtiff
comparison libinterp/corefcn/__tiff__.cc @ 31203:fa50e2c17568
Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
* libinterp/corefcn/__tiff__.cc (F__tiff_read_rgba_image__,
F__tiff_read_rgba_strip__, F__tiff_read_rgba_tile__): fixed bug where
orientations that require rotation and flipping were incorrectly handled.
author | magedrifaat <magedrifaat@gmail.com> |
---|---|
date | Fri, 02 Sep 2022 23:27:47 +0200 |
parents | be6ccdcd5775 |
children | f1c1efd356c8 |
comparison
equal
deleted
inserted
replaced
31202:be6ccdcd5775 | 31203:fa50e2c17568 |
---|---|
2750 TIFFRGBAImage img_config; | 2750 TIFFRGBAImage img_config; |
2751 char emsg[1024]; | 2751 char emsg[1024]; |
2752 if (! TIFFRGBAImageOK (tif, emsg) | 2752 if (! TIFFRGBAImageOK (tif, emsg) |
2753 || ! TIFFRGBAImageBegin (&img_config, tif, 0, emsg)) | 2753 || ! TIFFRGBAImageBegin (&img_config, tif, 0, emsg)) |
2754 error ("Failed to read image"); | 2754 error ("Failed to read image"); |
2755 | 2755 |
2756 // FIXME: rotated orientation don't work correctly (e.g. LeftTop) | 2756 if (orientation == ORIENTATION_RIGHTTOP |
2757 img_config.orientation = ORIENTATION_TOPLEFT; | 2757 || orientation == ORIENTATION_LEFTBOT) |
2758 // LibTIFF can only do flips and doesn't do rotations, so if we need | |
2759 // an orientation that requires a rotation before flipping | |
2760 // (i.e. LeftBottom, RightTop) then the only thing we can do is start | |
2761 // with an orientation that doesn't require a rotation, then permute at | |
2762 // the end. | |
2763 img_config.orientation = ORIENTATION_RIGHTBOT; | |
2764 else | |
2765 img_config.orientation = ORIENTATION_TOPLEFT; | |
2766 | |
2758 img_config.req_orientation = orientation; | 2767 img_config.req_orientation = orientation; |
2759 | 2768 |
2760 bool success = TIFFRGBAImageGet (&img_config, img_ptr, img_config.width, | 2769 bool success = TIFFRGBAImageGet (&img_config, img_ptr, img_config.width, |
2761 img_config.height); | 2770 img_config.height); |
2762 | 2771 |
2764 if (!success) | 2773 if (!success) |
2765 error ("Failed to read image"); | 2774 error ("Failed to read image"); |
2766 | 2775 |
2767 // Permute to the correct Octave dimension order | 2776 // Permute to the correct Octave dimension order |
2768 Array<octave_idx_type> perm (dim_vector (3, 1)); | 2777 Array<octave_idx_type> perm (dim_vector (3, 1)); |
2769 perm(0) = 2; | 2778 if (orientation >= ORIENTATION_LEFTTOP) |
2770 perm(1) = 1; | 2779 { |
2771 perm(2) = 0; | 2780 // Transpose for rotated orientations |
2781 perm(0) = 1; | |
2782 perm(1) = 2; | |
2783 perm(2) = 0; | |
2784 } | |
2785 else | |
2786 { | |
2787 perm(0) = 2; | |
2788 perm(1) = 1; | |
2789 perm(2) = 0; | |
2790 } | |
2772 img = img.permute (perm); | 2791 img = img.permute (perm); |
2773 | 2792 |
2774 // Slice the data into RGB and alpha | 2793 // Slice the data into RGB and alpha |
2775 return slice_rgba (img); | 2794 return slice_rgba (img); |
2776 #else | 2795 #else |
2842 char emsg[1024]; | 2861 char emsg[1024]; |
2843 if (! TIFFRGBAImageOK (tif, emsg) | 2862 if (! TIFFRGBAImageOK (tif, emsg) |
2844 || ! TIFFRGBAImageBegin (&img_config, tif, 0, emsg)) | 2863 || ! TIFFRGBAImageBegin (&img_config, tif, 0, emsg)) |
2845 error ("Failed to read strip"); | 2864 error ("Failed to read strip"); |
2846 | 2865 |
2847 img_config.orientation = ORIENTATION_TOPLEFT; | 2866 if (orientation == ORIENTATION_RIGHTTOP |
2867 || orientation == ORIENTATION_LEFTBOT) | |
2868 // LibTIFF can only do flips and doesn't do rotations, so if we need | |
2869 // an orientation that requires a rotation before flipping | |
2870 // (i.e. LeftBottom, RightTop) then the only thing we can do is start | |
2871 // with an orientation that doesn't require a rotation, then permute at | |
2872 // the end. | |
2873 img_config.orientation = ORIENTATION_RIGHTBOT; | |
2874 else | |
2875 img_config.orientation = ORIENTATION_TOPLEFT; | |
2876 | |
2848 img_config.req_orientation = orientation; | 2877 img_config.req_orientation = orientation; |
2849 img_config.row_offset = row; | 2878 img_config.row_offset = row; |
2850 img_config.col_offset = 0; | 2879 img_config.col_offset = 0; |
2851 | 2880 |
2852 bool success = TIFFRGBAImageGet (&img_config, strip_ptr, img_config.width, | 2881 bool success = TIFFRGBAImageGet (&img_config, strip_ptr, img_config.width, |
2856 if (!success) | 2885 if (!success) |
2857 error ("Failed to read strip"); | 2886 error ("Failed to read strip"); |
2858 | 2887 |
2859 // Permute to the correct order of dimensions for Octave | 2888 // Permute to the correct order of dimensions for Octave |
2860 Array<octave_idx_type> perm (dim_vector (3, 1)); | 2889 Array<octave_idx_type> perm (dim_vector (3, 1)); |
2861 perm(0) = 2; | 2890 if (orientation >= ORIENTATION_LEFTTOP) |
2862 perm(1) = 1; | 2891 { |
2863 perm(2) = 0; | 2892 // Transpose for rotated orientations |
2893 perm(0) = 1; | |
2894 perm(1) = 2; | |
2895 perm(2) = 0; | |
2896 } | |
2897 else | |
2898 { | |
2899 perm(0) = 2; | |
2900 perm(1) = 1; | |
2901 perm(2) = 0; | |
2902 } | |
2864 strip_data = strip_data.permute (perm); | 2903 strip_data = strip_data.permute (perm); |
2865 | 2904 |
2866 // Slice the data into RGB and alpha | 2905 // Slice the data into RGB and alpha |
2867 return slice_rgba (strip_data); | 2906 return slice_rgba (strip_data); |
2868 #else | 2907 #else |
2943 char emsg[1024]; | 2982 char emsg[1024]; |
2944 if (! TIFFRGBAImageOK (tif, emsg) | 2983 if (! TIFFRGBAImageOK (tif, emsg) |
2945 || ! TIFFRGBAImageBegin (&img_config, tif, 0, emsg)) | 2984 || ! TIFFRGBAImageBegin (&img_config, tif, 0, emsg)) |
2946 error ("Failed to read tile"); | 2985 error ("Failed to read tile"); |
2947 | 2986 |
2948 img_config.orientation = ORIENTATION_TOPLEFT; | 2987 if (orientation == ORIENTATION_RIGHTTOP |
2988 || orientation == ORIENTATION_LEFTBOT) | |
2989 // LibTIFF can only do flips and doesn't do rotations, so if we need | |
2990 // an orientation that requires a rotation before flipping | |
2991 // (i.e. LeftBottom, RightTop) then the only thing we can do is start | |
2992 // with an orientation that doesn't require a rotation, then permute at | |
2993 // the end. | |
2994 img_config.orientation = ORIENTATION_RIGHTBOT; | |
2995 else | |
2996 img_config.orientation = ORIENTATION_TOPLEFT; | |
2997 | |
2949 img_config.req_orientation = orientation; | 2998 img_config.req_orientation = orientation; |
2950 img_config.row_offset = row; | 2999 img_config.row_offset = row; |
2951 img_config.col_offset = col; | 3000 img_config.col_offset = col; |
2952 | 3001 |
2953 bool success = TIFFRGBAImageGet (&img_config, tile_ptr, corrected_width, | 3002 bool success = TIFFRGBAImageGet (&img_config, tile_ptr, corrected_width, |
2957 if (!success) | 3006 if (!success) |
2958 error ("Failed to read tile"); | 3007 error ("Failed to read tile"); |
2959 | 3008 |
2960 // Permute to the correct order of dimensions for Octave | 3009 // Permute to the correct order of dimensions for Octave |
2961 Array<octave_idx_type> perm (dim_vector (3, 1)); | 3010 Array<octave_idx_type> perm (dim_vector (3, 1)); |
2962 perm(0) = 2; | 3011 if (orientation >= ORIENTATION_LEFTTOP) |
2963 perm(1) = 1; | 3012 { |
2964 perm(2) = 0; | 3013 // Transpose for rotated orientations |
3014 perm(0) = 1; | |
3015 perm(1) = 2; | |
3016 perm(2) = 0; | |
3017 } | |
3018 else | |
3019 { | |
3020 perm(0) = 2; | |
3021 perm(1) = 1; | |
3022 perm(2) = 0; | |
3023 } | |
2965 tile_data = tile_data.permute (perm); | 3024 tile_data = tile_data.permute (perm); |
2966 | 3025 |
2967 // Slice the data into RGB and alpha | 3026 // Slice the data into RGB and alpha |
2968 return slice_rgba (tile_data); | 3027 return slice_rgba (tile_data); |
2969 #else | 3028 #else |