tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsJPEGEncoder.h (2283B)


      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/. */
      5 
      6 #ifndef mozilla_image_encoders_jpeg_nsJPEGEncoder_h
      7 #define mozilla_image_encoders_jpeg_nsJPEGEncoder_h
      8 
      9 #include "imgIEncoder.h"
     10 
     11 #include "mozilla/ReentrantMonitor.h"
     12 #include "mozilla/Attributes.h"
     13 
     14 #include "nsCOMPtr.h"
     15 
     16 struct jpeg_compress_struct;
     17 struct jpeg_common_struct;
     18 
     19 #define NS_JPEGENCODER_CID                    \
     20  {/* ac2bb8fe-eeeb-4572-b40f-be03932b56e0 */ \
     21   0xac2bb8fe,                                \
     22   0xeeeb,                                    \
     23   0x4572,                                    \
     24   {0xb4, 0x0f, 0xbe, 0x03, 0x93, 0x2b, 0x56, 0xe0}}
     25 
     26 // Provides JPEG encoding functionality. Use InitFromData() to do the
     27 // encoding. See that function definition for encoding options.
     28 class nsJPEGEncoderInternal;
     29 
     30 class nsJPEGEncoder final : public imgIEncoder {
     31  friend class nsJPEGEncoderInternal;
     32  typedef mozilla::ReentrantMonitor ReentrantMonitor;
     33 
     34 public:
     35  NS_DECL_THREADSAFE_ISUPPORTS
     36  NS_DECL_IMGIENCODER
     37  NS_DECL_NSIINPUTSTREAM
     38  NS_DECL_NSIASYNCINPUTSTREAM
     39 
     40  nsJPEGEncoder();
     41 
     42 private:
     43  ~nsJPEGEncoder();
     44 
     45 protected:
     46  void ConvertHostARGBRow(const uint8_t* aSrc, uint8_t* aDest,
     47                          uint32_t aPixelWidth);
     48  void ConvertRGBARow(const uint8_t* aSrc, uint8_t* aDest,
     49                      uint32_t aPixelWidth);
     50 
     51  void NotifyListener();
     52 
     53  bool mFinished;
     54 
     55  // image buffer
     56  uint8_t* mImageBuffer;
     57  uint32_t mImageBufferSize;
     58  uint32_t mImageBufferUsed;
     59 
     60  uint32_t mImageBufferReadPoint;
     61 
     62  nsCOMPtr<nsIInputStreamCallback> mCallback;
     63  nsCOMPtr<nsIEventTarget> mCallbackTarget;
     64  uint32_t mNotifyThreshold;
     65 
     66  // nsJPEGEncoder is designed to allow one thread to pump data into it while
     67  // another reads from it.  We lock to ensure that the buffer remains
     68  // append-only while we read from it (that it is not realloced) and to ensure
     69  // that only one thread dispatches a callback for each call to AsyncWait.
     70  ReentrantMonitor mReentrantMonitor MOZ_UNANNOTATED;
     71 };
     72 
     73 #endif  // mozilla_image_encoders_jpeg_nsJPEGEncoder_h