summaryrefslogtreecommitdiff
path: root/src/book.c
diff options
context:
space:
mode:
authorAlessio Treglia <alessio@debian.org>2010-08-16 14:20:17 +0200
committerAlessio Treglia <alessio@debian.org>2010-08-16 14:20:17 +0200
commitbbf22aaaa2fd5fe725a979f801472d52a1323242 (patch)
tree9ce9ef820f4f5e224289872d9b4f9b53908e78b7 /src/book.c
parent58d261b93430fd974ab617f15d1da551e43b2675 (diff)
Imported Upstream version 2.31.90.1upstream/2.31.90.1
Diffstat (limited to 'src/book.c')
-rw-r--r--src/book.c76
1 files changed, 61 insertions, 15 deletions
diff --git a/src/book.c b/src/book.c
index 387c7f0..081cbd3 100644
--- a/src/book.c
+++ b/src/book.c
@@ -73,14 +73,13 @@ page_changed_cb (Page *page, Book *book)
Page *
-book_append_page (Book *book, gint width, gint height, gint dpi, Orientation orientation)
+book_append_page (Book *book, gint width, gint height, gint dpi, ScanDirection scan_direction)
{
Page *page;
- page = page_new ();
- g_signal_connect (page, "image-changed", G_CALLBACK (page_changed_cb), book);
+ page = page_new (width, height, dpi, scan_direction);
+ g_signal_connect (page, "pixels-changed", G_CALLBACK (page_changed_cb), book);
g_signal_connect (page, "crop-changed", G_CALLBACK (page_changed_cb), book);
- page_setup (page, width, height, dpi, orientation);
book->priv->pages = g_list_append (book->priv->pages, page);
@@ -222,7 +221,7 @@ book_save_ps (Book *book, GFile *file, GError **error)
double width, height;
GdkPixbuf *image;
- image = page_get_cropped_image (page);
+ image = page_get_image (page, TRUE);
width = gdk_pixbuf_get_width (image) * 72.0 / page_get_dpi (page);
height = gdk_pixbuf_get_height (image) * 72.0 / page_get_dpi (page);
@@ -444,7 +443,7 @@ book_save_pdf (Book *book, GFile *file, GError **error)
height = page_get_height (page);
page_width = width * 72. / page_get_dpi (page);
page_height = height * 72. / page_get_dpi (page);
- image = page_get_cropped_image (page);
+ image = page_get_image (page, TRUE);
pixels = gdk_pixbuf_get_pixels (image);
if (page_is_color (page)) {
@@ -470,13 +469,53 @@ book_save_pdf (Book *book, GFile *file, GError **error)
}
}
}
+ else if (page_get_depth (page) == 2) {
+ int row, shift_count = 6;
+ guchar *write_ptr;
+
+ depth = 2;
+ color_space = "DeviceGray";
+ data_length = height * ((width * 2 + 7) / 8);
+ data = g_malloc (sizeof (guchar) * data_length);
+ write_ptr = data;
+ write_ptr[0] = 0;
+ for (row = 0; row < height; row++) {
+ int x;
+ guchar *in_line;
+
+ /* Pad to the next line */
+ if (shift_count != 6) {
+ write_ptr++;
+ write_ptr[0] = 0;
+ shift_count = 6;
+ }
+
+ in_line = pixels + row * gdk_pixbuf_get_rowstride (image);
+ for (x = 0; x < width; x++) {
+ guchar *in_p = in_line + x*3;
+ if (in_p[0] >= 192)
+ write_ptr[0] |= 3 << shift_count;
+ else if (in_p[0] >= 128)
+ write_ptr[0] |= 2 << shift_count;
+ else if (in_p[0] >= 64)
+ write_ptr[0] |= 1 << shift_count;
+ if (shift_count == 0) {
+ write_ptr++;
+ write_ptr[0] = 0;
+ shift_count = 6;
+ }
+ else
+ shift_count -= 2;
+ }
+ }
+ }
else if (page_get_depth (page) == 1) {
- int row, offset = 7;
+ int row, mask = 0x80;
guchar *write_ptr;
depth = 1;
color_space = "DeviceGray";
- data_length = (height * width + 7) / 8;
+ data_length = height * ((width + 7) / 8);
data = g_malloc (sizeof (guchar) * data_length);
write_ptr = data;
write_ptr[0] = 0;
@@ -484,16 +523,23 @@ book_save_pdf (Book *book, GFile *file, GError **error)
int x;
guchar *in_line;
+ /* Pad to the next line */
+ if (mask != 0x80) {
+ write_ptr++;
+ write_ptr[0] = 0;
+ mask = 0x80;
+ }
+
in_line = pixels + row * gdk_pixbuf_get_rowstride (image);
for (x = 0; x < width; x++) {
guchar *in_p = in_line + x*3;
- if (in_p[0])
- write_ptr[0] |= 1 << offset;
- offset--;
- if (offset < 0) {
+ if (in_p[0] != 0)
+ write_ptr[0] |= mask;
+ mask >>= 1;
+ if (mask == 0) {
write_ptr++;
write_ptr[0] = 0;
- offset = 7;
+ mask = 0x80;
}
}
}
@@ -583,9 +629,9 @@ book_save_pdf (Book *book, GFile *file, GError **error)
/* Page contents */
command = g_strdup_printf ("q\n"
- "%d 0 0 %d 0 0 cm\n"
+ "%f 0 0 %f 0 0 cm\n"
"/Im%d Do\n"
- "Q", width, height, i);
+ "Q", page_width, page_height, i);
pdf_printf (writer, "\n");
number = pdf_start_object (writer);
pdf_printf (writer, "%d 0 obj\n", number);