SDL_cgximage.c
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:22k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. /*
  2.     SDL - Simple DirectMedia Layer
  3.     Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.     This library is distributed in the hope that it will be useful,
  9.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.     Library General Public License for more details.
  12.     You should have received a copy of the GNU Library General Public
  13.     License along with this library; if not, write to the Free
  14.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  15.     Sam Lantinga
  16.     slouken@libsdl.org
  17. */
  18. #ifdef SAVE_RCSID
  19. static char rcsid =
  20.  "@(#) $Id: SDL_cgximage.c,v 1.4 2002/04/22 21:38:04 wmay Exp $";
  21. #endif
  22. #include <stdlib.h>
  23. #include "SDL_error.h"
  24. #include "SDL_endian.h"
  25. #include "SDL_cgximage_c.h"
  26. #ifdef HAVE_KSTAT
  27. #include <kstat.h>
  28. #endif
  29. #ifdef USE_CGX_WRITELUTPIXEL
  30. #if defined(__SASC) || defined(__PPC__)
  31. #define WLUT WriteLUTPixelArray
  32. #else
  33. void WLUT(APTR a,UWORD b,UWORD c,UWORD d,struct RastPort *e,APTR f,UWORD g,UWORD h,UWORD i,UWORD l,UBYTE m)
  34. { WriteLUTPixelArray(a,b,c,d,e,f,g,h,i,l,m); }
  35. #endif
  36. #endif
  37. /* Various screen update functions available */
  38. static void CGX_NormalUpdate(_THIS, int numrects, SDL_Rect *rects);
  39. static void CGX_FakeUpdate(_THIS, int numrects, SDL_Rect *rects);
  40. BOOL SafeDisp=TRUE,SafeChange=TRUE;
  41. struct MsgPort *safeport=NULL,*dispport=NULL;
  42. ULONG safe_sigbit,disp_sigbit;
  43. int use_picasso96=1;
  44. int CGX_SetupImage(_THIS, SDL_Surface *screen)
  45. {
  46. SDL_Ximage=NULL;
  47. if(screen->flags&SDL_HWSURFACE) {
  48. ULONG pitch;
  49. if(!screen->hwdata) {
  50. if(!(screen->hwdata=malloc(sizeof(struct private_hwdata))))
  51. return -1;
  52. D(bug("Creating system accel structn"));
  53. }
  54. screen->hwdata->lock=NULL;
  55. screen->hwdata->allocated=0;
  56. screen->hwdata->mask=NULL;
  57. screen->hwdata->bmap=SDL_RastPort->BitMap;
  58. screen->hwdata->videodata=this;
  59. if(!(screen->hwdata->lock=LockBitMapTags(screen->hwdata->bmap,
  60. LBMI_BASEADDRESS,(ULONG)&screen->pixels,
  61. LBMI_BYTESPERROW,(ULONG)&pitch,TAG_DONE))) {
  62. free(screen->hwdata);
  63. screen->hwdata=NULL;
  64. return -1;
  65. }
  66. else {
  67. UnLockBitMap(screen->hwdata->lock);
  68. screen->hwdata->lock=NULL;
  69. }
  70. screen->pitch=pitch;
  71. this->UpdateRects = CGX_FakeUpdate;
  72. D(bug("Accel video image configured (%lx, pitch %ld).n",screen->pixels,screen->pitch));
  73. return 0;
  74. }
  75. screen->pixels = malloc(screen->h*screen->pitch);
  76. if ( screen->pixels == NULL ) {
  77. SDL_OutOfMemory();
  78. return(-1);
  79. }
  80. SDL_Ximage=screen->pixels;
  81. if ( SDL_Ximage == NULL ) {
  82. SDL_SetError("Couldn't create XImage");
  83. return(-1);
  84. }
  85. this->UpdateRects = CGX_NormalUpdate;
  86. return(0);
  87. }
  88. void CGX_DestroyImage(_THIS, SDL_Surface *screen)
  89. {
  90. if ( SDL_Ximage ) {
  91. free(SDL_Ximage);
  92. SDL_Ximage = NULL;
  93. }
  94. if ( screen ) {
  95. screen->pixels = NULL;
  96. if(screen->hwdata) {
  97. free(screen->hwdata);
  98. screen->hwdata=NULL;
  99. }
  100. }
  101. }
  102. /* This is a hack to see whether this system has more than 1 CPU */
  103. static int num_CPU(void)
  104. {
  105. return 1;
  106. }
  107. int CGX_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags)
  108. {
  109. int retval;
  110. D(bug("Calling ResizeImage()n"));
  111. CGX_DestroyImage(this, screen);
  112. if ( flags & SDL_OPENGL ) {  /* No image when using GL */
  113.          retval = 0;
  114. } else {
  115. retval = CGX_SetupImage(this, screen);
  116. /* We support asynchronous blitting on the display */
  117. if ( flags & SDL_ASYNCBLIT ) {
  118. if ( num_CPU() > 1 ) {
  119. screen->flags |= SDL_ASYNCBLIT;
  120. }
  121. }
  122. }
  123. return(retval);
  124. }
  125. int CGX_AllocHWSurface(_THIS, SDL_Surface *surface)
  126. {
  127. D(bug("Alloc HW surface...%ld x %ld x %ld!n",surface->w,surface->h,this->hidden->depth));
  128. if(surface==SDL_VideoSurface)
  129. {
  130. D(bug("Allocation skipped, it's system one!n"));
  131. return 0;
  132. }
  133. if(!surface->hwdata)
  134. {
  135. if(!(surface->hwdata=malloc(sizeof(struct private_hwdata))))
  136. return -1;
  137. }
  138. surface->hwdata->mask=NULL;
  139. surface->hwdata->lock=NULL;
  140. surface->hwdata->videodata=this;
  141. surface->hwdata->allocated=0;
  142. if(surface->hwdata->bmap=AllocBitMap(surface->w,surface->h,this->hidden->depth,BMF_MINPLANES,SDL_Display->RastPort.BitMap))
  143. {
  144. surface->hwdata->allocated=1;
  145. surface->flags|=SDL_HWSURFACE;
  146. D(bug("...OKn"));
  147. return 0;
  148. }
  149. else
  150. {
  151. free(surface->hwdata);
  152. surface->hwdata=NULL;
  153. }
  154. return(-1);
  155. }
  156. void CGX_FreeHWSurface(_THIS, SDL_Surface *surface)
  157. {
  158. if(surface && surface!=SDL_VideoSurface && surface->hwdata)
  159. {
  160. D(bug("Free hw surface.n"));
  161. if(surface->hwdata->mask)
  162. free(surface->hwdata->mask);
  163. if(surface->hwdata->bmap&&surface->hwdata->allocated)
  164. FreeBitMap(surface->hwdata->bmap);
  165. free(surface->hwdata);
  166. surface->hwdata=NULL;
  167. surface->pixels=NULL;
  168. D(bug("end of free hw surfacen"));
  169. }
  170. return;
  171. }
  172. int CGX_LockHWSurface(_THIS, SDL_Surface *surface)
  173. {
  174. if (surface->hwdata)
  175. {
  176. // D(bug("Locking a bitmap...n"));
  177. if(!surface->hwdata->lock)
  178. {
  179. Uint32 pitch;
  180. if(!(surface->hwdata->lock=LockBitMapTags(surface->hwdata->bmap,
  181. LBMI_BASEADDRESS,(ULONG)&surface->pixels,
  182. LBMI_BYTESPERROW,(ULONG)&pitch,TAG_DONE)))
  183. return -1;
  184. // surface->pitch e' a 16bit!
  185. surface->pitch=pitch;
  186. if(!currently_fullscreen&&surface==SDL_VideoSurface)
  187. surface->pixels=((char *)surface->pixels)+(surface->pitch*(SDL_Window->BorderTop+SDL_Window->TopEdge)+
  188. surface->format->BytesPerPixel*(SDL_Window->BorderLeft+SDL_Window->LeftEdge));
  189. }
  190. D(else bug("Already locked!!!n"));
  191. }
  192. return(0);
  193. }
  194. void CGX_UnlockHWSurface(_THIS, SDL_Surface *surface)
  195. {
  196. if(surface->hwdata && surface->hwdata->lock)
  197. {
  198. UnLockBitMap(surface->hwdata->lock);
  199. surface->hwdata->lock=NULL;
  200. // surface->pixels=NULL;
  201. }
  202. }
  203. int CGX_FlipHWSurface(_THIS, SDL_Surface *surface)
  204. {
  205. static int current=0;
  206. if(this->hidden->dbuffer)
  207. {
  208. if(!SafeChange)
  209. {
  210. Wait(disp_sigbit);
  211. // Non faccio nulla, vuoto solo la porta
  212. while(GetMsg(dispport)!=NULL) 
  213. ;
  214. SafeChange=TRUE;
  215. }
  216. if(ChangeScreenBuffer(SDL_Display,this->hidden->SB[current^1]))
  217. {
  218. surface->hwdata->bmap=SDL_RastPort->BitMap=this->hidden->SB[current]->sb_BitMap;
  219. SafeChange=FALSE;
  220. SafeDisp=FALSE;
  221. current^=1;
  222. }
  223. if(!SafeDisp)
  224. {
  225. Wait(safe_sigbit);
  226. while(GetMsg(safeport)!=NULL) 
  227. ;
  228. SafeDisp=TRUE;
  229. }
  230. }
  231. return(0);
  232. }
  233. /* Byte-swap the pixels in the display image */
  234. static void CGX_SwapAllPixels(SDL_Surface *screen)
  235. {
  236. int x, y;
  237. switch (screen->format->BytesPerPixel) {
  238.     case 2: {
  239. Uint16 *spot;
  240. for ( y=0; y<screen->h; ++y ) {
  241. spot = (Uint16 *) ((Uint8 *)screen->pixels +
  242. y * screen->pitch);
  243. for ( x=0; x<screen->w; ++x, ++spot ) {
  244. *spot = SDL_Swap16(*spot);
  245. }
  246. }
  247.     }
  248.     break;
  249.     case 4: {
  250. Uint32 *spot;
  251. for ( y=0; y<screen->h; ++y ) {
  252. spot = (Uint32 *) ((Uint8 *)screen->pixels +
  253. y * screen->pitch);
  254. for ( x=0; x<screen->w; ++x, ++spot ) {
  255. *spot = SDL_Swap32(*spot);
  256. }
  257. }
  258.     }
  259.     break;
  260.     default:
  261. /* should never get here */
  262. break;
  263. }
  264. }
  265. static void CGX_SwapPixels(SDL_Surface *screen, int numrects, SDL_Rect *rects)
  266. {
  267. int i;
  268. int x, minx, maxx;
  269. int y, miny, maxy;
  270. switch (screen->format->BytesPerPixel) {
  271.     case 2: {
  272. Uint16 *spot;
  273. for ( i=0; i<numrects; ++i ) {
  274. minx = rects[i].x;
  275. maxx = rects[i].x+rects[i].w;
  276. miny = rects[i].y;
  277. maxy = rects[i].y+rects[i].h;
  278. for ( y=miny; y<maxy; ++y ) {
  279. spot = (Uint16 *) ((Uint8 *)screen->pixels +
  280. y * screen->pitch + minx * 2);
  281. for ( x=minx; x<maxx; ++x, ++spot ) {
  282. *spot = SDL_Swap16(*spot);
  283. }
  284. }
  285. }
  286.     }
  287.     break;
  288.     case 4: {
  289. Uint32 *spot;
  290. for ( i=0; i<numrects; ++i ) {
  291. minx = rects[i].x;
  292. maxx = rects[i].x+rects[i].w;
  293. miny = rects[i].y;
  294. maxy = rects[i].y+rects[i].h;
  295. for ( y=miny; y<maxy; ++y ) {
  296. spot = (Uint32 *) ((Uint8 *)screen->pixels +
  297. y * screen->pitch + minx * 4);
  298. for ( x=minx; x<maxx; ++x, ++spot ) {
  299. *spot = SDL_Swap32(*spot);
  300. }
  301. }
  302. }
  303.     }
  304.     break;
  305.     default:
  306. /* should never get here */
  307. break;
  308. }
  309. }
  310. #ifdef __SASC
  311. #define USE_WPA WritePixelArray
  312. #else
  313. void USE_WPA(char *a,int b,int c,int d, struct RastPort *e,int f,int g, int h, int i, Uint32 l)
  314. {
  315. WritePixelArray(a,b,c,d,e,f,g,h,i,l);
  316. }
  317. #endif
  318. static void CGX_FakeUpdate(_THIS, int numrects, SDL_Rect *rects)
  319. {
  320. }
  321. static void CGX_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
  322. {
  323. int i,format,customroutine=0;
  324. #ifndef USE_CGX_WRITELUTPIXEL
  325. int bpp;
  326. #endif
  327. if(this->hidden->same_format && !use_picasso96)
  328. {
  329. format=RECTFMT_RAW;
  330. }
  331. else switch(this->screen->format->BytesPerPixel)
  332. {
  333. case 4:
  334. format=RECTFMT_RGBA;
  335. break;
  336. case 3:
  337. format=RECTFMT_RGB;
  338. break;
  339. case 2:
  340. customroutine=1;
  341. break;
  342. case 1:
  343. // D(bug("soft depth: 8 hardbpp: %ldn",this->hidden->depth));
  344. if(this->hidden->depth>8)
  345. {
  346. #ifndef USE_CGX_WRITELUTPIXEL
  347. if(this->hidden->depth>32)
  348. customroutine=4;
  349. else if(this->hidden->depth>16)
  350. {
  351. bpp=this->hidden->BytesPerPixel; // That one is the only one that needs bpp
  352. customroutine=2; // The slow one!
  353. }
  354. else
  355. customroutine=3;
  356. #else
  357. customroutine=2;
  358. #endif
  359. // format=RECTFMT_LUT8;   Vecchia funzione x usare la WritePixelArray.
  360. }
  361. else
  362. customroutine=1;
  363. break;
  364. default:
  365. D(bug("Unable to blit this surface!n"));
  366. return;
  367. }
  368. /* Check for endian-swapped X server, swap if necessary (VERY slow!) */
  369. if ( swap_pixels &&
  370.      ((this->screen->format->BytesPerPixel%2) == 0) ) {
  371. D(bug("Software Swapping! SLOOOW!n"));
  372. CGX_SwapPixels(this->screen, numrects, rects);
  373. for ( i=0; i<numrects; ++i ) {
  374. if ( ! rects[i].w ) { /* Clipped? */
  375. continue;
  376. }
  377. USE_WPA(this->screen->pixels,rects[i].x, rects[i].y,this->screen->pitch,
  378. SDL_RastPort,SDL_Window->BorderLeft+rects[i].x,SDL_Window->BorderTop+rects[i].y,
  379. rects[i].w,rects[i].h,format);
  380. }
  381. CGX_SwapPixels(this->screen, numrects, rects);
  382. }
  383. else if (customroutine==2)
  384. {
  385. #ifdef USE_CGX_WRITELUTPIXEL
  386. for ( i=0; i<numrects; ++i ) {
  387. if ( ! rects[i].w ) { /* Clipped? */
  388. continue;
  389. }
  390. WLUT(this->screen->pixels,rects[i].x, rects[i].y,this->screen->pitch,
  391. SDL_RastPort,SDL_XPixels,SDL_Window->BorderLeft+rects[i].x,SDL_Window->BorderTop+rects[i].y,
  392. rects[i].w,rects[i].h,CTABFMT_XRGB8);
  393. }
  394. #else
  395. unsigned char *bm_address;
  396. Uint32 destpitch;
  397. APTR handle;
  398. if(handle=LockBitMapTags(SDL_RastPort->BitMap,LBMI_BASEADDRESS,&bm_address,
  399. LBMI_BYTESPERROW,&destpitch,TAG_DONE))
  400. {
  401. int srcwidth;
  402. unsigned char *destbase;
  403. register int j,k,t;
  404. register unsigned char *mask,*dst;
  405. register unsigned char *src,*dest;
  406. // Aggiungo il bordo della finestra se sono fullscreen.
  407. if(currently_fullscreen)
  408. destbase=bm_address;
  409. else
  410. destbase=bm_address+(SDL_Window->TopEdge+SDL_Window->BorderTop)*destpitch+(SDL_Window->BorderLeft+SDL_Window->LeftEdge)*this->hidden->BytesPerPixel;
  411. for ( i=0; i<numrects; ++i ) 
  412. {
  413. srcwidth=rects[i].w;
  414. if ( !srcwidth ) { /* Clipped? */
  415. continue;
  416. }
  417. dest=destbase+rects[i].x*this->hidden->BytesPerPixel;
  418. dest+=(rects[i].y*destpitch);
  419. src=((char *)(this->screen->pixels))+rects[i].x;
  420. src+=(rects[i].y*this->screen->pitch);
  421. for(j=rects[i].h;j;--j)
  422. {
  423. dst=dest;
  424. // SLOW routine, used for 8->24 bit mapping
  425. for(k=0;k<srcwidth;k++)
  426. {
  427. mask=(unsigned char *)(&SDL_XPixels[src[k]]);
  428. for(t=0;t<bpp;t++)
  429. {
  430. dst[t]=mask[t];
  431. }
  432. dst+=bpp;
  433. }
  434. src+=this->screen->pitch;
  435. dest+=destpitch;
  436. }
  437. }
  438. UnLockBitMap(handle);
  439. }
  440. }
  441. else if (customroutine==3)
  442. {
  443. unsigned char *bm_address;
  444. Uint32 destpitch;
  445. APTR handle;
  446. if(handle=LockBitMapTags(SDL_RastPort->BitMap,LBMI_BASEADDRESS,&bm_address,
  447. LBMI_BYTESPERROW,&destpitch,TAG_DONE))
  448. {
  449. int srcwidth;
  450. unsigned char *destbase;
  451. register int j,k;
  452. register unsigned char *src,*dest;
  453. register Uint16 *destl,*srcl;
  454. if(currently_fullscreen)
  455. destbase=bm_address;
  456. else
  457. destbase=bm_address+(SDL_Window->TopEdge+SDL_Window->BorderTop)*destpitch+(SDL_Window->BorderLeft+SDL_Window->LeftEdge)*this->hidden->BytesPerPixel;
  458. for ( i=0; i<numrects; ++i ) 
  459. {
  460. srcwidth=rects[i].w;
  461. if ( !srcwidth ) { /* Clipped? */
  462. continue;
  463. }
  464. dest=destbase+rects[i].x*this->hidden->BytesPerPixel;
  465. dest+=(rects[i].y*destpitch);
  466. src=((char *)(this->screen->pixels))+rects[i].x;
  467. src+=(rects[i].y*this->screen->pitch);
  468. // This is the fast, well not too slow, remapping code for 16bit displays
  469. for(j=rects[i].h;j;--j)
  470. {
  471. destl=(Uint16 *)dest;
  472. for(k=0;k<srcwidth;k++)
  473. {
  474. srcl=(Uint16 *)&SDL_XPixels[src[k]];
  475. *destl=*srcl;
  476. destl++;
  477. }
  478. src+=this->screen->pitch;
  479. dest+=destpitch;
  480. }
  481. }
  482. UnLockBitMap(handle);
  483. }
  484. }
  485. else if (customroutine==4)
  486. {
  487. unsigned char *bm_address;
  488. Uint32 destpitch;
  489. APTR handle;
  490. if(handle=LockBitMapTags(SDL_RastPort->BitMap,LBMI_BASEADDRESS,&bm_address,
  491. LBMI_BYTESPERROW,&destpitch,TAG_DONE))
  492. {
  493. int srcwidth;
  494. unsigned char *destbase;
  495. register int j,k;
  496. register unsigned char *src,*dest;
  497. register Uint32 *destl,*srcl;
  498. if(currently_fullscreen)
  499. destbase=bm_address;
  500. else
  501. destbase=bm_address+(SDL_Window->TopEdge+SDL_Window->BorderTop)*destpitch+(SDL_Window->BorderLeft+SDL_Window->LeftEdge)*this->hidden->BytesPerPixel;
  502. for ( i=0; i<numrects; ++i ) 
  503. {
  504. srcwidth=rects[i].w;
  505. if ( !srcwidth ) { /* Clipped? */
  506. continue;
  507. }
  508. dest=destbase+rects[i].x*this->hidden->BytesPerPixel;
  509. dest+=(rects[i].y*destpitch);
  510. src=((char *)(this->screen->pixels))+rects[i].x;
  511. src+=(rects[i].y*this->screen->pitch);
  512. // This is the fast, well not too slow, remapping code for 32bit displays
  513. for(j=rects[i].h;j;--j)
  514. {
  515. destl=(Uint32 *)dest;
  516. for(k=0;k<srcwidth;k++)
  517. {
  518. srcl=(Uint32 *)&SDL_XPixels[src[k]];
  519. *destl=*srcl;
  520. destl++;
  521. }
  522. src+=this->screen->pitch;
  523. dest+=destpitch;
  524. }
  525. }
  526. UnLockBitMap(handle);
  527. }
  528. #endif
  529. }
  530. else if(customroutine)
  531. {
  532. unsigned char *bm_address;
  533. Uint32 destpitch;
  534. APTR handle;
  535. // D(bug("Using customroutine!n"));
  536. if(handle=LockBitMapTags(SDL_RastPort->BitMap,LBMI_BASEADDRESS,(ULONG)&bm_address,
  537. LBMI_BYTESPERROW,(ULONG)&destpitch,TAG_DONE))
  538. {
  539. unsigned char *destbase;
  540. register int j,srcwidth;
  541. register unsigned char *src,*dest;
  542. // Aggiungo il bordo della finestra se sono fullscreen.
  543. if(currently_fullscreen)
  544. destbase=bm_address;
  545. else
  546. destbase=bm_address+(SDL_Window->TopEdge+SDL_Window->BorderTop)*destpitch+(SDL_Window->BorderLeft+SDL_Window->LeftEdge)*this->screen->format->BytesPerPixel;
  547. for ( i=0; i<numrects; ++i ) 
  548. {
  549. srcwidth=rects[i].w;
  550. if ( !srcwidth ) { /* Clipped? */
  551. continue;
  552. }
  553. dest=destbase+rects[i].x*this->screen->format->BytesPerPixel;
  554. dest+=(rects[i].y*destpitch);
  555. src=((char *)(this->screen->pixels))+rects[i].x*this->screen->format->BytesPerPixel;
  556. src+=(rects[i].y*this->screen->pitch);
  557. srcwidth*=this->screen->format->BytesPerPixel;
  558. // D(bug("Rects: %ld,%ld %ld,%ld Src:%lx Dest:%lxn",rects[i].x,rects[i].y,rects[i].w,rects[i].h,src,dest));
  559. for(j=rects[i].h;j;--j)
  560. {
  561. memcpy(dest,src,srcwidth);
  562. src+=this->screen->pitch;
  563. dest+=destpitch;
  564. }
  565. }
  566. UnLockBitMap(handle);
  567. // D(bug("Rectblit addr: %lx pitch: %ld rects:%ld srcptr: %lx srcpitch: %ldn",bm_address,destpitch,numrects,this->screen->pixels,this->screen->pitch));
  568. }
  569. }
  570. else
  571. {
  572. for ( i=0; i<numrects; ++i ) {
  573. if ( ! rects[i].w ) { /* Clipped? */
  574. continue;
  575. }
  576. USE_WPA(this->screen->pixels,rects[i].x, rects[i].y,this->screen->pitch,
  577. SDL_RastPort,SDL_Window->BorderLeft+rects[i].x,SDL_Window->BorderTop+rects[i].y,
  578. rects[i].w,rects[i].h,format);
  579. }
  580. }
  581. }
  582. void CGX_RefreshDisplay(_THIS)
  583. {
  584. int format,customroutine=0;
  585. #ifndef USE_CGX_WRITELUTPIXEL
  586. int bpp;
  587. #endif
  588. /* Don't refresh a display that doesn't have an image (like GL) */
  589. if ( ! SDL_Ximage ) {
  590. return;
  591. }
  592. if(this->hidden->same_format && !use_picasso96)
  593. {
  594. format=RECTFMT_RAW;
  595. }
  596. else switch(this->screen->format->BytesPerPixel)
  597. {
  598. case 4:
  599. format=RECTFMT_RGBA;
  600. break;
  601. case 3:
  602. format=RECTFMT_RGB;
  603. break;
  604. case 2:
  605. customroutine=1;
  606. break;
  607. case 1:
  608. // D(bug("soft depth: 8 hardbpp: %ldn",this->hidden->depth));
  609. if(this->hidden->depth>8)
  610. {
  611. #ifndef USE_CGX_WRITELUTPIXEL
  612. if(this->hidden->depth>32)
  613. customroutine=4;
  614. else if(this->hidden->depth>16)
  615. {
  616. bpp=this->hidden->BytesPerPixel; // That one is the only one that needs bpp
  617. customroutine=2; // The slow one!
  618. }
  619. else
  620. customroutine=3;
  621. #else
  622. customroutine=2;
  623. #endif
  624. // format=RECTFMT_LUT8;
  625. }
  626. else
  627. customroutine=1;
  628. break;
  629. }
  630. /* Check for endian-swapped X server, swap if necessary */
  631. if ( swap_pixels &&
  632.      ((this->screen->format->BytesPerPixel%2) == 0) ) {
  633. CGX_SwapAllPixels(this->screen);
  634. USE_WPA(this->screen->pixels,0,0,this->screen->pitch,
  635. SDL_RastPort,SDL_Window->BorderLeft,SDL_Window->BorderTop,
  636. this->screen->w,this->screen->h,format);
  637. CGX_SwapAllPixels(this->screen);
  638. }
  639. else if (customroutine==2)
  640. {
  641. #ifdef USE_CGX_WRITELUTPIXEL
  642. WLUT(this->screen->pixels,0,0,this->screen->pitch,
  643. SDL_RastPort,SDL_XPixels,SDL_Window->BorderLeft,SDL_Window->BorderTop,
  644. this->screen->w,this->screen->h,CTABFMT_XRGB8);
  645. #else
  646. unsigned char *bm_address;
  647. Uint32 destpitch;
  648. APTR handle;
  649. if(handle=LockBitMapTags(SDL_RastPort->BitMap,LBMI_BASEADDRESS,(ULONG)&bm_address,
  650. LBMI_BYTESPERROW,(ULONG)&destpitch,TAG_DONE))
  651. {
  652. register int j,k,t;
  653. register unsigned char *mask,*dst;
  654. register unsigned char *src,*dest;
  655. // Aggiungo il bordo della finestra se sono fullscreen.
  656. if(!currently_fullscreen)
  657. dest=bm_address+(SDL_Window->TopEdge+SDL_Window->BorderTop)*destpitch+(SDL_Window->BorderLeft+SDL_Window->LeftEdge)*this->hidden->BytesPerPixel;
  658. else
  659. dest=bm_address;
  660. src=this->screen->pixels;
  661. for(j=this->screen->h;j;--j)
  662. {
  663. dst=dest;
  664. // SLOW routine, used for 8->24 bit mapping
  665. for(k=0;k<this->screen->w;k++)
  666. {
  667. mask=(unsigned char *)(&SDL_XPixels[src[k]]);
  668. for(t=0;t<bpp;t++)
  669. {
  670. dst[t]=mask[t];
  671. }
  672. dst+=bpp;
  673. }
  674. src+=this->screen->pitch;
  675. dest+=destpitch;
  676. }
  677. UnLockBitMap(handle);
  678. }
  679. }
  680. else if (customroutine==3)
  681. {
  682. unsigned char *bm_address;
  683. Uint32 destpitch;
  684. APTR handle;
  685. if(handle=LockBitMapTags(SDL_RastPort->BitMap,LBMI_BASEADDRESS,(ULONG)&bm_address,
  686. LBMI_BYTESPERROW,(ULONG)&destpitch,TAG_DONE))
  687. {
  688. register int j,k;
  689. register unsigned char *src,*dest;
  690. register Uint16 *destl,*srcl;
  691. if(!currently_fullscreen)
  692. dest=bm_address+(SDL_Window->TopEdge+SDL_Window->BorderTop)*destpitch+(SDL_Window->BorderLeft+SDL_Window->LeftEdge)*this->hidden->BytesPerPixel;
  693. else
  694. dest=bm_address;
  695. src=this->screen->pixels;
  696. // This is the fast, well not too slow, remapping code for 16bit displays
  697. for(j=this->screen->h;j;--j)
  698. {
  699. destl=(Uint16 *)dest;
  700. for(k=0;k<this->screen->w;k++)
  701. {
  702. srcl=(Uint16 *)&SDL_XPixels[src[k]];
  703. *destl=*srcl;
  704. destl++;
  705. }
  706. src+=this->screen->pitch;
  707. dest+=destpitch;
  708. }
  709. UnLockBitMap(handle);
  710. }
  711. }
  712. else if (customroutine==4)
  713. {
  714. unsigned char *bm_address;
  715. Uint32 destpitch;
  716. APTR handle;
  717. if(handle=LockBitMapTags(SDL_RastPort->BitMap,LBMI_BASEADDRESS,(ULONG)&bm_address,
  718. LBMI_BYTESPERROW,(ULONG)&destpitch,TAG_DONE))
  719. {
  720. register int j,k;
  721. register unsigned char *src,*dest;
  722. register Uint32 *destl,*srcl;
  723. if(!currently_fullscreen)
  724. dest=bm_address+(SDL_Window->TopEdge+SDL_Window->BorderTop)*destpitch+(SDL_Window->BorderLeft+SDL_Window->LeftEdge)*this->hidden->BytesPerPixel;
  725. else
  726. dest=bm_address;
  727. src=this->screen->pixels;
  728. // This is the fast, well not too slow, remapping code for 32bit displays
  729. for(j=this->screen->h;j;--j)
  730. {
  731. destl=(Uint32 *)dest;
  732. for(k=0;k<this->screen->w;k++)
  733. {
  734. srcl=(Uint32 *)&SDL_XPixels[src[k]];
  735. *destl=*srcl;
  736. destl++;
  737. }
  738. src+=this->screen->pitch;
  739. dest+=destpitch;
  740. }
  741. UnLockBitMap(handle);
  742. }
  743. #endif
  744. }
  745. else if(customroutine)
  746. {
  747. unsigned char *bm_address;
  748. Uint32 destpitch;
  749. APTR handle;
  750. if(handle=LockBitMapTags(SDL_RastPort->BitMap,
  751. LBMI_BASEADDRESS,(ULONG)&bm_address,
  752. LBMI_BYTESPERROW,(ULONG)&destpitch,TAG_DONE))
  753. {
  754. register int j;
  755. register unsigned char *src,*dest;
  756. if(!currently_fullscreen)
  757. dest=bm_address+(SDL_Window->TopEdge+SDL_Window->BorderTop)*destpitch+(SDL_Window->BorderLeft+SDL_Window->LeftEdge)*this->screen->format->BytesPerPixel;
  758. else
  759. dest=bm_address;
  760. src=this->screen->pixels;
  761. // D(bug("addr: %lx pitch: %ld src:%lx srcpitch: %ldn",dest,destpitch,this->screen->pixels,this->screen->pitch));
  762. if(this->screen->pitch==destpitch)
  763. {
  764. memcpy(dest,src,this->screen->pitch*this->screen->h);
  765. }
  766. else
  767. {
  768. for(j=this->screen->h;j;--j)
  769. {
  770. memcpy(dest,src,this->screen->pitch);
  771. src+=this->screen->pitch;
  772. dest+=destpitch;
  773. }
  774. }
  775. UnLockBitMap(handle);
  776. }
  777. }
  778. else
  779. {
  780. USE_WPA(this->screen->pixels,0,0,this->screen->pitch,
  781. SDL_RastPort,SDL_Window->BorderLeft,SDL_Window->BorderTop,
  782. this->screen->w,this->screen->h,format);
  783. }
  784. }