/* * Class: org_apache_harmony_luni_platform_OSFileSystem * Method: writeImpl * Signature: (J[BII)J */ JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSFileSystem_writeImpl (JNIEnv * env, jobject thiz, jlong fd, jbyteArray byteArray, jint offset, jint nbytes) { PORT_ACCESS_FROM_ENV (env); jboolean isCopy; jbyte *bytes = (*env)->GetByteArrayElements (env, byteArray, &isCopy); jlong result; result = (jlong) hyfile_write ((IDATA) fd, (void *) (bytes + offset), (IDATA) nbytes); if(result == -1 && hyerror_last_error_number() == HYPORT_ERROR_FILE_LOCKED){ throwNewExceptionByName(env, "java/io/IOException", netLookupErrorString(env, HYPORT_ERROR_FILE_LOCKED)); } (*env)->ReleaseByteArrayElements (env, byteArray, bytes, JNI_ABORT); return result; }
/* * Class: org_apache_harmony_x_imageio_plugins_jpeg_JPEGImageWriter * Method: encode * Signature: ([BIIIIIIIZ[[IJ)Z */ JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_imageio_plugins_jpeg_JPEGImageWriter_encode(JNIEnv *env, jobject callerObj, jbyteArray arr, jint srcWidth, jint width, jint height, jint deltaX, jint in_cs, jint out_cs, jint numBands, jboolean progressive, jobjectArray dqts, jlong handle) { JSAMPROW row_pointer; struct jpeg_compress_struct * cinfo; enc_error_mgr_ptr err_mgr; int i, j; int cur_scanline; unsigned char * native_buffer; unsigned char * rowPtr; jboolean optimizeHuffman = FALSE; row_pointer = (JSAMPROW) malloc(width * numBands); if (!row_pointer) { throwNewOutOfMemoryError(env, "Unable to allocate memory for IJG structures"); return FALSE; } cinfo = (struct jpeg_compress_struct *) (IDATA)handle; err_mgr = (enc_error_mgr_ptr) cinfo->err; if (setjmp(err_mgr->jmp_buffer)) { if (!(*env)->ExceptionOccurred(env)) { char msg_buffer[JMSG_LENGTH_MAX]; cinfo->err->format_message((j_common_ptr)cinfo, msg_buffer); throwNewExceptionByName(env, "javax/imageio/IIOException", msg_buffer); } if (row_pointer) { free(row_pointer); } return FALSE; } cinfo->image_width = width; cinfo->image_height = height; cinfo->input_components = numBands; cinfo->in_color_space = in_cs; jpeg_set_defaults(cinfo); jpeg_set_colorspace(cinfo, out_cs); cinfo->optimize_coding = optimizeHuffman; //-- TRUE - for pure abbrivated images (wo tables) creation //-- if you want to write some tables set "sent_table = FALSE" after //-- this call for the table to be emitted. //jpeg_suppress_tables(&cinfo, TRUE); jpeg_suppress_tables(cinfo, FALSE); setupDQTs(env, cinfo, dqts); //-- only simple progression sequence if (progressive) { jpeg_simple_progression(cinfo); } //-- TRUE forces all "sent_table = FALSE" so all tables will be written jpeg_start_compress(cinfo, TRUE); //-- use this for tables-only files and abbrivated images. //-- If using jpeg_suppress_tables(&cinfo, TRUE): //-- Only DQT sent_table = FALSE right now -> so DQT will be written but not DHT. //-- uncomment when custom huffman tables be used. //jpeg_start_compress(&cinfo, FALSE); cur_scanline = 0; while (cinfo->next_scanline < cinfo->image_height) { (*env)->CallVoidMethod(env, callerObj, getScanlineID, cur_scanline); // checking for an exception in the java method if ((*env)->ExceptionOccurred(env)) { //c_struct->exception_in_callback = TRUE; cinfo->err->error_exit((j_common_ptr) cinfo); } native_buffer = (JOCTET*) (*env)->GetPrimitiveArrayCritical(env, arr, NULL); // subsampling and copying to internal array rowPtr = row_pointer; for (i = 0; i < srcWidth * numBands; i += numBands * deltaX) { for (j = 0; j < numBands; j++) { *rowPtr++ = native_buffer[i + j]; } } (*env)->ReleasePrimitiveArrayCritical(env, arr, native_buffer, 0); jpeg_write_scanlines(cinfo, &row_pointer, 1); cur_scanline++; } jpeg_finish_compress(cinfo); free(row_pointer); return TRUE; }
/** * Throw java.util.zip.ZipException with the message provided */ void throwJavaZIOException (JNIEnv * env, const char *message) { throwNewExceptionByName(env, "java/util/zip/ZipException", message); }
/** * Throw java.lang.InternalError */ void throwNewInternalError (JNIEnv * env, const char *message) { throwNewExceptionByName(env, "java/lang/InternalError", message); }
/** * Throw java.lang.IllegalArgumentException */ void throwNewIllegalArgumentException (JNIEnv * env, const char *message) { throwNewExceptionByName(env, "java/lang/IllegalArgumentException", message); }