bool CropInstance::ExecuteOn( View& view ) { if ( !view.IsMainView() ) return false; // should not happen! if ( p_margins == 0.0 ) { Console().WriteLn( "<end><cbr><* Identity *>" ); return true; } AutoViewLock lock( view ); ImageWindow window = view.Window(); ImageVariant image = view.Image(); Crop C( p_margins ); C.SetMode( static_cast<Crop::crop_mode>( p_mode ) ); C.SetResolution( p_resolution.x, p_resolution.y ); C.SetMetricResolution( p_metric ); C.SetFillValues( p_fillColor ); // Dimensions of target image int w0 = image.Width(); int h0 = image.Height(); // Dimensions of transformed image int width = w0, height = h0; C.GetNewSizes( width, height ); if ( width < 1 || height < 1 ) throw Error( "Crop: Invalid operation: Null target image dimensions" ); // On 32-bit systems, make sure the resulting image requires less than 4 GB. if ( sizeof( void* ) == sizeof( uint32 ) ) { uint64 sz = uint64( width )*uint64( height )*image.NumberOfChannels()*image.BytesPerSample(); if ( sz > uint64( uint32_max-256 ) ) throw Error( "Crop: Invalid operation: Target image dimensions would exceed four gigabytes" ); } DeleteAstrometryMetadataAndPreviewsAndMask( window ); Console().EnableAbort(); StandardStatus status; image.SetStatusCallback( &status ); C >> image; if ( p_forceResolution ) { Console().WriteLn( String().Format( "Setting resolution: h:%.3lf, v:%.3lf, u:px/%s", p_resolution.x, p_resolution.y, p_metric ? "cm" : "inch" ) ); window.SetResolution( p_resolution.x, p_resolution.y, p_metric ); } return true; }
bool RotationInstance::ExecuteOn( View& view ) { if ( !view.IsMainView() ) return false; // should never reach this point! AutoViewLock lock( view ); ImageVariant image = view.Image(); if ( image.IsComplexSample() ) return false; double degrees = Round( Deg( p_angle ), 4 ); if ( degrees == 0 ) { Console().WriteLn( "<end><cbr><* Identity *>" ); return true; } ImageWindow window = view.Window(); window.RemoveMaskReferences(); window.RemoveMask(); window.DeletePreviews(); Console().EnableAbort(); StandardStatus status; image.SetStatusCallback( &status ); if ( p_optimizeFast ) switch ( TruncI( degrees ) ) { case 90: Rotate90CCW() >> image; return true; case -90: Rotate90CW() >> image; return true; case 180: case -180: Rotate180() >> image; return true; default: break; } AutoPointer<PixelInterpolation> interpolation( NewInterpolation( p_interpolation, 1, 1, 1, 1, true, p_clampingThreshold, p_smoothness, image ) ); Rotation T( *interpolation, p_angle ); /* * On 32-bit systems, make sure the resulting image requires less than 4 GB. */ if ( sizeof( void* ) == sizeof( uint32 ) ) { int width = image.Width(), height = image.Height(); T.GetNewSizes( width, height ); uint64 sz = uint64( width )*uint64( height )*image.NumberOfChannels()*image.BytesPerSample(); if ( sz > uint64( uint32_max-256 ) ) throw Error( "Rotation: Invalid operation: Target image dimensions would exceed four gigabytes" ); } T.SetFillValues( p_fillColor ); T >> image; return true; }