1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
JNIEXPORT void JNICALL Java_com_mdz_livewallpaper_eb_Graphics_DrawInC(JNIEnv * env, jobject obj, jobject bmp, jobject pal, jbyteArray arr)
{
AndroidBitmapInfo  dinfo;
void*              dpixels;
int                ret;
	
if ((ret = AndroidBitmap_getInfo(env, bmp, &dinfo)) < 0) {
    LOGE("AndroidBitmap_getInfo() failed for DST ! error=%d", ret);
return;
}
	
if ((ret = AndroidBitmap_lockPixels(env, bmp, &dpixels)) < 0) {
    LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret);
}
					
char* dat = (char*)dpixels;
int stride = dinfo.stride;
jboolean isCopy;
jbyte* buffer = (*env)->GetByteArrayElements(env, arr, &isCopy);
LOGI("Size: %u x %u", dinfo.width, dinfo.height);

int i = 0;
int j = 0;
for (i = 0; i < dinfo.width; i++)
{		
    for (j = 0; j < dinfo.height; j++)
    {
        LOGI("DrawInC: i: %u j: %u", i, j);
        int n = j * 32+i;
	int block = buffer[n * 2] + (buffer[n * 2 + 1] << 8);
        int tile = block & 0x3FF;
        int vflip = (block & 0x8000) != 0;
        int hflip = (block & 0x4000) != 0;
        int subpal = (block >> 10) & 7;

        DrawTile(env, obj, stride, dat, i * 8, j * 8, pal, tile, subpal, vflip, hflip);
					
	}
}

AndroidBitmap_unlockPixels(env, bmp);
}
static void DrawTile(JNIEnv * env, jobject obj, int stride, char* dat, int x, int y, jobject pal, int tile, int subpal, int vflip, int hflip)
{
jclass cls = (*env)->GetObjectClass(env, obj);
jmethodID getRedPal_mid = (*env)->GetMethodID(env, cls, "getRedPal", "(Lcom/mdz/livewallpaper/Palette;IIII)B");
jmethodID getGreenPal_mid = (*env)->GetMethodID(env, cls, "getGreenPal", "(Lcom/mdz/livewallpaper/Palette;IIII)B");
jmethodID getBluePal_mid = (*env)->GetMethodID(env, cls, "getBluePal", "(Lcom/mdz/livewallpaper/Palette;IIII)B");
int i = 0;
int j = 0;
for (i = 0; i < 8; i++)
{
			
    for (j = 0; j < 8; j++)
    {
        LOGI("DrawTiles: i: %u j: %u", i, j);
        int px = 0;
        if	(hflip ==  1)
            px = x + 7 - i;
        else
            px = x + i;
						
        int py = 0;
        if (vflip == 1)
            py = y + 7 - j;
        else
            py = y + j;
						
        dat[px * 3 + py * stride + 2] = (char)(*env)->CallByteMethod(env, obj, getRedPal_mid, pal, tile, subpal, i, j);
        dat[px * 3 + py * stride + 1] = (char)(*env)->CallByteMethod(env, obj, getGreenPal_mid, pal, tile, subpal, i, j);
        dat[px * 3 + py * stride + 0] = (char)(*env)->CallByteMethod(env, obj, getBluePal_mid, pal, tile, subpal, i, j);
					
        }
    }
}