1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ags/lib/allegro/gfx.h"
#include "ags/lib/allegro/color.h"
#include "ags/lib/allegro/flood.h"
#include "ags/lib/allegro/rotate.h"
#include "ags/ags.h"
#include "ags/globals.h"
#include "common/textconsole.h"
#include "common/util.h"
#include "graphics/screen.h"
namespace AGS3 {
int color_conversion;
/*-------------------------------------------------------------------*/
void set_color_conversion(int mode) {
color_conversion = mode;
}
int get_color_conversion() {
return color_conversion;
}
int set_gfx_mode(int card, int w, int h, int depth) {
// Graphics shutdown can be ignored
if (card != -1) {
assert(card == SCUMMVM_ID);
::AGS::g_vm->setGraphicsMode(w, h, depth);
}
return 0;
}
void set_clip_rect(BITMAP *bitmap, int x1, int y1, int x2, int y2) {
// The rect passed to the function in inclusive-inclusive, but
// internally the clipping rect in BITMAP is inclusive-exclusive.
bitmap->cl = CLIP(x1, 0, (int)bitmap->w - 1);
bitmap->ct = CLIP(y1, 0, (int)bitmap->h - 1);
bitmap->cr = CLIP(x2 + 1, 0, (int)bitmap->w);
bitmap->cb = CLIP(y2 + 1, 0, (int)bitmap->h);
}
void get_clip_rect(BITMAP *bitmap, int *x1, int *y1, int *x2, int *y2) {
if (x1)
*x1 = bitmap->cl;
if (y1)
*y1 = bitmap->ct;
if (x2)
*x2 = bitmap->cr - 1;
if (y2)
*y2 = bitmap->cb - 1;
}
void acquire_bitmap(BITMAP *bitmap) {
// No implementation needed
}
void release_bitmap(BITMAP *bitmap) {
// No implementation needed
}
void clear_to_color(BITMAP *bitmap, int color) {
Graphics::ManagedSurface &surf = **bitmap;
surf.clear(color);
}
int bitmap_color_depth(BITMAP *bmp) {
Graphics::ManagedSurface &surf = **bmp;
return (surf.format.bytesPerPixel == 1) ? 8 : surf.format.bpp();
}
int bitmap_mask_color(BITMAP *bmp) {
// For paletted sprites this is 0.
// For other color depths this is bright pink (RGB 255, 0, 255).
// The alpha chanel should be 0.
//if (bmp-format.bytesPerPixel == 1)
// return 0;
//return bmp->format.AGRBToColor(0, 255, 0, 255);
return bmp->getTransparentColor();
}
void blit(const BITMAP *src, BITMAP *dest, int src_x, int src_y, int dst_x, int dst_y, int width, int height) {
dest->draw(src, Common::Rect(src_x, src_y, src_x + width, src_y + height),
dst_x, dst_y, false, false, false, -1);
}
void stretch_blit(const BITMAP *src, BITMAP *dest,
int source_x, int source_y, int source_width, int source_height,
int dest_x, int dest_y, int dest_width, int dest_height) {
dest->stretchDraw(src,
Common::Rect(source_x, source_y, source_x + source_width, source_y + source_height),
Common::Rect(dest_x, dest_y, dest_x + dest_width, dest_y + dest_height),
false, -1);
}
void masked_blit(const BITMAP *src, BITMAP *dest, int src_x, int src_y, int dst_x, int dst_y, int width, int height) {
assert(src->format == dest->format);
dest->draw(src, Common::Rect(src_x, src_y, src_x + width, src_y + height),
dst_x, dst_y, false, false, true, -1);
}
void masked_stretch_blit(const BITMAP *src, BITMAP *dest,
int source_x, int source_y, int source_width, int source_height,
int dest_x, int dest_y, int dest_width, int dest_height) {
dest->stretchDraw(src,
Common::Rect(source_x, source_y, source_x + source_width, source_y + source_height),
Common::Rect(dest_x, dest_y, dest_x + dest_width, dest_y + dest_height),
true, -1);
}
void draw_sprite(BITMAP *bmp, const BITMAP *sprite, int x, int y) {
bmp->draw(sprite, Common::Rect(0, 0, sprite->w, sprite->h),
x, y, false, false, true, -1);
}
void stretch_sprite(BITMAP *bmp, const BITMAP *sprite, int x, int y, int w, int h) {
bmp->stretchDraw(sprite, Common::Rect(0, 0, sprite->w, sprite->h),
Common::Rect(x, y, x + w, y + h),
true, -1);
}
void draw_trans_sprite(BITMAP *bmp, const BITMAP *sprite, int x, int y) {
bmp->draw(sprite, Common::Rect(0, 0, sprite->w, sprite->h),
x, y, false, false, true, _G(trans_blend_alpha));
}
void draw_lit_sprite(BITMAP *bmp, const BITMAP *sprite, int x, int y, int color) {
bmp->draw(sprite, Common::Rect(0, 0, sprite->w, sprite->h),
x, y, false, false, true, color,
_G(trans_blend_red), _G(trans_blend_green), _G(trans_blend_blue));
}
void draw_sprite_h_flip(BITMAP *bmp, const BITMAP *sprite, int x, int y) {
bmp->draw(sprite, Common::Rect(0, 0, sprite->w, sprite->h),
x, y, true, false, true, -1);
}
void draw_sprite_v_flip(BITMAP *bmp, const BITMAP *sprite, int x, int y) {
bmp->draw(sprite, Common::Rect(0, 0, sprite->w, sprite->h),
x, y, false, true, true, -1);
}
void draw_sprite_vh_flip(BITMAP *bmp, const BITMAP *sprite, int x, int y) {
bmp->draw(sprite, Common::Rect(0, 0, sprite->w, sprite->h),
x, y, true, true, true, -1);
}
void rotate_sprite(BITMAP *bmp, const BITMAP *sprite, int x, int y, fixed angle) {
pivot_scaled_sprite(bmp, sprite, (x<<16) + (sprite->w * 0x10000) / 2, (y<<16) + (sprite->h * 0x10000) / 2, sprite->w << 15, sprite->h << 15, angle, 0x10000);
}
void pivot_sprite(BITMAP *bmp, const BITMAP *sprite, int x, int y, int cx, int cy, fixed angle) {
pivot_scaled_sprite(bmp, sprite, x<<16, y<<16, cx<<16, cy<<16, angle, 0x10000);
}
bool is_screen_bitmap(BITMAP *bmp) {
return dynamic_cast<Graphics::Screen *>(bmp) != nullptr;
}
bool is_video_bitmap(BITMAP *bmp) {
return dynamic_cast<Graphics::Screen *>(bmp) != nullptr;
}
bool is_planar_bitmap(BITMAP *bmp) {
return false;
}
bool is_linear_bitmap(BITMAP *bmp) {
return true;
}
bool is_same_bitmap(BITMAP *bmp1, BITMAP *bmp2) {
if ((bmp1 == nullptr) || (bmp2 == nullptr))
return false;
if (bmp1 == bmp2)
return true;
// TODO: allegro also returns true if one bmp is a sub of the other,
// i.e. they share the same id
// This (if needed?) would require a different implementation
return false;
}
void bmp_select(BITMAP *bmp) {
// No implementation needed
}
byte *bmp_write_line(BITMAP *bmp, int line) {
return bmp->line[line];
}
void bmp_write8(byte *addr, int color) {
*addr = color;
}
void bmp_write15(byte *addr, int color) {
*((uint16 *)addr) = color;
}
void bmp_write16(byte *addr, int color) {
*((uint16 *)addr) = color;
}
void bmp_write24(byte *addr, int color) {
*addr = (color & 0xff);
*(addr + 1) = ((color >> 8) & 0xff);
*(addr + 2) = ((color >> 16) & 0xff);
}
void bmp_write32(byte *addr, int color) {
*((uint32 *)addr) = color;
}
void memory_putpixel(BITMAP *bmp, int x, int y, int color) {
putpixel(bmp, x, y, color);
}
void putpixel(BITMAP *bmp, int x, int y, int color) {
Graphics::ManagedSurface &surf = **bmp;
if (x < 0 || x >= surf.w || y < 0 || y >= surf.h)
return;
void *p = surf.getBasePtr(x, y);
switch (surf.format.bytesPerPixel) {
case 1:
*((uint8 *)p) = color;
break;
case 2:
*((uint16 *)p) = color;
break;
case 4:
*((uint32 *)p) = color;
break;
default:
break;
}
}
void _putpixel(BITMAP *bmp, int x, int y, int color) {
Graphics::ManagedSurface &surf = **bmp;
if (x < 0 || x >= surf.w || y < 0 || y >= surf.h)
return;
void *p = surf.getBasePtr(x, y);
*((uint8 *)p) = color;
}
void _putpixel15(BITMAP *bmp, int x, int y, int color) {
error("Unsupported bpp");
}
void _putpixel16(BITMAP *bmp, int x, int y, int color) {
Graphics::ManagedSurface &surf = **bmp;
if (x < 0 || x >= surf.w || y < 0 || y >= surf.h)
return;
void *p = surf.getBasePtr(x, y);
*((uint16 *)p) = color;
}
void _putpixel24(BITMAP *bmp, int x, int y, int color) {
error("Unsupported bpp");
}
void _putpixel32(BITMAP *bmp, int x, int y, int color) {
Graphics::ManagedSurface &surf = **bmp;
if (x < 0 || x >= surf.w || y < 0 || y >= surf.h)
return;
void *p = surf.getBasePtr(x, y);
*((uint32 *)p) = color;
}
int getpixel(const BITMAP *bmp, int x, int y) {
Graphics::ManagedSurface &surf = **bmp;
// Allegro returns -1 if the pixel lies outside the bitmap
if (x < 0 || y < 0 || x >= surf.w || y >= surf.h)
return -1;
void *p = surf.getBasePtr(x, y);
switch (surf.format.bytesPerPixel) {
case 1:
return *((uint8 *)p);
case 2:
return *((uint16 *)p);
case 4:
return *((uint32 *)p);
default:
break;
}
error("Unsupported bpp");
}
int _getpixel(const BITMAP *bmp, int x, int y) {
Graphics::ManagedSurface &surf = **bmp;
if (x < 0 || y < 0 || x >= surf.w || y >= surf.h)
return -1;
void *p = surf.getBasePtr(x, y);
return *((uint8 *)p);
}
int _getpixel15(const BITMAP *bmp, int x, int y) {
error("Unsupported bpp");
}
int _getpixel16(const BITMAP *bmp, int x, int y) {
Graphics::ManagedSurface &surf = **bmp;
if (x < 0 || y < 0 || x >= surf.w || y >= surf.h)
return -1;
void *p = surf.getBasePtr(x, y);
return *((uint16 *)p);
}
int _getpixel24(const BITMAP *bmp, int x, int y) {
error("Unsupported bpp");
}
int _getpixel32(const BITMAP *bmp, int x, int y) {
Graphics::ManagedSurface &surf = **bmp;
if (x < 0 || y < 0 || x >= surf.w || y >= surf.h)
return -1;
void *p = surf.getBasePtr(x, y);
return *((uint32 *)p);
}
void line(BITMAP *bmp, int x1, int y1, int x2, int y2, int color) {
Graphics::ManagedSurface &surf = **bmp;
surf.drawLine(x1, y1, x2, y2, color);
}
void rect(BITMAP *bmp, int x1, int y1, int x2, int y2, int color) {
Graphics::ManagedSurface &surf = **bmp;
if (x1 > x2)
SWAP(x1, x2);
if (y1 > y2)
SWAP(y1, y2);
surf.frameRect(Common::Rect(x1, y1, x2 + 1, y2 + 1), color);
}
void rectfill(BITMAP *bmp, int x1, int y1, int x2, int y2, int color) {
Graphics::ManagedSurface &surf = **bmp;
if (x1 > x2)
SWAP(x1, x2);
if (y1 > y2)
SWAP(y1, y2);
surf.fillRect(Common::Rect(x1, y1, x2 + 1, y2 + 1), color);
}
void triangle(BITMAP *bmp, int x1, int y1, int x2, int y2, int x3, int y3, int color) {
Graphics::ManagedSurface &surf = **bmp;
surf.drawLine(x1, y1, x2, y2, color);
surf.drawLine(x2, y2, x3, y3, color);
surf.drawLine(x3, y3, x1, y1, color);
}
void circlefill(BITMAP *bmp, int x, int y, int radius, int color) {
bmp->circlefill(x, y, radius, color);
}
void clear_bitmap(BITMAP *bmp) {
bmp->clear();
}
} // namespace AGS3
|