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