1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 //=============================================================================
24 //
25 // Base bitmap header
26 //
27 //=============================================================================
28
29 #ifndef AGS_SHARED_GFX_BITMAP_H
30 #define AGS_SHARED_GFX_BITMAP_H
31
32 #include "ags/shared/util/geometry.h"
33 #include "ags/shared/util/string.h"
34
35 namespace AGS3 {
36 namespace AGS {
37 namespace Shared {
38
39 // Mask option for blitting one bitmap on another
40 enum BitmapMaskOption {
41 // Plain copies bitmap pixels
42 kBitmap_Copy,
43 // Consider mask color fully transparent and do not copy pixels having it
44 kBitmap_Transparency
45 };
46
47 enum BitmapFlip {
48 kBitmap_HFlip,
49 kBitmap_VFlip,
50 kBitmap_HVFlip
51 };
52
53 } // namespace Shared
54 } // namespace AGS
55 } // namespace AGS3
56
57 #include "ags/shared/gfx/allegro_bitmap.h"
58
59 namespace AGS3 {
60 namespace AGS {
61 namespace Shared {
62
63 class Bitmap;
64
65 // TODO: revise this construction later
66 namespace BitmapHelper {
67 // Helper functions, that delete faulty bitmaps automatically, and return
68 // NULL if bitmap could not be created.
69 Bitmap *CreateBitmap(int width, int height, int color_depth = 0);
70 Bitmap *CreateTransparentBitmap(int width, int height, int color_depth = 0);
71 Bitmap *CreateSubBitmap(Bitmap *src, const Rect &rc);
72 Bitmap *CreateBitmapCopy(Bitmap *src, int color_depth = 0);
73 Bitmap *LoadFromFile(const char *filename);
LoadFromFile(const String & filename)74 inline Bitmap *LoadFromFile(const String &filename) {
75 return LoadFromFile(filename.GetCStr());
76 }
77
78 // Stretches bitmap to the requested size. The new bitmap will have same
79 // colour depth. Returns original bitmap if no changes are necessary.
80 Bitmap *AdjustBitmapSize(Bitmap *src, int width, int height);
81 // Copy transparency mask and/or alpha channel from one bitmap into another.
82 // Destination and mask bitmaps must be of the same pixel format.
83 // Transparency is merged, meaning that fully transparent pixels on
84 // destination should remain such regardless of mask pixel values.
85 void CopyTransparency(Bitmap *dst, const Bitmap *mask, bool dst_has_alpha, bool mask_has_alpha);
86 // Copy pixel data into bitmap from memory buffer. It is required that the
87 // source matches bitmap format and has enough data.
88 // Pitch is given in bytes and defines the length of the source scan line.
89 // Offset is optional and defines horizontal offset, in pixels.
90 void ReadPixelsFromMemory(Bitmap *dst, const uint8_t *src_buffer, const size_t src_pitch, const size_t src_px_offset = 0);
91 } // namespace BitmapHelper
92
93 } // namespace Shared
94 } // namespace AGS
95 } // namespace AGS3
96
97 #endif
98