Debian Codegraph @

system/idiserv/src/xwimg.c

raw symbols SCIP
1 /*===========================================================================
2 Copyright (C) 1994-2009 European Southern Observatory (ESO)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with this program; if not, write to the Free
16 Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
17 MA 02139, USA.
18
19 Correspondence concerning ESO-MIDAS should be addressed as follows:
20 Internet e-mail: [email protected]
21 Postal address: European Southern Observatory
22 Data Management Division
23 Karl-Schwarzschild-Strasse 2
24 D 85748 Garching bei Muenchen
25 GERMANY
26 ===========================================================================*/
27
28 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29 .IDENTIFIER module XWIMG
30 .LANGUAGE C
31 .AUTHOR Klaus Banse, IPG-ESO Garching
32 .KEYWORDS memory, ImageDisplay & Virtual Display
33 .COMMENTS contains XWIMG
34 Does not support device "Gould DeAnza IP8500"
35 .ENVIRONment MIDAS
36 #include <midas_def.h> Prototypes for MIDAS interfaces
37 #include <idinumd.h> Global variables for DISPLAY interfaces
38
39 .VERSIONS 1.00 940428 taken from wimg.c
40
41 090709 last modif
42 ------------------------------------------------------------*/
43
44 /* Define _POSIX_SOURCE to indicate that this is a POSIX program */
45
46 #define _POSIX_SOURCE 1
47
48 #include <stdio.h>
49 #include <stdlib.h>
50
51
52 #include <midas_def.h>
53 #include <idi.h>
54 #include <idistruct.h>
55 #include <proto_idi.h>
56
57
58 #define FOREVER while(1) /* infinite loop */
59
60
61 /*
62
63 */
64
65 /*++++++++++++++++++++++++++++++
66 .IDENTIFIER XWIMG
67 .PURPOSE write a 2-D image into given memory board of Image Display
68 .ALGORITHM set resolution to only low byte transfer
69 if image is larger than the image memory size, a square around
70 the given center pixels is loaded
71 image is loaded into center of image memory
72
73 .INPUT/OUTPUT
74 call as XWIMG(ldspno,imch,frame,khelp,loaddir,npix,icen,cuts,scale)
75
76 input:
77 int ldspno : display no.
78 int limch : channel no.
79 char *frame : input image name
80 int *khelp : [0] data type (as D_xx_FORMAT)
81 [1,2] mapping sizes
82 [3] subwindow flag (= 1, if so)
83 [4] NFX, if SUBWDW > 0
84 [5,6] NSX,NSY, if SUBWDW > 0
85 [7,8] start pixels in frame, if SUBWDW > 0
86 [9] SOURCE, 2 or 1 - overwrite or not
87 [10] cube_flag, 0 - 2-dim display
88 1 - 3-dim display in one channel
89 2 - 3-dim display in all channels
90 [11,12,13] if cube_flag > 0:
91 first plane, last plane, delay time
92 int loaddir : load direction, 0 = bottom-up, 1 = top-down
93 int npix[3] : no. of pixels in x- and y-dir.
94 int icen[4] : fixpoint: screen pixels + frame pixels
95 float cuts[2] : low + high cut in z-dir.
96 int scale[3]: scaling factors for image in x,y
97 [0,1] if > 1: make image smaller
98 if < 1: make image larger
99 [2] flag for using max (=3), using min (=2),
100 averaging (=1) or not (=0)
101
102 .RETURNS error code, 0 = o.k.
103
104 ------------------------------*/
105
106 int XWIMG(ldspno,limch,frame,khelp,loaddir,npix,icen,cuts,scale)
107 int ldspno, limch;
108 char *frame;
109 int *khelp, loaddir, *npix, *icen, *scale;
110 float *cuts;
111
112 {
113 int status, bufind, incr, imx, imy, ilx, ily, insiz, intake, ifact;
114 int ffelem, felem;
115 int msizei, msizeo, ntx, nty, nfx, nfy, nlines, outmul, outsiz;
116 int imno, qdepth, dattyp;
117 int rmaind, scsave, insav, subwdw, trs, trsize, zin, zinsiz;
118 int inaux[6], kcen[2], kcuts[2], outaux[2];
119 int nnsx, nnsy, nsspx, nsspy, nsfpx, nsfpy, origchan;
120 int cube_flag, plane_off, plcount, plooff, delay;
121 register int ii, jj, ix, iy, kk, mm;
122 register int xdim, xscale;
123
124 CONF_DATA *conf;
125 MEM_DATA *mem;
126
127 float factor, ranmax, sum, faux[3];
128
129 char cbuf[20];
130 char *pntrW;
131 unsigned char *pntrD;
132
133
134
135
136 /* allocate buffer space */
137
138 imx = khelp[2] * sizeof(unsigned char);
139 pntrD = (unsigned char *) malloc((size_t) imx);
140
141 delay = 0;
142 dattyp = khelp[0];
143 origchan = limch; /* save local image channel */
144 xdim = *npix;
145 xscale = *scale;
146
147 conf = ididev[ldspno].confptr;
148 if (conf->RGBmode == 1)
149 mem = conf->memory[0];
150 else
151 mem = conf->memory[limch];
152
153 qdepth = ididev[ldspno].depth;
154
155 switch (dattyp)
156 {
157 case D_R4_FORMAT:
158 imx = khelp[1] * sizeof(float);
159 pntrW = malloc((size_t) imx);
160 break;
161 case D_I4_FORMAT:
162 imx = khelp[1] * sizeof(int);
163 pntrW = malloc((size_t) imx);
164 break;
165 case D_I2_FORMAT:
166 imx = khelp[1] * sizeof(short int);
167 pntrW = malloc((size_t) imx);
168 break;
169 case D_I1_FORMAT:
170 imx = khelp[1] * sizeof(unsigned char);
171 pntrW = malloc((size_t) imx);
172 break;
173 case D_UI2_FORMAT:
174 imx = khelp[1] * sizeof(unsigned short int);
175 pntrW = malloc((size_t) imx);
176 break;
177 default:
178 return (ERR_INPINV);
179 }
180
181
182 /* open image on server side */
183
184 imno = 0;
185 status = SCFOPN(frame,dattyp,0,F_IMA_TYPE,&imno );
186 if (status != ERR_NORMAL) return (40);
187
188 inaux[0] = dattyp; /* get data type */
189 inaux[5] = ididev[ldspno].lutoff; /* LUT offset in X */
190 kk = ididev[ldspno].screen;
191 ranmax = Xworkst[kk].lutlen - 1.0;
192 msizei = khelp[1];
193 msizeo = khelp[2];
194 subwdw = khelp[3]; /* if = 1, it's a subwindow... */
195 *outaux = Xworkst[kk].lutlen - 1;
196 trsize = xdim*npix[1];
197 cube_flag = khelp[10];
198
199
200 sum = cuts[1] - cuts[0]; /* scale image */
201 if (sum < 10.e-25)
202 {
203 *faux = 1.0;
204 *cuts = 0.;
205 }
206 else
207 *faux = ranmax / sum;
208
209 faux[1] = cuts[0];
210 faux[2] = cuts[1];
211
212 if (xscale < 0)
213 inaux[3] = - xscale; /* scaling factor in x */
214 else
215 inaux[3] = xscale;
216 inaux[4] = 1;
217 if (*khelp == D_I1_FORMAT)
218 {
219 kcuts[0] = CGN_NINT(cuts[0]);
220 kcuts[1] = CGN_NINT(cuts[1]);
221 if ((kcuts[0] == 0) && (kcuts[1] == *outaux))
222 inaux[4] = 0; /* no packing for 1-byte `exact' data */
223 }
224
225 plcount = 1;
226 plooff = ididev[ldspno].ysize/8+4;
227 if (!subwdw)
228 {
229 *kcen = *icen;
230 *(kcen+1) = *(icen+2);
231 SIZER_C(mem->xsize,xdim,xscale,scale[2],kcen,&nnsx,&nsspx,&nfx,&nsfpx);
232
233 *kcen = *(icen+1);
234 *(kcen+1) = *(icen+3);
235 SIZER_C(mem->ysize,npix[1],scale[1],scale[2],kcen,&nnsy,&nsspy,&nfy,&nsfpy);
236
237 /* set up values for image display size X-, Y-registers */
238
239 ntx = nnsx;
240 nty = nnsy;
241 ffelem = nsfpx + (xdim * (nsfpy-1));
242 plane_off = 0;
243 }
244
245 else /* subwindow */
246 {
247 nfx = khelp[4];
248 ntx = khelp[5];
249 nty = khelp[6];
250 khelp[10] = 0;
251 ffelem = khelp[7] + (xdim * (khelp[8]-1));
252 plane_off = (mem->plane_no-1)*trsize;
253 }
254
255
256
257 if (cube_flag > 0) /* check 3-dim stuff */
258 {
259 plane_off = (khelp[11]-1) * trsize;
260 plcount = khelp[12]-khelp[11]+1;
261 if (khelp[13] > 0)
262 delay = khelp[13] * 1000; /* move to seconds */
263 else
264 delay = 0;
265 }
266
267
268 plane_loopA:
269
270 if (!subwdw)
271 { /* if complete window, save size of image loaded previously */
272 imx = mem->sspx; /* old SSPX */
273 imy = mem->sspy;
274 ilx = imx + mem->nsx;
275 ily = imy + mem->nsy;
276
277
278 /* test if we have to clear channel first */
279
280 if ( ((ilx != 0) || (ily != 0))
281 && (mem->frame[0] != ' ') /* already an image loaded? */
282 && (khelp[9] != 2) )
283 {
284 GLIST *gp;
285
286 if (mem->gpntr != 0)
287 {
288 gp = mem->gpntr;
289 jj = gp->geln;
290 }
291 else
292 jj = 0;
293
294 if ((jj != 0) || (imx < nsspx) || (imy < nsspy) ||
295 (ilx > (nsspx+ntx)) || (ily > (nsspy+nty)) )
296 (void) IIMCMY_C( ldspno, &limch, 1, 0 );
297 }
298
299
300 /* set up transfer window (load size regs. + CMRs) */
301
302 (void) IIMSTW_C(ldspno,limch,loaddir,ntx,nty,qdepth,nsspx,nsspy);
303
304 if (khelp[9] != 2)
305 {
306 mem->nsx = nnsx;
307 mem->nsy = nnsy;
308 mem->sspx = nsspx;
309 mem->sspy = nsspy;
310 mem->sfpx = nsfpx;
311 mem->sfpy = nsfpy;
312 mem->xscale = xscale;
313 mem->yscale = scale[1];
314 mem->zoom = 1;
315 mem->source = khelp[9];
316 mem->plane_no = 1;
317
318 strcpy(mem->frame,frame);
319 }
320 }
321
322
323 /* start in ima_memory */
324
325 plane_loopB:
326
327 felem = ffelem + plane_off;
328 imx = imy = 0; /* with respect to transfer window */
329 bufind = felem;
330 if ((cube_flag > 0) && (khelp[9] != 2)) mem->plane_no = khelp[11];
331
332
333 /* compute internal buffer sizes depending on scaling */
334
335 if (scale[1] < 0)
336 {
337 outmul = 1; /* 1 input line => multiple output lines */
338 scsave = 1;
339 incr = xdim;
340 }
341 else
342 {
343 outmul = msizeo / ntx; /* no. of lines in out buffer */
344 if (outmul < 1) return(41); /* should not happen... */
345 if (outmul > nty) outmul = nty;
346 scsave = scale[1];
347 incr = xdim * scale[1];
348 }
349
350 if (xscale < 0)
351 inaux[2] = nfx; /* no. of input data to work on */
352 else
353 inaux[2] = ntx; /* no. of input data to work on */
354
355
356 FOREVER /* we should fill at least once */
357 {
358 intake = xdim * outmul * scsave;
359 if (intake > trsize) intake = trsize;
360 if (intake > msizei)
361 {
362 if (--outmul <= 0)
363 {
364 if ((scsave > 1) && (scale[2] == 0)) /* if we omit lines, */
365 { /* no problem... */
366 outmul = 1;
367 intake = xdim * scsave; /* all lines together - this may be */
368 insiz = intake; /* too much, but truncated later on */
369 ifact = 1;
370 outsiz = ntx; /* we'll process just 1 line */
371 nlines = nty ;
372 rmaind = 0;
373 break;
374 }
375 else
376 return (41); /* if we really average, it's bad... */
377 }
378 }
379 else
380 {
381 ifact = msizei / intake;
382 insiz = ifact * intake; /* size of in buffer */
383 outsiz = outmul * ntx; /* size of out buffer */
384 nlines = nty / outmul;
385 rmaind = nty - (nlines * outmul);
386 break; /* we have filled it! */
387 }
388 }
389
390
391 /* branch on scaling factor */
392
393 if ((xscale == 1) && (scale[1] == 1)) /* NO SCALING */
394 {
395 if (xdim <= ntx) /* split depending on npix[0] */
396 {
397 outaux[1] = 0; /* output offset */
398 inaux[2] = outsiz;
399 for (ii=0; ii<nlines; ii++)
400 {
401 if ((felem + intake) > bufind)
402 {
403 (void) SCFGET(imno,felem,insiz,&trs,pntrW);
404 bufind += insiz;
405 inaux[1] = 0; /* input offset */
406 }
407
408 I1PACK_C(pntrW,inaux,faux,pntrD,outaux);
409 inaux[1] += outsiz;
410
411 (void) IIMWMY_C(ldspno,limch,pntrD,outsiz,qdepth,4,imx,imy);
412 imy += outmul;
413 felem += intake;
414 }
415 }
416 else
417 {
418 for (ii=0; ii<nlines; ii++)
419 {
420 if ((felem + intake) > bufind)
421 {
422 (void) SCFGET(imno,felem,insiz,&trs,pntrW);
423 bufind += insiz;
424 inaux[1] = 0; /* input offset */
425 }
426 outaux[1] = 0; /* output offset */
427 for (jj=0; jj<outmul; jj++)
428 {
429 I1PACK_C(pntrW,inaux,faux,pntrD,outaux);
430 inaux[1] += incr;
431 outaux[1] += ntx;
432 }
433
434 (void) IIMWMY_C(ldspno,limch,pntrD,outsiz,qdepth,4,imx,imy);
435 imy += outmul;
436 felem += intake;
437 }
438 }
439
440 if (rmaind > 0)
441 {
442 outsiz = rmaind * ntx;
443 intake = rmaind * xdim;
444
445 if ((felem + intake) > bufind )
446 {
447 (void) SCFGET(imno,felem,insiz,&trs,pntrW);
448 inaux[1] = 0;
449 }
450
451 outaux[1] = 0;
452 if (xdim <= ntx)
453 {
454 inaux[2] = outsiz;
455 I1PACK_C(pntrW,inaux,faux,pntrD,outaux);
456 inaux[1] += outsiz;
457 }
458 else
459 {
460 for (jj=0; jj<rmaind; jj++)
461 {
462 I1PACK_C(pntrW,inaux,faux,pntrD,outaux);
463 inaux[1] += incr;
464 outaux[1] += ntx;
465 }
466 }
467 (void) IIMWMY_C(ldspno,limch,pntrD,outsiz,qdepth,4,imx,imy);
468 }
469 }
470
471 else /* here for spatial scaling/sampling */
472 {
473 if (scale[1] > 0)
474 {
475 zin = xdim * (1 + (outmul-1)*scsave); /* avoid last omitted lines */
476 zinsiz = xdim * (1 + (outmul*ifact - 1)*scsave);
477
478 if (xscale < 0)
479 {
480 for (ii=0; ii<nlines; ii++)
481 {
482 if ((felem + zin) > bufind )
483 {
484 (void) SCFGET(imno,felem,zinsiz,&trs,pntrW);
485 bufind += insiz;
486 inaux[1] = 0;
487 }
488 outaux[1] = 0;
489
490 for (jj=0; jj<outmul; jj++)
491 {
492 K1PACK_C(pntrW,inaux,faux,pntrD,outaux);
493 inaux[1] += incr;
494 outaux[1] += ntx;
495 }
496 (void) IIMWMY_C(ldspno,limch,pntrD,outsiz,qdepth,4,imx,imy);
497 imy += outmul ;
498 felem += intake;
499 }
500
501 if ( rmaind > 0 )
502 {
503 outsiz = rmaind * ntx;
504 intake = xdim * rmaind * scale[1];
505 zin = intake - incr + xdim;
506 zinsiz = insiz - incr + xdim;
507
508 if ((felem + zin) > bufind )
509 {
510 (void) SCFGET(imno,felem,zinsiz,&trs,pntrW);
511 inaux[1] = 0;
512 }
513 outaux[1] = 0;
514
515 for (jj=0; jj<rmaind; jj++)
516 {
517 K1PACK_C(pntrW,inaux,faux,pntrD,outaux);
518 inaux[1] += incr;
519 outaux[1] += ntx;
520 }
521 (void) IIMWMY_C(ldspno,limch,pntrD,outsiz,qdepth,4,imx,imy);
522 }
523 }
524
525 else /* SCALE in X larger than ZERO */
526 {
527 if (scale[2] == 0) /* just scaling */
528 {
529 for (ii=0; ii<nlines; ii++)
530 {
531 if ((felem + zin) > bufind )
532 {
533 (void)SCFGET(imno,felem,zinsiz,&trs,pntrW);
534 bufind += insiz;
535 inaux[1] = 0;
536 }
537 outaux[1] = 0;
538
539 for (jj=0; jj<outmul; jj++)
540 {
541 I1PACK_C(pntrW,inaux,faux,pntrD,outaux);
542 inaux[1] += incr;
543 outaux[1] += ntx;
544 }
545 (void) IIMWMY_C(ldspno,limch,pntrD,outsiz,qdepth,4,imx,imy);
546 imy += outmul ;
547 felem += intake;
548 }
549
550 if (rmaind > 0)
551 {
552 outsiz = rmaind * ntx;
553 intake = xdim * rmaind * scale[1];
554 zin = xdim + intake - incr;
555 if ((felem + zin) > bufind )
556 {
557 (void) SCFGET(imno,felem,zin,&trs,pntrW);
558 inaux[1] = 0;
559 }
560 outaux[1] = 0;
561
562 for (jj=0; jj<rmaind; jj++)
563 {
564 I1PACK_C(pntrW,inaux,faux,pntrD,outaux);
565 inaux[1] += incr;
566 outaux[1] += ntx;
567 }
568 (void) IIMWMY_C(ldspno,limch,pntrD,outsiz,qdepth,4,imx,imy);
569 }
570 }
571
572 else /* we really average */
573 {
574 if ( nlines > 0 )
575 {
576 inaux[3] = 1; /* we don't scale anymore... */
577 inaux[4] = 0;
578 }
579
580 factor = 1. / (xscale * scale[1]); /* scaling factor */
581 mm = xscale * ntx;
582
583 if (dattyp == D_R4_FORMAT)
584 {
585 float *data, *tdata, *work;
586
587 data = (float *) pntrW; /* create work space */
588 work = (float *) malloc((size_t)(ntx * sizeof(float)));
589
590 for (ii=0; ii<nlines; ii++)
591 {
592 if ((felem + intake) > bufind )
593 {
594 (void) SCFGET(imno,felem,insiz,&trs,pntrW);
595 data = (float *) pntrW;
596 bufind += insiz;
597 inaux[1] = 0;
598 }
599 outaux[1] = 0;
600
601 if (scale[2] == 1)
602 {
603 for (jj=0; jj<outmul; jj++)
604 {
605 for (kk=0; kk<ntx; kk++) *work++ = 0.0;
606 work -= ntx;
607
608 tdata = data + inaux[1];
609 for (iy=0; iy<scale[1]; iy++)
610 {
611 for (kk=0; kk<ntx; kk++)
612 {
613 sum = 0.0;
614 for (ix=0; ix<xscale; ix++) sum += *tdata++;
615 *work++ += sum;
616 }
617 work -= ntx;
618 tdata += (xdim - mm); /* move up a line */
619 }
620
621
622 /* scale the accum. col.sums */
623
624 for (kk=0; kk<ntx; kk++) *work++ *= factor;
625 work -= ntx;
626
627 insav = inaux[1]; /* save inaux[1] */
628 inaux[1] = 0;
629 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
630 inaux[1] = insav + incr;
631 outaux[1] += ntx;
632 }
633 }
634
635 else
636 {
637 register float rr;
638
639 for (jj=0; jj<outmul; jj++)
640 {
641 tdata = data + inaux[1];
642 for (kk=0; kk<ntx; kk++)
643 {
644 *work++ = *tdata;
645 tdata += xscale;
646 }
647 work -= ntx;
648 tdata = data + inaux[1];
649
650 if (scale[2] == 2) /* Minimum */
651 {
652 for (iy=0; iy<scale[1]; iy++)
653 {
654 for (kk=0; kk<ntx; kk++)
655 {
656 sum = *work;
657 for (ix=0; ix<xscale; ix++)
658 {
659 rr = *tdata++;
660 if (sum > rr) sum = rr;
661 }
662 *work++ = sum;
663 }
664 work -= ntx;
665 tdata += (xdim - mm);
666 }
667 }
668 else /* Maximum */
669 {
670 for (iy=0; iy<scale[1]; iy++)
671 {
672 for (kk=0; kk<ntx; kk++)
673 {
674 sum = *work;
675 for (ix=0; ix<xscale; ix++)
676 {
677 rr = *tdata++;
678 if (sum < rr) sum = rr;
679 }
680 *work++ = sum;
681 }
682 work -= ntx;
683 tdata += (xdim - mm);
684 }
685 }
686
687 insav = inaux[1]; /* save inaux[1] */
688 inaux[1] = 0;
689 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
690 inaux[1] = insav + incr;
691 outaux[1] += ntx;
692 }
693 }
694
695 (void) IIMWMY_C(ldspno,limch,pntrD,outsiz,qdepth,4,imx,imy);
696 imy += outmul;
697 felem += intake;
698 }
699
700 if (rmaind > 0)
701 {
702 outsiz = rmaind * ntx;
703 intake = xdim * rmaind * scale[1];
704
705 if ( felem + intake > bufind )
706 { /* intake instead of insiz...? */
707 (void) SCFGET(imno,felem,insiz,&trs,pntrW);
708 data = (float *) pntrW;
709 inaux[1] = 0;
710 }
711 outaux[1] = 0;
712
713 if (scale[2] == 1)
714 {
715 for (jj=0; jj<rmaind; jj++)
716 {
717 for (kk=0; kk<ntx; kk++) *work++ = 0.0;
718 work -= ntx;
719
720 tdata = data + inaux[1];
721 for (iy=0; iy<scale[1]; iy++)
722 {
723 for (kk=0; kk<ntx; kk++)
724 {
725 sum = 0.0;
726 for ( ix = 0; ix < xscale; ix++ ) sum += *tdata++;
727 *work++ += sum;
728 }
729 work -= ntx;
730 tdata += (xdim - mm);
731 }
732 for (kk=0; kk<ntx; kk++) *work++ *= factor;
733 work -= ntx;
734
735 insav = inaux[1]; /* save inaux[1] */
736 inaux[1] = 0;
737 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
738 inaux[1] = insav + incr;
739 outaux[1] += ntx;
740 }
741 }
742 else
743 {
744 register float rr;
745
746 for (jj=0; jj<rmaind; jj++)
747 {
748 tdata = data + inaux[1];
749 for (kk=0; kk<ntx; kk++)
750 {
751 *work++ = *tdata;
752 tdata += xscale;
753 }
754 work -= ntx;
755 tdata = data + inaux[1];
756
757 if (scale[2] == 2) /* Minimum */
758 {
759 for (iy=0; iy<scale[1]; iy++)
760 {
761 for (kk=0; kk<ntx; kk++)
762 {
763 sum = *work;
764 for (ix=0; ix<xscale; ix++)
765 {
766 rr = *tdata++;
767 if (sum > rr) sum = rr;
768 }
769 *work++ = sum;
770 }
771 work -= ntx;
772 tdata += (xdim - mm);
773 }
774 }
775 else /* Maximum */
776 {
777 for (iy=0; iy<scale[1]; iy++)
778 {
779 for (kk=0; kk<ntx; kk++)
780 {
781 sum = *work;
782 for (ix=0; ix<xscale; ix++)
783 {
784 rr = *tdata++;
785 if (sum < rr) sum = rr;
786 }
787 *work++ = sum;
788 }
789 work -= ntx;
790 tdata += (xdim - mm);
791 }
792 }
793
794 insav = inaux[1]; /* save inaux[1] */
795 inaux[1] = 0;
796 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
797 inaux[1] = insav + incr;
798 outaux[1] += ntx;
799 }
800 }
801
802 (void) IIMWMY_C(ldspno,limch,pntrD,outsiz,qdepth,4,imx,imy);
803 }
804 (void) free((char *)work);
805 }
806
807 else if (dattyp == D_UI2_FORMAT)
808 {
809 unsigned short int isum, *data, *tdata, *work;
810
811 data = (unsigned short int *) pntrW; /* create work space */
812 work = (unsigned short int *)
813 malloc((size_t)(ntx * sizeof(unsigned short int)));
814
815
816 for (ii=0; ii<nlines; ii++)
817 {
818 if ((felem + intake) > bufind )
819 {
820 (void) SCFGET(imno,felem,insiz,&trs,pntrW);
821 data = (unsigned short int *) pntrW;
822 bufind += insiz;
823 inaux[1] = 0;
824 }
825 outaux[1] = 0;
826
827 if (scale[2] == 1)
828 {
829 for (jj=0; jj<outmul; jj++)
830 {
831 for (kk=0; kk<ntx; kk++) *work++ = 0;
832 work -= ntx;
833
834 tdata = data + inaux[1];
835 for (iy=0; iy<scale[1]; iy++)
836 {
837 for (kk=0; kk<ntx; kk++)
838 {
839 isum = 0;
840 for (ix=0; ix<xscale; ix++) isum += *tdata++;
841 *work++ += isum;
842 }
843 work -= ntx;
844 tdata += (xdim - mm); /* move up a line */
845 }
846
847
848 /* scale the accum. col.sums */
849
850 for (kk=0; kk<ntx; kk++) *work++ *= factor;
851 work -= ntx;
852
853 insav = inaux[1]; /* save inaux[1] */
854 inaux[1] = 0;
855 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
856 inaux[1] = insav + incr;
857 outaux[1] += ntx;
858 }
859 }
860 else
861 {
862 unsigned short int rr;
863
864 for (jj=0; jj<outmul; jj++)
865 {
866 tdata = data + inaux[1];
867 for (kk=0; kk<ntx; kk++)
868 {
869 *work++ = *tdata;
870 tdata += xscale;
871 }
872 work -= ntx;
873 tdata = data + inaux[1];
874
875 if (scale[2] == 2) /* Minimum */
876 {
877 for (iy=0; iy<scale[1]; iy++)
878 {
879 for (kk=0; kk<ntx; kk++)
880 {
881 isum = *work;
882 for (ix=0; ix<xscale; ix++)
883 {
884 rr = *tdata++;
885 if (isum > rr) isum = rr;
886 }
887 *work++ = isum;
888 }
889 work -= ntx;
890 tdata += (xdim - mm);
891 }
892 }
893 else /* Maximum */
894 {
895 for (iy=0; iy<scale[1]; iy++)
896 {
897 for (kk=0; kk<ntx; kk++)
898 {
899 isum = *work;
900 for (ix=0; ix<xscale; ix++)
901 {
902 rr = *tdata++;
903 if (isum < rr) isum = rr;
904 }
905 *work++ = isum;
906 }
907 work -= ntx;
908 tdata += (xdim - mm);
909 }
910 }
911
912 insav = inaux[1]; /* save inaux[1] */
913 inaux[1] = 0;
914 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
915 inaux[1] = insav + incr;
916 outaux[1] += ntx;
917 }
918 }
919
920 (void) IIMWMY_C(ldspno,limch,pntrD,outsiz,qdepth,4,imx,imy);
921 imy += outmul;
922 felem += intake;
923 }
924
925 if (rmaind > 0)
926 {
927 outsiz = rmaind * ntx;
928 intake = xdim * rmaind * scale[1];
929
930 if ((felem + intake) > bufind )
931 { /* intake instead of insiz...? */
932 (void) SCFGET(imno,felem,insiz,&trs,pntrW);
933 data = (unsigned short int *) pntrW;
934 inaux[1] = 0;
935 }
936 outaux[1] = 0;
937
938 if (scale[2] == 1)
939 {
940 for (jj=0; jj<rmaind; jj++)
941 {
942 for (kk=0; kk<ntx; kk++) *work++ = 0;
943 work -= ntx;
944
945 tdata = data + inaux[1];
946 for (iy=0; iy<scale[1]; iy++)
947 {
948 for (kk=0; kk<ntx; kk++)
949 {
950 isum = 0;
951 for (ix=0; ix< xscale; ix++) isum += *tdata++;
952 *work++ += isum;
953 }
954 work -= ntx;
955 tdata += (xdim - mm);
956 }
957 for (kk=0; kk<ntx; kk++) *work++ *= factor;
958 work -= ntx;
959
960 insav = inaux[1]; /* save inaux[1] */
961 inaux[1] = 0;
962 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
963 inaux[1] = insav + incr;
964 outaux[1] += ntx;
965 }
966 }
967 else
968 {
969 unsigned short int rr;
970
971 for (jj=0; jj<rmaind; jj++)
972 {
973 tdata = data + inaux[1];
974 for (kk=0; kk<ntx; kk++)
975 {
976 *work++ = *tdata;
977 tdata += xscale;
978 }
979 work -= ntx;
980 tdata = data + inaux[1];
981
982 if (scale[2] == 2) /* Minimum */
983 {
984 for (iy=0; iy<scale[1]; iy++)
985 {
986 for (kk=0; kk<ntx; kk++)
987 {
988 isum = *work;
989 for (ix=0; ix<xscale; ix++)
990 {
991 rr = *tdata++;
992 if (isum > rr) isum = rr;
993 }
994 *work++ = isum;
995 }
996 work -= ntx;
997 tdata += (xdim - mm);
998 }
999 }
1000 else /* Maximum */
1001 {
1002 for (iy=0; iy<scale[1]; iy++)
1003 {
1004 for (kk=0; kk<ntx; kk++)
1005 {
1006 isum = *work;
1007 for (ix=0; ix<xscale; ix++)
1008 {
1009 rr = *tdata++;
1010 if (isum < rr) isum = rr;
1011 }
1012 *work++ = isum;
1013 }
1014 work -= ntx;
1015 tdata += (xdim - mm);
1016 }
1017 }
1018
1019 insav = inaux[1]; /* save inaux[1] */
1020 inaux[1] = 0;
1021 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
1022 inaux[1] = insav + incr;
1023 outaux[1] += ntx;
1024 }
1025 }
1026
1027 (void) IIMWMY_C(ldspno,limch,pntrD,outsiz,qdepth,4,imx,imy);
1028 }
1029 (void) free((char *)work);
1030 }
1031
1032 else if (dattyp == D_I2_FORMAT)
1033 {
1034 short int isum, *data, *tdata, *work;
1035
1036 data = (short int *) pntrW; /* create work space */
1037 work = (short int *)
1038 malloc((size_t)(ntx * sizeof(short int)));
1039
1040
1041 for (ii=0; ii<nlines; ii++)
1042 {
1043 if ((felem + intake) > bufind )
1044 {
1045 (void) SCFGET(imno,felem,insiz,&trs,pntrW);
1046 data = (short int *) pntrW;
1047 bufind += insiz;
1048 inaux[1] = 0;
1049 }
1050 outaux[1] = 0;
1051
1052 if (scale[2] == 1)
1053 {
1054 for (jj=0; jj<outmul; jj++)
1055 {
1056 for (kk=0; kk<ntx; kk++) *work++ = 0;
1057 work -= ntx;
1058
1059 tdata = data + inaux[1];
1060 for (iy=0; iy<scale[1]; iy++)
1061 {
1062 for (kk=0; kk<ntx; kk++)
1063 {
1064 isum = 0;
1065 for (ix=0; ix<xscale; ix++) isum += *tdata++;
1066 *work++ += isum;
1067 }
1068 work -= ntx;
1069 tdata += (xdim - mm); /* move up a line */
1070 }
1071
1072
1073 /* scale the accum. col.sums */
1074
1075 for (kk=0; kk<ntx; kk++) *work++ *= factor;
1076 work -= ntx;
1077
1078 insav = inaux[1]; /* save inaux[1] */
1079 inaux[1] = 0;
1080 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
1081 inaux[1] = insav + incr;
1082 outaux[1] += ntx;
1083 }
1084 }
1085 else
1086 {
1087 short int rr;
1088
1089 for (jj=0; jj<outmul; jj++)
1090 {
1091 tdata = data + inaux[1];
1092 for (kk=0; kk<ntx; kk++)
1093 {
1094 *work++ = *tdata;
1095 tdata += xscale;
1096 }
1097 work -= ntx;
1098 tdata = data + inaux[1];
1099
1100 if (scale[2] == 2) /* Minimum */
1101 {
1102 for (iy=0; iy<scale[1]; iy++)
1103 {
1104 for (kk=0; kk<ntx; kk++)
1105 {
1106 isum = *work;
1107 for (ix=0; ix<xscale; ix++)
1108 {
1109 rr = *tdata++;
1110 if (isum > rr) isum = rr;
1111 }
1112 *work++ = isum;
1113 }
1114 work -= ntx;
1115 tdata += (xdim - mm);
1116 }
1117 }
1118 else /* Maximum */
1119 {
1120 for (iy=0; iy<scale[1]; iy++)
1121 {
1122 for (kk=0; kk<ntx; kk++)
1123 {
1124 isum = *work;
1125 for (ix=0; ix<xscale; ix++)
1126 {
1127 rr = *tdata++;
1128 if (isum < rr) isum = rr;
1129 }
1130 *work++ = isum;
1131 }
1132 work -= ntx;
1133 tdata += (xdim - mm);
1134 }
1135 }
1136
1137 insav = inaux[1]; /* save inaux[1] */
1138 inaux[1] = 0;
1139 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
1140 inaux[1] = insav + incr;
1141 outaux[1] += ntx;
1142 }
1143 }
1144
1145 (void) IIMWMY_C(ldspno,limch,pntrD,outsiz,qdepth,4,imx,imy);
1146 imy += outmul;
1147 felem += intake;
1148 }
1149
1150 if (rmaind > 0)
1151 {
1152 outsiz = rmaind * ntx;
1153 intake = xdim * rmaind * scale[1];
1154
1155 if ( felem + intake > bufind )
1156 { /* intake instead of insiz...? */
1157 (void) SCFGET(imno,felem,insiz,&trs,pntrW);
1158 data = (short int *) pntrW;
1159 inaux[1] = 0;
1160 }
1161 outaux[1] = 0;
1162
1163 if (scale[2] == 1)
1164 {
1165 for (jj=0; jj<rmaind; jj++)
1166 {
1167 for (kk=0; kk<ntx; kk++) *work++ = 0;
1168 work -= ntx;
1169
1170 tdata = data + inaux[1];
1171 for (iy=0; iy<scale[1]; iy++)
1172 {
1173 for (kk=0; kk<ntx; kk++)
1174 {
1175 isum = 0;
1176 for (ix=0; ix< xscale; ix++) isum += *tdata++;
1177 *work++ += isum;
1178 }
1179 work -= ntx;
1180 tdata += (xdim - mm);
1181 }
1182 for (kk=0; kk<ntx; kk++) *work++ *= factor;
1183 work -= ntx;
1184
1185 insav = inaux[1]; /* save inaux[1] */
1186 inaux[1] = 0;
1187 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
1188 inaux[1] = insav + incr;
1189 outaux[1] += ntx;
1190 }
1191 }
1192 else
1193 {
1194 short int rr;
1195
1196 for (jj=0; jj<rmaind; jj++)
1197 {
1198 tdata = data + inaux[1];
1199 for (kk=0; kk<ntx; kk++)
1200 {
1201 *work++ = *tdata;
1202 tdata += xscale;
1203 }
1204 work -= ntx;
1205 tdata = data + inaux[1];
1206
1207 if (scale[2] == 2) /* Minimum */
1208 {
1209 for (iy=0; iy<scale[1]; iy++)
1210 {
1211 for (kk=0; kk<ntx; kk++)
1212 {
1213 isum = *work;
1214 for (ix=0; ix<xscale; ix++)
1215 {
1216 rr = *tdata++;
1217 if (isum > rr) isum = rr;
1218 }
1219 *work++ = isum;
1220 }
1221 work -= ntx;
1222 tdata += (xdim - mm);
1223 }
1224 }
1225 else /* Maximum */
1226 {
1227 for (iy=0; iy<scale[1]; iy++)
1228 {
1229 for (kk=0; kk<ntx; kk++)
1230 {
1231 isum = *work;
1232 for (ix=0; ix<xscale; ix++)
1233 {
1234 rr = *tdata++;
1235 if (isum < rr) isum = rr;
1236 }
1237 *work++ = isum;
1238 }
1239 work -= ntx;
1240 tdata += (xdim - mm);
1241 }
1242 }
1243
1244 insav = inaux[1]; /* save inaux[1] */
1245 inaux[1] = 0;
1246 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
1247 inaux[1] = insav + incr;
1248 outaux[1] += ntx;
1249 }
1250 }
1251
1252 (void) IIMWMY_C(ldspno,limch,pntrD,outsiz,qdepth,4,imx,imy);
1253 }
1254 (void) free((char *)work);
1255 }
1256
1257 else if (dattyp == D_I1_FORMAT)
1258 {
1259 unsigned char isum, *data, *tdata, *work;
1260
1261 data = (unsigned char *) pntrW; /* create work space */
1262 work = (unsigned char *)
1263 malloc((size_t)(ntx * sizeof(unsigned char)));
1264
1265
1266 for (ii=0; ii<nlines; ii++)
1267 {
1268 if ((felem + intake) > bufind )
1269 {
1270 (void) SCFGET(imno,felem,insiz,&trs,pntrW);
1271 data = (unsigned char *) pntrW;
1272 bufind += insiz;
1273 inaux[1] = 0;
1274 }
1275 outaux[1] = 0;
1276
1277 if (scale[2] == 1)
1278 {
1279 for (jj=0; jj<outmul; jj++)
1280 {
1281 for (kk=0; kk<ntx; kk++) *work++ = 0;
1282 work -= ntx;
1283
1284 tdata = data + inaux[1];
1285 for (iy=0; iy<scale[1]; iy++)
1286 {
1287 for (kk=0; kk<ntx; kk++)
1288 {
1289 isum = 0;
1290 for (ix=0; ix<xscale; ix++) isum += *tdata++;
1291 *work++ += isum;
1292 }
1293 work -= ntx;
1294 tdata += (xdim - mm); /* move up a line */
1295 }
1296
1297
1298 /* scale the accum. col.sums */
1299
1300 for (kk=0; kk<ntx; kk++) *work++ *= factor;
1301 work -= ntx;
1302
1303 insav = inaux[1]; /* save inaux[1] */
1304 inaux[1] = 0;
1305 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
1306 inaux[1] = insav + incr;
1307 outaux[1] += ntx;
1308 }
1309 }
1310 else
1311 {
1312 unsigned char rr;
1313
1314 for (jj=0; jj<outmul; jj++)
1315 {
1316 tdata = data + inaux[1];
1317 for (kk=0; kk<ntx; kk++)
1318 {
1319 *work++ = *tdata;
1320 tdata += xscale;
1321 }
1322 work -= ntx;
1323 tdata = data + inaux[1];
1324
1325 if (scale[2] == 2) /* Minimum */
1326 {
1327 for (iy=0; iy<scale[1]; iy++)
1328 {
1329 for (kk=0; kk<ntx; kk++)
1330 {
1331 isum = *work;
1332 for (ix=0; ix<xscale; ix++)
1333 {
1334 rr = *tdata++;
1335 if (isum > rr) isum = rr;
1336 }
1337 *work++ = isum;
1338 }
1339 work -= ntx;
1340 tdata += (xdim - mm);
1341 }
1342 }
1343 else /* Maximum */
1344 {
1345 for (iy=0; iy<scale[1]; iy++)
1346 {
1347 for (kk=0; kk<ntx; kk++)
1348 {
1349 isum = *work;
1350 for (ix=0; ix<xscale; ix++)
1351 {
1352 rr = *tdata++;
1353 if (isum < rr) isum = rr;
1354 }
1355 *work++ = isum;
1356 }
1357 work -= ntx;
1358 tdata += (xdim - mm);
1359 }
1360 }
1361
1362 insav = inaux[1]; /* save inaux[1] */
1363 inaux[1] = 0;
1364 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
1365 inaux[1] = insav + incr;
1366 outaux[1] += ntx;
1367 }
1368 }
1369
1370 (void) IIMWMY_C(ldspno,limch,pntrD,outsiz,qdepth,4,imx,imy);
1371 imy += outmul;
1372 felem += intake;
1373 }
1374
1375 if (rmaind > 0)
1376 {
1377 outsiz = rmaind * ntx;
1378 intake = xdim * rmaind * scale[1];
1379
1380 if ((felem + intake) > bufind )
1381 { /* intake instead of insiz...? */
1382 (void) SCFGET(imno,felem,insiz,&trs,pntrW);
1383 data = (unsigned char *) pntrW;
1384 inaux[1] = 0;
1385 }
1386 outaux[1] = 0;
1387
1388 if (scale[2] == 1)
1389 {
1390 for (jj=0; jj<rmaind; jj++)
1391 {
1392 for (kk=0; kk<ntx; kk++) *work++ = 0;
1393 work -= ntx;
1394
1395 tdata = data + inaux[1];
1396 for (iy=0; iy<scale[1]; iy++)
1397 {
1398 for (kk=0; kk<ntx; kk++)
1399 {
1400 isum = 0;
1401 for (ix=0; ix< xscale; ix++) isum += *tdata++;
1402 *work++ += isum;
1403 }
1404 work -= ntx;
1405 tdata += (xdim - mm);
1406 }
1407 for (kk=0; kk<ntx; kk++) *work++ *= factor;
1408 work -= ntx;
1409
1410 insav = inaux[1]; /* save inaux[1] */
1411 inaux[1] = 0;
1412 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
1413 inaux[1] = insav + incr;
1414 outaux[1] += ntx;
1415 }
1416 }
1417 else
1418 {
1419 unsigned char rr;
1420
1421 for (jj=0; jj<rmaind; jj++)
1422 {
1423 tdata = data + inaux[1];
1424 for (kk=0; kk<ntx; kk++)
1425 {
1426 *work++ = *tdata;
1427 tdata += xscale;
1428 }
1429 work -= ntx;
1430 tdata = data + inaux[1];
1431
1432 if (scale[2] == 2) /* Minimum */
1433 {
1434 for (iy=0; iy<scale[1]; iy++)
1435 {
1436 for (kk=0; kk<ntx; kk++)
1437 {
1438 isum = *work;
1439 for (ix=0; ix<xscale; ix++)
1440 {
1441 rr = *tdata++;
1442 if (isum > rr) isum = rr;
1443 }
1444 *work++ = isum;
1445 }
1446 work -= ntx;
1447 tdata += (xdim - mm);
1448 }
1449 }
1450 else /* Maximum */
1451 {
1452 for (iy=0; iy<scale[1]; iy++)
1453 {
1454 for (kk=0; kk<ntx; kk++)
1455 {
1456 isum = *work;
1457 for (ix=0; ix<xscale; ix++)
1458 {
1459 rr = *tdata++;
1460 if (isum < rr) isum = rr;
1461 }
1462 *work++ = isum;
1463 }
1464 work -= ntx;
1465 tdata += (xdim - mm);
1466 }
1467 }
1468
1469 insav = inaux[1]; /* save inaux[1] */
1470 inaux[1] = 0;
1471 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
1472 inaux[1] = insav + incr;
1473 outaux[1] += ntx;
1474 }
1475 }
1476
1477 (void) IIMWMY_C(ldspno,limch,pntrD,outsiz,qdepth,4,imx,imy);
1478 }
1479 (void) free((char *)work);
1480 }
1481
1482 else if (dattyp == D_I4_FORMAT)
1483 {
1484 int isum, *data, *tdata, *work;
1485
1486 data = (int *) pntrW; /* create work space */
1487 work = (int *) malloc((size_t)(ntx * sizeof(int)));
1488
1489
1490 for (ii=0; ii<nlines; ii++)
1491 {
1492 if ((felem + intake) > bufind )
1493 {
1494 (void) SCFGET(imno,felem,insiz,&trs,pntrW);
1495 data = (int *) pntrW;
1496 bufind += insiz;
1497 inaux[1] = 0;
1498 }
1499 outaux[1] = 0;
1500
1501 if (scale[2] == 1)
1502 {
1503 for (jj=0; jj<outmul; jj++)
1504 {
1505 for (kk=0; kk<ntx; kk++) *work++ = 0;
1506 work -= ntx;
1507
1508 tdata = data + inaux[1];
1509 for (iy=0; iy<scale[1]; iy++)
1510 {
1511 for (kk=0; kk<ntx; kk++)
1512 {
1513 isum = 0;
1514 for (ix=0; ix<xscale; ix++) isum += *tdata++;
1515 *work++ += isum;
1516 }
1517 work -= ntx;
1518 tdata += (xdim - mm); /* move up a line */
1519 }
1520
1521
1522 /* scale the accum. col.sums */
1523
1524 for (kk=0; kk<ntx; kk++) *work++ *= factor;
1525 work -= ntx;
1526
1527 insav = inaux[1]; /* save inaux[1] */
1528 inaux[1] = 0;
1529 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
1530 inaux[1] = insav + incr;
1531 outaux[1] += ntx;
1532 }
1533 }
1534 else
1535 {
1536 int rr;
1537
1538 for (jj=0; jj<outmul; jj++)
1539 {
1540 tdata = data + inaux[1];
1541 for (kk=0; kk<ntx; kk++)
1542 {
1543 *work++ = *tdata;
1544 tdata += xscale;
1545 }
1546 work -= ntx;
1547 tdata = data + inaux[1];
1548
1549 if (scale[2] == 2) /* Minimum */
1550 {
1551 for (iy=0; iy<scale[1]; iy++)
1552 {
1553 for (kk=0; kk<ntx; kk++)
1554 {
1555 isum = *work;
1556 for (ix=0; ix<xscale; ix++)
1557 {
1558 rr = *tdata++;
1559 if (isum > rr) isum = rr;
1560 }
1561 *work++ = isum;
1562 }
1563 work -= ntx;
1564 tdata += (xdim - mm);
1565 }
1566 }
1567 else /* Maximum */
1568 {
1569 for (iy=0; iy<scale[1]; iy++)
1570 {
1571 for (kk=0; kk<ntx; kk++)
1572 {
1573 isum = *work;
1574 for (ix=0; ix<xscale; ix++)
1575 {
1576 rr = *tdata++;
1577 if (isum < rr) isum = rr;
1578 }
1579 *work++ = isum;
1580 }
1581 work -= ntx;
1582 tdata += (xdim - mm);
1583 }
1584 }
1585
1586 insav = inaux[1]; /* save inaux[1] */
1587 inaux[1] = 0;
1588 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
1589 inaux[1] = insav + incr;
1590 outaux[1] += ntx;
1591 }
1592 }
1593
1594 (void) IIMWMY_C(ldspno,limch,pntrD,outsiz,qdepth,4,imx,imy);
1595 imy += outmul;
1596 felem += intake;
1597 }
1598
1599 if (rmaind > 0)
1600 {
1601 outsiz = rmaind * ntx;
1602 intake = xdim * rmaind * scale[1];
1603
1604 if ((felem + intake) > bufind )
1605 { /* intake instead of insiz...? */
1606 (void) SCFGET(imno,felem,insiz,&trs,pntrW);
1607 data = (int *) pntrW;
1608 inaux[1] = 0;
1609 }
1610 outaux[1] = 0;
1611
1612 if (scale[2] == 1)
1613 {
1614 for (jj=0; jj<rmaind; jj++)
1615 {
1616 for (kk=0; kk<ntx; kk++) *work++ = 0;
1617 work -= ntx;
1618
1619 tdata = data + inaux[1];
1620 for (iy=0; iy<scale[1]; iy++)
1621 {
1622 for (kk=0; kk<ntx; kk++)
1623 {
1624 isum = 0;
1625 for (ix=0; ix< xscale; ix++) isum += *tdata++;
1626 *work++ += isum;
1627 }
1628 work -= ntx;
1629 tdata += (xdim - mm);
1630 }
1631 for (kk=0; kk<ntx; kk++) *work++ *= factor;
1632 work -= ntx;
1633
1634 insav = inaux[1]; /* save inaux[1] */
1635 inaux[1] = 0;
1636 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
1637 inaux[1] = insav + incr;
1638 outaux[1] += ntx;
1639 }
1640 }
1641 else
1642 {
1643 int rr;
1644
1645 for (jj=0; jj<rmaind; jj++)
1646 {
1647 tdata = data + inaux[1];
1648 for (kk=0; kk<ntx; kk++)
1649 {
1650 *work++ = *tdata;
1651 tdata += xscale;
1652 }
1653 work -= ntx;
1654 tdata = data + inaux[1];
1655
1656 if (scale[2] == 2) /* Minimum */
1657 {
1658 for (iy=0; iy<scale[1]; iy++)
1659 {
1660 for (kk=0; kk<ntx; kk++)
1661 {
1662 isum = *work;
1663 for (ix=0; ix<xscale; ix++)
1664 {
1665 rr = *tdata++;
1666 if (isum > rr) isum = rr;
1667 }
1668 *work++ = isum;
1669 }
1670 work -= ntx;
1671 tdata += (xdim - mm);
1672 }
1673 }
1674 else /* Maximum */
1675 {
1676 for (iy=0; iy<scale[1]; iy++)
1677 {
1678 for (kk=0; kk<ntx; kk++)
1679 {
1680 isum = *work;
1681 for (ix=0; ix<xscale; ix++)
1682 {
1683 rr = *tdata++;
1684 if (isum < rr) isum = rr;
1685 }
1686 *work++ = isum;
1687 }
1688 work -= ntx;
1689 tdata += (xdim - mm);
1690 }
1691 }
1692
1693 insav = inaux[1]; /* save inaux[1] */
1694 inaux[1] = 0;
1695 I1PACK_C((char *) work,inaux,faux,pntrD,outaux);
1696 inaux[1] = insav + incr;
1697 outaux[1] += ntx;
1698 }
1699 }
1700
1701 (void) IIMWMY_C(ldspno,limch,pntrD,outsiz,qdepth,4,imx,imy);
1702 }
1703 (void) free((char *)work);
1704 }
1705 }
1706 }
1707 }
1708
1709 else /* here with y-scale < 0 (replicate y-lines) */
1710 {
1711 outaux[1] = 0;
1712
1713 for (ii=0; ii<nlines && imy<nty; ii++)
1714 {
1715 if ((felem + nfx) > bufind )
1716 {
1717 (void) SCFGET(imno,felem,insiz,&trs,pntrW);
1718 bufind += trs;
1719 inaux[1] = 0;
1720 }
1721 if ( xscale < 0 )
1722 K1PACK_C(pntrW,inaux,faux,pntrD,outaux);
1723 else
1724 I1PACK_C(pntrW,inaux,faux,pntrD,outaux);
1725
1726 for (jj=0; jj<(- scale[1]) && imy<nty; jj++, imy++)
1727 {
1728 (void) IIMWMY_C(ldspno,limch,pntrD,outsiz,qdepth,4,imx,imy);
1729 }
1730 felem += intake; /* intake = npix[0] */
1731 inaux[1] += incr;
1732 }
1733 }
1734 }
1735
1736
1737 /* common end section: */
1738
1739 if ( subwdw != 0 )
1740 (void) IIMSMV_C(ldspno,&limch,1,1);
1741
1742 else
1743 {
1744 /* show loaded plane */
1745 if ((cube_flag > 0) && (limch == origchan))
1746 {
1747 (void) sprintf(cbuf,"PLANE:%d",khelp[11]);
1748 (void) IIGTXT_C(ldspno,99,cbuf,plooff,0,0,0,0,0);
1749 }
1750 else
1751 {
1752 (void) strcpy(cbuf," ");
1753 (void) IIGTXT_C(ldspno,99,cbuf,plooff,0,0,0,0,0);
1754 }
1755
1756 if (plcount > 1) /* more than 1 plane? */
1757 {
1758 plcount --;
1759 khelp[11] ++;
1760 plane_off += trsize; /* move to next plane */
1761 if (limch == origchan)
1762 (void) IIMSMV_C(ldspno,&origchan,1,1);
1763 if (delay > 0)
1764 {
1765 sendX(ldspno); /* refresh display */
1766 OSY_SLEEP(delay,0); /* and wait `delay' seconds */
1767 }
1768 if (cube_flag == 1)
1769 goto plane_loopB;
1770 else
1771 {
1772 if (subwdw != 2) /* reset transfer window */
1773 (void) IIMSTW_C(ldspno,limch,loaddir,mem->xsize,mem->ysize,
1774 qdepth,0,0);
1775 limch ++; /* move to next channel */
1776 if (conf->RGBmode == 0)
1777 mem = conf->memory[limch]; /* update memory pointer */
1778 goto plane_loopA;
1779 }
1780 }
1781 }
1782
1783
1784 (void) free(pntrW);
1785 (void) free((char *) pntrD);
1786
1787 /* for FITS images we have to disable any eventual updates
1788 so set fctpntr->KAUX[2] = 0 (via the MID_FCTCTRL interface) */
1789 zin = 0;
1790 (void) MID_FCTCTRL(1,imno,&zin);
1791 status = SCFCLO(imno);
1792 if (status != ERR_NORMAL) return (status);
1793
1794
1795 if (subwdw != 2) /* reset transfer window */
1796 (void) IIMSTW_C(ldspno,limch,loaddir,mem->xsize,mem->ysize,qdepth,0,0);
1797
1798 return (ERR_NORMAL);
1799 }
1800