Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / pdfium / core / src / fxcodec / codec / fx_codec_flate.cpp
index c02f097..e17c32a 100644 (file)
@@ -398,6 +398,7 @@ static void PNG_Predictor(FX_LPBYTE& data_buf, FX_DWORD& data_size,
     FX_LPBYTE pDestData = dest_buf;
     for (int row = 0; row < row_count; row ++) {
         FX_BYTE tag = pSrcData[0];
+        byte_cnt++;
         if (tag == 0) {
             int move_size = row_size;
             if ((row + 1) * (move_size + 1) > (int)data_size) {
@@ -406,7 +407,7 @@ static void PNG_Predictor(FX_LPBYTE& data_buf, FX_DWORD& data_size,
             FXSYS_memmove32(pDestData, pSrcData + 1, move_size);
             pSrcData += move_size + 1;
             pDestData += move_size;
-            byte_cnt += move_size + 1;
+            byte_cnt += move_size;
             continue;
         }
         for (int byte = 0; byte < row_size && byte_cnt < (int)data_size; byte ++) {
@@ -464,7 +465,6 @@ static void PNG_Predictor(FX_LPBYTE& data_buf, FX_DWORD& data_size,
         }
         pSrcData += row_size + 1;
         pDestData += row_size;
-        byte_cnt++;
     }
     FX_Free(data_buf);
     data_buf = dest_buf;
@@ -524,17 +524,19 @@ static void TIFF_PredictorEncode(FX_LPBYTE& data_buf, FX_DWORD& data_size,
 static void TIFF_PredictLine(FX_LPBYTE dest_buf, int row_size, int BitsPerComponent, int Colors, int Columns)
 {
     if (BitsPerComponent == 1) {
-        int row_bits = BitsPerComponent * Colors * Columns;
+        int row_bits = FX_MIN(BitsPerComponent * Colors * Columns, row_size * 8);
+        int index_pre = 0;
+        int col_pre = 0;
         for(int i = 1; i < row_bits; i ++) {
             int col = i % 8;
             int index = i / 8;
-            int index_pre = (col == 0) ? (index - 1) : index;
-            int col_pre = (col == 0) ? 8 : col;
-            if( ((dest_buf[index] >> (7 - col)) & 1) ^ ((dest_buf[index_pre] >> (8 - col_pre)) & 1) ) {
+            if( ((dest_buf[index] >> (7 - col)) & 1) ^ ((dest_buf[index_pre] >> (7 - col_pre)) & 1) ) {
                 dest_buf[index] |= 1 << (7 - col);
             } else {
                 dest_buf[index] &= ~(1 << (7 - col));
             }
+            index_pre = index;
+            col_pre = col;
         }
         return;
     }