2 * Copyright (C) 2013 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #ifndef JPEG_WRITER_H_
17 #define JPEG_WRITER_H_
19 #include "jerr_hook.h"
20 #include "jni_defines.h"
21 #include "jpeg_config.h"
26 * JpegWriter wraps libjpeg's compression functionality and a
27 * java OutputStream object. Write calls result in input data
28 * being compressed and written to the OuputStream.
36 * Call setup with a valid OutputStream reference, bitmap height and
37 * width, pixel format, and compression quality in range (0, 100].
39 * Returns J_SUCCESS on success or a negative error code.
41 int32_t setup(JNIEnv *env, jobject out, int32_t width, int32_t height,
42 Jpeg_Config::Format format, int32_t quality);
45 * Compresses bytes from the input buffer.
47 * ***This method will result in bytes being written to the OutputStream***
49 * Returns J_SUCCESS on success or a negative error code.
51 int32_t write(int8_t* bytes, int32_t length);
54 * Updates the environment pointer. Call this before write or reset
55 * in any jni function call.
57 void updateEnv(JNIEnv *env);
60 * Frees any java global references held by the JpegWriter, destroys
61 * the compress structure, and frees allocations in libjpeg's pools.
65 static const int32_t DEFAULT_X_DENSITY;
66 static const int32_t DEFAULT_Y_DENSITY;
67 static const int32_t DEFAULT_DENSITY_UNIT;
69 void formatPixels(uint8_t* buf, int32_t len);
70 struct jpeg_compress_struct mInfo;
71 ErrManager mErrorManager;
73 JSAMPLE* mScanlineBuf;
74 JSAMPLE* mScanlineIter;
75 int32_t mScanlineBuflen;
76 int32_t mScanlineBytesRemaining;
78 Jpeg_Config::Format mFormat;
83 #endif // JPEG_WRITER_H_