ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
bitmap.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 //=============================================================================
23 //
24 // Base bitmap header
25 //
26 //=============================================================================
27 
28 #ifndef AGS_SHARED_GFX_BITMAP_H
29 #define AGS_SHARED_GFX_BITMAP_H
30 
31 #include "ags/shared/gfx/gfx_def.h"
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 } // namespace Shared
48 } // namespace AGS
49 } // namespace AGS3
50 
51 #include "ags/shared/gfx/allegro_bitmap.h"
52 
53 namespace AGS3 {
54 namespace AGS {
55 namespace Shared {
56 
57 class Bitmap;
58 
59 // TODO: revise this construction later
60 namespace BitmapHelper {
61 
62 // Helper functions, that delete faulty bitmaps automatically, and return
63 // NULL if bitmap could not be created.
64 // NOTE: color_depth is in BITS per pixel (i.e. 8, 16, 24, 32...).
65 // NOTE: in all of these color_depth may be passed as 0 in which case a default
66 // color depth will be used (as previously set for the system).
67 // Creates a new bitmap of the given format; the pixel contents are undefined.
68 Bitmap *CreateBitmap(int width, int height, int color_depth = 0);
69 // Creates a new bitmap and clears it with the given color
70 Bitmap *CreateClearBitmap(int width, int height, int color_depth = 0, int clear_color = 0);
71 // Creates a new bitmap and clears it with the transparent color
72 Bitmap *CreateTransparentBitmap(int width, int height, int color_depth = 0);
73 // Creates a sub-bitmap of the given bitmap; the sub-bitmap is a reference to
74 // particular region inside a parent.
75 // WARNING: the parent bitmap MUST be kept in memory for as long as sub-bitmap exists!
76 Bitmap *CreateSubBitmap(Bitmap *src, const Rect &rc);
77 // Creates a plain copy of the given bitmap, optionally converting to a different color depth;
78 // pass color depth 0 to keep the original one.
79 Bitmap *CreateBitmapCopy(Bitmap *src, int color_depth = 0);
80 
81 // Load a bitmap from file; supported formats currently are: BMP, PCX.
82 Bitmap *LoadFromFile(const char *filename);
83 inline Bitmap *LoadFromFile(const String &filename) {
84  return LoadFromFile(filename.GetCStr());
85 }
86 Bitmap *LoadFromFile(PACKFILE *pf);
87 
88 // Stretches bitmap to the requested size. The new bitmap will have same
89 // colour depth. Returns original bitmap if no changes are necessary.
90 Bitmap *AdjustBitmapSize(Bitmap *src, int width, int height);
91 // Makes the given bitmap opaque (full alpha), while keeping pixel RGB unchanged.
92 void MakeOpaque(Bitmap *bmp);
93 // Makes the given bitmap opaque (full alpha), while keeping pixel RGB unchanged.
94 // Skips mask color (leaves it with zero alpha).
95 void MakeOpaqueSkipMask(Bitmap *bmp);
96 // Replaces fully transparent (alpha = 0) pixels with standard mask color.
97 void ReplaceAlphaWithRGBMask(Bitmap *bmp);
98 // Copy transparency mask and/or alpha channel from one bitmap into another.
99 // Destination and mask bitmaps must be of the same pixel format.
100 // Transparency is merged, meaning that fully transparent pixels on
101 // destination should remain such regardless of mask pixel values.
102 void CopyTransparency(Bitmap *dst, const Bitmap *mask, bool dst_has_alpha, bool mask_has_alpha);
103 // Copy pixel data into bitmap from memory buffer. It is required that the
104 // source matches bitmap format and has enough data.
105 // Pitch is given in bytes and defines the length of the source scan line.
106 // Offset is optional and defines horizontal offset, in pixels.
107 void ReadPixelsFromMemory(Bitmap *dst, const uint8_t *src_buffer, const size_t src_pitch, const size_t src_px_offset = 0);
108 
109 } // namespace BitmapHelper
110 } // namespace Shared
111 } // namespace AGS
112 } // namespace AGS3
113 
114 #endif
Definition: achievements_tables.h:27
Definition: ags.h:40