Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
XCopyImg.c
Go to the documentation of this file.
1 /*
2  * This software is copyrighted as noted below. It may be freely copied,
3  * modified, and redistributed, provided that the copyright notices are
4  * preserved on all copies.
5  *
6  * There is no warranty or other guarantee of fitness for this software,
7  * it is provided solely "as is". Bug reports or fixes may be sent
8  * to the author, who may or may not act on them as he desires.
9  *
10  * You may not include this software in a program or other software product
11  * without supplying the source, or without informing the end-user that the
12  * source is available for no extra charge.
13  *
14  * If you modify this software, you should include a notice giving the
15  * name of the person performing the modification, the date of modification,
16  * and the reason for such modification.
17  */
18 
19 /*
20  * Author: Martin R. Friedmann
21  * Dept of Electrical Engineering and Computer Science
22  * University of Michigan
23  * Date: Tue, Nov 14, 1989
24  * Copyright (c) 1989, University of Michigan
25  */
26 
27 #include "getx11.h"
28 
29 /* this function provides a client side, block move within a single image
30  * structure for panning around in the magnified image. bcopy is probubly
31  * faster on most machines...
32  */
33 
34 int
36 XImage *image;
37 int src_x, src_y, width, height, dst_x, dst_y;
38 {
39  int line_width = image->bytes_per_line;
40 
41  if ( width == 0 )
42  return False;
43 
44  switch ( image->bits_per_pixel )
45  {
46  case 1:
47  return False;
48 
49  case 8:
50  do {
51  char *srcline, *dstline;
52  register char *src, *dst;
53  register int counter;
54 
55  if ( src_y < dst_y )
56  {
57  srcline = image->data + line_width * (src_y+height-1) +
58  src_x;
59  dstline = image->data + line_width * (dst_y+height-1) +
60  dst_x;
61 
62  if ( src_x < dst_x ) {
63  dstline += width - 1;
64  while ( --height >= 0 ) {
65  src = srcline + width - 1;
66  dst = dstline;
67  counter = width;
68 
69  duff8( counter, *dst-- = *src-- );
70 
71  srcline -= line_width;
72  dstline -= line_width;
73  }
74  }
75  else {
76  srcline += width - 1;
77  while ( --height >= 0 ) {
78  src = srcline - width + 1;
79  dst = dstline;
80  counter = width;
81 
82  duff8( counter, *dst++ = *src++ );
83 
84  srcline -= line_width;
85  dstline -= line_width;
86  }
87  }
88  }
89  else
90  {
91  srcline = image->data + line_width * src_y + src_x;
92  dstline = image->data + line_width * dst_y + dst_x;
93 
94  if ( src_x < dst_x ) {
95 
96  dstline += width - 1;
97  while ( --height >= 0 ) {
98  src = srcline + width - 1;
99  dst = dstline;
100  counter = width;
101 
102  duff8( counter, *dst-- = *src-- );
103 
104  srcline += line_width;
105  dstline += line_width;
106  }
107  }
108  else {
109  srcline += width - 1;
110  while ( --height >= 0 ) {
111  src = srcline - width + 1;
112  dst = dstline;
113  counter = width;
114 
115  duff8( counter, *dst++ = *src++ );
116 
117  srcline += line_width;
118  dstline += line_width;
119  }
120  }
121  }
122  } while (0);
123  return True;
124 
125  case 32:
126  do {
127  register long *srcline, *dstline;
128  register long *src, *dst;
129 
130  if ( src_y < dst_y )
131  {
132  srcline = (long *) ((char *)image->data +
133  line_width * (src_y+height-1) +
134  src_x * sizeof(long));
135  dstline = (long *) ((char *)image->data +
136  line_width * (dst_y+height-1) +
137  dst_x * sizeof(long));
138 
139  if ( src_x < dst_x ) {
140 
141  dstline += width - 1;
142  while ( --height >= 0 ) {
143  src = srcline + width - 1;
144  dst = dstline;
145 
146  while ( src >= srcline )
147  *dst-- = *src--;
148 
149  srcline -= line_width/sizeof(long);
150  dstline -= line_width/sizeof(long);
151  }
152  }
153  else {
154  srcline += width - 1;
155  while ( --height >= 0 ) {
156  src = srcline - width + 1;
157  dst = dstline;
158 
159  while ( src <= srcline )
160  *dst++ = *src++;
161 
162  srcline -= line_width/sizeof(long);
163  dstline -= line_width/sizeof(long);
164  }
165  }
166  }
167  else
168  {
169  srcline = (long *) ((char *)image->data + line_width * src_y +
170  src_x * sizeof(long));
171  dstline = (long *) ((char *)image->data + line_width * dst_y +
172  dst_x * sizeof(long));
173 
174  if ( src_x < dst_x ) {
175 
176  dstline += width - 1;
177  while ( --height >= 0 ) {
178  src = srcline + width - 1;
179  dst = dstline;
180 
181  while ( src >= srcline )
182  *dst-- = *src--;
183 
184  srcline += line_width/sizeof(long);
185  dstline += line_width/sizeof(long);
186  }
187  }
188  else {
189  srcline += width - 1;
190  while ( --height >= 0 ) {
191  src = srcline - width + 1;
192  dst = dstline;
193 
194  while ( src <= srcline )
195  *dst++ = *src++;
196 
197  srcline += line_width/sizeof(long);
198  dstline += line_width/sizeof(long);
199  }
200  }
201  }
202  } while (0);
203  return True;
204  }
205  return False;
206 }
int XCopyImage(XImage *image, int src_x, int src_y, int width, int height, int dst_x, int dst_y)
Definition: XCopyImg.c:35
#define duff8(counter, block)
Definition: getx11.h:196