home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / edtplug / classes / netscape / test / plugin / composer / ImageEncoderTest.java < prev    next >
Encoding:
Java Source  |  1998-04-08  |  3.4 KB  |  88 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. package netscape.test.plugin.composer;
  20. import netscape.plugin.composer.ImageEncoder;
  21. import java.awt.Image;
  22. import java.awt.image.*;
  23. import java.io.*;
  24.  
  25. public class ImageEncoderTest {
  26.     public static void Test(String[] args, ImageEncoder encoder){
  27.         ImageEncoderTest test = new ImageEncoderTest(args);
  28.         test.test(encoder);
  29.         System.exit(0);
  30.     }
  31.  
  32.     public ImageEncoderTest(String[] args){
  33.     }
  34.  
  35.     public void test(ImageEncoder encoder){
  36.         try {
  37.             // plugin.setProperties(createProperties());
  38.             System.out.println("ImageEncoder class: " + encoder.getClass().toString());
  39.             System.out.println("              name: " + encoder.getName());
  40.             System.out.println("    file extension: " + encoder.getFileExtension());
  41.             byte[] type = new byte[4];
  42.             encoder.getFileType(type);
  43.             System.out.print("    file type: ");
  44.             for(int i = 0; i < 4; i++ ) {
  45.                 System.out.print(" " + type[i] + "'" + (char) (type[i]) + "'");
  46.             }
  47.             System.out.println("\n");
  48.             System.out.println("        hint: " + encoder.getHint());
  49.             System.out.println("needsQuantizedSource: " + encoder.needsQuantizedSource());
  50.             System.out.println("-------------------------------");
  51.             File file = new File("Test." + encoder.getFileExtension());
  52.             OutputStream out = new FileOutputStream(file);
  53.             ImageProducer in = createImageProducer(encoder.needsQuantizedSource());
  54.             boolean result = encoder.encode(in, out);
  55.             System.out.println("-------------------------------");
  56.             System.out.println("Encoder returned: " + result);
  57.             out.close();
  58.         } catch ( IOException e) {
  59.             e.printStackTrace();
  60.         }
  61.     }
  62.  
  63.     protected ImageProducer createImageProducer(boolean needsQuantizedSource){
  64.         int w = 512;
  65.         int h = 512;
  66.         int pix[] = new int[w * h];
  67.         int index = 0;
  68.         int green = 0;
  69.         for (int y = 0; y < h; y++) {
  70.             int red = y & 0xff;
  71.             if ( needsQuantizedSource ) {
  72.                 red = ( y & 0xf ) << 4;
  73.             }
  74.             for (int x = 0; x < w; x++) {
  75.                 int blue = x & 0xff;
  76.                 if ( needsQuantizedSource ) {
  77.                     blue = ( x & 0xf ) << 4;
  78.                 }
  79.                 if ( ! needsQuantizedSource ) {
  80.                     green = ((x + y) / 4 ) & 0xff;
  81.                 }
  82.                 pix[index++] = (255 << 24) | (red << 16) | blue;
  83.             }
  84.         }
  85.         return new MemoryImageSource(w, h, pix, 0, w);
  86.     }
  87. }
  88.