summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-04-04 23:46:49 +0200
committerTor Andersson <tor.andersson@artifex.com>2011-04-04 23:46:49 +0200
commita4e229f4a11ed93f3c5527c84ea7032342410a7c (patch)
tree18739f4a7dfdb33a959bed66790469de70e97c95
parent7cf6ccee8c6b59d8aac17ab6e4673bcb69f5e8d2 (diff)
downloadmupdf-a4e229f4a11ed93f3c5527c84ea7032342410a7c.tar.xz
android: Conform to coding convention.
Use tabs for indentation and no extra spaces to align stuff.
-rw-r--r--android/jni/mupdf.c348
-rw-r--r--android/src/com/artifex/mupdf/MuPDFActivity.java266
-rw-r--r--android/src/com/artifex/mupdf/MuPDFCore.java81
-rw-r--r--android/src/com/artifex/mupdf/PixmapView.java1125
-rw-r--r--fitz/crypt_aes.c282
5 files changed, 1045 insertions, 1057 deletions
diff --git a/android/jni/mupdf.c b/android/jni/mupdf.c
index c02c0f82..77ff39a2 100644
--- a/android/jni/mupdf.c
+++ b/android/jni/mupdf.c
@@ -10,203 +10,193 @@
#include "fitz.h"
#include "mupdf.h"
-#define LOG_TAG "libmupdf"
-#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
-#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
+#define LOG_TAG "libmupdf"
+#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
+#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
/* Set to 1 to enable debug log traces. */
#define DEBUG 0
/* Globals */
-fz_colorspace *colorspace;
-fz_glyph_cache *glyphcache;
-pdf_xref *xref;
-int pagenum = 1;
-int resolution = 160;
-float pageWidth = 100;
-float pageHeight = 100;
+fz_colorspace *colorspace;
+fz_glyph_cache *glyphcache;
+pdf_xref *xref;
+int pagenum = 1;
+int resolution = 160;
+float pageWidth = 100;
+float pageHeight = 100;
fz_display_list *currentPageList;
-fz_rect currentMediabox;
-int currentRotate;
+fz_rect currentMediabox;
+int currentRotate;
-JNIEXPORT int JNICALL Java_com_artifex_mupdf_MuPDFCore_openFile(JNIEnv * env, jobject thiz, jstring jfilename)
+JNIEXPORT int JNICALL
+Java_com_artifex_mupdf_MuPDFCore_openFile(JNIEnv * env, jobject thiz, jstring jfilename)
{
- const char *filename;
- char *password = "";
- int accelerate = 1;
- fz_error error;
-
- filename = (*env)->GetStringUTFChars(env, jfilename, NULL);
- if (filename == NULL)
- {
- LOGE("Failed to get filename");
- return 0;
- }
-
- if (accelerate)
- fz_accelerate();
- glyphcache = fz_new_glyph_cache();
- colorspace = fz_device_rgb;
-
- LOGE("Opening document...");
- error = pdf_open_xref(&xref, filename, password);
- if (error)
- {
- LOGE("Cannot open document: '%s'\n", filename);
- return 0;
- }
-
- LOGE("Loading page tree...");
- error = pdf_load_page_tree(xref);
- if (error)
- {
- LOGE("Cannot load page tree: '%s'\n", filename);
- return 0;
- }
- LOGE("Done! %d pages", pdf_get_page_count(xref));
-
- return pdf_get_page_count(xref);
+ const char *filename;
+ char *password = "";
+ int accelerate = 1;
+ fz_error error;
+
+ filename = (*env)->GetStringUTFChars(env, jfilename, NULL);
+ if (filename == NULL)
+ {
+ LOGE("Failed to get filename");
+ return 0;
+ }
+
+ if (accelerate)
+ fz_accelerate();
+ glyphcache = fz_new_glyph_cache();
+ colorspace = fz_device_rgb;
+
+ LOGE("Opening document...");
+ error = pdf_open_xref(&xref, filename, password);
+ if (error)
+ {
+ LOGE("Cannot open document: '%s'\n", filename);
+ return 0;
+ }
+
+ LOGE("Loading page tree...");
+ error = pdf_load_page_tree(xref);
+ if (error)
+ {
+ LOGE("Cannot load page tree: '%s'\n", filename);
+ return 0;
+ }
+ LOGE("Done! %d pages", pdf_get_page_count(xref));
+
+ return pdf_get_page_count(xref);
}
-JNIEXPORT void JNICALL Java_com_artifex_mupdf_MuPDFCore_gotoPageInternal(
- JNIEnv *env,
- jobject thiz,
- int page)
+JNIEXPORT void JNICALL
+Java_com_artifex_mupdf_MuPDFCore_gotoPageInternal(JNIEnv *env, jobject thiz, int page)
{
- float zoom;
- fz_matrix ctm;
- fz_obj *pageobj;
- fz_bbox bbox;
- fz_error error;
- fz_device *dev;
- pdf_page *currentPage;
-
- /* In the event of an error, ensure we give a non-empty page */
- pageWidth = 100;
- pageHeight = 100;
-
- LOGE("Goto page %d...", page);
- if (currentPageList != NULL)
- {
- fz_free_display_list(currentPageList);
- currentPageList = NULL;
- }
- pagenum = page;
- pageobj = pdf_get_page_object(xref, pagenum);
- if (pageobj == NULL)
- return;
- error = pdf_load_page(&currentPage, xref, pageobj);
- if (error)
- return;
- zoom = resolution / 72;
- currentMediabox = currentPage->mediabox;
- currentRotate = currentPage->rotate;
- ctm = fz_translate(0, -currentMediabox.y1);
- ctm = fz_concat(ctm, fz_scale(zoom, -zoom));
- ctm = fz_concat(ctm, fz_rotate(currentRotate));
- bbox = fz_round_rect(fz_transform_rect(ctm, currentMediabox));
- pageWidth = bbox.x1-bbox.x0;
- pageHeight = bbox.y1-bbox.y0;
- /* Render to list */
- currentPageList = fz_new_display_list();
- dev = fz_new_list_device(currentPageList);
- error = pdf_run_page(xref, currentPage, dev, fz_identity);
- pdf_free_page(currentPage);
- if (error)
- LOGE("cannot make displaylist from page %d", pagenum);
- fz_free_device(dev);
+ float zoom;
+ fz_matrix ctm;
+ fz_obj *pageobj;
+ fz_bbox bbox;
+ fz_error error;
+ fz_device *dev;
+ pdf_page *currentPage;
+
+ /* In the event of an error, ensure we give a non-empty page */
+ pageWidth = 100;
+ pageHeight = 100;
+
+ LOGE("Goto page %d...", page);
+ if (currentPageList != NULL)
+ {
+ fz_free_display_list(currentPageList);
+ currentPageList = NULL;
+ }
+ pagenum = page;
+ pageobj = pdf_get_page_object(xref, pagenum);
+ if (pageobj == NULL)
+ return;
+ error = pdf_load_page(&currentPage, xref, pageobj);
+ if (error)
+ return;
+ zoom = resolution / 72;
+ currentMediabox = currentPage->mediabox;
+ currentRotate = currentPage->rotate;
+ ctm = fz_translate(0, -currentMediabox.y1);
+ ctm = fz_concat(ctm, fz_scale(zoom, -zoom));
+ ctm = fz_concat(ctm, fz_rotate(currentRotate));
+ bbox = fz_round_rect(fz_transform_rect(ctm, currentMediabox));
+ pageWidth = bbox.x1-bbox.x0;
+ pageHeight = bbox.y1-bbox.y0;
+ /* Render to list */
+ currentPageList = fz_new_display_list();
+ dev = fz_new_list_device(currentPageList);
+ error = pdf_run_page(xref, currentPage, dev, fz_identity);
+ pdf_free_page(currentPage);
+ if (error)
+ LOGE("cannot make displaylist from page %d", pagenum);
+ fz_free_device(dev);
}
-JNIEXPORT float JNICALL Java_com_artifex_mupdf_MuPDFCore_getPageWidth(
- JNIEnv *env,
- jobject thiz)
+JNIEXPORT float JNICALL
+Java_com_artifex_mupdf_MuPDFCore_getPageWidth(JNIEnv *env, jobject thiz)
{
- LOGE("PageWidth=%g", pageWidth);
- return pageWidth;
+ LOGE("PageWidth=%g", pageWidth);
+ return pageWidth;
}
-JNIEXPORT float JNICALL Java_com_artifex_mupdf_MuPDFCore_getPageHeight(
- JNIEnv *env,
- jobject thiz)
+JNIEXPORT float JNICALL
+Java_com_artifex_mupdf_MuPDFCore_getPageHeight(JNIEnv *env, jobject thiz)
{
- LOGE("PageHeight=%g", pageHeight);
- return pageHeight;
+ LOGE("PageHeight=%g", pageHeight);
+ return pageHeight;
}
-JNIEXPORT jboolean JNICALL Java_com_artifex_mupdf_MuPDFCore_drawPage(
- JNIEnv *env,
- jobject thiz,
- jobject bitmap,
- int pageW,
- int pageH,
- int patchX,
- int patchY,
- int patchW,
- int patchH)
+JNIEXPORT jboolean JNICALL
+Java_com_artifex_mupdf_MuPDFCore_drawPage(JNIEnv *env, jobject thiz, jobject bitmap,
+ int pageW, int pageH, int patchX, int patchY, int patchW, int patchH)
{
- AndroidBitmapInfo info;
- void *pixels;
- int ret;
- fz_error error;
- fz_device *dev;
- float zoom;
- fz_matrix ctm;
- fz_bbox bbox;
- fz_pixmap *pix;
- float xscale, yscale;
-
- LOGI("In native method\n");
- if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) {
- LOGE("AndroidBitmap_getInfo() failed ! error=%d", ret);
- return 0;
- }
-
- LOGI("Checking format\n");
- if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {
- LOGE("Bitmap format is not RGBA_8888 !");
- return 0;
- }
-
- LOGI("locking pixels\n");
- if ((ret = AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) {
- LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret);
- return 0;
- }
-
- /* Call mupdf to render display list to screen */
- LOGE("Rendering page=%dx%d patch=[%d,%d,%d,%d]",
- pageW, pageH, patchX, patchY, patchW, patchH);
-
- pix = fz_new_pixmap_with_data(colorspace,
- patchX,
- patchY,
- patchW,
- patchH,
- pixels);
- if (currentPageList == NULL)
- {
- fz_clear_pixmap_with_color(pix, 0xd0);
- return 0;
- }
- fz_clear_pixmap_with_color(pix, 0xff);
-
- zoom = resolution / 72;
- ctm = fz_translate(0, -currentMediabox.y1);
- ctm = fz_concat(ctm, fz_scale(zoom, -zoom));
- ctm = fz_concat(ctm, fz_rotate(currentRotate));
- bbox = fz_round_rect(fz_transform_rect(ctm,currentMediabox));
- /* Now, adjust ctm so that it would give the correct page width
- * heights. */
- xscale = (float)pageW/(float)(bbox.x1-bbox.x0);
- yscale = (float)pageH/(float)(bbox.y1-bbox.y0);
- ctm = fz_concat(ctm, fz_scale(xscale, yscale));
- dev = fz_new_draw_device(glyphcache, pix);
- fz_execute_display_list(currentPageList, dev, ctm);
- fz_free_device(dev);
- fz_drop_pixmap(pix);
- LOGE("Rendered");
-
- AndroidBitmap_unlockPixels(env, bitmap);
-
- return 1;
+ AndroidBitmapInfo info;
+ void *pixels;
+ int ret;
+ fz_error error;
+ fz_device *dev;
+ float zoom;
+ fz_matrix ctm;
+ fz_bbox bbox;
+ fz_pixmap *pix;
+ float xscale, yscale;
+
+ LOGI("In native method\n");
+ if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) {
+ LOGE("AndroidBitmap_getInfo() failed ! error=%d", ret);
+ return 0;
+ }
+
+ LOGI("Checking format\n");
+ if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {
+ LOGE("Bitmap format is not RGBA_8888 !");
+ return 0;
+ }
+
+ LOGI("locking pixels\n");
+ if ((ret = AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) {
+ LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret);
+ return 0;
+ }
+
+ /* Call mupdf to render display list to screen */
+ LOGE("Rendering page=%dx%d patch=[%d,%d,%d,%d]",
+ pageW, pageH, patchX, patchY, patchW, patchH);
+
+ pix = fz_new_pixmap_with_data(colorspace,
+ patchX,
+ patchY,
+ patchW,
+ patchH,
+ pixels);
+ if (currentPageList == NULL)
+ {
+ fz_clear_pixmap_with_color(pix, 0xd0);
+ return 0;
+ }
+ fz_clear_pixmap_with_color(pix, 0xff);
+
+ zoom = resolution / 72;
+ ctm = fz_translate(0, -currentMediabox.y1);
+ ctm = fz_concat(ctm, fz_scale(zoom, -zoom));
+ ctm = fz_concat(ctm, fz_rotate(currentRotate));
+ bbox = fz_round_rect(fz_transform_rect(ctm,currentMediabox));
+ /* Now, adjust ctm so that it would give the correct page width
+ * heights. */
+ xscale = (float)pageW/(float)(bbox.x1-bbox.x0);
+ yscale = (float)pageH/(float)(bbox.y1-bbox.y0);
+ ctm = fz_concat(ctm, fz_scale(xscale, yscale));
+ dev = fz_new_draw_device(glyphcache, pix);
+ fz_execute_display_list(currentPageList, dev, ctm);
+ fz_free_device(dev);
+ fz_drop_pixmap(pix);
+ LOGE("Rendered");
+
+ AndroidBitmap_unlockPixels(env, bitmap);
+
+ return 1;
}
diff --git a/android/src/com/artifex/mupdf/MuPDFActivity.java b/android/src/com/artifex/mupdf/MuPDFActivity.java
index 10c69f4f..0561f01b 100644
--- a/android/src/com/artifex/mupdf/MuPDFActivity.java
+++ b/android/src/com/artifex/mupdf/MuPDFActivity.java
@@ -13,137 +13,137 @@ import com.artifex.mupdf.PixmapView;
public class MuPDFActivity extends Activity
{
- /* The core rendering instance */
- private MuPDFCore core;
-
- private MuPDFCore openFile()
- {
- String storageState = Environment.getExternalStorageState();
- File path, file;
- MuPDFCore core;
-
- if (Environment.MEDIA_MOUNTED.equals(storageState))
- {
- System.out.println("Media mounted read/write");
- }
- else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(storageState))
- {
- System.out.println("Media mounted read only");
- }
- else
- {
- System.out.println("No media at all! Bale!\n");
- return null;
- }
- path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
- file = new File(path, "test.pdf");
- System.out.println("Trying to open "+file.toString());
- try
- {
- core = new MuPDFCore(file.toString());
- }
- catch (Exception e)
- {
- System.out.println(e);
- return null;
- }
- return core;
- }
-
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- PixmapView pixmapView;
-
- core = (MuPDFCore)getLastNonConfigurationInstance();
- if (core == null)
- core = openFile();
- if (core == null)
- {
- /* FIXME: Error handling here! */
- return;
- }
-
- pixmapView = new PixmapView(this, core);
- super.onCreate(savedInstanceState);
-
- /* Now create the UI */
- RelativeLayout layout;
- LinearLayout bar;
- MyButtonHandler bh = new MyButtonHandler(pixmapView);
-
- bar = new LinearLayout(this);
- bar.setOrientation(LinearLayout.HORIZONTAL);
- bh.buttonStart = new Button(this);
- bh.buttonStart.setText("<<");
- bh.buttonStart.setOnClickListener(bh);
- bar.addView(bh.buttonStart);
- bh.buttonPrev = new Button(this);
- bh.buttonPrev.setText("<");
- bh.buttonPrev.setOnClickListener(bh);
- bar.addView(bh.buttonPrev);
- bh.buttonNext = new Button(this);
- bh.buttonNext.setText(">");
- bh.buttonNext.setOnClickListener(bh);
- bar.addView(bh.buttonNext);
- bh.buttonEnd = new Button(this);
- bh.buttonEnd.setText(">>");
- bh.buttonEnd.setOnClickListener(bh);
- bar.addView(bh.buttonEnd);
-
- layout = new RelativeLayout(this);
- layout.setLayoutParams(new RelativeLayout.LayoutParams(
- RelativeLayout.LayoutParams.FILL_PARENT,
- RelativeLayout.LayoutParams.FILL_PARENT));
- layout.setGravity(Gravity.FILL);
-
- RelativeLayout.LayoutParams barParams =
- new RelativeLayout.LayoutParams(
- RelativeLayout.LayoutParams.FILL_PARENT,
- RelativeLayout.LayoutParams.WRAP_CONTENT);
- barParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
- bar.setId(100);
- layout.addView(bar, barParams);
-
- RelativeLayout.LayoutParams pixmapParams =
- new RelativeLayout.LayoutParams(
- RelativeLayout.LayoutParams.FILL_PARENT,
- RelativeLayout.LayoutParams.FILL_PARENT);
- pixmapParams.addRule(RelativeLayout.ABOVE,100);
- layout.addView(pixmapView, pixmapParams);
-
- setContentView(layout);
- }
-
- public Object onRetainNonConfigurationInstance()
- {
- return core;
- }
-
- private class MyButtonHandler implements OnClickListener
- {
- Button buttonStart;
- Button buttonPrev;
- Button buttonNext;
- Button buttonEnd;
- PixmapView pixmapView;
-
- public MyButtonHandler(PixmapView pixmapView)
- {
- this.pixmapView = pixmapView;
- }
-
- public void onClick(View v)
- {
- if (v == buttonStart)
- pixmapView.changePage(Integer.MIN_VALUE);
- else if (v == buttonPrev)
- pixmapView.changePage(-1);
- else if (v == buttonNext)
- pixmapView.changePage(+1);
- else if (v == buttonEnd)
- pixmapView.changePage(Integer.MAX_VALUE);
- }
- }
+ /* The core rendering instance */
+ private MuPDFCore core;
+
+ private MuPDFCore openFile()
+ {
+ String storageState = Environment.getExternalStorageState();
+ File path, file;
+ MuPDFCore core;
+
+ if (Environment.MEDIA_MOUNTED.equals(storageState))
+ {
+ System.out.println("Media mounted read/write");
+ }
+ else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(storageState))
+ {
+ System.out.println("Media mounted read only");
+ }
+ else
+ {
+ System.out.println("No media at all! Bale!\n");
+ return null;
+ }
+ path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
+ file = new File(path, "test.pdf");
+ System.out.println("Trying to open "+file.toString());
+ try
+ {
+ core = new MuPDFCore(file.toString());
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ return null;
+ }
+ return core;
+ }
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ PixmapView pixmapView;
+
+ core = (MuPDFCore)getLastNonConfigurationInstance();
+ if (core == null)
+ core = openFile();
+ if (core == null)
+ {
+ /* FIXME: Error handling here! */
+ return;
+ }
+
+ pixmapView = new PixmapView(this, core);
+ super.onCreate(savedInstanceState);
+
+ /* Now create the UI */
+ RelativeLayout layout;
+ LinearLayout bar;
+ MyButtonHandler bh = new MyButtonHandler(pixmapView);
+
+ bar = new LinearLayout(this);
+ bar.setOrientation(LinearLayout.HORIZONTAL);
+ bh.buttonStart = new Button(this);
+ bh.buttonStart.setText("<<");
+ bh.buttonStart.setOnClickListener(bh);
+ bar.addView(bh.buttonStart);
+ bh.buttonPrev = new Button(this);
+ bh.buttonPrev.setText("<");
+ bh.buttonPrev.setOnClickListener(bh);
+ bar.addView(bh.buttonPrev);
+ bh.buttonNext = new Button(this);
+ bh.buttonNext.setText(">");
+ bh.buttonNext.setOnClickListener(bh);
+ bar.addView(bh.buttonNext);
+ bh.buttonEnd = new Button(this);
+ bh.buttonEnd.setText(">>");
+ bh.buttonEnd.setOnClickListener(bh);
+ bar.addView(bh.buttonEnd);
+
+ layout = new RelativeLayout(this);
+ layout.setLayoutParams(new RelativeLayout.LayoutParams(
+ RelativeLayout.LayoutParams.FILL_PARENT,
+ RelativeLayout.LayoutParams.FILL_PARENT));
+ layout.setGravity(Gravity.FILL);
+
+ RelativeLayout.LayoutParams barParams =
+ new RelativeLayout.LayoutParams(
+ RelativeLayout.LayoutParams.FILL_PARENT,
+ RelativeLayout.LayoutParams.WRAP_CONTENT);
+ barParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
+ bar.setId(100);
+ layout.addView(bar, barParams);
+
+ RelativeLayout.LayoutParams pixmapParams =
+ new RelativeLayout.LayoutParams(
+ RelativeLayout.LayoutParams.FILL_PARENT,
+ RelativeLayout.LayoutParams.FILL_PARENT);
+ pixmapParams.addRule(RelativeLayout.ABOVE,100);
+ layout.addView(pixmapView, pixmapParams);
+
+ setContentView(layout);
+ }
+
+ public Object onRetainNonConfigurationInstance()
+ {
+ return core;
+ }
+
+ private class MyButtonHandler implements OnClickListener
+ {
+ Button buttonStart;
+ Button buttonPrev;
+ Button buttonNext;
+ Button buttonEnd;
+ PixmapView pixmapView;
+
+ public MyButtonHandler(PixmapView pixmapView)
+ {
+ this.pixmapView = pixmapView;
+ }
+
+ public void onClick(View v)
+ {
+ if (v == buttonStart)
+ pixmapView.changePage(Integer.MIN_VALUE);
+ else if (v == buttonPrev)
+ pixmapView.changePage(-1);
+ else if (v == buttonNext)
+ pixmapView.changePage(+1);
+ else if (v == buttonEnd)
+ pixmapView.changePage(Integer.MAX_VALUE);
+ }
+ }
}
diff --git a/android/src/com/artifex/mupdf/MuPDFCore.java b/android/src/com/artifex/mupdf/MuPDFCore.java
index 245ffdc0..28408516 100644
--- a/android/src/com/artifex/mupdf/MuPDFCore.java
+++ b/android/src/com/artifex/mupdf/MuPDFCore.java
@@ -3,50 +3,47 @@ import android.graphics.*;
public class MuPDFCore
{
- /* load our native library */
- static {
- System.loadLibrary("mupdf");
- }
+ /* load our native library */
+ static {
+ System.loadLibrary("mupdf");
+ }
- /* Readable members */
- public int pageNum;
- public int numPages;
- public float pageWidth;
- public float pageHeight;
+ /* Readable members */
+ public int pageNum;
+ public int numPages;
+ public float pageWidth;
+ public float pageHeight;
- /* The native functions */
- private static native int openFile(String filename);
- private static native void gotoPageInternal(int localActionPageNum);
- private static native float getPageWidth();
- private static native float getPageHeight();
- public static native void drawPage(Bitmap bitmap,
- int pageW,
- int pageH,
- int patchX,
- int patchY,
- int patchW,
- int patchH);
+ /* The native functions */
+ private static native int openFile(String filename);
+ private static native void gotoPageInternal(int localActionPageNum);
+ private static native float getPageWidth();
+ private static native float getPageHeight();
+ public static native void drawPage(Bitmap bitmap,
+ int pageW, int pageH,
+ int patchX, int patchY,
+ int patchW, int patchH);
- public MuPDFCore(String filename) throws Exception
- {
- numPages = openFile(filename);
- if (numPages <= 0)
- {
- throw new Exception("Failed to open "+filename);
- }
- pageNum = 1;
- }
+ public MuPDFCore(String filename) throws Exception
+ {
+ numPages = openFile(filename);
+ if (numPages <= 0)
+ {
+ throw new Exception("Failed to open "+filename);
+ }
+ pageNum = 1;
+ }
- /* Shim function */
- public void gotoPage(int page)
- {
- if (page > numPages)
- page = numPages;
- else if (page < 1)
- page = 1;
- gotoPageInternal(page);
- this.pageNum = page;
- this.pageWidth = getPageWidth();
- this.pageHeight = getPageHeight();
- }
+ /* Shim function */
+ public void gotoPage(int page)
+ {
+ if (page > numPages)
+ page = numPages;
+ else if (page < 1)
+ page = 1;
+ gotoPageInternal(page);
+ this.pageNum = page;
+ this.pageWidth = getPageWidth();
+ this.pageHeight = getPageHeight();
+ }
}
diff --git a/android/src/com/artifex/mupdf/PixmapView.java b/android/src/com/artifex/mupdf/PixmapView.java
index f3b99f01..c7ba9d72 100644
--- a/android/src/com/artifex/mupdf/PixmapView.java
+++ b/android/src/com/artifex/mupdf/PixmapView.java
@@ -13,566 +13,567 @@ import java.io.*;
public class PixmapView extends SurfaceView implements SurfaceHolder.Callback
{
- private SurfaceHolder holder;
- private MuPDFThread thread = null;
- private boolean threadStarted = false;
- private MuPDFCore core;
-
- /* Constructor */
- public PixmapView(Context context, MuPDFCore core)
- {
- super(context);
- System.out.println("PixmapView construct");
- this.core = core;
- holder = getHolder();
- holder.addCallback(this);
- thread = new MuPDFThread(holder, core);
- setFocusable(true); // need to get the key events
- }
-
- /* load our native library */
- static {
- System.loadLibrary("mupdf");
- }
-
- /* Handlers for keys - so we can actually do stuff */
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
- if (thread.onKeyDown(keyCode, event))
- return true;
- return super.onKeyDown(keyCode, event);
- }
-
- @Override
- public boolean onKeyUp(int keyCode, KeyEvent event)
- {
- if (thread.onKeyUp(keyCode, event))
- return true;
- return super.onKeyUp(keyCode, event);
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent event)
- {
- if (thread.onTouchEvent(event))
- return true;
- return super.onTouchEvent(event);
- }
-
- public void changePage(int delta)
- {
- thread.changePage(delta);
- }
-
- /* Handlers for SurfaceHolder callbacks; these are called when the
- * surface is created/destroyed/changed. We need to ensure that we only
- * draw into the surface between the created and destroyed calls.
- * Therefore, we start/stop the thread that actually runs MuPDF on
- * creation/destruction. */
- public void surfaceCreated(SurfaceHolder holder)
- {
- }
-
- public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
- {
- thread.newScreenSize(width, height);
- if (!threadStarted)
- {
- threadStarted = true;
- thread.setRunning(true);
- thread.start();
- }
- }
-
- public void surfaceDestroyed(SurfaceHolder holder)
- {
- boolean retry = true;
- System.out.println("Surface destroyed 1 this="+this);
- thread.setRunning(false);
- System.out.println("Surface destroyed 2");
- while (retry)
- {
- try
- {
- thread.join();
- retry = false;
- }
- catch (InterruptedException e)
- {
- }
- }
- threadStarted = false;
- System.out.println("Surface destroyed 3");
- }
-
- class MuPDFThread extends Thread
- {
- private SurfaceHolder holder;
- private boolean running = false;
- private int keycode = -1;
- private int screenWidth;
- private int screenHeight;
- private int screenGeneration;
- private Bitmap bitmap;
- private MuPDFCore core;
-
- /* The following variables deal with the size of the current page;
- * specifically, its position on the screen, its raw size, its
- * current scale, and its current scaled size (in terms of whole
- * pixels).
- */
- private int pageOriginX;
- private int pageOriginY;
- private float pageScale;
- private int pageWidth;
- private int pageHeight;
-
- /* The following variables deal with the multitouch handling */
- private final int NONE = 0;
- private final int DRAG = 1;
- private final int ZOOM = 2;
- private int touchMode = NONE;
- private float touchInitialSpacing;
- private float touchDragStartX;
- private float touchDragStartY;
- private float touchInitialOriginX;
- private float touchInitialOriginY;
- private float touchInitialScale;
- private PointF touchZoomMidpoint;
-
- /* The following control the inner loop; other events etc cause
- * action to be set. The inner loop runs around a tight loop
- * performing the action requested of it.
- */
- private boolean wakeMe = false;
- private int action;
- private final int SLEEP = 0;
- private final int REDRAW = 1;
- private final int DIE = 2;
- private final int GOTOPAGE = 3;
- private int actionPageNum;
-
- /* Members for blitting, declared here to avoid causing gcs */
- private Rect srcRect;
- private RectF dstRect;
-
- public MuPDFThread(SurfaceHolder holder, MuPDFCore core)
- {
- this.holder = holder;
- this.core = core;
- touchZoomMidpoint = new PointF(0,0);
- srcRect = new Rect(0,0,0,0);
- dstRect = new RectF(0,0,0,0);
- }
-
- public void setRunning(boolean running)
- {
- this.running = running;
- if (!running)
- {
- System.out.println("killing 1");
- synchronized(this)
- {
- System.out.println("killing 2");
- action = DIE;
- if (wakeMe)
- {
- wakeMe = false;
- System.out.println("killing 3");
- this.notify();
- System.out.println("killing 4");
- }
- }
- }
- }
-
- public void newScreenSize(int width, int height)
- {
- this.screenWidth = width;
- this.screenHeight = height;
- this.screenGeneration++;
- }
-
- public boolean onKeyDown(int keyCode, KeyEvent msg)
- {
- keycode = keyCode;
- return false;
- }
-
- public boolean onKeyUp(int keyCode, KeyEvent msg)
- {
- return false;
- }
-
- public synchronized void changePage(int delta)
- {
- action = GOTOPAGE;
- if (delta == Integer.MIN_VALUE)
- actionPageNum = 1;
- else if (delta == Integer.MAX_VALUE)
- actionPageNum = core.numPages;
- else
- {
- actionPageNum += delta;
- if (actionPageNum < 1)
- actionPageNum = 1;
- if (actionPageNum > core.numPages)
- actionPageNum = core.numPages;
- }
- if (wakeMe)
- {
- wakeMe = false;
- this.notify();
- }
- }
-
- private float spacing(MotionEvent event)
- {
- float x = event.getX(0) - event.getX(1);
- float y = event.getY(0) - event.getY(1);
- return FloatMath.sqrt(x*x+y*y);
- }
-
- private void midpoint(PointF point, MotionEvent event)
- {
- float x = event.getX(0) + event.getX(1);
- float y = event.getY(0) + event.getY(1);
- point.set(x/2, y/2);
- }
-
- private synchronized void forceRedraw()
- {
- if (wakeMe)
- {
- wakeMe = false;
- this.notify();
- }
- action = REDRAW;
- }
-
- public synchronized void setPageOriginTo(int x, int y)
- {
- /* Adjust the coordinates so that the page always covers the
- * centre of the screen. */
- if (x + pageWidth < screenWidth/2)
- {
- x = screenWidth/2 - pageWidth;
- }
- else if (x > screenWidth/2)
- {
- x = screenWidth/2;
- }
- if (y + pageHeight < screenHeight/2)
- {
- y = screenHeight/2 - pageHeight;
- }
- else if (y > screenHeight/2)
- {
- y = screenHeight/2;
- }
- if ((x != pageOriginX) || (y != pageOriginY))
- {
- pageOriginX = x;
- pageOriginY = y;
- }
- forceRedraw();
- }
-
- public void setPageScaleTo(float scale, PointF midpoint)
- {
- float x, y;
- /* Convert midpoint (in screen coords) to page coords */
- x = (midpoint.x - pageOriginX)/pageScale;
- y = (midpoint.y - pageOriginY)/pageScale;
- /* Find new scaled page sizes */
- synchronized(this)
- {
- pageWidth = (int)(core.pageWidth*scale+0.5);
- if (pageWidth < screenWidth/2)
- {
- scale = screenWidth/2/core.pageWidth;
- pageWidth = (int)(core.pageWidth*scale+0.5);
- }
- pageHeight = (int)(core.pageHeight*scale+0.5);
- if (pageHeight < screenHeight/2)
- {
- scale = screenHeight/2/core.pageHeight;
- pageWidth = (int)(core.pageWidth *scale+0.5);
- pageHeight = (int)(core.pageHeight*scale+0.5);
- }
- pageScale = scale;
- /* Now given this new scale, calculate page origins so that
- * x and y are at midpoint */
- float xscale = (float)pageWidth /core.pageWidth;
- float yscale = (float)pageHeight/core.pageHeight;
- setPageOriginTo((int)(midpoint.x - x*xscale + 0.5),
- (int)(midpoint.y - y*yscale + 0.5));
- }
- }
-
- public void scalePageToScreen()
- {
- float scaleX, scaleY;
- scaleX = (float)screenWidth /core.pageWidth;
- scaleY = (float)screenHeight/core.pageHeight;
- synchronized(this)
- {
- if (scaleX < scaleY)
- pageScale = scaleX;
- else
- pageScale = scaleY;
- pageWidth = (int)(core.pageWidth * pageScale + 0.5);
- pageHeight = (int)(core.pageHeight * pageScale + 0.5);
- pageOriginX = (screenWidth - pageWidth)/2;
- pageOriginY = (screenHeight - pageHeight)/2;
- forceRedraw();
- }
- System.out.println("scalePageToScreen: Raw="+
- core.pageWidth+"x"+core.pageHeight+" scaled="+
- pageWidth+","+pageHeight+" pageScale="+
- pageScale);
- }
-
- public boolean onTouchEvent(MotionEvent event)
- {
- int action = event.getAction();
- boolean done = false;
- switch (action & MotionEvent.ACTION_MASK)
- {
- case MotionEvent.ACTION_DOWN:
- touchMode = DRAG;
- touchDragStartX = event.getX();
- touchDragStartY = event.getY();
- touchInitialOriginX = pageOriginX;
- touchInitialOriginY = pageOriginY;
- System.out.println("Starting dragging from: "+touchDragStartX+","+touchDragStartY+" ("+pageOriginX+","+pageOriginY+")");
- done = true;
- break;
- case MotionEvent.ACTION_POINTER_DOWN:
- touchInitialSpacing = spacing(event);
- if (touchInitialSpacing > 10f)
- {
- System.out.println("Started zooming: spacing="+touchInitialSpacing);
- touchInitialScale = pageScale;
- touchMode = ZOOM;
- done = true;
- }
- break;
- case MotionEvent.ACTION_UP:
- case MotionEvent.ACTION_POINTER_UP:
- if (touchMode != NONE)
- {
- System.out.println("Released!");
- touchMode = NONE;
- done = true;
- }
- break;
- case MotionEvent.ACTION_MOVE:
- if (touchMode == DRAG)
- {
- float x = touchInitialOriginX+event.getX()-touchDragStartX;
- float y = touchInitialOriginY+event.getY()-touchDragStartY;
- System.out.println("Dragged to "+x+","+y);
- setPageOriginTo((int)(x+0.5),(int)(y+0.5));
- done = true;
- }
- else if (touchMode == ZOOM)
- {
- float newSpacing = spacing(event);
- if (newSpacing > 10f)
- {
- float newScale = touchInitialScale*newSpacing/touchInitialSpacing;
- System.out.println("Zoomed to "+newSpacing);
- midpoint(touchZoomMidpoint,event);
- setPageScaleTo(newScale,touchZoomMidpoint);
- done = true;
- }
- }
- }
- return done;
- }
-
- public void run()
- {
- boolean redraw = false;
- int patchW = 0;
- int patchH = 0;
- int patchX = 0;
- int patchY = 0;
- int localPageW = 0;
- int localPageH = 0;
- int localScreenGeneration = screenGeneration;
- int localAction;
- int localActionPageNum = core.pageNum;
- /* Set up our default action */
- action = GOTOPAGE;
- actionPageNum = core.pageNum;
- while (action != DIE)
- {
- synchronized(this)
- {
- while (action == SLEEP)
- {
- wakeMe = true;
- try
- {
- System.out.println("Render thread sleeping");
- this.wait();
- System.out.println("Render thread woken");
- }
- catch (java.lang.InterruptedException e)
- {
- System.out.println("Render thread exception:"+e);
- }
- }
- /* Now we do as little as we can get away with while
- * synchronised. In general this means copying any action
- * or global variables into local ones so that when we
- * unsynchronoise, other people can alter them again.
- */
- switch (action)
- {
- case DIE:
- System.out.println("Woken to die!");
- break;
- case GOTOPAGE:
- localActionPageNum = actionPageNum;
- break;
- case REDRAW:
- /* Figure out what area of the page we want to
- * redraw (in local variables, in docspace).
- * We'll always draw a screensized lump, unless
- * that's too big. */
- System.out.println("page="+pageWidth+","+pageHeight+" ("+core.pageWidth+","+core.pageHeight+"@"+pageScale+") @ "+pageOriginX+","+pageOriginY);
- localPageW = pageWidth;
- localPageH = pageHeight;
- patchW = pageWidth;
- patchH = pageHeight;
- patchX = -pageOriginX;
- patchY = -pageOriginY;
- if (patchX < 0)
- patchX = 0;
- if (patchW > screenWidth)
- patchW = screenWidth;
- srcRect.left = 0;
- if (patchX+patchW > pageWidth)
- {
- srcRect.left += patchX+patchW-pageWidth;
- patchX = pageWidth-patchW;
- }
- if (patchY < 0)
- patchY = 0;
- if (patchH > screenHeight)
- patchH = screenHeight;
- srcRect.top = 0;
- if (patchY+patchH > pageHeight)
- {
- srcRect.top += patchY+patchH-pageHeight;
- patchY = pageHeight-patchH;
- }
- dstRect.left = pageOriginX;
- if (dstRect.left < 0)
- dstRect.left = 0;
- dstRect.top = pageOriginY;
- if (dstRect.top < 0)
- dstRect.top = 0;
- dstRect.right = dstRect.left + patchW;
- srcRect.right = srcRect.left + patchW;
- if (srcRect.right > screenWidth)
- {
- dstRect.right -= srcRect.right-screenWidth;
- srcRect.right = screenWidth;
- }
- if (dstRect.right > screenWidth)
- {
- srcRect.right -= dstRect.right-screenWidth;
- dstRect.right = screenWidth;
- }
- dstRect.bottom = dstRect.top + patchH;
- srcRect.bottom = srcRect.top + patchH;
- if (srcRect.bottom > screenHeight)
- {
- dstRect.bottom -=srcRect.bottom-screenHeight;
- srcRect.bottom = screenHeight;
- }
- if (dstRect.bottom > screenHeight)
- {
- srcRect.bottom -=dstRect.bottom-screenHeight;
- dstRect.bottom = screenHeight;
- }
- System.out.println("patch=["+patchX+","+patchY+","+patchW+","+patchH+"]");
- break;
- }
- localAction = action;
- if (action != DIE)
- action = SLEEP;
- }
- /* In the redraw case:
- * pW, pH, pX, pY, localPageW, localPageH are now all set
- * in local variables, and we are safe from the global vars
- * being altered in calls from other threads. This is all
- * the information we need to actually do our render.
- */
- switch (localAction)
- {
- case GOTOPAGE:
- core.gotoPage(localActionPageNum);
- scalePageToScreen();
- action = REDRAW;
- break;
- case REDRAW:
- if ((bitmap == null) ||
- (bitmap.getWidth() != patchW) ||
- (bitmap.getHeight() != patchH))
- {
- /* make bitmap of required size */
- bitmap = Bitmap.createBitmap(patchW, patchH,
- Bitmap.Config.ARGB_8888);
- }
- System.out.println("Calling redraw native method");
- core.drawPage(bitmap, localPageW, localPageH,
- patchX, patchY, patchW, patchH);
- System.out.println("Called native method");
- {
- Canvas c = null;
- try
- {
- c = holder.lockCanvas(null);
- synchronized(holder)
- {
- if (localScreenGeneration == screenGeneration)
- {
- doDraw(c);
- }
- else
- {
- /* Someone has changed the screen
- * under us! Better redraw again...
- */
- action = REDRAW;
- }
- }
- }
- finally
- {
- if (c != null)
- holder.unlockCanvasAndPost(c);
- }
- }
- }
- }
- }
-
- protected void doDraw(Canvas canvas)
- {
- if ((canvas == null) || (bitmap == null))
- return;
- /* Clear the screen */
- canvas.drawRGB(128,128,128);
- /* Draw our bitmap on top */
- System.out.println("Blitting bitmap from "+srcRect.left+","+srcRect.top+","+srcRect.right+","+srcRect.bottom+" to "+dstRect.left+","+dstRect.top+","+dstRect.right+","+dstRect.bottom);
- canvas.drawBitmap(bitmap, srcRect, dstRect, (Paint)null);
- }
- }
+ private SurfaceHolder holder;
+ private MuPDFThread thread = null;
+ private boolean threadStarted = false;
+ private MuPDFCore core;
+
+ /* Constructor */
+ public PixmapView(Context context, MuPDFCore core)
+ {
+ super(context);
+ System.out.println("PixmapView construct");
+ this.core = core;
+ holder = getHolder();
+ holder.addCallback(this);
+ thread = new MuPDFThread(holder, core);
+ setFocusable(true); // need to get the key events
+ }
+
+ /* load our native library */
+ static {
+ System.loadLibrary("mupdf");
+ }
+
+ /* Handlers for keys - so we can actually do stuff */
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event)
+ {
+ if (thread.onKeyDown(keyCode, event))
+ return true;
+ return super.onKeyDown(keyCode, event);
+ }
+
+ @Override
+ public boolean onKeyUp(int keyCode, KeyEvent event)
+ {
+ if (thread.onKeyUp(keyCode, event))
+ return true;
+ return super.onKeyUp(keyCode, event);
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event)
+ {
+ if (thread.onTouchEvent(event))
+ return true;
+ return super.onTouchEvent(event);
+ }
+
+ public void changePage(int delta)
+ {
+ thread.changePage(delta);
+ }
+
+ /* Handlers for SurfaceHolder callbacks; these are called when the
+ * surface is created/destroyed/changed. We need to ensure that we only
+ * draw into the surface between the created and destroyed calls.
+ * Therefore, we start/stop the thread that actually runs MuPDF on
+ * creation/destruction. */
+ public void surfaceCreated(SurfaceHolder holder)
+ {
+ }
+
+ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
+ {
+ thread.newScreenSize(width, height);
+ if (!threadStarted)
+ {
+ threadStarted = true;
+ thread.setRunning(true);
+ thread.start();
+ }
+ }
+
+ public void surfaceDestroyed(SurfaceHolder holder)
+ {
+ boolean retry = true;
+ System.out.println("Surface destroyed 1 this="+this);
+ thread.setRunning(false);
+ System.out.println("Surface destroyed 2");
+ while (retry)
+ {
+ try
+ {
+ thread.join();
+ retry = false;
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+ threadStarted = false;
+ System.out.println("Surface destroyed 3");
+ }
+
+ class MuPDFThread extends Thread
+ {
+ private SurfaceHolder holder;
+ private boolean running = false;
+ private int keycode = -1;
+ private int screenWidth;
+ private int screenHeight;
+ private int screenGeneration;
+ private Bitmap bitmap;
+ private MuPDFCore core;
+
+ /* The following variables deal with the size of the current page;
+ * specifically, its position on the screen, its raw size, its
+ * current scale, and its current scaled size (in terms of whole
+ * pixels).
+ */
+ private int pageOriginX;
+ private int pageOriginY;
+ private float pageScale;
+ private int pageWidth;
+ private int pageHeight;
+
+ /* The following variables deal with the multitouch handling */
+ private final int NONE = 0;
+ private final int DRAG = 1;
+ private final int ZOOM = 2;
+ private int touchMode = NONE;
+ private float touchInitialSpacing;
+ private float touchDragStartX;
+ private float touchDragStartY;
+ private float touchInitialOriginX;
+ private float touchInitialOriginY;
+ private float touchInitialScale;
+ private PointF touchZoomMidpoint;
+
+ /* The following control the inner loop; other events etc cause
+ * action to be set. The inner loop runs around a tight loop
+ * performing the action requested of it.
+ */
+ private boolean wakeMe = false;
+ private int action;
+ private final int SLEEP = 0;
+ private final int REDRAW = 1;
+ private final int DIE = 2;
+ private final int GOTOPAGE = 3;
+ private int actionPageNum;
+
+ /* Members for blitting, declared here to avoid causing gcs */
+ private Rect srcRect;
+ private RectF dstRect;
+
+ public MuPDFThread(SurfaceHolder holder, MuPDFCore core)
+ {
+ this.holder = holder;
+ this.core = core;
+ touchZoomMidpoint = new PointF(0,0);
+ srcRect = new Rect(0,0,0,0);
+ dstRect = new RectF(0,0,0,0);
+ }
+
+ public void setRunning(boolean running)
+ {
+ this.running = running;
+ if (!running)
+ {
+ System.out.println("killing 1");
+ synchronized(this)
+ {
+ System.out.println("killing 2");
+ action = DIE;
+ if (wakeMe)
+ {
+ wakeMe = false;
+ System.out.println("killing 3");
+ this.notify();
+ System.out.println("killing 4");
+ }
+ }
+ }
+ }
+
+ public void newScreenSize(int width, int height)
+ {
+ this.screenWidth = width;
+ this.screenHeight = height;
+ this.screenGeneration++;
+ }
+
+ public boolean onKeyDown(int keyCode, KeyEvent msg)
+ {
+ keycode = keyCode;
+ return false;
+ }
+
+ public boolean onKeyUp(int keyCode, KeyEvent msg)
+ {
+ return false;
+ }
+
+ public synchronized void changePage(int delta)
+ {
+ action = GOTOPAGE;
+ if (delta == Integer.MIN_VALUE)
+ actionPageNum = 1;
+ else if (delta == Integer.MAX_VALUE)
+ actionPageNum = core.numPages;
+ else
+ {
+ actionPageNum += delta;
+ if (actionPageNum < 1)
+ actionPageNum = 1;
+ if (actionPageNum > core.numPages)
+ actionPageNum = core.numPages;
+ }
+ if (wakeMe)
+ {
+ wakeMe = false;
+ this.notify();
+ }
+ }
+
+ private float spacing(MotionEvent event)
+ {
+ float x = event.getX(0) - event.getX(1);
+ float y = event.getY(0) - event.getY(1);
+ return FloatMath.sqrt(x*x+y*y);
+ }
+
+ private void midpoint(PointF point, MotionEvent event)
+ {
+ float x = event.getX(0) + event.getX(1);
+ float y = event.getY(0) + event.getY(1);
+ point.set(x/2, y/2);
+ }
+
+ private synchronized void forceRedraw()
+ {
+ if (wakeMe)
+ {
+ wakeMe = false;
+ this.notify();
+ }
+ action = REDRAW;
+ }
+
+ public synchronized void setPageOriginTo(int x, int y)
+ {
+ /* Adjust the coordinates so that the page always covers the
+ * centre of the screen. */
+ if (x + pageWidth < screenWidth/2)
+ {
+ x = screenWidth/2 - pageWidth;
+ }
+ else if (x > screenWidth/2)
+ {
+ x = screenWidth/2;
+ }
+ if (y + pageHeight < screenHeight/2)
+ {
+ y = screenHeight/2 - pageHeight;
+ }
+ else if (y > screenHeight/2)
+ {
+ y = screenHeight/2;
+ }
+ if ((x != pageOriginX) || (y != pageOriginY))
+ {
+ pageOriginX = x;
+ pageOriginY = y;
+ }
+ forceRedraw();
+ }
+
+ public void setPageScaleTo(float scale, PointF midpoint)
+ {
+ float x, y;
+ /* Convert midpoint (in screen coords) to page coords */
+ x = (midpoint.x - pageOriginX)/pageScale;
+ y = (midpoint.y - pageOriginY)/pageScale;
+ /* Find new scaled page sizes */
+ synchronized(this)
+ {
+ pageWidth = (int)(core.pageWidth*scale+0.5);
+ if (pageWidth < screenWidth/2)
+ {
+ scale = screenWidth/2/core.pageWidth;
+ pageWidth = (int)(core.pageWidth*scale+0.5);
+ }
+ pageHeight = (int)(core.pageHeight*scale+0.5);
+ if (pageHeight < screenHeight/2)
+ {
+ scale = screenHeight/2/core.pageHeight;
+ pageWidth = (int)(core.pageWidth *scale+0.5);
+ pageHeight = (int)(core.pageHeight*scale+0.5);
+ }
+ pageScale = scale;
+ /* Now given this new scale, calculate page origins so that
+ * x and y are at midpoint */
+ float xscale = (float)pageWidth /core.pageWidth;
+ float yscale = (float)pageHeight/core.pageHeight;
+ setPageOriginTo((int)(midpoint.x - x*xscale + 0.5),
+ (int)(midpoint.y - y*yscale + 0.5));
+ }
+ }
+
+ public void scalePageToScreen()
+ {
+ float scaleX, scaleY;
+ scaleX = (float)screenWidth /core.pageWidth;
+ scaleY = (float)screenHeight/core.pageHeight;
+ synchronized(this)
+ {
+ if (scaleX < scaleY)
+ pageScale = scaleX;
+ else
+ pageScale = scaleY;
+ pageWidth = (int)(core.pageWidth * pageScale + 0.5);
+ pageHeight = (int)(core.pageHeight * pageScale + 0.5);
+ pageOriginX = (screenWidth - pageWidth)/2;
+ pageOriginY = (screenHeight - pageHeight)/2;
+ forceRedraw();
+ }
+ System.out.println("scalePageToScreen: Raw="+
+ core.pageWidth+"x"+core.pageHeight+" scaled="+
+ pageWidth+","+pageHeight+" pageScale="+
+ pageScale);
+ }
+
+ public boolean onTouchEvent(MotionEvent event)
+ {
+ int action = event.getAction();
+ boolean done = false;
+ switch (action & MotionEvent.ACTION_MASK)
+ {
+ case MotionEvent.ACTION_DOWN:
+ touchMode = DRAG;
+ touchDragStartX = event.getX();
+ touchDragStartY = event.getY();
+ touchInitialOriginX = pageOriginX;
+ touchInitialOriginY = pageOriginY;
+ System.out.println("Starting dragging from: "+touchDragStartX+","+touchDragStartY+" ("+pageOriginX+","+pageOriginY+")");
+ done = true;
+ break;
+ case MotionEvent.ACTION_POINTER_DOWN:
+ touchInitialSpacing = spacing(event);
+ if (touchInitialSpacing > 10f)
+ {
+ System.out.println("Started zooming: spacing="+touchInitialSpacing);
+ touchInitialScale = pageScale;
+ touchMode = ZOOM;
+ done = true;
+ }
+ break;
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_POINTER_UP:
+ if (touchMode != NONE)
+ {
+ System.out.println("Released!");
+ touchMode = NONE;
+ done = true;
+ }
+ break;
+ case MotionEvent.ACTION_MOVE:
+ if (touchMode == DRAG)
+ {
+ float x = touchInitialOriginX+event.getX()-touchDragStartX;
+ float y = touchInitialOriginY+event.getY()-touchDragStartY;
+ System.out.println("Dragged to "+x+","+y);
+ setPageOriginTo((int)(x+0.5),(int)(y+0.5));
+ done = true;
+ }
+ else if (touchMode == ZOOM)
+ {
+ float newSpacing = spacing(event);
+ if (newSpacing > 10f)
+ {
+ float newScale = touchInitialScale*newSpacing/touchInitialSpacing;
+ System.out.println("Zoomed to "+newSpacing);
+ midpoint(touchZoomMidpoint,event);
+ setPageScaleTo(newScale,touchZoomMidpoint);
+ done = true;
+ }
+ }
+ }
+ return done;
+ }
+
+ public void run()
+ {
+ boolean redraw = false;
+ int patchW = 0;
+ int patchH = 0;
+ int patchX = 0;
+ int patchY = 0;
+ int localPageW = 0;
+ int localPageH = 0;
+ int localScreenGeneration = screenGeneration;
+ int localAction;
+ int localActionPageNum = core.pageNum;
+
+ /* Set up our default action */
+ action = GOTOPAGE;
+ actionPageNum = core.pageNum;
+ while (action != DIE)
+ {
+ synchronized(this)
+ {
+ while (action == SLEEP)
+ {
+ wakeMe = true;
+ try
+ {
+ System.out.println("Render thread sleeping");
+ this.wait();
+ System.out.println("Render thread woken");
+ }
+ catch (java.lang.InterruptedException e)
+ {
+ System.out.println("Render thread exception:"+e);
+ }
+ }
+
+ /* Now we do as little as we can get away with while
+ * synchronised. In general this means copying any action
+ * or global variables into local ones so that when we
+ * unsynchronoise, other people can alter them again.
+ */
+ switch (action)
+ {
+ case DIE:
+ System.out.println("Woken to die!");
+ break;
+ case GOTOPAGE:
+ localActionPageNum = actionPageNum;
+ break;
+ case REDRAW:
+ /* Figure out what area of the page we want to
+ * redraw (in local variables, in docspace).
+ * We'll always draw a screensized lump, unless
+ * that's too big. */
+ System.out.println("page="+pageWidth+","+pageHeight+" ("+core.pageWidth+","+core.pageHeight+"@"+pageScale+") @ "+pageOriginX+","+pageOriginY);
+ localPageW = pageWidth;
+ localPageH = pageHeight;
+ patchW = pageWidth;
+ patchH = pageHeight;
+ patchX = -pageOriginX;
+ patchY = -pageOriginY;
+ if (patchX < 0)
+ patchX = 0;
+ if (patchW > screenWidth)
+ patchW = screenWidth;
+ srcRect.left = 0;
+ if (patchX+patchW > pageWidth)
+ {
+ srcRect.left += patchX+patchW-pageWidth;
+ patchX = pageWidth-patchW;
+ }
+ if (patchY < 0)
+ patchY = 0;
+ if (patchH > screenHeight)
+ patchH = screenHeight;
+ srcRect.top = 0;
+ if (patchY+patchH > pageHeight)
+ {
+ srcRect.top += patchY+patchH-pageHeight;
+ patchY = pageHeight-patchH;
+ }
+ dstRect.left = pageOriginX;
+ if (dstRect.left < 0)
+ dstRect.left = 0;
+ dstRect.top = pageOriginY;
+ if (dstRect.top < 0)
+ dstRect.top = 0;
+ dstRect.right = dstRect.left + patchW;
+ srcRect.right = srcRect.left + patchW;
+ if (srcRect.right > screenWidth)
+ {
+ dstRect.right -= srcRect.right-screenWidth;
+ srcRect.right = screenWidth;
+ }
+ if (dstRect.right > screenWidth)
+ {
+ srcRect.right -= dstRect.right-screenWidth;
+ dstRect.right = screenWidth;
+ }
+ dstRect.bottom = dstRect.top + patchH;
+ srcRect.bottom = srcRect.top + patchH;
+ if (srcRect.bottom > screenHeight)
+ {
+ dstRect.bottom -=srcRect.bottom-screenHeight;
+ srcRect.bottom = screenHeight;
+ }
+ if (dstRect.bottom > screenHeight)
+ {
+ srcRect.bottom -=dstRect.bottom-screenHeight;
+ dstRect.bottom = screenHeight;
+ }
+ System.out.println("patch=["+patchX+","+patchY+","+patchW+","+patchH+"]");
+ break;
+ }
+ localAction = action;
+ if (action != DIE)
+ action = SLEEP;
+ }
+
+ /* In the redraw case:
+ * pW, pH, pX, pY, localPageW, localPageH are now all set
+ * in local variables, and we are safe from the global vars
+ * being altered in calls from other threads. This is all
+ * the information we need to actually do our render.
+ */
+ switch (localAction)
+ {
+ case GOTOPAGE:
+ core.gotoPage(localActionPageNum);
+ scalePageToScreen();
+ action = REDRAW;
+ break;
+ case REDRAW:
+ if ((bitmap == null) ||
+ (bitmap.getWidth() != patchW) ||
+ (bitmap.getHeight() != patchH))
+ {
+ /* make bitmap of required size */
+ bitmap = Bitmap.createBitmap(patchW, patchH, Bitmap.Config.ARGB_8888);
+ }
+ System.out.println("Calling redraw native method");
+ core.drawPage(bitmap, localPageW, localPageH, patchX, patchY, patchW, patchH);
+ System.out.println("Called native method");
+ {
+ Canvas c = null;
+ try
+ {
+ c = holder.lockCanvas(null);
+ synchronized(holder)
+ {
+ if (localScreenGeneration == screenGeneration)
+ {
+ doDraw(c);
+ }
+ else
+ {
+ /* Someone has changed the screen
+ * under us! Better redraw again...
+ */
+ action = REDRAW;
+ }
+ }
+ }
+ finally
+ {
+ if (c != null)
+ holder.unlockCanvasAndPost(c);
+ }
+ }
+ }
+ }
+ }
+
+ protected void doDraw(Canvas canvas)
+ {
+ if ((canvas == null) || (bitmap == null))
+ return;
+ /* Clear the screen */
+ canvas.drawRGB(128,128,128);
+ /* Draw our bitmap on top */
+ System.out.println("Blitting bitmap from "+srcRect.left+","+srcRect.top+","+srcRect.right+","+srcRect.bottom+" to "+dstRect.left+","+dstRect.top+","+dstRect.right+","+dstRect.bottom);
+ canvas.drawBitmap(bitmap, srcRect, dstRect, (Paint)null);
+ }
+ }
}
diff --git a/fitz/crypt_aes.c b/fitz/crypt_aes.c
index 77c3aa93..afdff0fe 100644
--- a/fitz/crypt_aes.c
+++ b/fitz/crypt_aes.c
@@ -1,19 +1,19 @@
/*
* FIPS-197 compliant AES implementation
*
- * Copyright (C) 2006-2007 Christophe Devine
+ * Copyright (C) 2006-2007 Christophe Devine
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * * Redistributions of source code _must_ retain the above copyright
+ * * Redistributions of source code _must_ retain the above copyright
* notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form may or may not reproduce the above
+ * * Redistributions in binary form may or may not reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
- * * Neither the name of XySSL nor the names of its contributors may be
+ * * Neither the name of XySSL nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -46,22 +46,22 @@
* 32-bit integer manipulation macros (little endian)
*/
#ifndef GET_ULONG_LE
-#define GET_ULONG_LE(n,b,i) \
-{ \
- (n) = ( (unsigned long) (b)[(i) ] ) \
- | ( (unsigned long) (b)[(i) + 1] << 8 ) \
- | ( (unsigned long) (b)[(i) + 2] << 16 ) \
- | ( (unsigned long) (b)[(i) + 3] << 24 ); \
+#define GET_ULONG_LE(n,b,i) \
+{ \
+ (n) = ( (unsigned long) (b)[(i)] ) \
+ | ( (unsigned long) (b)[(i) + 1] << 8 ) \
+ | ( (unsigned long) (b)[(i) + 2] << 16 ) \
+ | ( (unsigned long) (b)[(i) + 3] << 24 ); \
}
#endif
#ifndef PUT_ULONG_LE
-#define PUT_ULONG_LE(n,b,i) \
-{ \
- (b)[(i) ] = (unsigned char) ( (n) ); \
- (b)[(i) + 1] = (unsigned char) ( (n) >> 8 ); \
- (b)[(i) + 2] = (unsigned char) ( (n) >> 16 ); \
- (b)[(i) + 3] = (unsigned char) ( (n) >> 24 ); \
+#define PUT_ULONG_LE(n,b,i) \
+{ \
+ (b)[(i) ] = (unsigned char) ( (n) ); \
+ (b)[(i) + 1] = (unsigned char) ( (n) >> 8 ); \
+ (b)[(i) + 2] = (unsigned char) ( (n) >> 16 ); \
+ (b)[(i) + 3] = (unsigned char) ( (n) >> 24 ); \
}
#endif
@@ -132,7 +132,7 @@ static void aes_gen_tables( void )
{
x = pow[255 - log[i]];
- y = x; y = ( (y << 1) | (y >> 7) ) & 0xFF;
+ y = x; y = ( (y << 1) | (y >> 7) ) & 0xFF;
x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF;
x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF;
x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF;
@@ -149,9 +149,9 @@ static void aes_gen_tables( void )
{
x = FSb[i];
y = XTIME( x ) & 0xFF;
- z = ( y ^ x ) & 0xFF;
+ z = ( y ^ x ) & 0xFF;
- FT0[i] = ( (unsigned long) y ) ^
+ FT0[i] = ( (unsigned long) y ) ^
( (unsigned long) x << 8 ) ^
( (unsigned long) x << 16 ) ^
( (unsigned long) z << 24 );
@@ -162,8 +162,8 @@ static void aes_gen_tables( void )
x = RSb[i];
- RT0[i] = ( (unsigned long) MUL( 0x0E, x ) ) ^
- ( (unsigned long) MUL( 0x09, x ) << 8 ) ^
+ RT0[i] = ( (unsigned long) MUL( 0x0E, x ) ) ^
+ ( (unsigned long) MUL( 0x09, x ) << 8 ) ^
( (unsigned long) MUL( 0x0D, x ) << 16 ) ^
( (unsigned long) MUL( 0x0B, x ) << 24 );
@@ -214,15 +214,15 @@ void aes_setkey_enc( aes_context *ctx, const unsigned char *key, int keysize )
for( i = 0; i < 10; i++, RK += 4 )
{
- RK[4] = RK[0] ^ RCON[i] ^
- ( FSb[ ( RK[3] >> 8 ) & 0xFF ] ) ^
- ( FSb[ ( RK[3] >> 16 ) & 0xFF ] << 8 ) ^
- ( FSb[ ( RK[3] >> 24 ) & 0xFF ] << 16 ) ^
- ( FSb[ ( RK[3] ) & 0xFF ] << 24 );
-
- RK[5] = RK[1] ^ RK[4];
- RK[6] = RK[2] ^ RK[5];
- RK[7] = RK[3] ^ RK[6];
+ RK[4] = RK[0] ^ RCON[i] ^
+ ( FSb[ ( RK[3] >> 8 ) & 0xFF ] ) ^
+ ( FSb[ ( RK[3] >> 16 ) & 0xFF ] << 8 ) ^
+ ( FSb[ ( RK[3] >> 24 ) & 0xFF ] << 16 ) ^
+ ( FSb[ ( RK[3] ) & 0xFF ] << 24 );
+
+ RK[5] = RK[1] ^ RK[4];
+ RK[6] = RK[2] ^ RK[5];
+ RK[7] = RK[3] ^ RK[6];
}
break;
@@ -230,15 +230,15 @@ void aes_setkey_enc( aes_context *ctx, const unsigned char *key, int keysize )
for( i = 0; i < 8; i++, RK += 6 )
{
- RK[6] = RK[0] ^ RCON[i] ^
- ( FSb[ ( RK[5] >> 8 ) & 0xFF ] ) ^
- ( FSb[ ( RK[5] >> 16 ) & 0xFF ] << 8 ) ^
- ( FSb[ ( RK[5] >> 24 ) & 0xFF ] << 16 ) ^
- ( FSb[ ( RK[5] ) & 0xFF ] << 24 );
-
- RK[7] = RK[1] ^ RK[6];
- RK[8] = RK[2] ^ RK[7];
- RK[9] = RK[3] ^ RK[8];
+ RK[6] = RK[0] ^ RCON[i] ^
+ ( FSb[ ( RK[5] >> 8 ) & 0xFF ] ) ^
+ ( FSb[ ( RK[5] >> 16 ) & 0xFF ] << 8 ) ^
+ ( FSb[ ( RK[5] >> 24 ) & 0xFF ] << 16 ) ^
+ ( FSb[ ( RK[5] ) & 0xFF ] << 24 );
+
+ RK[7] = RK[1] ^ RK[6];
+ RK[8] = RK[2] ^ RK[7];
+ RK[9] = RK[3] ^ RK[8];
RK[10] = RK[4] ^ RK[9];
RK[11] = RK[5] ^ RK[10];
}
@@ -248,21 +248,21 @@ void aes_setkey_enc( aes_context *ctx, const unsigned char *key, int keysize )
for( i = 0; i < 7; i++, RK += 8 )
{
- RK[8] = RK[0] ^ RCON[i] ^
- ( FSb[ ( RK[7] >> 8 ) & 0xFF ] ) ^
- ( FSb[ ( RK[7] >> 16 ) & 0xFF ] << 8 ) ^
- ( FSb[ ( RK[7] >> 24 ) & 0xFF ] << 16 ) ^
- ( FSb[ ( RK[7] ) & 0xFF ] << 24 );
+ RK[8] = RK[0] ^ RCON[i] ^
+ ( FSb[ ( RK[7] >> 8 ) & 0xFF ] ) ^
+ ( FSb[ ( RK[7] >> 16 ) & 0xFF ] << 8 ) ^
+ ( FSb[ ( RK[7] >> 24 ) & 0xFF ] << 16 ) ^
+ ( FSb[ ( RK[7] ) & 0xFF ] << 24 );
- RK[9] = RK[1] ^ RK[8];
+ RK[9] = RK[1] ^ RK[8];
RK[10] = RK[2] ^ RK[9];
RK[11] = RK[3] ^ RK[10];
RK[12] = RK[4] ^
- ( FSb[ ( RK[11] ) & 0xFF ] ) ^
- ( FSb[ ( RK[11] >> 8 ) & 0xFF ] << 8 ) ^
- ( FSb[ ( RK[11] >> 16 ) & 0xFF ] << 16 ) ^
- ( FSb[ ( RK[11] >> 24 ) & 0xFF ] << 24 );
+ ( FSb[ ( RK[11] ) & 0xFF ] ) ^
+ ( FSb[ ( RK[11] >> 8 ) & 0xFF ] << 8 ) ^
+ ( FSb[ ( RK[11] >> 16 ) & 0xFF ] << 16 ) ^
+ ( FSb[ ( RK[11] >> 24 ) & 0xFF ] << 24 );
RK[13] = RK[5] ^ RK[12];
RK[14] = RK[6] ^ RK[13];
@@ -312,10 +312,10 @@ void aes_setkey_dec( aes_context *ctx, const unsigned char *key, int keysize )
{
for( j = 0; j < 4; j++, SK++ )
{
- *RK++ = RT0[ FSb[ ( *SK ) & 0xFF ] ] ^
- RT1[ FSb[ ( *SK >> 8 ) & 0xFF ] ] ^
- RT2[ FSb[ ( *SK >> 16 ) & 0xFF ] ] ^
- RT3[ FSb[ ( *SK >> 24 ) & 0xFF ] ];
+ *RK++ = RT0[ FSb[ ( *SK ) & 0xFF ] ] ^
+ RT1[ FSb[ ( *SK >> 8 ) & 0xFF ] ] ^
+ RT2[ FSb[ ( *SK >> 16 ) & 0xFF ] ] ^
+ RT3[ FSb[ ( *SK >> 24 ) & 0xFF ] ];
}
}
@@ -327,50 +327,50 @@ void aes_setkey_dec( aes_context *ctx, const unsigned char *key, int keysize )
memset( &cty, 0, sizeof( aes_context ) );
}
-#define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \
-{ \
- X0 = *RK++ ^ FT0[ ( Y0 ) & 0xFF ] ^ \
- FT1[ ( Y1 >> 8 ) & 0xFF ] ^ \
- FT2[ ( Y2 >> 16 ) & 0xFF ] ^ \
- FT3[ ( Y3 >> 24 ) & 0xFF ]; \
- \
- X1 = *RK++ ^ FT0[ ( Y1 ) & 0xFF ] ^ \
- FT1[ ( Y2 >> 8 ) & 0xFF ] ^ \
- FT2[ ( Y3 >> 16 ) & 0xFF ] ^ \
- FT3[ ( Y0 >> 24 ) & 0xFF ]; \
- \
- X2 = *RK++ ^ FT0[ ( Y2 ) & 0xFF ] ^ \
- FT1[ ( Y3 >> 8 ) & 0xFF ] ^ \
- FT2[ ( Y0 >> 16 ) & 0xFF ] ^ \
- FT3[ ( Y1 >> 24 ) & 0xFF ]; \
- \
- X3 = *RK++ ^ FT0[ ( Y3 ) & 0xFF ] ^ \
- FT1[ ( Y0 >> 8 ) & 0xFF ] ^ \
- FT2[ ( Y1 >> 16 ) & 0xFF ] ^ \
- FT3[ ( Y2 >> 24 ) & 0xFF ]; \
+#define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \
+{ \
+ X0 = *RK++ ^ FT0[ ( Y0 ) & 0xFF ] ^ \
+ FT1[ ( Y1 >> 8 ) & 0xFF ] ^ \
+ FT2[ ( Y2 >> 16 ) & 0xFF ] ^ \
+ FT3[ ( Y3 >> 24 ) & 0xFF ]; \
+ \
+ X1 = *RK++ ^ FT0[ ( Y1 ) & 0xFF ] ^ \
+ FT1[ ( Y2 >> 8 ) & 0xFF ] ^ \
+ FT2[ ( Y3 >> 16 ) & 0xFF ] ^ \
+ FT3[ ( Y0 >> 24 ) & 0xFF ]; \
+ \
+ X2 = *RK++ ^ FT0[ ( Y2 ) & 0xFF ] ^ \
+ FT1[ ( Y3 >> 8 ) & 0xFF ] ^ \
+ FT2[ ( Y0 >> 16 ) & 0xFF ] ^ \
+ FT3[ ( Y1 >> 24 ) & 0xFF ]; \
+ \
+ X3 = *RK++ ^ FT0[ ( Y3 ) & 0xFF ] ^ \
+ FT1[ ( Y0 >> 8 ) & 0xFF ] ^ \
+ FT2[ ( Y1 >> 16 ) & 0xFF ] ^ \
+ FT3[ ( Y2 >> 24 ) & 0xFF ]; \
}
-#define AES_RROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \
-{ \
- X0 = *RK++ ^ RT0[ ( Y0 ) & 0xFF ] ^ \
- RT1[ ( Y3 >> 8 ) & 0xFF ] ^ \
- RT2[ ( Y2 >> 16 ) & 0xFF ] ^ \
- RT3[ ( Y1 >> 24 ) & 0xFF ]; \
- \
- X1 = *RK++ ^ RT0[ ( Y1 ) & 0xFF ] ^ \
- RT1[ ( Y0 >> 8 ) & 0xFF ] ^ \
- RT2[ ( Y3 >> 16 ) & 0xFF ] ^ \
- RT3[ ( Y2 >> 24 ) & 0xFF ]; \
- \
- X2 = *RK++ ^ RT0[ ( Y2 ) & 0xFF ] ^ \
- RT1[ ( Y1 >> 8 ) & 0xFF ] ^ \
- RT2[ ( Y0 >> 16 ) & 0xFF ] ^ \
- RT3[ ( Y3 >> 24 ) & 0xFF ]; \
- \
- X3 = *RK++ ^ RT0[ ( Y3 ) & 0xFF ] ^ \
- RT1[ ( Y2 >> 8 ) & 0xFF ] ^ \
- RT2[ ( Y1 >> 16 ) & 0xFF ] ^ \
- RT3[ ( Y0 >> 24 ) & 0xFF ]; \
+#define AES_RROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \
+{ \
+ X0 = *RK++ ^ RT0[ ( Y0 ) & 0xFF ] ^ \
+ RT1[ ( Y3 >> 8 ) & 0xFF ] ^ \
+ RT2[ ( Y2 >> 16 ) & 0xFF ] ^ \
+ RT3[ ( Y1 >> 24 ) & 0xFF ]; \
+ \
+ X1 = *RK++ ^ RT0[ ( Y1 ) & 0xFF ] ^ \
+ RT1[ ( Y0 >> 8 ) & 0xFF ] ^ \
+ RT2[ ( Y3 >> 16 ) & 0xFF ] ^ \
+ RT3[ ( Y2 >> 24 ) & 0xFF ]; \
+ \
+ X2 = *RK++ ^ RT0[ ( Y2 ) & 0xFF ] ^ \
+ RT1[ ( Y1 >> 8 ) & 0xFF ] ^ \
+ RT2[ ( Y0 >> 16 ) & 0xFF ] ^ \
+ RT3[ ( Y3 >> 24 ) & 0xFF ]; \
+ \
+ X3 = *RK++ ^ RT0[ ( Y3 ) & 0xFF ] ^ \
+ RT1[ ( Y2 >> 8 ) & 0xFF ] ^ \
+ RT2[ ( Y1 >> 16 ) & 0xFF ] ^ \
+ RT3[ ( Y0 >> 24 ) & 0xFF ]; \
}
/*
@@ -394,9 +394,9 @@ void aes_crypt_ecb( aes_context *ctx,
RK = ctx->rk;
- GET_ULONG_LE( X0, input, 0 ); X0 ^= *RK++;
- GET_ULONG_LE( X1, input, 4 ); X1 ^= *RK++;
- GET_ULONG_LE( X2, input, 8 ); X2 ^= *RK++;
+ GET_ULONG_LE( X0, input, 0 ); X0 ^= *RK++;
+ GET_ULONG_LE( X1, input, 4 ); X1 ^= *RK++;
+ GET_ULONG_LE( X2, input, 8 ); X2 ^= *RK++;
GET_ULONG_LE( X3, input, 12 ); X3 ^= *RK++;
if( mode == AES_DECRYPT )
@@ -409,25 +409,25 @@ void aes_crypt_ecb( aes_context *ctx,
AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
- X0 = *RK++ ^ ( RSb[ ( Y0 ) & 0xFF ] ) ^
- ( RSb[ ( Y3 >> 8 ) & 0xFF ] << 8 ) ^
- ( RSb[ ( Y2 >> 16 ) & 0xFF ] << 16 ) ^
- ( RSb[ ( Y1 >> 24 ) & 0xFF ] << 24 );
-
- X1 = *RK++ ^ ( RSb[ ( Y1 ) & 0xFF ] ) ^
- ( RSb[ ( Y0 >> 8 ) & 0xFF ] << 8 ) ^
- ( RSb[ ( Y3 >> 16 ) & 0xFF ] << 16 ) ^
- ( RSb[ ( Y2 >> 24 ) & 0xFF ] << 24 );
-
- X2 = *RK++ ^ ( RSb[ ( Y2 ) & 0xFF ] ) ^
- ( RSb[ ( Y1 >> 8 ) & 0xFF ] << 8 ) ^
- ( RSb[ ( Y0 >> 16 ) & 0xFF ] << 16 ) ^
- ( RSb[ ( Y3 >> 24 ) & 0xFF ] << 24 );
-
- X3 = *RK++ ^ ( RSb[ ( Y3 ) & 0xFF ] ) ^
- ( RSb[ ( Y2 >> 8 ) & 0xFF ] << 8 ) ^
- ( RSb[ ( Y1 >> 16 ) & 0xFF ] << 16 ) ^
- ( RSb[ ( Y0 >> 24 ) & 0xFF ] << 24 );
+ X0 = *RK++ ^ ( RSb[ ( Y0 ) & 0xFF ] ) ^
+ ( RSb[ ( Y3 >> 8 ) & 0xFF ] << 8 ) ^
+ ( RSb[ ( Y2 >> 16 ) & 0xFF ] << 16 ) ^
+ ( RSb[ ( Y1 >> 24 ) & 0xFF ] << 24 );
+
+ X1 = *RK++ ^ ( RSb[ ( Y1 ) & 0xFF ] ) ^
+ ( RSb[ ( Y0 >>8 ) & 0xFF ] << 8 ) ^
+ ( RSb[ ( Y3 >> 16 ) & 0xFF ] << 16 ) ^
+ ( RSb[ ( Y2 >> 24 ) & 0xFF ] << 24 );
+
+ X2 = *RK++ ^ ( RSb[ ( Y2 ) & 0xFF ] ) ^
+ ( RSb[ ( Y1 >> 8 ) & 0xFF ] << 8 ) ^
+ ( RSb[ ( Y0 >> 16 ) & 0xFF ] << 16 ) ^
+ ( RSb[ ( Y3 >> 24 ) & 0xFF ] << 24 );
+
+ X3 = *RK++ ^ ( RSb[ ( Y3 ) & 0xFF ] ) ^
+ ( RSb[ ( Y2 >> 8 ) & 0xFF ] << 8 ) ^
+ ( RSb[ ( Y1 >> 16 ) & 0xFF ] << 16 ) ^
+ ( RSb[ ( Y0 >> 24 ) & 0xFF ] << 24 );
}
else /* AES_ENCRYPT */
{
@@ -439,30 +439,30 @@ void aes_crypt_ecb( aes_context *ctx,
AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
- X0 = *RK++ ^ ( FSb[ ( Y0 ) & 0xFF ] ) ^
- ( FSb[ ( Y1 >> 8 ) & 0xFF ] << 8 ) ^
- ( FSb[ ( Y2 >> 16 ) & 0xFF ] << 16 ) ^
- ( FSb[ ( Y3 >> 24 ) & 0xFF ] << 24 );
-
- X1 = *RK++ ^ ( FSb[ ( Y1 ) & 0xFF ] ) ^
- ( FSb[ ( Y2 >> 8 ) & 0xFF ] << 8 ) ^
- ( FSb[ ( Y3 >> 16 ) & 0xFF ] << 16 ) ^
- ( FSb[ ( Y0 >> 24 ) & 0xFF ] << 24 );
-
- X2 = *RK++ ^ ( FSb[ ( Y2 ) & 0xFF ] ) ^
- ( FSb[ ( Y3 >> 8 ) & 0xFF ] << 8 ) ^
- ( FSb[ ( Y0 >> 16 ) & 0xFF ] << 16 ) ^
- ( FSb[ ( Y1 >> 24 ) & 0xFF ] << 24 );
-
- X3 = *RK++ ^ ( FSb[ ( Y3 ) & 0xFF ] ) ^
- ( FSb[ ( Y0 >> 8 ) & 0xFF ] << 8 ) ^
- ( FSb[ ( Y1 >> 16 ) & 0xFF ] << 16 ) ^
- ( FSb[ ( Y2 >> 24 ) & 0xFF ] << 24 );
+ X0 = *RK++ ^ ( FSb[ ( Y0 ) & 0xFF ] ) ^
+ ( FSb[ ( Y1 >> 8 ) & 0xFF ] << 8 ) ^
+ ( FSb[ ( Y2 >> 16 ) & 0xFF ] << 16 ) ^
+ ( FSb[ ( Y3 >> 24 ) & 0xFF ] << 24 );
+
+ X1 = *RK++ ^ ( FSb[ ( Y1 ) & 0xFF ] ) ^
+ ( FSb[ ( Y2 >> 8 ) & 0xFF ] << 8 ) ^
+ ( FSb[ ( Y3 >> 16 ) & 0xFF ] << 16 ) ^
+ ( FSb[ ( Y0 >> 24 ) & 0xFF ] << 24 );
+
+ X2 = *RK++ ^ ( FSb[ ( Y2 ) & 0xFF ] ) ^
+ ( FSb[ ( Y3 >> 8 ) & 0xFF ] << 8 ) ^
+ ( FSb[ ( Y0 >> 16 ) & 0xFF ] << 16 ) ^
+ ( FSb[ ( Y1 >> 24 ) & 0xFF ] << 24 );
+
+ X3 = *RK++ ^ ( FSb[ ( Y3 ) & 0xFF ] ) ^
+ ( FSb[ ( Y0 >> 8 ) & 0xFF ] << 8 ) ^
+ ( FSb[ ( Y1 >> 16 ) & 0xFF ] << 16 ) ^
+ ( FSb[ ( Y2 >> 24 ) & 0xFF ] << 24 );
}
- PUT_ULONG_LE( X0, output, 0 );
- PUT_ULONG_LE( X1, output, 4 );
- PUT_ULONG_LE( X2, output, 8 );
+ PUT_ULONG_LE( X0, output, 0 );
+ PUT_ULONG_LE( X1, output, 4 );
+ PUT_ULONG_LE( X2, output, 8 );
PUT_ULONG_LE( X3, output, 12 );
}
@@ -499,7 +499,7 @@ void aes_crypt_cbc( aes_context *ctx,
memcpy( iv, temp, 16 );
- input += 16;
+ input += 16;
output += 16;
length -= 16;
}
@@ -514,7 +514,7 @@ void aes_crypt_cbc( aes_context *ctx,
aes_crypt_ecb( ctx, mode, output, output );
memcpy( iv, output, 16 );
- input += 16;
+ input += 16;
output += 16;
length -= 16;
}