|
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/. */ |
|
5 |
|
6 #ifndef nsImageClipboard_h |
|
7 #define nsImageClipboard_h |
|
8 |
|
9 /* Things To Do 11/8/00 |
|
10 |
|
11 Check image metrics, can we support them? Do we need to? |
|
12 Any other render format? HTML? |
|
13 |
|
14 */ |
|
15 |
|
16 #include "nsError.h" |
|
17 #include <windows.h> |
|
18 |
|
19 #include "nsCOMPtr.h" |
|
20 #include "imgIContainer.h" |
|
21 #include "nsIInputStream.h" |
|
22 |
|
23 |
|
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(); |
|
35 |
|
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 ) ; |
|
41 |
|
42 private: |
|
43 |
|
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); |
|
47 |
|
48 // Do the work |
|
49 nsresult CreateFromImage ( imgIContainer* inImage, HANDLE* outBitmap ); |
|
50 |
|
51 nsCOMPtr<imgIContainer> mImage; // the image we're working with |
|
52 bool mWantDIBV5; |
|
53 |
|
54 }; // class nsImageToClipboard |
|
55 |
|
56 |
|
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 }; |
|
68 |
|
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 ( ) ; |
|
80 |
|
81 // Retrieve the newly created image |
|
82 nsresult GetEncodedImageStream (unsigned char * aClipboardData, const char * aMIMEFormat, nsIInputStream** outImage); |
|
83 |
|
84 private: |
|
85 |
|
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); |
|
90 |
|
91 }; // nsImageFromClipboard |
|
92 |
|
93 #endif |