Source Code Cross Referenced for ParameterBlockUtilTest.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » ca » forklabs » media » jai » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » Java Advanced Imaging » ca.forklabs.media.jai 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#) $Header: /cvs/jai-operators/src/tests/ca/forklabs/media/jai/ParameterBlockUtilTest.java,v 1.5 2007/06/13 18:54:43 forklabs Exp $
003:         *
004:         * Copyright (C) 2007  Forklabs Daniel Léonard
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License
008:         * as published by the Free Software Foundation; either version 2
009:         * of the License, or (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         */
020:
021:        package ca.forklabs.media.jai;
022:
023:        import java.awt.image.DataBuffer;
024:        import java.awt.image.RenderedImage;
025:        import java.awt.image.renderable.RenderableImage;
026:        import java.net.MalformedURLException;
027:        import java.net.URL;
028:        import javax.media.jai.BorderExtender;
029:        import javax.media.jai.ImageFunction;
030:        import javax.media.jai.Interpolation;
031:        import javax.media.jai.ParameterBlockJAI;
032:        import javax.media.jai.operator.AddConstDescriptor;
033:        import javax.media.jai.operator.BandMergeDescriptor;
034:        import javax.media.jai.operator.BandSelectDescriptor;
035:        import javax.media.jai.operator.BorderDescriptor;
036:        import javax.media.jai.operator.BoxFilterDescriptor;
037:        import javax.media.jai.operator.ConstantDescriptor;
038:        import javax.media.jai.operator.CropDescriptor;
039:        import javax.media.jai.operator.DFTDescriptor;
040:        import javax.media.jai.operator.ExpDescriptor;
041:        import javax.media.jai.operator.ExtremaDescriptor;
042:        import javax.media.jai.operator.FileLoadDescriptor;
043:        import javax.media.jai.operator.FileStoreDescriptor;
044:        import javax.media.jai.operator.FormatDescriptor;
045:        import javax.media.jai.operator.IDFTDescriptor;
046:        import javax.media.jai.operator.ImageFunctionDescriptor;
047:        import javax.media.jai.operator.LogDescriptor;
048:        import javax.media.jai.operator.MeanDescriptor;
049:        import javax.media.jai.operator.MultiplyComplexDescriptor;
050:        import javax.media.jai.operator.MultiplyConstDescriptor;
051:        import javax.media.jai.operator.MultiplyDescriptor;
052:        import javax.media.jai.operator.NullDescriptor;
053:        import javax.media.jai.operator.PeriodicShiftDescriptor;
054:        import javax.media.jai.operator.RescaleDescriptor;
055:        import javax.media.jai.operator.ScaleDescriptor;
056:        import javax.media.jai.operator.SubsampleAverageDescriptor;
057:        import javax.media.jai.operator.SubtractConstDescriptor;
058:        import javax.media.jai.operator.SubtractDescriptor;
059:        import javax.media.jai.operator.URLDescriptor;
060:        import javax.media.jai.registry.RenderableRegistryMode;
061:        import javax.media.jai.registry.RenderedRegistryMode;
062:        import junit.framework.TestCase;
063:        import ca.forklabs.media.jai.ParameterBlockUtil;
064:        import ca.forklabs.media.jai.mock.MockImageFunction;
065:        import ca.forklabs.media.jai.mock.MockRenderableImage;
066:        import ca.forklabs.media.jai.mock.MockRenderedImage;
067:
068:        /**
069:         * Class {@code ParameterBlockUtilTest} tests class {@link ParameterBlockUtil}.
070:         *
071:         * @author   <a href="mailto:forklabs at dev.java.net?subject=ca.forklabs.media.jai.ParameterBlockUtilTest">Daniel Léonard</a>
072:         * @version $Revision: 1.5 $
073:         */
074:        @SuppressWarnings("nls")
075:        public class ParameterBlockUtilTest extends TestCase {
076:
077:            //---------------------------
078:            // Constructors
079:            //---------------------------
080:
081:            /**
082:             * Constructor.
083:             * @param   name   the name of this test.
084:             */
085:            public ParameterBlockUtilTest(String name) {
086:                super (name);
087:            }
088:
089:            //---------------------------
090:            // Test methods
091:            //---------------------------
092:
093:            /**
094:             * Tests the two basic creation methods.
095:             */
096:            public void testcreateParameterBlock() {
097:                ParameterBlockJAI pb;
098:
099:                // for rendered images
100:                RenderedImage rendered_image = new MockRenderedImage();
101:                pb = ParameterBlockUtil.createParameterBlock("exp",
102:                        rendered_image);
103:                assertEquals(ExpDescriptor.class, pb.getOperationDescriptor()
104:                        .getClass());
105:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
106:                assertSame(rendered_image, pb.getSource(0));
107:
108:                // for renderable image
109:                RenderableImage renderable_image = new MockRenderableImage();
110:                pb = ParameterBlockUtil.createParameterBlock("exp",
111:                        renderable_image);
112:                assertEquals(ExpDescriptor.class, pb.getOperationDescriptor()
113:                        .getClass());
114:                assertEquals(RenderableRegistryMode.MODE_NAME, pb.getMode());
115:                assertSame(renderable_image, pb.getSource(0));
116:            }
117:
118:            /**
119:             * Tests the creation of parameter blocks for operation <em>addconst</em>.
120:             */
121:            public void testAddConst() {
122:                RenderedImage source = new MockRenderedImage();
123:                ParameterBlockJAI pb = ParameterBlockUtil
124:                        .createAddConstParameterBlock(source);
125:
126:                assertEquals(AddConstDescriptor.class, pb
127:                        .getOperationDescriptor().getClass());
128:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
129:                assertSame(source, pb.getSource(0));
130:
131:                assertEquals(1, pb.getNumParameters());
132:                double[] constants = (double[]) pb
133:                        .getObjectParameter("constants");
134:                assertEquals(1, constants.length);
135:                assertEquals(0.0, constants[0], 10e-6);
136:            }
137:
138:            /**
139:             * Tests the creation of parameter blocks for operation <em>bandmerge</em>.
140:             */
141:            public void testBandMerge() {
142:                RenderedImage source = new MockRenderedImage();
143:                ParameterBlockJAI pb = ParameterBlockUtil
144:                        .createBandMergeParameterBlock(source, source, source,
145:                                source, source);
146:
147:                assertEquals(BandMergeDescriptor.class, pb
148:                        .getOperationDescriptor().getClass());
149:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
150:                assertEquals(5, pb.getNumSources());
151:                assertSame(source, pb.getSource(0));
152:                assertSame(source, pb.getSource(1));
153:                assertSame(source, pb.getSource(2));
154:                assertSame(source, pb.getSource(3));
155:                assertSame(source, pb.getSource(4));
156:
157:                assertEquals(0, pb.getNumParameters());
158:            }
159:
160:            /**
161:             * Tests the creation of parameter blocks for operation <em>bandselect</em>.
162:             */
163:            public void testBandSelect() {
164:                RenderedImage source = new MockRenderedImage();
165:                ParameterBlockJAI pb = ParameterBlockUtil
166:                        .createBandSelectParameterBlock(source, 5, 2);
167:
168:                assertEquals(BandSelectDescriptor.class, pb
169:                        .getOperationDescriptor().getClass());
170:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
171:                assertSame(source, pb.getSource(0));
172:
173:                assertEquals(1, pb.getNumParameters());
174:                int[] bands = (int[]) pb.getObjectParameter("bandIndices");
175:                assertEquals(2, bands.length);
176:                assertEquals(5, bands[0]);
177:                assertEquals(2, bands[1]);
178:            }
179:
180:            /**
181:             * Tests the creation of parameter blocks for operation <em>border</em>.
182:             */
183:            @SuppressWarnings("boxing")
184:            public void testBorder() {
185:                RenderedImage source = new MockRenderedImage();
186:                ParameterBlockJAI pb = ParameterBlockUtil
187:                        .createBorderParameterBlock(source, 5);
188:
189:                assertEquals(BorderDescriptor.class, pb
190:                        .getOperationDescriptor().getClass());
191:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
192:                assertSame(source, pb.getSource(0));
193:
194:                assertEquals(5, pb.getNumParameters());
195:                assertEquals(5, pb.getObjectParameter("leftPad"));
196:                assertEquals(5, pb.getObjectParameter("rightPad"));
197:                assertEquals(5, pb.getObjectParameter("topPad"));
198:                assertEquals(5, pb.getObjectParameter("bottomPad"));
199:                assertEquals(BorderExtender
200:                        .createInstance(BorderExtender.BORDER_ZERO), pb
201:                        .getObjectParameter("type"));
202:            }
203:
204:            /**
205:             * Tests the creation of parameter blocks for operation <em>boxfilter</em>.
206:             */
207:            @SuppressWarnings("boxing")
208:            public void testBoxFilter() {
209:                RenderedImage source = new MockRenderedImage();
210:                ParameterBlockJAI pb = ParameterBlockUtil
211:                        .createBoxFilterParameterBlock(source, 5);
212:
213:                assertEquals(BoxFilterDescriptor.class, pb
214:                        .getOperationDescriptor().getClass());
215:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
216:                assertSame(source, pb.getSource(0));
217:
218:                assertEquals(4, pb.getNumParameters());
219:                assertEquals(5, pb.getObjectParameter("width"));
220:                assertEquals(5, pb.getObjectParameter("height"));
221:                assertEquals(2, pb.getObjectParameter("xKey"));
222:                assertEquals(2, pb.getObjectParameter("yKey"));
223:            }
224:
225:            /**
226:             * Tests the creation of parameter blocks for operation <em>constant</em>.
227:             */
228:            @SuppressWarnings("boxing")
229:            public void testCrop() {
230:                RenderedImage source = new MockRenderedImage();
231:                float x = (float) Math.PI;
232:                float y = (float) Math.E;
233:                float width = (float) Math.PI;
234:                float height = (float) Math.E;
235:                ParameterBlockJAI pb = ParameterBlockUtil
236:                        .createCropParameterBlock(source, x, y, width, height);
237:
238:                assertEquals(CropDescriptor.class, pb.getOperationDescriptor()
239:                        .getClass());
240:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
241:                assertSame(source, pb.getSource(0));
242:
243:                assertEquals(4, pb.getNumParameters());
244:                assertEquals(x, pb.getObjectParameter("x"));
245:                assertEquals(y, pb.getObjectParameter("y"));
246:                assertEquals(width, pb.getObjectParameter("width"));
247:                assertEquals(height, pb.getObjectParameter("height"));
248:            }
249:
250:            /**
251:             * Tests the creation of parameter blocks for operation <em>constant</em>.
252:             */
253:            @SuppressWarnings("boxing")
254:            public void testConstant() {
255:                float width = (float) Math.PI;
256:                float height = (float) Math.E;
257:                Number[] values = new Double[] { Math.PI, Math.E, };
258:                ParameterBlockJAI pb = ParameterBlockUtil
259:                        .createConstantParameterBlock(width, height, values);
260:
261:                assertEquals(ConstantDescriptor.class, pb
262:                        .getOperationDescriptor().getClass());
263:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
264:                assertEquals(0, pb.getNumSources());
265:
266:                assertEquals(3, pb.getNumParameters());
267:                assertEquals(width, pb.getObjectParameter("width"));
268:                assertEquals(height, pb.getObjectParameter("height"));
269:                assertSame(values, pb.getObjectParameter("bandValues"));
270:            }
271:
272:            /**
273:             * Tests the creation of parameter blocks for operation <em>dft</em>.
274:             */
275:            @SuppressWarnings("boxing")
276:            public void testDFT() {
277:                RenderedImage source = new MockRenderedImage();
278:                ParameterBlockJAI pb = ParameterBlockUtil
279:                        .createDFTParameterBlock(source);
280:
281:                assertEquals(DFTDescriptor.class, pb.getOperationDescriptor()
282:                        .getClass());
283:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
284:                assertSame(source, pb.getSource(0));
285:
286:                assertEquals(2, pb.getNumParameters());
287:                assertEquals(DFTDescriptor.SCALING_NONE, pb
288:                        .getObjectParameter("scalingType"));
289:                assertEquals(DFTDescriptor.REAL_TO_COMPLEX, pb
290:                        .getObjectParameter("dataNature"));
291:            }
292:
293:            /**
294:             * Tests the creation of parameter blocks for operation <em>exp</em>.
295:             */
296:            public void testExp() {
297:                RenderedImage source = new MockRenderedImage();
298:                ParameterBlockJAI pb = ParameterBlockUtil
299:                        .createExpParameterBlock(source);
300:
301:                assertEquals(ExpDescriptor.class, pb.getOperationDescriptor()
302:                        .getClass());
303:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
304:                assertSame(source, pb.getSource(0));
305:
306:                assertEquals(0, pb.getNumParameters());
307:            }
308:
309:            /**
310:             * Tests the creation of parameter blocks for operation <em>extrema</em>.
311:             */
312:            @SuppressWarnings("boxing")
313:            public void testExtrema() {
314:                RenderedImage source = new MockRenderedImage();
315:                ParameterBlockJAI pb = ParameterBlockUtil
316:                        .createExtremaParameterBlock(source);
317:
318:                assertEquals(ExtremaDescriptor.class, pb
319:                        .getOperationDescriptor().getClass());
320:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
321:                assertSame(source, pb.getSource(0));
322:
323:                assertEquals(5, pb.getNumParameters());
324:                assertNull(pb.getObjectParameter("roi"));
325:                assertEquals(1, pb.getObjectParameter("xPeriod"));
326:                assertEquals(1, pb.getObjectParameter("yPeriod"));
327:                assertEquals(false, pb.getObjectParameter("saveLocations"));
328:                assertEquals(1, pb.getObjectParameter("maxRuns"));
329:            }
330:
331:            /**
332:             * Tests the creation of parameter blocks for operation <em>fileload</em>.
333:             */
334:            @SuppressWarnings("boxing")
335:            public void testFileLoad() {
336:                String filename = "./image.jpg";
337:                ParameterBlockJAI pb = ParameterBlockUtil
338:                        .createFileLoadParameterBlock(filename);
339:
340:                assertEquals(FileLoadDescriptor.class, pb
341:                        .getOperationDescriptor().getClass());
342:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
343:                assertEquals(0, pb.getNumSources());
344:
345:                assertEquals(3, pb.getNumParameters());
346:                assertEquals(filename, pb.getObjectParameter("filename"));
347:                assertEquals(null, pb.getObjectParameter("param"));
348:                assertEquals(true, pb.getObjectParameter("checkFileLocally"));
349:            }
350:
351:            /**
352:             * Tests the creation of parameter blocks for operation <em>filestore</em>.
353:             */
354:            @SuppressWarnings("boxing")
355:            public void testFileStore() {
356:                RenderedImage source = new MockRenderedImage();
357:                String filename = "./image.jpg";
358:                ParameterBlockJAI pb = ParameterBlockUtil
359:                        .createFileStoreParameterBlock(source, filename);
360:
361:                assertEquals(FileStoreDescriptor.class, pb
362:                        .getOperationDescriptor().getClass());
363:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
364:                assertEquals(source, pb.getSource(0));
365:
366:                assertEquals(4, pb.getNumParameters());
367:                assertEquals(filename, pb.getObjectParameter("filename"));
368:                assertEquals("jpg", pb.getObjectParameter("format"));
369:                assertEquals(null, pb.getObjectParameter("param"));
370:                assertEquals(true, pb.getObjectParameter("checkFileLocally"));
371:            }
372:
373:            /**
374:             * Tests the creation of parameter blocks for operation <em>format</em>.
375:             */
376:            @SuppressWarnings("boxing")
377:            public void testFormat() {
378:                RenderedImage source = new MockRenderedImage();
379:                int type = DataBuffer.TYPE_DOUBLE;
380:                ParameterBlockJAI pb = ParameterBlockUtil
381:                        .createFormatParameterBlock(source, type);
382:
383:                assertEquals(FormatDescriptor.class, pb
384:                        .getOperationDescriptor().getClass());
385:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
386:                assertSame(source, pb.getSource(0));
387:
388:                assertEquals(1, pb.getNumParameters());
389:                assertEquals(type, pb.getObjectParameter("dataType"));
390:            }
391:
392:            /**
393:             * Tests the creation of parameter blocks for operation <em>idft</em>.
394:             */
395:            @SuppressWarnings("boxing")
396:            public void testIDFT() {
397:                RenderedImage source = new MockRenderedImage();
398:                ParameterBlockJAI pb = ParameterBlockUtil
399:                        .createIDFTParameterBlock(source);
400:
401:                assertEquals(IDFTDescriptor.class, pb.getOperationDescriptor()
402:                        .getClass());
403:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
404:                assertSame(source, pb.getSource(0));
405:
406:                assertEquals(2, pb.getNumParameters());
407:                assertEquals(IDFTDescriptor.SCALING_DIMENSIONS, pb
408:                        .getObjectParameter("scalingType"));
409:                assertEquals(IDFTDescriptor.COMPLEX_TO_REAL, pb
410:                        .getObjectParameter("dataNature"));
411:            }
412:
413:            /**
414:             * Tests the creation of parameter blocks for operation
415:             * <em>imagefunction</em>.
416:             */
417:            public void testImageFunction() {
418:                ImageFunction function = new MockImageFunction();
419:                ParameterBlockJAI pb = ParameterBlockUtil
420:                        .createImageFunctionParameterBlock(function, 5, 5);
421:
422:                assertEquals(ImageFunctionDescriptor.class, pb
423:                        .getOperationDescriptor().getClass());
424:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
425:                assertEquals(0, pb.getNumSources());
426:
427:                assertEquals(7, pb.getNumParameters());
428:                assertSame(function, pb.getObjectParameter("function"));
429:                assertEquals(5, pb.getIntParameter("width"));
430:                assertEquals(5, pb.getIntParameter("height"));
431:                assertEquals(1.0f, pb.getFloatParameter("xScale"), 10e-6f);
432:                assertEquals(1.0f, pb.getFloatParameter("yScale"), 10e-6f);
433:                assertEquals(0.0f, pb.getFloatParameter("xTrans"), 10e-6f);
434:                assertEquals(0.0f, pb.getFloatParameter("yTrans"), 10e-6f);
435:            }
436:
437:            /**
438:             * Tests the creation of parameter blocks for operation <em>log</em>.
439:             */
440:            public void testLog() {
441:                RenderedImage source = new MockRenderedImage();
442:                ParameterBlockJAI pb = ParameterBlockUtil
443:                        .createLogParameterBlock(source);
444:
445:                assertEquals(LogDescriptor.class, pb.getOperationDescriptor()
446:                        .getClass());
447:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
448:                assertSame(source, pb.getSource(0));
449:
450:                assertEquals(0, pb.getNumParameters());
451:            }
452:
453:            /**
454:             * Tests the creation of parameter blocks for operation <em>mean</em>.
455:             */
456:            @SuppressWarnings("boxing")
457:            public void testMean() {
458:                RenderedImage source = new MockRenderedImage();
459:                ParameterBlockJAI pb = ParameterBlockUtil
460:                        .createMeanParameterBlock(source);
461:
462:                assertEquals(MeanDescriptor.class, pb.getOperationDescriptor()
463:                        .getClass());
464:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
465:                assertSame(source, pb.getSource(0));
466:
467:                assertEquals(3, pb.getNumParameters());
468:                assertEquals(1, pb.getObjectParameter("xPeriod"));
469:                assertEquals(1, pb.getObjectParameter("yPeriod"));
470:                assertEquals(null, pb.getObjectParameter("roi"));
471:            }
472:
473:            /**
474:             * Tests the creation of parameter blocks for operation <em>multiply</em>.
475:             */
476:            @SuppressWarnings("boxing")
477:            public void testMultiply() {
478:                RenderedImage source0 = new MockRenderedImage();
479:                RenderedImage source1 = new MockRenderedImage();
480:                ParameterBlockJAI pb = ParameterBlockUtil
481:                        .createMultiplyParameterBlock(source0, source1);
482:
483:                assertEquals(MultiplyDescriptor.class, pb
484:                        .getOperationDescriptor().getClass());
485:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
486:                assertSame(source0, pb.getSource(0));
487:                assertSame(source1, pb.getSource(1));
488:            }
489:
490:            /**
491:             * Tests the creation of parameter blocks for operation <em>multiplycomplex</em>.
492:             */
493:            @SuppressWarnings("boxing")
494:            public void testMultiplyComplex() {
495:                RenderedImage source0 = new MockRenderedImage();
496:                RenderedImage source1 = new MockRenderedImage();
497:                ParameterBlockJAI pb = ParameterBlockUtil
498:                        .createMultiplyComplexParameterBlock(source0, source1);
499:
500:                assertEquals(MultiplyComplexDescriptor.class, pb
501:                        .getOperationDescriptor().getClass());
502:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
503:                assertSame(source0, pb.getSource(0));
504:                assertSame(source1, pb.getSource(1));
505:            }
506:
507:            /**
508:             * Tests the creation of parameter blocks for operation <em>multiplyconst</em>.
509:             */
510:            public void testMultiplyConst() {
511:                RenderedImage source = new MockRenderedImage();
512:                ParameterBlockJAI pb = ParameterBlockUtil
513:                        .createMultiplyConstParameterBlock(source);
514:
515:                assertEquals(MultiplyConstDescriptor.class, pb
516:                        .getOperationDescriptor().getClass());
517:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
518:                assertSame(source, pb.getSource(0));
519:
520:                assertEquals(1, pb.getNumParameters());
521:                double[] constants = (double[]) pb
522:                        .getObjectParameter("constants");
523:                assertEquals(1, constants.length);
524:                assertEquals(1.0, constants[0], 10e-6);
525:            }
526:
527:            /**
528:             * Tests the creation of parameter blocks for operation <em>null</em>.
529:             */
530:            public void testNull() {
531:                ParameterBlockJAI pb;
532:
533:                RenderedImage rendered_source = new MockRenderedImage();
534:                pb = ParameterBlockUtil
535:                        .createNullParameterBlock(rendered_source);
536:
537:                assertEquals(NullDescriptor.class, pb.getOperationDescriptor()
538:                        .getClass());
539:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
540:                assertSame(rendered_source, pb.getSource(0));
541:                assertEquals(0, pb.getNumParameters());
542:
543:                RenderableImage renderable_source = new MockRenderableImage();
544:                pb = ParameterBlockUtil
545:                        .createNullParameterBlock(renderable_source);
546:
547:                assertEquals(NullDescriptor.class, pb.getOperationDescriptor()
548:                        .getClass());
549:                assertEquals(RenderableRegistryMode.MODE_NAME, pb.getMode());
550:                assertSame(renderable_source, pb.getSource(0));
551:                assertEquals(0, pb.getNumParameters());
552:            }
553:
554:            /**
555:             * Tests the creation of parameter blocks for operation
556:             * <em>periodicshift</em>.
557:             */
558:            public void testPeriodicShift() {
559:                ParameterBlockJAI pb;
560:
561:                RenderedImage rendered_source = new MockRenderedImage() {
562:                    @Override
563:                    public int getHeight() {
564:                        return 16;
565:                    }
566:
567:                    @Override
568:                    public int getWidth() {
569:                        return 18;
570:                    }
571:                };
572:                pb = ParameterBlockUtil
573:                        .createPeriodicShiftParameterBlock(rendered_source);
574:
575:                assertEquals(PeriodicShiftDescriptor.class, pb
576:                        .getOperationDescriptor().getClass());
577:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
578:                assertSame(rendered_source, pb.getSource(0));
579:                assertEquals(2, pb.getNumParameters());
580:                assertEquals(9, pb.getIntParameter("shiftX"));
581:                assertEquals(8, pb.getIntParameter("shiftY"));
582:
583:                RenderableImage renderable_source = new MockRenderableImage() {
584:                    @Override
585:                    public float getHeight() {
586:                        return 16.0f;
587:                    }
588:
589:                    @Override
590:                    public float getWidth() {
591:                        return 18.0f;
592:                    }
593:                };
594:                pb = ParameterBlockUtil
595:                        .createPeriodicShiftParameterBlock(renderable_source);
596:                assertEquals(PeriodicShiftDescriptor.class, pb
597:                        .getOperationDescriptor().getClass());
598:                assertEquals(RenderableRegistryMode.MODE_NAME, pb.getMode());
599:                assertSame(renderable_source, pb.getSource(0));
600:                assertEquals(2, pb.getNumParameters());
601:                assertEquals(9, pb.getIntParameter("shiftX"));
602:                assertEquals(8, pb.getIntParameter("shiftY"));
603:            }
604:
605:            /**
606:             * Tests the creation of parameter blocks for operation <em>rescale</em>.
607:             */
608:            public void testRescale() {
609:                RenderedImage source = new MockRenderedImage();
610:                ParameterBlockJAI pb = ParameterBlockUtil
611:                        .createRescaleParameterBlock(source);
612:
613:                assertEquals(RescaleDescriptor.class, pb
614:                        .getOperationDescriptor().getClass());
615:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
616:                assertSame(source, pb.getSource(0));
617:
618:                assertEquals(2, pb.getNumParameters());
619:
620:                double[] constants = (double[]) pb
621:                        .getObjectParameter("constants");
622:                assertEquals(1, constants.length);
623:                assertEquals(1.0, constants[0], 10e-6);
624:
625:                double[] offsets = (double[]) pb.getObjectParameter("offsets");
626:                assertEquals(1, offsets.length);
627:                assertEquals(0.0, offsets[0], 10e-6);
628:            }
629:
630:            /**
631:             * Tests the creation of parameter blocks for operation <em>scale</em>.
632:             */
633:            @SuppressWarnings("boxing")
634:            public void testScale() {
635:                ParameterBlockJAI pb;
636:
637:                RenderedImage source = new MockRenderedImage();
638:                float sx = (float) Math.PI;
639:                float sy = (float) Math.E;
640:
641:                pb = ParameterBlockUtil.createScaleParameterBlock(source, sx,
642:                        sy);
643:                assertEquals(ScaleDescriptor.class, pb.getOperationDescriptor()
644:                        .getClass());
645:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
646:                assertSame(source, pb.getSource(0));
647:
648:                assertEquals(5, pb.getNumParameters());
649:                assertEquals(sx, pb.getObjectParameter("xScale"));
650:                assertEquals(sy, pb.getObjectParameter("yScale"));
651:                assertEquals(0.0f, pb.getObjectParameter("xTrans"));
652:                assertEquals(0.0f, pb.getObjectParameter("yTrans"));
653:                assertEquals(Interpolation
654:                        .getInstance(Interpolation.INTERP_NEAREST), pb
655:                        .getObjectParameter("interpolation"));
656:
657:                Interpolation interpolation = Interpolation
658:                        .getInstance(Interpolation.INTERP_BILINEAR);
659:                pb = ParameterBlockUtil.createScaleParameterBlock(source, sx,
660:                        sy, interpolation);
661:                assertEquals(ScaleDescriptor.class, pb.getOperationDescriptor()
662:                        .getClass());
663:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
664:                assertSame(source, pb.getSource(0));
665:
666:                assertEquals(5, pb.getNumParameters());
667:                assertEquals(sx, pb.getObjectParameter("xScale"));
668:                assertEquals(sy, pb.getObjectParameter("yScale"));
669:                assertEquals(0.0f, pb.getObjectParameter("xTrans"));
670:                assertEquals(0.0f, pb.getObjectParameter("yTrans"));
671:                assertEquals(interpolation, pb
672:                        .getObjectParameter("interpolation"));
673:            }
674:
675:            /**
676:             * Tests the creation of parameter blocks for operation <em>scale</em>.
677:             */
678:            @SuppressWarnings("boxing")
679:            public void testSubsampleAverage() {
680:                RenderedImage source = new MockRenderedImage();
681:                double sx = 1.0 / 7.0;
682:                double sy = 99.0 / 100.0;
683:
684:                ParameterBlockJAI pb = ParameterBlockUtil
685:                        .createSubSampleAverageParameterBlock(source, sx, sy);
686:                assertEquals(SubsampleAverageDescriptor.class, pb
687:                        .getOperationDescriptor().getClass());
688:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
689:                assertSame(source, pb.getSource(0));
690:
691:                assertEquals(2, pb.getNumParameters());
692:                assertEquals(sx, pb.getObjectParameter("scaleX"));
693:                assertEquals(sy, pb.getObjectParameter("scaleY"));
694:            }
695:
696:            /**
697:             * Tests the creation of parameter blocks for operation <em>subtract</em>.
698:             */
699:            public void testSubtract() {
700:                RenderedImage source1 = new MockRenderedImage();
701:                RenderedImage source2 = new MockRenderedImage();
702:                ParameterBlockJAI pb = ParameterBlockUtil
703:                        .createSubtractParameterBlock(source1, source2);
704:
705:                assertEquals(SubtractDescriptor.class, pb
706:                        .getOperationDescriptor().getClass());
707:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
708:                assertSame(source1, pb.getSource(0));
709:                assertSame(source2, pb.getSource(1));
710:
711:                assertEquals(0, pb.getNumParameters());
712:            }
713:
714:            /**
715:             * Tests the creation of parameter blocks for operation <em>subtractconst</em>.
716:             */
717:            public void testSubtractConst() {
718:                RenderedImage source = new MockRenderedImage();
719:                ParameterBlockJAI pb = ParameterBlockUtil
720:                        .createSubtractConstParameterBlock(source);
721:
722:                assertEquals(SubtractConstDescriptor.class, pb
723:                        .getOperationDescriptor().getClass());
724:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
725:                assertSame(source, pb.getSource(0));
726:
727:                assertEquals(1, pb.getNumParameters());
728:                double[] constants = (double[]) pb
729:                        .getObjectParameter("constants");
730:                assertEquals(1, constants.length);
731:                assertEquals(0.0, constants[0], 10e-6);
732:            }
733:
734:            /**
735:             * Tests the creation of parameter blocks for operation <em>url</em>.
736:             * @throws MalformedURLException
737:             */
738:            public void testUrl() throws MalformedURLException {
739:                URL url = new URL(
740:                        "http://www.java.net/images/header_jnet_new.jpg");
741:                ParameterBlockJAI pb = ParameterBlockUtil
742:                        .createUrlParameterBlock(url);
743:
744:                assertEquals(URLDescriptor.class, pb.getOperationDescriptor()
745:                        .getClass());
746:                assertEquals(RenderedRegistryMode.MODE_NAME, pb.getMode());
747:
748:                assertEquals(2, pb.getNumParameters());
749:
750:                assertSame(url, pb.getObjectParameter("URL"));
751:                assertNull(pb.getObjectParameter("param"));
752:            }
753:
754:            //---------------------------
755:            // Class methods
756:            //---------------------------
757:
758:            /**
759:             * Runs only this test.
760:             * @param   args   ignored.
761:             */
762:            public static void main(String... args) {
763:                junit.swingui.TestRunner.run(ParameterBlockUtilTest.class);
764:            }
765:
766:        }
767:
768:        /*
769:         * $Log: ParameterBlockUtilTest.java,v $
770:         * Revision 1.5  2007/06/13 18:54:43  forklabs
771:         * Added many more parameter block factories.
772:         *
773:         * Revision 1.4  2007/06/05 20:48:26  forklabs
774:         * More factories.
775:         *
776:         * Revision 1.3  2007/06/05 02:08:43  forklabs
777:         * Added new factories.
778:         *
779:         * Revision 1.2  2007/05/10 17:56:17  forklabs
780:         * Added factory for operation url.
781:         *
782:         * Revision 1.1  2007/05/03 20:23:57  forklabs
783:         * Class ParameterBlockUtil.
784:         *
785:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.