widget/windows/nsImageClipboard.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/windows/nsImageClipboard.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,93 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsImageClipboard_h
    1.10 +#define nsImageClipboard_h
    1.11 +
    1.12 +/* Things To Do 11/8/00
    1.13 +
    1.14 +Check image metrics, can we support them? Do we need to?
    1.15 +Any other render format? HTML?
    1.16 +
    1.17 +*/
    1.18 +
    1.19 +#include "nsError.h"
    1.20 +#include <windows.h>
    1.21 +
    1.22 +#include "nsCOMPtr.h"
    1.23 +#include "imgIContainer.h"
    1.24 +#include "nsIInputStream.h"
    1.25 +
    1.26 +
    1.27 +//
    1.28 +// nsImageToClipboard
    1.29 +//
    1.30 +// A utility class that takes an imgIContainer and does all the bitmap magic
    1.31 +// to allow us to put it on the clipboard
    1.32 +//
    1.33 +class nsImageToClipboard
    1.34 +{
    1.35 +public:
    1.36 +  nsImageToClipboard(imgIContainer* aInImage, bool aWantDIBV5 = true);
    1.37 +  ~nsImageToClipboard();
    1.38 +
    1.39 +    // Call to get the actual bits that go on the clipboard. If |nullptr|, the
    1.40 +    // setup operations have failed.
    1.41 +    //
    1.42 +    // NOTE: The caller owns the handle and must delete it with ::GlobalRelease()
    1.43 +  nsresult GetPicture ( HANDLE* outBits ) ;
    1.44 +
    1.45 +private:
    1.46 +
    1.47 +    // Computes # of bytes needed by a bitmap with the specified attributes.
    1.48 +  int32_t CalcSize(int32_t aHeight, int32_t aColors, WORD aBitsPerPixel, int32_t aSpanBytes);
    1.49 +  int32_t CalcSpanLength(uint32_t aWidth, uint32_t aBitCount);
    1.50 +
    1.51 +    // Do the work
    1.52 +  nsresult CreateFromImage ( imgIContainer* inImage, HANDLE* outBitmap );
    1.53 +
    1.54 +  nsCOMPtr<imgIContainer> mImage;            // the image we're working with
    1.55 +  bool mWantDIBV5;
    1.56 +
    1.57 +}; // class nsImageToClipboard
    1.58 +
    1.59 +
    1.60 +struct bitFields {
    1.61 +    uint32_t red;
    1.62 +    uint32_t green;
    1.63 +    uint32_t blue;
    1.64 +    uint8_t redLeftShift;
    1.65 +    uint8_t redRightShift;
    1.66 +    uint8_t greenLeftShift;
    1.67 +    uint8_t greenRightShift;
    1.68 +    uint8_t blueLeftShift;
    1.69 +    uint8_t blueRightShift;
    1.70 +};
    1.71 +
    1.72 +//
    1.73 +// nsImageFromClipboard
    1.74 +//
    1.75 +// A utility class that takes a DIB from the win32 clipboard and does
    1.76 +// all the bitmap magic to convert it to a PNG or a JPEG in the form of a nsIInputStream
    1.77 +//
    1.78 +class nsImageFromClipboard
    1.79 +{
    1.80 +public:
    1.81 +  nsImageFromClipboard () ;
    1.82 +  ~nsImageFromClipboard ( ) ;
    1.83 +  
    1.84 +    // Retrieve the newly created image
    1.85 +  nsresult GetEncodedImageStream (unsigned char * aClipboardData, const char * aMIMEFormat, nsIInputStream** outImage);
    1.86 +
    1.87 +private:
    1.88 +
    1.89 +  void InvertRows(unsigned char * aInitialBuffer, uint32_t aSizeOfBuffer, uint32_t aNumBytesPerRow);
    1.90 +  nsresult ConvertColorBitMap(unsigned char * aInputBuffer, PBITMAPINFO pBitMapInfo, unsigned char * aOutBuffer);
    1.91 +  void CalcBitmask(uint32_t aMask, uint8_t& aBegin, uint8_t& aLength);
    1.92 +  void CalcBitShift(bitFields * aColorMask);
    1.93 +
    1.94 +}; // nsImageFromClipboard
    1.95 +
    1.96 +#endif

mercurial