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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
|
//
// Lynkeos
// $Id: MyImageList.m 585 2018-09-08 21:30:37Z j-etienne $
//
// Created by Jean-Etienne LAMIAUD on Wed Sep 24 2003.
// Copyright (c) 2003-2014. Jean-Etienne LAMIAUD
//
// 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 <math.h>
#import <AppKit/NSCell.h>
// V1 compatibility includes
#ifndef NO_FILE_FORMAT_COMPATIBILITY_CODE
//#include "MyImageAligner.h"
//#include "MyImageAnalyzer.h"
//#include "MyImageStacker.h"
//#include "MyDeconvolution.h"
//#include "MyUnsharpMask.h"
//#include "MyDocument.h"
#endif
#include "MyImageList.h"
#include "MyImageListEnumerator.h"
#include "MyMultiPassImageEnumerator.h"
#include "LynkeosFourierBuffer.h"
static NSString * const K_LIST_KEY = @"images";
static NSString * const K_BLACK_LEVEL_KEY = @"blackl";
static NSString * const K_WHITE_LEVEL_KEY = @"whitel";
static NSString * const K_GAMMA_CORRECTION_KEY = @"gamma";
//! Key for saving the stacked image
static NSString * const K_IMAGE_KEY = @"stack";
//! Key for saving the parameters
@interface MyImageList(Private)
- (void) connectParametersChain ;
@end
@implementation MyImageList(Private)
- (void) connectParametersChain
{
// Connect the parameters chain
NSEnumerator *en = [_list objectEnumerator];
MyImageListItem *item;
while( (item = [en nextObject]) != nil )
[item setParametersParent:_parameters];
}
@end
@implementation MyImageList
//==============================================================================
// Coding
//==============================================================================
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_list forKey:K_LIST_KEY];
[super encodeWithCoder:encoder];
}
- (id) initWithCoder:(NSCoder *)decoder
{
if ( (self = [super initWithCoder:decoder]) != nil )
{
if ( [decoder containsValueForKey:K_LIST_KEY] )
{
id stack;
// List data
_list = [[decoder decodeObjectForKey:K_LIST_KEY] retain];
// Compatibility for versions < V2.2
if ( _originalImage == nil )
{
// Stack data
if ( (stack = [decoder decodeObjectForKey:K_IMAGE_KEY]) != nil
&& [stack conformsToProtocol:@protocol(LynkeosImageBuffer)] )
{
_originalImage = [stack retain];
_processedImage = stack;
_size.width = [_originalImage width];
_size.height = [_originalImage height];
_nPlanes = [_originalImage numberOfPlanes];
}
// We don't even try to read stack from V1.0 .. V1.2 file as the
// endianness issues would be too hard to solve.
}
// Only global black and white for V2.1 and earlier
if ( _originalImage != nil &&
[decoder containsValueForKey:K_BLACK_LEVEL_KEY] &&
[decoder containsValueForKey:K_WHITE_LEVEL_KEY] )
{
double vmin, vmax;
u_short c;
_black = (double*)malloc( sizeof(double)*(_nPlanes+1) );
_white = (double*)malloc( sizeof(double)*(_nPlanes+1) );
_gamma = (double*)malloc( sizeof(double)*(_nPlanes+1) );
_black[_nPlanes] = [decoder decodeDoubleForKey:K_BLACK_LEVEL_KEY];
_white[_nPlanes] = [decoder decodeDoubleForKey:K_WHITE_LEVEL_KEY];
_gamma[_nPlanes] = [decoder decodeDoubleForKey:K_GAMMA_CORRECTION_KEY];
if ( _gamma[_nPlanes] == 0.0 )
_gamma[_nPlanes] = 1.0;
[_originalImage getMinLevel:&vmin maxLevel:&vmax];
for( c = 0; c < _nPlanes; c++ )
{
_black[c] = vmin;
_white[c] = vmax;
_gamma[c] = 1.0;
}
}
[self connectParametersChain];
}
else
{
// File format is not compatible, abort loading
[self release];
self = nil;
}
}
return( self );
}
//==============================================================================
// Initializers, Constructors and destructors
//==============================================================================
- (id)init
{
if ( (self = [super init]) != nil )
{
_list = nil;
}
return self;
}
- (id) initWithArray :(NSArray*)list
{
if ( (self = [self init]) != nil )
{
_list = [[list mutableCopy] retain];
[self connectParametersChain];
}
return( self );
}
+ (id) imageListWithArray :(NSArray*)list
{
return( [[[self alloc] initWithArray:list] autorelease] );
}
- (void) dealloc
{
[_list release];
[super dealloc];
}
//==============================================================================
// Read accessors
//==============================================================================
// List
- (NSMutableArray*) imageArray { return( _list ); }
// Enumerator access
- (id <LynkeosProcessableItem>) firstItem
{
NSEnumerator* list = [self imageEnumeratorStartAt:nil
directSense:YES
skipUnselected:YES];
return( [list nextObject] );
}
- (id <LynkeosProcessableItem>) lastItem
{
NSEnumerator* list = [self imageEnumeratorStartAt:nil
directSense:NO
skipUnselected:YES];
return( [list nextObject] );
}
- (NSEnumerator*)imageEnumerator
{
return( [[[MyImageListEnumerator alloc] initWithImageList:_list]
autorelease] );
}
- (NSEnumerator*) imageEnumeratorStartAt:(id)item
directSense:(BOOL)direct
skipUnselected:(BOOL)skip
{
return( [[[MyImageListEnumerator alloc] initWithImageList:_list
startAt:item
directSense:direct
skipUnselected:skip]
autorelease] );
}
- (NSEnumerator <LynkeosMultiPassEnumerator> *)
multiPassImageEnumeratorStartAt:(id)item
directSense:(BOOL)direct
skipUnselected:(BOOL)skip
{
return( [[[MyMultiPassImageEnumerator alloc] initWithImageList:_list
startAt:item
directSense:direct
skipUnselected:skip]
autorelease] );
}
//==============================================================================
// Actions
//==============================================================================
- (BOOL) addItem :(MyImageListItem*)item
{
if ( _list == nil )
_list = [[NSMutableArray array] retain];
[_list addObject: item];
// Connect the parameters chain
[item setParametersParent:_parameters];
return( YES );
}
- (BOOL) deleteItem :(MyImageListItem*)item
{
MyImageListItem *movie = [item getParent];
if ( movie != nil )
{
NSAssert( [_list containsObject:movie],
@"Cannot delete from a nonexistent movie!" );
[movie deleteChild:item];
// Remove the movie when empty
if ( [movie numberOfChildren] == 0 )
[_list removeObject:movie];
}
else
{
NSAssert( [_list containsObject:item],
@"Cannot delete a nonexistent item!" );
[_list removeObject:item];
}
// Clear the resulting image when list is emptied
if ( [_list count] == 0 )
[self setOriginalImage:nil];
return( YES );
}
- (void) setMode:(ListMode_t)mode
{
// Propagate the mode to the items in the list
NSEnumerator *list = [_list objectEnumerator];
MyImageListItem *item;
while ( (item = [list nextObject]) != nil )
[item setMode:mode];
}
#pragma mark LynkeosProcessable protocol
- (BOOL) changeItemSelection :(MyImageListItem*)item value:(BOOL)v
{
if ( [item getSelectionState] == (v ? NSOnState : NSOffState) )
return( NO );
// Set the desired value
[item setSelected:v];
return( YES );
}
- (void) setParametersParent :(LynkeosProcessingParameterMgr*)parent
{
if ( _parameters->_parent != nil )
[_parameters->_parent release];
_parameters->_parent = [parent retain];
}
- (void) setProcessingParameter:(id <LynkeosProcessingParameter>)parameter
withRef:(NSString*)ref
forProcessing:(NSString*)processing
{
[_parameters setProcessingParameter:parameter withRef:ref
forProcessing:processing];
// Propagate the dark frame and flat field down for optimisation
if ( processing == nil
&& ( [ref isEqual:myImageListItemDarkFrame]
|| [ref isEqual:myImageListItemFlatField] ) )
{
NSEnumerator *list;
MyImageListItem *item;
list = [_list objectEnumerator];
while( (item = [list nextObject]) != nil )
[item setProcessingParameter:parameter withRef:ref
forProcessing:processing];
}
// Notify of the change
[_parameters notifyItemModification:self];
}
- (NSDictionary*) getMetaData
{
return(nil);
}
@end
|