summaryrefslogtreecommitdiff
path: root/packaging/tizen-pdftoraster-oom-fix.patch
blob: f8be34d583853a80811981a88280326b854f8481 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
diff -urN cups-filters.orig/filter/pdftoraster.cxx cups-filters/filter/pdftoraster.cxx
--- cups-filters.orig/filter/pdftoraster.cxx	2012-12-18 11:26:38.864685553 +0900
+++ cups-filters/filter/pdftoraster.cxx	2012-12-26 14:56:47.500912858 +0900
@@ -87,6 +87,7 @@
 
 #define MAX_CHECK_COMMENT_LINES	20
 #define MAX_BYTES_PER_PIXEL 32
+#define MAX_BYTES_PER_SLICE 20000000
 
 namespace {
   typedef unsigned char *(*ConvertLineFunc)(unsigned char *src,
@@ -1469,7 +1470,7 @@
 }
 
 static void writePageImage(cups_raster_t *raster, SplashBitmap *bitmap,
-  int pageNo)
+  int pageNo, unsigned int nlines)
 {
   ConvertLineFunc convertLine;
   unsigned char *lineBuf = NULL;
@@ -1505,9 +1506,9 @@
     for (unsigned int plane = 0;plane < nplanes;plane++) {
       unsigned char *bp = (unsigned char *)(bitmap->getDataPtr());
 
-      bp += rowsize * bitmapoffset[1] + 
-        popplerBitsPerPixel * bitmapoffset[0] / 8;
-      for (unsigned int h = 0;h < header.cupsHeight;h++) {
+//      bp += rowsize * bitmapoffset[1] +
+//        popplerBitsPerPixel * bitmapoffset[0] / 8;
+      for (unsigned int h = 0;h < nlines;h++) {
         for (unsigned int band = 0;band < nbands;band++) {
           dp = convertLine(bp,lineBuf,h,plane+band,header.cupsWidth,
                  bytesPerLine);
@@ -1622,10 +1623,6 @@
     }
   }
 
-  doc->displayPage(out,pageNo,header.HWResolution[0],
-		   header.HWResolution[1],(landscape == 0 ? 0 : 90),
-		   gTrue,gTrue,gTrue);
-  bitmap = out->getBitmap();
   bitmapoffset[0] = margins[0] / 72.0 * header.HWResolution[0];
   bitmapoffset[1] = margins[3] / 72.0 * header.HWResolution[1];
 
@@ -1656,8 +1653,22 @@
       exit(1);
   }
 
-  /* write page image */
-  writePageImage(raster,bitmap,pageNo);
+  //calculate the number of slices
+  unsigned int totalBytes = header.cupsBytesPerLine * header.cupsHeight;
+  unsigned int numSlices = totalBytes / MAX_BYTES_PER_SLICE;
+  numSlices += ((totalBytes % MAX_BYTES_PER_SLICE) > 0) ? 1 : 0;
+  unsigned int linesInSlice = header.cupsHeight / numSlices;
+  linesInSlice += header.cupsHeight % numSlices > 0 ? 1 : 0;
+  unsigned int linesRemained = header.cupsHeight;
+  for(unsigned int i=0;i<numSlices;i++) {
+      unsigned int linesToPrint = linesInSlice > linesRemained ? linesRemained : linesInSlice;
+      doc->displayPageSlice(out,pageNo,header.HWResolution[0],
+               header.HWResolution[1], 0,
+               gTrue,gTrue,gTrue, bitmapoffset[0], bitmapoffset[1] + linesInSlice*i, header.cupsWidth, linesToPrint);
+      bitmap = out->getBitmap();
+      writePageImage(raster,bitmap,pageNo, linesToPrint);
+      linesRemained = linesRemained - linesInSlice;
+  }
 }
 
 static void setPopplerColorProfile()