1515
1616#include <android/log.h>
1717
18+ #if defined(__aarch64__ ) || defined(__arm__ )
19+ #include <arm_neon.h>
20+ #define ARM_NEON
21+ #endif
22+
1823#define LOGI (...) __android_log_print(ANDROID_LOG_INFO, "LTW", __VA_ARGS__)
1924
2025static GLint pick_depth_internalformat (GLenum * type , bool * convert ) {
@@ -348,12 +353,42 @@ static void convert_##INTYPE##_##INCHANNELS##_to_##OUTTYPE##_##OUTCHANNELS(GLuin
348353 } \
349354} \
350355
356+ #ifdef ARM_NEON
357+ void
358+ convert_GLubyte_4_to_GLubyte_4 (GLuint unpack_row_length , GLuint height , const GLubyte * in ,
359+ GLubyte * out , GLuint outw , const unsigned char swizzle [4 ]) {
360+ GLint s = sizeof (GLubyte );
361+ GLint a = current_context -> unpack .alignment ;
362+ GLuint k ;
363+ if (s >= a )k = unpack_row_length * 4 ;
364+ else
365+ k = (GLuint ) (((double ) a / s ) * ceil ((s * 4.0 * unpack_row_length ) / a ));
366+
367+ uint64_t swizzle_raw = * (uint32_t * )swizzle ;
368+ uint8x8_t index = vadd_u8 (vcreate_u8 ((uint64_t ) swizzle_raw | swizzle_raw << 32 ) , vcreate_u8 (0x0404040400000000L ));
369+
370+ for (GLuint y = 0 ; y < height ; y ++ ) {
371+ const GLubyte * inrow = & in [k * y ];
372+ GLubyte * outrow = & out [outw * y * 4 ];
373+
374+ for (GLuint x = 0 ; x < unpack_row_length ; x += 2 ) {
375+ GLuint outbase = x * 4 ;
376+ GLuint inbase = x * 4 ;
377+ {
378+ uint8x8_t rowbase = * (uint8x8_t * ) & inrow [inbase ];
379+ * (uint8x8_t * )& outrow [outbase ] = vtbl1_u8 (rowbase , index );
380+ }
381+ }
382+ }
383+ }
384+ #else
351385CONVERT (GLubyte , GLubyte , 4 , 4 , {
352386 outrow [outbase + 0 ] = inrow [inbase + swizzle [0 ]];
353387 outrow [outbase + 1 ] = inrow [inbase + swizzle [1 ]];
354388 outrow [outbase + 2 ] = inrow [inbase + swizzle [2 ]];
355389 outrow [outbase + 3 ] = inrow [inbase + swizzle [3 ]];
356390})
391+ #endif
357392
358393CONVERT (GLubyte , GLubyte , 3 , 4 , {
359394 outrow [outbase + 0 ] = inrow [inbase + 0 ];
@@ -363,6 +398,9 @@ CONVERT(GLubyte, GLubyte, 3, 4, {
363398})
364399
365400INTERNAL void convert_texture2d (GLenum type , GLenum format , GLuint width , GLuint height , GLvoid const * data , GLenum outtype , GLenum outformat , GLvoid * * outdata ) {
401+ if (type == GL_UNSIGNED_INT_8_8_8_8_REV && (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT )) {
402+ type = GL_UNSIGNED_BYTE ;
403+ }
366404 if (!is_type_basic (type ) || !is_type_basic (outtype )) {
367405 LOGI ("conversion between non-basic types %x and %x" , type , outtype );
368406 return ;
0 commit comments