mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
imporve _fileImageData performance (#3547)
This commit is contained in:
+2
-6
@@ -441,18 +441,14 @@ public class CanvasRenderingContext2DImpl {
|
||||
mLineWidth = lineWidth;
|
||||
}
|
||||
|
||||
private void _fillImageData(byte[] imageData, float imageWidth, float imageHeight, float offsetX, float offsetY) {
|
||||
private void _fillImageData(int[] imageData, float imageWidth, float imageHeight, float offsetX, float offsetY) {
|
||||
Log.d(TAG, "_fillImageData: ");
|
||||
int fillSize = (int) (imageWidth * imageHeight);
|
||||
int[] fillColors = new int[fillSize];
|
||||
int r, g, b, a;
|
||||
for (int i = 0; i < fillSize; ++i) {
|
||||
// imageData Pixel (RGBA) -> fillColors int (ARGB)
|
||||
r = ((int)imageData[4 * i + 0]) & 0xff;
|
||||
g = ((int)imageData[4 * i + 1]) & 0xff;
|
||||
b = ((int)imageData[4 * i + 2]) & 0xff;
|
||||
a = ((int)imageData[4 * i + 3]) & 0xff;
|
||||
fillColors[i] = (a & 0xff) << 24 | (r & 0xff) << 16 | (g & 0xff) << 8 | (b & 0xff);
|
||||
fillColors[i] = Integer.rotateRight(imageData[i], 8);
|
||||
}
|
||||
mBitmap.setPixels(fillColors, 0, (int) imageWidth, (int) offsetX, (int) offsetY, (int) imageWidth, (int) imageHeight);
|
||||
}
|
||||
|
||||
@@ -224,10 +224,10 @@ public:
|
||||
if (_bufferWidth < 1.0F || _bufferHeight < 1.0F) {
|
||||
return;
|
||||
}
|
||||
|
||||
jbyteArray arr = JniHelper::getEnv()->NewByteArray(imageData.getSize());
|
||||
JniHelper::getEnv()->SetByteArrayRegion(arr, 0, imageData.getSize(),
|
||||
reinterpret_cast<const jbyte *>(imageData.getBytes()));
|
||||
|
||||
auto arr = JniHelper::getEnv()->NewIntArray(imageData.getSize()/ 4);
|
||||
JniHelper::getEnv()->SetIntArrayRegion(arr, 0, imageData.getSize()/4,
|
||||
reinterpret_cast<const jint *>(imageData.getBytes()));
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "_fillImageData", arr, imageWidth,
|
||||
imageHeight, offsetX, offsetY);
|
||||
ccDeleteLocalRef(JniHelper::getEnv(), arr);
|
||||
|
||||
@@ -399,6 +399,10 @@ private:
|
||||
return "[B";
|
||||
}
|
||||
|
||||
static std::string getJNISignature(jintArray /*unused*/) {
|
||||
return "[I";
|
||||
}
|
||||
|
||||
static std::string getJNISignature(const char * /*unused*/) {
|
||||
return "Ljava/lang/String;";
|
||||
}
|
||||
|
||||
+2
-3
@@ -429,13 +429,12 @@ public class CanvasRenderingContext2DImpl {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void _fillImageData(byte[] imageData, float imageWidth, float imageHeight, float offsetX, float offsetY) {
|
||||
public void _fillImageData(int[] imageData, float imageWidth, float imageHeight, float offsetX, float offsetY) {
|
||||
int fillSize = (int) (imageWidth * imageHeight);
|
||||
int[] fillColors = new int[fillSize];
|
||||
IntBuffer imageIntBuffer = ByteBuffer.wrap(imageData).asIntBuffer();
|
||||
for (int i = 0; i < fillSize; ++i) {
|
||||
// r g b a -> a r g b
|
||||
fillColors[i] = Integer.rotateRight(imageIntBuffer.get(i), 8);
|
||||
fillColors[i] = Integer.rotateRight(imageData[i], 8);
|
||||
}
|
||||
Rect dstRect = new Rect((int) offsetX, (int) offsetY, (int) imageWidth, (int) imageHeight);
|
||||
mTexture.getPixelMap().writePixels(fillColors, 0, (int) imageWidth, dstRect);
|
||||
|
||||
Reference in New Issue
Block a user