Пример #1
0
void SE_NetDataCommand::handle(SE_TimeMS realDelta, SE_TimeMS simulateDelta)
{
	SE_ASSERT(mMsg->len >= 3);
	int id = mMsg->data[0];
	unsigned short dataLen = 0;
	memcpy(&dataLen, mMsg->data + 1, 2);
    dataLen = SE_Util::net2HostInt16(dataLen);
	int realDataLen = dataLen - 3;
	std::string str;
	if(realDataLen > 0)
	{
		str.assign((char*)mMsg->data + 3, realDataLen);
	}
	for(int i = 0 ; i < mMsg->len ; i++)
	{
		LOGI("%d\n", mMsg->data[i]);
	}
	LOGI("### msg len = %d , str = %s ###\n", mMsg->len, str.c_str());
	if(id == 0 && str.size() > 0)
	{
		SE_ImageUnit iu;
		SE_ResourceManager* resourceManager = SE_GET_RESOURCEMANAGER();
		SE_ImageData* imageData = resourceManager->loadImageWithFullPath(str.c_str());
		if(!imageData)
		{
			LOGI("can not load image\n");
			return;
		}
		iu.imageDataID = str.c_str();
		iu.imageRect.x = 0;
		iu.imageRect.y = 0;
		iu.imageRect.width = imageData->getWidth();
		iu.imageRect.height = imageData->getHeight();
		SE_ImageElement* imageElement = new SE_ImageElement("");
		imageElement->setBaseColor(iu);
		SE_SceneManager* sceneManager = SE_Application::getInstance()->getSceneManager();
		SE_Scene* scene = new SE_2DScene;
		scene->setBackground(SE_Vector4f(1.0f, 1.0f, 1.0f, 1.0f));
		scene->setBound(480, 800);
		scene->setRootElement(imageElement);
		SE_SceneID sceneID = sceneManager->add(scene);
		//create camera
		SE_Camera* camera = SE_Camera::create2DSceneCamera(480, 800);
		SE_CameraManager* cameraManager = SE_Application::getInstance()->getCameraManager();
		SE_CameraID cameraID = cameraManager->add(camera);
		scene->setCamera(cameraID);
		//end
		sceneManager->show(sceneID);
	}
	else
	{

	}
}
Пример #2
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);
}
Пример #3
0
static void se_savePixelsData(JNIEnv *env, jobject obj, jstring savePath, jstring imageKey) {
    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) {
        SE_File fbase(savePath8, SE_File::WRITE);
        fbase.write(imgd->getData(), imgd->getHeight() * imgd->getBytesPerRow());
        LOGI("SEHome:#################savePixelsData success!!!");
    }
    env->ReleaseStringUTFChars(imageKey, imageKey8);
    env->ReleaseStringUTFChars(savePath, savePath8);
}
Пример #4
0
static void se_changeTextureImage(JNIEnv* env, jobject clazz,
        jstring imageKey) {
    const char* imagePath = env->GetStringUTFChars(imageKey, NULL);
    SE_ResourceManager *resourceManager =
            SE_Application::getInstance()->getResourceManager();
    SE_ImageData* existdata = resourceManager->getImageDataFromPath(imagePath);
    if (existdata && !existdata->getData()) {
        GLuint texid = existdata->getTexID();
        if (texid != 0) {
            glDeleteTextures(1, &texid);
        }
        existdata->setTexID(0);

    }

    env->ReleaseStringUTFChars(imageKey, imagePath);
}
Пример #5
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;
}
Пример #6
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

}
Пример #7
0
static void se_loadTextureImage(JNIEnv* env, jobject clazz, jstring imageKey,
        jobject jbitmap) {
    const char* imagePath = env->GetStringUTFChars(imageKey, NULL);
    SE_ResourceManager *resourceManager =
            SE_Application::getInstance()->getResourceManager();
    SE_ImageData* existdata = resourceManager->getImageDataFromPath(imagePath);
    if (existdata && !existdata->getData()) {
        GLuint texid = existdata->getTexID();
        if (texid != 0) {
            glDeleteTextures(1, &texid);
        }
        existdata->setTexID(0);
        AndroidBitmapInfo bitmapInfo;
        int ret;
        void* pixels;
        if ((ret = AndroidBitmap_getInfo(env, jbitmap, &bitmapInfo)) < 0) {
            LOGE("error: AndroidBitmap_getInfo() failed ! error = %d\n", ret);
            return;
        }
        if (bitmapInfo.format != ANDROID_BITMAP_FORMAT_RGB_565
                && bitmapInfo.format != ANDROID_BITMAP_FORMAT_RGBA_8888
                && bitmapInfo.format != ANDROID_BITMAP_FORMAT_RGBA_4444) {
            LOGE("error: Bitmap format is not supported\n");
            return;
        }
        if ((ret = AndroidBitmap_lockPixels(env, jbitmap, &pixels)) < 0) {
            LOGE("error: AndroidBitmap_lockPixels() failed ! error = %d\n",
                    ret);
            return;
        }

        GLint internalFormat = GL_RGB;
        GLenum format = GL_RGB;
        GLenum type = GL_UNSIGNED_BYTE;

        switch (bitmapInfo.format) {
        case ANDROID_BITMAP_FORMAT_RGB_565:
            type = GL_UNSIGNED_SHORT_5_6_5;
            break;
        case ANDROID_BITMAP_FORMAT_RGBA_8888:
            internalFormat = GL_RGBA;
            format = GL_RGBA;
            break;
        case ANDROID_BITMAP_FORMAT_RGBA_4444:
            internalFormat = GL_RGBA;
            format = GL_RGBA;
            type = GL_UNSIGNED_SHORT_4_4_4_4;
            break;
        default:
            return;
            break;
        }
        int width = bitmapInfo.width;
        int height = bitmapInfo.height;
        glPixelStorei(GL_UNPACK_ALIGNMENT,1);
        glActiveTexture(GL_TEXTURE0);
        glGenTextures(1, &texid);
        existdata->setTexID(texid);
        glBindTexture(GL_TEXTURE_2D, texid);
        glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format,
                type, pixels);
        glGenerateMipmap (GL_TEXTURE_2D);

        GLint wraps, wrapt;
        if (SE_Util::isPower2(width) && SE_Util::isPower2(height)) {
            wraps = GL_REPEAT;
        } else {
            wraps = GL_CLAMP_TO_EDGE;
        }

        if (SE_Util::isPower2(width) && SE_Util::isPower2(height)) {
            wrapt = GL_REPEAT;
        } else {
            wrapt = GL_CLAMP_TO_EDGE;
        }

        GLint sampleMin, sampleMag;
        sampleMin = GL_LINEAR_MIPMAP_LINEAR;
        sampleMag = GL_LINEAR;
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wraps);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapt);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, sampleMin);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, sampleMag);
    }
    env->ReleaseStringUTFChars(imageKey, imagePath);
}