This commit is contained in:
Ming 2010-11-04 09:33:31 +00:00
parent ca066d0bac
commit 0ea2035ec6
4 changed files with 123 additions and 71 deletions

View File

@ -50,7 +50,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
return JNI_VERSION_1_4;
}
void Java_org_cocos2dx_DemoRenderer_nativeRender(JNIEnv* env)
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeRender(JNIEnv* env)
{
cocos2d::CCDirector::getSharedDirector()->preMainLoop();
}

View File

@ -86,7 +86,7 @@ namespace cocos2d {
//__android_log_write(ANDROID_LOG_DEBUG, "cocos2d::CCXBitmapDC", "get env");
jclass mClass = env->FindClass("org/cocos2dx/Cocos2dJNI");
jclass mClass = env->FindClass("org/cocos2dx/lib/Cocos2dxJNI");
if (! mClass)
{
__android_log_write(ANDROID_LOG_DEBUG, "cocos2d::CCXBitmapDC", "can not find org.cocos2dx.Cocos2dJNI");
@ -119,15 +119,30 @@ namespace cocos2d {
data = new unsigned char[info.width * info.height * 4];
if (! data)
{
AndroidBitmap_unlockPixels(evn, bitmap);
AndroidBitmap_unlockPixels(env, bitmap);
__android_log_write(ANDROID_LOG_DEBUG, "cocos2d::CCXBitmapDC", "failed to allocate memory");
return;
}
memcpy(data, pixels, info.width * info.height * 4);
AndroidBitmap_unlockPixels(env, bitmap);
// swap data
unsigned int *tempPtr = (unsigned int*)data;
unsigned int tempdata = 0;
for (int i = 0; i < info.height; ++i)
{
for (int j = 0; j < info.width; ++j)
{
tempdata = *tempPtr;
*tempPtr++ = swapAlpha(tempdata);
}
}
m_nWidth = info.width;
m_nHeight =info.height;
//__android_log_print(ANDROID_LOG_DEBUG, "cocos2d::CCXBitmapDC", "width: %d, height:%d", m_nWidth, m_nHeight);
}
unsigned int CCXBitmapDC::swapAlpha(unsigned int value)

View File

@ -30,6 +30,39 @@ THE SOFTWARE.
#include "CCTouch.h"
#include "CCTouchDispatcher.h"
#include <stdlib.h>
#include <jni.h>
extern "C"
{
static cocos2d::EGLTouchDelegate *s_pDelegate;
static cocos2d::CCTouch s_touch;
static cocos2d::NSSet s_set;
void Java_org_cocos2dx_lib_Cocos2dxGLSurfaceView_nativeTouchesBegin(jfloat x, jfloat y)
{
s_touch.SetTouchInfo(0, x, y);
s_set.addObject(&s_touch);
s_pDelegate->touchesBegan(&s_set, NULL);
}
void Java_org_cocos2dx_lib_Cocos2dxGLSurfaceView_nativeTouchesEnd(jfloat x, jfloat y)
{
s_touch.SetTouchInfo(0, x, y);
s_pDelegate->touchesEnded(&s_set, NULL);
s_set.removeObject(&s_touch);
}
void Java_org_cocos2dx_lib_Cocos2dxGLSurfaceView_nativeTouchesMove(jfloat x, jfloat y)
{
}
void Java_org_cocos2dx_lib_Cocos2dxGLSurfaceView_nativeTouchesCancel(jfloat x, jfloat y)
{
}
}
namespace cocos2d {
@ -47,6 +80,7 @@ void CCXEGLView::setFrameWitdAndHeight(int width, int height)
CCXEGLView::~CCXEGLView()
{
CCX_SAFE_DELETE(s_pDelegate);
}
CGSize CCXEGLView::getSize()
@ -62,10 +96,12 @@ bool CCXEGLView::isOpenGLReady()
void CCXEGLView::release()
{
exit(0);
}
void CCXEGLView::setTouchDelegate(EGLTouchDelegate * pDelegate)
{
s_pDelegate = pDelegate;
}
void CCXEGLView::swapBuffers()
@ -73,3 +109,4 @@ void CCXEGLView::swapBuffers()
}
} // end of namespace cocos2d

View File

@ -31,7 +31,7 @@ THE SOFTWARE.
#include <android/log.h>
/*#include "jpeglib.h"*/
#include "jpeglib.h"
//using namespace ImageToolKit;
using namespace std;
@ -287,73 +287,73 @@ bool UIImage::loadPngFromStream(unsigned char *data, int nLength)
bool UIImage::loadJpg(const char *strFileName)
{
// /* these are standard libjpeg structures for reading(decompression) */
// struct jpeg_decompress_struct cinfo;
// struct jpeg_error_mgr jerr;
// /* libjpeg data structure for storing one row, that is, scanline of an image */
// JSAMPROW row_pointer[1];
//
// FILE *infile = fopen( strFileName, "rb" );
// unsigned long location = 0;
// unsigned int i = 0;
//
// if ( !infile )
// {
// return false;
// }
//
// /* here we set up the standard libjpeg error handler */
// cinfo.err = jpeg_std_error( &jerr );
//
// /* setup decompression process and source, then read JPEG header */
// jpeg_create_decompress( &cinfo );
//
// /* this makes the library read from infile */
// jpeg_stdio_src( &cinfo, infile );
//
// /* reading the image header which contains image information */
// jpeg_read_header( &cinfo, true );
//
// // we only support RGB or grayscale
// if (cinfo.jpeg_color_space != JCS_RGB)
// {
// if (cinfo.jpeg_color_space == JCS_GRAYSCALE || cinfo.jpeg_color_space == JCS_YCbCr)
// {
// cinfo.out_color_space = JCS_RGB;
// }
// }
// else
// {
// return false;
// }
//
// /* Start decompression jpeg here */
// jpeg_start_decompress( &cinfo );
//
// /* init image info */
// m_imageInfo.width = cinfo.image_width;
// m_imageInfo.height = cinfo.image_height;
// m_imageInfo.hasAlpha = false;
// m_imageInfo.isPremultipliedAlpha = false;
// m_imageInfo.bitsPerComponent = 8;
// m_imageInfo.data = new unsigned char[cinfo.output_width*cinfo.output_height*cinfo.output_components];
//
// /* now actually read the jpeg into the raw buffer */
// row_pointer[0] = new unsigned char[cinfo.output_width*cinfo.output_components];
//
// /* read one scan line at a time */
// while( cinfo.output_scanline < cinfo.image_height )
// {
// jpeg_read_scanlines( &cinfo, row_pointer, 1 );
// for( i=0; i<cinfo.image_width*cinfo.num_components;i++)
// m_imageInfo.data[location++] = row_pointer[0][i];
// }
//
// /* wrap up decompression, destroy objects, free pointers and close open files */
// jpeg_finish_decompress( &cinfo );
// jpeg_destroy_decompress( &cinfo );
// delete row_pointer[0];
// fclose( infile );
/* these are standard libjpeg structures for reading(decompression) */
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
/* libjpeg data structure for storing one row, that is, scanline of an image */
JSAMPROW row_pointer[1];
FILE *infile = fopen( strFileName, "rb" );
unsigned long location = 0;
unsigned int i = 0;
if ( !infile )
{
return false;
}
/* here we set up the standard libjpeg error handler */
cinfo.err = jpeg_std_error( &jerr );
/* setup decompression process and source, then read JPEG header */
jpeg_create_decompress( &cinfo );
/* this makes the library read from infile */
jpeg_stdio_src( &cinfo, infile );
/* reading the image header which contains image information */
jpeg_read_header( &cinfo, true );
// we only support RGB or grayscale
if (cinfo.jpeg_color_space != JCS_RGB)
{
if (cinfo.jpeg_color_space == JCS_GRAYSCALE || cinfo.jpeg_color_space == JCS_YCbCr)
{
cinfo.out_color_space = JCS_RGB;
}
}
else
{
return false;
}
/* Start decompression jpeg here */
jpeg_start_decompress( &cinfo );
/* init image info */
m_imageInfo.width = cinfo.image_width;
m_imageInfo.height = cinfo.image_height;
m_imageInfo.hasAlpha = false;
m_imageInfo.isPremultipliedAlpha = false;
m_imageInfo.bitsPerComponent = 8;
m_imageInfo.data = new unsigned char[cinfo.output_width*cinfo.output_height*cinfo.output_components];
/* now actually read the jpeg into the raw buffer */
row_pointer[0] = new unsigned char[cinfo.output_width*cinfo.output_components];
/* read one scan line at a time */
while( cinfo.output_scanline < cinfo.image_height )
{
jpeg_read_scanlines( &cinfo, row_pointer, 1 );
for( i=0; i<cinfo.image_width*cinfo.num_components;i++)
m_imageInfo.data[location++] = row_pointer[0][i];
}
/* wrap up decompression, destroy objects, free pointers and close open files */
jpeg_finish_decompress( &cinfo );
jpeg_destroy_decompress( &cinfo );
delete row_pointer[0];
fclose( infile );
return true;
}