Author: nbelaevski
Date: 2009-07-07 20:01:28 -0400 (Tue, 07 Jul 2009)
New Revision: 14825
Added:
framework/trunk/api/src/
framework/trunk/impl/generatescript.xml
framework/trunk/impl/src/
framework/trunk/test-base/src/
Removed:
framework/trunk/api/src/main/java/org/ajax4jsf/model/QueueImpl.java
framework/trunk/impl/src/main/java/org/ajax4jsf/context/SAXEndElementEvent.java
framework/trunk/impl/src/main/java/org/ajax4jsf/context/SAXStartElementEvent.java
framework/trunk/impl/src/main/java/org/ajax4jsf/context/SAXTextEvent.java
framework/trunk/impl/src/main/java/org/ajax4jsf/model/
framework/trunk/impl/src/main/java/org/ajax4jsf/resource/image/DiffusionFilterOp.java
framework/trunk/impl/src/main/java/org/ajax4jsf/resource/image/GIFEncoder.java
framework/trunk/impl/src/main/java/org/ajax4jsf/resource/image/Quantize.java
framework/trunk/impl/src/main/java/org/richfaces/model/ExtendedDataTableModifiableModel.java
framework/trunk/impl/src/main/java/org/richfaces/model/ExtendedTableDataModelWrapper.java
Modified:
framework/trunk/api/pom.xml
framework/trunk/impl/pom.xml
framework/trunk/pom.xml
framework/trunk/test-base/pom.xml
framework/trunk/version-matrix/pom.xml
Log:
- framework moved into new build system
- legacy classes removed: SAX*Event, QueueImpl and GIF SPI
Modified: framework/trunk/api/pom.xml
===================================================================
--- framework/trunk/api/pom.xml 2009-07-07 23:36:18 UTC (rev 14824)
+++ framework/trunk/api/pom.xml 2009-07-08 00:01:28 UTC (rev 14825)
@@ -15,4 +15,30 @@
<artifactId>richfaces-api</artifactId>
<name>Java Server Faces AJAX framework API</name>
+ <dependencies>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <version>1.7.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ <version>2.4</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
</project>
\ No newline at end of file
Copied: framework/trunk/api/src (from rev 14808, branches/jsf2.0/framework/api/src)
Deleted: framework/trunk/api/src/main/java/org/ajax4jsf/model/QueueImpl.java
===================================================================
---
branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/model/QueueImpl.java 2009-07-07
13:08:56 UTC (rev 14808)
+++ framework/trunk/api/src/main/java/org/ajax4jsf/model/QueueImpl.java 2009-07-08
00:01:28 UTC (rev 14825)
@@ -1,96 +0,0 @@
-package org.ajax4jsf.model;
-
-import javax.el.ValueExpression;
-import javax.faces.context.FacesContext;
-
-/**
- * @author Konstantin Mishin
- *
- */
-public class QueueImpl implements Queue {
-
- private FacesContext context;
-
- private ValueExpression nameExpression;
-
- private ValueExpression requestDelayExpression;
-
- private ValueExpression timeoutExpression;
-
- private ValueExpression ignoreDupResponsesExpression;
-
- private ValueExpression limitToListExpression;
-
- public QueueImpl() {
- this(null);
- }
-
- public QueueImpl(FacesContext context) {
- if(context == null) {
- this.context = FacesContext.getCurrentInstance();
- } else {
- this.context = context;
- }
- }
-
- public String getName() {
- String name = null;
- if (nameExpression != null) {
- name = (String) nameExpression.getValue(context.getELContext());
- }
- return name;
- }
-
- public Integer getRequestDelay() {
- Integer requestDelay = null;
- if (requestDelayExpression != null) {
- requestDelay = (Integer) requestDelayExpression.getValue(context.getELContext());
- }
- return requestDelay;
- }
-
- public Integer getTimeout() {
- Integer timeout = null;
- if (timeoutExpression != null) {
- timeout = (Integer) timeoutExpression.getValue(context.getELContext());
- }
- return timeout;
- }
-
- public Boolean getIgnoreDupResponses() {
- Boolean ignoreDupResponses = null;
- if (ignoreDupResponsesExpression != null) {
- ignoreDupResponses = (Boolean)
ignoreDupResponsesExpression.getValue(context.getELContext());
- }
- return ignoreDupResponses;
- }
-
- public Boolean getLimitToList() {
- Boolean limitToList = null;
- if (limitToListExpression != null) {
- limitToList = (Boolean) limitToListExpression.getValue(context.getELContext());
- }
- return limitToList;
- }
-
- public void setNameExpression(ValueExpression nameExpression) {
- this.nameExpression = nameExpression;
- }
-
- public void setRequestDelayExpression(ValueExpression requestDelayExpression) {
- this.requestDelayExpression = requestDelayExpression;
- }
-
- public void setTimeoutExpression(ValueExpression timeoutExpression) {
- this.timeoutExpression = timeoutExpression;
- }
-
- public void setIgnoreDupResponsesExpression(
- ValueExpression ignoreDupResponsesExpression) {
- this.ignoreDupResponsesExpression = ignoreDupResponsesExpression;
- }
-
- public void setLimitToListExpression(ValueExpression limitToListExpression) {
- this.limitToListExpression = limitToListExpression;
- }
-}
Copied: framework/trunk/impl/generatescript.xml (from rev 14817,
branches/jsf2.0/framework/impl/generatescript.xml)
===================================================================
--- framework/trunk/impl/generatescript.xml (rev 0)
+++ framework/trunk/impl/generatescript.xml 2009-07-08 00:01:28 UTC (rev 14825)
@@ -0,0 +1,157 @@
+<?xml version="1.0"?>
+<!-- ======================================================================
+ 12.11.2005 23:40:43
+
+ assemblescripts
+ Assemble all javaScript library files to one AJAXJSF.js
+
+ shura
+ ====================================================================== -->
+<project name="assemblescripts" default="assembly">
+ <description>
+ Assemble all javaScript library files to one AJAXJSF.js
+ </description>
+
+ <property name="scripts-path"
value="org/ajax4jsf/javascript/scripts"></property>
+ <property name="prototype-scripts-path"
value="org/ajax4jsf/javascript/scripts"></property>
+ <property name="scriptaculous-scripts-path"
value="org/richfaces/renderkit/html/scripts/scriptaculous"></property>
+ <property name="jquery-scripts-path"
value="org/richfaces/renderkit/html/scripts/jquery"></property>
+
+ <property name="target-dir"
value="${project.build.directory}/javascript"></property>
+
+ <property name="scripts.dir"
+ value="${target-dir}/${scripts-path}"
+ />
+ <property name="prototype.scripts.dir"
+ value="${target-dir}/${prototype-scripts-path}"
+ />
+ <property name="script" value="AJAX.js" />
+
+ <property name="script.rico"
value="rico.js"></property>
+ <property name="script.aculo"
value="scriptaculo.js"></property>
+ <property name="script.scriptaculous"
value="scriptaculous.js"></property>
+ <property name="scriptaculous.scripts.dir"
+ value="${target-dir}/${scriptaculous-scripts-path}"/>
+ <property name="jquery.scripts.dir"
+ value="${target-dir}/${jquery-scripts-path}"/>
+
+ <property name="script.prototype"
value="prototype.js"></property>
+ <property name="script.jquery"
value="jquery.js"></property>
+
+ <property name="script.imagecache"
value="imagecache.js"></property>
+ <property name="script.dnd" value="dnd.js"></property>
+ <property name="script.css-rules"
value="css-rules.js"></property>
+ <filelist id="imagecache"
dir="${basedir}/src/main/javascript/ajaxjsf"
files="imagecache.js"></filelist>
+<!--
+ <filelist id="prototype"
+ dir="${basedir}/src/main/javascript/prototype"
+
files="empty.js,base.js,string.js,enumerable.js,array.js,hash.js,range.js"
+ >
+-->
+ <filelist id="jquery"
+ dir="${basedir}/src/main/javascript/jquery"
+ files="jquery-1.3.2.js,../memory.js,patches.js">
+ </filelist>
+
+ <filelist id="scriptaculous"
+ dir="${basedir}/src/main/javascript/scriptaculous"
+
files="builder.js,effects.js,dragdrop.js,controls.js,slider.js,sound.js" >
+ </filelist>
+
+
+ <filelist id="prototype"
+ dir="${basedir}/src/main/javascript/prototype"
+ files="prototype-1.6.0.3.js,../memory.js,patches.js">
+ </filelist>
+
+
+ <filelist id="dnd"
+ dir="${basedir}/src/main/javascript/dnd"
+ files="prolog.js,dnd.js,epilog.js">
+ </filelist>
+
+ <filelist id="ajaxjsf"
dir="${basedir}/src/main/javascript/ajaxjsf"
files="prolog.js,sarissa.js,JSFAJAX.js,queue.js,log4ajax.js,epilog.js,../memory.js"></filelist>
+ <!-- =================================
+ target: assemble
+ ================================= -->
+ <target name="assembly"
+ depends="depends"
+ description="--> Assemble all javaScript library files to one
AJAXJSF.js"
+ >
+ <concat append="false"
+ binary="false"
+ destfile="${scripts.dir}/${script}"
+ fixlastline="yes"
+ eol="unix"
+ >
+ <filelist refid="ajaxjsf">
+ </filelist>
+ </concat>
+ <concat append="false"
+ binary="false"
+ destfile="${scripts.dir}/${script.imagecache}"
+ fixlastline="yes"
+ eol="unix"
+ >
+ <filelist refid="imagecache"/>
+ </concat>
+ <concat append="false"
+ binary="false"
+ destfile="${scripts.dir}/${script.dnd}"
+ fixlastline="yes"
+ eol="unix"
+ >
+ <filelist refid="dnd"/>
+ </concat>
+ <concat append="false"
+ binary="false"
+ destfile="${prototype.scripts.dir}/${script.prototype}"
+ fixlastline="yes"
+ eol="unix">
+ <filelist refid="prototype">
+ </filelist>
+ </concat>
+ <concat append="false"
+ binary="false"
+ destfile="${scriptaculous.scripts.dir}/${script.scriptaculous}"
+ fixlastline="yes"
+ eol="unix"
+ >
+ <filelist refid="scriptaculous"></filelist>
+ </concat>
+
+ <concat append="false"
+ binary="false"
+ destfile="${jquery.scripts.dir}/${script.jquery}"
+ fixlastline="yes"
+ eol="unix"
+ >
+ <filelist refid="jquery"></filelist>
+ </concat>
+
+
+ <copy todir="${prototype.scripts.dir}"
file="${basedir}/src/main/javascript/ajaxjsf/smartposition.js">
+ </copy>
+ <copy todir="${scriptaculous.scripts.dir}">
+ <fileset
dir="${basedir}/src/main/javascript/scriptaculous"></fileset>
+ </copy>
+ </target>
+
+
+ <!-- =================================
+ target: fixeol
+ ================================= -->
+ <target name="fixeol" depends="depends"
description="--> Fix CR/LF in files">
+ <fixcrlf srcdir="${basedir}" includes="*.js"
eol="unix">
+ </fixcrlf>
+ </target>
+
+
+ <!-- - - - - - - - - - - - - - - - - -
+ target: depends
+ - - - - - - - - - - - - - - - - - -->
+ <target name="depends">
+ </target>
+
+</project>
+
Modified: framework/trunk/impl/pom.xml
===================================================================
--- framework/trunk/impl/pom.xml 2009-07-07 23:36:18 UTC (rev 14824)
+++ framework/trunk/impl/pom.xml 2009-07-08 00:01:28 UTC (rev 14825)
@@ -13,13 +13,138 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.richfaces.framework</groupId>
<artifactId>richfaces-impl</artifactId>
- <name>JSF ajax framework implementation</name>
+ <name>JSF ajax framework implementation</name>
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ <resource>
+ <directory>target/javascript</directory>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>javacc-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>javacc</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>javascript</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <tasks>
+ <ant antfile="${basedir}/generatescript.xml"
inheritRefs="true">
+ <target name="assembly" />
+ <property name="target-dir"
value="${project.build.directory}/javascript" />
+ </ant>
+ </tasks>
+ <resourceRoot>${project.build.directory}/javascript</resourceRoot>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>maven-javascript-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compress</goal>
+ </goals>
+ <configuration>
+ <nosuffix>false</nosuffix>
+ <outputDirectory>${project.build.directory}/compressed/</outputDirectory>
+ <aggregations>
+ <aggregation>
+ <insertNewLine>true</insertNewLine>
+ <output>${project.build.outputDirectory}/org/ajax4jsf/framework.pack.js</output>
+ <includes>
+ <include>${project.build.directory}/compressed/org/ajax4jsf/javascript/scripts/prototype-min.js</include>
+ <include>${project.build.directory}/compressed/org/ajax4jsf/javascript/scripts/AJAX-min.js</include>
+ <include>${project.build.directory}/compressed/org/richfaces/renderkit/html/scripts/scriptaculous/scriptaculous-min.js</include>
+ <include>${project.build.directory}/compressed/org/richfaces/renderkit/html/scripts/jquery/jquery-min.js</include>
+ <include>${project.build.directory}/compressed/org/richfaces/renderkit/html/scripts/jquery.utils-min.js</include>
+ <include>${project.build.directory}/compressed/org/ajax4jsf/javascript/scripts/dnd-min.js</include>
+ <include>**/*-min.js</include>
+ </includes>
+ <excludes>
+ <exclude>**/*.pack.js</exclude>
+ <exclude>**/scriptaculous/*.js</exclude>
+ <exclude>**/extend-min.js</exclude>
+ <exclude>**/jquery.jcarousel-min.js</exclude>
+ <exclude>**/compressed.css</exclude>
+ </excludes>
+ </aggregation>
+ </aggregations>
+ <resources>
+ <resource>
+ <directory>target/javascript</directory>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ <execution>
+ <id>jslint</id>
+ <phase>test</phase>
+ <goals>
+ <goal>jslint</goal>
+ </goals>
+ <configuration>
+ <includes>
+ <include>**/framework.pack.js</include>
+ </includes>
+ <resources>
+ <resource>
+ <directory>${project.build.outputDirectory}</directory>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>richfaces-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-digester</groupId>
+ <artifactId>commons-digester</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>opensymphony</groupId>
+ <artifactId>oscache</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.nekohtml</groupId>
+ <artifactId>nekohtml</artifactId>
+ <optional>true</optional>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Copied: framework/trunk/impl/src (from rev 14807, branches/jsf2.0/framework/impl/src)
Deleted: framework/trunk/impl/src/main/java/org/ajax4jsf/context/SAXEndElementEvent.java
===================================================================
---
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/context/SAXEndElementEvent.java 2009-07-07
12:45:54 UTC (rev 14807)
+++
framework/trunk/impl/src/main/java/org/ajax4jsf/context/SAXEndElementEvent.java 2009-07-08
00:01:28 UTC (rev 14825)
@@ -1,49 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.ajax4jsf.context;
-
-
-/**
- * Created 19.07.2008
- * @author Nick Belaevski
- * @since 3.2.2
- */
-
-public class SAXEndElementEvent {
-
- private String name;
-
- public SAXEndElementEvent(String name) {
- super();
-
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- @Override
- public String toString() {
- return "</" + name + ">";
- }
-}
Deleted:
framework/trunk/impl/src/main/java/org/ajax4jsf/context/SAXStartElementEvent.java
===================================================================
---
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/context/SAXStartElementEvent.java 2009-07-07
12:45:54 UTC (rev 14807)
+++
framework/trunk/impl/src/main/java/org/ajax4jsf/context/SAXStartElementEvent.java 2009-07-08
00:01:28 UTC (rev 14825)
@@ -1,80 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.ajax4jsf.context;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Created 19.07.2008
- * @author Nick Belaevski
- * @since 3.2.2
- */
-
-public class SAXStartElementEvent {
-
- private String name;
-
- private Map<String, String> attributes;
-
- /**
- * Constructor that parses string into map for usage in unit tests
- * @param name
- * @param attributesString
- */
- public SAXStartElementEvent(String name, String attributesString) {
- super();
- this.name = name;
-
- Map<String, String> attributes = null;
- if (attributesString != null) {
- attributes = new HashMap<String, String>();
- String[] split = attributesString.split(",");
- for (String s : split) {
- String[] split2 = s.split("=");
-
- attributes.put(split2[0], split2[1]);
- }
- }
-
- this.attributes = attributes;
- }
-
- public SAXStartElementEvent(String name, Map<String, String> attributes) {
- super();
- this.name = name;
- this.attributes = attributes;
- }
-
- public String getName() {
- return name;
- }
-
- public Map<String, String> getAttributes() {
- return attributes;
- }
-
- @Override
- public String toString() {
- return "<" + name + " " + attributes + " >";
- }
-}
Deleted: framework/trunk/impl/src/main/java/org/ajax4jsf/context/SAXTextEvent.java
===================================================================
---
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/context/SAXTextEvent.java 2009-07-07
12:45:54 UTC (rev 14807)
+++ framework/trunk/impl/src/main/java/org/ajax4jsf/context/SAXTextEvent.java 2009-07-08
00:01:28 UTC (rev 14825)
@@ -1,46 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.ajax4jsf.context;
-
-/**
- * Created 19.07.2008
- * @author Nick Belaevski
- * @since 3.2.2
- */
-
-public class SAXTextEvent {
- private String text;
-
- public SAXTextEvent(String text) {
- super();
- this.text = text;
- }
-
- public String getText() {
- return text;
- }
-
- @Override
- public String toString() {
- return "'" + text + "'";
- }
-}
Deleted:
framework/trunk/impl/src/main/java/org/ajax4jsf/resource/image/DiffusionFilterOp.java
===================================================================
---
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/resource/image/DiffusionFilterOp.java 2009-07-07
12:45:54 UTC (rev 14807)
+++
framework/trunk/impl/src/main/java/org/ajax4jsf/resource/image/DiffusionFilterOp.java 2009-07-08
00:01:28 UTC (rev 14825)
@@ -1,268 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Helma License Notice
- *
- * The contents of this file are subject to the Helma License
- * Version 2.0 (the "License"). You may not use this file except in
- * compliance with the License. A copy of the License is available at
- *
http://adele.helma.org/download/helma/license.txt
- *
- * Copyright 1998-2003 Helma Software. All Rights Reserved.
- *
- * $RCSfile: DiffusionFilterOp.java,v $
- * $Author: alexsmirnov $
- * $Revision: 1.1.2.1 $
- * $Date: 2007/01/09 18:59:06 $
- */
-
-/*
- * Code from com.jhlabs.image.DiffusionFilter, Java Image Processing
- * Copyright (C) Jerry Huxtable 1998
- *
http://www.jhlabs.com/ip/
- *
- * Conversion to a BufferedImageOp inspired by:
- *
http://www.peter-cockerell.net:8080/java/FloydSteinberg/FloydSteinbergFil...
- *
- */
-
-package org.ajax4jsf.resource.image;
-
-import java.awt.RenderingHints;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.awt.image.BufferedImage;
-import java.awt.image.BufferedImageOp;
-import java.awt.image.ColorModel;
-import java.awt.image.DataBufferByte;
-import java.awt.image.DataBufferInt;
-import java.awt.image.IndexColorModel;
-
-import org.ajax4jsf.Messages;
-
-public class DiffusionFilterOp implements BufferedImageOp {
-
- protected final static int[] diffusionMatrix = {
- 0, 0, 0,
- 0, 0, 7,
- 3, 5, 1,
- };
-
- private int[] matrix;
- private int sum;
- private boolean serpentine = true;
- private int[] colorMap;
-
- /**
- * Construct a DiffusionFilter
- */
- public DiffusionFilterOp() {
- setMatrix(diffusionMatrix);
- }
-
- /**
- * Set whether to use a serpentine pattern for return or not. This can reduce
'avalanche' artifacts in the output.
- * @param serpentine true to use serpentine pattern
- */
- public void setSerpentine(boolean serpentine) {
- this.serpentine = serpentine;
- }
-
- /**
- * Return the serpentine setting
- * @return the current setting
- */
- public boolean getSerpentine() {
- return serpentine;
- }
-
- public void setMatrix(int[] matrix) {
- this.matrix = matrix;
- sum = 0;
- for (int i = 0; i < matrix.length; i++)
- sum += matrix[i];
- }
-
- public int[] getMatrix() {
- return matrix;
- }
-
- /**
- * Do the filter operation
- *
- * @param src The source BufferedImage. Can be any type.
- * @param dst The destination image. If not null, must be of type TYPE_BYTE_INDEXED
- * @return A dithered version of src in a BufferedImage of type TYPE_BYTE_INDEXED
- */
- public BufferedImage filter(BufferedImage src, BufferedImage dst) {
-
- // If there's no dest. create one
- if (dst == null)
- dst = createCompatibleDestImage(src, null);
-
- // Otherwise check that the provided dest is an indexed image
- else if (dst.getType() != BufferedImage.TYPE_BYTE_INDEXED) {
- throw new
IllegalArgumentException(Messages.getMessage(Messages.BUFFER_TYPE_ERROR));
- }
-
- DataBufferByte dstBuffer = (DataBufferByte) dst.getRaster().getDataBuffer();
- byte dstData[] = dstBuffer.getData();
-
- // Other things to test are pixel bit strides, scanline stride and transfer type
- // Same goes for the source image
-
- IndexColorModel icm = (IndexColorModel) dst.getColorModel();
- colorMap = new int[icm.getMapSize()];
- icm.getRGBs(colorMap);
-
- int width = src.getWidth();
- int height = src.getHeight();
-
- DataBufferInt srcBuffer = (DataBufferInt) src.getRaster().getDataBuffer();
- int srcData[] = srcBuffer.getData();
-
- // This is the offset into the buffer of the current source pixel
- int index = 0;
-
- // Loop through each pixel
- for (int y = 0; y < height; y++) {
- boolean reverse = serpentine && (y & 1) == 1;
- int direction;
- if (reverse) {
- index = y * width + width - 1;
- direction = -1;
- } else {
- index = y * width;
- direction = 1;
- }
- for (int x = 0; x < width; x++) {
- int rgb1 = srcData[index];
- int a1 = (rgb1 >> 24) & 0xff;
- int r1 = (rgb1 >> 16) & 0xff;
- int g1 = (rgb1 >> 8) & 0xff;
- int b1 = rgb1 & 0xff;
-
- int idx = findIndex(r1, g1, b1, a1);
- dstData[index] = (byte) idx;
-
- int rgb2 = colorMap[idx];
- int a2 = (rgb2 >> 24) & 0xff;
- int r2 = (rgb2 >> 16) & 0xff;
- int g2 = (rgb2 >> 8) & 0xff;
- int b2 = rgb2 & 0xff;
-
- int er = r1 - r2;
- int eg = g1 - g2;
- int eb = b1 - b2;
- int ea = a1 - a2;
-
- for (int i = -1; i <= 1; i++) {
- int iy = i + y;
- if (0 <= iy && iy < height) {
- for (int j = -1; j <= 1; j++) {
- int jx = j + x;
- if (0 <= jx && jx < width) {
- int w;
- if (reverse)
- w = matrix[(i + 1) * 3 - j + 1];
- else
- w = matrix[(i + 1) * 3 + j + 1];
- if (w != 0) {
- int k = reverse ? index - j : index + j;
- rgb1 = srcData[k];
- a1 = ((rgb1 >> 24) & 0xff) + ea * w / sum;
- r1 = ((rgb1 >> 16) & 0xff) + er * w / sum;
- g1 = ((rgb1 >> 8) & 0xff) + eg * w / sum;
- b1 = (rgb1 & 0xff) + eb * w / sum;
-
- srcData[k] = ((clamp(a1) << 24) | clamp(r1)
<< 16)
- | (clamp(g1) << 8) | clamp(b1);
- }
- }
- }
- }
- }
- index += direction;
- }
- }
-
- return dst;
- }
-
- private static int clamp(int c) {
- if (c < 0)
- return 0;
- if (c > 255)
- return 255;
- return c;
- }
-
- int findIndex(int r1, int g1, int b1, int a1)
- throws ArrayIndexOutOfBoundsException {
- int idx = 0;
- long dist = Long.MAX_VALUE;
- for (int i = 0; i < colorMap.length; i++) {
- int rgb2 = colorMap[i];
- int a2 = (rgb2 >> 24) & 0xff;
- int r2 = (rgb2 >> 16) & 0xff;
- int g2 = (rgb2 >> 8) & 0xff;
- int b2 = rgb2 & 0xff;
-
- int da = a1 - a2;
- int dr = r1 - r2;
- int dg = g1 - g2;
- int db = b1 - b2;
-
- long newdist = da * da + dr * dr + dg * dg + db * db;
- if (newdist < dist) {
- idx = i;
- dist = newdist;
- }
- }
- return idx;
- }
-
- // This always returns an indexed image
- public BufferedImage createCompatibleDestImage(BufferedImage src,
- ColorModel destCM) {
- return new BufferedImage(src.getWidth(), src.getHeight(),
- BufferedImage.TYPE_BYTE_INDEXED);
- }
-
- // There are no rendering hints
- public RenderingHints getRenderingHints() {
- return null;
- }
-
- // No transformation, so return the source point
- public Point2D getPoint2D(Point2D srcPt, Point2D dstPt) {
- if (dstPt == null)
- dstPt = new Point2D.Float();
- dstPt.setLocation(srcPt.getX(), srcPt.getY());
- return dstPt;
- }
-
- // No transformation, so return the source bounds
- public Rectangle2D getBounds2D(BufferedImage src) {
- return src.getRaster().getBounds();
- }
-}
\ No newline at end of file
Deleted: framework/trunk/impl/src/main/java/org/ajax4jsf/resource/image/GIFEncoder.java
===================================================================
---
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/resource/image/GIFEncoder.java 2009-07-07
12:45:54 UTC (rev 14807)
+++
framework/trunk/impl/src/main/java/org/ajax4jsf/resource/image/GIFEncoder.java 2009-07-08
00:01:28 UTC (rev 14825)
@@ -1,554 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Helma License Notice
- *
- * The contents of this file are subject to the Helma License
- * Version 2.0 (the "License"). You may not use this file except in
- * compliance with the License. A copy of the License is available at
- *
http://adele.helma.org/download/helma/license.txt
- *
- * Copyright 1998-2003 Helma Software. All Rights Reserved.
- *
- * $RCSfile: GIFEncoder.java,v $
- * $Author: alexsmirnov $
- * $Revision: 1.1.2.1 $
- * $Date: 2007/01/09 18:59:03 $
- */
-
-/*
- * The GIF encoding routines are based on the Acme libary
- *
- * The following addaptions and extensions were added by Joerg Lehni:
- *
- * - encode now directly works on BufferedImage objects, the ImageEncoder
- * and ImageConsumer oriented frameworks has been removed.
- * - Only BufferedImages with IndexColorModel are taken, so no more
- * palette optimization with IntHashtable objects are necessary. If the
- * BufferedImage is in wrong format, helma.image.Quantizie is used to
- * convert it into a index based image.
- * - This version is much less space consuming as it only takes one sample
- * row of the rastered image at a time into memory during compression.
- * - The overall time for color reduction and gif compression should
- * therefore be greatly reduced.
- *
- * Acme Disclaimer:
- *
- * Transparency handling and variable bit size courtesy of Jack Palevich.
- *
- * Copyright (C)1996,1998 by Jef Poskanzer <jef(a)acme.com>. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * Visit the ACME Labs Java page for up-to-date versions of this and other
- * fine Java utilities:
http://www.acme.com/java/
- *
- * GifEncoder is adapted from ppmtogif, which is based on GIFENCOD by David
- * Rowley <mgardi(a)watdscu.waterloo.edu>. Lempel-Zim compression
- * based on "compress".
- *
- */
-
-package org.ajax4jsf.resource.image;
-
-import java.awt.image.BufferedImage;
-import java.awt.image.IndexColorModel;
-import java.awt.image.Raster;
-import java.io.DataOutput;
-import java.io.IOException;
-
-public class GIFEncoder {
- private boolean interlace = false;
-
- private int width, height;
- private Raster raster;
- // DataOutput is used for compatibility with ImageIO (see
helma.image.imageio.gif.GIFImageWriter)
- // otherwise, OutputStream would make much more sense here:
- private DataOutput out;
-
- private int curx, cury;
- private int countdown;
- private int pass;
- private int[] row;
-
- public void encode(BufferedImage bi, DataOutput out) throws IOException {
- encode(bi, out, false, null);
- }
-
- public void encode(BufferedImage bi, DataOutput out, boolean interlace,
- String comment) throws IOException {
- this.out = out;
- this.interlace = interlace;
-
- // make sure it's index colors:
- if (bi.getType() != BufferedImage.TYPE_BYTE_INDEXED)
- bi = Quantize.process(bi, 256, false, true);
-
- raster = bi.getRaster();
-
- width = bi.getWidth();
- height = bi.getHeight();
-
- int numPixels = width * height;
-
- IndexColorModel icm = (IndexColorModel) bi.getColorModel();
- int transparentIndex = icm.getTransparentPixel();
- int numColors = icm.getMapSize();
-
- // Figure out how many bits to use.
- int bitsPerPixel;
- if (numColors <= 2)
- bitsPerPixel = 1;
- else if (numColors <= 4)
- bitsPerPixel = 2;
- else if (numColors <= 16)
- bitsPerPixel = 4;
- else
- bitsPerPixel = 8;
-
- int initCodeSize;
-
- // Calculate number of bits we are expecting
- countdown = numPixels;
-
- // Indicate which pass we are on (if interlace)
- pass = 0;
-
- // The initial code size
- if (bitsPerPixel <= 1)
- initCodeSize = 2;
- else
- initCodeSize = bitsPerPixel;
-
- // Set up the current x and y position
- curx = 0;
- cury = 0;
- row = new int[width];
-
- // Write the Magic header
- writeString("GIF89a");
-
- // Write out the screen width and height
- writeWord(width);
- writeWord(height);
-
- // Indicate that there is a global colour map
- byte flags = (byte) 0x80; // Yes, there is a color map
- // OR in the resolution
- flags |= (byte) ((8 - 1) << 4);
- // Not sorted
- // OR in the Bits per Pixel
- flags |= (byte) ((bitsPerPixel - 1));
- // Write it out
- out.write(flags);
-
- // Write out the Background colour
- out.write((byte) 0);
-
- // Pixel aspect ratio - 1:1.
- //out.write((byte) 49);
- // Java's GIF reader currently has a bug, if the aspect ratio byte is
- // not zero it throws an ImageFormatException. It doesn't know that
- // 49 means a 1:1 aspect ratio. Well, whatever, zero works with all
- // the other decoders I've tried so it probably doesn't hurt.
- out.write((byte) 0);
-
- // Write out the Global Colour Map
- // Turn colors into colormap entries.
- int mapSize = 1 << bitsPerPixel;
- byte[] reds = new byte[mapSize], greens = new byte[mapSize], blues = new
byte[mapSize];
- icm.getReds(reds);
- icm.getGreens(greens);
- icm.getBlues(blues);
-
- for (int i = 0; i < mapSize; ++i) {
- out.write(reds[i]);
- out.write(greens[i]);
- out.write(blues[i]);
- }
-
- // Write out extension for transparent colour index, if necessary.
- if (transparentIndex != -1) {
- out.write((byte) '!');
- out.write((byte) 0xf9);
- out.write((byte) 4);
- out.write((byte) 1);
- out.write((byte) 0);
- out.write((byte) 0);
- out.write((byte) transparentIndex);
- out.write((byte) 0);
- }
-
- // Write an Image separator
- out.write((byte) ',');
-
- // Write the Image header
- writeWord(0); // leftOfs
- writeWord(0); // topOfs
- writeWord(width);
- writeWord(height);
-
- // Write out whether or not the image is interlaced
- if (interlace)
- out.write((byte) 0x40);
- else
- out.write((byte) 0x00);
-
- // Write out the initial code size
- out.write((byte) initCodeSize);
-
- // Go and actually compress the data
- compress(initCodeSize + 1);
-
- // Write out a Zero-length packet (to end the series)
- out.write((byte) 0);
-
- // Write out the comment
- if (comment != null && comment.length() > 0) {
- out.write((byte) 0x21);
- out.write((byte) 0xFE);
- out.write((byte) comment.length());
- writeString(comment);
- out.write((byte) 0);
- }
-
- // Write the GIF file terminator
- out.write((byte) ';');
- }
-
- // Return the next pixel from the image
- int getNextPixel() throws IOException {
- if (countdown == 0)
- return -1;
-
- --countdown;
-
- if (curx == 0)
- row = raster.getSamples(0, cury, width, 1, 0, row);
- int index = row[curx];
-
- // Bump the current X position
- ++curx;
-
- // If we are at the end of a scan line, set curx back to the beginning
- // If we are interlaced, bump the cury to the appropriate spot,
- // otherwise, just increment it.
- if (curx == width) {
- curx = 0;
-
- if (!interlace) {
- ++cury;
- } else {
- switch (pass) {
- case 0:
- cury += 8;
- if (cury >= height) {
- ++pass;
- cury = 4;
- }
- break;
-
- case 1:
- cury += 8;
- if (cury >= height) {
- ++pass;
- cury = 2;
- }
- break;
-
- case 2:
- cury += 4;
- if (cury >= height) {
- ++pass;
- cury = 1;
- }
- break;
-
- case 3:
- cury += 2;
- break;
- }
- }
- }
- return index;
- }
-
- void writeString(String str) throws IOException {
- byte[] buf = str.getBytes();
- out.write(buf);
- }
-
- // Write out a word to the GIF file
- void writeWord(int w) throws IOException {
- out.write((byte) (w & 0xff));
- out.write((byte) ((w >> 8) & 0xff));
- }
-
- // GIFCOMPR.C - GIF Image compression routines
- //
- // Lempel-Ziv compression based on 'compress'. GIF modifications by
- // David Rowley (mgardi(a)watdcsu.waterloo.edu)
-
- // General DEFINEs
-
- static final int BITS = 12;
-
- static final int HASH_SIZE = 5003; // 80% occupancy
-
- // GIF Image compression - modified 'compress'
- //
- // Based on: compress.c - File compression ala IEEE Computer, June 1984.
- //
- // By Authors: Spencer W. Thomas (decvax!harpo!utah-cs!utah-gr!thomas)
- // Jim McKie (decvax!mcvax!jim)
- // Steve Davies (decvax!vax135!petsd!peora!srd)
- // Ken Turkowski (decvax!decwrl!turtlevax!ken)
- // James A. Woods (decvax!ihnp4!ames!jaw)
- // Joe Orost (decvax!vax135!petsd!joe)
-
- private int numBits; // number of bits/code
- private int maxBits = BITS; // user settable max # bits/code
- private int maxCode; // maximum code, given numBits
- private int maxMaxCode = 1 << BITS; // should NEVER generate this code
-
- final int getMaxCode(int numBits) {
- return (1 << numBits) - 1;
- }
-
- private int[] hashTable = new int[HASH_SIZE];
- private int[] codeTable = new int[HASH_SIZE];
-
- private int freeEntry = 0; // first unused entry
-
- // block compression parameters -- after all codes are used up,
- // and compression rate changes, start over.
- private boolean clearFlag = false;
-
- // Algorithm: use open addressing double hashing (no chaining) on the
- // prefix code / next character combination. We do a variant of Knuth's
- // algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime
- // secondary probe. Here, the modular division first probe is gives way
- // to a faster exclusive-or manipulation. Also do block compression with
- // an adaptive reset, whereby the code table is cleared when the compression
- // ratio decreases, but after the table fills. The variable-length output
- // codes are re-sized at this point, and a special CLEAR code is generated
- // for the decompressor. Late addition: construct the table according to
- // file size for noticeable speed improvement on small files. Please direct
- // questions about this implementation to ames!jaw.
-
- private int initBits;
-
- private int clearCode;
- private int EOFCode;
-
- void compress(int initBits) throws IOException {
- // Set up the globals: initBits - initial number of bits
- this.initBits = initBits;
-
- // Set up the necessary values
- clearFlag = false;
- numBits = initBits;
- maxCode = getMaxCode(numBits);
-
- clearCode = 1 << (initBits - 1);
- EOFCode = clearCode + 1;
- freeEntry = clearCode + 2;
-
- charInit();
-
- int ent = getNextPixel();
-
- int hashShift = 0;
- for (int fcode = HASH_SIZE; fcode < 65536; fcode *= 2)
- ++hashShift;
- hashShift = 8 - hashShift; // set hash code range bound
-
- clearHash(); // clear hash table
-
- output(clearCode);
-
- int c;
- outerLoop: while ((c = getNextPixel()) != -1) {
- int fcode = (c << maxBits) + ent;
- int i = (c << hashShift) ^ ent; // xor hashing
-
- if (hashTable[i] == fcode) {
- ent = codeTable[i];
- continue;
- } else if (hashTable[i] >= 0) { // non-empty slot
- int disp = HASH_SIZE - i; // secondary hash (after G. Knott)
- if (i == 0)
- disp = 1;
- do {
- if ((i -= disp) < 0)
- i += HASH_SIZE;
-
- if (hashTable[i] == fcode) {
- ent = codeTable[i];
- continue outerLoop;
- }
- } while (hashTable[i] >= 0);
- }
- output(ent);
- ent = c;
- if (freeEntry < maxMaxCode) {
- codeTable[i] = freeEntry++; // code -> hashtable
- hashTable[i] = fcode;
- } else
- clearBlock();
- }
- // Put out the final code.
- output(ent);
- output(EOFCode);
- }
-
- // output
- //
- // Output the given code.
- // Inputs:
- // code: A numBits-bit integer. If == -1, then EOF. This assumes
- // that numBits =< wordsize - 1.
- // Outputs:
- // Outputs code to the file.
- // Assumptions:
- // Chars are 8 bits long.
- // Algorithm:
- // Maintain a BITS character long buffer (so that 8 codes will
- // fit in it exactly). Use the VAX insv instruction to insert each
- // code in turn. When the buffer fills up empty it and start over.
-
- int curAccum = 0;
- int curBits = 0;
-
- int masks[] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F,
- 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF,
- 0x7FFF, 0xFFFF };
-
- void output(int code) throws IOException {
- curAccum &= masks[curBits];
-
- if (curBits > 0)
- curAccum |= (code << curBits);
- else
- curAccum = code;
-
- curBits += numBits;
-
- while (curBits >= 8) {
- charOut((byte) (curAccum & 0xff));
- curAccum >>= 8;
- curBits -= 8;
- }
-
- // If the next entry is going to be too big for the code size,
- // then increase it, if possible.
- if (freeEntry > maxCode || clearFlag) {
- if (clearFlag) {
- maxCode = getMaxCode(numBits = initBits);
- clearFlag = false;
- } else {
- ++numBits;
- if (numBits == maxBits)
- maxCode = maxMaxCode;
- else
- maxCode = getMaxCode(numBits);
- }
- }
-
- if (code == EOFCode) {
- // At EOF, write the rest of the buffer.
- while (curBits > 0) {
- charOut((byte) (curAccum & 0xff));
- curAccum >>= 8;
- curBits -= 8;
- }
-
- charFlush();
- }
- }
-
- // Clear out the hash table
-
- // table clear for block compress
- void clearBlock() throws IOException {
- clearHash();
- freeEntry = clearCode + 2;
- clearFlag = true;
-
- output(clearCode);
- }
-
- // reset code table
- void clearHash() {
- for (int i = 0; i < HASH_SIZE; ++i)
- hashTable[i] = -1;
- }
-
- // GIF Specific routines
-
- // Number of characters so far in this 'packet'
- private int a_count;
-
- // Set up the 'byte output' routine
- void charInit() {
- a_count = 0;
- }
-
- // Define the storage for the packet accumulator
- private byte[] accum = new byte[256];
-
- // Add a character to the end of the current packet, and if it is 254
- // characters, flush the packet to disk.
- void charOut(byte c) throws IOException {
- accum[a_count++] = c;
- if (a_count >= 254)
- charFlush();
- }
-
- // Flush the packet to disk, and reset the accumulator
- void charFlush() throws IOException {
- if (a_count > 0) {
- out.write(a_count);
- out.write(accum, 0, a_count);
- a_count = 0;
- }
- }
-}
\ No newline at end of file
Deleted: framework/trunk/impl/src/main/java/org/ajax4jsf/resource/image/Quantize.java
===================================================================
---
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/resource/image/Quantize.java 2009-07-07
12:45:54 UTC (rev 14807)
+++
framework/trunk/impl/src/main/java/org/ajax4jsf/resource/image/Quantize.java 2009-07-08
00:01:28 UTC (rev 14825)
@@ -1,840 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Helma License Notice
- *
- * The contents of this file are subject to the Helma License
- * Version 2.0 (the "License"). You may not use this file except in
- * compliance with the License. A copy of the License is available at
- *
http://adele.helma.org/download/helma/license.txt
- *
- * Copyright 1998-2003 Helma Software. All Rights Reserved.
- *
- * $RCSfile: Quantize.java,v $
- * $Author: alexsmirnov $
- * $Revision: 1.1.2.1 $
- * $Date: 2007/01/09 18:59:05 $
- */
-
-package org.ajax4jsf.resource.image;
-
-import java.awt.image.BufferedImage;
-import java.awt.image.DataBufferByte;
-import java.awt.image.DataBufferInt;
-import java.awt.image.IndexColorModel;
-
-/*
- * @(#)Quantize.java 0.90 9/19/00 Adam Doppelt
- *
- * Modifications by Joerg Lehni:
- *
- * - Support for alpha-channels.
- * - Returns a BufferedImage of TYPE_BYTE_INDEXED with a IndexColorModel.
- * - Dithering of images through helma.image.DiffusionFilterOp by setting
- * the dither parameter to true.
- * - Support for a transparent color, which is correctly rendered by GIFEncoder.
- * All pixels with alpha < 0x80 are converted to this color when the parameter
- * alphaToBitmask is set to true.
- * - Removed the SQUARES lookup tables as multiplications of integer values
- * shouldn't take more than one clock nowadays anyhow.
- */
-
-/**
- * An efficient color quantization algorithm, adapted from the C++
- * implementation quantize.c in <a
- *
href="http://www.imagemagick.org/">ImageMagick</a>. The pixels for
- * an image are placed into an oct tree. The oct tree is reduced in
- * size, and the pixels from the original image are reassigned to the
- * nodes in the reduced tree.<p>
- *
- * Here is the copyright notice from ImageMagick:
- *
- * <pre>
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Permission is hereby granted, free of charge, to any person obtaining a %
-% copy of this software and associated documentation files ("ImageMagick"),
%
-% to deal in ImageMagick without restriction, including without limitation %
-% the rights to use, copy, modify, merge, publish, distribute, sublicense, %
-% and/or sell copies of ImageMagick, and to permit persons to whom the %
-% ImageMagick is furnished to do so, subject to the following conditions: %
-% %
-% The above copyright notice and this permission notice shall be included in %
-% all copies or substantial portions of ImageMagick. %
-% %
-% The software is provided "as is", without warranty of any kind, express or
%
-% implied, including but not limited to the warranties of merchantability, %
-% fitness for a particular purpose and noninfringement. In no event shall %
-% E. I. du Pont de Nemours and Company be liable for any claim, damages or %
-% other liability, whether in an action of contract, tort or otherwise, %
-% arising from, out of or in connection with ImageMagick or the use or other %
-% dealings in ImageMagick. %
-% %
-% Except as contained in this notice, the name of the E. I. du Pont de %
-% Nemours and Company shall not be used in advertising or otherwise to %
-% promote the sale, use or other dealings in ImageMagick without prior %
-% written authorization from the E. I. du Pont de Nemours and Company. %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-</pre>
- *
- *
- * @version 0.90 19 Sep 2000
- * @author <a
href="http://www.gurge.com/amd/">Adam Doppelt</a>
- */
-public class Quantize {
-
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
-% QQQ U U AAA N N TTTTT IIIII ZZZZZ EEEEE %
-% Q Q U U A A NN N T I ZZ E %
-% Q Q U U AAAAA N N N T I ZZZ EEEEE %
-% Q QQ U U A A N NN T I ZZ E %
-% QQQQ UUU A A N N T IIIII ZZZZZ EEEEE %
-% %
-% %
-% Reduce the Number of Unique Colors in an Image %
-% %
-% %
-% Software Design %
-% John Cristy %
-% July 1992 %
-% %
-% %
-% Copyright 1998 E. I. du Pont de Nemours and Company %
-% %
-% Permission is hereby granted, free of charge, to any person obtaining a %
-% copy of this software and associated documentation files ("ImageMagick"),
%
-% to deal in ImageMagick without restriction, including without limitation %
-% the rights to use, copy, modify, merge, publish, distribute, sublicense, %
-% and/or sell copies of ImageMagick, and to permit persons to whom the %
-% ImageMagick is furnished to do so, subject to the following conditions: %
-% %
-% The above copyright notice and this permission notice shall be included in %
-% all copies or substantial portions of ImageMagick. %
-% %
-% The software is provided "as is", without warranty of any kind, express or
%
-% implied, including but not limited to the warranties of merchantability, %
-% fitness for a particular purpose and noninfringement. In no event shall %
-% E. I. du Pont de Nemours and Company be liable for any claim, damages or %
-% other liability, whether in an action of contract, tort or otherwise, %
-% arising from, out of or in connection with ImageMagick or the use or other %
-% dealings in ImageMagick. %
-% %
-% Except as contained in this notice, the name of the E. I. du Pont de %
-% Nemours and Company shall not be used in advertising or otherwise to %
-% promote the sale, use or other dealings in ImageMagick without prior %
-% written authorization from the E. I. du Pont de Nemours and Company. %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% Realism in computer graphics typically requires using 24 bits/pixel to
-% generate an image. Yet many graphic display devices do not contain
-% the amount of memory necessary to match the spatial and color
-% resolution of the human eye. The QUANTIZE program takes a 24 bit
-% image and reduces the number of colors so it can be displayed on
-% raster device with less bits per pixel. In most instances, the
-% quantized image closely resembles the original reference image.
-%
-% A reduction of colors in an image is also desirable for image
-% transmission and real-time animation.
-%
-% Function Quantize takes a standard RGB or monochrome images and quantizes
-% them down to some fixed number of colors.
-%
-% For purposes of color allocation, an image is a set of n pixels, where
-% each pixel is a point in RGB space. RGB space is a 3-dimensional
-% vector space, and each pixel, pi, is defined by an ordered triple of
-% red, green, and blue coordinates, (ri, gi, bi).
-%
-% Each primary color component (red, green, or blue) represents an
-% intensity which varies linearly from 0 to a maximum value, cmax, which
-% corresponds to full saturation of that color. Color allocation is
-% defined over a domain consisting of the cube in RGB space with
-% opposite vertices at (0,0,0) and (cmax,cmax,cmax). QUANTIZE requires
-% cmax = 255.
-%
-% The algorithm maps this domain onto a tree in which each node
-% represents a cube within that domain. In the following discussion
-% these cubes are defined by the coordinate of two opposite vertices:
-% The vertex nearest the origin in RGB space and the vertex farthest
-% from the origin.
-%
-% The tree's root node represents the the entire domain, (0,0,0) through
-% (cmax,cmax,cmax). Each lower level in the tree is generated by
-% subdividing one node's cube into eight smaller cubes of equal size.
-% This corresponds to bisecting the parent cube with planes passing
-% through the midpoints of each edge.
-%
-% The basic algorithm operates in three phases: Classification,
-% Reduction, and Assignment. Classification builds a color
-% description tree for the image. Reduction collapses the tree until
-% the number it represents, at most, the number of colors desired in the
-% output image. Assignment defines the output image's color map and
-% sets each pixel's color by reclassification in the reduced tree.
-% Our goal is to minimize the numerical discrepancies between the original
-% colors and quantized colors (quantization error).
-%
-% Classification begins by initializing a color description tree of
-% sufficient depth to represent each possible input color in a leaf.
-% However, it is impractical to generate a fully-formed color
-% description tree in the classification phase for realistic values of
-% cmax. If colors components in the input image are quantized to k-bit
-% precision, so that cmax= 2k-1, the tree would need k levels below the
-% root node to allow representing each possible input color in a leaf.
-% This becomes prohibitive because the tree's total number of nodes is
-% 1 + sum(i=1,k,8k).
-%
-% A complete tree would require 19,173,961 nodes for k = 8, cmax = 255.
-% Therefore, to avoid building a fully populated tree, QUANTIZE: (1)
-% Initializes data structures for nodes only as they are needed; (2)
-% Chooses a maximum depth for the tree as a function of the desired
-% number of colors in the output image (currently log2(colorMap size)).
-%
-% For each pixel in the input image, classification scans downward from
-% the root of the color description tree. At each level of the tree it
-% identifies the single node which represents a cube in RGB space
-% containing the pixel's color. It updates the following data for each
-% such node:
-%
-% n1: Number of pixels whose color is contained in the RGB cube
-% which this node represents;
-%
-% n2: Number of pixels whose color is not represented in a node at
-% lower depth in the tree; initially, n2 = 0 for all nodes except
-% leaves of the tree.
-%
-% Sr, Sg, Sb: Sums of the red, green, and blue component values for
-% all pixels not classified at a lower depth. The combination of
-% these sums and n2 will ultimately characterize the mean color of a
-% set of pixels represented by this node.
-%
-% E: The distance squared in RGB space between each pixel contained
-% within a node and the nodes' center. This represents the quantization
-% error for a node.
-%
-% Reduction repeatedly prunes the tree until the number of nodes with
-% n2 > 0 is less than or equal to the maximum number of colors allowed
-% in the output image. On any given iteration over the tree, it selects
-% those nodes whose E count is minimal for pruning and merges their
-% color statistics upward. It uses a pruning threshold, Ep, to govern
-% node selection as follows:
-%
-% Ep = 0
-% while number of nodes with (n2 > 0) > required maximum number of colors
-% prune all nodes such that E <= Ep
-% Set Ep to minimum E in remaining nodes
-%
-% This has the effect of minimizing any quantization error when merging
-% two nodes together.
-%
-% When a node to be pruned has offspring, the pruning procedure invokes
-% itself recursively in order to prune the tree from the leaves upward.
-% n2, Sr, Sg, and Sb in a node being pruned are always added to the
-% corresponding data in that node's parent. This retains the pruned
-% node's color characteristics for later averaging.
-%
-% For each node, n2 pixels exist for which that node represents the
-% smallest volume in RGB space containing those pixel's colors. When n2
-% > 0 the node will uniquely define a color in the output image. At the
-% beginning of reduction, n2 = 0 for all nodes except a the leaves of
-% the tree which represent colors present in the input image.
-%
-% The other pixel count, n1, indicates the total number of colors
-% within the cubic volume which the node represents. This includes n1 -
-% n2 pixels whose colors should be defined by nodes at a lower level in
-% the tree.
-%
-% Assignment generates the output image from the pruned tree. The
-% outpu t image consists of two parts: (1) A color map, which is an
-% array of color descriptions (RGB triples) for each color present in
-% the output image; (2) A pixel array, which represents each pixel as
-% an index into the color map array.
-%
-% First, the assignment phase makes one pass over the pruned color
-% description tree to establish the image's color map. For each node
-% with n2 > 0, it divides Sr, Sg, and Sb by n2 . This produces the
-% mean color of all pixels that classify no lower than this node. Each
-% of these colors becomes an entry in the color map.
-%
-% Finally, the assignment phase reclassifies each pixel in the pruned
-% tree to identify the deepest node containing the pixel's color. The
-% pixel's value in the pixel array becomes the index of this node's mean
-% color in the color map.
-%
-% With the permission of USC Information Sciences Institute, 4676 Admiralty
-% Way, Marina del Rey, California 90292, this code was adapted from module
-% ALCOLS written by Paul Raveling.
-%
-% The names of ISI and USC are not used in advertising or publicity
-% pertaining to distribution of the software without prior specific
-% written permission from ISI.
-%
-*/
-
- final static boolean QUICK = false;
-
- final static int MAX_RGB = 255;
- final static int MAX_NODES = 266817;
- final static int MAX_TREE_DEPTH = 8;
- final static int MAX_CHILDREN = 16;
-
- /**
- * Reduce the image to the given number of colors. The pixels are reduced in
- * place.
- *
- * @return The new color palette.
- */
- public static BufferedImage process(BufferedImage source, int maxColors,
- boolean dither, boolean alphaToBitmask) {
- int type = source.getType();
- int[] pixels;
- // try to get the direct pixels of the BufferedImage
- // this works for images of type INT_RGB, INT_ARGB and INT_ARGB_PRE
- // for all others, a new array with rgb pixels is created!
- if (type == BufferedImage.TYPE_INT_RGB
- || type == BufferedImage.TYPE_INT_ARGB
- || type == BufferedImage.TYPE_INT_ARGB_PRE) {
- pixels = ((DataBufferInt) source.getRaster().getDataBuffer()).getData();
- } else {
- pixels = source.getRGB(0, 0, source.getWidth(), source.getHeight(), null, 0,
source.getWidth());
- }
- Cube cube = new Cube(source, pixels, maxColors, dither, alphaToBitmask);
- cube.classification();
- cube.reduction();
- return cube.assignment();
- }
-
- static class Cube {
- BufferedImage source;
- int[] pixels;
- int maxColors;
- byte colorMap[][];
-
- Node root;
- int depth;
-
- boolean dither;
- boolean alphaToBitmask;
- boolean addTransparency;
- // firstColor is set to 1 when when addTransparency is true!
- int firstColor = 0;
-
- // counter for the number of colors in the cube. this gets
- // recalculated often.
- int numColors;
-
- // counter for the number of nodes in the tree
- int numNodes;
-
- Cube(BufferedImage source, int[] pixels, int maxColors, boolean dither,
- boolean alphaToBitmask) {
- this.source = source;
- this.pixels = pixels;
- this.maxColors = maxColors;
- this.dither = dither;
- this.alphaToBitmask = alphaToBitmask;
-
- int i = maxColors;
- // tree_depth = log maxColors
- // 4
- for (depth = 1; i != 0; depth++) {
- i /= 4;
- }
- if (depth > 1) {
- --depth;
- }
- if (depth > MAX_TREE_DEPTH) {
- depth = MAX_TREE_DEPTH;
- } else if (depth < 2) {
- depth = 2;
- }
-
- root = new Node(this);
- }
-
- /*
- * Procedure Classification begins by initializing a color description
- * tree of sufficient depth to represent each possible input color in a
- * leaf. However, it is impractical to generate a fully-formed color
- * description tree in the classification phase for realistic values of
- * cmax. If colors components in the input image are quantized to k-bit
- * precision, so that cmax= 2k-1, the tree would need k levels below the
- * root node to allow representing each possible input color in a leaf.
- * This becomes prohibitive because the tree's total number of nodes is
- * 1 + sum(i=1,k,8k).
- *
- * A complete tree would require 19,173,961 nodes for k = 8, cmax = 255.
- * Therefore, to avoid building a fully populated tree, QUANTIZE: (1)
- * Initializes data structures for nodes only as they are needed; (2)
- * Chooses a maximum depth for the tree as a function of the desired
- * number of colors in the output image (currently log2(colorMap size)).
- *
- * For each pixel in the input image, classification scans downward from
- * the root of the color description tree. At each level of the tree it
- * identifies the single node which represents a cube in RGB space
- * containing It updates the following data for each such node:
- *
- * numPixels : Number of pixels whose color is contained in the RGB cube
- * which this node represents;
- *
- * unique : Number of pixels whose color is not represented in a node at
- * lower depth in the tree; initially, n2 = 0 for all nodes except
- * leaves of the tree.
- *
- * totalRed/green/blue : Sums of the red, green, and blue component
- * values for all pixels not classified at a lower depth. The
- * combination of these sums and n2 will ultimately characterize the
- * mean color of a set of pixels represented by this node.
- */
- void classification() {
- addTransparency = false;
- firstColor = 0;
- for (int i = 0; i < pixels.length; i++) {
- int pixel = pixels[i];
- int red = (pixel >> 16) & 0xff;
- int green = (pixel >> 8) & 0xff;
- int blue = (pixel >> 0) & 0xff;
- int alpha = (pixel >> 24) & 0xff;
- if (alphaToBitmask)
- alpha = alpha < 0x80 ? 0 : 0xff;
-
- if (alpha > 0) {
- // a hard limit on the number of nodes in the tree
- if (numNodes > MAX_NODES) {
- // System.out.println("pruning");
- root.pruneLevel();
- --depth;
- }
-
- // walk the tree to depth, increasing the
- // numPixels count for each node
- Node node = root;
- for (int level = 1; level <= depth; ++level) {
- int id = (((red > node.midRed ? 1 : 0) << 0)
- | ((green > node.midGreen ? 1 : 0) << 1)
- | ((blue > node.midBlue ? 1 : 0) << 2) | ((alpha
> node.midAlpha ? 1
- : 0) << 3));
- if (node.children[id] == null) {
- node = new Node(node, id, level);
- } else {
- node = node.children[id];
- }
- node.numPixels++;
- }
-
- ++node.unique;
- node.totalRed += red;
- node.totalGreen += green;
- node.totalBlue += blue;
- node.totalAlpha += alpha;
- } else if (!addTransparency) {
- addTransparency = true;
- numColors++;
- firstColor = 1; // start at 1 as 0 will be the transparent
- // color
- }
- }
- }
-
- /*
- * reduction repeatedly prunes the tree until the number of nodes with
- * unique > 0 is less than or equal to the maximum number of colors
- * allowed in the output image.
- *
- * When a node to be pruned has offspring, the pruning procedure invokes
- * itself recursively in order to prune the tree from the leaves upward.
- * The statistics of the node being pruned are always added to the
- * corresponding data in that node's parent. This retains the pruned
- * node's color characteristics for later averaging.
- */
- void reduction() {
- int threshold = 1;
- while (numColors > maxColors) {
- numColors = firstColor;
- threshold = root.reduce(threshold, Integer.MAX_VALUE);
- }
- }
-
- /**
- * The result of a closest color search.
- */
- static class Search {
- int distance;
- int colorIndex;
- }
-
- /*
- * Procedure assignment generates the output image from the pruned tree.
- * The output image consists of two parts: (1) A color map, which is an
- * array of color descriptions (RGB triples) for each color present in
- * the output image; (2) A pixel array, which represents each pixel as
- * an index into the color map array.
- *
- * First, the assignment phase makes one pass over the pruned color
- * description tree to establish the image's color map. For each node
- * with n2 > 0, it divides Sr, Sg, and Sb by n2. This produces the mean
- * color of all pixels that classify no lower than this node. Each of
- * these colors becomes an entry in the color map.
- *
- * Finally, the assignment phase reclassifies each pixel in the pruned
- * tree to identify the deepest node containing the pixel's color. The
- * pixel's value in the pixel array becomes the index of this node's
- * mean color in the color map.
- */
- BufferedImage assignment() {
- colorMap = new byte[4][numColors];
-
- if (addTransparency) {
- // if a transparency color is added, firstColor was set to 1,
- // so color 0 can be used for this
- colorMap[0][0] = 0;
- colorMap[1][0] = 0;
- colorMap[2][0] = 0;
- colorMap[3][0] = 0;
- }
- numColors = firstColor;
- root.mapColors();
-
- // determine bit depth for palette
- int depth;
- for (depth = 1; depth <= 8; depth++)
- if ((1 << depth) >= numColors)
- break;
-
- // create the right color model, depending on transparency settings:
- IndexColorModel icm;
- if (alphaToBitmask) {
- if (addTransparency)
- icm = new IndexColorModel(depth, numColors, colorMap[0],
- colorMap[1], colorMap[2], 0);
- else
- icm = new IndexColorModel(depth, numColors, colorMap[0],
- colorMap[1], colorMap[2]);
- } else {
- icm = new IndexColorModel(depth, numColors, colorMap[0],
- colorMap[1], colorMap[2], colorMap[3]);
- }
- // create the indexed BufferedImage:
- BufferedImage dest = new BufferedImage(source.getWidth(),
- source.getHeight(), BufferedImage.TYPE_BYTE_INDEXED, icm);
-
- boolean firstOut = true;
- if (dither)
- new DiffusionFilterOp().filter(source, dest);
- else {
- Search search = new Search();
- // convert to indexed color
- byte[] dst = ((DataBufferByte)
dest.getRaster().getDataBuffer()).getData();
-
- for (int i = 0; i < pixels.length; i++) {
- int pixel = pixels[i];
- int red = (pixel >> 16) & 0xff;
- int green = (pixel >> 8) & 0xff;
- int blue = (pixel >> 0) & 0xff;
- int alpha = (pixel >> 24) & 0xff;
-
- if (alphaToBitmask)
- alpha = alpha < 128 ? 0 : 0xff;
-
- // this is super weird: on some systems, transparent pixels are
- // not calculated correctly if the following block is taken out.
- // the bug is very strange, isn't related to the code (compiler
error?)
- // but doesn't allways happen. as soon as it does, though, it
doesn't
- // seem to want to go away.
- // This happened at various times on my two different debian systems
- // and i never found out how to really fix it. the following line
seems to
- // prevent it from happening, but i wonder wether there's a
better way
- // to fix it.
- // it looks as if the command forces alpha to take on correct
values.
- // Until now I only knew of effects like that in quantum
mechanics...
- if (i == 0) {
- String fix = "" + alpha;
- }
-
- if (alpha == 0 && addTransparency) {
- dst[i] = 0; // transparency color is at 0
- } else {
- // walk the tree to find the cube containing that color
- Node node = root;
- for (;;) {
- int id = (((red > node.midRed ? 1 : 0) << 0)
- | ((green > node.midGreen ? 1 : 0) << 1)
- | ((blue > node.midBlue ? 1 : 0) << 2) | ((alpha
> node.midAlpha ? 1
- : 0) << 3));
- if (node.children[id] == null) {
- break;
- }
- node = node.children[id];
- }
-
- if (QUICK) {
- // if QUICK is set, just use that
- // node. Strictly speaking, this isn't
- // necessarily best match.
- dst[i] = (byte) node.colorIndex;
- } else {
- // Find the closest color.
- search.distance = Integer.MAX_VALUE;
- node.parent.closestColor(red, green, blue, alpha,
- search);
- dst[i] = (byte) search.colorIndex;
- }
- }
- }
- }
- return dest;
- }
-
- /**
- * A single Node in the tree.
- */
- static class Node {
- Cube cube;
-
- // parent node
- Node parent;
-
- // children nodes
- Node children[];
- int numChildren;
-
- // our index within our parent
- int id;
- // our level within the tree
- int level;
- // our color midpoint
- int midRed;
- int midGreen;
- int midBlue;
- int midAlpha;
-
- // the pixel count for this node and all children
- int numPixels;
-
- // the pixel count for this node
- int unique;
- // the sum of all pixels contained in this node
- int totalRed;
- int totalGreen;
- int totalBlue;
- int totalAlpha;
-
- // used to build the colorMap
- int colorIndex;
-
- Node(Cube cube) {
- this.cube = cube;
- this.parent = this;
- this.children = new Node[MAX_CHILDREN];
- this.id = 0;
- this.level = 0;
-
- this.numPixels = Integer.MAX_VALUE;
-
- this.midRed = (MAX_RGB + 1) >> 1;
- this.midGreen = (MAX_RGB + 1) >> 1;
- this.midBlue = (MAX_RGB + 1) >> 1;
- this.midAlpha = (MAX_RGB + 1) >> 1;
- }
-
- Node(Node parent, int id, int level) {
- this.cube = parent.cube;
- this.parent = parent;
- this.children = new Node[MAX_CHILDREN];
- this.id = id;
- this.level = level;
-
- // add to the cube
- ++cube.numNodes;
- if (level == cube.depth) {
- ++cube.numColors;
- }
-
- // add to the parent
- ++parent.numChildren;
- parent.children[id] = this;
-
- // figure out our midpoint
- int bi = (1 << (MAX_TREE_DEPTH - level)) >> 1;
- midRed = parent.midRed + ((id & 1) > 0 ? bi : -bi);
- midGreen = parent.midGreen + ((id & 2) > 0 ? bi : -bi);
- midBlue = parent.midBlue + ((id & 4) > 0 ? bi : -bi);
- midAlpha = parent.midAlpha + ((id & 8) > 0 ? bi : -bi);
- }
-
- /**
- * Remove this children node, and make sure our parent absorbs our
- * pixel statistics.
- */
- void pruneChild() {
- --parent.numChildren;
- parent.unique += unique;
- parent.totalRed += totalRed;
- parent.totalGreen += totalGreen;
- parent.totalBlue += totalBlue;
- parent.totalAlpha += totalAlpha;
- parent.children[id] = null;
- --cube.numNodes;
- cube = null;
- parent = null;
- }
-
- /**
- * Prune the lowest layer of the tree.
- */
- void pruneLevel() {
- if (numChildren != 0) {
- for (int id = 0; id < MAX_CHILDREN; id++) {
- if (children[id] != null) {
- children[id].pruneLevel();
- }
- }
- }
- if (level == cube.depth) {
- pruneChild();
- }
- }
-
- /**
- * Remove any nodes that have fewer than threshold pixels. Also, as
- * long as we're walking the tree: - figure out the color with the
- * fewest pixels - recalculate the total number of colors in the
- * tree
- */
- int reduce(int threshold, int nextThreshold) {
- if (numChildren != 0) {
- for (int id = 0; id < MAX_CHILDREN; id++) {
- if (children[id] != null) {
- nextThreshold = children[id].reduce(threshold,
- nextThreshold);
- }
- }
- }
- if (numPixels <= threshold) {
- pruneChild();
- } else {
- if (unique != 0) {
- cube.numColors++;
- }
- if (numPixels < nextThreshold) {
- nextThreshold = numPixels;
- }
- }
- return nextThreshold;
- }
-
- /*
- * mapColors traverses the color cube tree and notes each colorMap
- * entry. A colorMap entry is any node in the color cube tree where
- * the number of unique colors is not zero.
- */
- void mapColors() {
- if (numChildren != 0) {
- for (int id = 0; id < MAX_CHILDREN; id++) {
- if (children[id] != null) {
- children[id].mapColors();
- }
- }
- }
- if (unique != 0) {
- int add = unique >> 1;
- cube.colorMap[0][cube.numColors] = (byte) ((totalRed + add) /
unique);
- cube.colorMap[1][cube.numColors] = (byte) ((totalGreen + add) /
unique);
- cube.colorMap[2][cube.numColors] = (byte) ((totalBlue + add) /
unique);
- cube.colorMap[3][cube.numColors] = (byte) ((totalAlpha + add) /
unique);
- colorIndex = cube.numColors++;
- }
- }
-
- /*
- * ClosestColor traverses the color cube tree at a particular node
- * and determines which colorMap entry best represents the input
- * color.
- */
- void closestColor(int red, int green, int blue, int alpha,
- Search search) {
- if (numChildren != 0) {
- for (int id = 0; id < MAX_CHILDREN; id++) {
- if (children[id] != null) {
- children[id].closestColor(red, green, blue, alpha,
- search);
- }
- }
- }
-
- if (unique != 0) {
- int distance = distance(
- cube.colorMap[0][colorIndex] & 0xff,
- cube.colorMap[1][colorIndex] & 0xff,
- cube.colorMap[2][colorIndex] & 0xff,
- cube.colorMap[3][colorIndex] & 0xff, red, green, blue,
- alpha);
- if (distance < search.distance) {
- search.distance = distance;
- search.colorIndex = colorIndex;
- }
- }
- }
-
- /**
- * Figure out the distance between this node and som color.
- */
- final static int distance(int r1, int g1, int b1, int a1, int r2,
- int g2, int b2, int a2) {
- int da = a1 - a2;
- int dr = r1 - r2;
- int dg = g1 - g2;
- int db = b1 - b2;
-
- return da * da + dr * dr + dg * dg + db * db;
-// return (SQUARES[r1 - r2 + MAX_RGB] +
-// SQUARES[g1 - g2 + MAX_RGB] +
-// SQUARES[b1 - b2 + MAX_RGB] +
-// SQUARES[a1 - a2 + MAX_RGB]);
- }
-
- public String toString() {
- StringBuffer buf = new StringBuffer();
- if (parent == this) {
- buf.append("root");
- } else {
- buf.append("node");
- }
- buf.append(' ');
- buf.append(level);
- buf.append(" [");
- buf.append(midRed);
- buf.append(',');
- buf.append(midGreen);
- buf.append(',');
- buf.append(midBlue);
- buf.append(',');
- buf.append(midAlpha);
- buf.append(']');
- return new String(buf);
- }
- }
- }
-}
\ No newline at end of file
Deleted:
framework/trunk/impl/src/main/java/org/richfaces/model/ExtendedDataTableModifiableModel.java
===================================================================
---
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/model/ExtendedDataTableModifiableModel.java 2009-07-07
12:45:54 UTC (rev 14807)
+++
framework/trunk/impl/src/main/java/org/richfaces/model/ExtendedDataTableModifiableModel.java 2009-07-08
00:01:28 UTC (rev 14825)
@@ -1,196 +0,0 @@
-/**
- *
- */
-package org.richfaces.model;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import javax.faces.context.FacesContext;
-import javax.faces.model.DataModelListener;
-
-import org.ajax4jsf.model.DataVisitor;
-import org.ajax4jsf.model.ExtendedDataModel;
-import org.ajax4jsf.model.Range;
-import org.ajax4jsf.model.SequenceRange;
-import org.ajax4jsf.model.SerializableDataModel;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.richfaces.model.FilterField;
-import org.richfaces.model.SortField2;
-import org.richfaces.model.impl.expressive.JavaBeanWrapper;
-import org.richfaces.model.impl.expressive.ObjectWrapperFactory;
-import org.richfaces.model.impl.expressive.WrappedBeanComparator2;
-import org.richfaces.model.impl.expressive.WrappedBeanFilter;
-
-/**
- * @author pawelgo
- *
- */
-public class ExtendedDataTableModifiableModel<T> extends ExtendedDataModel {
-
- private static final Log log =
LogFactory.getLog(ExtendedDataTableModifiableModel.class);
-
- private ExtendedDataModel delegate;
-
- private ExtendedTableDataModel<T> originalModel;
-
- private ExtendedDataModel modifiedModel;
-
- private String var;
-
- private List<FilterField> filterFields;
- private List<SortField2> sortFields;
-
- /**
- * @param originalModel
- * @param var
- * @param filterFields
- * @param sortFields
- */
- public ExtendedDataTableModifiableModel(ExtendedTableDataModel<T> originalModel,
- String var, List<FilterField> filterFields,
- List<SortField2> sortFields) {
- this.originalModel = originalModel;
- this.delegate = originalModel;
- this.var = var;
- this.filterFields = filterFields;
- this.sortFields = sortFields;
- }
-
- public void addDataModelListener(DataModelListener listener) {
- originalModel.addDataModelListener(listener);
- }
-
- public DataModelListener[] getDataModelListeners() {
- return originalModel.getDataModelListeners();
- }
-
- public int getRowCount() {
- return delegate.getRowCount();
- }
-
- public Object getRowData() {
- return delegate.getRowData();
- }
-
- public int getRowIndex() {
- return delegate.getRowIndex();
- }
-
- public Object getRowKey() {
- return delegate.getRowKey();
- }
-
- public SerializableDataModel getSerializableModel(Range range) {
- return delegate.getSerializableModel(range);
- }
-
- public Object getWrappedData() {
- return delegate.getWrappedData();
- }
-
- public boolean isRowAvailable() {
- return delegate.isRowAvailable();
- }
-
- public void removeDataModelListener(DataModelListener listener) {
- delegate.removeDataModelListener(listener);
- }
-
- public void setRowIndex(int rowIndex) {
- delegate.setRowIndex(rowIndex);
- }
-
- public void setRowKey(Object key) {
- delegate.setRowKey(key);
- }
-
- public void setWrappedData(Object data) {
- delegate.setWrappedData(data);
- }
-
- @SuppressWarnings("unchecked")
- public void walk(FacesContext context, DataVisitor visitor, Range range,
- Object argument) throws IOException {
-
- if (shouldSort() || shouldFilter()) {
- if (modifiedModel == null) {
- modifiedModel = new
ExtendedTableDataModelWrapper<T>(originalModel.getDataProvider(), (List<T>)
prepareCollection());
- }
- delegate = modifiedModel;
- } else {
- delegate = originalModel;
- }
-
- delegate.walk(context, visitor, range, argument);
- }
-
- private boolean shouldSort() {
- return sortFields != null && !sortFields.isEmpty();
- }
-
- private boolean shouldFilter() {
- return filterFields != null && !filterFields.isEmpty();
- }
-
- private List<?> prepareCollection() {
- int rowCount = originalModel.getRowCount();
- final List<Object> collection;
-
- if (rowCount > 0) {
- collection = new ArrayList<Object>(rowCount);
- } else {
- collection = new ArrayList<Object>();
- }
-
- FacesContext context = FacesContext.getCurrentInstance();
- try {
-
- originalModel.walk(context, new DataVisitor() {
- public void process(FacesContext context, Object rowKey,
- Object argument) throws IOException {
- originalModel.setRowKey(rowKey);
- if (originalModel.isRowAvailable()) {
- collection.add(originalModel.getRowData());
- }
- }
- }, new SequenceRange(0, -1),
- null);
- } catch (IOException e) {
- log.error(e.getMessage(), e);
- }
-
- List<Object> modifedcollection = collection;
-
- if (shouldFilter()) {
- List <Object> filteredCollection = new ArrayList<Object>();
- ObjectWrapperFactory wrapperFactory = new ObjectWrapperFactory(
- context, var, filterFields);
- WrappedBeanFilter wrappedBeanFilter = new WrappedBeanFilter(filterFields);
- wrapperFactory.wrapList(modifedcollection);
- for (Object object : modifedcollection) {
- if(wrappedBeanFilter.accept((JavaBeanWrapper)object)) {
- filteredCollection.add(object);
- }
- }
- modifedcollection = filteredCollection;
- wrapperFactory.unwrapList(modifedcollection);
- }
-
- if (shouldSort()) {
- ObjectWrapperFactory wrapperFactory = new ObjectWrapperFactory(
- context, var, sortFields);
- WrappedBeanComparator2 wrappedBeanComparator = new WrappedBeanComparator2(
- sortFields);
- wrapperFactory.wrapList(modifedcollection);
- Collections.sort(modifedcollection, wrappedBeanComparator);
- wrapperFactory.unwrapList(modifedcollection);
- }
- return modifedcollection;
-
- }
-
-}
Deleted:
framework/trunk/impl/src/main/java/org/richfaces/model/ExtendedTableDataModelWrapper.java
===================================================================
---
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/model/ExtendedTableDataModelWrapper.java 2009-07-07
12:45:54 UTC (rev 14807)
+++
framework/trunk/impl/src/main/java/org/richfaces/model/ExtendedTableDataModelWrapper.java 2009-07-08
00:01:28 UTC (rev 14825)
@@ -1,40 +0,0 @@
-/**
- *
- */
-package org.richfaces.model;
-
-import java.util.List;
-
-/**
- * @author pawelgo
- *
- */
-public class ExtendedTableDataModelWrapper<T> extends
ExtendedTableDataModel<T> {
-
- private static final long serialVersionUID = 6932958007982793632L;
-
- protected List<T> wrappedList;
-
- /**
- *
- * @param dataProvider
- * @param wrappedList
- */
- public ExtendedTableDataModelWrapper(DataProvider<T> dataProvider, List<T>
wrappedList) {
- super(dataProvider);
- this.wrappedList = wrappedList;
- }
-
- protected List<T> loadData(int startRow, int endRow) {
- //return super.loadData(startRow, endRow);
- return wrappedList.subList(startRow, endRow);
- }
-
- public int getRowCount() {
- return wrappedList.size();
- }
-
-
-
-
-}
Modified: framework/trunk/pom.xml
===================================================================
--- framework/trunk/pom.xml 2009-07-07 23:36:18 UTC (rev 14824)
+++ framework/trunk/pom.xml 2009-07-08 00:01:28 UTC (rev 14825)
@@ -74,8 +74,8 @@
<modules>
<module>version-matrix</module>
<module>api</module>
+ <module>impl</module>
<module>test-base</module>
- <module>impl</module>
</modules>
</project>
\ No newline at end of file
Modified: framework/trunk/test-base/pom.xml
===================================================================
--- framework/trunk/test-base/pom.xml 2009-07-07 23:36:18 UTC (rev 14824)
+++ framework/trunk/test-base/pom.xml 2009-07-08 00:01:28 UTC (rev 14825)
@@ -22,6 +22,100 @@
<artifactId>jsf-impl</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.htmlunit</groupId>
+ <artifactId>htmlunit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.htmlunit</groupId>
+ <artifactId>htmlunit-core-js</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.cssparser</groupId>
+ <artifactId>cssparser</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>net.sourceforge.nekohtml</groupId>
+ <artifactId>nekohtml</artifactId>
+
+ <!-- TODO: move exclusions to VM? -->
+ <exclusions>
+ <exclusion>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ </exclusion>
+ <!--
+ <exclusion> <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId> </exclusion>
+ -->
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-ri</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet.jsp</groupId>
+ <artifactId>jsp-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>jstl</groupId>
+ <artifactId>jstl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>jsr250-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>xalan</groupId>
+ <artifactId>xalan</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>de.berlios.jsunit</groupId>
+ <artifactId>jsunit</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>rhino</groupId>
+ <artifactId>js</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
</dependencies>
</project>
\ No newline at end of file
Copied: framework/trunk/test-base/src (from rev 14798,
branches/jsf2.0/framework/jsf-test/src)
Modified: framework/trunk/version-matrix/pom.xml
===================================================================
--- framework/trunk/version-matrix/pom.xml 2009-07-07 23:36:18 UTC (rev 14824)
+++ framework/trunk/version-matrix/pom.xml 2009-07-08 00:01:28 UTC (rev 14825)
@@ -80,9 +80,62 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.4</version>
+ <version>4.6</version>
</dependency>
<dependency>
+ <groupId>net.sourceforge.htmlunit</groupId>
+ <artifactId>htmlunit</artifactId>
+ <version>2.5</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.htmlunit</groupId>
+ <artifactId>htmlunit-core-js</artifactId>
+ <version>2.5</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.cssparser</groupId>
+ <artifactId>cssparser</artifactId>
+ <version>0.9.5</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>net.sourceforge.nekohtml</groupId>
+ <artifactId>nekohtml</artifactId>
+ <version>1.9.12</version>
+ </dependency>
+ <dependency>
+ <groupId>xalan</groupId>
+ <artifactId>xalan</artifactId>
+ <version>2.7.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>de.berlios.jsunit</groupId>
+ <artifactId>jsunit</artifactId>
+ <version>1.3</version>
+ </dependency>
+
+ <dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.0-SNAPSHOT</version>
@@ -107,20 +160,99 @@
<version>2.1</version>
</dependency>
<dependency>
+ <groupId>jstl</groupId>
+ <artifactId>jstl</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <!-- end -->
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-ri</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>jsr250-api</artifactId>
<version>1.0</version>
</dependency>
+
+ <!-- TODO: remove commons dependencies -->
<dependency>
- <groupId>jstl</groupId>
- <artifactId>jstl</artifactId>
- <version>1.2</version>
+ <groupId>commons-digester</groupId>
+ <artifactId>commons-digester</artifactId>
+ <version>1.8.1</version>
</dependency>
- <!-- end -->
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <version>1.7.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <!-- -->
+
+ <!-- TODO: legacy dependnecies -->
+ <dependency>
+ <groupId>opensymphony</groupId>
+ <artifactId>oscache</artifactId>
+ <version>2.3</version>
+ </dependency>
+ <!-- dependency>
+ <groupId>nekohtml</groupId>
+ <artifactId>nekohtml</artifactId>
+ <version>0.9.5</version>
+ </dependency -->
+ <!-- -->
+
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ <version>2.4</version>
+ </dependency>
+
</dependencies>
</dependencyManagement>
<build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>javacc-maven-plugin</artifactId>
+ <version>2.4</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ </plugin>
+
+ <!-- TODO: change to the current CDK version -->
+ <plugin>
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>maven-javascript-plugin</artifactId>
+ <version>3.3.1.GA</version>
+ </plugin>
+ <!-- -->
+
+ </plugins>
+ </pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>