Diff of /pan.c [000000] .. [2a97a8] Maximize Restore

  Switch to unified view

a b/pan.c
1
/* Panorama_Tools -   Generate, Edit and Convert Panoramic Images
2
   Copyright (C) 1998,1999 - Helmut Dersch  der@fh-furtwangen.de
3
   
4
   This program is free software; you can redistribute it and/or modify
5
   it under the terms of the GNU General Public License as published by
6
   the Free Software Foundation; either version 2, or (at your option)
7
   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 License
15
   along with this program; if not, write to the Free Software
16
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
17
18
/*------------------------------------------------------------*/
19
20
21
#include "filter.h"
22
23
void  pan (TrformStr *TrPtr, panControls *pc )
24
{
25
  int         destwidth, destheight;
26
  aPrefs      aP;
27
  double      hfov;
28
  Image       *im, buf;
29
30
31
  if( readPrefs( (char*)&aP, _adjust ) != 0 )
32
  {
33
      PrintError("Could not read Preferences");
34
      TrPtr->success = 0;
35
      return;
36
  }
37
38
  switch( TrPtr->tool )
39
  {
40
      case _apply:            
41
          // Maybe the viewing window has been resized (Hopefully not more!)
42
          aP.im.width         = TrPtr->src->width;
43
          aP.im.height        = TrPtr->src->height;
44
          
45
          // pano must be the saved buffer image
46
          if( *aP.sBuf.destName == 0  || LoadBufImage( &aP.pano, aP.sBuf.destName, 0) != 0 )
47
          {
48
              PrintError("Could not load Buffer");
49
              TrPtr->success = 0;
50
              return;
51
          }
52
          
53
          im                  = TrPtr->dest;
54
          TrPtr->dest         = &aP.pano;
55
          TrPtr->dest->data   = (unsigned char**) mymalloc( TrPtr->dest->dataSize );
56
          if( TrPtr->dest->data == NULL )
57
          {
58
              PrintError( "Not enough memory to create Panorama");
59
              TrPtr->success = 0;
60
              return;
61
          }
62
          TrPtr->mode             |= _honor_valid;
63
64
          CopyPosition( TrPtr->src, &(aP.im) );
65
          addAlpha( TrPtr->src ); // Add alpha channel to indicate valid data
66
      
67
          MakePano( TrPtr,  &aP );
68
69
          // Stitch images; Proceed only if panoramic image valid
70
              
71
          if( TrPtr->success )
72
          {
73
              // Now load the whole bufferimage
74
75
              if(  LoadBufImage( &buf, aP.sBuf.destName, 1 ) != 0  )
76
              {
77
                  PrintError( "Not enough Memory to merge Images" );
78
              }
79
              else 
80
              {
81
                  if( merge( TrPtr->dest , &buf, aP.sBuf.feather, TrPtr->mode & _show_progress, _dest ) != 0 )
82
                  {
83
                      PrintError( "Error merging images" );
84
                  }
85
                  else
86
                  {
87
                      if( SaveBufImage( TrPtr->dest, aP.sBuf.destName ) != 0 )
88
                          PrintError( "Could not save Buffer Image.");
89
                  }
90
                  myfree( (void**)buf.data );
91
              }
92
93
          } // Tr.success 
94
          
95
          TrPtr->success = 0;
96
          myfree( (void**)TrPtr->dest->data );
97
          TrPtr->dest = im;
98
          break;
99
      case _getPano:
100
          
101
          // Load buffer into dest
102
          // destSupplied is not allowed here!
103
          
104
          if( *aP.sBuf.destName == 0  || LoadBufImage( TrPtr->dest, aP.sBuf.destName, 1) != 0 )
105
          {
106
              PrintError("Could not load Buffer");
107
              TrPtr->success = 0;
108
          }
109
          else
110
              TrPtr->success = 1;
111
          break;
112
      case _increment:
113
          if( SetPanPrefs( pc ) )
114
              writePrefs( (char*)pc, _panleft );
115
          TrPtr->success = 0; // don't destroy source!
116
          break;
117
      default:
118
          switch( TrPtr->tool )
119
          {
120
              case _panright:
121
                  aP.im.yaw += pc->panAngle;
122
                  NORM_ANGLE( aP.im.yaw );
123
                  break;
124
              case _panleft:
125
                  aP.im.yaw -= pc->panAngle;
126
                  NORM_ANGLE( aP.im.yaw );
127
                  break;
128
              case _panup:
129
                  aP.im.pitch += pc->panAngle;
130
                  NORM_ANGLE( aP.im.pitch );
131
                  break;
132
              case _pandown:
133
                  aP.im.pitch -= pc->panAngle;
134
                  NORM_ANGLE( aP.im.pitch );
135
                  break;
136
              case _zoomin:
137
                  hfov = aP.im.hfov / ((100.0 + pc->zoomFactor)/100.0);
138
                  if( aP.im.format != _rectilinear || hfov < 180.0 )
139
                      aP.im.hfov = hfov;
140
                  break;
141
              case _zoomout:
142
                  hfov = aP.im.hfov * ((100.0 + pc->zoomFactor)/100.0);
143
                  if( aP.im.format != _rectilinear || hfov < 180.0 )
144
                      aP.im.hfov = hfov;
145
                  break;
146
              default: break;
147
          }
148
          // Maybe the viewing window has been resized (Hopefully not more!)
149
          aP.im.width         = TrPtr->src->width;
150
          aP.im.height        = TrPtr->src->height;
151
152
153
          destheight              = aP.im.height;
154
          destwidth               = aP.im.width;
155
          
156
          if( SetDestImage( TrPtr, destwidth, destheight) != 0)
157
          {
158
              PrintError("Could not allocate %ld bytes",TrPtr->dest->dataSize );
159
              TrPtr->success = 0;
160
              return;
161
          }
162
          TrPtr->mode             |= _honor_valid;
163
164
          if( LoadBufImage( &aP.pano, aP.sBuf.destName, 1) != 0 )
165
          {
166
              PrintError("Could not load Buffer" );
167
              TrPtr->success = 0;
168
              return;
169
          }
170
                      
171
          im = TrPtr->src;
172
          TrPtr->src = &aP.pano;
173
174
          if( aP.pano.hfov == 360.0 )
175
              TrPtr->mode             |= _wrapX;
176
          
177
          ExtractStill( TrPtr , &aP );
178
179
          myfree( (void**)TrPtr->src->data );
180
          TrPtr->src = im;
181
          
182
          if(TrPtr->success)
183
              writePrefs(  (char*)&aP, _adjust );
184
185
          if( TrPtr->success == 0 && ! (TrPtr->mode & _destSupplied))
186
              myfree( (void**)TrPtr->dest->data );
187
          break;
188
      
189
  }
190
}
191
192
193