blob: a65fcc416d10666d4ac444695436e17d3a79419a (
plain)
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
|
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkHitBox.h"
SkHitBox::SkHitBox() {
fHitBox = NULL;
fX = -1;
fY = -1;
fLayer = -1;
}
SkHitBox::~SkHitBox() {}
void SkHitBox::alloc(int width, int height) {
free(fHitBox);
int length = width * height;
fHitBox = (int*) malloc(length * sizeof(int));
for (int i = 0; i < length; i++) {
fHitBox[i] = 0;
}
}
void SkHitBox::updateHitBox(SkBitmap* newBitmap, int layer) {
int length = fPrev.width() * fPrev.height();
int* prevBase = (int*)fPrev.getPixels();
int* currBase = (int*)newBitmap->getPixels();
for (int i = 0; i < length; i++) {
if (SkUnPreMultiply::PMColorToColor(prevBase[i]) !=
SkUnPreMultiply::PMColorToColor(currBase[i])) {
fHitBox[i] = layer;
}
}
if (fPrev.empty()) {
alloc(newBitmap->width(), newBitmap->height());
fPrev.setConfig(SkBitmap::kARGB_8888_Config, newBitmap->width(), newBitmap->height());
fPrev.allocPixels();
}
newBitmap->deepCopyTo(&fPrev, SkBitmap::kARGB_8888_Config);
}
void SkHitBox::updateHitPoint(SkBitmap* newBitmap, int layer) {
int* prevBase = (int*)fPrev.getPixels();
int* currBase = (int*)newBitmap->getPixels();
int pixel = fY * fPrev.width() + fX;
if (pointIsSet() && !fPrev.empty()) {
if (SkUnPreMultiply::PMColorToColor(prevBase[pixel]) !=
SkUnPreMultiply::PMColorToColor(currBase[pixel])) {
fLayer = layer;
}
}
if (fPrev.empty()) {
alloc(newBitmap->width(), newBitmap->height());
fPrev.setConfig(SkBitmap::kARGB_8888_Config, newBitmap->width(), newBitmap->height());
fPrev.allocPixels();
}
newBitmap->deepCopyTo(&fPrev, SkBitmap::kARGB_8888_Config);
}
|