File: MyImageStacker_Standard.m

package info (click to toggle)
lynkeos.app 3.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 15,740 kB
  • sloc: objc: 36,412; ansic: 684; cpp: 148; sh: 68; makefile: 21
file content (211 lines) | stat: -rw-r--r-- 5,713 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//
//  Lynkeos
//  $Id: MyImageStacker_Standard.m 589 2018-11-21 22:13:30Z j-etienne $
//
//  Created by Jean-Etienne LAMIAUD on 01/01/11.
//  Copyright 2011-2018 Jean-Etienne LAMIAUD. All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
#include <objc/runtime.h>

#include "MyImageStacker_Standard.h"

// Private (and temporary) parameter used to recombine the stacks
static NSString * const myStandardImageStackerResult = @"StandardStackerResult";

static LynkeosStandardImageBuffer *getPlanarData(id <LynkeosImageBuffer> img)
{
   if ([img isKindOfClass:[LynkeosStandardImageBuffer class]]
       && ![(LynkeosStandardImageBuffer*)img hasCustomFormat])
      return img;
   else
   {
      LynkeosStandardImageBuffer *newImg
         = [LynkeosStandardImageBuffer imageBufferWithNumberOfPlanes:[img numberOfPlanes]
                                                               width:[img width]
                                                              height:[img height]];
      [img convertToPlanar:[newImg colorPlanes] withPlanes:newImg->_nPlanes lineWidth:newImg->_padw];
      return newImg;
   }
}

/*!
 * @abstract Result of the standard stacking strategy
 */
@interface StandardImageStackerResult : NSObject <LynkeosProcessingParameter>
{
@public
   LynkeosStandardImageBuffer* _mono; //!< Stack of monochrome image
   LynkeosStandardImageBuffer* _rgb;  //!< Stack of colour images
}
@end

@implementation StandardImageStackerResult
- (id) init
{
   self = [super init];
   if ( self != nil )
   {
      _mono = nil;
      _rgb = nil;
   }
   
   return( self );
}

- (void) dealloc
{
   if ( _mono != nil )
      [_mono release];
   if ( _rgb != nil )
      [_rgb release];
   
   [super dealloc];
}

// This parameter is deleted at process end, it cannot be saved
- (void)encodeWithCoder:(NSCoder *)encoder
{
   [self doesNotRecognizeSelector:_cmd];
}
- (id)initWithCoder:(NSCoder *)decoder
{
   [self doesNotRecognizeSelector:_cmd];
   return( nil );
}
@end

@implementation MyImageStacker_Standard

- (id) init
{
   if ( (self = [super init]) != nil )
   {
      _params = nil;
      _monoStack = nil;
      _rgbStack = nil;
   }

   return( self );
}

- (id) initWithParameters: (id <NSObject>)params
                     list: (id <LynkeosImageList>)list
{
   if ( (self = [self init]) != nil )
   {
      NSAssert1( [params isMemberOfClass:[MyImageStackerParameters class]],
                 @"Wrong parameter class %s for Image stacker (standard)",
                 class_getName([params class]) );
      _params = (MyImageStackerParameters*)[params retain];
   }

   return( self );
}

- (void) dealloc
{
   if ( _monoStack != nil )
      [_monoStack release];
   if ( _rgbStack != nil )
      [_rgbStack release];

   [super dealloc];
}

- (void) processImage: (id <LynkeosImageBuffer>)image
{
   LynkeosStandardImageBuffer **sum;

   if ( [image numberOfPlanes] == 1 )
      sum = &_monoStack;
   else
      sum = &_rgbStack;

   // If this is the first image, keep it as stack buffer
   if ( *sum == nil )
      *sum = [image retain];
   else
      // Accumulate
      [*sum add:image];
}

- (void) finishOneProcessingThreadInList:(id <LynkeosImageList>)list ;
{
   // Recombine the stacks in the list
   StandardImageStackerResult *res
      = [list getProcessingParameterWithRef:myStandardImageStackerResult
                              forProcessing:myImageStackerRef];

   if ( res == nil )
   {
      res = [[[StandardImageStackerResult alloc] init] autorelease];
      [list setProcessingParameter:res withRef:myStandardImageStackerResult
                     forProcessing:myImageStackerRef];
   }

   if ( _monoStack != nil )
   {
      if ( res->_mono != nil )
         [res->_mono add:_monoStack];
      else
         res->_mono = [_monoStack retain];
   }
   if ( _rgbStack != nil )
   {
      if ( res->_rgb != nil )
         [res->_rgb add:_rgbStack];
      else
         res->_rgb = [_rgbStack retain];
   }
}

- (void) finishAllProcessingInList: (id <LynkeosImageList>)list;
{
   // Recombine monochrome and RGB stacks if needed
   StandardImageStackerResult *res
      = [list getProcessingParameterWithRef:myStandardImageStackerResult
                              forProcessing:myImageStackerRef];
   LynkeosStandardImageBuffer *stack = nil;

   if ( res->_rgb != nil )
      // Make it planar if needed
      stack = [getPlanarData(res->_rgb) retain];

   if ( res->_mono != nil )
   {
      if ( stack == nil )
         stack = [getPlanarData(res->_mono) retain];
      else
         // Add code knows how to add L with RGB
         [stack add:res->_mono];
   }

   if ( _rgbStack != nil )
      [_rgbStack release];
   _rgbStack = stack;
   if ( _monoStack != nil )
      [_monoStack release];
   _monoStack = nil;

   // And get rid of the recombining parameter
   [list setProcessingParameter:nil withRef:myStandardImageStackerResult 
                  forProcessing:myImageStackerRef];   
}

- (LynkeosStandardImageBuffer*) stackingResult { return( _rgbStack ); }

@end