Ejemplo n.º 1
0
JNIEXPORT jobject JNICALL Java_com_badlogic_gdx_graphics_glutils_ETC1_encodeImagePKM
  (JNIEnv *env, jclass, jobject imageData, jint offset, jint width, jint height, jint pixelSize) {
  	etc1_byte* imgPtr = (etc1_byte*)env->GetDirectBufferAddress(imageData) + offset;
	int compressedSize = etc1_get_encoded_data_size(width, height);
	etc1_byte* comprPtr = (etc1_byte*)malloc(compressedSize + ETC_PKM_HEADER_SIZE);
	etc1_pkm_format_header(comprPtr, width, height);
	etc1_encode_image(imgPtr, width, height, pixelSize, width * pixelSize, comprPtr + ETC_PKM_HEADER_SIZE);
	return env->NewDirectByteBuffer(comprPtr, compressedSize + ETC_PKM_HEADER_SIZE);
}
JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_glutils_ETC1_formatHeader(JNIEnv* env, jclass clazz, jobject obj_header, jint offset, jint width, jint height) {
	char* header = (char*)(obj_header?env->GetDirectBufferAddress(obj_header):0);


//@line:214

		etc1_pkm_format_header((etc1_byte*)header + offset, width, height);
	

}
static inline jobject wrapped_Java_com_badlogic_gdx_graphics_glutils_ETC1_encodeImagePKM
(JNIEnv* env, jclass clazz, jobject obj_imageData, jint offset, jint width, jint height, jint pixelSize, char* imageData) {

//@line:274

		int compressedSize = etc1_get_encoded_data_size(width, height);
		etc1_byte* compressed = (etc1_byte*)malloc(compressedSize + ETC_PKM_HEADER_SIZE);
		etc1_pkm_format_header(compressed, width, height);
		etc1_encode_image((etc1_byte*)imageData + offset, width, height, pixelSize, width * pixelSize, compressed + ETC_PKM_HEADER_SIZE);
		return env->NewDirectByteBuffer(compressed, compressedSize + ETC_PKM_HEADER_SIZE);
	
}
Ejemplo n.º 4
0
/**
 *  Remove the last row and column of ETC1 blocks, effectively
 *  making a texture that started as power of two into a texture
 *  that is no longer power of two...
 */
bool slice_etc1_data(void *data, int* width, int* height) {

    // First, parse the data and get to it...
    etc1_byte *origData = reinterpret_cast<etc1_byte *>(data);
    if (!etc1_pkm_is_valid(origData)) {
        return false;
    }

    int origW = etc1_pkm_get_width(origData);
    int origH = etc1_pkm_get_height(origData);

    int blockWidth = (origW + 3) >> 2;
    int blockHeight = (origH + 3) >> 2;

    // Make sure that we have blocks to trim off..
    if (blockWidth < 2 || blockHeight < 2) {
        return false;
    }

    int newWidth = (blockWidth - 1) << 2;
    int newHeight = (blockHeight - 1) << 2;

    size_t newDataSz = etc1_get_encoded_data_size(newWidth, newHeight) + ETC_PKM_HEADER_SIZE;
    SkAutoMalloc am(newDataSz);

    etc1_byte *newData = reinterpret_cast<etc1_byte *>(am.get());

    etc1_pkm_format_header(newData, newWidth, newHeight);
    newData += ETC_PKM_HEADER_SIZE;
    origData += ETC_PKM_HEADER_SIZE;

    for (int j = 0; j < blockHeight - 1; ++j) {
        memcpy(newData, origData, (blockWidth - 1)*ETC1_ENCODED_BLOCK_SIZE);
        origData += blockWidth*ETC1_ENCODED_BLOCK_SIZE;
        newData += (blockWidth - 1)*ETC1_ENCODED_BLOCK_SIZE;
    }

    // Stick the data back whence it came
    memcpy(data, am.get(), newDataSz);
    *width = newWidth;
    *height = newHeight;

    return true;
}
Ejemplo n.º 5
0
JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_glutils_ETC1_formatHeader
  (JNIEnv *env, jclass, jobject header, jint offset, jint width, jint height) {
	etc1_byte* headerPtr = (etc1_byte*)env->GetDirectBufferAddress(header) + offset;
	etc1_pkm_format_header(headerPtr, width, height);
}