Home | History | Annotate | Download | only in codec
      1 /*
      2  * Copyright 2015 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #ifndef SkJpegDecoderMgr_DEFINED
      9 #define SkJpegDecoderMgr_DEFINED
     10 
     11 #include "SkCodec.h"
     12 #include "SkCodecPriv.h"
     13 #include <stdio.h>
     14 #include "SkJpegUtility.h"
     15 
     16 extern "C" {
     17     #include "jpeglib.h"
     18 }
     19 
     20 class JpegDecoderMgr : SkNoncopyable {
     21 public:
     22 
     23     /*
     24      * Print a useful error message and return false
     25      */
     26     bool returnFalse(const char caller[]);
     27 
     28     /*
     29      * Print a useful error message and return a decode failure
     30      */
     31     SkCodec::Result returnFailure(const char caller[], SkCodec::Result result);
     32 
     33     /*
     34      * Create the decode manager
     35      * Does not take ownership of stream
     36      */
     37     JpegDecoderMgr(SkStream* stream);
     38 
     39     /*
     40      * Initialize decompress struct
     41      * Initialize the source manager
     42      */
     43     void  init();
     44 
     45     /*
     46      * Returns true if it successfully sets outColor to the encoded color,
     47      * and false otherwise.
     48      */
     49     bool getEncodedColor(SkEncodedInfo::Color* outColor);
     50 
     51     /*
     52      * Free memory used by the decode manager
     53      */
     54     ~JpegDecoderMgr();
     55 
     56     /*
     57      * Get the jump buffer in order to set an error return point
     58      */
     59     jmp_buf& getJmpBuf();
     60 
     61     /*
     62      * Get function for the decompress info struct
     63      */
     64     jpeg_decompress_struct* dinfo();
     65 
     66 private:
     67 
     68     jpeg_decompress_struct fDInfo;
     69     skjpeg_source_mgr      fSrcMgr;
     70     skjpeg_error_mgr       fErrorMgr;
     71     jpeg_progress_mgr      fProgressMgr;
     72     bool                   fInit;
     73 };
     74 
     75 #endif
     76