diff options
author | Alessio Treglia <alessio@debian.org> | 2012-04-04 21:01:18 +0200 |
---|---|---|
committer | Alessio Treglia <alessio@debian.org> | 2012-04-04 21:01:18 +0200 |
commit | 3423cc86f86a823a318ea72981dc8eb889fc7987 (patch) | |
tree | 01c27814a7d75d2b39c9ad1df8a730993496e3ec /src/book.vala | |
parent | 7249c8ed3cb0da5185af4ecd2031c483bfc0258a (diff) |
Imported Upstream version 3.4.0upstream/3.4.0
Diffstat (limited to 'src/book.vala')
-rw-r--r-- | src/book.vala | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/book.vala b/src/book.vala index a410264..c931f41 100644 --- a/src/book.vala +++ b/src/book.vala @@ -272,7 +272,7 @@ public class Book { depth = 8; color_space = "DeviceRGB"; - var data_length = height * width * 3 + 1; + var data_length = height * width * 3; data = new uint8[data_length]; for (var row = 0; row < height; row++) { @@ -297,20 +297,23 @@ public class Book var data_length = height * ((width * 2 + 7) / 8); data = new uint8[data_length]; var offset = 0; - data[offset] = 0; for (var row = 0; row < height; row++) { /* Pad to the next line */ if (shift_count != 6) { offset++; - data[offset] = 0; shift_count = 6; } var in_offset = row * image.get_rowstride (); for (var x = 0; x < width; x++) { + /* Clear byte */ + if (shift_count == 6) + data[offset] = 0; + + /* Set bits */ var p = pixels[in_offset + x*3]; if (p >= 192) data[offset] |= 3 << shift_count; @@ -318,10 +321,11 @@ public class Book data[offset] |= 2 << shift_count; else if (p >= 64) data[offset] |= 1 << shift_count; + + /* Move to the next position */ if (shift_count == 0) { offset++; - data[offset] = 0; shift_count = 6; } else @@ -338,27 +342,31 @@ public class Book var data_length = height * ((width + 7) / 8); data = new uint8[data_length]; var offset = 0; - data[offset] = 0; for (var row = 0; row < height; row++) { /* Pad to the next line */ if (mask != 0x80) { offset++; - data[offset] = 0; mask = 0x80; } var in_offset = row * image.get_rowstride (); for (var x = 0; x < width; x++) { + /* Clear byte */ + if (mask == 0x80) + data[offset] = 0; + + /* Set bit */ if (pixels[in_offset+x*3] != 0) data[offset] |= (uint8) mask; + + /* Move to the next bit */ mask >>= 1; if (mask == 0) { offset++; - data[offset] = 0; mask = 0x80; } } @@ -368,7 +376,7 @@ public class Book { depth = 8; color_space = "DeviceGray"; - var data_length = height * width + 1; + var data_length = height * width; data = new uint8 [data_length]; for (var row = 0; row < height; row++) { |