image/encoders/png/nsPNGEncoder.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

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "mozilla/Attributes.h"
michael@0 7 #include "mozilla/ReentrantMonitor.h"
michael@0 8
michael@0 9 #include "imgIEncoder.h"
michael@0 10
michael@0 11 #include "nsCOMPtr.h"
michael@0 12
michael@0 13 #include <png.h>
michael@0 14
michael@0 15 #define NS_PNGENCODER_CID \
michael@0 16 { /* 38d1592e-b81e-432b-86f8-471878bbfe07 */ \
michael@0 17 0x38d1592e, \
michael@0 18 0xb81e, \
michael@0 19 0x432b, \
michael@0 20 {0x86, 0xf8, 0x47, 0x18, 0x78, 0xbb, 0xfe, 0x07} \
michael@0 21 }
michael@0 22
michael@0 23 // Provides PNG encoding functionality. Use InitFromData() to do the
michael@0 24 // encoding. See that function definition for encoding options.
michael@0 25
michael@0 26 class nsPNGEncoder MOZ_FINAL : public imgIEncoder
michael@0 27 {
michael@0 28 typedef mozilla::ReentrantMonitor ReentrantMonitor;
michael@0 29 public:
michael@0 30 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 31 NS_DECL_IMGIENCODER
michael@0 32 NS_DECL_NSIINPUTSTREAM
michael@0 33 NS_DECL_NSIASYNCINPUTSTREAM
michael@0 34
michael@0 35 nsPNGEncoder();
michael@0 36 ~nsPNGEncoder();
michael@0 37
michael@0 38 protected:
michael@0 39 nsresult ParseOptions(const nsAString& aOptions,
michael@0 40 bool* useTransparency,
michael@0 41 bool* skipFirstFrame,
michael@0 42 uint32_t* numAnimatedFrames,
michael@0 43 uint32_t* numIterations,
michael@0 44 uint32_t* frameDispose,
michael@0 45 uint32_t* frameBlend,
michael@0 46 uint32_t* frameDelay,
michael@0 47 uint32_t* offsetX,
michael@0 48 uint32_t* offsetY);
michael@0 49 void ConvertHostARGBRow(const uint8_t* aSrc, uint8_t* aDest,
michael@0 50 uint32_t aPixelWidth, bool aUseTransparency);
michael@0 51 void StripAlpha(const uint8_t* aSrc, uint8_t* aDest,
michael@0 52 uint32_t aPixelWidth);
michael@0 53 static void WarningCallback(png_structp png_ptr, png_const_charp warning_msg);
michael@0 54 static void ErrorCallback(png_structp png_ptr, png_const_charp error_msg);
michael@0 55 static void WriteCallback(png_structp png, png_bytep data, png_size_t size);
michael@0 56 void NotifyListener();
michael@0 57
michael@0 58 png_struct* mPNG;
michael@0 59 png_info* mPNGinfo;
michael@0 60
michael@0 61 bool mIsAnimation;
michael@0 62 bool mFinished;
michael@0 63
michael@0 64 // image buffer
michael@0 65 uint8_t* mImageBuffer;
michael@0 66 uint32_t mImageBufferSize;
michael@0 67 uint32_t mImageBufferUsed;
michael@0 68
michael@0 69 uint32_t mImageBufferReadPoint;
michael@0 70
michael@0 71 nsCOMPtr<nsIInputStreamCallback> mCallback;
michael@0 72 nsCOMPtr<nsIEventTarget> mCallbackTarget;
michael@0 73 uint32_t mNotifyThreshold;
michael@0 74
michael@0 75 /*
michael@0 76 nsPNGEncoder is designed to allow one thread to pump data into it while another
michael@0 77 reads from it. We lock to ensure that the buffer remains append-only while
michael@0 78 we read from it (that it is not realloced) and to ensure that only one thread
michael@0 79 dispatches a callback for each call to AsyncWait.
michael@0 80 */
michael@0 81 ReentrantMonitor mReentrantMonitor;
michael@0 82 };

mercurial