src/video/SDL_surface.c
changeset 5499 2b8e6d1e3817
parent 5438 b705640cb34a
child 5515 0fcf231a6e74
equal deleted inserted replaced
5498:ef1db08c40ac 5499:2b8e6d1e3817
   600     }
   600     }
   601     dstrect->w = dstrect->h = 0;
   601     dstrect->w = dstrect->h = 0;
   602     return 0;
   602     return 0;
   603 }
   603 }
   604 
   604 
   605 /*
   605 int
   606  * Scale and blit a surface 
   606 SDL_UpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect,
   607 */
   607               SDL_Surface * dst, SDL_Rect * dstrect)
   608 int
   608 {
   609 SDL_BlitScaled(SDL_Surface * src, const SDL_Rect * srcrect,
   609     SDL_Rect final_src, final_dst, fulldst;
   610                SDL_Surface * dst, const SDL_Rect * dstrect)
   610 
       
   611     /* Make sure the surfaces aren't locked */
       
   612     if (!src || !dst) {
       
   613         SDL_SetError("SDL_UpperBlitScaled: passed a NULL surface");
       
   614         return (-1);
       
   615     }
       
   616     if (src->locked || dst->locked) {
       
   617         SDL_SetError("Surfaces must not be locked during blit");
       
   618         return (-1);
       
   619     }
       
   620 
       
   621     /* If the destination rectangle is NULL, use the entire dest surface */
       
   622     if (dstrect == NULL) {
       
   623         fulldst.x = fulldst.y = 0;
       
   624         dstrect = &fulldst;
       
   625     }
       
   626 
       
   627     /* clip the source rectangle to the source surface */
       
   628     if (srcrect) {
       
   629         int maxw, maxh;
       
   630 
       
   631         final_src.x = srcrect->x;
       
   632         final_src.w = srcrect->w;
       
   633         if (final_src.x < 0) {
       
   634             final_src.w += final_src.x;
       
   635             final_src.x = 0;
       
   636         }
       
   637         maxw = src->w - final_src.x;
       
   638         if (maxw < final_src.w)
       
   639             final_src.w = maxw;
       
   640 
       
   641         final_src.y = srcrect->y;
       
   642         final_src.h = srcrect->h;
       
   643         if (final_src.y < 0) {
       
   644             final_src.h += final_src.y;
       
   645             final_src.y = 0;
       
   646         }
       
   647         maxh = src->h - final_src.y;
       
   648         if (maxh < final_src.h)
       
   649             final_src.h = maxh;
       
   650 
       
   651     } else {
       
   652         final_src.x = final_src.y = 0;
       
   653         final_src.w = src->w;
       
   654         final_src.h = src->h;
       
   655     }
       
   656 
       
   657     /* clip the destination rectangle against the clip rectangle */
       
   658     if (dstrect) {
       
   659         int maxw, maxh;
       
   660 
       
   661         final_dst.x = dstrect->x;
       
   662         final_dst.w = dstrect->w;
       
   663         if (final_dst.x < 0) {
       
   664             final_dst.w += final_dst.x;
       
   665             final_dst.x = 0;
       
   666         }
       
   667         maxw = dst->w - final_dst.x;
       
   668         if (maxw < final_dst.w)
       
   669             final_dst.w = maxw;
       
   670 
       
   671         final_dst.y = dstrect->y;
       
   672         final_dst.h = dstrect->h;
       
   673         if (final_dst.y < 0) {
       
   674             final_dst.h += final_dst.y;
       
   675             final_dst.y = 0;
       
   676         }
       
   677         maxh = dst->h - final_dst.y;
       
   678         if (maxh < final_dst.h)
       
   679             final_dst.h = maxh;
       
   680     } else {
       
   681         final_dst.x = final_dst.y = 0;
       
   682         final_dst.w = dst->w;
       
   683         final_dst.h = dst->h;
       
   684     }
       
   685 
       
   686     if (final_dst.w > 0 && final_dst.h > 0) {
       
   687         return SDL_LowerBlitScaled(src, &final_src, dst, &final_dst);
       
   688     }
       
   689 
       
   690     return 0;
       
   691 }
       
   692 
       
   693 /**
       
   694  *  This is a semi-private blit function and it performs low-level surface
       
   695  *  scaled blitting only.
       
   696  */
       
   697 int
       
   698 SDL_LowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect,
       
   699                 SDL_Surface * dst, SDL_Rect * dstrect)
   611 {
   700 {
   612     /* Save off the original dst width, height */
   701     /* Save off the original dst width, height */
   613     int dstW = dstrect->w;
   702     int dstW = dstrect->w;
   614     int dstH = dstrect->h;
   703     int dstH = dstrect->h;
   615     SDL_Rect final_dst = *dstrect;
   704     SDL_Rect final_dst = *dstrect;
   616     SDL_Rect final_src = *srcrect;
   705     SDL_Rect final_src = *srcrect;
   617 
   706 
   618     /* Clip the dst surface to the dstrect */
   707     /* Clip the dst surface to the dstrect */
   619     SDL_SetClipRect( dst, &final_dst );
   708     SDL_SetClipRect( dst, &final_dst );
   620 
       
   621     /* If the dest was clipped to a zero sized rect then exit */
       
   622     if ( dst->clip_rect.w <= 0 || dst->clip_rect.h <= 0 ) {
       
   623         return -1;
       
   624     }
       
   625 
   709 
   626     /* Did the dst width change? */
   710     /* Did the dst width change? */
   627     if ( dstW != dst->clip_rect.w ) {
   711     if ( dstW != dst->clip_rect.w ) {
   628         /* scale the src width appropriately */
   712         /* scale the src width appropriately */
   629         final_src.w = final_src.w * dst->clip_rect.w / dstW;
   713         final_src.w = final_src.w * dst->clip_rect.w / dstW;