Пример #1
0
static void se_glReadPixels(JNIEnv *env, jobject obj, jstring imageKey, jint x, jint y, jint w, jint h) {
    int width = w;
    int height = h;
    int rowBytes = w * 4;
    int pixelFormat = SE_ImageData::RGBA;
    int pixNum = width * height;
    char* newData = (char *)malloc(height * rowBytes);
    glReadPixels(
        (GLint)x,
        (GLint)y,
        (GLsizei)width,
        (GLsizei)height,
        (GLenum)GL_RGBA,
        (GLenum)GL_UNSIGNED_BYTE,
        (GLvoid *)newData
    );
    const char* imageKey8 = env->GetStringUTFChars(imageKey, 0);
    SE_ResourceManager *resourceManager = SE_Application::getInstance()->getResourceManager();
    SE_ImageData* newImgd = new SE_ImageData;
    newImgd->setWidth(width);
    newImgd->setHeight(height);
    newImgd->setBytesPerRow(rowBytes);
    newImgd->setPixelFormat(pixelFormat);
    newImgd->setData(newData);
    newImgd->setCompressType(SE_ImageData::RAW);
    newImgd->setName(imageKey8);
    resourceManager->insertPathImageData(imageKey8, newImgd, true);   
    env->ReleaseStringUTFChars(imageKey, imageKey8);
}
Пример #2
0
static jboolean se_loadPixelsData(JNIEnv *env, jobject obj, jstring savePath, jstring imageKey, jint w, jint h) {
    const char* imageKey8 = env->GetStringUTFChars(imageKey, 0);
    const char* savePath8 = env->GetStringUTFChars(savePath, 0);
    SE_ImageDataID imageDataid(imageKey8);
    SE_ResourceManager *resourceManager = SE_Application::getInstance()->getResourceManager();
    SE_ImageData* imgd = resourceManager->getImageData(imageDataid);
    if (!imgd) {
        char* data = NULL;
        int len = 0;
        SE_IO::readFileAll(savePath8, data, len);
        if(len != 0) {
            int power2Width = w;
            int power2Height = h;
            int pixelFormat = SE_ImageData::RGBA;
            if(!SE_Util::isPower2(w))
            {
                power2Width = SE_Util::higherPower2(w);
            }
            if(!SE_Util::isPower2(h))
            {
                power2Height = SE_Util::higherPower2(h);
            }
            imgd = new SE_ImageData;
            imgd->setWidth(power2Width);
            imgd->setHeight(power2Height);
            imgd->setBytesPerRow(power2Width * 4);
            imgd->setPixelFormat(pixelFormat);
            imgd->setData(data);
            imgd->setCompressType(SE_ImageData::RAW);
            imgd->setName(imageDataid.getStr());
            //imgd->setPreWidth(w);
            //imgd->setPreHeight(h);
            resourceManager->insertPathImageData(imageDataid.getStr(), imgd); 
            resourceManager->setIdPath(imageDataid.getStr(),imageDataid.getStr());            
        }
    }
    env->ReleaseStringUTFChars(imageKey, imageKey8);
    env->ReleaseStringUTFChars(savePath, savePath8);
    if (!imgd)
    {
         return false;
    }
    return true;
}
Пример #3
0
static void se_setViewImage2(JNIEnv* env, jobject clazz, jstring viewgroupName,jstring viewName, jobject jbitmap)
{
    const char* viewgroupname = env->GetStringUTFChars(viewgroupName, 0);
    const char* viewname = env->GetStringUTFChars(viewName, 0);
#ifdef NDK
    AndroidBitmapInfo bitmapInfo;
    int ret;
    void* pixels;
    if((ret = AndroidBitmap_getInfo(env, jbitmap, &bitmapInfo)) < 0)
    {
        LOGE("AndroidBitmap_getInfo() failed ! error = %d", ret);
        return;
    }
    if(bitmapInfo.format != ANDROID_BITMAP_FORMAT_RGB_565 && bitmapInfo.format != ANDROID_BITMAP_FORMAT_RGBA_8888)
    {
        LOGE("Bitmap format is not supported\n");
        return;
    }
    if((ret = AndroidBitmap_lockPixels(env, jbitmap, &pixels)) < 0)
    {
        LOGE("AndroidBitmap_lockPixels() failed ! error = %d", ret);
        return;
    }
    int pixelSize = 0;
    switch(bitmapInfo.format)
    {
        case ANDROID_BITMAP_FORMAT_RGB_565:
            pixelSize = 2;
            break;
        case ANDROID_BITMAP_FORMAT_RGBA_8888:
            pixelSize = 4;
            break;
        default:
            break;
    }
    int bytesPerRow = pixelSize * bitmapInfo.width;
    if(bytesPerRow != bitmapInfo.stride)
    {
        LOGE("bytes per row is not align with original image");
        return;
    }

    SE_ImageData* newImage = new SE_ImageData;
    newImage->setWidth(bitmapInfo.width);
    newImage->setHeight(bitmapInfo.height);
    switch(bitmapInfo.format)
    {
        case ANDROID_BITMAP_FORMAT_RGB_565:
            newImage->setPixelFormat(SE_ImageData::RGB_565);
            break;
        case ANDROID_BITMAP_FORMAT_RGBA_8888:
            newImage->setPixelFormat(SE_ImageData::RGBA);
            break;
        default:
            break;
    }
    int width = newImage->getWidth();
    int height = newImage->getHeight();
    unsigned char* src = (unsigned char*) pixels;
    unsigned char* dst = new unsigned char[width * height * pixelSize];
    for(int y = height - 1 ; y >= 0 ; y--)
    {
        unsigned char* srcData = src + y * width * pixelSize;
        unsigned char* dstData = dst + (height - 1 - y) * width * pixelSize;
        memcpy(dstData, srcData, width * pixelSize);
    }   
    newImage->setBytesPerRow(bytesPerRow);
    newImage->setData((char*)dst);
    newImage->setCompressType(SE_ImageData::RAW);
    SE_UIManager* uiManager = SE_Application::getInstance()->getUIManager();
    if(uiManager)
    {
	uiManager->SetViewImage(viewgroupname,viewname, newImage);
    }
    AndroidBitmap_unlockPixels(env, jbitmap);
#else
    SkBitmap* nativeBitmap = (SkBitmap*)env->GetIntField(jbitmap, nativeBitmapID);
    SkBitmap* bitmap = new  SkBitmap(*nativeBitmap);
    SE_ImageData*  newImgd = SE_ImageCodec::load(bitmap);
    SE_ImageCodec::resizeImageData(newImgd);

    LOGD("bitmap .config() %d",bitmap->config());
    LOGD("bitmap newImgd->getPixelFormat() %d",newImgd->getPixelFormat()); 
    SE_UIManager* uiManager = SE_Application::getInstance()->getUIManager();
    if(uiManager)
    {
	uiManager->SetViewImage(viewgroupname,viewname, newImgd);
    }
#endif

}