001 /* 002 * Lanczos3Filter 003 * 004 * Copyright (c) 2002, 2003 Marco Schmidt. 005 * All rights reserved. 006 */ 007 008 package net.sourceforge.jiu.geometry; 009 010 /** 011 * The Lanczos 3 resample filter. 012 * @author Marco Schmidt 013 * @since 0.10.0 014 * @see Resample 015 * @see ResampleFilter 016 */ 017 public class Lanczos3Filter extends ResampleFilter 018 { 019 private double sinc(double value) 020 { 021 if (value != 0.0f) 022 { 023 value = value * Math.PI; 024 return Math.sin(value) / value; 025 } 026 else 027 { 028 return 1.0; 029 } 030 } 031 032 public float apply(float value) 033 { 034 if (value < 0.0f) 035 { 036 value = -value; 037 } 038 if (value < 3.0f) 039 { 040 return (float)(sinc(value) * sinc(value / 3.0)); 041 } 042 else 043 { 044 return 0.0f; 045 } 046 } 047 048 public String getName() 049 { 050 return "Lanczos3"; 051 } 052 053 public float getRecommendedSamplingRadius() 054 { 055 return 3.0f; 056 } 057 }