00001
00002
00003 #include "Bitmap.h"
00004 #include "StandardLibrary.h"
00005 #include "Image.h"
00006 #include "Asset.h"
00007
00008 const char* Pixie_Bm_Header="PIXIE_BM";
00009
00010
00011
00012
00013 Bitmap::Bitmap():
00014 data_(0),
00015 width_(0),
00016 height_(0)
00017 {
00018 }
00019
00020
00021
00022
00023 Bitmap::Bitmap(const Asset& asset):
00024 data_(0),
00025 width_(0),
00026 height_(0)
00027 {
00028 Load(asset);
00029 }
00030
00031
00032
00033
00034 Bitmap::Bitmap(int width, int height):
00035 data_(0),
00036 width_(width),
00037 height_(height)
00038 {
00039 data_=(unsigned short*)Malloc(sizeof(unsigned short)*width*height);
00040 Clear();
00041 }
00042
00043
00044
00045
00046 Bitmap::Bitmap(const Image& image):
00047 data_(0),
00048 width_(0),
00049 height_(0)
00050 {
00051 width_=image.GetWidth();
00052 height_=image.GetHeight();
00053 data_=(unsigned short*)Malloc(sizeof(unsigned short)*width_*height_);
00054
00055 for (int y=0; y<height_; y++)
00056 {
00057 for (int x=0; x<width_; x++)
00058 {
00059 unsigned int c=image.GetPixel(x,y);
00060 data_[x+y*width_]=RGB32TO16(c);
00061 }
00062 }
00063 }
00064
00065
00066
00067
00068 Bitmap::~Bitmap()
00069 {
00070 if (data_)
00071 {
00072 Free(data_);
00073 }
00074 }
00075
00076
00077
00078
00079 int Bitmap::GetWidth(Orientation orientation) const
00080 {
00081 switch (orientation)
00082 {
00083 case Rotate_0:
00084 case Rotate_180:
00085 case Mirror_X:
00086 case Mirror_Y:
00087 {
00088 return width_;
00089 } break;
00090
00091 case Rotate_90:
00092 case Rotate_270:
00093 {
00094 return height_;
00095 } break;
00096 }
00097
00098 return width_;
00099 }
00100
00101
00102
00103
00104 int Bitmap::GetHeight(Orientation orientation) const
00105 {
00106 switch (orientation)
00107 {
00108 case Rotate_0:
00109 case Rotate_180:
00110 case Mirror_X:
00111 case Mirror_Y:
00112 {
00113 return height_;
00114 } break;
00115
00116 case Rotate_90:
00117 case Rotate_270:
00118 {
00119 return width_;
00120 } break;
00121 }
00122
00123 return height_;
00124 }
00125
00126
00127
00128
00129 unsigned short* Bitmap::GetData()
00130 {
00131 return data_;
00132 }
00133
00134
00135
00136
00137 void Bitmap::Clear()
00138 {
00139 MemSet(data_,0,sizeof(unsigned short)*width_*height_);
00140 }
00141
00142
00143
00144
00145 void Bitmap::Fill(int x1, int y1, int x2, int y2, unsigned short color, unsigned char alpha)
00146 {
00147 if (x1<0)
00148 {
00149 x1=0;
00150 }
00151
00152 if (y1<0)
00153 {
00154 y1=0;
00155 }
00156
00157 if (x2>=width_)
00158 {
00159 x2=width_-1;
00160 }
00161
00162 if (y2>=height_)
00163 {
00164 y2=height_-1;
00165 }
00166
00167 unsigned short* data=&data_[x1+y1*width_];
00168 int pitch=width_-(x2-x1+1);
00169
00170 if (alpha==255)
00171 {
00172 for (int y=y1; y<=y2; y++)
00173 {
00174 for (int x=x1; x<=x2; x++)
00175 {
00176 *data=color;
00177 data++;
00178 }
00179 data+=pitch;
00180 }
00181 }
00182 else
00183 {
00184 for (int y=y1; y<=y2; y++)
00185 {
00186 for (int x=x1; x<=x2; x++)
00187 {
00188 if (alpha>0)
00189 {
00190 *data=AlphaBlend16(*data,color,alpha);
00191 }
00192 data++;
00193 }
00194 data+=pitch;
00195 }
00196 }
00197 }
00198
00199
00200
00201
00202 void Bitmap::Fill(unsigned short color, unsigned char alpha)
00203 {
00204 unsigned short* data=data_;
00205
00206 if (alpha==255)
00207 {
00208 for (int y=0; y<height_; y++)
00209 {
00210 for (int x=0; x<width_; x++)
00211 {
00212 *data=color;
00213 data++;
00214 }
00215 }
00216 }
00217 else
00218 {
00219 for (int y=0; y<height_; y++)
00220 {
00221 for (int x=0; x<width_; x++)
00222 {
00223 if (alpha>0)
00224 {
00225 *data=AlphaBlend16(*data,color,alpha);
00226 }
00227 data++;
00228 }
00229 }
00230 }
00231 }
00232
00233
00234
00235
00236 void Bitmap::SetPixel(int x, int y,unsigned short color)
00237 {
00238 if (x>=0 && x<width_ && y>=0 && y<height_)
00239 {
00240 data_[x+y*width_]=color;
00241 }
00242 }
00243
00244
00245
00246
00247 void Bitmap::SetPixel(int x, int y,unsigned short color, Orientation orientation)
00248 {
00249 if (x>=0 && x<GetWidth(orientation) && y>=0 && y<GetHeight(orientation))
00250 {
00251 TransformCoordinates(x,y,orientation);
00252 data_[x+y*width_]=color;
00253 }
00254 }
00255
00256
00257
00258
00259 unsigned short Bitmap::GetPixel(int x, int y) const
00260 {
00261 if (x>=0 && x<width_ && y>=0 && y<height_)
00262 {
00263 return data_[x+y*width_];
00264 }
00265 return 0;
00266 }
00267
00268
00269
00270
00271 unsigned short Bitmap::GetPixel(int x, int y, Orientation orientation) const
00272 {
00273 if (x>=0 && x<GetWidth(orientation) && y>=0 && y<GetHeight(orientation))
00274 {
00275 TransformCoordinates(x,y,orientation);
00276 return data_[x+y*width_];
00277 }
00278 return 0;
00279 }
00280
00281
00282
00283
00284 void Bitmap::BlendPixel(int x, int y,unsigned short color, unsigned char alpha)
00285 {
00286 if (x>=0 && x<width_ && y>=0 && y<height_)
00287 {
00288 unsigned short* d=&data_[x+y*width_];
00289 if (alpha==255)
00290 {
00291 *d=color;
00292 }
00293 else if (alpha>0)
00294 {
00295 *d=AlphaBlend16(*d,color,alpha);
00296 }
00297 }
00298 }
00299
00300
00301
00302
00303 void Bitmap::BlendPixel(int x, int y,unsigned short color, unsigned char alpha, Orientation orientation)
00304 {
00305 if (x>=0 && x<GetWidth(orientation) && y>=0 && y<GetHeight(orientation))
00306 {
00307 TransformCoordinates(x,y,orientation);
00308 unsigned short* d=&data_[x+y*width_];
00309 if (alpha==255)
00310 {
00311 *d=color;
00312 }
00313 else if (alpha>0)
00314 {
00315 *d=AlphaBlend16(*d,color,alpha);
00316 }
00317 }
00318 }
00319
00320
00321
00322
00323 void Bitmap::TransformCoordinates(int& x, int& y, Orientation orientation) const
00324 {
00325 int xp=x;
00326 int yp=y;
00327 switch (orientation)
00328 {
00329 case Rotate_0:
00330 {
00331 return;
00332 } break;
00333
00334 case Rotate_90:
00335 {
00336 xp=y;
00337 yp=(height_-1)-x;
00338 } break;
00339
00340 case Rotate_180:
00341 {
00342 xp=(width_-1)-x;
00343 yp=(height_-1)-y;
00344 } break;
00345
00346 case Rotate_270:
00347 {
00348 xp=(width_-1)-y;
00349 yp=x;
00350 } break;
00351
00352 case Mirror_X:
00353 {
00354 xp=(width_-1)-x;
00355 } break;
00356
00357 case Mirror_Y:
00358 {
00359 yp=(height_-1)-y;
00360 } break;
00361
00362 }
00363 x=xp;
00364 y=yp;
00365 }
00366
00367
00368
00369
00370 void Bitmap::Blit(Bitmap* target, int x, int y, unsigned short modulate, unsigned char alpha, Orientation orientation) const
00371 {
00372 Blit(0, 0, width_-1, height_-1, target, x, y, modulate, alpha, orientation);
00373 }
00374
00375
00376
00377
00378 void Bitmap::Blit(int x1, int y1, int x2, int y2, Bitmap* target, int x, int y, unsigned short modulate, unsigned char alpha, Orientation orientation) const
00379 {
00380
00381 if (alpha==0)
00382 {
00383 return;
00384 }
00385
00386
00387
00388 int sourceX=x1;
00389 int sourceY=y1;
00390 int sourceWidth=(x2-x1)+1;
00391 int sourceHeight=(y2-y1)+1;
00392 int targetX=x;
00393 int targetY=y;
00394
00395
00396
00397
00398 if (sourceX<0)
00399 {
00400 targetX+=-sourceX;
00401 sourceWidth-=-sourceX;
00402 sourceX=0;
00403 }
00404
00405
00406 if (sourceY<0)
00407 {
00408 targetY+=-sourceY;
00409 sourceHeight-=-sourceY;
00410 sourceY=0;
00411 }
00412
00413
00414 if (sourceX+sourceWidth>GetWidth(orientation))
00415 {
00416 sourceWidth-=(sourceX+sourceWidth)-GetWidth(orientation);
00417 }
00418
00419
00420 if (sourceY+sourceHeight>GetHeight(orientation))
00421 {
00422 sourceHeight-=(sourceY+sourceHeight)-GetHeight(orientation);
00423 }
00424
00425
00426
00427
00428 if (targetX<0)
00429 {
00430 sourceX+=-targetX;
00431 sourceWidth-=-targetX;
00432 targetX=0;
00433 }
00434
00435
00436 if (targetY<0)
00437 {
00438 sourceY+=-targetY;
00439 sourceHeight-=-targetY;
00440 targetY=0;
00441 }
00442
00443
00444 if (targetX+sourceWidth>target->GetWidth())
00445 {
00446 sourceWidth-=1+(targetX+sourceWidth)-target->GetWidth();
00447 }
00448
00449
00450 if (targetY+sourceHeight>target->GetHeight())
00451 {
00452 sourceHeight-=1+(targetY+sourceHeight)-target->GetHeight();
00453 }
00454
00455
00456 Assert(sourceX>=0 && sourceY>=0 && (sourceX+sourceWidth)<=GetWidth(orientation) && (sourceY+sourceHeight)<=GetHeight(orientation),"Source rect out of range");
00457 Assert(targetX>=0 && targetY>=0 && (targetX+sourceWidth)<=target->GetWidth() && (targetY+sourceHeight)<=target->GetHeight(),"Targer rect out of range");
00458
00459
00460 if (sourceWidth<=0 || sourceHeight<=0)
00461 {
00462 return;
00463 }
00464
00465
00466
00467 switch (orientation)
00468 {
00469 case Rotate_0:
00470 {
00471 if (modulate==0xffff && alpha==255)
00472 {
00473 Blit_Rotate0(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY);
00474 }
00475 else if (modulate!=0xffff && alpha==255)
00476 {
00477 Blit_Rotate0_Modulate(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY,modulate);
00478 }
00479 else if (modulate==0xffff && alpha!=255)
00480 {
00481 Blit_Rotate0_Alpha(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY,alpha);
00482 }
00483 else
00484 {
00485 Blit_Rotate0_Modulate_Alpha(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY,modulate,alpha);
00486 }
00487 } break;
00488
00489 case Rotate_90:
00490 {
00491 if (modulate==0xffff && alpha==255)
00492 {
00493 Blit_Rotate90(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY);
00494 }
00495 else if (modulate!=0xffff && alpha==255)
00496 {
00497 Blit_Rotate90_Modulate(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY,modulate);
00498 }
00499 else if (modulate==0xffff && alpha!=255)
00500 {
00501 Blit_Rotate90_Alpha(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY,alpha);
00502 }
00503 else
00504 {
00505 Blit_Rotate90_Modulate_Alpha(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY,modulate,alpha);
00506 }
00507 } break;
00508
00509 case Rotate_180:
00510 {
00511 if (modulate==0xffff && alpha==255)
00512 {
00513 Blit_Rotate180(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY);
00514 }
00515 else if (modulate!=0xffff && alpha==255)
00516 {
00517 Blit_Rotate180_Modulate(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY,modulate);
00518 }
00519 else if (modulate==0xffff && alpha!=255)
00520 {
00521 Blit_Rotate180_Alpha(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY,alpha);
00522 }
00523 else
00524 {
00525 Blit_Rotate180_Modulate_Alpha(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY,modulate,alpha);
00526 }
00527 } break;
00528
00529 case Rotate_270:
00530 {
00531 if (modulate==0xffff && alpha==255)
00532 {
00533 Blit_Rotate270(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY);
00534 }
00535 else if (modulate!=0xffff && alpha==255)
00536 {
00537 Blit_Rotate270_Modulate(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY,modulate);
00538 }
00539 else if (modulate==0xffff && alpha!=255)
00540 {
00541 Blit_Rotate270_Alpha(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY,alpha);
00542 }
00543 else
00544 {
00545 Blit_Rotate270_Modulate_Alpha(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY,modulate,alpha);
00546 }
00547 } break;
00548
00549 case Mirror_X:
00550 {
00551 if (modulate==0xffff && alpha==255)
00552 {
00553 Blit_MirrorX(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY);
00554 }
00555 else if (modulate!=0xffff && alpha==255)
00556 {
00557 Blit_MirrorX_Modulate(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY,modulate);
00558 }
00559 else if (modulate==0xffff && alpha!=255)
00560 {
00561 Blit_MirrorX_Alpha(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY,alpha);
00562 }
00563 else
00564 {
00565 Blit_MirrorX_Modulate_Alpha(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY,modulate,alpha);
00566 }
00567 } break;
00568
00569 case Mirror_Y:
00570 {
00571 if (modulate==0xffff && alpha==255)
00572 {
00573 Blit_MirrorY(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY);
00574 }
00575 else if (modulate!=0xffff && alpha==255)
00576 {
00577 Blit_MirrorY_Modulate(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY,modulate);
00578 }
00579 else if (modulate==0xffff && alpha!=255)
00580 {
00581 Blit_MirrorY_Alpha(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY,alpha);
00582 }
00583 else
00584 {
00585 Blit_MirrorY_Modulate_Alpha(sourceX,sourceY,sourceWidth,sourceHeight,target,targetX,targetY,modulate,alpha);
00586 }
00587 } break;
00588
00589 }
00590 }
00591
00592
00593
00594
00595 void Bitmap::Blit_Rotate0(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY) const
00596 {
00597 unsigned short* source=&data_[sourceX+sourceY*width_];
00598 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
00599
00600 int byteCount=sourceWidth*2;
00601 int sourcePitch=width_;
00602 int destinationPitch=target->width_;
00603 for (int y=0; y<sourceHeight; y++)
00604 {
00605 MemCpy(destination,source,byteCount);
00606 source+=sourcePitch;
00607 destination+=destinationPitch;
00608 }
00609 }
00610
00611
00612
00613
00614 void Bitmap::Blit_Rotate0_Modulate(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY, unsigned short modulate) const
00615 {
00616 unsigned short* source=&data_[sourceX+sourceY*width_];
00617 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
00618
00619 int sourcePitch=width_-sourceWidth;
00620 int destinationPitch=target->width_-sourceWidth;
00621 for (int y=0; y<sourceHeight; y++)
00622 {
00623 for (int x=0; x<sourceWidth; x++)
00624 {
00625 *destination=RGBModulate16(*source,modulate);
00626 source++;
00627 destination++;
00628 }
00629 source+=sourcePitch;
00630 destination+=destinationPitch;
00631 }
00632 }
00633
00634
00635
00636
00637 void Bitmap::Blit_Rotate0_Alpha(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY, unsigned char alpha) const
00638 {
00639 unsigned short* source=&data_[sourceX+sourceY*width_];
00640 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
00641
00642 int sourcePitch=width_-sourceWidth;
00643 int destinationPitch=target->width_-sourceWidth;
00644 for (int y=0; y<sourceHeight; y++)
00645 {
00646 for (int x=0; x<sourceWidth; x++)
00647 {
00648 *destination=AlphaBlend16(*destination,*source,alpha);
00649 source++;
00650 destination++;
00651 }
00652 source+=sourcePitch;
00653 destination+=destinationPitch;
00654 }
00655 }
00656
00657
00658
00659
00660 void Bitmap::Blit_Rotate0_Modulate_Alpha(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY, unsigned short modulate, unsigned char alpha) const
00661 {
00662 unsigned short* source=&data_[sourceX+sourceY*width_];
00663 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
00664
00665 int sourcePitch=width_-sourceWidth;
00666 int destinationPitch=target->width_-sourceWidth;
00667 for (int y=0; y<sourceHeight; y++)
00668 {
00669 for (int x=0; x<sourceWidth; x++)
00670 {
00671 unsigned short destinationColor=*destination;
00672 unsigned short sourceColor=RGBModulate16(*source,modulate);
00673 *destination=AlphaBlend16(destinationColor,sourceColor,alpha);
00674 source++;
00675 destination++;
00676 }
00677 source+=sourcePitch;
00678 destination+=destinationPitch;
00679 }
00680 }
00681
00682
00683
00684
00685 void Bitmap::Blit_Rotate90(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY) const
00686 {
00687 unsigned short* source=&data_[((height_-1)-sourceX)*width_+sourceY];
00688 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
00689
00690 int sourcePitch=sourceWidth*width_+1;
00691 int destinationPitch=target->width_-sourceWidth;
00692 for (int y=0; y<sourceHeight; y++)
00693 {
00694 for (int x=0; x<sourceWidth; x++)
00695 {
00696 *destination=*source;
00697 source-=width_;
00698 destination++;
00699 }
00700 source+=sourcePitch;
00701 destination+=destinationPitch;
00702 }
00703 }
00704
00705
00706
00707
00708 void Bitmap::Blit_Rotate90_Modulate(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY, unsigned short modulate) const
00709 {
00710 unsigned short* source=&data_[((height_-1)-sourceX)*width_+sourceY];
00711 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
00712
00713 int sourcePitch=sourceWidth*width_+1;
00714 int destinationPitch=target->width_-sourceWidth;
00715 for (int y=0; y<sourceHeight; y++)
00716 {
00717 for (int x=0; x<sourceWidth; x++)
00718 {
00719 *destination=RGBModulate16(*source,modulate);
00720 source-=width_;
00721 destination++;
00722 }
00723 source+=sourcePitch;
00724 destination+=destinationPitch;
00725 }
00726 }
00727
00728
00729
00730
00731 void Bitmap::Blit_Rotate90_Alpha(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY, unsigned char alpha) const
00732 {
00733 unsigned short* source=&data_[((height_-1)-sourceX)*width_+sourceY];
00734 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
00735
00736 int sourcePitch=sourceWidth*width_+1;
00737 int destinationPitch=target->width_-sourceWidth;
00738 for (int y=0; y<sourceHeight; y++)
00739 {
00740 for (int x=0; x<sourceWidth; x++)
00741 {
00742 *destination=AlphaBlend16(*destination,*source,alpha);
00743 source-=width_;
00744 destination++;
00745 }
00746 source+=sourcePitch;
00747 destination+=destinationPitch;
00748 }
00749 }
00750
00751
00752
00753
00754 void Bitmap::Blit_Rotate90_Modulate_Alpha(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY, unsigned short modulate, unsigned char alpha) const
00755 {
00756 unsigned short* source=&data_[((height_-1)-sourceX)*width_+sourceY];
00757 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
00758
00759 int sourcePitch=sourceWidth*width_+1;
00760 int destinationPitch=target->width_-sourceWidth;
00761 for (int y=0; y<sourceHeight; y++)
00762 {
00763 for (int x=0; x<sourceWidth; x++)
00764 {
00765 unsigned short destinationColor=*destination;
00766 unsigned short sourceColor=RGBModulate16(*source,modulate);
00767 *destination=AlphaBlend16(destinationColor,sourceColor,alpha);
00768 source-=width_;
00769 destination++;
00770 }
00771 source+=sourcePitch;
00772 destination+=destinationPitch;
00773 }
00774 }
00775
00776
00777
00778
00779 void Bitmap::Blit_Rotate180(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY) const
00780 {
00781 unsigned short* source=&data_[(width_-1)-sourceX+((height_-1)-sourceY)*width_];
00782 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
00783
00784 int sourcePitch=-(width_-sourceWidth);
00785 int destinationPitch=target->width_-sourceWidth;
00786 for (int y=0; y<sourceHeight; y++)
00787 {
00788 for (int x=0; x<sourceWidth; x++)
00789 {
00790 *destination=*source;
00791 source--;
00792 destination++;
00793 }
00794 source+=sourcePitch;
00795 destination+=destinationPitch;
00796 }
00797 }
00798
00799
00800
00801
00802 void Bitmap::Blit_Rotate180_Modulate(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY, unsigned short modulate) const
00803 {
00804 unsigned short* source=&data_[(width_-1)-sourceX+((height_-1)-sourceY)*width_];
00805 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
00806
00807 int sourcePitch=-(width_-sourceWidth);
00808 int destinationPitch=target->width_-sourceWidth;
00809 for (int y=0; y<sourceHeight; y++)
00810 {
00811 for (int x=0; x<sourceWidth; x++)
00812 {
00813 *destination=RGBModulate16(*source,modulate);
00814 source--;
00815 destination++;
00816 }
00817 source+=sourcePitch;
00818 destination+=destinationPitch;
00819 }
00820 }
00821
00822
00823
00824
00825 void Bitmap::Blit_Rotate180_Alpha(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY, unsigned char alpha) const
00826 {
00827 unsigned short* source=&data_[(width_-1)-sourceX+((height_-1)-sourceY)*width_];
00828 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
00829
00830 int sourcePitch=-(width_-sourceWidth);
00831 int destinationPitch=target->width_-sourceWidth;
00832 for (int y=0; y<sourceHeight; y++)
00833 {
00834 for (int x=0; x<sourceWidth; x++)
00835 {
00836 *destination=AlphaBlend16(*destination,*source,alpha);
00837 source--;
00838 destination++;
00839 }
00840 source+=sourcePitch;
00841 destination+=destinationPitch;
00842 }
00843 }
00844
00845
00846
00847
00848 void Bitmap::Blit_Rotate180_Modulate_Alpha(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY, unsigned short modulate, unsigned char alpha) const
00849 {
00850 unsigned short* source=&data_[(width_-1)-sourceX+((height_-1)-sourceY)*width_];
00851 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
00852
00853 int sourcePitch=-(width_-sourceWidth);
00854 int destinationPitch=target->width_-sourceWidth;
00855 for (int y=0; y<sourceHeight; y++)
00856 {
00857 for (int x=0; x<sourceWidth; x++)
00858 {
00859 unsigned short destinationColor=*destination;
00860 unsigned short sourceColor=RGBModulate16(*source,modulate);
00861 *destination=AlphaBlend16(destinationColor,sourceColor,alpha);
00862 source--;
00863 destination++;
00864 }
00865 source+=sourcePitch;
00866 destination+=destinationPitch;
00867 }
00868 }
00869
00870
00871
00872
00873 void Bitmap::Blit_Rotate270(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY) const
00874 {
00875 unsigned short* source=&data_[(width_-1-sourceY)+sourceX*width_];
00876 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
00877
00878 int sourcePitch=sourceWidth*width_+1;
00879 int destinationPitch=target->width_-sourceWidth;
00880 for (int y=0; y<sourceHeight; y++)
00881 {
00882 for (int x=0; x<sourceWidth; x++)
00883 {
00884 *destination=*source;
00885 source+=width_;
00886 destination++;
00887 }
00888 source-=sourcePitch;
00889 destination+=destinationPitch;
00890 }
00891 }
00892
00893
00894
00895
00896 void Bitmap::Blit_Rotate270_Modulate(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY, unsigned short modulate) const
00897 {
00898 unsigned short* source=&data_[(width_-1-sourceY)+sourceX*width_];
00899 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
00900
00901 int sourcePitch=sourceWidth*width_+1;
00902 int destinationPitch=target->width_-sourceWidth;
00903 for (int y=0; y<sourceHeight; y++)
00904 {
00905 for (int x=0; x<sourceWidth; x++)
00906 {
00907 *destination=RGBModulate16(*source,modulate);
00908 source+=width_;
00909 destination++;
00910 }
00911 source-=sourcePitch;
00912 destination+=destinationPitch;
00913 }
00914 }
00915
00916
00917
00918
00919 void Bitmap::Blit_Rotate270_Alpha(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY, unsigned char alpha) const
00920 {
00921 unsigned short* source=&data_[(width_-1-sourceY)+sourceX*width_];
00922 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
00923
00924 int sourcePitch=sourceWidth*width_+1;
00925 int destinationPitch=target->width_-sourceWidth;
00926 for (int y=0; y<sourceHeight; y++)
00927 {
00928 for (int x=0; x<sourceWidth; x++)
00929 {
00930 *destination=AlphaBlend16(*destination,*source,alpha);
00931 source+=width_;
00932 destination++;
00933 }
00934 source-=sourcePitch;
00935 destination+=destinationPitch;
00936 }
00937 }
00938
00939
00940
00941
00942 void Bitmap::Blit_Rotate270_Modulate_Alpha(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY, unsigned short modulate, unsigned char alpha) const
00943 {
00944 unsigned short* source=&data_[(width_-1-sourceY)+sourceX*width_];
00945 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
00946
00947 int sourcePitch=sourceWidth*width_+1;
00948 int destinationPitch=target->width_-sourceWidth;
00949 for (int y=0; y<sourceHeight; y++)
00950 {
00951 for (int x=0; x<sourceWidth; x++)
00952 {
00953 unsigned short destinationColor=*destination;
00954 unsigned short sourceColor=RGBModulate16(*source,modulate);
00955 *destination=AlphaBlend16(destinationColor,sourceColor,alpha);
00956 source+=width_;
00957 destination++;
00958 }
00959 source-=sourcePitch;
00960 destination+=destinationPitch;
00961 }
00962 }
00963
00964
00965
00966
00967 void Bitmap::Blit_MirrorX(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY) const
00968 {
00969 unsigned short* source=&data_[(width_-1)-sourceX+sourceY*width_];
00970 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
00971
00972 int sourcePitch=width_+sourceWidth;
00973 int destinationPitch=target->width_-sourceWidth;
00974 for (int y=0; y<sourceHeight; y++)
00975 {
00976 for (int x=0; x<sourceWidth; x++)
00977 {
00978 *destination=*source;
00979 source--;
00980 destination++;
00981 }
00982 source+=sourcePitch;
00983 destination+=destinationPitch;
00984 }
00985 }
00986
00987
00988
00989
00990 void Bitmap::Blit_MirrorX_Modulate(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY, unsigned short modulate) const
00991 {
00992 unsigned short* source=&data_[(width_-1)-sourceX+sourceY*width_];
00993 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
00994
00995 int sourcePitch=width_+sourceWidth;
00996 int destinationPitch=target->width_-sourceWidth;
00997 for (int y=0; y<sourceHeight; y++)
00998 {
00999 for (int x=0; x<sourceWidth; x++)
01000 {
01001 *destination=RGBModulate16(*source,modulate);
01002 source--;
01003 destination++;
01004 }
01005 source+=sourcePitch;
01006 destination+=destinationPitch;
01007 }
01008 }
01009
01010
01011
01012
01013 void Bitmap::Blit_MirrorX_Alpha(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY, unsigned char alpha) const
01014 {
01015 unsigned short* source=&data_[(width_-1)-sourceX+sourceY*width_];
01016 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
01017
01018 int sourcePitch=width_+sourceWidth;
01019 int destinationPitch=target->width_-sourceWidth;
01020 for (int y=0; y<sourceHeight; y++)
01021 {
01022 for (int x=0; x<sourceWidth; x++)
01023 {
01024 *destination=AlphaBlend16(*destination,*source,alpha);
01025 source--;
01026 destination++;
01027 }
01028 source+=sourcePitch;
01029 destination+=destinationPitch;
01030 }
01031 }
01032
01033
01034
01035
01036 void Bitmap::Blit_MirrorX_Modulate_Alpha(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY, unsigned short modulate, unsigned char alpha) const
01037 {
01038 unsigned short* source=&data_[(width_-1)-sourceX+sourceY*width_];
01039 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
01040
01041 int sourcePitch=width_+sourceWidth;
01042 int destinationPitch=target->width_-sourceWidth;
01043 for (int y=0; y<sourceHeight; y++)
01044 {
01045 for (int x=0; x<sourceWidth; x++)
01046 {
01047 unsigned short destinationColor=*destination;
01048 unsigned short sourceColor=RGBModulate16(*source,modulate);
01049 *destination=AlphaBlend16(destinationColor,sourceColor,alpha);
01050 source--;
01051 destination++;
01052 }
01053 source+=sourcePitch;
01054 destination+=destinationPitch;
01055 }
01056 }
01057
01058
01059
01060
01061 void Bitmap::Blit_MirrorY(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY) const
01062 {
01063 unsigned short* source=&data_[sourceX+((height_-1)-sourceY)*width_];
01064 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
01065
01066 int byteCount=sourceWidth*2;
01067 int sourcePitch=-width_;
01068 int destinationPitch=target->width_;
01069 for (int y=0; y<sourceHeight; y++)
01070 {
01071 MemCpy(destination,source,byteCount);
01072 source+=sourcePitch;
01073 destination+=destinationPitch;
01074 }
01075 }
01076
01077
01078
01079
01080 void Bitmap::Blit_MirrorY_Modulate(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY, unsigned short modulate) const
01081 {
01082 unsigned short* source=&data_[sourceX+((height_-1)-sourceY)*width_];
01083 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
01084
01085 int sourcePitch=-(width_+sourceWidth);
01086 int destinationPitch=target->width_-sourceWidth;
01087 for (int y=0; y<sourceHeight; y++)
01088 {
01089 for (int x=0; x<sourceWidth; x++)
01090 {
01091 *destination=RGBModulate16(*source,modulate);
01092 source++;
01093 destination++;
01094 }
01095 source+=sourcePitch;
01096 destination+=destinationPitch;
01097 }
01098 }
01099
01100
01101
01102
01103 void Bitmap::Blit_MirrorY_Alpha(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY, unsigned char alpha) const
01104 {
01105 unsigned short* source=&data_[sourceX+((height_-1)-sourceY)*width_];
01106 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
01107
01108 int sourcePitch=-(width_+sourceWidth);
01109 int destinationPitch=target->width_-sourceWidth;
01110 for (int y=0; y<sourceHeight; y++)
01111 {
01112 for (int x=0; x<sourceWidth; x++)
01113 {
01114 *destination=AlphaBlend16(*destination,*source,alpha);
01115 source++;
01116 destination++;
01117 }
01118 source+=sourcePitch;
01119 destination+=destinationPitch;
01120 }
01121 }
01122
01123
01124
01125
01126 void Bitmap::Blit_MirrorY_Modulate_Alpha(int sourceX, int sourceY, int sourceWidth, int sourceHeight, Bitmap* target, int targetX, int targetY, unsigned short modulate, unsigned char alpha) const
01127 {
01128 unsigned short* source=&data_[sourceX+((height_-1)-sourceY)*width_];
01129 unsigned short* destination=&target->data_[targetX+targetY*target->width_];
01130
01131 int sourcePitch=-(width_+sourceWidth);
01132 int destinationPitch=target->width_-sourceWidth;
01133 for (int y=0; y<sourceHeight; y++)
01134 {
01135 for (int x=0; x<sourceWidth; x++)
01136 {
01137 unsigned short destinationColor=*destination;
01138 unsigned short sourceColor=