OSDN Git Service

merge in jb-mr1-release history after reset to jb-mr1-dev
[android-x86/packages-apps-Gallery2.git] / jni / filters / geometry.c
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "filters.h"
18
19 void JNIFUNCF(ImageFilterGeometry, nativeApplyFilterFlip, jobject src, jint srcWidth, jint srcHeight, jobject dst, jint dstWidth, jint dstHeight, jint flip) {
20     char* destination = 0;
21     char* source = 0;
22     int len = dstWidth * dstHeight * 4;
23     if (srcWidth != dstWidth || srcHeight != dstHeight) {
24         return;
25     }
26     AndroidBitmap_lockPixels(env, src, (void**) &source);
27     AndroidBitmap_lockPixels(env, dst, (void**) &destination);
28     int i = 0;
29     for (; i < len; i += 4) {
30         int r = source[RED];
31         int g = source[GREEN];
32         int b = source[BLUE];
33         // TODO: implement flip
34         destination[RED] = 255;
35         destination[GREEN] = g;
36         destination[BLUE] = b;
37     }
38     AndroidBitmap_unlockPixels(env, dst);
39     AndroidBitmap_unlockPixels(env, src);
40 }
41
42 void JNIFUNCF(ImageFilterGeometry, nativeApplyFilterRotate, jobject src, jint srcWidth, jint srcHeight, jobject dst, jint dstWidth, jint dstHeight, jfloat rotate) {
43     char* destination = 0;
44     char* source = 0;
45     int len = dstWidth * dstHeight * 4;
46     AndroidBitmap_lockPixels(env, src, (void**) &source);
47     AndroidBitmap_lockPixels(env, dst, (void**) &destination);
48     // TODO: implement rotate
49     int i = 0;
50     for (; i < len; i += 4) {
51         int r = source[RED];
52         int g = source[GREEN];
53         int b = source[BLUE];
54         destination[RED] = r;
55         destination[GREEN] = 255;
56         destination[BLUE] = b;
57     }
58     AndroidBitmap_unlockPixels(env, dst);
59     AndroidBitmap_unlockPixels(env, src);
60 }
61
62 void JNIFUNCF(ImageFilterGeometry, nativeApplyFilterCrop, jobject src, jint srcWidth, jint srcHeight, jobject dst, jint dstWidth, jint dstHeight, jint offsetWidth, jint offsetHeight) {
63     char* destination = 0;
64     char* source = 0;
65     int len = dstWidth * dstHeight * 4;
66     AndroidBitmap_lockPixels(env, src, (void**) &source);
67     AndroidBitmap_lockPixels(env, dst, (void**) &destination);
68     // TODO: implement crop
69     int i = 0;
70     for (; i < len; i += 4) {
71         int r = source[RED];
72         int g = source[GREEN];
73         int b = source[BLUE];
74         destination[RED] = r;
75         destination[GREEN] = g;
76         destination[BLUE] = 255;
77     }
78     AndroidBitmap_unlockPixels(env, dst);
79     AndroidBitmap_unlockPixels(env, src);
80 }
81
82 void JNIFUNCF(ImageFilterGeometry, nativeApplyFilterStraighten, jobject src, jint srcWidth, jint srcHeight, jobject dst, jint dstWidth, jint dstHeight, jfloat straightenAngle) {
83     char* destination = 0;
84     char* source = 0;
85     int len = dstWidth * dstHeight * 4;
86     AndroidBitmap_lockPixels(env, src, (void**) &source);
87     AndroidBitmap_lockPixels(env, dst, (void**) &destination);
88     // TODO: implement straighten
89     int i = 0;
90     for (; i < len; i += 4) {
91         int r = source[RED];
92         int g = source[GREEN];
93         int b = source[BLUE];
94         destination[RED] = 128;
95         destination[GREEN] = g;
96         destination[BLUE] = 128;
97     }
98     AndroidBitmap_unlockPixels(env, dst);
99     AndroidBitmap_unlockPixels(env, src);
100 }