image/encoders/jpeg/nsJPEGEncoder.h

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "imgIEncoder.h"
     8 #include "mozilla/ReentrantMonitor.h"
     9 #include "mozilla/Attributes.h"
    11 #include "nsCOMPtr.h"
    13 // needed for JPEG library
    14 #include <stdio.h>
    16 extern "C" {
    17 #include "jpeglib.h"
    18 }
    20 #define NS_JPEGENCODER_CID \
    21 { /* ac2bb8fe-eeeb-4572-b40f-be03932b56e0 */         \
    22      0xac2bb8fe,                                     \
    23      0xeeeb,                                         \
    24      0x4572,                                         \
    25     {0xb4, 0x0f, 0xbe, 0x03, 0x93, 0x2b, 0x56, 0xe0} \
    26 }
    28 // Provides JPEG encoding functionality. Use InitFromData() to do the
    29 // encoding. See that function definition for encoding options.
    31 class nsJPEGEncoder MOZ_FINAL : public imgIEncoder
    32 {
    33   typedef mozilla::ReentrantMonitor ReentrantMonitor;
    34 public:
    35   NS_DECL_THREADSAFE_ISUPPORTS
    36   NS_DECL_IMGIENCODER
    37   NS_DECL_NSIINPUTSTREAM
    38   NS_DECL_NSIASYNCINPUTSTREAM
    40   nsJPEGEncoder();
    42 private:
    43   ~nsJPEGEncoder();
    45 protected:
    47   void ConvertHostARGBRow(const uint8_t* aSrc, uint8_t* aDest,
    48                           uint32_t aPixelWidth);
    49   void ConvertRGBARow(const uint8_t* aSrc, uint8_t* aDest, uint32_t aPixelWidth);
    51   static void initDestination(jpeg_compress_struct* cinfo);
    52   static boolean emptyOutputBuffer(jpeg_compress_struct* cinfo);
    53   static void termDestination(jpeg_compress_struct* cinfo);
    55   static void errorExit(jpeg_common_struct* cinfo);
    57   void NotifyListener();
    59   bool mFinished;
    61   // image buffer
    62   uint8_t* mImageBuffer;
    63   uint32_t mImageBufferSize;
    64   uint32_t mImageBufferUsed;
    66   uint32_t mImageBufferReadPoint;
    68   nsCOMPtr<nsIInputStreamCallback> mCallback;
    69   nsCOMPtr<nsIEventTarget> mCallbackTarget;
    70   uint32_t mNotifyThreshold;
    72   /*
    73     nsJPEGEncoder is designed to allow one thread to pump data into it while another
    74     reads from it.  We lock to ensure that the buffer remains append-only while
    75     we read from it (that it is not realloced) and to ensure that only one thread
    76     dispatches a callback for each call to AsyncWait.
    77    */
    78   ReentrantMonitor mReentrantMonitor;
    79 };

mercurial