Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  *
      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
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     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.
     15  */
     16 
     17 #ifndef LIBJPEG_HOOK_H_
     18 #define LIBJPEG_HOOK_H_
     19 
     20 extern "C" {
     21 #include "jinclude.h"
     22 #include "jpeglib.h"
     23 #include "jerror.h"
     24 }
     25 
     26 #include "inputstream_wrapper.h"
     27 #include "outputstream_wrapper.h"
     28 
     29 #include <stdint.h>
     30 
     31 /**
     32  * DestManager holds the libjpeg destination manager struct and
     33  * a holder with a java OutputStream.
     34  */
     35 typedef struct {
     36     struct jpeg_destination_mgr mgr;
     37     OutputStreamWrapper *outStream;
     38 } DestManager;
     39 
     40 // Initializes the DestManager struct, sets up the jni refs
     41 int32_t MakeDst(j_compress_ptr cinfo, JNIEnv *env, jobject outStream);
     42 
     43 /**
     44  * Updates the jni env pointer. This should be called in the beginning of any
     45  * JNI method in jpegstream.cpp before CleanDst or any of the libjpeg functions
     46  * that can trigger a call to an OutputStreamWrapper method.
     47  */
     48 void UpdateDstEnv(j_compress_ptr cinfo, JNIEnv* env);
     49 
     50 // Cleans the jni refs.  To wipe the compress object call jpeg_destroy_compress
     51 void CleanDst(j_compress_ptr cinfo);
     52 
     53 /**
     54  * SourceManager holds the libjpeg source manager struct and a
     55  * holder with a java InputStream.
     56  */
     57 typedef struct {
     58     struct jpeg_source_mgr mgr;
     59     boolean start_of_file;
     60     InputStreamWrapper *inStream;
     61 } SourceManager;
     62 
     63 // Initializes the SourceManager struct, sets up the jni refs
     64 int32_t MakeSrc(j_decompress_ptr cinfo, JNIEnv *env, jobject inStream);
     65 
     66 /**
     67  * Updates the jni env pointer. This should be called in the beginning of any
     68  * JNI method in jpegstream.cpp before CleanSrc or any of the libjpeg functions
     69  * that can trigger a call to an InputStreamWrapper method.
     70  */
     71 void UpdateSrcEnv(j_decompress_ptr cinfo, JNIEnv* env);
     72 
     73 // Cleans the jni refs.  To wipe the decompress object, call jpeg_destroy_decompress
     74 void CleanSrc(j_decompress_ptr cinfo);
     75 
     76 #endif // LIBJPEG_HOOK_H_
     77