home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / ppc / ppcRot.c < prev    next >
C/C++ Source or Header  |  1989-11-07  |  11KB  |  421 lines

  1. /*
  2.  * Copyright IBM Corporation 1987,1988,1989
  3.  *
  4.  * All Rights Reserved
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted,
  8.  * provided that the above copyright notice appear in all copies and that 
  9.  * both that copyright notice and this permission notice appear in
  10.  * supporting documentation, and that the name of IBM not be
  11.  * used in advertising or publicity pertaining to distribution of the
  12.  * software without specific, written prior permission.
  13.  *
  14.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  16.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  17.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  18.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  19.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  20.  * SOFTWARE.
  21.  *
  22. */
  23.  
  24. /* ROTATE  and CLIP Z8 PixMaps
  25.  * Demands that pixmaps be Z oriented, 8 bits per pixel
  26.  * Note that depth doesn't matter ; only bits per pixel.
  27.  *
  28.  */
  29.  
  30. /* Seems that for depth
  31.  * 1 non-frame-buffer displays, this is one of the last ppc things to prevent
  32.  * the ppc from fully supporting depth 1. 
  33.  * Anyway, Code added for 1-bit-per-pixel maps since mfb doesn't quite
  34.  * make it. 
  35.  *
  36.  */
  37.  
  38. #include "X.h"
  39. #include "misc.h"
  40. #include "pixmapstr.h"
  41.  
  42. #include "OScompiler.h"
  43. #include "ibmTrace.h"
  44.  
  45. extern int ppcDepthOK() ;
  46. extern PixmapPtr ppcCreatePixmap() ;
  47.  
  48. void
  49. ppcRotZ8mapUp( pSource, pDest, shift )
  50. register PixmapPtr pSource ;
  51. register PixmapPtr pDest ;
  52. register int shift ;
  53. {
  54. register char *s, *d ;
  55. register int i, j, w, h ;
  56.  
  57. if ( !ppcDepthOK( pSource, pSource->drawable.depth ) ) {
  58.     ErrorF( "ppcRotZ8mapUp: Source depth not valid\n" ) ;
  59.     return ;
  60. }
  61. if ( !ppcDepthOK( pDest, pDest->drawable.depth ) ) {
  62.     ErrorF( "ppcRotZ8mapUp: Destination depth not valid\n" ) ;
  63.     return ;
  64. }
  65. if ( ( pDest->drawable.width  != pSource->drawable.width )
  66.   || ( pDest->drawable.height != pSource->drawable.height ) ) {
  67.     ErrorF( "ppcRotZ8mapUp: Pixmaps different size\n" ) ;
  68.     return ;
  69. }
  70.  
  71. w = pDest->devKind ;
  72. h = pDest->drawable.height ;
  73.  
  74. shift %= h ;
  75. if ( shift < 0 )
  76.     shift += h ; /* compilers don't REALLY do modulo */
  77.  
  78. s = (char *) pSource->devPrivate.ptr ;
  79. d = (char *) pDest->devPrivate.ptr ;
  80.  
  81. for ( i = shift, j = 0 ; i < h ; i++, j++ )
  82.     MOVE( &(s[ i * w ]), &d[ j * w ], w ) ; /* move Ith line up */
  83. for ( i = 0 ; i < shift ; i++, j++ )
  84.     MOVE( &(s[ i * w ]), &d[ j * w ], w ) ; /* move top rows down */
  85.  
  86. return ;
  87. }
  88.  
  89. void
  90. ppcRotZ8mapLeft( pSource, pDest, shift )
  91. register PixmapPtr pSource ;
  92. register PixmapPtr pDest ;
  93. register int shift ;
  94. {
  95. register char *s, *d ;
  96. register int i, j, w, h ;
  97.  
  98. if ( !ppcDepthOK( pSource, pSource->drawable.depth ) ) {
  99.     ErrorF( "ppcRotZ8mapLeft: Source depth not valid\n" ) ;
  100.     return ;
  101. }
  102. if ( !ppcDepthOK( pDest, pDest->drawable.depth ) ) {
  103.     ErrorF( "ppcRotZ8mapLeft: Destination depth not valid\n" ) ;
  104.     return ;
  105. }
  106. if ( ( ( w = pDest->drawable.width ) != pSource->drawable.width )
  107.   || ( ( h = pDest->drawable.height ) != pSource->drawable.height ) ) {
  108.     ErrorF( "ppcRotZ8mapLeft: Pixmaps different size\n" ) ;
  109.     return ;
  110. }
  111.  
  112. if ( ( shift %= w ) < 0 )
  113.     shift += w ; /* compilers don't REALLY do modulo */
  114.  
  115. s = (char *) pSource->devPrivate.ptr ;
  116. d = (char *) pDest->devPrivate.ptr ;
  117. while ( h-- ) {
  118.     for ( i = shift, j = 0 ; i < w ; i++, j++ )
  119.         d[j] = s[i] ;
  120.     for ( i = 0 ; i < shift ; i++, j++ )
  121.         d[j] = s[i] ;
  122.     d += pDest->devKind ;    /* next line */
  123.     s += pSource->devKind ;    /* next line */
  124. }
  125.  
  126. return ;
  127. }
  128.  
  129. void
  130. ppcClipZ8Pixmap( pSource, pDest )
  131. register PixmapPtr pSource, pDest ;
  132. {
  133. register unsigned char        *dest, *source ;
  134. register int            dh, bytesperSline, bytesperDline, j ;
  135. int                dw ;
  136.  
  137. if ( !ppcDepthOK( pSource, pSource->drawable.depth ) ) {
  138.     ErrorF( "ppcClipZ8Pixmap: Source depth not valid\n" ) ;
  139.     return ;
  140. }
  141. if ( !ppcDepthOK( pDest, pDest->drawable.depth ) ) {
  142.     ErrorF( "ppcClipZ8Pixmap: Destination depth not valid\n" ) ;
  143.     return ;
  144. }
  145. if ( ( dw = pDest->drawable.width ) > pSource->drawable.width ) {
  146.     ErrorF( "ppcClipZ8Pixmap: Destination witdh > src width\n" ) ;
  147.     return ;
  148. }
  149. if ( ( dh = pDest->drawable.height ) > pSource->drawable.height ) {
  150.     ErrorF( "ppcClipZ8Pixmap: Destination height > src height\n" ) ;
  151.     return ;
  152. }
  153.  
  154. bytesperSline = pSource->devKind - dw ;
  155. bytesperDline = pDest->devKind - dw ;
  156.  
  157. for ( dest = (unsigned char *) pDest->devPrivate.ptr,
  158.       source = (unsigned char *) pSource->devPrivate.ptr ;
  159.       dh-- ;
  160.       source += bytesperSline, dest += bytesperDline )
  161.     for ( j = dw ; j-- ; )
  162.         *dest++ = *source++ ;
  163.  
  164. return ;
  165. }
  166.  
  167. PixmapPtr
  168. ppcClipBitmap( pStipple, w, h )
  169. PixmapPtr pStipple ;
  170. int w, h ;
  171. {
  172.     register unsigned char *src, *dst ;
  173.     register int bytesperline ;
  174.     PixmapPtr pNewStipple ;
  175.  
  176.     pNewStipple = ppcCreatePixmap( pStipple->drawable.pScreen,
  177.                     w, h, 1 ) ;
  178.     if (pNewStipple) {
  179.         w = MIN( w, pStipple->drawable.width ) ;
  180.         bytesperline = ((w+7)/8) ;
  181.         h = MIN( h, pStipple->drawable.height ) ;
  182.         src = (unsigned char *) pStipple->devPrivate.ptr ;
  183.         dst = (unsigned char *) pNewStipple->devPrivate.ptr ;
  184.         while (h--) {
  185.             MOVE(src,dst,bytesperline) ;
  186.             src += pStipple->devKind ;
  187.             dst += pNewStipple->devKind ;
  188.         }
  189.     }
  190.     return pNewStipple ;
  191. }
  192.  
  193. void
  194. ppcRotBitmapUp( pSource, pDest, shift )
  195. register PixmapPtr pSource ;
  196. register PixmapPtr pDest ;
  197. register int shift ;
  198. {
  199. register char *s, *d ;
  200. register int i, j, w, h ;
  201.  
  202. if ( pSource->drawable.depth != 1 ) {
  203.     ErrorF( "ppcRotBitmapUp: source depth of %d != 1! Abandon ship!\n",
  204.         pSource->drawable.depth ) ;
  205.     return ;
  206. }
  207. if ( pDest->drawable.depth != 1 ) {
  208.     ErrorF( "ppcRotBitmapUp: dest depth of %d != 1! Abandon ship!\n",
  209.         pDest->drawable.depth ) ;
  210.     return ;
  211. }
  212. if ( ( pDest->drawable.width != pSource->drawable.width )
  213.   || ( pDest->drawable.height != pSource->drawable.height ) ) {
  214.     ErrorF( "ppcRotBitmapUp: Pixmaps different size\n" ) ;
  215.     return ;
  216. }
  217.  
  218. /* holy cow, this code is the same as 8 bits-per-pixel.  *sigh* */
  219.  
  220. w = pDest->devKind ;
  221. h = pDest->drawable.height ;
  222.  
  223. shift %= h ;
  224. if ( shift < 0 )
  225.     shift += h ; /* compilers don't REALLY do modulo */
  226.  
  227. s = (char *) pSource->devPrivate.ptr ;
  228. d = (char *) pDest->devPrivate.ptr ;
  229.  
  230. for ( i = shift, j = 0 ; i < h ; i++, j++ )
  231.     MOVE( &(s[ i * w ]), &d[ j * w ], w ) ; /* move Ith line up */
  232. for ( i = 0 ; i < shift ; i++, j++ )
  233.     MOVE( &(s[ i * w ]), &d[ j * w ], w ) ; /* move top rows down */
  234.  
  235. return ;
  236. }
  237.  
  238. void
  239. ppcRotBitmapLeft( pSource, pDest, shift )
  240. register PixmapPtr pSource ;
  241. register PixmapPtr pDest ;
  242. register int shift ;
  243. {
  244. register unsigned long *src, *dst ;
  245. register unsigned long leftpart, p1mask, p2mask ;
  246. register int perbyte ;
  247. register int perlong ;
  248. int w,h, sx, dx ;
  249. int numBytesOnRight, scanline, bytestodo, wholebytes ;
  250. int longstodo, wholelongs ;
  251. int srcLongsPerScanline, dstLongsPerScanline ;
  252. unsigned long  perlongR, lastperlongR, lastlongmask, p1lastmask, p2lastmask ;
  253.  
  254. if ( ( ( w = pDest->drawable.width ) != pSource->drawable.width )
  255.   || ( ( h = pDest->drawable.height ) != pSource->drawable.height ) ) {
  256.     ErrorF( "ppcRotBitmapLeft: Pixmaps different size\n" ) ;
  257.     return ;
  258. }
  259.  
  260. if ( ( shift %= w ) < 0 )
  261.     shift += w ; /* compilers don't REALLY do modulo */
  262.  
  263. /* OK, we've got 1 bit per pixel, padded to 32.  CAN I DO SOMETHING
  264.    INTELLIGENT?  Since it's 2AM, probably not. */
  265.  
  266. wholebytes = shift >> 3 ; /* multiples of 8 to shift */
  267. perbyte = shift & 7 ;
  268. bytestodo = (w+7) >> 3 ;
  269.  
  270. wholelongs = shift >> 5 ; /* multiples of 32 to shift */
  271. perlong = shift & 31 ;
  272. perlongR = 32 - perlong ;
  273. lastperlongR = (31 & w) - perlong ;
  274. longstodo = (w+31) >> 5 ;
  275.  
  276. /* LEAVE THIS SECTION ALONE EVEN IF YOU MASK & ROTATE BY LONGS */
  277. if ( perbyte == 0 ) {
  278.     register unsigned char *bsrc, *bdst ;
  279.     bsrc =  pSource->devPrivate.ptr ;
  280.     bdst =  pDest->devPrivate.ptr ;
  281.     numBytesOnRight = bytestodo-wholebytes ;
  282.     for ( scanline = 0 ; scanline < h ; scanline++ ) {
  283.         MOVE( &(bsrc[wholebytes]), bdst, numBytesOnRight ) ;
  284.         MOVE( bsrc, &(bdst[numBytesOnRight]), wholebytes ) ;
  285.         bsrc += pSource->devKind ;
  286.         bdst += pDest->devKind ;
  287.     }
  288.     return ;
  289. }
  290.  
  291. src =  (unsigned long *) pSource->devPrivate.ptr ;
  292. dst =  (unsigned long *) pDest->devPrivate.ptr ;
  293.  
  294. srcLongsPerScanline = pSource->devKind >> 2 ;
  295. dstLongsPerScanline = pDest->devKind >> 2 ;
  296.  
  297. p1mask = (~0 << perlong) ;
  298. p2mask = ~p1mask ;
  299. lastlongmask = ( ~0 << (32- (w&31))) ;
  300. p1lastmask = lastlongmask << perlong ;
  301. p2lastmask = (~p1lastmask) & lastlongmask ;
  302.  
  303. for ( scanline = 0 ; scanline < h ; scanline++ ) {
  304.     leftpart = (src[wholelongs] << perlong) & p1mask ;
  305.     for ( sx = wholelongs, dx=0 ; sx<longstodo-1 ; sx++, dx++ ) {
  306.         dst[dx] = leftpart | ((src[sx+1] >> perlongR) & p2mask) ;
  307.         leftpart = (src[sx+1] << perlong) & p1mask ;
  308.     }
  309.  
  310.     /* do wraparound long */
  311.     if ( dx >= srcLongsPerScanline - 1 )
  312.         dst[dx] = leftpart | ((src[0] >> lastperlongR ) & p2lastmask) ;
  313.     else
  314.         dst[dx] = leftpart | ((src[0] >> perlongR) & p2mask) ;
  315.     leftpart = (src[0] << perlong) & p1mask ;
  316.     dx++ ;
  317.  
  318.     for (sx=0 ; sx<wholelongs ; sx++, dx++) {
  319.         if (dx >= srcLongsPerScanline-1)
  320.             dst[dx] = leftpart |
  321.                 ((src[0] >> lastperlongR ) & p2lastmask) ;
  322.            else
  323.                dst[dx] = leftpart | ((src[0] >> perlongR) & p2mask) ;
  324.         leftpart = (src[sx+1] << perlong) & p1mask ;
  325.     }
  326.  
  327.     src += srcLongsPerScanline ;
  328.     dst += dstLongsPerScanline ;
  329. }
  330.  
  331. return ;
  332. }
  333.  
  334. void
  335. ppcClipZ1Pixmap( pSource, pDest )
  336. register PixmapPtr pSource, pDest ;
  337. {
  338. register unsigned char        *dest, *source ;
  339. register int            dh, bytesperSline, bytesperDline, j ;
  340. int                dw ;
  341.  
  342. if ( ( dw = pDest->drawable.width ) > pSource->drawable.width ) {
  343.     ErrorF("ppcClipZ1Pixmap: Destination witdh > src width\n") ;
  344.     return ;
  345. }
  346. if ( ( dh = pDest->drawable.height ) > pSource->drawable.height ) {
  347.     ErrorF("ppcClipZ1Pixmap: Destination height > src height\n") ;
  348.     return ;
  349. }
  350.  
  351. bytesperSline = pSource->devKind - dw ;
  352. bytesperDline = pDest->devKind - dw ;
  353.  
  354. for ( dest   = (unsigned char *) pDest->devPrivate.ptr,
  355.       source = (unsigned char *) pSource->devPrivate.ptr ;
  356.       dh-- ;
  357.       source += bytesperSline,
  358.       dest += bytesperDline )
  359.     for ( j = dw ; j-- ; )
  360.         *dest++ = *source++ ;
  361.  
  362. return ;
  363. }
  364.  
  365. #if defined(DEBUG)
  366. void
  367. ppcPrintZ8Pixmap( pMap )
  368. register PixmapPtr pMap ;
  369. {
  370. register unsigned char          *map ;
  371. register int                   j, h ;
  372.  
  373. ErrorF("width   %d\n", pMap->width) ;
  374. ErrorF("devKind %d\n", pMap->devKind) ;
  375. ErrorF("height  %d\n", pMap->height) ;
  376.  
  377. map   = (unsigned char *) pMap->devPrivate.ptr ;
  378.  
  379. for ( h = 0 ; h < pMap->height ; h++) {
  380.     for ( j = 0 ; j < pMap->devKind ; j++)
  381.     ErrorF("%2x ",map[j]) ;
  382.     ErrorF("\n") ;
  383.     map += pMap->devKind ;
  384. }
  385.  
  386. return ;
  387. }
  388. #endif
  389.  
  390. /* Following functions are added since it seems that the ppc has to solve
  391. just about everybody's problems these days */
  392.  
  393. void
  394. ppcEndWorldHunger()
  395. {
  396. ErrorF("ppcEndWorldHunger: not implemented yet.\n") ;
  397. ErrorF("\tBlame Paquin, Fortune, Shupak, Weinstein, or Gould.\n") ;
  398. return ;
  399. }
  400.  
  401. void
  402. ppcRefinanceNationalDebt()
  403. {
  404. ErrorF("ppcRefinanceNationalDebt: not implemented yet.\n") ;
  405. return ;
  406. }
  407.  
  408. void
  409. ppcEndWarForever()
  410. {
  411. ErrorF("ppcEndWarForever: not implemented yet.\n") ;
  412. return ;
  413. }
  414.  
  415. void
  416. ppcPayServerHackersWhatTheyreWorth()
  417. {
  418. ErrorF("ppcPayServerHackersWhatTheyreWorth: cannot execute.\n") ;
  419. return ;
  420. }
  421.