xref: /haiku/headers/os/translation/BitmapStream.h (revision 893988af824e65e49e55f517b157db8386e8002b)
1 /*****************************************************************************/
2 //               File: BitmapStream.h
3 //              Class: BBitmapStream
4 //   Reimplemented by: Travis Smith, Michael Wilber, Translation Kit Team
5 //   Reimplementation: 2002-04
6 //
7 // Description: BPositionIO based object to read/write bitmap format to/from
8 //              a BBitmap object.
9 //
10 //              The BTranslationUtils class uses this object and makes it
11 //              easy for users to load bitmaps.
12 //
13 // Copyright (c) 2002 OpenBeOS Project
14 //
15 // Original Version: Copyright 1998, Be Incorporated, All Rights Reserved.
16 //                   Copyright 1995-1997, Jon Watte
17 //
18 // Permission is hereby granted, free of charge, to any person obtaining a
19 // copy of this software and associated documentation files (the "Software"),
20 // to deal in the Software without restriction, including without limitation
21 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
22 // and/or sell copies of the Software, and to permit persons to whom the
23 // Software is furnished to do so, subject to the following conditions:
24 //
25 // The above copyright notice and this permission notice shall be included
26 // in all copies or substantial portions of the Software.
27 //
28 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
29 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
31 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
34 // DEALINGS IN THE SOFTWARE.
35 /*****************************************************************************/
36 
37 #if !defined(_BITMAP_STREAM_H)
38 #define _BITMAP_STREAM_H
39 
40 #include <BeBuild.h>
41 #include <TranslationDefs.h>
42 #include <DataIO.h>
43 #include <TranslatorFormats.h>
44 #include <ByteOrder.h>
45 
46 class BBitmap;
47 
48 class BBitmapStream : public BPositionIO {
49 public:
50 	BBitmapStream(BBitmap *bitmap = NULL);
51 		// Initializes the stream to use map as the bitmap for stream
52 		// operations. If map is null, a BBitmap is created when properly
53 		// formatted data is written to the stream.
54 
55 	~BBitmapStream();
56 		// Destroys the BBitmap held by this object if it has not been
57 		// detached and frees fpBigEndianHeader
58 
59 	// Overrides from BPositionIO
60 	ssize_t ReadAt(off_t pos, void *buffer, size_t size);
61 		// reads data from the bitmap into buffer
62 	ssize_t WriteAt(off_t pos, const void *data, size_t size);
63 		// writes the data from data into this bitmap
64 		// (if the data is properly formatted)
65 	off_t Seek(off_t position, uint32 whence);
66 		// sets the stream position member
67 	off_t Position() const;
68 		// returns the current stream position
69 	off_t Size() const;
70 		// returns the size of the data
71 	status_t SetSize(off_t size);
72 		// sets the amount of memory to be used by this object
73 
74 	status_t DetachBitmap(BBitmap **outMap);
75 		// "Detaches" the bitmap used by this stream and returns it
76 		// to the user through outMap. This allows the user to
77 		// use the bitmap even after the BBitmapStream that it
78 		// came from has been deleted.
79 
80 protected:
81 	TranslatorBitmap fHeader;
82 		// stores the bitmap header information in the
83 		// host format, used to determine the format of
84 		// the bitmap data and to see if the data is valid
85 	BBitmap *fBitmap;
86 		// the actual bitmap used by this object
87 	size_t fPosition;
88 		// current data position
89 	size_t fSize;
90 		// size of the data stored
91 	bool fDetached;
92 		// true if the bitmap has been detached, false if not
93 
94 	void SwapHeader(const TranslatorBitmap *source,
95 		TranslatorBitmap *destination);
96 		// swaps the byte order of source, no matter what the
97 		// byte order of source is, and copies the result to
98 		// destination
99 
100 private:
101 	TranslatorBitmap *fpBigEndianHeader;
102 		// same data as in fHeader, but in Big Endian format
103 		// (Intel machines are Little Endian)
104 
105 	// For maintaining binary compatibility with past and future
106 	// versions of this object
107 	long fUnused[5];
108 	virtual	void _ReservedBitmapStream1();
109 	virtual void _ReservedBitmapStream2();
110 };
111 
112 #endif /* _BITMAP_STREAM_H */
113 
114