diff.txt

patch to fix the bug - Matti Picus, 2014-01-02 08:44 pm

Download (6.3 kB)

 
1
diff --git a/modules/highgui/src/grfmt_tiff.cpp b/modules/highgui/src/grfmt_tiff.cpp
2
index efabf76..360bbdb 100644
3
--- a/modules/highgui/src/grfmt_tiff.cpp
4
+++ b/modules/highgui/src/grfmt_tiff.cpp
5
@@ -266,25 +266,25 @@ bool  TiffDecoder::readData( Mat& img )
6
                                 close();
7
                                 return false;
8
                             }
9
-
10
+                            uchar * bstart = buffer + (tile_height0 - tile_height) * tile_width0 * 4;
11
                             for( i = 0; i < tile_height; i++ )
12
                                 if( color )
13
                                 {
14
                                     if (wanted_channels == 4)
15
                                     {
16
-                                        icvCvt_BGRA2RGBA_8u_C4R( buffer + i*tile_width*4, 0,
17
+                                        icvCvt_BGRA2RGBA_8u_C4R( bstart + i*tile_width0*4, 0,
18
                                                              data + x*4 + img.step*(tile_height - i - 1), 0,
19
                                                              cvSize(tile_width,1) );
20
                                     }
21
                                     else
22
                                     {
23
-                                        icvCvt_BGRA2BGR_8u_C4C3R( buffer + i*tile_width*4, 0,
24
+                                        icvCvt_BGRA2BGR_8u_C4C3R( bstart + i*tile_width0*4, 0,
25
                                                              data + x*3 + img.step*(tile_height - i - 1), 0,
26
                                                              cvSize(tile_width,1), 2 );
27
                                     }
28
                                 }
29
                                 else
30
-                                    icvCvt_BGRA2Gray_8u_C4C1R( buffer + i*tile_width*4, 0,
31
+                                    icvCvt_BGRA2Gray_8u_C4C1R( bstart + i*tile_width0*4, 0,
32
                                                               data + x + img.step*(tile_height - i - 1), 0,
33
                                                               cvSize(tile_width,1), 2 );
34
                             break;
35
@@ -303,25 +303,26 @@ bool  TiffDecoder::readData( Mat& img )
36
                                 return false;
37
                             }
38
 
39
+                            uint16 * bstart = buffer16 + (tile_height0 - tile_height) * tile_width0 * ncn;
40
                             for( i = 0; i < tile_height; i++ )
41
                             {
42
                                 if( color )
43
                                 {
44
                                     if( ncn == 1 )
45
                                     {
46
-                                        icvCvt_Gray2BGR_16u_C1C3R(buffer16 + i*tile_width*ncn, 0,
47
+                                        icvCvt_Gray2BGR_16u_C1C3R(bstart + i*tile_width0*ncn, 0,
48
                                                                   (ushort*)(data + img.step*i) + x*3, 0,
49
                                                                   cvSize(tile_width,1) );
50
                                     }
51
                                     else if( ncn == 3 )
52
                                     {
53
-                                        icvCvt_RGB2BGR_16u_C3R(buffer16 + i*tile_width*ncn, 0,
54
+                                        icvCvt_RGB2BGR_16u_C3R(bstart + i*tile_width0*ncn, 0,
55
                                                                (ushort*)(data + img.step*i) + x*3, 0,
56
                                                                cvSize(tile_width,1) );
57
                                     }
58
                                     else
59
                                     {
60
-                                        icvCvt_BGRA2BGR_16u_C4C3R(buffer16 + i*tile_width*ncn, 0,
61
+                                        icvCvt_BGRA2BGR_16u_C4C3R(bstart + i*tile_width0*ncn, 0,
62
                                                                (ushort*)(data + img.step*i) + x*3, 0,
63
                                                                cvSize(tile_width,1), 2 );
64
                                     }
65
@@ -331,12 +332,12 @@ bool  TiffDecoder::readData( Mat& img )
66
                                     if( ncn == 1 )
67
                                     {
68
                                         memcpy((ushort*)(data + img.step*i)+x,
69
-                                               buffer16 + i*tile_width*ncn,
70
+                                               bstart + i*tile_width0*ncn,
71
                                                tile_width*sizeof(buffer16[0]));
72
                                     }
73
                                     else
74
                                     {
75
-                                        icvCvt_BGRA2Gray_16u_CnC1R(buffer16 + i*tile_width*ncn, 0,
76
+                                        icvCvt_BGRA2Gray_16u_CnC1R(bstart + i*tile_width0*ncn, 0,
77
                                                                (ushort*)(data + img.step*i) + x, 0,
78
                                                                cvSize(tile_width,1), ncn, 2 );
79
                                     }
80
@@ -359,18 +360,20 @@ bool  TiffDecoder::readData( Mat& img )
81
                                 return false;
82
                             }
83
 
84
+                            float * fstart = buffer32 + (tile_height0 - tile_height) * tile_width0 * sizeof(buffer32[0]);
85
+                            double * dstart = buffer64 + (tile_height0 - tile_height) * tile_width0 * sizeof(buffer64[0]);
86
                             for( i = 0; i < tile_height; i++ )
87
                             {
88
                                 if(dst_bpp == 32)
89
                                 {
90
                                     memcpy((float*)(data + img.step*i)+x,
91
-                                           buffer32 + i*tile_width*ncn,
92
+                                           fstart + i*tile_width0*ncn,
93
                                            tile_width*sizeof(buffer32[0]));
94
                                 }
95
                                 else
96
                                 {
97
                                     memcpy((double*)(data + img.step*i)+x,
98
-                                         buffer64 + i*tile_width*ncn,
99
+                                         dstart + i*tile_width0*ncn,
100
                                          tile_width*sizeof(buffer64[0]));
101
                                 }
102
                             }