diff options
author | Sebastien Vincent <seb@jitsi.org> | 2010-02-26 15:29:16 +0000 |
---|---|---|
committer | Sebastien Vincent <seb@jitsi.org> | 2010-02-26 15:29:16 +0000 |
commit | 06c56ae2a201c469310481184b1c5c6dcce34ad6 (patch) | |
tree | e5e0a03d340ed06ed5e93b14a2602cfa23120b70 /src/native | |
parent | f94b6f0cf3899d4582fcb452e678afaac9fe6f8b (diff) | |
download | jitsi-06c56ae2a201c469310481184b1c5c6dcce34ad6.zip jitsi-06c56ae2a201c469310481184b1c5c6dcce34ad6.tar.gz jitsi-06c56ae2a201c469310481184b1c5c6dcce34ad6.tar.bz2 |
Handle correctly endianess for different RGB (24/32) format.
Diffstat (limited to 'src/native')
4 files changed, 97 insertions, 23 deletions
diff --git a/src/native/ffmpeg/Makefile b/src/native/ffmpeg/Makefile index 9b0c14a..35ac4fc 100644 --- a/src/native/ffmpeg/Makefile +++ b/src/native/ffmpeg/Makefile @@ -1,5 +1,7 @@ FFMPEG_HOME=/home/seb/svn_work/ffmpeg
JAVA_HOME=/usr/lib/jvm/java-6-sun
+#JAVA_HOME=/System/Library/Frameworks/JavaVM.framework
+#JAVA_HOME=C:\Progra~1\jdk1.6.0_18
X264_HOME=/home/seb/svn_work/x264-snapshot-20091208-2245
CC=gcc
@@ -9,6 +11,13 @@ CPPFLAGS=-DJNI_IMPLEMENTATION \ # Uncomment section for your OS AND comment out the others
+# Linux configuration
+CPPFLAGS+=-I$(JAVA_HOME)/include/linux
+LDFLAGS=-fPIC -shared
+# Choose between 32-bit or 64-bit
+#TARGET=../../../lib/native/linux/libffmpeg.so
+TARGET=../../../lib/native/linux-64/libffmpeg.so
+
# MacOS X configuration
#CPPFLAGS+=-I$(JAVA_HOME)/Headers/
#LDFLAGS=-dynamiclib -Wl,-read_only_relocs,suppress
@@ -21,13 +30,6 @@ CPPFLAGS=-DJNI_IMPLEMENTATION \ #TARGET=../../../lib/native/windows/ffmpeg.dll
#TARGET=../../../lib/native/windows-64/ffmpeg.dll
-# Linux configuration
-CPPFLAGS+=-I$(JAVA_HOME)/include/linux
-LDFLAGS=-fPIC -shared
-# Choose between 32-bit or 64-bit
-#TARGET=../../../lib/native/linux/libffmpeg.so
-TARGET=../../../lib/native/linux-64/libffmpeg.so
-
# FreeBSD configuration
#CPPFLAGS+=-I$(JAVA_HOME)/include/freebsd
#LDFLAGS=-fPIC -shared
diff --git a/src/native/ffmpeg/net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG.c b/src/native/ffmpeg/net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG.c index 39ffe8f..85c8533 100644 --- a/src/native/ffmpeg/net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG.c +++ b/src/native/ffmpeg/net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG.c @@ -523,19 +523,40 @@ Java_net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG_getRGB24Format if(little_endian)
{
- return PIX_FMT_RGB24;
+ return PIX_FMT_BGR24;
}
else /* big endian */
{
- return PIX_FMT_BGR24;
+ return PIX_FMT_RGB24;
}
}
JNIEXPORT jint JNICALL
-Java_net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG_getRGBAFormat
+Java_net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG_getRGB32Format
+ (JNIEnv *env, jclass clazz)
+{
+ return PIX_FMT_RGB32;
+}
+
+JNIEXPORT jint JNICALL
+Java_net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG_getRGB32_11Format
+ (JNIEnv *env, jclass clazz)
+{
+ return PIX_FMT_RGB32_1;
+}
+
+JNIEXPORT jint JNICALL
+Java_net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG_getBGR32Format
+ (JNIEnv *env, jclass clazz)
+{
+ return PIX_FMT_BGR32;
+}
+
+JNIEXPORT jint JNICALL
+Java_net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG_getBGR32_11Format
(JNIEnv *env, jclass clazz)
{
- return PIX_FMT_RGBA;
+ return PIX_FMT_BGR32_1;
}
JNIEXPORT jint JNICALL
diff --git a/src/native/ffmpeg/net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG.h b/src/native/ffmpeg/net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG.h index 47ee2e0..02b2ecf 100644 --- a/src/native/ffmpeg/net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG.h +++ b/src/native/ffmpeg/net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG.h @@ -23,10 +23,34 @@ extern "C" { #define net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG_X264_RC_ABR 2L /* * Class: net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG - * Method: getRGBAFormat + * Method: getRGB32Format * Signature: ()I */ -JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG_getRGBAFormat +JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG_getRGB32Format + (JNIEnv *, jclass); + +/* + * Class: net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG + * Method: getRGB32_1Format + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG_getRGB32_11Format + (JNIEnv *, jclass); + +/* + * Class: net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG + * Method: getBGR32Format + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG_getBGR32Format + (JNIEnv *, jclass); + +/* + * Class: net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG + * Method: getBGR32_1Format + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_codec_video_FFMPEG_getBGR32_11Format (JNIEnv *, jclass); /* diff --git a/src/native/screencapture/net_java_sip_communicator_impl_neomedia_imgstreaming_NativeScreenCapture.c b/src/native/screencapture/net_java_sip_communicator_impl_neomedia_imgstreaming_NativeScreenCapture.c index 3c6965d..23d828e 100644 --- a/src/native/screencapture/net_java_sip_communicator_impl_neomedia_imgstreaming_NativeScreenCapture.c +++ b/src/native/screencapture/net_java_sip_communicator_impl_neomedia_imgstreaming_NativeScreenCapture.c @@ -76,6 +76,8 @@ static int windows_grab_screen(jbyte* data, int32_t x, int32_t y, int32_t w, int RGBQUAD *pixels = NULL; size_t i = 0; size_t off = 0; + uint32_t test = 1; + int little_endian = *((uint8_t*)&test); /* get handle to the entire screen of Windows */ desktop = GetDC(NULL); @@ -194,6 +196,15 @@ static int windows_grab_screen(jbyte* data, int32_t x, int32_t y, int32_t w, int uint32_t pixel = 0xFF000000 | quad->rgbRed << 16 | quad->rgbGreen << 8 | quad->rgbBlue; /* Java int is always big endian so output as ARGB */ + if(little_endian) + { + /* ARGB is BGRA in little-endian */ + uint8_t r = (pixel >> 16) & 0xff; + uint8_t g = (pixel >> 8) & 0xff; + uint8_t b = pixel & 0xff; + pixel = b << 24 | g << 16 | r << 8 | 0xff; + } + memcpy(data + off, &pixel, 4); off += 4; } @@ -229,6 +240,8 @@ static int quartz_grab_screen(jbyte* data, int32_t x, int32_t y, int32_t w, int3 size_t off = 0; size_t i = 0; CGRect rect; + uint32_t test = 1; + int little_endian = *((uint8_t*)&test); rect = CGRectMake(x, y, w, h); img = CGWindowListCreateImage(rect, kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault); @@ -249,12 +262,19 @@ static int quartz_grab_screen(jbyte* data, int32_t x, int32_t y, int32_t w, int3 for(i = 0 ; i < len ; i+=4) { uint32_t pixel = *((uint32_t*)&pixels[i]); - uint8_t r = (pixel >> 16) & 0xff; - uint8_t g = (pixel >> 8) & 0xff; - uint8_t b = pixel & 0xff; + + pixel |= (0xff << 24); /* Java int is always big endian so output as ARGB */ - pixel = 0xff << 24 | r << 16 | g << 8 | b; + if(little_endian) + { + /* ARGB is BGRA in little-endian */ + uint8_t r = (pixel >> 16) & 0xff; + uint8_t g = (pixel >> 8) & 0xff; + uint8_t b = pixel & 0xff; + pixel = b << 24 | g << 16 | r << 8 | 0xff; + } + memcpy(data + off, &pixel, 4); off += 4; } @@ -294,6 +314,8 @@ static int x11_grab_screen(const char* x11display, jbyte* data, int32_t x, int32 int i = 0; int j = 0; size_t size = 0; + uint32_t test = 1; + int little_endian = *((uint8_t*)&test); display_str = x11display ? x11display : getenv("DISPLAY"); @@ -403,13 +425,18 @@ static int x11_grab_screen(const char* x11display, jbyte* data, int32_t x, int32 /* do not care about high 32-bit for Linux 64 bit * machine (sizeof(unsigned long) = 8) */ - uint32_t pixel = (uint32_t)XGetPixel(img, i, j); - uint8_t r = (pixel >> 16) & 0xff; - uint8_t g = (pixel >> 8) & 0xff; - uint8_t b = pixel & 0xff; - + uint32_t pixel = (uint32_t)XGetPixel(img, i, j) | (0xff << 24); + /* Java int is always big endian so output as ARGB */ - pixel = 0xff << 24 | r << 16 | g << 8 | b; + if(little_endian) + { + /* ARGB is BGRA in little-endian */ + uint8_t r = (pixel >> 16) & 0xff; + uint8_t g = (pixel >> 8) & 0xff; + uint8_t b = pixel & 0xff; + pixel = b << 24 | g << 16 | r << 8 | 0xff; + } + memcpy(data + off, &pixel, 4); off += 4; } |