00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "OSDLPixel.h"
00028
00029 #include "OSDLUtils.h"
00030 #include "OSDLSurface.h"
00031 #include "OSDLOpenGL.h"
00032
00033 #include "OSDLFromGfx.h"
00034
00035 #include "Ceylan.h"
00036
00037 #include <list>
00038
00039
00040
00041 #ifdef OSDL_USES_CONFIG_H
00042 #include "OSDLConfig.h"
00043 #endif // OSDL_USES_CONFIG_H
00044
00045
00046 #if OSDL_ARCH_NINTENDO_DS
00047 #include "OSDLConfigForNintendoDS.h"
00048 #endif // OSDL_ARCH_NINTENDO_DS
00049
00050
00051
00052 #if OSDL_USES_SDL_GFX
00053
00054 #include "SDL_gfxPrimitives.h"
00055
00056 #endif // OSDL_USES_SDL_GFX
00057
00058
00059
00060
00061 using namespace OSDL::Video ;
00062 using namespace OSDL::Video::Pixels ;
00063
00064 using namespace Ceylan::Log ;
00065
00066 using std::string ;
00067
00068
00069
00070
00071
00072
00073
00075
00076 extern const ColorDefinition OSDL::Video::Pixels::Transparent =
00077 { 0, 0, 0, 0 } ;
00078
00079
00080
00081
00082
00084
00085 extern const ColorDefinition OSDL::Video::Pixels::Black =
00086 { 0, 0, 0, 255 } ;
00087
00088 extern const ColorDefinition OSDL::Video::Pixels::Grey =
00089 { 190, 190, 190, 255 } ;
00090
00091 extern const ColorDefinition OSDL::Video::Pixels::DimGrey =
00092 { 105, 105, 105, 255 } ;
00093
00094 extern const ColorDefinition OSDL::Video::Pixels::LightGrey =
00095 { 211, 211, 211, 255 } ;
00096
00097 extern const ColorDefinition OSDL::Video::Pixels::SlateGrey =
00098 { 112, 128, 144, 255 } ;
00099
00100 extern const ColorDefinition OSDL::Video::Pixels::Silver =
00101 { 230, 232, 250, 255 } ;
00102
00103
00104
00105
00107
00108 extern const ColorDefinition OSDL::Video::Pixels::AliceBlue =
00109 { 240, 248, 255, 255 } ;
00110
00111 extern const ColorDefinition OSDL::Video::Pixels::BlueViolet =
00112 { 138, 43, 226, 255 } ;
00113
00114 extern const ColorDefinition OSDL::Video::Pixels::CadetBlue =
00115 { 95, 158, 160, 255 } ;
00116
00117 extern const ColorDefinition OSDL::Video::Pixels::DarkSlateBlue =
00118 { 72, 61, 139, 255 } ;
00119
00120 extern const ColorDefinition OSDL::Video::Pixels::DarkTurquoise =
00121 { 0, 206, 209, 255 } ;
00122
00123 extern const ColorDefinition OSDL::Video::Pixels::DeepSkyBlue =
00124 { 0, 191, 255, 255 } ;
00125
00126 extern const ColorDefinition OSDL::Video::Pixels::DodgerBlue =
00127 { 30, 144, 255, 255 } ;
00128
00129 extern const ColorDefinition OSDL::Video::Pixels::LightBlue =
00130 { 173, 216, 230, 255 } ;
00131
00132 extern const ColorDefinition OSDL::Video::Pixels::LightCyan =
00133 { 224, 255, 255, 255 } ;
00134
00135 extern const ColorDefinition OSDL::Video::Pixels::MediumBlue =
00136 { 123, 104, 238, 255 } ;
00137
00138 extern const ColorDefinition OSDL::Video::Pixels::NavyBlue =
00139 { 0, 0, 128, 255 } ;
00140
00141 extern const ColorDefinition OSDL::Video::Pixels::RoyalBlue =
00142 { 65, 105, 225, 255 } ;
00143
00144 extern const ColorDefinition OSDL::Video::Pixels::SkyBlue =
00145 { 135, 206, 235, 255 } ;
00146
00147 extern const ColorDefinition OSDL::Video::Pixels::SlateBlue =
00148 { 106, 90, 205, 255 } ;
00149
00150 extern const ColorDefinition OSDL::Video::Pixels::SteelBlue =
00151 { 70, 130, 180, 255 } ;
00152
00153 extern const ColorDefinition OSDL::Video::Pixels::Aquamarine =
00154 { 127, 255, 212, 255 } ;
00155
00156 extern const ColorDefinition OSDL::Video::Pixels::Azure =
00157 { 240, 255, 255, 255 } ;
00158
00159 extern const ColorDefinition OSDL::Video::Pixels::Blue =
00160 { 0, 0, 255, 255 } ;
00161
00162 extern const ColorDefinition OSDL::Video::Pixels::Cyan =
00163 { 0, 255, 255, 255 } ;
00164
00165 extern const ColorDefinition OSDL::Video::Pixels::Turquoise =
00166 { 64, 224, 208, 255 } ;
00167
00168 extern const ColorDefinition OSDL::Video::Pixels::MidnightBlue =
00169 { 25, 25, 112, 255 } ;
00170
00171
00172
00173
00175
00176 extern const ColorDefinition OSDL::Video::Pixels::Brown =
00177 { 165, 42, 42, 255 } ;
00178
00179 extern const ColorDefinition OSDL::Video::Pixels::RosyBrown =
00180 { 188, 143, 143, 255 } ;
00181
00182 extern const ColorDefinition OSDL::Video::Pixels::SaddleBrown =
00183 { 139, 69, 19, 255 } ;
00184
00185 extern const ColorDefinition OSDL::Video::Pixels::Beige =
00186 { 245, 42, 42, 255 } ;
00187
00188 extern const ColorDefinition OSDL::Video::Pixels::Burlywood =
00189 { 222, 184, 135, 255 } ;
00190
00191 extern const ColorDefinition OSDL::Video::Pixels::Chocolate =
00192 { 210, 105, 30, 255 } ;
00193
00194 extern const ColorDefinition OSDL::Video::Pixels::Peru =
00195 { 205, 133, 63, 255 } ;
00196
00197 extern const ColorDefinition OSDL::Video::Pixels::Tan =
00198 { 210, 180, 140, 255 } ;
00199
00200 extern const ColorDefinition OSDL::Video::Pixels::Copper =
00201 { 184, 115, 51, 255 } ;
00202
00203
00204
00205
00207
00208 extern const ColorDefinition OSDL::Video::Pixels::DarkGreen =
00209 { 0, 100, 0, 255 } ;
00210
00211 extern const ColorDefinition OSDL::Video::Pixels::DarkOliveGreen =
00212 { 85, 107, 47, 255 } ;
00213
00214 extern const ColorDefinition OSDL::Video::Pixels::ForestGreen =
00215 { 34, 139, 34, 255 } ;
00216
00217 extern const ColorDefinition OSDL::Video::Pixels::GreenYellow =
00218 { 173, 255, 47, 255 } ;
00219
00220 extern const ColorDefinition OSDL::Video::Pixels::LawnGreen =
00221 { 124, 252, 0, 255 } ;
00222
00223 extern const ColorDefinition OSDL::Video::Pixels::LimeGreen =
00224 { 50, 205, 50, 255 } ;
00225
00226 extern const ColorDefinition OSDL::Video::Pixels::MintCream =
00227 { 245, 255, 250, 255 } ;
00228
00229 extern const ColorDefinition OSDL::Video::Pixels::OliveDrab =
00230 { 107, 142, 35, 255 } ;
00231
00232 extern const ColorDefinition OSDL::Video::Pixels::PaleGreen =
00233 { 152, 251, 152, 255 } ;
00234
00235 extern const ColorDefinition OSDL::Video::Pixels::SeaGreen =
00236 { 46, 139, 87, 255 } ;
00237
00238 extern const ColorDefinition OSDL::Video::Pixels::SpringGreen =
00239 { 0, 255, 127, 255 } ;
00240
00241 extern const ColorDefinition OSDL::Video::Pixels::YellowGreen =
00242 { 154, 205, 50, 255 } ;
00243
00244 extern const ColorDefinition OSDL::Video::Pixels::Chartreuse =
00245 { 127, 255, 0, 255 } ;
00246
00247 extern const ColorDefinition OSDL::Video::Pixels::Green =
00248 { 0, 255, 0, 255 } ;
00249
00250 extern const ColorDefinition OSDL::Video::Pixels::Khaki =
00251 { 240, 230, 140, 255 } ;
00252
00253
00254
00255
00257
00258 extern const ColorDefinition OSDL::Video::Pixels::DarkOrange =
00259 { 255, 140, 0, 255 } ;
00260
00261 extern const ColorDefinition OSDL::Video::Pixels::DarkSalmon =
00262 { 233, 150, 122, 255 } ;
00263
00264 extern const ColorDefinition OSDL::Video::Pixels::LightCoral =
00265 { 240, 128, 128, 255 } ;
00266
00267 extern const ColorDefinition OSDL::Video::Pixels::LightSalmon =
00268 { 255, 160, 122, 255 } ;
00269
00270 extern const ColorDefinition OSDL::Video::Pixels::PeachPuff =
00271 { 255, 218, 185, 255 } ;
00272
00273 extern const ColorDefinition OSDL::Video::Pixels::Bisque =
00274 { 255, 228, 196, 255 } ;
00275
00276 extern const ColorDefinition OSDL::Video::Pixels::Coral =
00277 { 255, 127, 80, 255 } ;
00278
00279 extern const ColorDefinition OSDL::Video::Pixels::Honeydew =
00280 { 240, 255, 240, 255 } ;
00281
00282 extern const ColorDefinition OSDL::Video::Pixels::Orange =
00283 { 255, 165, 0, 255 } ;
00284
00285 extern const ColorDefinition OSDL::Video::Pixels::Salmon =
00286 { 250, 128, 114, 255 } ;
00287
00288 extern const ColorDefinition OSDL::Video::Pixels::Sienna =
00289 { 160, 82, 45, 255 } ;
00290
00291
00292
00293
00295
00296 extern const ColorDefinition OSDL::Video::Pixels::DeepPink =
00297 { 255, 20, 147, 255 } ;
00298
00299 extern const ColorDefinition OSDL::Video::Pixels::HotPink =
00300 { 255, 105, 180, 255 } ;
00301
00302 extern const ColorDefinition OSDL::Video::Pixels::IndianRed =
00303 { 205, 92, 92, 255 } ;
00304
00305 extern const ColorDefinition OSDL::Video::Pixels::LightPink =
00306 { 255, 182, 193, 255 } ;
00307
00308 extern const ColorDefinition OSDL::Video::Pixels::MediumVioletRed =
00309 { 199, 21, 133, 255 } ;
00310
00311 extern const ColorDefinition OSDL::Video::Pixels::MistyRose =
00312 { 255, 228, 225, 255 } ;
00313
00314 extern const ColorDefinition OSDL::Video::Pixels::OrangeRed =
00315 { 255, 69, 0, 255 } ;
00316
00317 extern const ColorDefinition OSDL::Video::Pixels::VioletRed =
00318 { 208, 32, 144, 255 } ;
00319
00320 extern const ColorDefinition OSDL::Video::Pixels::Firebrick =
00321 { 178, 34, 34 , 255 } ;
00322
00323 extern const ColorDefinition OSDL::Video::Pixels::Pink =
00324 { 255, 192, 203, 255 } ;
00325
00326 extern const ColorDefinition OSDL::Video::Pixels::Red =
00327 { 255, 0, 0, 255 } ;
00328
00329 extern const ColorDefinition OSDL::Video::Pixels::Tomato =
00330 { 255, 99, 71, 255 } ;
00331
00332
00333
00334
00336
00337 extern const ColorDefinition OSDL::Video::Pixels::DarkOrchid =
00338 { 153, 50, 204, 255 } ;
00339
00340 extern const ColorDefinition OSDL::Video::Pixels::DarkViolet =
00341 { 148, 0, 211, 255 } ;
00342
00343 extern const ColorDefinition OSDL::Video::Pixels::LavenderBlush =
00344 { 255, 240, 245, 255 } ;
00345
00346 extern const ColorDefinition OSDL::Video::Pixels::MediumOrchid =
00347 { 186, 85, 211, 255 } ;
00348
00349 extern const ColorDefinition OSDL::Video::Pixels::MediumPurple =
00350 { 147, 112, 219, 255 } ;
00351
00352 extern const ColorDefinition OSDL::Video::Pixels::Lavender =
00353 { 230, 230, 250, 255 } ;
00354
00355 extern const ColorDefinition OSDL::Video::Pixels::Magenta =
00356 { 255, 0, 255, 255 } ;
00357
00358 extern const ColorDefinition OSDL::Video::Pixels::Maroon =
00359 { 176, 48, 96, 255 } ;
00360
00361 extern const ColorDefinition OSDL::Video::Pixels::Orchid =
00362 { 218, 112, 214, 255 } ;
00363
00364 extern const ColorDefinition OSDL::Video::Pixels::Plum =
00365 { 221, 160, 221, 255 } ;
00366
00367 extern const ColorDefinition OSDL::Video::Pixels::Purple =
00368 { 160, 32, 240, 255 } ;
00369
00370 extern const ColorDefinition OSDL::Video::Pixels::Thistle =
00371 { 216, 191, 216, 255 } ;
00372
00373 extern const ColorDefinition OSDL::Video::Pixels::Violet =
00374 { 238, 130, 238, 255 } ;
00375
00376
00377
00378
00380
00381 extern const ColorDefinition OSDL::Video::Pixels::AntiqueWhite =
00382 { 250, 235, 215, 255 } ;
00383
00384 extern const ColorDefinition OSDL::Video::Pixels::FloralWhite =
00385 { 255, 250, 240, 255 } ;
00386
00387 extern const ColorDefinition OSDL::Video::Pixels::GhostWhite =
00388 { 248, 248, 255, 255 } ;
00389
00390 extern const ColorDefinition OSDL::Video::Pixels::NavajoWhite =
00391 { 255, 222, 173, 255 } ;
00392
00393 extern const ColorDefinition OSDL::Video::Pixels::OldLace =
00394 { 253, 245, 230, 255 } ;
00395
00396 extern const ColorDefinition OSDL::Video::Pixels::WhiteSmoke =
00397 { 245, 245, 245, 255 } ;
00398
00399 extern const ColorDefinition OSDL::Video::Pixels::Gainsboro =
00400 { 220, 220, 220, 255 } ;
00401
00402 extern const ColorDefinition OSDL::Video::Pixels::Ivory =
00403 { 255, 255, 240, 255 } ;
00404
00405 extern const ColorDefinition OSDL::Video::Pixels::Linen =
00406 { 250, 240, 230, 255 } ;
00407
00408 extern const ColorDefinition OSDL::Video::Pixels::Seashell =
00409 { 255, 245, 238, 255 } ;
00410
00411 extern const ColorDefinition OSDL::Video::Pixels::Snow =
00412 { 255, 250, 250, 255 } ;
00413
00414 extern const ColorDefinition OSDL::Video::Pixels::Wheat =
00415 { 245, 222, 179, 255 } ;
00416
00417 extern const ColorDefinition OSDL::Video::Pixels::White =
00418 { 255, 255, 255, 255 } ;
00419
00420
00421
00422
00424
00425 extern const ColorDefinition OSDL::Video::Pixels::BlanchedAlmond =
00426 { 255, 235, 205, 255 } ;
00427
00428 extern const ColorDefinition OSDL::Video::Pixels::DarkGoldenrod =
00429 { 184, 134, 11, 255 } ;
00430
00431 extern const ColorDefinition OSDL::Video::Pixels::LemonChiffon =
00432 { 255, 250, 205, 255 } ;
00433
00434 extern const ColorDefinition OSDL::Video::Pixels::LightGoldenrod =
00435 { 238, 221, 130, 255 } ;
00436
00437 extern const ColorDefinition OSDL::Video::Pixels::LightYellow =
00438 { 255, 255, 224, 255 } ;
00439
00440 extern const ColorDefinition OSDL::Video::Pixels::PaleGoldenrod =
00441 { 238, 232, 170, 255 } ;
00442
00443 extern const ColorDefinition OSDL::Video::Pixels::PapayaWhip =
00444 { 255, 239, 213, 255 } ;
00445
00446 extern const ColorDefinition OSDL::Video::Pixels::Cornsilk =
00447 { 255, 248, 220, 255 } ;
00448
00449 extern const ColorDefinition OSDL::Video::Pixels::Gold =
00450 { 255, 215, 0, 255 } ;
00451
00452 extern const ColorDefinition OSDL::Video::Pixels::Goldenrod =
00453 { 218, 165, 32, 255 } ;
00454
00455 extern const ColorDefinition OSDL::Video::Pixels::Moccasin =
00456 { 255, 228, 181, 255 } ;
00457
00458 extern const ColorDefinition OSDL::Video::Pixels::Yellow =
00459 { 255, 255, 0, 255 } ;
00460
00461
00462 extern const ColorDefinition OSDL::Video::Pixels::DefaultColorkey = Magenta ;
00463
00464
00465
00466
00467
00468 bool Pixels::setGamma( GammaFactor red, GammaFactor green, GammaFactor blue )
00469 {
00470
00471 #if OSDL_USES_SDL
00472
00473 if ( SDL_SetGamma( red, green, blue ) == -1 )
00474 {
00475 LogPlug::error( "Pixels::setGamma: "
00476 + Utils::getBackendLastError() ) ;
00477 return false ;
00478 }
00479
00480 return true ;
00481
00482 #else // OSDL_USES_SDL
00483
00484 return false ;
00485
00486 #endif // OSDL_USES_SDL
00487
00488 }
00489
00490
00491
00492 bool Pixels::setGammaRamp( GammaRampElement * redRamp,
00493 GammaRampElement * greenRamp, GammaRampElement * blueRamp )
00494 {
00495
00496 #if OSDL_USES_SDL
00497
00498 if ( SDL_SetGammaRamp( redRamp, greenRamp, blueRamp ) == -1 )
00499 {
00500 LogPlug::error( "Pixels::setGammaRamp: "
00501 + Utils::getBackendLastError() ) ;
00502 return false ;
00503 }
00504
00505 return true ;
00506
00507 #else // OSDL_USES_SDL
00508
00509 return false ;
00510
00511 #endif // OSDL_USES_SDL
00512
00513 }
00514
00515
00516
00517 bool Pixels::getGammaRamp( GammaRampElement * redRamp,
00518 GammaRampElement * greenRamp, GammaRampElement * blueRamp )
00519 {
00520
00521 #if OSDL_USES_SDL
00522
00523 if ( SDL_GetGammaRamp( redRamp, greenRamp, blueRamp ) == -1 )
00524 {
00525 LogPlug::error( "Pixels::getGammaRamp: "
00526 + Utils::getBackendLastError() ) ;
00527 return false ;
00528 }
00529
00530 return true ;
00531
00532 #else // OSDL_USES_SDL
00533
00534 return false ;
00535
00536 #endif // OSDL_USES_SDL
00537
00538 }
00539
00540
00541
00542
00543
00544
00545
00546
00547 void Pixels::getRecommendedColorMasks( ColorMask & redMask,
00548 ColorMask & greenMask, ColorMask & blueMask, ColorMask & alphaMask )
00549 {
00550
00551 #if OSDL_DEBUG_PIXEL
00552
00553
00554
00555 #if CEYLAN_DETECTED_LITTLE_ENDIAN
00556
00557 LogPlug::debug( "Pixels::getRecommendedColorMasks (with alpha): "
00558 "using little endian convention." ) ;
00559
00560 #else // CEYLAN_DETECTED_LITTLE_ENDIAN
00561
00562 LogPlug::debug( "Pixels::getRecommendedColorMasks (with alpha): "
00563 "using big endian convention." ) ;
00564
00565 #endif // CEYLAN_DETECTED_LITTLE_ENDIAN
00566
00567 #endif // OSDL_DEBUG_PIXEL
00568
00569
00570
00571
00572
00573
00574
00575 redMask = OpenGL::RedMask ;
00576 greenMask = OpenGL::GreenMask ;
00577 blueMask = OpenGL::BlueMask ;
00578 alphaMask = OpenGL::AlphaMask ;
00579
00580 }
00581
00582
00583
00584 void Pixels::getRecommendedColorMasks( ColorMask & redMask,
00585 ColorMask & greenMask, ColorMask & blueMask )
00586 {
00587
00588
00589 #if OSDL_DEBUG_PIXEL
00590
00591
00592
00593 #if CEYLAN_DETECTED_LITTLE_ENDIAN
00594
00595 LogPlug::debug( "Pixels::getRecommendedColorMasks (with alpha): "
00596 "using little endian convention." ) ;
00597
00598 #else // CEYLAN_DETECTED_LITTLE_ENDIAN
00599
00600 LogPlug::debug( "Pixels::getRecommendedColorMasks (with alpha): "
00601 "using big endian convention." ) ;
00602
00603 #endif // CEYLAN_DETECTED_LITTLE_ENDIAN
00604
00605 #endif // OSDL_DEBUG_PIXEL
00606
00607
00608 redMask = OpenGL::RedMask ;
00609 greenMask = OpenGL::GreenMask ;
00610 blueMask = OpenGL::BlueMask ;
00611
00612 }
00613
00614
00615
00616 void Pixels::getCurrentColorMasks( const Pixels::PixelFormat & format,
00617 Pixels::ColorMask & redMask, Pixels::ColorMask & greenMask,
00618 Pixels::ColorMask & blueMask, Pixels::ColorMask & alphaMask )
00619 {
00620
00621 redMask = format.Rmask ;
00622 greenMask = format.Gmask ;
00623 blueMask = format.Bmask ;
00624 alphaMask = format.Amask ;
00625
00626 }
00627
00628
00629
00630
00631
00632
00633
00634 ColorDefinition Pixels::convertRGBAToColorDefinition(
00635 ColorElement red, ColorElement green,
00636 ColorElement blue, ColorElement alpha )
00637 {
00638
00639 ColorDefinition result ;
00640
00641 result.r = red ;
00642 result.g = green ;
00643 result.b = blue ;
00644 result.unused = alpha ;
00645
00646 return result ;
00647
00648 }
00649
00650
00651
00652 void Pixels::convertColorDefinitionToRGBA( ColorDefinition color,
00653 ColorElement & red, ColorElement & green, ColorElement & blue,
00654 ColorElement & alpha )
00655 {
00656
00657 red = color.r ;
00658 green = color.g ;
00659 blue = color.b ;
00660 alpha = color.unused ;
00661
00662 }
00663
00664
00665
00666 PixelColor Pixels::convertRGBAToPixelColor( const Pixels::PixelFormat & format,
00667 ColorElement red, ColorElement green, ColorElement blue,
00668 ColorElement alpha )
00669 {
00670
00671 #if OSDL_USES_SDL
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683 return SDL_MapRGBA( const_cast<Pixels::PixelFormat *>( & format ),
00684 red, green, blue, alpha ) ;
00685
00686 #else // OSDL_USES_SDL
00687
00688 throw VideoException( "Pixels::convertRGBAToPixelColor failed: "
00689 "no SDL support available" ) ;
00690
00691 #endif // OSDL_USES_SDL
00692
00693 }
00694
00695
00696
00697 ColorDefinition Pixels::convertPixelColorToColorDefinition(
00698 const PixelFormat & format, PixelColor pixel )
00699 {
00700
00701 #if OSDL_USES_SDL
00702
00703 ColorDefinition pixDef ;
00704
00705 SDL_GetRGBA( pixel, const_cast<Pixels::PixelFormat *>( & format ),
00706 & pixDef.r, & pixDef.g, & pixDef.b, & pixDef.unused ) ;
00707
00708 return pixDef ;
00709
00710 #else // OSDL_USES_SDL
00711
00712 throw VideoException( "Pixels::convertPixelColorToColorDefinition failed: "
00713 "no SDL support available" ) ;
00714
00715 #endif // OSDL_USES_SDL
00716
00717 }
00718
00719
00720
00721 PixelColor Pixels::convertColorDefinitionToPixelColor(
00722 const PixelFormat & format, ColorDefinition colorDef )
00723 {
00724
00725 #if OSDL_USES_SDL
00726
00727 return SDL_MapRGBA( const_cast<Pixels::PixelFormat *>( & format ),
00728 colorDef.r, colorDef.g, colorDef.b, colorDef.unused ) ;
00729
00730 #else // OSDL_USES_SDL
00731
00732 throw VideoException( "Pixels::convertColorDefinitionToPixelColor failed: "
00733 "no SDL support available" ) ;
00734
00735 #endif // OSDL_USES_SDL
00736
00737 }
00738
00739
00740
00741 PixelColor Pixels::convertColorDefinitionToRawPixelColor(
00742 ColorDefinition colorDef )
00743 {
00744
00745
00746
00747
00748
00749
00750 return ((Ceylan::Uint32) colorDef.r << 24)
00751 | ((Ceylan::Uint32) colorDef.g << 16)
00752 | ((Ceylan::Uint32) colorDef.b << 8 )
00753 | ((Ceylan::Uint32) colorDef.unused ) ;
00754
00755 }
00756
00757
00758
00759 PixelColor Pixels::convertRGBAToRawPixelColor(
00760 ColorElement red, ColorElement green, ColorElement blue,
00761 ColorElement alpha )
00762 {
00763 return ((Ceylan::Uint32) red << 24) | ((Ceylan::Uint32) green << 16)
00764 | ((Ceylan::Uint32) blue << 8) | ((Ceylan::Uint32) alpha ) ;
00765
00766 }
00767
00768
00769
00770
00771
00772
00773
00774 bool Pixels::areEqual( ColorDefinition first, ColorDefinition second,
00775 bool useAlpha )
00776 {
00777
00778
00779 #if OSDL_DEBUG_COLOR
00780 LogPlug::trace( "Pixels::areEqual: comparing "
00781 + Pixels::toString( first ) + " with "
00782 + Pixels::toString( second )
00783 + ( useAlpha ? " (alpha taken into account)": " (alpha ignored)" ) ) ;
00784 #endif // OSDL_DEBUG_COLOR
00785
00786 if ( first.r != second.r )
00787 return false ;
00788
00789 if ( first.g != second.g )
00790 return false ;
00791
00792 if ( first.b != second.b )
00793 return false ;
00794
00795 if ( useAlpha )
00796 return ( first.unused == second.unused ) ;
00797 else
00798 return true ;
00799
00800 }
00801
00802
00803
00804 bool Pixels::isLess( ColorDefinition value, ColorDefinition comparison )
00805 {
00806
00807 if ( value.r < comparison.r )
00808 return true ;
00809
00810 if ( value.r > comparison.r )
00811 return false ;
00812
00813
00814 if ( value.g < comparison.g )
00815 return true ;
00816
00817 if ( value.g > comparison.g )
00818 return false ;
00819
00820
00821 if ( value.b < comparison.b )
00822 return true ;
00823
00824 if ( value.b > comparison.b )
00825 return false ;
00826
00827
00828 if ( value.unused < comparison.unused )
00829 return true ;
00830
00831 if ( value.unused > comparison.unused )
00832 return false ;
00833
00834 return false ;
00835
00836 }
00837
00838
00839
00840 bool Pixels::areEqual( PixelColor first, PixelColor second )
00841 {
00842
00843 return first == second ;
00844
00845 }
00846
00847
00848
00849 ColorDefinition Pixels::selectColorDifferentFrom( ColorDefinition first,
00850 ColorDefinition second )
00851 {
00852
00853
00854 ColorDefinition res = Pixels::Red ;
00855
00856 if ( ( ! areEqual( res, first, false ) )
00857 && ( ! areEqual( res, second, false ) ) )
00858 return res ;
00859
00860 res = Pixels::Green ;
00861
00862 if ( ( ! areEqual( res, first, false ) )
00863 && ( ! areEqual( res, second, false ) ) )
00864 return res ;
00865
00866 return Pixels::Blue ;
00867
00868 }
00869
00870
00871
00872 ColorDefinition Pixels::selectColorDifferentFrom( ColorDefinition first,
00873 ColorDefinition second, ColorDefinition third )
00874 {
00875
00876
00877 ColorDefinition res = Pixels::Red ;
00878
00879 if ( ( ! areEqual( res, first, false ) )
00880 && ( ! areEqual( res, second, false )
00881 && ( ! areEqual( res, third, false ) ) ) )
00882 return res ;
00883
00884 res = Pixels::Green ;
00885
00886 if ( ( ! areEqual( res, first, false ) )
00887 && ( ! areEqual( res, second, false )
00888 && ( ! areEqual( res, third, false ) ) ) )
00889 return res ;
00890
00891 res = Pixels::Blue ;
00892
00893 if ( ( ! areEqual( res, first, false ) )
00894 && ( ! areEqual( res, second, false )
00895 && ( ! areEqual( res, third, false ) ) ) )
00896 return res ;
00897
00898 return Pixels::Black ;
00899
00900 }
00901
00902
00903
00904
00905
00906
00907
00908
00909 Pixels::PixelColor Pixels::getPixelColor( const Surface & fromSurface,
00910 Coordinate x, Coordinate y )
00911 {
00912
00913 #if OSDL_USES_SDL
00914
00915 BytesPerPixel bpp = fromSurface.getBytesPerPixel() ;
00916
00917
00918
00919
00920
00921
00922 Uint8 * p = reinterpret_cast<Uint8 *>( fromSurface.getPixels() )
00923 + y * fromSurface.getPitch() + x * bpp ;
00924
00925 switch( bpp )
00926 {
00927
00928 case 1:
00929 return * p ;
00930
00931 case 2:
00932 return *( Uint16 * ) p ;
00933
00934 case 3:
00935 #if CEYLAN_DETECTED_LITTLE_ENDIAN
00936 return p[0] | ( p[1] << 8 ) | p[2] << 16 ;
00937 #else // CEYLAN_DETECTED_LITTLE_ENDIAN
00938 return ( p[0] << 16 ) | ( p[1] << 8 ) | p[2] ;
00939 #endif // CEYLAN_DETECTED_LITTLE_ENDIAN
00940
00941 case 4:
00942 return *( Uint32 * ) p ;
00943
00944 default:
00945 throw VideoException( "Pixels::getPixelColor: "
00946 "abnormal bit per pixel detected" ) ;
00947 }
00948
00949 #else // OSDL_USES_SDL
00950
00951 throw VideoException( "Pixels::getPixelColor failed: "
00952 "no SDL support available" ) ;
00953
00954 #endif // OSDL_USES_SDL
00955
00956 }
00957
00958
00959
00960 Pixels::ColorDefinition Pixels::getColorDefinition(
00961 const Surface & fromSurface, Coordinate x, Coordinate y )
00962 {
00963
00964 return convertPixelColorToColorDefinition( fromSurface.getPixelFormat(),
00965 getPixelColor( fromSurface, x, y ) ) ;
00966
00967 }
00968
00969
00970
00971
00972 void Pixels::putRGBAPixel( Surface & targetSurface,
00973 Coordinate x, Coordinate y,
00974 ColorElement red, ColorElement green, ColorElement blue,
00975 ColorElement alpha, bool blending, bool clipping, bool locking )
00976 {
00977
00978 putPixelColor( targetSurface, x, y,
00979 convertRGBAToPixelColor( targetSurface.getPixelFormat(),
00980 red, green, blue, alpha ), alpha, blending, clipping, locking ) ;
00981
00982 }
00983
00984
00985
00986 void Pixels::putColorDefinition( Surface & targetSurface,
00987 Coordinate x, Coordinate y, ColorDefinition colorDef,
00988 bool blending, bool clipping, bool locking )
00989 {
00990
00991 putPixelColor( targetSurface, x, y,
00992 convertRGBAToPixelColor( targetSurface.getPixelFormat(),
00993 colorDef.r, colorDef.g, colorDef.b, colorDef.unused ),
00994 colorDef.unused, blending, clipping, locking ) ;
00995
00996 }
00997
00998
00999
01000 void Pixels::putPixelColor( Surface & targetSurface,
01001 Coordinate x, Coordinate y, PixelColor convertedColor,
01002 ColorElement alpha, bool blending, bool clipping, bool locking )
01003 {
01004
01005 #if OSDL_USES_SDL_GFX
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018 if ( locking )
01019 {
01020
01021 if ( clipping )
01022 {
01023
01024 if ( blending )
01025 {
01026
01027
01028
01029 if ( targetSurface.mustBeLocked() )
01030 {
01031 targetSurface.lock() ;
01032
01033 ::putPixelAlpha( & targetSurface.getSDLSurface(), x, y,
01034 convertedColor, alpha ) ;
01035
01036 targetSurface.unlock() ;
01037 }
01038 else
01039 {
01040 ::putPixelAlpha( & targetSurface.getSDLSurface(), x, y,
01041 convertedColor, alpha ) ;
01042 }
01043
01044 }
01045 else
01046 {
01047
01048
01049
01050 if ( targetSurface.mustBeLocked() )
01051 {
01052 targetSurface.lock() ;
01053
01054 ::fastPixelColorNolock( & targetSurface.getSDLSurface(),
01055 x, y, convertedColor ) ;
01056
01057 targetSurface.unlock() ;
01058 }
01059 else
01060 {
01061 ::fastPixelColorNolock( & targetSurface.getSDLSurface(),
01062 x, y, convertedColor ) ;
01063 }
01064
01065 }
01066
01067 }
01068 else
01069 {
01070
01071 if ( blending )
01072 {
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082 if ( targetSurface.mustBeLocked() )
01083 {
01084 targetSurface.lock() ;
01085 ::putPixelAlpha( & targetSurface.getSDLSurface(), x, y,
01086 convertedColor, alpha ) ;
01087 targetSurface.unlock() ;
01088 }
01089 else
01090 {
01091 ::putPixelAlpha( & targetSurface.getSDLSurface(), x, y,
01092 convertedColor, alpha ) ;
01093 }
01094
01095
01096 }
01097 else
01098 {
01099
01100
01101
01102
01103
01104 if ( targetSurface.mustBeLocked() )
01105 {
01106 targetSurface.lock() ;
01107 ::fastPixelColorNolockNoclip(
01108 & targetSurface.getSDLSurface(),
01109 x, y, convertedColor ) ;
01110 targetSurface.unlock() ;
01111 }
01112 else
01113 {
01114 ::fastPixelColorNolockNoclip(
01115 & targetSurface.getSDLSurface(),
01116 x, y, convertedColor ) ;
01117 }
01118
01119
01120 }
01121
01122
01123 }
01124
01125
01126 }
01127 else
01128 {
01129
01130 if ( clipping )
01131 {
01132
01133
01134 if ( blending )
01135 {
01136
01137
01138
01139
01140
01141
01142 ::putPixelAlpha( & targetSurface.getSDLSurface(), x, y,
01143 convertedColor, alpha ) ;
01144
01145 }
01146 else
01147 {
01148
01149
01150
01151 ::fastPixelColorNolock( & targetSurface.getSDLSurface(),
01152 x, y, convertedColor ) ;
01153
01154 }
01155
01156 }
01157 else
01158 {
01159
01160 if ( blending )
01161 {
01162
01163
01164
01165
01166 ::putPixelAlpha( & targetSurface.getSDLSurface(), x, y,
01167 convertedColor, alpha ) ;
01168
01169 }
01170 else
01171 {
01172
01173
01174
01175 ::fastPixelColorNolockNoclip( & targetSurface.getSDLSurface(),
01176 x, y, convertedColor ) ;
01177
01178 }
01179
01180
01181 }
01182
01183
01184 }
01185
01186
01187 #else // OSDL_USES_SDL_GFX
01188
01189 throw VideoException( "Pixels::putPixelColor failed: "
01190 "no SDL support available" ) ;
01191
01192 #endif // OSDL_USES_SDL_GFX
01193
01194 }
01195
01196
01197
01198 void Pixels::alternativePutPixelColor( Surface & targetSurface,
01199 Coordinate x, Coordinate y, PixelColor color, bool mapToSurfaceFormat )
01200 {
01201
01202 #if OSDL_USES_SDL
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214 ColorMask redMask, greenMask, blueMask, alphaMask ;
01215 Pixels::getRecommendedColorMasks( redMask, greenMask, blueMask,
01216 alphaMask ) ;
01217
01218 if ( mapToSurfaceFormat )
01219 {
01220 color = SDL_MapRGBA( & targetSurface.getPixelFormat(),
01221 ( color & redMask ) >> 24,
01222 ( color & greenMask ) >> 16,
01223 ( color & blueMask ) >> 8,
01224 color & alphaMask ) ;
01225 }
01226
01227 BytesPerPixel bytes = targetSurface.getBytesPerPixel() ;
01228
01229
01230 ColorElement * p = reinterpret_cast<ColorElement *>(
01231 targetSurface.getPixels() )
01232 + y * targetSurface.getPitch() + x * bytes ;
01233
01234 switch( bytes )
01235 {
01236
01237 case 1:
01238 *p = color ;
01239 break ;
01240
01241 case 2:
01242 *( Uint16 * ) p = color ;
01243 break ;
01244
01245 case 3:
01246 #if CEYLAN_DETECTED_LITTLE_ENDIAN
01247 p[0] = color & 0xff ;
01248 p[1] = ( color >> 8 ) & 0xff ;
01249 p[2] = ( color >> 16 ) & 0xff ;
01250 #else // CEYLAN_DETECTED_LITTLE_ENDIAN
01251 p[0] = ( color >> 16 ) & 0xff ;
01252 p[1] = ( color >> 8 ) & 0xff ;
01253 p[2] = color & 0xff ;
01254 #endif // CEYLAN_DETECTED_LITTLE_ENDIAN
01255 break ;
01256
01257 case 4:
01258 *( Uint32 * ) p = color ;
01259 break ;
01260
01261 default:
01262 LogPlug::error( "Pixels::alternativePut: "
01263 "unexpected bytes per pixel specified ("
01264 + Ceylan::toString(
01265 static_cast<Ceylan::Uint16>( bytes ) )
01266 + "), nothing done." ) ;
01267 break ;
01268
01269 }
01270
01271
01272 #else // OSDL_USES_SDL
01273
01274 throw VideoException( "Pixels::alternativePutPixelColor failed: "
01275 "no SDL support available" ) ;
01276
01277 #endif // OSDL_USES_SDL
01278
01279 }
01280
01281
01282
01283 string Pixels::toString( const Pixels::PixelFormat & format )
01284 {
01285
01286 string result = "Pixel format description "
01287 "(masks are binary masks used to retrieve individual color values, "
01288 "loss is the precision loss of each color component, "
01289 "shift correspond to binary left shifts of each "
01290 "color component in the pixel value): " ;
01291
01292 std::list<string> l ;
01293
01294 l.push_back( Ceylan::toNumericalString( format.BitsPerPixel )
01295 + " bits per pixel." ) ;
01296
01297 l.push_back( Ceylan::toNumericalString( format.BytesPerPixel )
01298 + " bytes per pixel." ) ;
01299
01300 l.push_back( "Colorkey (pixel value of transparent pixels) is "
01301 + toString( format.colorkey, format ) + "." ) ;
01302
01303 l.push_back( "Overall alpha is "
01304 + Ceylan::toNumericalString( format.alpha ) + "." ) ;
01305
01306 if ( format.palette )
01307 l.push_back( "Palette available." ) ;
01308 else
01309 l.push_back( "No palette used." ) ;
01310
01311
01312 l.push_back( "Rmask is " + Ceylan::toString( format.Rmask, true ) + "." ) ;
01313 l.push_back( "Gmask is " + Ceylan::toString( format.Gmask, true ) + "." ) ;
01314 l.push_back( "Bmask is " + Ceylan::toString( format.Bmask, true ) + "." ) ;
01315 l.push_back( "Amask is " + Ceylan::toString( format.Amask, true ) + "." ) ;
01316
01317 l.push_back( "Rshift is "
01318 + Ceylan::toNumericalString( format.Rshift ) + "." ) ;
01319
01320 l.push_back( "Gshift is "
01321 + Ceylan::toNumericalString( format.Gshift ) + "." ) ;
01322
01323 l.push_back( "Bshift is "
01324 + Ceylan::toNumericalString( format.Bshift ) + "." ) ;
01325
01326 l.push_back( "Ashift is "
01327 + Ceylan::toNumericalString( format.Ashift ) + "." ) ;
01328
01329 l.push_back( "Rloss is "
01330 + Ceylan::toNumericalString( format.Rloss ) + "." ) ;
01331
01332 l.push_back( "Gloss is "
01333 + Ceylan::toNumericalString( format.Gloss ) + "." ) ;
01334
01335 l.push_back( "Bloss is "
01336 + Ceylan::toNumericalString( format.Bloss ) + "." ) ;
01337
01338 l.push_back( "Aloss is "
01339 + Ceylan::toNumericalString( format.Aloss ) + "." ) ;
01340
01341
01342 return result + Ceylan::formatStringList( l ) ;
01343
01344 }
01345
01346
01347
01348 string Pixels::toString( PixelColor pixel, const PixelFormat & format )
01349 {
01350
01351 return "Pixel whose color definition is "
01352 + toString( convertPixelColorToColorDefinition( format, pixel ) ) ;
01353
01354 }
01355
01356
01357
01358 string Pixels::toString( ColorDefinition color )
01359 {
01360
01361 string result = "[R;G;B;A] = [ "
01362 + Ceylan::toNumericalString( color.r ) + " ; "
01363 + Ceylan::toNumericalString( color.g ) + " ; "
01364 + Ceylan::toNumericalString( color.b ) + " ; "
01365 + Ceylan::toNumericalString( color.unused ) + " ]" ;
01366
01367 if ( Ceylan::TextDisplayable::GetOutputFormat()
01368 == Ceylan::TextDisplayable::html )
01369 {
01370
01371 string hexcolor = Ceylan::toHexString( color.r,
01372 false, 2 )
01373 + Ceylan::toHexString( color.g ,
01374 false, 2 )
01375 + Ceylan::toHexString( color.b ,
01376 false, 2 ) ;
01377
01378
01379
01380
01381
01382
01383 result += "<table><tr><td style=\"background: #"
01384 + hexcolor + "; color: #"
01385 + hexcolor + "\">OSDL rocks!</td></tr></table>" ;
01386
01387 }
01388
01389 return result ;
01390
01391 }
01392