home *** CD-ROM | disk | FTP | other *** search
/ Monster Disc 2: The Best of 1992 / MONSTER2.ISO / prog / djgpp / cbgrx102.a01 / CONTRIB / LIBGRX / SRC / P8BITBLT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-12  |  3.6 KB  |  106 lines

  1. /**
  2.  ** P8BITBLT.C
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #include "p8.h"
  25. #include "memcopy.h"
  26. #include "gmalloc.h"
  27.  
  28. void _GrP8PixCopy(GC *dst,long daddr,GC *src,long saddr,int w,int h,int op)
  29. {
  30.     pixptr dstp = P_ADDRESS(dst,daddr);
  31.     pixptr srcp = P_ADDRESS(src,saddr);
  32.     pixptr temp;
  33.     int doff = dst->gc_lineoffset - w;
  34.     int soff = src->gc_lineoffset - w;
  35.     int bytecpy = ((int)daddr | (int)saddr | doff | soff | w) & 1;
  36.     int copywdt = w >> (bytecpy ^ 1);
  37.     int reverse = FALSE;
  38.  
  39.     if((w <= 0) || (h <= 0)) return;
  40.     op = C_OPER(op);
  41.     _ClrDir();
  42.     if((dst->gc_baseaddr == src->gc_baseaddr) && (daddr > saddr)) {
  43.         dstp += (unsigned)((h * dst->gc_lineoffset) - doff - 2 + bytecpy);
  44.         srcp += (unsigned)((h * src->gc_lineoffset) - soff - 2 + bytecpy);
  45.         doff = (-doff);
  46.         soff = (-soff);
  47.         reverse = TRUE;
  48.         _SetDir();
  49.     }
  50.     if(dst->gc_onscreen && src->gc_onscreen && _GrBigFrameBuffer) {
  51.         if(_GrCanBcopyInBlit && (op == C_SET)) {
  52.         dstp += _GrWrOnlyOffset;
  53.         srcp += _GrRdOnlyOffset;
  54.         }
  55.         else {
  56.         temp = (pixptr)_GrGetTempBuffer(w + 2);
  57.         if(temp == (pixptr)NULL) return;
  58.         if(reverse) { temp += w; w = (-w); }
  59.         doff += w;
  60.         soff += w;
  61.         _SaveDS();
  62.         if(bytecpy) while(--h >= 0) {
  63.             _RowCpyB(RB,temp,srcp,copywdt);
  64.             switch(op) {
  65.             case C_XOR: _RowCpyXorB(WBX,dstp,temp,copywdt); break;
  66.             case C_OR:  _RowCpyOrB(WBO,dstp,temp,copywdt);  break;
  67.             case C_AND: _RowCpyAndB(WBA,dstp,temp,copywdt); break;
  68.             default:    _RowCpyB(WB,dstp,temp,copywdt);    break;
  69.             }
  70.             dstp += doff;
  71.             srcp += soff;
  72.         }
  73.         else while(--h >= 0) {
  74.             _RowCpyW(RW,temp,srcp,copywdt);
  75.             switch(op) {
  76.             case C_XOR: _RowCpyXorW(WWX,dstp,temp,copywdt); break;
  77.             case C_OR:  _RowCpyOrW(WWO,dstp,temp,copywdt);  break;
  78.             case C_AND: _RowCpyAndW(WWA,dstp,temp,copywdt); break;
  79.             default:    _RowCpyW(WW,dstp,temp,copywdt);    break;
  80.             }
  81.             dstp += doff;
  82.             srcp += soff;
  83.         }
  84.         _RestoreDS();
  85.         _ClrDir();
  86.         return;
  87.         }
  88.     }
  89.     _SaveDS();
  90.     if(bytecpy) switch(op) {
  91.         case C_XOR: _BlkCpyXorB(CBX,dstp,doff,srcp,soff,copywdt,h); break;
  92.         case C_OR:  _BlkCpyOrB(CBO,dstp,doff,srcp,soff,copywdt,h);  break;
  93.         case C_AND: _BlkCpyAndB(CBA,dstp,doff,srcp,soff,copywdt,h); break;
  94.         default:    _BlkCpyB(CB,dstp,doff,srcp,soff,copywdt,h);    break;
  95.     }
  96.     else switch(op) {
  97.         case C_XOR: _BlkCpyXorW(CWX,dstp,doff,srcp,soff,copywdt,h); break;
  98.         case C_OR:  _BlkCpyOrW(CWO,dstp,doff,srcp,soff,copywdt,h);  break;
  99.         case C_AND: _BlkCpyAndW(CWA,dstp,doff,srcp,soff,copywdt,h); break;
  100.         default:    _BlkCpyW(CW,dstp,doff,srcp,soff,copywdt,h);    break;
  101.     }
  102.     _RestoreDS();
  103.     _ClrDir();
  104. }
  105.  
  106.