Lars Wassermann avatar Lars Wassermann committed d185c46

fixed boundary errors with display bitmaps:
every line starts with a round word, therefore the empty space is at the end of every lines last word.
The effect is that we need to recalculate the offset of our bloated pixel values and eventually need to stop copying to the diplay buffer prematurely

Comments (0)

Files changed (1)

     def __del__(self):
         lltype.free(self._real_depth_buffer, flavor='raw')
 
+    @jit.elidable
+    def compute_pos_and_line_end(self, n, depth):
+        width = self.display.width
+        words_per_line = width / (NATIVE_DEPTH / depth)
+        if width % (NATIVE_DEPTH / depth) != 0:
+            words_per_line += 1
+        line = n / words_per_line
+        assert line < self.display.height # line is 0 based
+        line_start = width * line
+        line_end = line_start + width # actually the start of the next line
+        pos = ((n % words_per_line) * (NATIVE_DEPTH / depth)) + line_start
+        return pos, line_end
+
+
 class W_DisplayBitmap1Bit(W_DisplayBitmap):
     @jit.unroll_safe
     def setword(self, n, word):
         self._real_depth_buffer[n] = word
-        pos = n * NATIVE_DEPTH
+        pos, line_end = self.compute_pos_and_line_end(n, 1)
         mask = r_uint(1)
         mask <<= 31
         for i in xrange(32):
+            if pos == line_end:
+                return
             bit = mask & word
             pixel = r_uint((0x00ffffff * (bit == 0)) | r_uint(0xff000000))
             self.pixelbuffer[pos] = pixel
     @jit.unroll_safe
     def setword(self, n, word):
         self._real_depth_buffer[n] = word
-        pos = n * NATIVE_DEPTH / 16
+        pos, line_end = self.compute_pos_and_line_end(n, 16)
         mask = 0xf
         for i in range(2):
             pixel = 0
                 pixel |= r_uint(word & mask << (8 * j + 4))
                 mask <<= 4
             self.pixelbuffer[pos + i] = pixel
+            if pos + 1 == line_end:
+                return
 
 class W_DisplayBitmap32Bit(W_DisplayBitmap):
     @jit.unroll_safe
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.