michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsImageClipboard_h michael@0: #define nsImageClipboard_h michael@0: michael@0: /* Things To Do 11/8/00 michael@0: michael@0: Check image metrics, can we support them? Do we need to? michael@0: Any other render format? HTML? michael@0: michael@0: */ michael@0: michael@0: #include "nsError.h" michael@0: #include michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "imgIContainer.h" michael@0: #include "nsIInputStream.h" michael@0: michael@0: michael@0: // michael@0: // nsImageToClipboard michael@0: // michael@0: // A utility class that takes an imgIContainer and does all the bitmap magic michael@0: // to allow us to put it on the clipboard michael@0: // michael@0: class nsImageToClipboard michael@0: { michael@0: public: michael@0: nsImageToClipboard(imgIContainer* aInImage, bool aWantDIBV5 = true); michael@0: ~nsImageToClipboard(); michael@0: michael@0: // Call to get the actual bits that go on the clipboard. If |nullptr|, the michael@0: // setup operations have failed. michael@0: // michael@0: // NOTE: The caller owns the handle and must delete it with ::GlobalRelease() michael@0: nsresult GetPicture ( HANDLE* outBits ) ; michael@0: michael@0: private: michael@0: michael@0: // Computes # of bytes needed by a bitmap with the specified attributes. michael@0: int32_t CalcSize(int32_t aHeight, int32_t aColors, WORD aBitsPerPixel, int32_t aSpanBytes); michael@0: int32_t CalcSpanLength(uint32_t aWidth, uint32_t aBitCount); michael@0: michael@0: // Do the work michael@0: nsresult CreateFromImage ( imgIContainer* inImage, HANDLE* outBitmap ); michael@0: michael@0: nsCOMPtr mImage; // the image we're working with michael@0: bool mWantDIBV5; michael@0: michael@0: }; // class nsImageToClipboard michael@0: michael@0: michael@0: struct bitFields { michael@0: uint32_t red; michael@0: uint32_t green; michael@0: uint32_t blue; michael@0: uint8_t redLeftShift; michael@0: uint8_t redRightShift; michael@0: uint8_t greenLeftShift; michael@0: uint8_t greenRightShift; michael@0: uint8_t blueLeftShift; michael@0: uint8_t blueRightShift; michael@0: }; michael@0: michael@0: // michael@0: // nsImageFromClipboard michael@0: // michael@0: // A utility class that takes a DIB from the win32 clipboard and does michael@0: // all the bitmap magic to convert it to a PNG or a JPEG in the form of a nsIInputStream michael@0: // michael@0: class nsImageFromClipboard michael@0: { michael@0: public: michael@0: nsImageFromClipboard () ; michael@0: ~nsImageFromClipboard ( ) ; michael@0: michael@0: // Retrieve the newly created image michael@0: nsresult GetEncodedImageStream (unsigned char * aClipboardData, const char * aMIMEFormat, nsIInputStream** outImage); michael@0: michael@0: private: michael@0: michael@0: void InvertRows(unsigned char * aInitialBuffer, uint32_t aSizeOfBuffer, uint32_t aNumBytesPerRow); michael@0: nsresult ConvertColorBitMap(unsigned char * aInputBuffer, PBITMAPINFO pBitMapInfo, unsigned char * aOutBuffer); michael@0: void CalcBitmask(uint32_t aMask, uint8_t& aBegin, uint8_t& aLength); michael@0: void CalcBitShift(bitFields * aColorMask); michael@0: michael@0: }; // nsImageFromClipboard michael@0: michael@0: #endif