Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- JNIEXPORT void JNICALL
- JNI_FN(MuPDFCore_saveImageInternal)(JNIEnv * env, jobject thiz, jobject bitmap, int imgW, int imgH, int posX, int posY)
- {
- AndroidBitmapInfo info;
- void *pixels;
- int ret;
- fz_irect bbox;
- fz_rect rect;
- fz_pixmap *pix = NULL;
- fz_image *img = NULL;
- fz_point pos;
- fz_matrix matrix;
- image_struct *img_s = NULL;
- globals *glo = get_globals(env, thiz);
- fz_context *ctx = glo->ctx;
- pdf_document *doc = glo->doc;
- pdf_page *page = &glo->pages[glo->current];
- fz_var(pix);
- fz_var(img);
- fz_var(pos);
- 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;
- }
- bbox.x0 = 0;
- bbox.y0 = 0;
- bbox.x1 = imgW;
- bbox.y1 = imgH;
- pix = fz_new_pixmap_with_bbox_and_data(ctx, glo->colorspace, &bbox, pixels);
- img = fz_new_image_from_pixmap(ctx, pix, NULL);
- pos.x = posX;
- pos.y = posY;
- fz_matrix ctm = fz_identity;
- float zoom = glo->resolution / 72;
- zoom = 1.0 / zoom;
- fz_scale(&ctm, zoom, zoom);
- fz_transform_point(&pos, &ctm);
- img_s->image = *img;
- img_s->pos = pos;
- matrix.a = imgW;
- matrix.d = imgH;
- matrix.e = posX;
- matrix.f = posY;
- img_s->matrix = matrix;
- img_s->doc = doc;
- pdf_clean_page_contents(doc, page, NULL, my_process_fn, &img_s);
- }
- static void my_process_fn(void *arg, fz_buffer *buffer, pdf_obj *res)
- {
- image_struct *img_s = arg;
- fz_image *img = &img_s->image;
- fz_matrix *matrix = &img_s->matrix;
- pdf_document *doc = img_s->doc;
- fz_matrix ctm = fz_identity;
- fz_device *pdf_dev = NULL;
- fz_var(pdf_dev);
- pdf_dev = pdf_new_pdf_device(doc, NULL, res, &ctm, buffer);
- pdf_dev_fill_image(pdf_dev, img, matrix, 1);
- fz_free_device(pdf_dev);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement