]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/clipboard/headers/BitmapFileHeader.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / gfx / clipboard / headers / BitmapFileHeader.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.utils.ui.gfx.clipboard.headers;\r
13 \r
14 import java.nio.ByteBuffer;\r
15 import java.nio.ByteOrder;\r
16 \r
17 \r
18 \r
19 /**\r
20  * WIN32 API BITMAPFILEHEADER\r
21  * \r
22  * @see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_62uq.asp\r
23  * @author Marko Luukkainen\r
24  *\r
25  */\r
26 public class BitmapFileHeader {\r
27     public short bfType;\r
28     public int bfSize;\r
29     public short bfReserved1;\r
30     public short bfReserved2;\r
31     public int bfOffBits;\r
32     public static final int sizeof = 14;\r
33     \r
34     /**\r
35      * Creates BITMAPFILEHEADER for bitmap that has\r
36      * BITMAPINFO.bmiColors field NULL / undefined \r
37      *\r
38      */\r
39     public BitmapFileHeader() {\r
40         bfType = 'B';\r
41         bfType <<= 8;\r
42         bfType |= (0xff & 'M');\r
43         bfSize = 0;\r
44         bfReserved1 = 0;\r
45         bfReserved2 = 0;\r
46         bfOffBits = sizeof + BitmapInfoHeader.sizeof;\r
47     \r
48     }\r
49     \r
50     public byte[] getBytes() {\r
51         byte [] array = new byte[sizeof];\r
52         ByteBuffer buffer = ByteBuffer.wrap(array);\r
53         buffer.order(ByteOrder.LITTLE_ENDIAN);\r
54         buffer.putShort(bfType);\r
55         buffer.putInt(bfSize);\r
56         buffer.putShort(bfReserved1);\r
57         buffer.putShort(bfReserved2);\r
58         buffer.putInt(bfOffBits);\r
59         return array;\r
60     }\r
61 }\r