Home | History | Annotate | Download | only in images
      1 /*
      2  * Copyright (C) 2010 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 SkJpegUtility_DEFINED
     18 #define SkJpegUtility_DEFINED
     19 
     20 #include "SkImageDecoder.h"
     21 #include "SkStream.h"
     22 
     23 extern "C" {
     24     #include "jpeglib.h"
     25     #include "jerror.h"
     26 }
     27 
     28 #include <setjmp.h>
     29 
     30 /* Our error-handling struct.
     31  *
     32 */
     33 struct skjpeg_error_mgr : jpeg_error_mgr {
     34     jmp_buf fJmpBuf;
     35 };
     36 
     37 
     38 void skjpeg_error_exit(j_common_ptr cinfo);
     39 
     40 ///////////////////////////////////////////////////////////////////////////
     41 /* Our source struct for directing jpeg to our stream object.
     42 */
     43 struct skjpeg_source_mgr : jpeg_source_mgr {
     44     skjpeg_source_mgr(SkStream* stream, SkImageDecoder* decoder, bool ownStream);
     45     ~skjpeg_source_mgr();
     46 
     47     SkStream*   fStream;
     48     void*       fMemoryBase;
     49     size_t      fMemoryBaseSize;
     50     bool        fUnrefStream;
     51     SkImageDecoder* fDecoder;
     52     enum {
     53         kBufferSize = 1024
     54     };
     55     char    fBuffer[kBufferSize];
     56 };
     57 
     58 /////////////////////////////////////////////////////////////////////////////
     59 /* Our destination struct for directing decompressed pixels to our stream
     60  * object.
     61  */
     62 struct skjpeg_destination_mgr : jpeg_destination_mgr {
     63     skjpeg_destination_mgr(SkWStream* stream);
     64 
     65     SkWStream*  fStream;
     66 
     67     enum {
     68         kBufferSize = 1024
     69     };
     70     uint8_t fBuffer[kBufferSize];
     71 };
     72 
     73 #endif
     74