Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
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 | #ifndef nsImageClipboard_h |
michael@0 | 7 | #define nsImageClipboard_h |
michael@0 | 8 | |
michael@0 | 9 | /* Things To Do 11/8/00 |
michael@0 | 10 | |
michael@0 | 11 | Check image metrics, can we support them? Do we need to? |
michael@0 | 12 | Any other render format? HTML? |
michael@0 | 13 | |
michael@0 | 14 | */ |
michael@0 | 15 | |
michael@0 | 16 | #include "nsError.h" |
michael@0 | 17 | #include <windows.h> |
michael@0 | 18 | |
michael@0 | 19 | #include "nsCOMPtr.h" |
michael@0 | 20 | #include "imgIContainer.h" |
michael@0 | 21 | #include "nsIInputStream.h" |
michael@0 | 22 | |
michael@0 | 23 | |
michael@0 | 24 | // |
michael@0 | 25 | // nsImageToClipboard |
michael@0 | 26 | // |
michael@0 | 27 | // A utility class that takes an imgIContainer and does all the bitmap magic |
michael@0 | 28 | // to allow us to put it on the clipboard |
michael@0 | 29 | // |
michael@0 | 30 | class nsImageToClipboard |
michael@0 | 31 | { |
michael@0 | 32 | public: |
michael@0 | 33 | nsImageToClipboard(imgIContainer* aInImage, bool aWantDIBV5 = true); |
michael@0 | 34 | ~nsImageToClipboard(); |
michael@0 | 35 | |
michael@0 | 36 | // Call to get the actual bits that go on the clipboard. If |nullptr|, the |
michael@0 | 37 | // setup operations have failed. |
michael@0 | 38 | // |
michael@0 | 39 | // NOTE: The caller owns the handle and must delete it with ::GlobalRelease() |
michael@0 | 40 | nsresult GetPicture ( HANDLE* outBits ) ; |
michael@0 | 41 | |
michael@0 | 42 | private: |
michael@0 | 43 | |
michael@0 | 44 | // Computes # of bytes needed by a bitmap with the specified attributes. |
michael@0 | 45 | int32_t CalcSize(int32_t aHeight, int32_t aColors, WORD aBitsPerPixel, int32_t aSpanBytes); |
michael@0 | 46 | int32_t CalcSpanLength(uint32_t aWidth, uint32_t aBitCount); |
michael@0 | 47 | |
michael@0 | 48 | // Do the work |
michael@0 | 49 | nsresult CreateFromImage ( imgIContainer* inImage, HANDLE* outBitmap ); |
michael@0 | 50 | |
michael@0 | 51 | nsCOMPtr<imgIContainer> mImage; // the image we're working with |
michael@0 | 52 | bool mWantDIBV5; |
michael@0 | 53 | |
michael@0 | 54 | }; // class nsImageToClipboard |
michael@0 | 55 | |
michael@0 | 56 | |
michael@0 | 57 | struct bitFields { |
michael@0 | 58 | uint32_t red; |
michael@0 | 59 | uint32_t green; |
michael@0 | 60 | uint32_t blue; |
michael@0 | 61 | uint8_t redLeftShift; |
michael@0 | 62 | uint8_t redRightShift; |
michael@0 | 63 | uint8_t greenLeftShift; |
michael@0 | 64 | uint8_t greenRightShift; |
michael@0 | 65 | uint8_t blueLeftShift; |
michael@0 | 66 | uint8_t blueRightShift; |
michael@0 | 67 | }; |
michael@0 | 68 | |
michael@0 | 69 | // |
michael@0 | 70 | // nsImageFromClipboard |
michael@0 | 71 | // |
michael@0 | 72 | // A utility class that takes a DIB from the win32 clipboard and does |
michael@0 | 73 | // all the bitmap magic to convert it to a PNG or a JPEG in the form of a nsIInputStream |
michael@0 | 74 | // |
michael@0 | 75 | class nsImageFromClipboard |
michael@0 | 76 | { |
michael@0 | 77 | public: |
michael@0 | 78 | nsImageFromClipboard () ; |
michael@0 | 79 | ~nsImageFromClipboard ( ) ; |
michael@0 | 80 | |
michael@0 | 81 | // Retrieve the newly created image |
michael@0 | 82 | nsresult GetEncodedImageStream (unsigned char * aClipboardData, const char * aMIMEFormat, nsIInputStream** outImage); |
michael@0 | 83 | |
michael@0 | 84 | private: |
michael@0 | 85 | |
michael@0 | 86 | void InvertRows(unsigned char * aInitialBuffer, uint32_t aSizeOfBuffer, uint32_t aNumBytesPerRow); |
michael@0 | 87 | nsresult ConvertColorBitMap(unsigned char * aInputBuffer, PBITMAPINFO pBitMapInfo, unsigned char * aOutBuffer); |
michael@0 | 88 | void CalcBitmask(uint32_t aMask, uint8_t& aBegin, uint8_t& aLength); |
michael@0 | 89 | void CalcBitShift(bitFields * aColorMask); |
michael@0 | 90 | |
michael@0 | 91 | }; // nsImageFromClipboard |
michael@0 | 92 | |
michael@0 | 93 | #endif |