mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-05-21 00:00:01 -04:00
Compare commits
52 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 26d3de45a7 | |||
| 13507ce303 | |||
| a8508dc234 | |||
| b3cf467f0b | |||
| b0e6fbed9f | |||
| c087addb76 | |||
| 250c58cc2e | |||
| c33b3a76f4 | |||
| f14e6823bd | |||
| cae72336a2 | |||
| c5bf0a6f0b | |||
| 691b7560db | |||
| e1025f9540 | |||
| fa09099da0 | |||
| 140b074ac6 | |||
| 59c6c18cbb | |||
| c48e17dabf | |||
| 22a842eb78 | |||
| bdd7f5b228 | |||
| 0e41d4a5f7 | |||
| 653360e054 | |||
| 4f193d543c | |||
| 1d0cc43476 | |||
| 9791a251ed | |||
| 0bc30f4d18 | |||
| 022fc03fbb | |||
| 8b66842859 | |||
| 5251f4665e | |||
| b98b81b877 | |||
| 774b494fec | |||
| 90ef605b0c | |||
| b40eea0fc4 | |||
| 9ac2013965 | |||
| 4740a39cd2 | |||
| 7ebcc437c3 | |||
| 70c16dfdd9 | |||
| c9e2e21727 | |||
| 230ac33283 | |||
| 66e0acb668 | |||
| 7d8858c177 | |||
| faab9517dd | |||
| 2433777b6d | |||
| 3980c937cf | |||
| 468ffb891d | |||
| e27e8a7ccb | |||
| f2dba604da | |||
| 04f27a1694 | |||
| 2630a6a795 | |||
| ab2f1f7e91 | |||
| 7110e89bda | |||
| a06cbfd6f4 | |||
| 3b68d676f3 |
@@ -1 +0,0 @@
|
|||||||
github: haraldk
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
---
|
|
||||||
name: Bug report
|
|
||||||
about: Create a report to help us improve
|
|
||||||
title: ''
|
|
||||||
labels: Reported bug
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Describe the bug**
|
|
||||||
A clear and concise description of what the bug is.
|
|
||||||
|
|
||||||
**Version information**
|
|
||||||
1. The version of the TwelveMonkeys ImageIO library in use.
|
|
||||||
For example: 4.0.0
|
|
||||||
|
|
||||||
2. The *exact* output of `java --version` (or `java -version` for older Java releases).
|
|
||||||
For example:
|
|
||||||
|
|
||||||
java version "1.8.0_271"
|
|
||||||
Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
|
|
||||||
Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)
|
|
||||||
|
|
||||||
3. Extra information about OS version, server version, standalone program or web application packaging, executable wrapper, etc. Please state exact version numbers where applicable.
|
|
||||||
|
|
||||||
**To Reproduce**
|
|
||||||
Steps to reproduce the behavior:
|
|
||||||
|
|
||||||
1. Compile the below sample code
|
|
||||||
2. Download the sample image file
|
|
||||||
3. Run the code with the sample file
|
|
||||||
4. See error
|
|
||||||
|
|
||||||
**Expected behavior**
|
|
||||||
A clear and concise description of what you expected to happen.
|
|
||||||
|
|
||||||
**Example code**
|
|
||||||
Preferably as a failing JUnit test, or a standalone program with a `main` method that showcases the problem.
|
|
||||||
|
|
||||||
Less is more. Don't add your entire project, only the code required to reproduce the problem. 😀
|
|
||||||
|
|
||||||
**Sample file(s)**
|
|
||||||
Attach any sample files needed to reproduce the problem. Use a ZIP-file if the format is not directly supported by GitHub.
|
|
||||||
|
|
||||||
**Stak trace**
|
|
||||||
Always include the stack trace you experience.
|
|
||||||
|
|
||||||
**Screenshots**
|
|
||||||
If applicable, add screenshots to help explain your problem.
|
|
||||||
Do not add screenshots of code or stack traces. 😀
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context about the problem here.
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
---
|
|
||||||
name: Feature request
|
|
||||||
about: Suggest an idea for this project
|
|
||||||
title: ''
|
|
||||||
labels: New feature
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Is your feature request related to a use case or a problem you are working on? Please describe.**
|
|
||||||
A clear and concise description of what the problem or use case is. Understanding the rationale is key, to be able to implemeent the right solution.
|
|
||||||
|
|
||||||
**Describe the solution you'd like**
|
|
||||||
A clear and concise description of what you want to happen.
|
|
||||||
|
|
||||||
**Describe alternatives you've considered**
|
|
||||||
A clear and concise description of any alternative solutions or features you've already considered, and why they won't work.
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context or screenshots about the feature request here, like links to specifications or sample files.
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
---
|
|
||||||
name: Trouble shooting and programming help
|
|
||||||
about: "General programming issues will reach a wider audience at StackOverflow. Tag
|
|
||||||
questions with javax-imageio and/or twelvemonkeys \U0001F600 "
|
|
||||||
title: ''
|
|
||||||
labels: Trouble-shooting
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
General programming issues and problems will reach a much wider audience at StackOverflow, we suggest you ask them there. This will offload our work with maintaining the library, and make sure you get better help sooner.
|
|
||||||
|
|
||||||
Tag the question with `javax-imageio` and/or `twelvemonkeys` and we'll find them there.
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
**What is fixed** Add link to the issue this PR fixes.
|
|
||||||
|
|
||||||
Example: Fixes #42.
|
|
||||||
|
|
||||||
**Why is this change proposed** If this change does *not* fix an open issue, briefly describe the rationale for this PR.
|
|
||||||
|
|
||||||
**What is changed** Briefly describe the changes proposed in this pull request:
|
|
||||||
|
|
||||||
* Fixed rare exception happening in `x >= 42` case
|
|
||||||
* Small optimization of `decompress()` method
|
|
||||||
* Corrected API doc for `compress()` method to reflect current implementation
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
name: CI
|
|
||||||
|
|
||||||
on: [ push, pull_request ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
name: Test OpenJDK ${{ matrix.java }} on ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
|
||||||
java: [ 8, 11, 17 ]
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- uses: actions/setup-java@v2
|
|
||||||
with:
|
|
||||||
distribution: 'temurin'
|
|
||||||
java-version: ${{ matrix.java }}
|
|
||||||
java-package: jdk
|
|
||||||
cache: 'maven'
|
|
||||||
- name: Run Tests
|
|
||||||
run: mvn test
|
|
||||||
- name: Publish Test Report
|
|
||||||
uses: mikepenz/action-junit-report@v2
|
|
||||||
if: ${{ !cancelled() }}
|
|
||||||
with:
|
|
||||||
report_paths: "**/target/surefire-reports/TEST*.xml"
|
|
||||||
check_name: Unit Test Results for OpenJDK ${{ matrix.java }} on ${{ matrix.os }}
|
|
||||||
|
|
||||||
test_oracle:
|
|
||||||
name: Test Oracle JDK 8 with KCMS=${{ matrix.kcms }}
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
kcms: [ true, false ]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- run: |
|
|
||||||
download_url="https://javadl.oracle.com/webapps/download/AutoDL?BundleId=245038_d3c52aa6bfa54d3ca74e617f18309292"
|
|
||||||
wget -O $RUNNER_TEMP/java_package.tar.gz $download_url
|
|
||||||
- uses: actions/setup-java@v2
|
|
||||||
with:
|
|
||||||
distribution: 'jdkfile'
|
|
||||||
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
|
||||||
java-version: '8'
|
|
||||||
cache: 'maven'
|
|
||||||
- name: Set MAVEN_OPTS
|
|
||||||
if: ${{ matrix.kcms }}
|
|
||||||
run: |
|
|
||||||
echo "MAVEN_OPTS=-Dsun.java2d.cmm=sun.java2d.cmm.kcms.KcmsServiceProvider" >> $GITHUB_ENV
|
|
||||||
- name: Display Java version
|
|
||||||
run: java -version
|
|
||||||
- name: Run Tests
|
|
||||||
run: mvn test
|
|
||||||
- name: Publish Test Report
|
|
||||||
uses: mikepenz/action-junit-report@v2
|
|
||||||
if: ${{ !cancelled() }}
|
|
||||||
with:
|
|
||||||
report_paths: "**/target/surefire-reports/TEST*.xml"
|
|
||||||
check_name: Unit Test Results for Oracle JDK 8 with KCMS=${{ matrix.kcms }}
|
|
||||||
|
|
||||||
release:
|
|
||||||
name: Deploy
|
|
||||||
needs: [ test, test_oracle ]
|
|
||||||
if: github.ref == 'refs/heads/master' # only perform on latest master
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Set up Maven Central
|
|
||||||
uses: actions/setup-java@v2
|
|
||||||
with: # running setup-java again overwrites the settings.xml
|
|
||||||
distribution: 'temurin'
|
|
||||||
java-version: '8'
|
|
||||||
java-package: jdk
|
|
||||||
server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml
|
|
||||||
server-username: MAVEN_CENTRAL_USERNAME # env variable for username in deploy (1)
|
|
||||||
server-password: MAVEN_CENTRAL_PASSWORD # env variable for token in deploy (2)
|
|
||||||
gpg-private-key: ${{ secrets.GPG_KEY }} # Value of the GPG private key to import
|
|
||||||
gpg-passphrase: MAVEN_CENTRAL_GPG_PASSPHRASE # env variable for GPG private key passphrase (3)
|
|
||||||
- name: Get Project Version
|
|
||||||
run: |
|
|
||||||
echo "PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
|
|
||||||
- name: Publish to Maven Central
|
|
||||||
if: ${{ endsWith(env.PROJECT_VERSION, '-SNAPSHOT') }}
|
|
||||||
run: mvn deploy -P release -DskipTests
|
|
||||||
env:
|
|
||||||
MAVEN_CENTRAL_USERNAME: ${{ secrets.SONATYPE_USERNAME }} # must be the same env variable name as (1)
|
|
||||||
MAVEN_CENTRAL_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} # must be the same env variable name as (2)
|
|
||||||
MAVEN_CENTRAL_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} # must be the same env variable name as (3)
|
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
dist: trusty
|
||||||
|
language: java
|
||||||
|
jdk:
|
||||||
|
- oraclejdk8
|
||||||
|
# Oracle JDK 7 no longer supported, we use env matrix to test various CMM providers
|
||||||
|
# - oraclejdk7
|
||||||
|
# Some JPEGImageReader tests fail on OpenJDK, need to investigate/fix before enabling
|
||||||
|
# - openjdk7
|
||||||
|
env:
|
||||||
|
- MAVEN_OPTS=-Dsun.java2d.cmm=sun.java2d.cmm.kcms.KcmsServiceProvider
|
||||||
|
- MAVEN_OPTS=""
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- $HOME/.m2
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
BSD 3-Clause License
|
BSD 3-Clause License
|
||||||
|
|
||||||
Copyright (c) 2008-2020, Harald Kuhr
|
Copyright (c) 2017, Harald Kuhr
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
|||||||
@@ -1,78 +1,264 @@
|
|||||||
[](https://github.com/haraldk/TwelveMonkeys/actions/workflows/ci.yml)
|
## Latest
|
||||||
[](https://search.maven.org/search?q=g:com.twelvemonkeys.imageio)
|
|
||||||
[](https://oss.sonatype.org/content/repositories/snapshots/com/twelvemonkeys/)
|
Master branch build status: [](https://travis-ci.org/haraldk/TwelveMonkeys)
|
||||||
[](https://stackoverflow.com/questions/tagged/twelvemonkeys)
|
|
||||||
[](https://paypal.me/haraldk76/100)
|
Latest release is TwelveMonkeys ImageIO [3.4.1](https://search.maven.org/search?q=g:com.twelvemonkeys.imageio%20AND%20v:3.4.1) (Sep. 7th, 2018).
|
||||||
|
[Release notes](https://github.com/haraldk/TwelveMonkeys/releases/latest).
|
||||||
|
|
||||||
## About
|
## About
|
||||||
|
|
||||||
TwelveMonkeys ImageIO provides extended image file format support for the Java platform, through plugins for the `javax.imageio.*` package.
|
TwelveMonkeys ImageIO is a collection of plugins and extensions for Java's ImageIO.
|
||||||
|
|
||||||
The main goal of this project is to provide support for formats not covered by the JRE itself.
|
These plugins extends the number of image file formats supported in Java, using the javax.imageio.* package.
|
||||||
Support for these formats is important, to be able to read data found
|
The main purpose of this project is to provide support for formats not covered by the JRE itself.
|
||||||
|
|
||||||
|
Support for formats is important, both to be able to read data found
|
||||||
"in the wild", as well as to maintain access to data in legacy formats.
|
"in the wild", as well as to maintain access to data in legacy formats.
|
||||||
As there is lots of legacy data out there, we see the need for open implementations of readers for popular formats.
|
Because there is lots of legacy data out there, we see the need for open implementations of readers for popular formats.
|
||||||
|
The goal is to create a set of efficient and robust ImageIO plug-ins, that can be distributed independently.
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
## File formats supported
|
## Features
|
||||||
|
|
||||||
| Plugin | Format | Description | R | W | Metadata | Notes |
|
Mainstream format support
|
||||||
| ------ | -------- |---------------------------------------------------------|:---:|:---:| -------- | ----- |
|
|
||||||
| Batik | **SVG** | Scalable Vector Graphics | ✔ | - | - | Requires [Batik](https://xmlgraphics.apache.org/batik/) |
|
|
||||||
| | WMF | MS Windows Metafile | ✔ | - | - | Requires [Batik](https://xmlgraphics.apache.org/batik/) |
|
|
||||||
| [BMP](https://github.com/haraldk/TwelveMonkeys/wiki/BMP-Plugin) | **BMP** | MS Windows and IBM OS/2 Device Independent Bitmap | ✔ | ✔ | [Native](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/bmp_metadata.html), [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| | CUR | MS Windows Cursor Format | ✔ | - | - |
|
|
||||||
| | ICO | MS Windows Icon Format | ✔ | ✔ | - |
|
|
||||||
| [HDR](https://github.com/haraldk/TwelveMonkeys/wiki/HDR-Plugin) | HDR | Radiance High Dynamic Range RGBE Format | ✔ | - | [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| [ICNS](https://github.com/haraldk/TwelveMonkeys/wiki/ICNS-Plugin) | ICNS | Apple Icon Image | ✔ | ✔ | - |
|
|
||||||
| [IFF](https://github.com/haraldk/TwelveMonkeys/wiki/IFF-Plugin) | IFF | Commodore Amiga/Electronic Arts Interchange File Format | ✔ | ✔ | [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| [JPEG](https://github.com/haraldk/TwelveMonkeys/wiki/JPEG-Plugin) | **JPEG** | Joint Photographers Expert Group | ✔ | ✔ | [Native](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/jpeg_metadata.html#image), [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| | JPEG Lossless | | ✔ | - | [Native](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/jpeg_metadata.html#image), [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| [PCX](https://github.com/haraldk/TwelveMonkeys/wiki/PCX-Plugin) | PCX | ZSoft Paintbrush Format | ✔ | - | [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| | DCX | Multi-page PCX fax document | ✔ | - | [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| [PICT](https://github.com/haraldk/TwelveMonkeys/wiki/PICT-Plugin) | PICT | Apple QuickTime Picture Format | ✔ | ✔ | [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| | PNTG | Apple MacPaint Picture Format | ✔ | - | [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| [PNM](https://github.com/haraldk/TwelveMonkeys/wiki/PNM-Plugin) | PAM | NetPBM Portable Any Map | ✔ | ✔ | [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| | PBM | NetPBM Portable Bit Map | ✔ | - | [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| | PGM | NetPBM Portable Grey Map | ✔ | - | [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| | PPM | NetPBM Portable Pix Map | ✔ | ✔ | [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| | PFM | Portable Float Map | ✔ | - | [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| [PSD](https://github.com/haraldk/TwelveMonkeys/wiki/PSD-Plugin) | **PSD** | Adobe Photoshop Document | ✔ | (✔) | Native, [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| | PSB | Adobe Photoshop Large Document | ✔ | - | Native, [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| [SGI](https://github.com/haraldk/TwelveMonkeys/wiki/SGI-Plugin) | SGI | Silicon Graphics Image Format | ✔ | - | [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| [TGA](https://github.com/haraldk/TwelveMonkeys/wiki/TGA-Plugin) | TGA | Truevision TGA Image Format | ✔ | ✔ | [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
|ThumbsDB| Thumbs.db| MS Windows Thumbs DB | ✔ | - | - | OLE2 Compound Document based format only |
|
|
||||||
| [TIFF](https://github.com/haraldk/TwelveMonkeys/wiki/TIFF-Plugin) | **TIFF** | Aldus/Adobe Tagged Image File Format | ✔ | ✔ | [Native](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/tiff_metadata.html#ImageMetadata), [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| | BigTIFF | | ✔ | ✔ | [Native](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/tiff_metadata.html#ImageMetadata), [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| [WebP](https://github.com/haraldk/TwelveMonkeys/wiki/WebP-Plugin) | **WebP** | Google WebP Format | ✔ | - | [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
| XWD | XWD | X11 Window Dump Format | ✔ | - | [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
|
||||||
|
|
||||||
|
#### BMP - MS Windows/IBM OS/2 Device Independent Bitmap
|
||||||
|
|
||||||
|
* Read support for all known versions of the DIB/BMP format
|
||||||
|
* Indexed color, 1, 4 and 8 bit, including 4 and 8 bit RLE
|
||||||
|
* RGB, 16, 24 and 32 bit
|
||||||
|
* Embedded PNG and JPEG data
|
||||||
|
* Windows and OS/2 versions
|
||||||
|
* Native and standard metadata format
|
||||||
|
|
||||||
**Important note on using Batik:** *Please read [The Apache™ XML Graphics Project - Security](https://xmlgraphics.apache.org/security.html),
|
#### JPEG
|
||||||
and make sure you use version 1.14 or later.*
|
|
||||||
|
* Read support for the following JPEG "flavors":
|
||||||
|
* All JFIF compliant JPEGs
|
||||||
|
* All Exif compliant JPEGs
|
||||||
|
* YCbCr JPEGs without JFIF segment (converted to RGB, using embedded ICC profile)
|
||||||
|
* CMYK JPEGs (converted to RGB by default or as CMYK, using embedded ICC profile)
|
||||||
|
* Adobe YCCK JPEGs (converted to RGB by default or as CMYK, using embedded ICC profile)
|
||||||
|
* JPEGs containing ICC profiles with interpretation other than 'Perceptual' or class other than 'Display'
|
||||||
|
* JPEGs containing ICC profiles that are incompatible with stream data, corrupted ICC profiles or corrupted `ICC_PROFILE` segments
|
||||||
|
* JPEGs using non-standard color spaces, unsupported by Java 2D
|
||||||
|
* JPEGs with APP14/Adobe segments with length other than 14 bytes
|
||||||
|
* 8 bit JPEGs with 16 bit DQT segments
|
||||||
|
* Issues warnings instead of throwing exceptions in cases of corrupted or non-conformant data where ever the image
|
||||||
|
data can still be read in a reasonable way
|
||||||
|
* Thumbnail support:
|
||||||
|
* JFIF thumbnails (even if stream contains "inconsistent metadata")
|
||||||
|
* JFXX thumbnails (JPEG, Indexed and RGB)
|
||||||
|
* EXIF thumbnails (JPEG, RGB and YCbCr)
|
||||||
|
* Metadata support:
|
||||||
|
* JPEG metadata in both standard and native formats (even if stream contains "inconsistent metadata")
|
||||||
|
* `javax_imageio_jpeg_image_1.0` format (currently as native format, may change in the future)
|
||||||
|
* Non-conforming combinations of JFIF, Exif and Adobe markers, using "unknown" segments in the
|
||||||
|
"MarkerSequence" tag for the unsupported segments (for `javax_imageio_jpeg_image_1.0` format)
|
||||||
|
* Extended write support:
|
||||||
|
* CMYK JPEGs
|
||||||
|
* YCCK JPEGs in progress
|
||||||
|
|
||||||
|
#### JPEG-2000
|
||||||
|
|
||||||
|
* Possibly coming in the future, pending some license issues.
|
||||||
|
|
||||||
|
If you are one of the authors, or know one of the authors and/or the current license holders of either the original
|
||||||
|
jj2000 package or the JAI ImageIO project, please contact me (I've tried to get in touch in various ways,
|
||||||
|
without success so far).
|
||||||
|
|
||||||
|
Alternatively, if you have or know of a JPEG-2000 implementation in Java with a suitable license, get in touch. :-)
|
||||||
|
|
||||||
|
#### PNM - NetPBM Portable Any Map
|
||||||
|
|
||||||
|
* Read support for the following file types:
|
||||||
|
* PBM in 'P1' (ASCII) and 'P4' (binary) formats, 1 bit per pixel
|
||||||
|
* PGM in 'P2' (ASCII) and 'P5' (binary) formats, up to 16/32 bits per pixel
|
||||||
|
* PPM in 'P3' (ASCII) and 'P6' (binary) formats, up to 16/32 bits per pixel component
|
||||||
|
* PAM in 'P7' (binary) format up to 32 bits per pixel component
|
||||||
|
* Limited support for PFM in 'Pf' (gray) and 'PF' (RGB) formats, 32 bits floating point
|
||||||
|
* Write support for the following formats:
|
||||||
|
* PPM in 'P6' (binary) format
|
||||||
|
* PAM in 'P7' (binary) format
|
||||||
|
* Standard metadata support
|
||||||
|
|
||||||
|
#### PSD - Adobe Photoshop Document
|
||||||
|
|
||||||
|
* Read support for the following file types:
|
||||||
|
* Monochrome, 1 channel, 1 bit
|
||||||
|
* Indexed, 1 channel, 8 bit
|
||||||
|
* Gray, 1 channel, 8, 16 and 32 bit
|
||||||
|
* Duotone, 1 channel, 8, 16 and 32 bit
|
||||||
|
* RGB, 3-4 channels, 8, 16 and 32 bit
|
||||||
|
* CMYK, 4-5 channels, 8, 16 and 32 bit
|
||||||
|
* Read support for the following compression types:
|
||||||
|
* Uncompressed
|
||||||
|
* RLE (PackBits)
|
||||||
|
* Layer support
|
||||||
|
* Image layers only, in all of the above types
|
||||||
|
* Thumbnail support
|
||||||
|
* JPEG
|
||||||
|
* RAW (RGB)
|
||||||
|
* Support for "Large Document Format" (PSB)
|
||||||
|
* Native and Standard metadata support
|
||||||
|
|
||||||
|
#### TIFF - Aldus/Adobe Tagged Image File Format
|
||||||
|
|
||||||
|
* Read support for the following "Baseline" TIFF file types:
|
||||||
|
* Class B (Bi-level), all relevant compression types, 1 bit per sample
|
||||||
|
* Class G (Gray), all relevant compression types, 2, 4, 8, 16 or 32 bits per sample, unsigned integer
|
||||||
|
* Class P (Palette/indexed color), all relevant compression types, 1, 2, 4, 8 or 16 bits per sample, unsigned integer
|
||||||
|
* Class R (RGB), all relevant compression types, 8 or 16 bits per sample, unsigned integer
|
||||||
|
* Read support for the following TIFF extensions:
|
||||||
|
* Tiling
|
||||||
|
* Class F (Facsimile), CCITT Modified Huffman RLE, T4 and T6 (type 2, 3 and 4) compressions.
|
||||||
|
* LZW Compression (type 5)
|
||||||
|
* "Old-style" JPEG Compression (type 6), as a best effort, as the spec is not well-defined
|
||||||
|
* JPEG Compression (type 7)
|
||||||
|
* ZLib (aka Adobe-style Deflate) Compression (type 8)
|
||||||
|
* Deflate Compression (type 32946)
|
||||||
|
* Horizontal differencing Predictor (type 2) for LZW, ZLib, Deflate and PackBits compression
|
||||||
|
* Alpha channel (ExtraSamples type 1/Associated Alpha and type 2/Unassociated Alpha)
|
||||||
|
* CMYK data (PhotometricInterpretation type 5/Separated)
|
||||||
|
* YCbCr data (PhotometricInterpretation type 6/YCbCr) for JPEG
|
||||||
|
* CIELab data in TIFF, ITU and ICC variants (PhotometricInterpretation type 9, 10 and 11)
|
||||||
|
* Planar data (PlanarConfiguration type 2/Planar)
|
||||||
|
* ICC profiles (ICCProfile)
|
||||||
|
* BitsPerSample values up to 16 for most PhotometricInterpretations
|
||||||
|
* Multiple images (pages) in one file
|
||||||
|
* Write support for most "Baseline" TIFF options
|
||||||
|
* Uncompressed, PackBits, ZLib and Deflate
|
||||||
|
* Additional support for CCITT T4 and and T6 compressions.
|
||||||
|
* Additional support for LZW and JPEG (type 7) compressions
|
||||||
|
* Horizontal differencing Predictor (type 2) for LZW, ZLib, Deflate
|
||||||
|
* Native and Standard metadata support
|
||||||
|
|
||||||
|
Legacy formats
|
||||||
|
|
||||||
|
#### HDR - Radiance High Dynamic Range RGBE Format
|
||||||
|
|
||||||
|
* Read support for the most common RGBE (.hdr) format
|
||||||
|
* Samples are converted to 32 bit floating point (`float`) and normalized using a global tone mapper by default.
|
||||||
|
* Support for custom global tone mappers
|
||||||
|
* Alternatively, use a "null-tone mapper", for unnormalized data (allows local tone mapping)
|
||||||
|
* Unconverted RGBE samples accessible using `readRaster`
|
||||||
|
* Standard metadata support
|
||||||
|
|
||||||
|
#### IFF - Commodore Amiga/Electronic Arts Interchange File Format
|
||||||
|
|
||||||
|
* Legacy format, allows reading popular image format from the Commodore Amiga computer.
|
||||||
|
* Read support for the following file types:
|
||||||
|
* ILBM Indexed color, 1-8 interleaved bit planes, including 6 bit EHB
|
||||||
|
* ILBM Gray, 8 bit interleaved bit planes
|
||||||
|
* ILBM RGB, 24 and 32 bit interleaved bit planes
|
||||||
|
* ILBM HAM6 and HAM8
|
||||||
|
* PBM Indexed color, 1-8 bit,
|
||||||
|
* PBM Gray, 8 bit
|
||||||
|
* PBM RGB, 24 and 32 bit
|
||||||
|
* PBM HAM6 and HAM8
|
||||||
|
* Write support
|
||||||
|
* ILBM Indexed color, 1-8 bits per sample, 8 bit gray, 24 and 32 bit true color.
|
||||||
|
* Support for the following compression types (read/write):
|
||||||
|
* Uncompressed
|
||||||
|
* RLE (PackBits)
|
||||||
|
|
||||||
|
#### PCX - ZSoft Paintbrush Format
|
||||||
|
|
||||||
|
* Read support for the following file types:
|
||||||
|
* Indexed color, 1, 2, 4 or 8 bits per pixel, bit planes or interleaved
|
||||||
|
* Grayscale, 8 bits per pixel
|
||||||
|
* Color (RGB), 8 bits per pixel component
|
||||||
|
* Read support for DCX (multi-page) fax format, containing any of the above types
|
||||||
|
* Support for the following compression types:
|
||||||
|
* Uncompressed (experimental)
|
||||||
|
* RLE compressed
|
||||||
|
* Standard metadata support
|
||||||
|
|
||||||
|
#### PICT - Apple Mac Paint Picture Format
|
||||||
|
|
||||||
|
* Legacy format, especially useful for reading OS X clipboard data.
|
||||||
|
* Read support for the following file types:
|
||||||
|
* QuickDraw (format support is not complete, but supports most OS X clipboard data as well as RGB pixel data)
|
||||||
|
* QuickDraw bitmap
|
||||||
|
* QuickDraw pixmap
|
||||||
|
* QuickTime stills
|
||||||
|
* Write support for RGB pixel data:
|
||||||
|
* QuickDraw pixmap
|
||||||
|
|
||||||
|
#### SGI - Silicon Graphics Image Format
|
||||||
|
|
||||||
|
* Read support for the following file types:
|
||||||
|
* 1, 2, 3 or 4 channel image data
|
||||||
|
* 8 or 16 bits per pixel component
|
||||||
|
* Support for the following compression types:
|
||||||
|
* Uncompressed
|
||||||
|
* RLE compressed
|
||||||
|
* Standard metadata support
|
||||||
|
|
||||||
|
#### TGA - Truevision TGA Image Format
|
||||||
|
|
||||||
|
* Read support for the following file types:
|
||||||
|
* ColorMapped
|
||||||
|
* Monochrome
|
||||||
|
* TrueColor
|
||||||
|
* Support for the following compression types:
|
||||||
|
* Uncompressed
|
||||||
|
* RLE compressed
|
||||||
|
* Standard metadata support
|
||||||
|
* Write support
|
||||||
|
|
||||||
|
Icon/other formats
|
||||||
|
|
||||||
|
#### ICNS - Apple Icon Image
|
||||||
|
|
||||||
|
* Read support for the following icon types:
|
||||||
|
* All known "native" icon types
|
||||||
|
* Large PNG encoded icons
|
||||||
|
* Large JPEG 2000 encoded icons (requires JPEG 2000 ImageIO plugin or fallback to `sips` command line tool)
|
||||||
|
* Write support for PNG encoded icons
|
||||||
|
|
||||||
|
#### ICO & CUR - MS Windows Icon and Cursor Formats
|
||||||
|
|
||||||
|
* Read support for the following file types:
|
||||||
|
* ICO Indexed color, 1, 4 and 8 bit
|
||||||
|
* ICO RGB, 16, 24 and 32 bit
|
||||||
|
* CUR Indexed color, 1, 4 and 8 bit
|
||||||
|
* CUR RGB, 16, 24 and 32 bit
|
||||||
|
* Write support
|
||||||
|
* *3.1* Note: These formats are now part of the BMP plugin
|
||||||
|
|
||||||
|
#### Thumbs.db - MS Windows Thumbs DB
|
||||||
|
|
||||||
|
* Read support
|
||||||
|
|
||||||
|
Other formats, using 3rd party libraries
|
||||||
|
|
||||||
|
#### SVG - Scalable Vector Graphics
|
||||||
|
|
||||||
|
* Read-only support using Batik
|
||||||
|
|
||||||
|
#### WMF - MS Windows MetaFile
|
||||||
|
|
||||||
|
* Limited read-only support using Batik
|
||||||
|
|
||||||
|
**Important note on using Batik:** *Please read [The Apache™ XML Graphics Project - Security](http://xmlgraphics.apache.org/security.html), and make sure you use
|
||||||
|
either version 1.6.1, 1.7.1 or 1.8+.*
|
||||||
|
|
||||||
Note that GIF, PNG and WBMP formats are already supported through the ImageIO API, using the
|
|
||||||
[JDK standard plugins](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/package-summary.html).
|
|
||||||
For BMP, JPEG, and TIFF formats the TwelveMonkeys plugins provides extended format support and additional features.
|
|
||||||
|
|
||||||
## Basic usage
|
## Basic usage
|
||||||
|
|
||||||
Most of the time, all you need to do is simply include the plugins in your project and write:
|
Most of the time, all you need to do is simply include the plugins in your project and write:
|
||||||
|
|
||||||
```java
|
BufferedImage image = ImageIO.read(file);
|
||||||
BufferedImage image = ImageIO.read(file);
|
|
||||||
```
|
|
||||||
|
|
||||||
This will load the first image of the file, entirely into memory.
|
This will load the first image of the file, entirely into memory.
|
||||||
|
|
||||||
The basic and simplest form of writing is:
|
The basic and simplest form of writing is:
|
||||||
|
|
||||||
```java
|
if (!ImageIO.write(image, format, file)) {
|
||||||
if (!ImageIO.write(image, format, file)) {
|
// Handle image not written case
|
||||||
// Handle image not written case
|
}
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
This will write the entire image into a single file, using the default settings for the given format.
|
This will write the entire image into a single file, using the default settings for the given format.
|
||||||
|
|
||||||
@@ -83,44 +269,50 @@ The plugins are discovered automatically at run time. See the [FAQ](#faq) for mo
|
|||||||
If you need more control of read parameters and the reading process, the common idiom for reading is something like:
|
If you need more control of read parameters and the reading process, the common idiom for reading is something like:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
// Create input stream (in try-with-resource block to avoid leaks)
|
// Create input stream
|
||||||
try (ImageInputStream input = ImageIO.createImageInputStream(file)) {
|
ImageInputStream input = ImageIO.createImageInputStream(file);
|
||||||
// Get the reader
|
|
||||||
Iterator<ImageReader> readers = ImageIO.getImageReaders(input);
|
|
||||||
|
|
||||||
if (!readers.hasNext()) {
|
|
||||||
throw new IllegalArgumentException("No reader for: " + file);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageReader reader = readers.next();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader.setInput(input);
|
// Get the reader
|
||||||
|
Iterator<ImageReader> readers = ImageIO.getImageReaders(input);
|
||||||
|
|
||||||
// Optionally, listen for read warnings, progress, etc.
|
if (!readers.hasNext()) {
|
||||||
reader.addIIOReadWarningListener(...);
|
throw new IllegalArgumentException("No reader for: " + file);
|
||||||
reader.addIIOReadProgressListener(...);
|
}
|
||||||
|
|
||||||
ImageReadParam param = reader.getDefaultReadParam();
|
ImageReader reader = readers.next();
|
||||||
|
|
||||||
// Optionally, control read settings like sub sampling, source region or destination etc.
|
try {
|
||||||
param.setSourceSubsampling(...);
|
reader.setInput(input);
|
||||||
param.setSourceRegion(...);
|
|
||||||
param.setDestination(...);
|
|
||||||
// ...
|
|
||||||
|
|
||||||
// Finally read the image, using settings from param
|
// Optionally, listen for read warnings, progress, etc.
|
||||||
BufferedImage image = reader.read(0, param);
|
reader.addIIOReadWarningListener(...);
|
||||||
|
reader.addIIOReadProgressListener(...);
|
||||||
|
|
||||||
// Optionally, read thumbnails, meta data, etc...
|
ImageReadParam param = reader.getDefaultReadParam();
|
||||||
int numThumbs = reader.getNumThumbnails(0);
|
|
||||||
// ...
|
// Optionally, control read settings like sub sampling, source region or destination etc.
|
||||||
|
param.setSourceSubsampling(...);
|
||||||
|
param.setSourceRegion(...);
|
||||||
|
param.setDestination(...);
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// Finally read the image, using settings from param
|
||||||
|
BufferedImage image = reader.read(0, param);
|
||||||
|
|
||||||
|
// Optionally, read thumbnails, meta data, etc...
|
||||||
|
int numThumbs = reader.getNumThumbnails(0);
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
// Dispose reader in finally block to avoid memory leaks
|
||||||
|
reader.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
// Dispose reader in finally block to avoid memory leaks
|
// Close stream in finally block to avoid resource leaks
|
||||||
reader.dispose();
|
input.close();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Query the reader for source image dimensions using `reader.getWidth(n)` and `reader.getHeight(n)` without reading the
|
Query the reader for source image dimensions using `reader.getWidth(n)` and `reader.getHeight(n)` without reading the
|
||||||
@@ -132,56 +324,86 @@ It's also possible to read multiple images from the same file in a loop, using `
|
|||||||
If you need more control of write parameters and the writing process, the common idiom for writing is something like:
|
If you need more control of write parameters and the writing process, the common idiom for writing is something like:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
// Get the writer
|
// Get the writer
|
||||||
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(format);
|
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(format);
|
||||||
|
|
||||||
if (!writers.hasNext()) {
|
if (!writers.hasNext()) {
|
||||||
throw new IllegalArgumentException("No writer for: " + format);
|
throw new IllegalArgumentException("No writer for: " + format);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageWriter writer = writers.next();
|
ImageWriter writer = writers.next();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Create output stream (in try-with-resource block to avoid leaks)
|
// Create output stream
|
||||||
try (ImageOutputStream output = ImageIO.createImageOutputStream(file)) {
|
ImageOutputStream output = ImageIO.createImageOutputStream(file);
|
||||||
writer.setOutput(output);
|
|
||||||
|
try {
|
||||||
// Optionally, listen to progress, warnings, etc.
|
writer.setOutput(output);
|
||||||
|
|
||||||
ImageWriteParam param = writer.getDefaultWriteParam();
|
// Optionally, listen to progress, warnings, etc.
|
||||||
|
|
||||||
// Optionally, control format specific settings of param (requires casting), or
|
ImageWriteParam param = writer.getDefaultWriteParam();
|
||||||
// control generic write settings like sub sampling, source region, output type etc.
|
|
||||||
|
// Optionally, control format specific settings of param (requires casting), or
|
||||||
// Optionally, provide thumbnails and image/stream metadata
|
// control generic write settings like sub sampling, source region, output type etc.
|
||||||
writer.write(..., new IIOImage(..., image, ...), param);
|
|
||||||
|
// Optionally, provide thumbnails and image/stream metadata
|
||||||
|
writer.write(..., new IIOImage(..., image, ...), param);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
// Close stream in finally block to avoid resource leaks
|
||||||
|
output.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
// Dispose writer in finally block to avoid memory leaks
|
||||||
|
writer.dispose();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
finally {
|
|
||||||
// Dispose writer in finally block to avoid memory leaks
|
|
||||||
writer.dispose();
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
For more advanced usage, and information on how to use the ImageIO API, I suggest you read the
|
For more advanced usage, and information on how to use the ImageIO API, I suggest you read the
|
||||||
[Java Image I/O API Guide](https://docs.oracle.com/javase/7/docs/technotes/guides/imageio/spec/imageio_guideTOC.fm.html)
|
[Java Image I/O API Guide](http://docs.oracle.com/javase/7/docs/technotes/guides/imageio/spec/imageio_guideTOC.fm.html)
|
||||||
from Oracle.
|
from Oracle.
|
||||||
|
|
||||||
#### Adobe Clipping Path support
|
|
||||||
|
|
||||||
```java
|
#### Deploying the plugins in a web app
|
||||||
import com.twelvemonkeys.imageio.path.Paths;
|
|
||||||
|
|
||||||
...
|
Because the `ImageIO` plugin registry (the `IIORegistry`) is "VM global", it doesn't by default work well with
|
||||||
|
servlet contexts. This is especially evident if you load plugins from the `WEB-INF/lib` or `classes` folder.
|
||||||
|
Unless you add `ImageIO.scanForPlugins()` somewhere in your code, the plugins might never be available at all.
|
||||||
|
|
||||||
try (ImageInputStream stream = ImageIO.createImageInputStream(new File("image_with_path.jpg")) {
|
In addition, servlet contexts dynamically loads and unloads classes (using a new class loader per context).
|
||||||
BufferedImage image = Paths.readClipped(stream);
|
If you restart your application, old classes will by default remain in memory forever (because the next time
|
||||||
|
`scanForPlugins` is called, it's another `ClassLoader` that scans/loads classes, and thus they will be new instances
|
||||||
|
in the registry). If a read is attempted using one of the remaining "old" readers, weird exceptions
|
||||||
|
(like `NullPointerException`s when accessing `static final` initialized fields or `NoClassDefFoundError`s
|
||||||
|
for uninitialized inner classes) may occur.
|
||||||
|
|
||||||
// Do something with the clipped image...
|
To work around both the discovery problem and the resource leak,
|
||||||
}
|
it is *strongly recommended* to use the `IIOProviderContextListener` that implements
|
||||||
|
dynamic loading and unloading of ImageIO plugins for web applications.
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<web-app ...>
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
<listener>
|
||||||
|
<display-name>ImageIO service provider loader/unloader</display-name>
|
||||||
|
<listener-class>com.twelvemonkeys.servlet.image.IIOProviderContextListener</listener-class>
|
||||||
|
</listener>
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
</web-app>
|
||||||
```
|
```
|
||||||
See [Adobe Clipping Path support on the Wiki](https://github.com/haraldk/TwelveMonkeys/wiki/Photoshop-Clipping-Path-support) for more details and example code.
|
|
||||||
|
|
||||||
|
Loading plugins from `WEB-INF/lib` without the context listener installed is unsupported and will not work correctly.
|
||||||
|
|
||||||
|
The context listener has no dependencies to the TwelveMonkeys ImageIO plugins, and may be used with JAI ImageIO
|
||||||
|
or other ImageIO plugins as well.
|
||||||
|
|
||||||
|
Another safe option, is to place the JAR files in the application server's shared or common lib folder.
|
||||||
|
|
||||||
#### Using the ResampleOp
|
#### Using the ResampleOp
|
||||||
|
|
||||||
@@ -189,15 +411,15 @@ The library comes with a resampling (image resizing) operation, that contains ma
|
|||||||
to provide excellent results at reasonable speed.
|
to provide excellent results at reasonable speed.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
import com.twelvemonkeys.image.ResampleOp;
|
import com.twelvemonkeys.image.ResampleOp;
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
BufferedImage input = ...; // Image to resample
|
BufferedImage input = ...; // Image to resample
|
||||||
int width, height = ...; // new width/height
|
int width, height = ...; // new width/height
|
||||||
|
|
||||||
BufferedImageOp resampler = new ResampleOp(width, height, ResampleOp.FILTER_LANCZOS); // A good default filter, see class documentation for more info
|
BufferedImageOp resampler = new ResampleOp(width, height, ResampleOp.FILTER_LANCZOS); // A good default filter, see class documentation for more info
|
||||||
BufferedImage output = resampler.filter(input, null);
|
BufferedImage output = resampler.filter(input, null);
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Using the DiffusionDither
|
#### Using the DiffusionDither
|
||||||
@@ -206,30 +428,30 @@ The library comes with a dithering operation, that can be used to convert `Buffe
|
|||||||
Floyd-Steinberg error-diffusion dither.
|
Floyd-Steinberg error-diffusion dither.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
import com.twelvemonkeys.image.DiffusionDither;
|
import com.twelvemonkeys.image.DiffusionDither;
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
BufferedImage input = ...; // Image to dither
|
BufferedImage input = ...; // Image to dither
|
||||||
|
|
||||||
BufferedImageOp ditherer = new DiffusionDither();
|
BufferedImageOp ditherer = new DiffusionDither();
|
||||||
BufferedImage output = ditherer.filter(input, null);
|
BufferedImage output = ditherer.filter(input, null);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
Download the project (using [Git](https://git-scm.com/downloads)):
|
Download the project (using [Git](http://git-scm.com/downloads)):
|
||||||
|
|
||||||
$ git clone git@github.com:haraldk/TwelveMonkeys.git
|
$ git clone git@github.com:haraldk/TwelveMonkeys.git
|
||||||
|
|
||||||
This should create a folder named `TwelveMonkeys` in your current directory. Change directory to the `TwelveMonkeys`
|
This should create a folder named `TwelveMonkeys` in your current directory. Change directory to the `TwelveMonkeys`
|
||||||
folder, and issue the command below to build.
|
folder, and issue the command below to build.
|
||||||
|
|
||||||
Build the project (using [Maven](https://maven.apache.org/download.cgi)):
|
Build the project (using [Maven](http://maven.apache.org/download.cgi)):
|
||||||
|
|
||||||
$ mvn package
|
$ mvn package
|
||||||
|
|
||||||
Currently, the recommended JDK for making a build is Oracle JDK 8.x.
|
Currently, the recommended JDK for making a build is Oracle JDK 7.x or 8.x.
|
||||||
|
|
||||||
It's possible to build using OpenJDK, but some tests might fail due to some minor differences between the color management systems used. You will need to either disable the tests in question, or build without tests altogether.
|
It's possible to build using OpenJDK, but some tests might fail due to some minor differences between the color management systems used. You will need to either disable the tests in question, or build without tests altogether.
|
||||||
|
|
||||||
@@ -251,10 +473,10 @@ The ImageIO registry and service lookup mechanism will make sure the plugins are
|
|||||||
To verify that the JPEG plugin is installed and used at run-time, you could use the following code:
|
To verify that the JPEG plugin is installed and used at run-time, you could use the following code:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("JPEG");
|
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("JPEG");
|
||||||
while (readers.hasNext()) {
|
while (readers.hasNext()) {
|
||||||
System.out.println("reader: " + readers.next());
|
System.out.println("reader: " + readers.next());
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The first line should print:
|
The first line should print:
|
||||||
@@ -266,193 +488,119 @@ The first line should print:
|
|||||||
To depend on the JPEG and TIFF plugin using Maven, add the following to your POM:
|
To depend on the JPEG and TIFF plugin using Maven, add the following to your POM:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
...
|
|
||||||
<dependencies>
|
|
||||||
...
|
...
|
||||||
<dependency>
|
<dependencies>
|
||||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
...
|
||||||
<artifactId>imageio-jpeg</artifactId>
|
<dependency>
|
||||||
<version>3.8.1</version>
|
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||||
</dependency>
|
<artifactId>imageio-jpeg</artifactId>
|
||||||
<dependency>
|
<version>3.4.1</version>
|
||||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
</dependency>
|
||||||
<artifactId>imageio-tiff</artifactId>
|
<dependency>
|
||||||
<version>3.8.1</version>
|
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||||
</dependency>
|
<artifactId>imageio-tiff</artifactId>
|
||||||
|
<version>3.4.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Optional dependency. Needed only if you deploy ImageIO plugins as part of a web app.
|
Optional dependency. Needed only if you deploy `ImageIO` plugins as part of a web app.
|
||||||
Make sure you add the IIOProviderContextListener to your web.xml, see above.
|
Make sure you add the `IIOProviderContextListener` to your `web.xml`, see above.
|
||||||
-->
|
-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.twelvemonkeys.servlet</groupId>
|
<groupId>com.twelvemonkeys.servlet</groupId>
|
||||||
<artifactId>servlet</artifactId>
|
<artifactId>servlet</artifactId>
|
||||||
<version>3.8.1</version>
|
<version>3.4.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
<!--
|
|
||||||
Or Jakarta version, for Servlet API 5.0
|
|
||||||
-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.twelvemonkeys.servlet</groupId>
|
|
||||||
<artifactId>servlet</artifactId>
|
|
||||||
<version>3.8.1</version>
|
|
||||||
<classifier>jakarta</classifier>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Manual dependency example
|
#### Manual dependency example
|
||||||
|
|
||||||
To depend on the JPEG and TIFF plugin in your IDE or program, add all of the following JARs to your class path:
|
To depend on the JPEG and TIFF plugin in your IDE or program, add all of the following JARs to your class path:
|
||||||
|
|
||||||
twelvemonkeys-common-lang-3.8.1.jar
|
twelvemonkeys-common-lang-3.4.1.jar
|
||||||
twelvemonkeys-common-io-3.8.1.jar
|
twelvemonkeys-common-io-3.4.1.jar
|
||||||
twelvemonkeys-common-image-3.8.1.jar
|
twelvemonkeys-common-image-3.4.1.jar
|
||||||
twelvemonkeys-imageio-core-3.8.1.jar
|
twelvemonkeys-imageio-core-3.4.1.jar
|
||||||
twelvemonkeys-imageio-metadata-3.8.1.jar
|
twelvemonkeys-imageio-metadata-3.4.1.jar
|
||||||
twelvemonkeys-imageio-jpeg-3.8.1.jar
|
twelvemonkeys-imageio-jpeg-3.4.1.jar
|
||||||
twelvemonkeys-imageio-tiff-3.8.1.jar
|
twelvemonkeys-imageio-tiff-3.4.1.jar
|
||||||
|
|
||||||
#### Deploying the plugins in a web app
|
|
||||||
|
|
||||||
Because the `ImageIO` plugin registry (the `IIORegistry`) is "VM global", it doesn't by default work well with
|
|
||||||
servlet contexts. This is especially evident if you load plugins from the `WEB-INF/lib` or `classes` folder.
|
|
||||||
Unless you add `ImageIO.scanForPlugins()` somewhere in your code, the plugins might never be available at all.
|
|
||||||
|
|
||||||
In addition, servlet contexts dynamically loads and unloads classes (using a new class loader per context).
|
|
||||||
If you restart your application, old classes will by default remain in memory forever (because the next time
|
|
||||||
`scanForPlugins` is called, it's another `ClassLoader` that scans/loads classes, and thus they will be new instances
|
|
||||||
in the registry). If a read is attempted using one of the remaining "old" readers, weird exceptions
|
|
||||||
(like `NullPointerException`s when accessing `static final` initialized fields or `NoClassDefFoundError`s
|
|
||||||
for uninitialized inner classes) may occur.
|
|
||||||
|
|
||||||
To work around both the discovery problem and the resource leak,
|
|
||||||
it is *strongly recommended* to use the `IIOProviderContextListener` that implements
|
|
||||||
dynamic loading and unloading of ImageIO plugins for web applications.
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<web-app ...>
|
|
||||||
|
|
||||||
...
|
|
||||||
|
|
||||||
<listener>
|
|
||||||
<display-name>ImageIO service provider loader/unloader</display-name>
|
|
||||||
<listener-class>com.twelvemonkeys.servlet.image.IIOProviderContextListener</listener-class>
|
|
||||||
</listener>
|
|
||||||
|
|
||||||
...
|
|
||||||
|
|
||||||
</web-app>
|
|
||||||
```
|
|
||||||
|
|
||||||
Loading plugins from `WEB-INF/lib` without the context listener installed is unsupported and will not work correctly.
|
|
||||||
|
|
||||||
The context listener has no dependencies to the TwelveMonkeys ImageIO plugins, and may be used with JAI ImageIO
|
|
||||||
or other ImageIO plugins as well.
|
|
||||||
|
|
||||||
Another safe option, is to place the JAR files in the application server's shared or common lib folder.
|
|
||||||
|
|
||||||
#### Including the plugins in a "fat" JAR
|
|
||||||
|
|
||||||
The recommended way to use the plugins, is just to include the JARs as-is in your project, through a Maven dependency or similar.
|
|
||||||
Re-packaging is not necessary to use the library, and not recommended.
|
|
||||||
|
|
||||||
However, if you like to create a "fat"
|
|
||||||
JAR, or otherwise like to re-package the JARs for some reason, it's important to remember that automatic discovery of
|
|
||||||
the plugins by ImageIO depends on the
|
|
||||||
[Service Provider Interface (SPI)](https://docs.oracle.com/javase/tutorial/sound/SPI-intro.html) mechanism.
|
|
||||||
In short, each JAR contains a special folder, named `META-INF/services` containing one or more files,
|
|
||||||
typically `javax.imageio.spi.ImageReaderSpi` and `javax.imageio.spi.ImageWriterSpi`.
|
|
||||||
These files exist *with the same name in every JAR*,
|
|
||||||
so if you simply unpack everything to a single folder or create a JAR, files will be overwritten and behavior be
|
|
||||||
unspecified (most likely you will end up with a single plugin being installed).
|
|
||||||
|
|
||||||
The solution is to make sure all files with the same name, are merged to a single file,
|
|
||||||
containing all the SPI information of each type. If using the Maven Shade plugin, you should use the
|
|
||||||
[ServicesResourceTransformer](https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#ServicesResourceTransformer)
|
|
||||||
to properly merge these files. You may also want to use the
|
|
||||||
[ManifestResourceTransforme](https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#ManifestResourceTransformer)
|
|
||||||
to get the correct vendor name, version info etc.
|
|
||||||
Other "fat" JAR bundlers will probably have similar mechanisms to merge entries with the same name.
|
|
||||||
|
|
||||||
### Links to prebuilt binaries
|
### Links to prebuilt binaries
|
||||||
|
|
||||||
##### Latest version (3.8.1)
|
##### Latest version (3.4.1)
|
||||||
|
|
||||||
Requires Java 7 or later.
|
Requires Java 7 or later.
|
||||||
|
|
||||||
Common dependencies
|
Common dependencies
|
||||||
* [common-lang-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/common/common-lang/3.8.1/common-lang-3.8.1.jar)
|
* [common-lang-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/common/common-lang/3.4.1/common-lang-3.4.1.jar)
|
||||||
* [common-io-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/common/common-io/3.8.1/common-io-3.8.1.jar)
|
* [common-io-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/common/common-io/3.4.1/common-io-3.4.1.jar)
|
||||||
* [common-image-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/common/common-image/3.8.1/common-image-3.8.1.jar)
|
* [common-image-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/common/common-image/3.4.1/common-image-3.4.1.jar)
|
||||||
|
|
||||||
ImageIO dependencies
|
ImageIO dependencies
|
||||||
* [imageio-core-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-core/3.8.1/imageio-core-3.8.1.jar)
|
* [imageio-core-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-core/3.4.1/imageio-core-3.4.1.jar)
|
||||||
* [imageio-metadata-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-metadata/3.8.1/imageio-metadata-3.8.1.jar)
|
* [imageio-metadata-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-metadata/3.4.1/imageio-metadata-3.4.1.jar)
|
||||||
|
|
||||||
ImageIO plugins
|
ImageIO plugins
|
||||||
* [imageio-bmp-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-bmp/3.8.1/imageio-bmp-3.8.1.jar)
|
* [imageio-bmp-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-bmp/3.4.1/imageio-bmp-3.4.1.jar)
|
||||||
* [imageio-hdr-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-hdr/3.8.1/imageio-hdr-3.8.1.jar)
|
* [imageio-jpeg-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-jpeg/3.4.1/imageio-jpeg-3.4.1.jar)
|
||||||
* [imageio-icns-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-icns/3.8.1/imageio-icns-3.8.1.jar)
|
* [imageio-tiff-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-tiff/3.4.1/imageio-tiff-3.4.1.jar)
|
||||||
* [imageio-iff-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-iff/3.8.1/imageio-iff-3.8.1.jar)
|
* [imageio-pnm-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-pnm/3.4.1/imageio-pnm-3.4.1.jar)
|
||||||
* [imageio-jpeg-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-jpeg/3.8.1/imageio-jpeg-3.8.1.jar)
|
* [imageio-psd-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-psd/3.4.1/imageio-psd-3.4.1.jar)
|
||||||
* [imageio-pcx-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-pcx/3.8.1/imageio-pcx-3.8.1.jar)
|
* [imageio-hdr-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-hdr/3.4.1/imageio-hdr-3.4.1.jar)
|
||||||
* [imageio-pict-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-pict/3.8.1/imageio-pict-3.8.1.jar)
|
* [imageio-iff-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-iff/3.4.1/imageio-iff-3.4.1.jar)
|
||||||
* [imageio-pnm-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-pnm/3.8.1/imageio-pnm-3.8.1.jar)
|
* [imageio-pcx-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-pcx/3.4.1/imageio-pcx-3.4.1.jar)
|
||||||
* [imageio-psd-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-psd/3.8.1/imageio-psd-3.8.1.jar)
|
* [imageio-pict-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-pict/3.4.1/imageio-pict-3.4.1.jar)
|
||||||
* [imageio-sgi-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-sgi/3.8.1/imageio-sgi-3.8.1.jar)
|
* [imageio-sgi-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-sgi/3.4.1/imageio-sgi-3.4.1.jar)
|
||||||
* [imageio-tga-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-tga/3.8.1/imageio-tga-3.8.1.jar)
|
* [imageio-tga-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-tga/3.4.1/imageio-tga-3.4.1.jar)
|
||||||
* [imageio-thumbsdb-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-thumbsdb/3.8.1/imageio-thumbsdb-3.8.1.jar)
|
* [imageio-icns-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-icns/3.4.1/imageio-icns-3.4.1.jar)
|
||||||
* [imageio-tiff-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-tiff/3.8.1/imageio-tiff-3.8.1.jar)
|
* [imageio-thumbsdb-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-thumbsdb/3.4.1/imageio-thumbsdb-3.4.1.jar)
|
||||||
* [imageio-webp-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-webp/3.8.1/imageio-webp-3.8.1.jar)
|
|
||||||
* [imageio-xwd-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-xwd/3.8.1/imageio-xwd-3.8.1.jar)
|
|
||||||
|
|
||||||
ImageIO plugins requiring 3rd party libs
|
ImageIO plugins requiring 3rd party libs
|
||||||
* [imageio-batik-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-batik/3.8.1/imageio-batik-3.8.1.jar)
|
* [imageio-batik-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-batik/3.4.1/imageio-batik-3.4.1.jar)
|
||||||
|
|
||||||
Photoshop Path support for ImageIO
|
Photoshop Path support for ImageIO
|
||||||
* [imageio-clippath-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-clippath/3.8.1/imageio-clippath-3.8.1.jar)
|
* [imageio-clippath-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-clippath/3.4.1/imageio-clippath-3.4.1.jar)
|
||||||
|
|
||||||
Servlet support
|
Servlet support
|
||||||
* [servlet-3.8.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/servlet/servlet/3.8.1/servlet-3.8.1.jar)
|
* [servlet-3.4.1.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/servlet/servlet/3.4.1/servlet-3.4.1.jar)
|
||||||
|
|
||||||
##### Old version (3.0.x)
|
##### Old version (3.0.x)
|
||||||
|
|
||||||
Use this version for projects that requires Java 6 or need the JMagick support. *Does not support Java 8 or later*.
|
Use this version for projects that requires Java 6 or need the JMagick support. *Does not support Java 8 or later*.
|
||||||
|
|
||||||
Common dependencies
|
Common dependencies
|
||||||
* [common-lang-3.0.2.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/common/common-lang/3.0.2/common-lang-3.0.2.jar)
|
* [common-lang-3.0.2.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/common/common-lang/3.0.2/common-lang-3.0.2.jar)
|
||||||
* [common-io-3.0.2.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/common/common-io/3.0.2/common-io-3.0.2.jar)
|
* [common-io-3.0.2.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/common/common-io/3.0.2/common-io-3.0.2.jar)
|
||||||
* [common-image-3.0.2.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/common/common-image/3.0.2/common-image-3.0.2.jar)
|
* [common-image-3.0.2.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/common/common-image/3.0.2/common-image-3.0.2.jar)
|
||||||
|
|
||||||
ImageIO dependencies
|
ImageIO dependencies
|
||||||
* [imageio-core-3.0.2.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-core/3.0.2/imageio-core-3.0.2.jar)
|
* [imageio-core-3.0.2.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-core/3.0.2/imageio-core-3.0.2.jar)
|
||||||
* [imageio-metadata-3.0.2.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-metadata/3.0.2/imageio-metadata-3.0.2.jar)
|
* [imageio-metadata-3.0.2.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-metadata/3.0.2/imageio-metadata-3.0.2.jar)
|
||||||
|
|
||||||
ImageIO plugins
|
ImageIO plugins
|
||||||
* [imageio-jpeg-3.0.2.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-jpeg/3.0.2/imageio-jpeg-3.0.2.jar)
|
* [imageio-jpeg-3.0.2.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-jpeg/3.0.2/imageio-jpeg-3.0.2.jar)
|
||||||
* [imageio-tiff-3.0.2.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-tiff/3.0.2/imageio-tiff-3.0.2.jar)
|
* [imageio-tiff-3.0.2.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-tiff/3.0.2/imageio-tiff-3.0.2.jar)
|
||||||
* [imageio-psd-3.0.2.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-psd/3.0.2/imageio-psd-3.0.2.jar)
|
* [imageio-psd-3.0.2.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-psd/3.0.2/imageio-psd-3.0.2.jar)
|
||||||
* [imageio-pict-3.0.2.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-pict/3.0.2/imageio-pict-3.0.2.jar)
|
* [imageio-pict-3.0.2.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-pict/3.0.2/imageio-pict-3.0.2.jar)
|
||||||
* [imageio-iff-3.0.2.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-iff/3.0.2/imageio-iff-3.0.2.jar)
|
* [imageio-iff-3.0.2.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-iff/3.0.2/imageio-iff-3.0.2.jar)
|
||||||
* [imageio-icns-3.0.2.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-icns/3.0.2/imageio-icns-3.0.2.jar)
|
* [imageio-icns-3.0.2.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-icns/3.0.2/imageio-icns-3.0.2.jar)
|
||||||
* [imageio-ico-3.0.2.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-ico/3.0.2/imageio-ico-3.0.2.jar)
|
* [imageio-ico-3.0.2.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-ico/3.0.2/imageio-ico-3.0.2.jar)
|
||||||
* [imageio-thumbsdb-3.0.2.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-thumbsdb/3.0.2/imageio-thumbsdb-3.0.2.jar)
|
* [imageio-thumbsdb-3.0.2.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-thumbsdb/3.0.2/imageio-thumbsdb-3.0.2.jar)
|
||||||
|
|
||||||
ImageIO plugins requiring 3rd party libs
|
ImageIO plugins requiring 3rd party libs
|
||||||
* [imageio-batik-3.0.2.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-batik/3.0.2/imageio-batik-3.0.2.jar)
|
* [imageio-batik-3.0.2.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-batik/3.0.2/imageio-batik-3.0.2.jar)
|
||||||
* [imageio-jmagick-3.0.2.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-jmagick/3.0.2/imageio-jmagick-3.0.2.jar)
|
* [imageio-jmagick-3.0.2.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-jmagick/3.0.2/imageio-jmagick-3.0.2.jar)
|
||||||
|
|
||||||
Servlet support
|
Servlet support
|
||||||
* [servlet-3.0.2.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/servlet/servlet/3.0.2/servlet-3.0.2.jar)
|
* [servlet-3.0.2.jar](http://search.maven.org/remotecontent?filepath=com/twelvemonkeys/servlet/servlet/3.0.2/servlet-3.0.2.jar)
|
||||||
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
This project is provided under the OSI approved [BSD license](https://opensource.org/licenses/BSD-3-Clause):
|
The project is distributed under the OSI approved [BSD license](http://opensource.org/licenses/BSD-3-Clause):
|
||||||
|
|
||||||
Copyright (c) 2008-2020, Harald Kuhr
|
Copyright (c) 2008-2018, Harald Kuhr
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
@@ -505,7 +653,7 @@ a: The TwelveMonkeys ImageIO project contains plug-ins for ImageIO. ImageIO uses
|
|||||||
|
|
||||||
All you have have to do, is to make sure you have the TwelveMonkeys JARs in your classpath.
|
All you have have to do, is to make sure you have the TwelveMonkeys JARs in your classpath.
|
||||||
|
|
||||||
You can read more about the registry and the lookup mechanism in the [IIORegistry API doc](https://docs.oracle.com/javase/7/docs/api/javax/imageio/spi/IIORegistry.html).
|
You can read more about the registry and the lookup mechanism in the [IIORegistry API doc](http://docs.oracle.com/javase/7/docs/api/javax/imageio/spi/IIORegistry.html).
|
||||||
|
|
||||||
The fine print: The TwelveMonkeys service providers for JPEG, BMP and TIFF, overrides the onRegistration method, and
|
The fine print: The TwelveMonkeys service providers for JPEG, BMP and TIFF, overrides the onRegistration method, and
|
||||||
utilizes the pairwise partial ordering mechanism of the `IIOServiceRegistry` to make sure it is installed before
|
utilizes the pairwise partial ordering mechanism of the `IIOServiceRegistry` to make sure it is installed before
|
||||||
@@ -513,15 +661,10 @@ the Sun/Oracle provided `JPEGImageReader` and `BMPImageReader`, and the Apple pr
|
|||||||
respectively. Using the pairwise ordering will not remove any functionality form these implementations, but in most
|
respectively. Using the pairwise ordering will not remove any functionality form these implementations, but in most
|
||||||
cases you'll end up using the TwelveMonkeys plug-ins instead.
|
cases you'll end up using the TwelveMonkeys plug-ins instead.
|
||||||
|
|
||||||
q: Why is there no support for common formats like GIF or PNG?
|
|
||||||
|
|
||||||
a: The short answer is simply that the built-in support in ImageIO for these formats are good enough as-is.
|
|
||||||
If you are looking for better PNG write performance on Java 7 and 8, see [JDK9 PNG Writer Backport](https://github.com/gredler/jdk9-png-writer-backport).
|
|
||||||
|
|
||||||
|
|
||||||
q: What about JAI? Several of the formats are already supported by JAI.
|
q: What about JAI? Several of the formats are already supported by JAI.
|
||||||
|
|
||||||
a: While JAI (and jai-imageio in particular) have support for some of the same formats, JAI has some major issues.
|
a: While JAI (and jai-imageio in particular) have support for some of the formats, JAI has some major issues.
|
||||||
The most obvious being:
|
The most obvious being:
|
||||||
- It's not actively developed. No issues has been fixed for years.
|
- It's not actively developed. No issues has been fixed for years.
|
||||||
- To get full format support, you need native libs.
|
- To get full format support, you need native libs.
|
||||||
|
|||||||
+1
-11
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.twelvemonkeys</groupId>
|
<groupId>com.twelvemonkeys</groupId>
|
||||||
<artifactId>twelvemonkeys</artifactId>
|
<artifactId>twelvemonkeys</artifactId>
|
||||||
<version>3.8.4-SNAPSHOT</version>
|
<version>3.4.4-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>com.twelvemonkeys.bom</groupId>
|
<groupId>com.twelvemonkeys.bom</groupId>
|
||||||
@@ -123,16 +123,6 @@
|
|||||||
<artifactId>imageio-tiff</artifactId>
|
<artifactId>imageio-tiff</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
|
||||||
<artifactId>imageio-webp</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
|
||||||
<artifactId>imageio-xwd</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- ImageIO 3rd party dependent plugins -->
|
<!-- ImageIO 3rd party dependent plugins -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.twelvemonkeys.common</groupId>
|
<groupId>com.twelvemonkeys.common</groupId>
|
||||||
<artifactId>common</artifactId>
|
<artifactId>common</artifactId>
|
||||||
<version>3.8.4-SNAPSHOT</version>
|
<version>3.4.4-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>common-image</artifactId>
|
<artifactId>common-image</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
@@ -13,10 +13,6 @@
|
|||||||
The TwelveMonkeys Common Image support
|
The TwelveMonkeys Common Image support
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<project.jpms.module.name>com.twelvemonkeys.common.image</project.jpms.module.name>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.groupId}</groupId>
|
<groupId>${project.groupId}</groupId>
|
||||||
@@ -31,7 +27,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jmagick</groupId>
|
<groupId>jmagick</groupId>
|
||||||
<artifactId>jmagick</artifactId>
|
<artifactId>jmagick</artifactId>
|
||||||
<version>6.6.9</version>
|
<version>6.2.4</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|||||||
@@ -34,13 +34,7 @@ import java.awt.*;
|
|||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.*;
|
||||||
import java.awt.image.BufferedImageOp;
|
|
||||||
import java.awt.image.ColorModel;
|
|
||||||
import java.awt.image.ImagingOpException;
|
|
||||||
import java.awt.image.Raster;
|
|
||||||
import java.awt.image.RasterOp;
|
|
||||||
import java.awt.image.WritableRaster;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a drop-in replacement for {@link java.awt.image.AffineTransformOp}.
|
* This is a drop-in replacement for {@link java.awt.image.AffineTransformOp}.
|
||||||
@@ -76,7 +70,6 @@ public class AffineTransformOp implements BufferedImageOp, RasterOp {
|
|||||||
delegate = new java.awt.image.AffineTransformOp(xform, interpolationType);
|
delegate = new java.awt.image.AffineTransformOp(xform, interpolationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
|
||||||
@Override
|
@Override
|
||||||
public BufferedImage filter(final BufferedImage src, BufferedImage dst) {
|
public BufferedImage filter(final BufferedImage src, BufferedImage dst) {
|
||||||
try {
|
try {
|
||||||
@@ -87,9 +80,10 @@ public class AffineTransformOp implements BufferedImageOp, RasterOp {
|
|||||||
dst = createCompatibleDestImage(src, src.getColorModel());
|
dst = createCompatibleDestImage(src, src.getColorModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
Graphics2D g2d = dst.createGraphics();
|
Graphics2D g2d = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
g2d = dst.createGraphics();
|
||||||
int interpolationType = delegate.getInterpolationType();
|
int interpolationType = delegate.getInterpolationType();
|
||||||
|
|
||||||
if (interpolationType > 0) {
|
if (interpolationType > 0) {
|
||||||
@@ -115,7 +109,9 @@ public class AffineTransformOp implements BufferedImageOp, RasterOp {
|
|||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
g2d.dispose();
|
if (g2d != null) {
|
||||||
|
g2d.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ import java.awt.image.BufferedImage;
|
|||||||
*/
|
*/
|
||||||
public class BufferedImageIcon implements Icon {
|
public class BufferedImageIcon implements Icon {
|
||||||
private final BufferedImage image;
|
private final BufferedImage image;
|
||||||
private final int width;
|
private int width;
|
||||||
private final int height;
|
private int height;
|
||||||
private final boolean fast;
|
private final boolean fast;
|
||||||
|
|
||||||
public BufferedImageIcon(BufferedImage pImage) {
|
public BufferedImageIcon(BufferedImage pImage) {
|
||||||
@@ -81,10 +81,11 @@ public class BufferedImageIcon implements Icon {
|
|||||||
else {
|
else {
|
||||||
//System.out.println("Scaling using interpolation");
|
//System.out.println("Scaling using interpolation");
|
||||||
Graphics2D g2 = (Graphics2D) g;
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
AffineTransform transform = AffineTransform.getTranslateInstance(x, y);
|
AffineTransform xform = AffineTransform.getTranslateInstance(x, y);
|
||||||
transform.scale(width / (double) image.getWidth(), height / (double) image.getHeight());
|
xform.scale(width / (double) image.getWidth(), height / (double) image.getHeight());
|
||||||
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
|
||||||
g2.drawImage(image, transform, null);
|
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||||
|
g2.drawImage(image, xform, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -587,7 +587,6 @@ class IndexImage {
|
|||||||
* @deprecated Use {@link #getIndexColorModel(Image,int,int)} instead!
|
* @deprecated Use {@link #getIndexColorModel(Image,int,int)} instead!
|
||||||
* This version will be removed in a later version of the API.
|
* This version will be removed in a later version of the API.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public static IndexColorModel getIndexColorModel(Image pImage, int pNumberOfColors, boolean pFast) {
|
public static IndexColorModel getIndexColorModel(Image pImage, int pNumberOfColors, boolean pFast) {
|
||||||
return getIndexColorModel(pImage, pNumberOfColors, pFast ? COLOR_SELECTION_FAST : COLOR_SELECTION_QUALITY);
|
return getIndexColorModel(pImage, pNumberOfColors, pFast ? COLOR_SELECTION_FAST : COLOR_SELECTION_QUALITY);
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-22
@@ -30,26 +30,17 @@
|
|||||||
|
|
||||||
package com.twelvemonkeys.image;
|
package com.twelvemonkeys.image;
|
||||||
|
|
||||||
import static java.lang.Math.min;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
|
import javax.imageio.ImageTypeSpecifier;
|
||||||
import java.awt.color.ColorSpace;
|
import java.awt.color.ColorSpace;
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.*;
|
||||||
import java.awt.image.BufferedImageOp;
|
|
||||||
import java.awt.image.DataBuffer;
|
|
||||||
import java.awt.image.ImagingOpException;
|
|
||||||
import java.awt.image.Raster;
|
|
||||||
import java.awt.image.RasterOp;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.imageio.ImageTypeSpecifier;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AffineTransformOpTest.
|
* AffineTransformOpTest.
|
||||||
@@ -110,7 +101,6 @@ public class AffineTransformOpTest {
|
|||||||
|
|
||||||
private final int width = 30;
|
private final int width = 30;
|
||||||
private final int height = 20;
|
private final int height = 20;
|
||||||
private final double anchor = min(width, height) / 2.0;
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPoint2D() {
|
public void testGetPoint2D() {
|
||||||
@@ -138,8 +128,8 @@ public class AffineTransformOpTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFilterRotateBIStandard() {
|
public void testFilterRotateBIStandard() {
|
||||||
BufferedImageOp jreOp = new java.awt.image.AffineTransformOp(AffineTransform.getQuadrantRotateInstance(1, anchor, anchor), null);
|
BufferedImageOp jreOp = new java.awt.image.AffineTransformOp(AffineTransform.getQuadrantRotateInstance(1, Math.min(width, height) / 2, Math.min(width, height) / 2), null);
|
||||||
BufferedImageOp tmOp = new com.twelvemonkeys.image.AffineTransformOp(AffineTransform.getQuadrantRotateInstance(1, anchor, anchor), null);
|
BufferedImageOp tmOp = new com.twelvemonkeys.image.AffineTransformOp(AffineTransform.getQuadrantRotateInstance(1, Math.min(width, height) / 2, Math.min(width, height) / 2), null);
|
||||||
|
|
||||||
for (Integer type : TYPES) {
|
for (Integer type : TYPES) {
|
||||||
BufferedImage image = new BufferedImage(width, height, type);
|
BufferedImage image = new BufferedImage(width, height, type);
|
||||||
@@ -157,8 +147,8 @@ public class AffineTransformOpTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFilterRotateBICustom() {
|
public void testFilterRotateBICustom() {
|
||||||
BufferedImageOp jreOp = new java.awt.image.AffineTransformOp(AffineTransform.getQuadrantRotateInstance(1, anchor, anchor), null);
|
BufferedImageOp jreOp = new java.awt.image.AffineTransformOp(AffineTransform.getQuadrantRotateInstance(1, Math.min(width, height) / 2, Math.min(width, height) / 2), null);
|
||||||
BufferedImageOp tmOp = new com.twelvemonkeys.image.AffineTransformOp(AffineTransform.getQuadrantRotateInstance(1, anchor, anchor), null);
|
BufferedImageOp tmOp = new com.twelvemonkeys.image.AffineTransformOp(AffineTransform.getQuadrantRotateInstance(1, Math.min(width, height) / 2, Math.min(width, height) / 2), null);
|
||||||
|
|
||||||
for (ImageTypeSpecifier spec : SPECS) {
|
for (ImageTypeSpecifier spec : SPECS) {
|
||||||
BufferedImage image = spec.createBufferedImage(width, height);
|
BufferedImage image = spec.createBufferedImage(width, height);
|
||||||
@@ -207,8 +197,8 @@ public class AffineTransformOpTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFilterRotateRasterStandard() {
|
public void testFilterRotateRasterStandard() {
|
||||||
RasterOp jreOp = new java.awt.image.AffineTransformOp(AffineTransform.getQuadrantRotateInstance(1, anchor, anchor), null);
|
RasterOp jreOp = new java.awt.image.AffineTransformOp(AffineTransform.getQuadrantRotateInstance(1, Math.min(width, height) / 2, Math.min(width, height) / 2), null);
|
||||||
RasterOp tmOp = new com.twelvemonkeys.image.AffineTransformOp(AffineTransform.getQuadrantRotateInstance(1, anchor, anchor), null);
|
RasterOp tmOp = new com.twelvemonkeys.image.AffineTransformOp(AffineTransform.getQuadrantRotateInstance(1, Math.min(width, height) / 2, Math.min(width, height) / 2), null);
|
||||||
|
|
||||||
for (Integer type : TYPES) {
|
for (Integer type : TYPES) {
|
||||||
Raster raster = new BufferedImage(width, height, type).getRaster();
|
Raster raster = new BufferedImage(width, height, type).getRaster();
|
||||||
@@ -231,6 +221,8 @@ public class AffineTransformOpTest {
|
|||||||
fail("No result!");
|
fail("No result!");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
System.err.println("AffineTransformOpTest.testFilterRotateRasterStandard");
|
||||||
|
System.err.println("type: " + type);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,8 +240,8 @@ public class AffineTransformOpTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFilterRotateRasterCustom() {
|
public void testFilterRotateRasterCustom() {
|
||||||
RasterOp jreOp = new java.awt.image.AffineTransformOp(AffineTransform.getQuadrantRotateInstance(1, anchor, anchor), null);
|
RasterOp jreOp = new java.awt.image.AffineTransformOp(AffineTransform.getQuadrantRotateInstance(1, Math.min(width, height) / 2, Math.min(width, height) / 2), null);
|
||||||
RasterOp tmOp = new com.twelvemonkeys.image.AffineTransformOp(AffineTransform.getQuadrantRotateInstance(1, anchor, anchor), null);
|
RasterOp tmOp = new com.twelvemonkeys.image.AffineTransformOp(AffineTransform.getQuadrantRotateInstance(1, Math.min(width, height) / 2, Math.min(width, height) / 2), null);
|
||||||
|
|
||||||
for (ImageTypeSpecifier spec : SPECS) {
|
for (ImageTypeSpecifier spec : SPECS) {
|
||||||
Raster raster = spec.createBufferedImage(width, height).getRaster();
|
Raster raster = spec.createBufferedImage(width, height).getRaster();
|
||||||
@@ -272,6 +264,8 @@ public class AffineTransformOpTest {
|
|||||||
fail("No result!");
|
fail("No result!");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
System.err.println("AffineTransformOpTest.testFilterRotateRasterCustom");
|
||||||
|
System.err.println("spec: " + spec);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.twelvemonkeys.common</groupId>
|
<groupId>com.twelvemonkeys.common</groupId>
|
||||||
<artifactId>common</artifactId>
|
<artifactId>common</artifactId>
|
||||||
<version>3.8.4-SNAPSHOT</version>
|
<version>3.4.4-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>common-io</artifactId>
|
<artifactId>common-io</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
@@ -13,10 +13,6 @@
|
|||||||
The TwelveMonkeys Common IO support
|
The TwelveMonkeys Common IO support
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<project.jpms.module.name>com.twelvemonkeys.common.io</project.jpms.module.name>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.groupId}</groupId>
|
<groupId>${project.groupId}</groupId>
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An unsynchronized {@code ByteArrayOutputStream} implementation. This version
|
* An unsynchronized {@code ByteArrayOutputStream} implementation. This version
|
||||||
@@ -43,8 +42,11 @@ import java.util.Arrays;
|
|||||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||||
* @version $Id: FastByteArrayOutputStream.java#2 $
|
* @version $Id: FastByteArrayOutputStream.java#2 $
|
||||||
*/
|
*/
|
||||||
// TODO: Performance test of a stream impl that uses list of fixed size blocks, rather than contiguous block
|
// TODO: Performance test of a stream impl that uses list of fixed size blocks, rather than contiguous block
|
||||||
public final class FastByteArrayOutputStream extends ByteArrayOutputStream {
|
public final class FastByteArrayOutputStream extends ByteArrayOutputStream {
|
||||||
|
/** Max grow size (unless if writing more than this amount of bytes) */
|
||||||
|
protected int maxGrowSize = 1024 * 1024; // 1 MB
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@code ByteArrayOutputStream} with the given initial buffer
|
* Creates a {@code ByteArrayOutputStream} with the given initial buffer
|
||||||
* size.
|
* size.
|
||||||
@@ -70,7 +72,7 @@ public final class FastByteArrayOutputStream extends ByteArrayOutputStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(byte[] pBytes, int pOffset, int pLength) {
|
public void write(byte pBytes[], int pOffset, int pLength) {
|
||||||
if ((pOffset < 0) || (pOffset > pBytes.length) || (pLength < 0) ||
|
if ((pOffset < 0) || (pOffset > pBytes.length) || (pLength < 0) ||
|
||||||
((pOffset + pLength) > pBytes.length) || ((pOffset + pLength) < 0)) {
|
((pOffset + pLength) > pBytes.length) || ((pOffset + pLength) < 0)) {
|
||||||
throw new IndexOutOfBoundsException();
|
throw new IndexOutOfBoundsException();
|
||||||
@@ -95,8 +97,10 @@ public final class FastByteArrayOutputStream extends ByteArrayOutputStream {
|
|||||||
|
|
||||||
private void growIfNeeded(int pNewCount) {
|
private void growIfNeeded(int pNewCount) {
|
||||||
if (pNewCount > buf.length) {
|
if (pNewCount > buf.length) {
|
||||||
int newSize = Math.max(buf.length << 1, pNewCount);
|
int newSize = Math.max(Math.min(buf.length << 1, buf.length + maxGrowSize), pNewCount);
|
||||||
buf = Arrays.copyOf(buf, newSize);
|
byte newBuf[] = new byte[newSize];
|
||||||
|
System.arraycopy(buf, 0, newBuf, 0, count);
|
||||||
|
buf = newBuf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +113,10 @@ public final class FastByteArrayOutputStream extends ByteArrayOutputStream {
|
|||||||
// Non-synchronized version of toByteArray
|
// Non-synchronized version of toByteArray
|
||||||
@Override
|
@Override
|
||||||
public byte[] toByteArray() {
|
public byte[] toByteArray() {
|
||||||
return Arrays.copyOf(buf, count);
|
byte newBuf[] = new byte[count];
|
||||||
|
System.arraycopy(buf, 0, newBuf, 0, count);
|
||||||
|
|
||||||
|
return newBuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ public final class FileUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the file (type) extension of the given file.
|
* Gets the file (type) extension of the given file.
|
||||||
* A file extension is the part of the filename, after the last occurrence
|
* A file extension is the part of the filename, after the last occurence
|
||||||
* of a period {@code '.'}.
|
* of a period {@code '.'}.
|
||||||
* If the filename contains no period, {@code null} is returned.
|
* If the filename contains no period, {@code null} is returned.
|
||||||
*
|
*
|
||||||
@@ -922,7 +922,7 @@ public final class FileUtil {
|
|||||||
// A URL should never be able to represent an opaque URI, test anyway
|
// A URL should never be able to represent an opaque URI, test anyway
|
||||||
throw new IllegalArgumentException("URI is not hierarchical");
|
throw new IllegalArgumentException("URI is not hierarchical");
|
||||||
}
|
}
|
||||||
if (path.isEmpty()) {
|
if (path.equals("")) {
|
||||||
throw new IllegalArgumentException("URI path component is empty");
|
throw new IllegalArgumentException("URI path component is empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ import java.io.FilenameFilter;
|
|||||||
* @see WildcardStringParser
|
* @see WildcardStringParser
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public class FilenameMaskFilter implements FilenameFilter {
|
public class FilenameMaskFilter implements FilenameFilter {
|
||||||
|
|
||||||
// TODO: Rewrite to use regexp, or create new class
|
// TODO: Rewrite to use regexp, or create new class
|
||||||
|
|||||||
@@ -442,7 +442,6 @@ public class LittleEndianDataInputStream extends FilterInputStream implements Da
|
|||||||
* @see java.io.BufferedReader#readLine()
|
* @see java.io.BufferedReader#readLine()
|
||||||
* @see java.io.DataInputStream#readLine()
|
* @see java.io.DataInputStream#readLine()
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public String readLine() throws IOException {
|
public String readLine() throws IOException {
|
||||||
DataInputStream ds = new DataInputStream(in);
|
DataInputStream ds = new DataInputStream(in);
|
||||||
return ds.readLine();
|
return ds.readLine();
|
||||||
|
|||||||
@@ -45,39 +45,39 @@ import java.nio.ByteBuffer;
|
|||||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/DecoderStream.java#2 $
|
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/DecoderStream.java#2 $
|
||||||
*/
|
*/
|
||||||
public final class DecoderStream extends FilterInputStream {
|
public final class DecoderStream extends FilterInputStream {
|
||||||
private final ByteBuffer buffer;
|
protected final ByteBuffer buffer;
|
||||||
private final Decoder decoder;
|
protected final Decoder decoder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new decoder stream and chains it to the
|
* Creates a new decoder stream and chains it to the
|
||||||
* input stream specified by the {@code stream} argument.
|
* input stream specified by the {@code pStream} argument.
|
||||||
* The stream will use a default decode buffer size.
|
* The stream will use a default decode buffer size.
|
||||||
*
|
*
|
||||||
* @param stream the underlying input stream.
|
* @param pStream the underlying input stream.
|
||||||
* @param decoder the decoder that will be used to decode the underlying stream
|
* @param pDecoder the decoder that will be used to decode the underlying stream
|
||||||
*
|
*
|
||||||
* @see java.io.FilterInputStream#in
|
* @see java.io.FilterInputStream#in
|
||||||
*/
|
*/
|
||||||
public DecoderStream(final InputStream stream, final Decoder decoder) {
|
public DecoderStream(final InputStream pStream, final Decoder pDecoder) {
|
||||||
// TODO: Let the decoder decide preferred buffer size
|
// TODO: Let the decoder decide preferred buffer size
|
||||||
this(stream, decoder, 1024);
|
this(pStream, pDecoder, 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new decoder stream and chains it to the
|
* Creates a new decoder stream and chains it to the
|
||||||
* input stream specified by the {@code stream} argument.
|
* input stream specified by the {@code pStream} argument.
|
||||||
*
|
*
|
||||||
* @param stream the underlying input stream.
|
* @param pStream the underlying input stream.
|
||||||
* @param decoder the decoder that will be used to decode the underlying stream
|
* @param pDecoder the decoder that will be used to decode the underlying stream
|
||||||
* @param bufferSize the size of the decode buffer
|
* @param pBufferSize the size of the decode buffer
|
||||||
*
|
*
|
||||||
* @see java.io.FilterInputStream#in
|
* @see java.io.FilterInputStream#in
|
||||||
*/
|
*/
|
||||||
public DecoderStream(final InputStream stream, final Decoder decoder, final int bufferSize) {
|
public DecoderStream(final InputStream pStream, final Decoder pDecoder, final int pBufferSize) {
|
||||||
super(stream);
|
super(pStream);
|
||||||
|
|
||||||
this.decoder = decoder;
|
decoder = pDecoder;
|
||||||
buffer = ByteBuffer.allocate(bufferSize);
|
buffer = ByteBuffer.allocate(pBufferSize);
|
||||||
buffer.flip();
|
buffer.flip();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,15 +95,15 @@ public final class DecoderStream extends FilterInputStream {
|
|||||||
return buffer.get() & 0xff;
|
return buffer.get() & 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int read(final byte[] bytes, final int offset, final int length) throws IOException {
|
public int read(final byte pBytes[], final int pOffset, final int pLength) throws IOException {
|
||||||
if (bytes == null) {
|
if (pBytes == null) {
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
}
|
}
|
||||||
else if ((offset < 0) || (offset > bytes.length) || (length < 0) ||
|
else if ((pOffset < 0) || (pOffset > pBytes.length) || (pLength < 0) ||
|
||||||
((offset + length) > bytes.length) || ((offset + length) < 0)) {
|
((pOffset + pLength) > pBytes.length) || ((pOffset + pLength) < 0)) {
|
||||||
throw new IndexOutOfBoundsException("bytes.length=" + bytes.length + " offset=" + offset + " length=" + length);
|
throw new IndexOutOfBoundsException("bytes.length=" + pBytes.length + " offset=" + pOffset + " length=" + pLength);
|
||||||
}
|
}
|
||||||
else if (length == 0) {
|
else if (pLength == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,11 +114,11 @@ public final class DecoderStream extends FilterInputStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read until we have read length bytes, or have reached EOF
|
// Read until we have read pLength bytes, or have reached EOF
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int off = offset;
|
int off = pOffset;
|
||||||
|
|
||||||
while (length > count) {
|
while (pLength > count) {
|
||||||
if (!buffer.hasRemaining()) {
|
if (!buffer.hasRemaining()) {
|
||||||
if (fill() < 0) {
|
if (fill() < 0) {
|
||||||
break;
|
break;
|
||||||
@@ -126,8 +126,8 @@ public final class DecoderStream extends FilterInputStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy as many bytes as possible
|
// Copy as many bytes as possible
|
||||||
int dstLen = Math.min(length - count, buffer.remaining());
|
int dstLen = Math.min(pLength - count, buffer.remaining());
|
||||||
buffer.get(bytes, off, dstLen);
|
buffer.get(pBytes, off, dstLen);
|
||||||
|
|
||||||
// Update offset (rest)
|
// Update offset (rest)
|
||||||
off += dstLen;
|
off += dstLen;
|
||||||
@@ -139,7 +139,7 @@ public final class DecoderStream extends FilterInputStream {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long skip(final long length) throws IOException {
|
public long skip(final long pLength) throws IOException {
|
||||||
// End of file?
|
// End of file?
|
||||||
if (!buffer.hasRemaining()) {
|
if (!buffer.hasRemaining()) {
|
||||||
if (fill() < 0) {
|
if (fill() < 0) {
|
||||||
@@ -147,10 +147,10 @@ public final class DecoderStream extends FilterInputStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip until we have skipped length bytes, or have reached EOF
|
// Skip until we have skipped pLength bytes, or have reached EOF
|
||||||
long total = 0;
|
long total = 0;
|
||||||
|
|
||||||
while (total < length) {
|
while (total < pLength) {
|
||||||
if (!buffer.hasRemaining()) {
|
if (!buffer.hasRemaining()) {
|
||||||
if (fill() < 0) {
|
if (fill() < 0) {
|
||||||
break;
|
break;
|
||||||
@@ -158,7 +158,7 @@ public final class DecoderStream extends FilterInputStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: Skipped can never be more than avail, which is an int, so the cast is safe
|
// NOTE: Skipped can never be more than avail, which is an int, so the cast is safe
|
||||||
int skipped = (int) Math.min(length - total, buffer.remaining());
|
int skipped = (int) Math.min(pLength - total, buffer.remaining());
|
||||||
buffer.position(buffer.position() + skipped);
|
buffer.position(buffer.position() + skipped);
|
||||||
total += skipped;
|
total += skipped;
|
||||||
}
|
}
|
||||||
@@ -174,7 +174,7 @@ public final class DecoderStream extends FilterInputStream {
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs
|
* @throws IOException if an I/O error occurs
|
||||||
*/
|
*/
|
||||||
private int fill() throws IOException {
|
protected int fill() throws IOException {
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
int read = decoder.decode(in, buffer);
|
int read = decoder.decode(in, buffer);
|
||||||
|
|
||||||
|
|||||||
@@ -45,39 +45,41 @@ import java.nio.ByteBuffer;
|
|||||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/EncoderStream.java#2 $
|
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/EncoderStream.java#2 $
|
||||||
*/
|
*/
|
||||||
public final class EncoderStream extends FilterOutputStream {
|
public final class EncoderStream extends FilterOutputStream {
|
||||||
|
// TODO: This class need a test case ASAP!!!
|
||||||
|
|
||||||
private final Encoder encoder;
|
protected final Encoder encoder;
|
||||||
private final boolean flushOnWrite;
|
private final boolean flushOnWrite;
|
||||||
|
|
||||||
private final ByteBuffer buffer;
|
protected final ByteBuffer buffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an output stream filter built on top of the specified
|
* Creates an output stream filter built on top of the specified
|
||||||
* underlying output stream.
|
* underlying output stream.
|
||||||
*
|
*
|
||||||
* @param stream the underlying output stream
|
* @param pStream the underlying output stream
|
||||||
* @param encoder the encoder to use
|
* @param pEncoder the encoder to use
|
||||||
*/
|
*/
|
||||||
public EncoderStream(final OutputStream stream, final Encoder encoder) {
|
public EncoderStream(final OutputStream pStream, final Encoder pEncoder) {
|
||||||
this(stream, encoder, false);
|
this(pStream, pEncoder, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an output stream filter built on top of the specified
|
* Creates an output stream filter built on top of the specified
|
||||||
* underlying output stream.
|
* underlying output stream.
|
||||||
*
|
*
|
||||||
* @param stream the underlying output stream
|
* @param pStream the underlying output stream
|
||||||
* @param encoder the encoder to use
|
* @param pEncoder the encoder to use
|
||||||
* @param flushOnWrite if {@code true}, calls to the byte-array
|
* @param pFlushOnWrite if {@code true}, calls to the byte-array
|
||||||
* {@code write} methods will automatically flush the buffer.
|
* {@code write} methods will automatically flush the buffer.
|
||||||
*/
|
*/
|
||||||
public EncoderStream(final OutputStream stream, final Encoder encoder, final boolean flushOnWrite) {
|
public EncoderStream(final OutputStream pStream, final Encoder pEncoder, final boolean pFlushOnWrite) {
|
||||||
super(stream);
|
super(pStream);
|
||||||
|
|
||||||
this.encoder = encoder;
|
encoder = pEncoder;
|
||||||
this.flushOnWrite = flushOnWrite;
|
flushOnWrite = pFlushOnWrite;
|
||||||
|
|
||||||
buffer = ByteBuffer.allocate(1024);
|
buffer = ByteBuffer.allocate(1024);
|
||||||
|
buffer.flip();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
@@ -102,33 +104,33 @@ public final class EncoderStream extends FilterOutputStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(final byte[] bytes) throws IOException {
|
public final void write(final byte[] pBytes) throws IOException {
|
||||||
write(bytes, 0, bytes.length);
|
write(pBytes, 0, pBytes.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Verify that this works for the general case (it probably won't)...
|
// TODO: Verify that this works for the general case (it probably won't)...
|
||||||
// TODO: We might need a way to explicitly flush the encoder, or specify
|
// TODO: We might need a way to explicitly flush the encoder, or specify
|
||||||
// that the encoder can't buffer. In that case, the encoder should probably
|
// that the encoder can't buffer. In that case, the encoder should probably
|
||||||
// tell the EncoderStream how large buffer it prefers...
|
// tell the EncoderStream how large buffer it prefers...
|
||||||
public void write(final byte[] values, final int offset, final int length) throws IOException {
|
public void write(final byte[] pBytes, final int pOffset, final int pLength) throws IOException {
|
||||||
if (!flushOnWrite && length < buffer.remaining()) {
|
if (!flushOnWrite && pLength < buffer.remaining()) {
|
||||||
// Buffer data
|
// Buffer data
|
||||||
buffer.put(values, offset, length);
|
buffer.put(pBytes, pOffset, pLength);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Encode data already in the buffer
|
// Encode data already in the buffer
|
||||||
encodeBuffer();
|
encodeBuffer();
|
||||||
|
|
||||||
// Encode rest without buffering
|
// Encode rest without buffering
|
||||||
encoder.encode(out, ByteBuffer.wrap(values, offset, length));
|
encoder.encode(out, ByteBuffer.wrap(pBytes, pOffset, pLength));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(final int value) throws IOException {
|
public void write(final int pByte) throws IOException {
|
||||||
if (!buffer.hasRemaining()) {
|
if (!buffer.hasRemaining()) {
|
||||||
encodeBuffer(); // Resets bufferPos to 0
|
encodeBuffer(); // Resets bufferPos to 0
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.put((byte) value);
|
buffer.put((byte) pByte);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,9 +29,6 @@
|
|||||||
|
|
||||||
package com.twelvemonkeys.xml;
|
package com.twelvemonkeys.xml;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.Writer;
|
|
||||||
|
|
||||||
import org.w3c.dom.DOMConfiguration;
|
import org.w3c.dom.DOMConfiguration;
|
||||||
import org.w3c.dom.DOMImplementationList;
|
import org.w3c.dom.DOMImplementationList;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
@@ -41,6 +38,9 @@ import org.w3c.dom.ls.DOMImplementationLS;
|
|||||||
import org.w3c.dom.ls.LSOutput;
|
import org.w3c.dom.ls.LSOutput;
|
||||||
import org.w3c.dom.ls.LSSerializer;
|
import org.w3c.dom.ls.LSSerializer;
|
||||||
|
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.Writer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@code DOMImplementationLS} backed implementation.
|
* {@code DOMImplementationLS} backed implementation.
|
||||||
*
|
*
|
||||||
@@ -88,6 +88,17 @@ public final class DOMSerializer {
|
|||||||
output.setCharacterStream(pStream);
|
output.setCharacterStream(pStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// TODO: Is it useful?
|
||||||
|
public void setNewLine(final String pNewLine) {
|
||||||
|
serializer.setNewLine(pNewLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNewLine() {
|
||||||
|
return serializer.getNewLine();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies wether the serializer should use indentation and optimize for
|
* Specifies wether the serializer should use indentation and optimize for
|
||||||
* readability.
|
* readability.
|
||||||
@@ -158,7 +169,13 @@ public final class DOMSerializer {
|
|||||||
try {
|
try {
|
||||||
return DOMImplementationRegistry.newInstance();
|
return DOMImplementationRegistry.newInstance();
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
|
catch (ClassNotFoundException e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
|
catch (InstantiationException e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
|
catch (IllegalAccessException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,23 +30,16 @@
|
|||||||
|
|
||||||
package com.twelvemonkeys.xml;
|
package com.twelvemonkeys.xml;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import com.twelvemonkeys.lang.StringUtil;
|
||||||
import java.io.ByteArrayOutputStream;
|
import org.w3c.dom.*;
|
||||||
import java.io.IOException;
|
import org.xml.sax.SAXException;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import java.io.*;
|
||||||
import org.w3c.dom.*;
|
import java.nio.charset.Charset;
|
||||||
import org.xml.sax.SAXException;
|
import java.util.Date;
|
||||||
|
|
||||||
import com.twelvemonkeys.lang.StringUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XMLSerializer
|
* XMLSerializer
|
||||||
@@ -297,7 +290,7 @@ public class XMLSerializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static int appendAndEscape(final String pString, int pStart, final int pEnd, final StringBuilder pBuilder, final String pEntity) {
|
private static int appendAndEscape(final String pString, int pStart, final int pEnd, final StringBuilder pBuilder, final String pEntity) {
|
||||||
pBuilder.append(pString, pStart, pEnd);
|
pBuilder.append(pString.substring(pStart, pEnd));
|
||||||
pBuilder.append(pEntity);
|
pBuilder.append(pEntity);
|
||||||
return pEnd + 1;
|
return pEnd + 1;
|
||||||
}
|
}
|
||||||
@@ -534,7 +527,8 @@ public class XMLSerializer {
|
|||||||
builder = factory.newDocumentBuilder();
|
builder = factory.newDocumentBuilder();
|
||||||
}
|
}
|
||||||
catch (ParserConfigurationException e) {
|
catch (ParserConfigurationException e) {
|
||||||
throw new IOException(e);
|
//noinspection ThrowableInstanceNeverThrown BOGUS
|
||||||
|
throw (IOException) new IOException(e.getMessage()).initCause(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
DOMImplementation dom = builder.getDOMImplementation();
|
DOMImplementation dom = builder.getDOMImplementation();
|
||||||
|
|||||||
@@ -1,130 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022, Harald Kuhr
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * 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.
|
|
||||||
*
|
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.twelvemonkeys.io.enc;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
public class DecoderStreamTest {
|
|
||||||
|
|
||||||
private final Random rng = new Random(5467809876546L);
|
|
||||||
|
|
||||||
private byte[] createData(final int length) {
|
|
||||||
byte[] data = new byte[length];
|
|
||||||
rng.nextBytes(data);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDecodeSingleBytes() throws IOException {
|
|
||||||
byte[] data = createData(1327);
|
|
||||||
|
|
||||||
InputStream source = new ByteArrayInputStream(data);
|
|
||||||
try (InputStream stream = new DecoderStream(source, new NullDecoder())) {
|
|
||||||
for (byte datum : data) {
|
|
||||||
int read = stream.read();
|
|
||||||
assertNotEquals(-1, read);
|
|
||||||
assertEquals(datum, (byte) read);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(-1, stream.read());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDecodeArray() throws IOException {
|
|
||||||
int length = 793;
|
|
||||||
byte[] data = createData(length * 10);
|
|
||||||
|
|
||||||
InputStream source = new ByteArrayInputStream(data);
|
|
||||||
byte[] result = new byte[477];
|
|
||||||
|
|
||||||
try (InputStream stream = new DecoderStream(source, new NullDecoder())) {
|
|
||||||
int dataOffset = 0;
|
|
||||||
while (dataOffset < data.length) {
|
|
||||||
int count = stream.read(result);
|
|
||||||
|
|
||||||
assertFalse(count <= 0);
|
|
||||||
assertArrayEquals(Arrays.copyOfRange(data, dataOffset, dataOffset + count), Arrays.copyOfRange(result, 0, count));
|
|
||||||
|
|
||||||
dataOffset += count;
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(-1, stream.read());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDecodeArrayOffset() throws IOException {
|
|
||||||
int length = 793;
|
|
||||||
byte[] data = createData(length * 10);
|
|
||||||
|
|
||||||
InputStream source = new ByteArrayInputStream(data);
|
|
||||||
byte[] result = new byte[477];
|
|
||||||
|
|
||||||
try (InputStream stream = new DecoderStream(source, new NullDecoder())) {
|
|
||||||
int dataOffset = 0;
|
|
||||||
while (dataOffset < data.length) {
|
|
||||||
int resultOffset = dataOffset % result.length;
|
|
||||||
int count = stream.read(result, resultOffset, result.length - resultOffset);
|
|
||||||
|
|
||||||
assertFalse(count <= 0);
|
|
||||||
assertArrayEquals(Arrays.copyOfRange(data, dataOffset + resultOffset, dataOffset + count), Arrays.copyOfRange(result, resultOffset, count));
|
|
||||||
|
|
||||||
dataOffset += count;
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(-1, stream.read());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class NullDecoder implements Decoder {
|
|
||||||
@Override
|
|
||||||
public int decode(InputStream stream, ByteBuffer buffer) throws IOException {
|
|
||||||
int read = stream.read(buffer.array(), buffer.arrayOffset(), buffer.remaining());
|
|
||||||
|
|
||||||
if (read > 0) {
|
|
||||||
// Set position, should be equivalent to using buffer.put(stream.read()) until EOF or buffer full
|
|
||||||
buffer.position(read);
|
|
||||||
}
|
|
||||||
|
|
||||||
return read;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -32,13 +32,13 @@ package com.twelvemonkeys.io.enc;
|
|||||||
|
|
||||||
import com.twelvemonkeys.io.FileUtil;
|
import com.twelvemonkeys.io.FileUtil;
|
||||||
import com.twelvemonkeys.lang.ObjectAbstractTest;
|
import com.twelvemonkeys.lang.ObjectAbstractTest;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,7 +73,7 @@ public abstract class EncoderAbstractTest extends ObjectAbstractTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] createData(final int pLength) {
|
private byte[] createData(final int pLength) throws Exception {
|
||||||
byte[] bytes = new byte[pLength];
|
byte[] bytes = new byte[pLength];
|
||||||
RANDOM.nextBytes(bytes);
|
RANDOM.nextBytes(bytes);
|
||||||
return bytes;
|
return bytes;
|
||||||
@@ -82,8 +82,9 @@ public abstract class EncoderAbstractTest extends ObjectAbstractTest {
|
|||||||
private void runStreamTest(final int pLength) throws Exception {
|
private void runStreamTest(final int pLength) throws Exception {
|
||||||
byte[] data = createData(pLength);
|
byte[] data = createData(pLength);
|
||||||
ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
|
ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
|
||||||
|
OutputStream out = new EncoderStream(outBytes, createEncoder(), true);
|
||||||
|
|
||||||
try (OutputStream out = new EncoderStream(outBytes, createEncoder(), true)) {
|
try {
|
||||||
// Provoke failure for encoders that doesn't take array offset properly into account
|
// Provoke failure for encoders that doesn't take array offset properly into account
|
||||||
int off = (data.length + 1) / 2;
|
int off = (data.length + 1) / 2;
|
||||||
out.write(data, 0, off);
|
out.write(data, 0, off);
|
||||||
@@ -91,6 +92,9 @@ public abstract class EncoderAbstractTest extends ObjectAbstractTest {
|
|||||||
out.write(data, off, data.length - off);
|
out.write(data, off, data.length - off);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
|
||||||
byte[] encoded = outBytes.toByteArray();
|
byte[] encoded = outBytes.toByteArray();
|
||||||
|
|
||||||
@@ -98,7 +102,7 @@ public abstract class EncoderAbstractTest extends ObjectAbstractTest {
|
|||||||
// System.err.println("encoded: " + Arrays.toString(encoded));
|
// System.err.println("encoded: " + Arrays.toString(encoded));
|
||||||
|
|
||||||
byte[] decoded = FileUtil.read(new DecoderStream(new ByteArrayInputStream(encoded), createCompatibleDecoder()));
|
byte[] decoded = FileUtil.read(new DecoderStream(new ByteArrayInputStream(encoded), createCompatibleDecoder()));
|
||||||
assertArrayEquals(data, decoded);
|
assertTrue(Arrays.equals(data, decoded));
|
||||||
|
|
||||||
InputStream in = new DecoderStream(new ByteArrayInputStream(encoded), createCompatibleDecoder());
|
InputStream in = new DecoderStream(new ByteArrayInputStream(encoded), createCompatibleDecoder());
|
||||||
outBytes = new ByteArrayOutputStream();
|
outBytes = new ByteArrayOutputStream();
|
||||||
@@ -112,7 +116,7 @@ public abstract class EncoderAbstractTest extends ObjectAbstractTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
decoded = outBytes.toByteArray();
|
decoded = outBytes.toByteArray();
|
||||||
assertArrayEquals(data, decoded);
|
assertTrue(Arrays.equals(data, decoded));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -125,6 +129,10 @@ public abstract class EncoderAbstractTest extends ObjectAbstractTest {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
fail(e.getMessage() + ": " + i);
|
fail(e.getMessage() + ": " + i);
|
||||||
}
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
fail(e.getMessage() + ": " + i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 100; i < 2000; i += 250) {
|
for (int i = 100; i < 2000; i += 250) {
|
||||||
@@ -135,6 +143,10 @@ public abstract class EncoderAbstractTest extends ObjectAbstractTest {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
fail(e.getMessage() + ": " + i);
|
fail(e.getMessage() + ": " + i);
|
||||||
}
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
fail(e.getMessage() + ": " + i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 2000; i < 80000; i += 1000) {
|
for (int i = 2000; i < 80000; i += 1000) {
|
||||||
@@ -145,8 +157,14 @@ public abstract class EncoderAbstractTest extends ObjectAbstractTest {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
fail(e.getMessage() + ": " + i);
|
fail(e.getMessage() + ": " + i);
|
||||||
}
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
fail(e.getMessage() + ": " + i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Test that the transition from byte[] to ByteBuffer didn't introduce bugs when writing to a wrapped array with offset.
|
// TODO: Test that the transition from byte[] to ByteBuffer didn't introduce bugs when writing to a wrapped array with offset.
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,111 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022, Harald Kuhr
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * 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.
|
|
||||||
*
|
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.twelvemonkeys.io.enc;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
|
||||||
|
|
||||||
public class EncoderStreamTest {
|
|
||||||
|
|
||||||
private final Random rng = new Random(5467809876546L);
|
|
||||||
|
|
||||||
private byte[] createData(final int length) {
|
|
||||||
byte[] data = new byte[length];
|
|
||||||
rng.nextBytes(data);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEncodeSingleBytes() throws IOException {
|
|
||||||
byte[] data = createData(1327);
|
|
||||||
|
|
||||||
ByteArrayOutputStream result = new ByteArrayOutputStream();
|
|
||||||
try (OutputStream stream = new EncoderStream(result, new NullEncoder())) {
|
|
||||||
for (byte datum : data) {
|
|
||||||
stream.write(datum);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assertArrayEquals(data, result.toByteArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEncodeArray() throws IOException {
|
|
||||||
byte[] data = createData(1793);
|
|
||||||
|
|
||||||
ByteArrayOutputStream result = new ByteArrayOutputStream();
|
|
||||||
try (OutputStream stream = new EncoderStream(result, new NullEncoder())) {
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
stream.write(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] encoded = result.toByteArray();
|
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
assertArrayEquals(data, Arrays.copyOfRange(encoded, i * data.length, (i + 1) * data.length));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEncodeArrayOffset() throws IOException {
|
|
||||||
byte[] data = createData(87);
|
|
||||||
|
|
||||||
ByteArrayOutputStream result = new ByteArrayOutputStream();
|
|
||||||
try (OutputStream stream = new EncoderStream(result, new NullEncoder())) {
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
stream.write(data, 13, 59);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] original = Arrays.copyOfRange(data, 13, 13 + 59);
|
|
||||||
byte[] encoded = result.toByteArray();
|
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
assertArrayEquals(original, Arrays.copyOfRange(encoded, i * original.length, (i + 1) * original.length));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class NullEncoder implements Encoder {
|
|
||||||
@Override
|
|
||||||
public void encode(OutputStream stream, ByteBuffer buffer) throws IOException {
|
|
||||||
stream.write(buffer.array(), buffer.arrayOffset(), buffer.remaining());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+4
-4
@@ -33,12 +33,12 @@ package com.twelvemonkeys.io.ole2;
|
|||||||
import com.twelvemonkeys.io.InputStreamAbstractTest;
|
import com.twelvemonkeys.io.InputStreamAbstractTest;
|
||||||
import com.twelvemonkeys.io.LittleEndianDataOutputStream;
|
import com.twelvemonkeys.io.LittleEndianDataOutputStream;
|
||||||
import com.twelvemonkeys.io.MemoryCacheSeekableStream;
|
import com.twelvemonkeys.io.MemoryCacheSeekableStream;
|
||||||
|
import com.twelvemonkeys.io.SeekableInputStream;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.*;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.net.URISyntaxException;
|
||||||
import java.io.IOException;
|
import java.net.URL;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.twelvemonkeys.common</groupId>
|
<groupId>com.twelvemonkeys.common</groupId>
|
||||||
<artifactId>common</artifactId>
|
<artifactId>common</artifactId>
|
||||||
<version>3.8.4-SNAPSHOT</version>
|
<version>3.4.4-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>common-lang</artifactId>
|
<artifactId>common-lang</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
@@ -13,8 +13,4 @@
|
|||||||
The TwelveMonkeys Common Language support
|
The TwelveMonkeys Common Language support
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<project.jpms.module.name>com.twelvemonkeys.common.lang</project.jpms.module.name>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public final class BeanUtil {
|
|||||||
|
|
||||||
while (begIdx < pProperty.length() && begIdx >= 0) {
|
while (begIdx < pProperty.length() && begIdx >= 0) {
|
||||||
|
|
||||||
endIdx = pProperty.indexOf('.', endIdx + 1);
|
endIdx = pProperty.indexOf(".", endIdx + 1);
|
||||||
if (endIdx > 0) {
|
if (endIdx > 0) {
|
||||||
subProp = pProperty.substring(begIdx, endIdx);
|
subProp = pProperty.substring(begIdx, endIdx);
|
||||||
begIdx = endIdx + 1;
|
begIdx = endIdx + 1;
|
||||||
@@ -106,7 +106,7 @@ public final class BeanUtil {
|
|||||||
Class[] paramClass = new Class[0];
|
Class[] paramClass = new Class[0];
|
||||||
|
|
||||||
int begBracket;
|
int begBracket;
|
||||||
if ((begBracket = subProp.indexOf('[')) > 0) {
|
if ((begBracket = subProp.indexOf("[")) > 0) {
|
||||||
// An error if there is no matching bracket
|
// An error if there is no matching bracket
|
||||||
if (!subProp.endsWith("]")) {
|
if (!subProp.endsWith("]")) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -770,7 +770,6 @@ public final class StringUtil {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*public*/
|
/*public*/
|
||||||
@Deprecated
|
|
||||||
static String formatNumber(long pNum, int pLen) throws IllegalArgumentException {
|
static String formatNumber(long pNum, int pLen) throws IllegalArgumentException {
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
|
|
||||||
@@ -1465,7 +1464,6 @@ public final class StringUtil {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*public*/
|
/*public*/
|
||||||
@Deprecated
|
|
||||||
static String removeSubstring(final String pSource, final char pBeginBoundaryChar, final char pEndBoundaryChar, final int pOffset) {
|
static String removeSubstring(final String pSource, final char pBeginBoundaryChar, final char pEndBoundaryChar, final int pOffset) {
|
||||||
StringBuilder filteredString = new StringBuilder();
|
StringBuilder filteredString = new StringBuilder();
|
||||||
boolean insideDemarcatedArea = false;
|
boolean insideDemarcatedArea = false;
|
||||||
|
|||||||
@@ -330,7 +330,7 @@ abstract class AbstractDecoratedMap<K, V> extends AbstractMap<K, V> implements M
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple Map.Entry implementation.
|
* A simple Map.Entry implementaton.
|
||||||
*/
|
*/
|
||||||
static class BasicEntry<K, V> implements Entry<K, V>, Serializable {
|
static class BasicEntry<K, V> implements Entry<K, V>, Serializable {
|
||||||
K mKey;
|
K mKey;
|
||||||
|
|||||||
@@ -129,7 +129,8 @@ public class Time {
|
|||||||
* @see #toString(String)
|
* @see #toString(String)
|
||||||
*/
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getMinutes() + ":" + (getSeconds() < 10 ? "0" : "") + getSeconds();
|
return "" + getMinutes() + ":"
|
||||||
|
+ (getSeconds() < 10 ? "0" : "") + getSeconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -157,7 +158,6 @@ public class Time {
|
|||||||
* @see #parseTime(String)
|
* @see #parseTime(String)
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public String toString(String pFormatStr) {
|
public String toString(String pFormatStr) {
|
||||||
TimeFormat tf = new TimeFormat(pFormatStr);
|
TimeFormat tf = new TimeFormat(pFormatStr);
|
||||||
|
|
||||||
@@ -175,7 +175,6 @@ public class Time {
|
|||||||
* @see #toString(String)
|
* @see #toString(String)
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public static Time parseTime(String pStr) {
|
public static Time parseTime(String pStr) {
|
||||||
TimeFormat tf = TimeFormat.getInstance();
|
TimeFormat tf = TimeFormat.getInstance();
|
||||||
|
|
||||||
|
|||||||
@@ -44,12 +44,12 @@ import java.util.Vector;
|
|||||||
* The format is expressed in a string as follows:
|
* The format is expressed in a string as follows:
|
||||||
* <DL>
|
* <DL>
|
||||||
* <DD>m (or any multiple of m's)
|
* <DD>m (or any multiple of m's)
|
||||||
* <DT>the minutes part (padded with 0's, if number has less digits than
|
* <DT>the minutes part (padded with 0's, if number has less digits than
|
||||||
* the number of m's)
|
* the number of m's)
|
||||||
* m -> 0,1,...,59,60,61,...
|
* m -> 0,1,...,59,60,61,...
|
||||||
* mm -> 00,01,...,59,60,61,...
|
* mm -> 00,01,...,59,60,61,...
|
||||||
* <DD>s or ss
|
* <DD>s or ss
|
||||||
* <DT>the seconds part (padded with 0's, if number has less digits than
|
* <DT>the seconds part (padded with 0's, if number has less digits than
|
||||||
* the number of s's)
|
* the number of s's)
|
||||||
* s -> 0,1,...,59
|
* s -> 0,1,...,59
|
||||||
* ss -> 00,01,...,59
|
* ss -> 00,01,...,59
|
||||||
@@ -62,7 +62,7 @@ import java.util.Vector;
|
|||||||
* <P>
|
* <P>
|
||||||
* Known bugs:
|
* Known bugs:
|
||||||
* <P>
|
* <P>
|
||||||
* The last character in the formatString is not escaped, while it should be.
|
* The last character in the formatString is not escaped, while it should be.
|
||||||
* The first character after an escaped character is escaped while is shouldn't
|
* The first character after an escaped character is escaped while is shouldn't
|
||||||
* be.
|
* be.
|
||||||
* <P>
|
* <P>
|
||||||
@@ -81,15 +81,15 @@ public class TimeFormat extends Format {
|
|||||||
final static String SECOND = "s";
|
final static String SECOND = "s";
|
||||||
final static String TIME = "S";
|
final static String TIME = "S";
|
||||||
final static String ESCAPE = "\\";
|
final static String ESCAPE = "\\";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default time format
|
* The default time format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private final static TimeFormat DEFAULT_FORMAT = new TimeFormat("m:ss");
|
private final static TimeFormat DEFAULT_FORMAT = new TimeFormat("m:ss");
|
||||||
protected String formatString = null;
|
protected String formatString = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main method for testing ONLY
|
* Main method for testing ONLY
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ public class TimeFormat extends Format {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
time = new Time();
|
time = new Time();
|
||||||
|
|
||||||
System.out.println("Time is \"" + out.format(time) +
|
System.out.println("Time is \"" + out.format(time) +
|
||||||
"\" according to format \"" + out.formatString + "\"");
|
"\" according to format \"" + out.formatString + "\"");
|
||||||
}
|
}
|
||||||
@@ -147,18 +147,18 @@ public class TimeFormat extends Format {
|
|||||||
String previous = null;
|
String previous = null;
|
||||||
String current = null;
|
String current = null;
|
||||||
int previousCount = 0;
|
int previousCount = 0;
|
||||||
|
|
||||||
while (tok.hasMoreElements()) {
|
while (tok.hasMoreElements()) {
|
||||||
current = tok.nextToken();
|
current = tok.nextToken();
|
||||||
|
|
||||||
if (previous != null && previous.equals(ESCAPE)) {
|
if (previous != null && previous.equals(ESCAPE)) {
|
||||||
// Handle escaping of s, S or m
|
// Handle escaping of s, S or m
|
||||||
current = ((current != null) ? current : "")
|
current = ((current != null) ? current : "")
|
||||||
+ (tok.hasMoreElements() ? tok.nextToken() : "");
|
+ (tok.hasMoreElements() ? tok.nextToken() : "");
|
||||||
previous = null;
|
previous = null;
|
||||||
previousCount = 0;
|
previousCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip over first,
|
// Skip over first,
|
||||||
// or if current is the same, increase count, and try again
|
// or if current is the same, increase count, and try again
|
||||||
if (previous == null || previous.equals(current)) {
|
if (previous == null || previous.equals(current)) {
|
||||||
@@ -173,12 +173,12 @@ public class TimeFormat extends Format {
|
|||||||
formatter.add(new SecondsFormatter(previousCount));
|
formatter.add(new SecondsFormatter(previousCount));
|
||||||
else if (previous.equals(TIME))
|
else if (previous.equals(TIME))
|
||||||
formatter.add(new SecondsFormatter(-1));
|
formatter.add(new SecondsFormatter(-1));
|
||||||
else
|
else
|
||||||
formatter.add(new TextFormatter(previous));
|
formatter.add(new TextFormatter(previous));
|
||||||
|
|
||||||
previousCount = 1;
|
previousCount = 1;
|
||||||
previous = current;
|
previous = current;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +197,7 @@ public class TimeFormat extends Format {
|
|||||||
// Debug
|
// Debug
|
||||||
/*
|
/*
|
||||||
for (int i = 0; i < formatter.size(); i++) {
|
for (int i = 0; i < formatter.size(); i++) {
|
||||||
System.out.println("Formatter " + formatter.get(i).getClass()
|
System.out.println("Formatter " + formatter.get(i).getClass()
|
||||||
+ ": length=" + ((TimeFormatter) formatter.get(i)).digits);
|
+ ": length=" + ((TimeFormatter) formatter.get(i)).digits);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
@@ -206,7 +206,7 @@ public class TimeFormat extends Format {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DUMMY IMPLEMENTATION!!
|
* DUMMY IMPLEMENTATION!!
|
||||||
* Not locale specific.
|
* Not locale specific.
|
||||||
*/
|
*/
|
||||||
@@ -259,9 +259,9 @@ public class TimeFormat extends Format {
|
|||||||
/** DUMMY IMPLEMENTATION!! */
|
/** DUMMY IMPLEMENTATION!! */
|
||||||
public Object parseObject(String pStr, ParsePosition pStatus) {
|
public Object parseObject(String pStr, ParsePosition pStatus) {
|
||||||
Time t = parse(pStr);
|
Time t = parse(pStr);
|
||||||
|
|
||||||
pStatus.setIndex(pStr.length()); // Not 100%
|
pStatus.setIndex(pStr.length()); // Not 100%
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,7 +270,7 @@ public class TimeFormat extends Format {
|
|||||||
* <p>
|
* <p>
|
||||||
* Will bug on some formats. It's safest to always use delimiters between
|
* Will bug on some formats. It's safest to always use delimiters between
|
||||||
* the minutes (m) and seconds (s) part.
|
* the minutes (m) and seconds (s) part.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public Time parse(String pStr) {
|
public Time parse(String pStr) {
|
||||||
Time time = new Time();
|
Time time = new Time();
|
||||||
@@ -286,7 +286,7 @@ public class TimeFormat extends Format {
|
|||||||
&& (pos + skip < pStr.length()) ; i++) {
|
&& (pos + skip < pStr.length()) ; i++) {
|
||||||
// Go to next offset
|
// Go to next offset
|
||||||
pos += skip;
|
pos += skip;
|
||||||
|
|
||||||
if (formatter[i] instanceof MinutesFormatter) {
|
if (formatter[i] instanceof MinutesFormatter) {
|
||||||
// Parse MINUTES
|
// Parse MINUTES
|
||||||
if ((i + 1) < formatter.length
|
if ((i + 1) < formatter.length
|
||||||
@@ -327,9 +327,9 @@ public class TimeFormat extends Format {
|
|||||||
else {
|
else {
|
||||||
// Cannot possibly know how long?
|
// Cannot possibly know how long?
|
||||||
skip = 0;
|
skip = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get seconds
|
// Get seconds
|
||||||
sec = Integer.parseInt(pStr.substring(pos, skip));
|
sec = Integer.parseInt(pStr.substring(pos, skip));
|
||||||
// System.out.println("Only seconds: " + sec);
|
// System.out.println("Only seconds: " + sec);
|
||||||
@@ -343,7 +343,7 @@ public class TimeFormat extends Format {
|
|||||||
&& formatter[i + 1] instanceof TextFormatter) {
|
&& formatter[i + 1] instanceof TextFormatter) {
|
||||||
// Skip until next format element
|
// Skip until next format element
|
||||||
skip = pStr.indexOf(((TextFormatter) formatter[i + 1]).text, pos);
|
skip = pStr.indexOf(((TextFormatter) formatter[i + 1]).text, pos);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ((i + 1) >= formatter.length) {
|
else if ((i + 1) >= formatter.length) {
|
||||||
// Skip until end of string
|
// Skip until end of string
|
||||||
@@ -359,7 +359,7 @@ public class TimeFormat extends Format {
|
|||||||
else if (formatter[i] instanceof TextFormatter) {
|
else if (formatter[i] instanceof TextFormatter) {
|
||||||
skip = formatter[i].digits;
|
skip = formatter[i].digits;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the minutes part if we should
|
// Set the minutes part if we should
|
||||||
@@ -390,7 +390,7 @@ class SecondsFormatter extends TimeFormatter {
|
|||||||
SecondsFormatter(int pDigits) {
|
SecondsFormatter(int pDigits) {
|
||||||
digits = pDigits;
|
digits = pDigits;
|
||||||
}
|
}
|
||||||
|
|
||||||
String format(Time t) {
|
String format(Time t) {
|
||||||
// Negative number of digits, means all seconds, no padding
|
// Negative number of digits, means all seconds, no padding
|
||||||
if (digits < 0) {
|
if (digits < 0) {
|
||||||
@@ -404,7 +404,7 @@ class SecondsFormatter extends TimeFormatter {
|
|||||||
|
|
||||||
// Else return it with leading 0's
|
// Else return it with leading 0's
|
||||||
//return StringUtil.formatNumber(t.getSeconds(), digits);
|
//return StringUtil.formatNumber(t.getSeconds(), digits);
|
||||||
return StringUtil.pad(String.valueOf(t.getSeconds()), digits, "0", true);
|
return StringUtil.pad("" + t.getSeconds(), digits, "0", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,7 +425,7 @@ class MinutesFormatter extends TimeFormatter {
|
|||||||
|
|
||||||
// Else return it with leading 0's
|
// Else return it with leading 0's
|
||||||
//return StringUtil.formatNumber(t.getMinutes(), digits);
|
//return StringUtil.formatNumber(t.getMinutes(), digits);
|
||||||
return StringUtil.pad(String.valueOf(t.getMinutes()), digits, "0", true);
|
return StringUtil.pad("" + t.getMinutes(), digits, "0", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import java.io.Serializable;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@code Map} implementation that removes (expires) its elements after
|
* A {@code Map} implementation that removes (exipres) its elements after
|
||||||
* a given period. The map is by default backed by a {@link java.util.HashMap},
|
* a given period. The map is by default backed by a {@link java.util.HashMap},
|
||||||
* or can be instantiated with any given {@code Map} as backing.
|
* or can be instantiated with any given {@code Map} as backing.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -67,7 +67,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
|||||||
protected long expiryTime = 60000L; // 1 minute
|
protected long expiryTime = 60000L; // 1 minute
|
||||||
|
|
||||||
//////////////////////
|
//////////////////////
|
||||||
private volatile long nextExpiryTime = Long.MAX_VALUE;
|
private volatile long nextExpiryTime;
|
||||||
//////////////////////
|
//////////////////////
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -178,7 +178,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
|||||||
* @return {@code true} if this map contains no key-value mappings.
|
* @return {@code true} if this map contains no key-value mappings.
|
||||||
*/
|
*/
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return size() <= 0;
|
return (size() <= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -208,7 +208,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
|||||||
* @see #containsKey(java.lang.Object)
|
* @see #containsKey(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
public V get(Object pKey) {
|
public V get(Object pKey) {
|
||||||
TimedEntry entry = (TimedEntry) entries.get(pKey);
|
TimedEntry<K, V> entry = (TimedEntry<K, V>) entries.get(pKey);
|
||||||
|
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -236,7 +236,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
|||||||
* {@code null} values.
|
* {@code null} values.
|
||||||
*/
|
*/
|
||||||
public V put(K pKey, V pValue) {
|
public V put(K pKey, V pValue) {
|
||||||
TimedEntry entry = (TimedEntry) entries.get(pKey);
|
TimedEntry<K, V> entry = (TimedEntry<K, V>) entries.get(pKey);
|
||||||
V oldValue;
|
V oldValue;
|
||||||
|
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
@@ -272,7 +272,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
|||||||
* {@code null} values.
|
* {@code null} values.
|
||||||
*/
|
*/
|
||||||
public V remove(Object pKey) {
|
public V remove(Object pKey) {
|
||||||
TimedEntry entry = (TimedEntry) entries.remove(pKey);
|
TimedEntry<K, V> entry = (TimedEntry<K, V>) entries.remove(pKey);
|
||||||
return (entry != null) ? entry.getValue() : null;
|
return (entry != null) ? entry.getValue() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,12 +284,13 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*protected*/ TimedEntry createEntry(K pKey, V pValue) {
|
/*protected*/ TimedEntry<K, V> createEntry(K pKey, V pValue) {
|
||||||
return new TimedEntry(pKey, pValue);
|
return new TimedEntry<K, V>(pKey, pValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes any expired mappings.
|
* Removes any expired mappings.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
protected void removeExpiredEntries() {
|
protected void removeExpiredEntries() {
|
||||||
// Remove any expired elements
|
// Remove any expired elements
|
||||||
@@ -311,7 +312,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
|||||||
long next = Long.MAX_VALUE;
|
long next = Long.MAX_VALUE;
|
||||||
nextExpiryTime = next; // Avoid multiple runs...
|
nextExpiryTime = next; // Avoid multiple runs...
|
||||||
for (Iterator<Entry<K, V>> iterator = new EntryIterator(); iterator.hasNext();) {
|
for (Iterator<Entry<K, V>> iterator = new EntryIterator(); iterator.hasNext();) {
|
||||||
TimedEntry entry = (TimedEntry) iterator.next();
|
TimedEntry<K, V> entry = (TimedEntry<K, V>) iterator.next();
|
||||||
////
|
////
|
||||||
long expires = entry.expires();
|
long expires = entry.expires();
|
||||||
if (expires < next) {
|
if (expires < next) {
|
||||||
@@ -375,7 +376,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
|||||||
|
|
||||||
while (mNext == null && mIterator.hasNext()) {
|
while (mNext == null && mIterator.hasNext()) {
|
||||||
Entry<K, Entry<K, V>> entry = mIterator.next();
|
Entry<K, Entry<K, V>> entry = mIterator.next();
|
||||||
TimedEntry timed = (TimedEntry) entry.getValue();
|
TimedEntry<K, V> timed = (TimedEntry<K, V>) entry.getValue();
|
||||||
|
|
||||||
if (timed.isExpiredBy(mNow)) {
|
if (timed.isExpiredBy(mNow)) {
|
||||||
// Remove from map, and continue
|
// Remove from map, and continue
|
||||||
@@ -424,26 +425,17 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
|||||||
/**
|
/**
|
||||||
* Keeps track of timed objects
|
* Keeps track of timed objects
|
||||||
*/
|
*/
|
||||||
private class TimedEntry extends BasicEntry<K, V> {
|
private class TimedEntry<K, V> extends BasicEntry<K, V> {
|
||||||
private long mTimestamp;
|
private long mTimestamp;
|
||||||
|
|
||||||
TimedEntry(K pKey, V pValue) {
|
TimedEntry(K pKey, V pValue) {
|
||||||
super(pKey, pValue);
|
super(pKey, pValue);
|
||||||
updateTimestamp();
|
mTimestamp = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
public V setValue(V pValue) {
|
public V setValue(V pValue) {
|
||||||
updateTimestamp();
|
|
||||||
return super.setValue(pValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateTimestamp() {
|
|
||||||
mTimestamp = System.currentTimeMillis();
|
mTimestamp = System.currentTimeMillis();
|
||||||
|
return super.setValue(pValue);
|
||||||
long expires = expires();
|
|
||||||
if (expires < nextExpiryTime) {
|
|
||||||
nextExpiryTime = expires;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean isExpired() {
|
final boolean isExpired() {
|
||||||
|
|||||||
+1
-2
@@ -111,7 +111,6 @@ import java.io.PrintStream;
|
|||||||
* @author <a href="mailto:eirik.torske@iconmedialab.no">Eirik Torske</a>
|
* @author <a href="mailto:eirik.torske@iconmedialab.no">Eirik Torske</a>
|
||||||
* @deprecated Will probably be removed in the near future
|
* @deprecated Will probably be removed in the near future
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public class WildcardStringParser {
|
public class WildcardStringParser {
|
||||||
// TODO: Get rid of this class
|
// TODO: Get rid of this class
|
||||||
|
|
||||||
@@ -623,7 +622,7 @@ public class WildcardStringParser {
|
|||||||
buffer.append("\n");
|
buffer.append("\n");
|
||||||
buffer.append(" Format: <state index>: <character> (<last free state>)");
|
buffer.append(" Format: <state index>: <character> (<last free state>)");
|
||||||
buffer.append("\n");
|
buffer.append("\n");
|
||||||
buffer.append(" Number of strings parsed: ").append(totalNumberOfStringsParsed);
|
buffer.append(" Number of strings parsed: " + totalNumberOfStringsParsed);
|
||||||
buffer.append("\n");
|
buffer.append("\n");
|
||||||
}
|
}
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
package com.twelvemonkeys.lang;
|
package com.twelvemonkeys.lang;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
@@ -41,7 +41,7 @@ import java.util.Date;
|
|||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StringUtilTestCase
|
* StringUtilTestCase
|
||||||
@@ -76,24 +76,24 @@ public class StringUtilTest {
|
|||||||
assertNull(StringUtil.valueOf(null));
|
assertNull(StringUtil.valueOf(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
|
||||||
@Test
|
@Test
|
||||||
public void testToUpperCase() {
|
public void testToUpperCase() {
|
||||||
String str = StringUtil.toUpperCase(TEST_STRING);
|
String str = StringUtil.toUpperCase(TEST_STRING);
|
||||||
assertNotNull(str);
|
assertNotNull(str);
|
||||||
assertEquals(TEST_STRING.toUpperCase(), str);
|
assertEquals(TEST_STRING.toUpperCase(), str);
|
||||||
|
|
||||||
assertNull(StringUtil.toUpperCase(null));
|
str = StringUtil.toUpperCase(null);
|
||||||
|
assertNull(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
|
||||||
@Test
|
@Test
|
||||||
public void testToLowerCase() {
|
public void testToLowerCase() {
|
||||||
String str = StringUtil.toLowerCase(TEST_STRING);
|
String str = StringUtil.toLowerCase(TEST_STRING);
|
||||||
assertNotNull(str);
|
assertNotNull(str);
|
||||||
assertEquals(TEST_STRING.toLowerCase(), str);
|
assertEquals(TEST_STRING.toLowerCase(), str);
|
||||||
|
|
||||||
assertNull(StringUtil.toLowerCase(null));
|
str = StringUtil.toLowerCase(null);
|
||||||
|
assertNull(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -113,7 +113,6 @@ public class StringUtilTest {
|
|||||||
assertFalse(StringUtil.isEmpty(new String[]{WHITESPACE_STRING, TEST_STRING}));
|
assertFalse(StringUtil.isEmpty(new String[]{WHITESPACE_STRING, TEST_STRING}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
|
||||||
@Test
|
@Test
|
||||||
public void testContains() {
|
public void testContains() {
|
||||||
assertTrue(StringUtil.contains(TEST_STRING, TEST_STRING));
|
assertTrue(StringUtil.contains(TEST_STRING, TEST_STRING));
|
||||||
@@ -146,7 +145,6 @@ public class StringUtilTest {
|
|||||||
assertFalse(StringUtil.containsIgnoreCase(null, null));
|
assertFalse(StringUtil.containsIgnoreCase(null, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
|
||||||
@Test
|
@Test
|
||||||
public void testContainsChar() {
|
public void testContainsChar() {
|
||||||
for (int i = 0; i < TEST_STRING.length(); i++) {
|
for (int i = 0; i < TEST_STRING.length(); i++) {
|
||||||
@@ -468,7 +466,7 @@ public class StringUtilTest {
|
|||||||
assertEquals(TEST_STRING, StringUtil.ltrim(TEST_STRING));
|
assertEquals(TEST_STRING, StringUtil.ltrim(TEST_STRING));
|
||||||
assertEquals(TEST_STRING, StringUtil.ltrim(" " + TEST_STRING));
|
assertEquals(TEST_STRING, StringUtil.ltrim(" " + TEST_STRING));
|
||||||
assertEquals(TEST_STRING, StringUtil.ltrim(WHITESPACE_STRING + TEST_STRING));
|
assertEquals(TEST_STRING, StringUtil.ltrim(WHITESPACE_STRING + TEST_STRING));
|
||||||
assertNotEquals(TEST_STRING, StringUtil.ltrim(TEST_STRING + WHITESPACE_STRING));
|
assertFalse(TEST_STRING.equals(StringUtil.ltrim(TEST_STRING + WHITESPACE_STRING)));
|
||||||
// TODO: Test is not complete
|
// TODO: Test is not complete
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,7 +475,7 @@ public class StringUtilTest {
|
|||||||
assertEquals(TEST_STRING, StringUtil.rtrim(TEST_STRING));
|
assertEquals(TEST_STRING, StringUtil.rtrim(TEST_STRING));
|
||||||
assertEquals(TEST_STRING, StringUtil.rtrim(TEST_STRING + " "));
|
assertEquals(TEST_STRING, StringUtil.rtrim(TEST_STRING + " "));
|
||||||
assertEquals(TEST_STRING, StringUtil.rtrim(TEST_STRING + WHITESPACE_STRING));
|
assertEquals(TEST_STRING, StringUtil.rtrim(TEST_STRING + WHITESPACE_STRING));
|
||||||
assertNotEquals(TEST_STRING, StringUtil.rtrim(WHITESPACE_STRING + TEST_STRING));
|
assertFalse(TEST_STRING.equals(StringUtil.rtrim(WHITESPACE_STRING + TEST_STRING)));
|
||||||
// TODO: Test is not complete
|
// TODO: Test is not complete
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -518,7 +516,7 @@ public class StringUtilTest {
|
|||||||
public void testCaptialize() {
|
public void testCaptialize() {
|
||||||
assertNull(StringUtil.capitalize(null));
|
assertNull(StringUtil.capitalize(null));
|
||||||
assertEquals(TEST_STRING.toUpperCase(), StringUtil.capitalize(TEST_STRING.toUpperCase()));
|
assertEquals(TEST_STRING.toUpperCase(), StringUtil.capitalize(TEST_STRING.toUpperCase()));
|
||||||
assertEquals('A', StringUtil.capitalize("abc").charAt(0));
|
assertTrue(StringUtil.capitalize("abc").charAt(0) == 'A');
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -554,13 +552,13 @@ public class StringUtilTest {
|
|||||||
public void testToDateWithFormatString() {
|
public void testToDateWithFormatString() {
|
||||||
Calendar cal = new GregorianCalendar();
|
Calendar cal = new GregorianCalendar();
|
||||||
cal.clear();
|
cal.clear();
|
||||||
cal.set(1976, Calendar.MARCH, 16); // Month is 0-based
|
cal.set(1976, 2, 16); // Month is 0-based
|
||||||
Date date = StringUtil.toDate("16.03.1976", "dd.MM.yyyy");
|
Date date = StringUtil.toDate("16.03.1976", "dd.MM.yyyy");
|
||||||
assertNotNull(date);
|
assertNotNull(date);
|
||||||
assertEquals(cal.getTime(), date);
|
assertEquals(cal.getTime(), date);
|
||||||
|
|
||||||
cal.clear();
|
cal.clear();
|
||||||
cal.set(2004, Calendar.MAY, 13, 23, 51, 3);
|
cal.set(2004, 4, 13, 23, 51, 3);
|
||||||
date = StringUtil.toDate("2004-5-13 23:51 (03)", "yyyy-MM-dd hh:mm (ss)");
|
date = StringUtil.toDate("2004-5-13 23:51 (03)", "yyyy-MM-dd hh:mm (ss)");
|
||||||
assertNotNull(date);
|
assertNotNull(date);
|
||||||
assertEquals(cal.getTime(), date);
|
assertEquals(cal.getTime(), date);
|
||||||
@@ -578,15 +576,15 @@ public class StringUtilTest {
|
|||||||
public void testToDateWithFormat() {
|
public void testToDateWithFormat() {
|
||||||
Calendar cal = new GregorianCalendar();
|
Calendar cal = new GregorianCalendar();
|
||||||
cal.clear();
|
cal.clear();
|
||||||
cal.set(1976, Calendar.MARCH, 16); // Month is 0-based
|
cal.set(1976, 2, 16); // Month is 0-based
|
||||||
Date date = StringUtil.toDate("16.03.1976", new SimpleDateFormat("dd.MM.yyyy"));
|
Date date = StringUtil.toDate("16.03.1976", new SimpleDateFormat("dd.MM.yyyy"));
|
||||||
assertNotNull(date);
|
assertNotNull(date);
|
||||||
assertEquals(cal.getTime(), date);
|
assertEquals(cal.getTime(), date);
|
||||||
|
|
||||||
cal.clear();
|
cal.clear();
|
||||||
cal.set(2004, Calendar.MAY, 13, 23, 51);
|
cal.set(2004, 4, 13, 23, 51);
|
||||||
DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, new Locale("no", "NO"));
|
date = StringUtil.toDate("13.5.04 23:51",
|
||||||
date = StringUtil.toDate(format.format(cal.getTime()), format);
|
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, new Locale("no", "NO")));
|
||||||
assertNotNull(date);
|
assertNotNull(date);
|
||||||
assertEquals(cal.getTime(), date);
|
assertEquals(cal.getTime(), date);
|
||||||
|
|
||||||
@@ -603,9 +601,10 @@ public class StringUtilTest {
|
|||||||
public void testToTimestamp() {
|
public void testToTimestamp() {
|
||||||
Calendar cal = new GregorianCalendar();
|
Calendar cal = new GregorianCalendar();
|
||||||
cal.clear();
|
cal.clear();
|
||||||
cal.set(1976, Calendar.MARCH, 16, 21, 28, 4); // Month is 0-based
|
cal.set(1976, 2, 16, 21, 28, 4); // Month is 0-based
|
||||||
Timestamp date = StringUtil.toTimestamp("1976-03-16 21:28:04");
|
Date date = StringUtil.toTimestamp("1976-03-16 21:28:04");
|
||||||
assertNotNull(date);
|
assertNotNull(date);
|
||||||
|
assertTrue(date instanceof Timestamp);
|
||||||
assertEquals(cal.getTime(), date);
|
assertEquals(cal.getTime(), date);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -822,7 +821,7 @@ public class StringUtilTest {
|
|||||||
assertTrue(StringUtil.isNumber("12345"));
|
assertTrue(StringUtil.isNumber("12345"));
|
||||||
assertTrue(StringUtil.isNumber(TEST_INTEGER.toString()));
|
assertTrue(StringUtil.isNumber(TEST_INTEGER.toString()));
|
||||||
assertTrue(StringUtil.isNumber("1234567890123456789012345678901234567890"));
|
assertTrue(StringUtil.isNumber("1234567890123456789012345678901234567890"));
|
||||||
assertTrue(StringUtil.isNumber(String.valueOf(Long.MAX_VALUE) + Long.MAX_VALUE));
|
assertTrue(StringUtil.isNumber(String.valueOf(Long.MAX_VALUE) + String.valueOf(Long.MAX_VALUE)));
|
||||||
assertFalse(StringUtil.isNumber("abc"));
|
assertFalse(StringUtil.isNumber("abc"));
|
||||||
assertFalse(StringUtil.isNumber(TEST_STRING));
|
assertFalse(StringUtil.isNumber(TEST_STRING));
|
||||||
}
|
}
|
||||||
@@ -832,7 +831,7 @@ public class StringUtilTest {
|
|||||||
assertTrue(StringUtil.isNumber("-12345"));
|
assertTrue(StringUtil.isNumber("-12345"));
|
||||||
assertTrue(StringUtil.isNumber('-' + TEST_INTEGER.toString()));
|
assertTrue(StringUtil.isNumber('-' + TEST_INTEGER.toString()));
|
||||||
assertTrue(StringUtil.isNumber("-1234567890123456789012345678901234567890"));
|
assertTrue(StringUtil.isNumber("-1234567890123456789012345678901234567890"));
|
||||||
assertTrue(StringUtil.isNumber('-' + String.valueOf(Long.MAX_VALUE) + Long.MAX_VALUE));
|
assertTrue(StringUtil.isNumber('-' + String.valueOf(Long.MAX_VALUE) + String.valueOf(Long.MAX_VALUE)));
|
||||||
assertFalse(StringUtil.isNumber("-abc"));
|
assertFalse(StringUtil.isNumber("-abc"));
|
||||||
assertFalse(StringUtil.isNumber('-' + TEST_STRING));
|
assertFalse(StringUtil.isNumber('-' + TEST_STRING));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1117,19 +1117,18 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
|||||||
/**
|
/**
|
||||||
* Tests {@link Collection#toArray(Object[])}.
|
* Tests {@link Collection#toArray(Object[])}.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"SuspiciousToArrayCall", "RedundantCast"})
|
|
||||||
@Test
|
@Test
|
||||||
public void testCollectionToArray2() {
|
public void testCollectionToArray2() {
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
Object[] a = new Object[] { new Object(), null, null };
|
Object[] a = new Object[] { new Object(), null, null };
|
||||||
Object[] array = collection.toArray(a);
|
Object[] array = collection.toArray(a);
|
||||||
assertArrayEquals("Given array shouldn't shrink", array, a);
|
assertEquals("Given array shouldn't shrink", array, a);
|
||||||
assertNull("Last element should be set to null", a[0]);
|
assertEquals("Last element should be set to null", a[0], null);
|
||||||
verifyAll();
|
verifyAll();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
try {
|
||||||
collection.toArray(new Void[0]);
|
array = collection.toArray(new Void[0]);
|
||||||
fail("toArray(new Void[0]) should raise ArrayStore");
|
fail("toArray(new Void[0]) should raise ArrayStore");
|
||||||
} catch (ArrayStoreException e) {
|
} catch (ArrayStoreException e) {
|
||||||
// expected
|
// expected
|
||||||
@@ -1137,7 +1136,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
|||||||
verifyAll();
|
verifyAll();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
collection.toArray((Object[]) null);
|
array = collection.toArray(null);
|
||||||
fail("toArray(null) should raise NPE");
|
fail("toArray(null) should raise NPE");
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
// expected
|
// expected
|
||||||
@@ -1151,13 +1150,13 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
|||||||
|
|
||||||
// Figure out if they're all the same class
|
// Figure out if they're all the same class
|
||||||
// TODO: It'd be nicer to detect a common superclass
|
// TODO: It'd be nicer to detect a common superclass
|
||||||
HashSet<Class<?>> classes = new HashSet<>();
|
HashSet classes = new HashSet();
|
||||||
for (int i = 0; i < array.length; i++) {
|
for (int i = 0; i < array.length; i++) {
|
||||||
classes.add((array[i] == null) ? null : array[i].getClass());
|
classes.add((array[i] == null) ? null : array[i].getClass());
|
||||||
}
|
}
|
||||||
if (classes.size() > 1) return;
|
if (classes.size() > 1) return;
|
||||||
|
|
||||||
Class<?> cl = (Class<?>)classes.iterator().next();
|
Class cl = (Class)classes.iterator().next();
|
||||||
if (Map.Entry.class.isAssignableFrom(cl)) { // check needed for protective cases like Predicated/Unmod map entrySet
|
if (Map.Entry.class.isAssignableFrom(cl)) { // check needed for protective cases like Predicated/Unmod map entrySet
|
||||||
cl = Map.Entry.class;
|
cl = Map.Entry.class;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -250,12 +250,12 @@ public class CollectionUtilTest {
|
|||||||
assertCorrectListIterator(new ArrayList<String>(Arrays.asList(new String[] {"foo", "bar", "baz", "boo"})).subList(1, 3).listIterator(0), new String[] {"bar", "baz"}, true, true);
|
assertCorrectListIterator(new ArrayList<String>(Arrays.asList(new String[] {"foo", "bar", "baz", "boo"})).subList(1, 3).listIterator(0), new String[] {"bar", "baz"}, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertCorrectListIterator(ListIterator<String> iterator, final Object[] elements) {
|
private void assertCorrectListIterator(ListIterator<String> iterator, final Object[] elements) {
|
||||||
assertCorrectListIterator(iterator, elements, false, false);
|
assertCorrectListIterator(iterator, elements, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: The test is can only test list iterators with a starting index == 0
|
// NOTE: The test is can only test list iterators with a starting index == 0
|
||||||
private static void assertCorrectListIterator(ListIterator<String> iterator, final Object[] elements, boolean skipRemove, boolean skipAdd) {
|
private void assertCorrectListIterator(ListIterator<String> iterator, final Object[] elements, boolean skipRemove, boolean skipAdd) {
|
||||||
// Index is now "before 0"
|
// Index is now "before 0"
|
||||||
assertEquals(-1, iterator.previousIndex());
|
assertEquals(-1, iterator.previousIndex());
|
||||||
assertEquals(0, iterator.nextIndex());
|
assertEquals(0, iterator.nextIndex());
|
||||||
|
|||||||
@@ -557,7 +557,7 @@ public class TimeoutMapTest extends MapAbstractTest {
|
|||||||
// NOTE: Only wait fist time, to avoid slooow tests
|
// NOTE: Only wait fist time, to avoid slooow tests
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
try {
|
try {
|
||||||
wait(60L);
|
wait(60l);
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) {
|
catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
@@ -591,7 +591,7 @@ public class TimeoutMapTest extends MapAbstractTest {
|
|||||||
try {
|
try {
|
||||||
wait(60l);
|
wait(60l);
|
||||||
}
|
}
|
||||||
catch (InterruptedException ignore) {
|
catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -651,24 +651,5 @@ public class TimeoutMapTest extends MapAbstractTest {
|
|||||||
assertTrue("Wrong entry removed, keySet().iterator() is broken.", !map.containsKey(removedKey));
|
assertTrue("Wrong entry removed, keySet().iterator() is broken.", !map.containsKey(removedKey));
|
||||||
assertTrue("Wrong entry removed, keySet().iterator() is broken.", map.containsKey(otherKey));
|
assertTrue("Wrong entry removed, keySet().iterator() is broken.", map.containsKey(otherKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testContainsKeyOnEmptyMap() {
|
|
||||||
// See #600
|
|
||||||
Map<String, String> timeoutMap = new TimeoutMap<>(30);
|
|
||||||
assertFalse(timeoutMap.containsKey("xyz"));
|
|
||||||
timeoutMap.put("xyz", "xyz");
|
|
||||||
assertTrue(timeoutMap.containsKey("xyz"));
|
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.sleep(50); // Let the item expire
|
|
||||||
}
|
|
||||||
catch (InterruptedException ignore) {
|
|
||||||
}
|
|
||||||
|
|
||||||
assertFalse(timeoutMap.containsKey("xyz"));
|
|
||||||
assertNull(timeoutMap.get("xyz"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.twelvemonkeys</groupId>
|
<groupId>com.twelvemonkeys</groupId>
|
||||||
<artifactId>twelvemonkeys</artifactId>
|
<artifactId>twelvemonkeys</artifactId>
|
||||||
<version>3.8.4-SNAPSHOT</version>
|
<version>3.4.4-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.twelvemonkeys.common</groupId>
|
<groupId>com.twelvemonkeys.common</groupId>
|
||||||
<artifactId>common</artifactId>
|
<artifactId>common</artifactId>
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.13.1</version>
|
<version>4.7</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
+2
-2
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.twelvemonkeys</groupId>
|
<groupId>com.twelvemonkeys</groupId>
|
||||||
<artifactId>twelvemonkeys</artifactId>
|
<artifactId>twelvemonkeys</artifactId>
|
||||||
<version>3.8.4-SNAPSHOT</version>
|
<version>3.4.4-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.twelvemonkeys.contrib</groupId>
|
<groupId>com.twelvemonkeys.contrib</groupId>
|
||||||
<artifactId>contrib</artifactId>
|
<artifactId>contrib</artifactId>
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.13.1</version>
|
<version>4.7</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -1,178 +0,0 @@
|
|||||||
package com.twelvemonkeys.contrib.exif;
|
|
||||||
|
|
||||||
import com.twelvemonkeys.image.ImageUtil;
|
|
||||||
import com.twelvemonkeys.imageio.ImageReaderBase;
|
|
||||||
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
import javax.imageio.IIOImage;
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import javax.imageio.ImageReader;
|
|
||||||
import javax.imageio.metadata.IIOMetadata;
|
|
||||||
import javax.imageio.metadata.IIOMetadataFormatImpl;
|
|
||||||
import javax.imageio.metadata.IIOMetadataNode;
|
|
||||||
import javax.imageio.stream.ImageInputStream;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import static com.twelvemonkeys.contrib.tiff.TIFFUtilities.applyOrientation;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* EXIFUtilities.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
|
||||||
* @version : EXIFUtilities.java,v 1.0 23/06/2020
|
|
||||||
*/
|
|
||||||
public class EXIFUtilities {
|
|
||||||
/**
|
|
||||||
* Reads image and metadata, applies Exif orientation to image, and returns everything as an {@code IIOImage}.
|
|
||||||
* The returned {@code IIOImage} will always contain an image and no raster, and
|
|
||||||
* the {@code RenderedImage} may be safely cast to a {@code BufferedImage}.
|
|
||||||
*
|
|
||||||
* If no registered {@code ImageReader} claims to be able to read the input, {@code null} is returned.
|
|
||||||
*
|
|
||||||
* @param input a {@code URL}
|
|
||||||
* @return an {@code IIOImage} containing the correctly oriented image and metadata including rotation info, or
|
|
||||||
* {@code null}.
|
|
||||||
* @throws IOException if an error occurs during reading.
|
|
||||||
*/
|
|
||||||
public static IIOImage readWithOrientation(final URL input) throws IOException {
|
|
||||||
try (ImageInputStream stream = ImageIO.createImageInputStream(input)) {
|
|
||||||
return readWithOrientation(stream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads image and metadata, applies Exif orientation to image, and returns everything as an {@code IIOImage}.
|
|
||||||
* The returned {@code IIOImage} will always contain an image and no raster, and
|
|
||||||
* the {@code RenderedImage} may be safely cast to a {@code BufferedImage}.
|
|
||||||
*
|
|
||||||
* If no registered {@code ImageReader} claims to be able to read the input, {@code null} is returned.
|
|
||||||
*
|
|
||||||
* @param input an {@code InputStream}
|
|
||||||
* @return an {@code IIOImage} containing the correctly oriented image and metadata including rotation info, or
|
|
||||||
* {@code null}.
|
|
||||||
* @throws IOException if an error occurs during reading.
|
|
||||||
*/
|
|
||||||
public static IIOImage readWithOrientation(final InputStream input) throws IOException {
|
|
||||||
try (ImageInputStream stream = ImageIO.createImageInputStream(input)) {
|
|
||||||
return readWithOrientation(stream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads image and metadata, applies Exif orientation to image, and returns everything as an {@code IIOImage}.
|
|
||||||
* The returned {@code IIOImage} will always contain an image and no raster, and
|
|
||||||
* the {@code RenderedImage} may be safely cast to a {@code BufferedImage}.
|
|
||||||
*
|
|
||||||
* If no registered {@code ImageReader} claims to be able to read the input, {@code null} is returned.
|
|
||||||
*
|
|
||||||
* @param input a {@code File}
|
|
||||||
* @return an {@code IIOImage} containing the correctly oriented image and metadata including rotation info or
|
|
||||||
* {@code null}.
|
|
||||||
* @throws IOException if an error occurs during reading.
|
|
||||||
*/
|
|
||||||
public static IIOImage readWithOrientation(final File input) throws IOException {
|
|
||||||
try (ImageInputStream stream = ImageIO.createImageInputStream(input)) {
|
|
||||||
return readWithOrientation(stream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads image and metadata, applies Exif orientation to image, and returns everything as an {@code IIOImage}.
|
|
||||||
* The returned {@code IIOImage} will always contain an image and no raster, and
|
|
||||||
* the {@code RenderedImage} may be safely cast to a {@code BufferedImage}.
|
|
||||||
*
|
|
||||||
* If no registered {@code ImageReader} claims to be able to read the input, {@code null} is returned.
|
|
||||||
*
|
|
||||||
* @param input an {@code ImageInputStream}
|
|
||||||
* @return an {@code IIOImage} containing the correctly oriented image and metadata including rotation info, or
|
|
||||||
* {@code null}.
|
|
||||||
* @throws IOException if an error occurs during reading.
|
|
||||||
*/
|
|
||||||
public static IIOImage readWithOrientation(final ImageInputStream input) throws IOException {
|
|
||||||
Iterator<ImageReader> readers = ImageIO.getImageReaders(input);
|
|
||||||
if (!readers.hasNext()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageReader reader = readers.next();
|
|
||||||
try {
|
|
||||||
reader.setInput(input, true, false);
|
|
||||||
|
|
||||||
IIOMetadata metadata = reader.getImageMetadata(0);
|
|
||||||
BufferedImage bufferedImage = applyOrientation(reader.read(0), findImageOrientation(metadata).value());
|
|
||||||
|
|
||||||
return new IIOImage(bufferedImage, null, metadata);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
reader.dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds the {@code ImageOrientation} tag, if any, and returns an {@link Orientation} based on its
|
|
||||||
* {@code value} attribute.
|
|
||||||
* If no match is found or the tag is not present, {@code Normal} (the default orientation) is returned.
|
|
||||||
*
|
|
||||||
* @param metadata an {@code IIOMetadata} object
|
|
||||||
* @return the {@code Orientation} matching the {@code value} attribute of the {@code ImageOrientation} tag,
|
|
||||||
* or {@code Normal}, never {@code null}.
|
|
||||||
* @see Orientation
|
|
||||||
* @see <a href="https://docs.oracle.com/javase/7/docs/api/javax/imageio/metadata/doc-files/standard_metadata.html">Standard (Plug-in Neutral) Metadata Format Specification</a>
|
|
||||||
*/
|
|
||||||
public static Orientation findImageOrientation(final IIOMetadata metadata) {
|
|
||||||
if (metadata != null) {
|
|
||||||
IIOMetadataNode root = (IIOMetadataNode) metadata.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
|
|
||||||
NodeList imageOrientations = root.getElementsByTagName("ImageOrientation");
|
|
||||||
|
|
||||||
if (imageOrientations != null && imageOrientations.getLength() > 0) {
|
|
||||||
IIOMetadataNode imageOrientation = (IIOMetadataNode) imageOrientations.item(0);
|
|
||||||
return Orientation.fromMetadataOrientation(imageOrientation.getAttribute("value"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Orientation.Normal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
|
||||||
for (String arg : args) {
|
|
||||||
File input = new File(arg);
|
|
||||||
|
|
||||||
// Read everything but thumbnails (similar to ImageReader.readAll(0, null)),
|
|
||||||
// and applies the correct image orientation
|
|
||||||
IIOImage image = readWithOrientation(input);
|
|
||||||
|
|
||||||
if (image == null) {
|
|
||||||
System.err.printf("No reader for %s%n", input);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finds the orientation as defined by the javax_imageio_1.0 format
|
|
||||||
Orientation orientation = findImageOrientation(image.getMetadata());
|
|
||||||
|
|
||||||
// Retrieve the image as a BufferedImage. The image is already rotated by the readWithOrientation method
|
|
||||||
// In this case it will already be a BufferedImage, so using a cast will also do
|
|
||||||
// (i.e.: BufferedImage bufferedImage = (BufferedImage) image.getRenderedImage())
|
|
||||||
BufferedImage bufferedImage = ImageUtil.toBuffered(image.getRenderedImage());
|
|
||||||
|
|
||||||
// Demo purpose only, show image with orientation details in title
|
|
||||||
DisplayHelper.showIt(bufferedImage, input.getName() + ": " + orientation.name() + "/" + orientation.value());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't do this... :-) Provided for convenience/demo only!
|
|
||||||
static abstract class DisplayHelper extends ImageReaderBase {
|
|
||||||
private DisplayHelper() {
|
|
||||||
super(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void showIt(BufferedImage image, String title) {
|
|
||||||
ImageReaderBase.showIt(image, title);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
package com.twelvemonkeys.contrib.exif;
|
|
||||||
|
|
||||||
import com.twelvemonkeys.contrib.tiff.TIFFUtilities;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Orientation.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
|
||||||
* @version : Orientation.java,v 1.0 10/07/2020 harald.kuhr
|
|
||||||
*/
|
|
||||||
public enum Orientation {
|
|
||||||
Normal(TIFFUtilities.TIFFBaseline.ORIENTATION_TOPLEFT),
|
|
||||||
FlipH(TIFFUtilities.TIFFExtension.ORIENTATION_TOPRIGHT),
|
|
||||||
Rotate180(TIFFUtilities.TIFFExtension.ORIENTATION_BOTRIGHT),
|
|
||||||
FlipV(TIFFUtilities.TIFFExtension.ORIENTATION_BOTLEFT),
|
|
||||||
FlipVRotate90(TIFFUtilities.TIFFExtension.ORIENTATION_LEFTTOP),
|
|
||||||
Rotate270(TIFFUtilities.TIFFExtension.ORIENTATION_RIGHTTOP),
|
|
||||||
FlipHRotate90(TIFFUtilities.TIFFExtension.ORIENTATION_RIGHTBOT),
|
|
||||||
Rotate90(TIFFUtilities.TIFFExtension.ORIENTATION_LEFTBOT);
|
|
||||||
|
|
||||||
// name as defined in javax.imageio metadata
|
|
||||||
private final int value; // value as defined in TIFF spec
|
|
||||||
|
|
||||||
Orientation(int value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int value() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Orientation fromMetadataOrientation(final String orientationName) {
|
|
||||||
if (orientationName != null) {
|
|
||||||
try {
|
|
||||||
return valueOf(orientationName);
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException e) {
|
|
||||||
// Not found, try ignore case match, as some metadata implementations are known to return "normal" etc.
|
|
||||||
String lowerCaseName = orientationName.toLowerCase();
|
|
||||||
|
|
||||||
for (Orientation orientation : values()) {
|
|
||||||
if (orientation.name().toLowerCase().equals(lowerCaseName)) {
|
|
||||||
return orientation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Metadata does not have other orientations, default to Normal
|
|
||||||
return Normal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Orientation fromTIFFOrientation(final int tiffOrientation) {
|
|
||||||
for (Orientation orientation : values()) {
|
|
||||||
if (orientation.value() == tiffOrientation) {
|
|
||||||
return orientation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// No other TIFF orientations possible, default to Normal
|
|
||||||
return Normal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -45,9 +45,11 @@ import javax.imageio.stream.ImageInputStream;
|
|||||||
import javax.imageio.stream.ImageOutputStream;
|
import javax.imageio.stream.ImageOutputStream;
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -200,10 +202,11 @@ public final class TIFFUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<TIFFPage> getPages(ImageInputStream imageInput) throws IOException {
|
public static List<TIFFPage> getPages(ImageInputStream imageInput) throws IOException {
|
||||||
|
ArrayList<TIFFPage> pages = new ArrayList<TIFFPage>();
|
||||||
|
|
||||||
CompoundDirectory IFDs = (CompoundDirectory) new TIFFReader().read(imageInput);
|
CompoundDirectory IFDs = (CompoundDirectory) new TIFFReader().read(imageInput);
|
||||||
|
|
||||||
final int pageCount = IFDs.directoryCount();
|
int pageCount = IFDs.directoryCount();
|
||||||
List<TIFFPage> pages = new ArrayList<>(pageCount);
|
|
||||||
for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
|
for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
|
||||||
pages.add(new TIFFPage(IFDs.getDirectory(pageIndex), imageInput));
|
pages.add(new TIFFPage(IFDs.getDirectory(pageIndex), imageInput));
|
||||||
}
|
}
|
||||||
@@ -355,21 +358,13 @@ public final class TIFFUtilities {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int compression = -1;
|
|
||||||
Entry compressionEntry = IFD.getEntryById(TIFF.TAG_COMPRESSION);
|
|
||||||
if (compressionEntry != null && compressionEntry.getValue() instanceof Number) {
|
|
||||||
compression = ((Number) compressionEntry.getValue()).shortValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean rearrangedByteStrips = false;
|
boolean rearrangedByteStrips = false;
|
||||||
Entry oldJpegData = IFD.getEntryById(TIFF.TAG_JPEG_INTERCHANGE_FORMAT);
|
Entry oldJpegData = IFD.getEntryById(TIFF.TAG_JPEG_INTERCHANGE_FORMAT);
|
||||||
Entry oldJpegDataLength = IFD.getEntryById(TIFF.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH);
|
Entry oldJpegDataLength = IFD.getEntryById(TIFF.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH);
|
||||||
long[] jpegByteCounts = null;
|
|
||||||
long[] jpegOffsets = null;
|
|
||||||
if (oldJpegData != null && oldJpegData.valueCount() > 0) {
|
if (oldJpegData != null && oldJpegData.valueCount() > 0) {
|
||||||
// convert JPEGInterchangeFormat to new-style-JPEG
|
// convert JPEGInterchangeFormat to new-style-JPEG
|
||||||
jpegByteCounts = new long[0];
|
long[] jpegByteCounts = new long[0];
|
||||||
jpegOffsets = getValueAsLongArray(oldJpegData);
|
long[] jpegOffsets = getValueAsLongArray(oldJpegData);
|
||||||
if (oldJpegDataLength != null && oldJpegDataLength.valueCount() > 0) {
|
if (oldJpegDataLength != null && oldJpegDataLength.valueCount() > 0) {
|
||||||
jpegByteCounts = getValueAsLongArray(oldJpegDataLength);
|
jpegByteCounts = getValueAsLongArray(oldJpegDataLength);
|
||||||
}
|
}
|
||||||
@@ -393,20 +388,6 @@ public final class TIFFUtilities {
|
|||||||
newIFD.remove(oldJpegDataLength);
|
newIFD.remove(oldJpegDataLength);
|
||||||
rearrangedByteStrips = true;
|
rearrangedByteStrips = true;
|
||||||
}
|
}
|
||||||
else if (offsets.length == 1 && oldJpegDataLength != null && (jpegOffsets[0] < offsets[0]) && (jpegOffsets[0] + jpegByteCounts[0]) > (offsets[0] + byteCounts[0])) {
|
|
||||||
|
|
||||||
// ByteStrip contains only a part of JPEGInterchangeFormat
|
|
||||||
newOffsets = writeData(jpegOffsets, jpegByteCounts, outputStream);
|
|
||||||
|
|
||||||
newIFD.remove(stripOffsetsEntry);
|
|
||||||
newIFD.add(new TIFFEntry(useTiles ? TIFF.TAG_TILE_OFFSETS : TIFF.TAG_STRIP_OFFSETS, newOffsets));
|
|
||||||
newIFD.remove(stripByteCountsEntry);
|
|
||||||
newIFD.add(new TIFFEntry(useTiles ? TIFF.TAG_TILE_BYTE_COUNTS : TIFF.TAG_STRIP_BYTE_COUNTS, new int[]{(int) (jpegByteCounts[0])}));
|
|
||||||
|
|
||||||
newIFD.remove(oldJpegData);
|
|
||||||
newIFD.remove(oldJpegDataLength);
|
|
||||||
rearrangedByteStrips = true;
|
|
||||||
}
|
|
||||||
else if (oldJpegDataLength != null) {
|
else if (oldJpegDataLength != null) {
|
||||||
// multiple bytestrips
|
// multiple bytestrips
|
||||||
// search for SOF on first strip and copy to each if needed
|
// search for SOF on first strip and copy to each if needed
|
||||||
@@ -442,7 +423,7 @@ public final class TIFFUtilities {
|
|||||||
byte[] buffer = new byte[(int) byteCounts[i]];
|
byte[] buffer = new byte[(int) byteCounts[i]];
|
||||||
newByteCounts[i] = (int) (jpegInterchangeData.length + byteCounts[i]);
|
newByteCounts[i] = (int) (jpegInterchangeData.length + byteCounts[i]);
|
||||||
stream.readFully(buffer);
|
stream.readFully(buffer);
|
||||||
if (buffer[0] != ((byte) 0xff) || buffer[1] != ((byte) 0xda)) {
|
if (buffer[0] != 0xff && buffer[1] != 0xda) {
|
||||||
outputStream.write(sosMarker);
|
outputStream.write(sosMarker);
|
||||||
newByteCounts[i] += sosMarker.length;
|
newByteCounts[i] += sosMarker.length;
|
||||||
}
|
}
|
||||||
@@ -459,58 +440,7 @@ public final class TIFFUtilities {
|
|||||||
rearrangedByteStrips = true;
|
rearrangedByteStrips = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (compression == TIFFExtension.COMPRESSION_OLD_JPEG) {
|
|
||||||
// old-style but no JPEGInterchangeFormat
|
|
||||||
|
|
||||||
long[] yCbCrSubSampling = getValueAsLongArray(IFD.getEntryById(TIFF.TAG_YCBCR_SUB_SAMPLING));
|
|
||||||
int subsampling = yCbCrSubSampling != null
|
|
||||||
? (int) ((yCbCrSubSampling[0] & 0xf) << 4 | yCbCrSubSampling[1] & 0xf)
|
|
||||||
: 0x22;
|
|
||||||
int bands = ((Number) IFD.getEntryById(TIFF.TAG_SAMPLES_PER_PIXEL).getValue()).intValue();
|
|
||||||
|
|
||||||
int w = ((Number) IFD.getEntryById(TIFF.TAG_IMAGE_WIDTH).getValue()).intValue();
|
|
||||||
int h = ((Number) IFD.getEntryById(TIFF.TAG_IMAGE_HEIGHT).getValue()).intValue();
|
|
||||||
|
|
||||||
int r = ((Number) (useTiles ? IFD.getEntryById(TIFF.TAG_TILE_HEIGTH) : IFD.getEntryById(TIFF.TAG_ROWS_PER_STRIP)).getValue()).intValue();
|
|
||||||
int c = useTiles ? ((Number) IFD.getEntryById(TIFF.TAG_TILE_WIDTH).getValue()).intValue() : w;
|
|
||||||
|
|
||||||
newOffsets = new int[offsets.length];
|
|
||||||
int[] newByteCounts = new int[byteCounts.length];
|
|
||||||
|
|
||||||
// No JPEGInterchangeFormat
|
|
||||||
for (int i = 0; i < offsets.length; i++) {
|
|
||||||
byte[] start = new byte[2];
|
|
||||||
stream.seek(offsets[i]);
|
|
||||||
stream.readFully(start);
|
|
||||||
newOffsets[i] = (int) outputStream.getStreamPosition();
|
|
||||||
if (start[0] == ((byte) 0xff) && start[1] == ((byte) 0xd8)) {
|
|
||||||
// full image stream, nothing to do
|
|
||||||
writeData(stream, outputStream, offsets[i], byteCounts[i]);
|
|
||||||
}
|
|
||||||
else if (start[0] == ((byte) 0xff) && start[1] == ((byte) 0xda)) {
|
|
||||||
// starts with SOS
|
|
||||||
outputStream.writeShort(JPEG.SOI);
|
|
||||||
writeSOF0(outputStream, bands, c, r, subsampling);
|
|
||||||
writeData(stream, outputStream, offsets[i], byteCounts[i]);
|
|
||||||
outputStream.writeShort(JPEG.EOI);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// raw data
|
|
||||||
outputStream.writeShort(JPEG.SOI);
|
|
||||||
writeSOF0(outputStream, bands, c, r, subsampling);
|
|
||||||
writeSOS(outputStream, bands);
|
|
||||||
writeData(stream, outputStream, offsets[i], byteCounts[i]);
|
|
||||||
outputStream.writeShort(JPEG.EOI);
|
|
||||||
}
|
|
||||||
newByteCounts[i] = ((int) outputStream.getStreamPosition()) - newOffsets[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
newIFD.remove(stripOffsetsEntry);
|
|
||||||
newIFD.add(new TIFFEntry(useTiles ? TIFF.TAG_TILE_OFFSETS : TIFF.TAG_STRIP_OFFSETS, newOffsets));
|
|
||||||
newIFD.remove(stripByteCountsEntry);
|
|
||||||
newIFD.add(new TIFFEntry(useTiles ? TIFF.TAG_TILE_BYTE_COUNTS : TIFF.TAG_STRIP_BYTE_COUNTS, newByteCounts));
|
|
||||||
rearrangedByteStrips = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rearrangedByteStrips && stripOffsetsEntry != null && stripByteCountsEntry != null) {
|
if (!rearrangedByteStrips && stripOffsetsEntry != null && stripByteCountsEntry != null) {
|
||||||
newOffsets = writeData(offsets, byteCounts, outputStream);
|
newOffsets = writeData(offsets, byteCounts, outputStream);
|
||||||
@@ -527,21 +457,12 @@ public final class TIFFUtilities {
|
|||||||
oldJpegTableQ = IFD.getEntryById(TIFF.TAG_OLD_JPEG_Q_TABLES);
|
oldJpegTableQ = IFD.getEntryById(TIFF.TAG_OLD_JPEG_Q_TABLES);
|
||||||
oldJpegTableDC = IFD.getEntryById(TIFF.TAG_OLD_JPEG_DC_TABLES);
|
oldJpegTableDC = IFD.getEntryById(TIFF.TAG_OLD_JPEG_DC_TABLES);
|
||||||
oldJpegTableAC = IFD.getEntryById(TIFF.TAG_OLD_JPEG_AC_TABLES);
|
oldJpegTableAC = IFD.getEntryById(TIFF.TAG_OLD_JPEG_AC_TABLES);
|
||||||
if ((oldJpegTableQ != null) || (oldJpegTableDC != null) || (oldJpegTableAC != null)) {
|
if (oldJpegTableQ != null || oldJpegTableDC != null || oldJpegTableAC != null) {
|
||||||
if (IFD.getEntryById(TIFF.TAG_JPEG_TABLES) != null) {
|
if (IFD.getEntryById(TIFF.TAG_JPEG_TABLES) != null) {
|
||||||
throw new IOException("Found old-style and new-style JPEGTables");
|
throw new IOException("Found old-style and new-style JPEGTables");
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean tablesInStream = jfifContainsTables(oldJpegTableQ, jpegOffsets, jpegByteCounts);
|
newIFD.add(mergeTables(oldJpegTableQ, oldJpegTableDC, oldJpegTableAC));
|
||||||
tablesInStream &= jfifContainsTables(oldJpegTableDC, jpegOffsets, jpegByteCounts);
|
|
||||||
tablesInStream &= jfifContainsTables(oldJpegTableAC, jpegOffsets, jpegByteCounts);
|
|
||||||
if (!tablesInStream) {
|
|
||||||
// merge them only to JPEGTables if they are not already contained within the stream
|
|
||||||
Entry jpegTables = mergeTables(oldJpegTableQ, oldJpegTableDC, oldJpegTableAC);
|
|
||||||
if (jpegTables != null) {
|
|
||||||
newIFD.add(jpegTables);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldJpegTableQ != null) {
|
if (oldJpegTableQ != null) {
|
||||||
newIFD.remove(oldJpegTableQ);
|
newIFD.remove(oldJpegTableQ);
|
||||||
}
|
}
|
||||||
@@ -553,66 +474,17 @@ public final class TIFFUtilities {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compressionEntry != null && compression == TIFFExtension.COMPRESSION_OLD_JPEG) {
|
Entry compressionEntry = IFD.getEntryById(TIFF.TAG_COMPRESSION);
|
||||||
newIFD.remove(compressionEntry);
|
if(compressionEntry != null) {
|
||||||
newIFD.add(new TIFFEntry(TIFF.TAG_COMPRESSION, TIFF.TYPE_SHORT, TIFFExtension.COMPRESSION_JPEG));
|
Number compression = (Number) compressionEntry.getValue();
|
||||||
|
if (compression.shortValue() == TIFFExtension.COMPRESSION_OLD_JPEG) {
|
||||||
|
newIFD.remove(compressionEntry);
|
||||||
|
newIFD.add(new TIFFEntry(TIFF.TAG_COMPRESSION, TIFF.TYPE_SHORT, TIFFExtension.COMPRESSION_JPEG));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return newIFD;
|
return newIFD;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO merge/extract from TIFFReader Jpeg/6 stream reconstruction
|
|
||||||
private void writeSOF0(ImageOutputStream outputStream, int bands, int width, int height, int subsampling) throws IOException {
|
|
||||||
outputStream.writeShort(JPEG.SOF0); // TODO: Use correct process for data
|
|
||||||
outputStream.writeShort(2 + 6 + 3 * bands); // SOF0 len
|
|
||||||
outputStream.writeByte(8); // bits TODO: Consult raster/transfer type or BitsPerSample for 12/16 bits support
|
|
||||||
outputStream.writeShort(height); // height
|
|
||||||
outputStream.writeShort(width); // width
|
|
||||||
outputStream.writeByte(bands); // Number of components
|
|
||||||
|
|
||||||
for (int comp = 0; comp < bands; comp++) {
|
|
||||||
outputStream.writeByte(comp); // Component id
|
|
||||||
outputStream.writeByte(comp == 0 ? subsampling : 0x11); // h/v subsampling
|
|
||||||
outputStream.writeByte(comp); // Q table selector TODO: Consider merging if tables are equal, correct selection if only 1 or 2 valid tables are contained
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO merge/extract from TIFFReader Jpeg/6 stream reconstruction
|
|
||||||
private void writeSOS(ImageOutputStream outputStream, int bands) throws IOException {
|
|
||||||
outputStream.writeShort(JPEG.SOS);
|
|
||||||
outputStream.writeShort(6 + 2 * bands); // SOS length
|
|
||||||
outputStream.writeByte(bands); // Num comp
|
|
||||||
|
|
||||||
for (int component = 0; component < bands; component++) {
|
|
||||||
outputStream.writeByte(component); // Comp id
|
|
||||||
outputStream.writeByte(component == 0 ? component : 0x10 + (component & 0xf)); // dc/ac selector TODO: correct selection if only 1 or 2 valid tables are contained
|
|
||||||
}
|
|
||||||
|
|
||||||
outputStream.writeByte(0); // Spectral selection start
|
|
||||||
outputStream.writeByte(0); // Spectral selection end
|
|
||||||
outputStream.writeByte(0); // Approx high & low
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeData(ImageInputStream input, ImageOutputStream output, long offset, long length) throws IOException {
|
|
||||||
input.seek(offset);
|
|
||||||
byte[] buffer = new byte[(int) length];
|
|
||||||
stream.readFully(buffer);
|
|
||||||
output.write(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean jfifContainsTables(Entry tableEntry, long[] jpegOffsets, long[] jpegLengths) throws IOException {
|
|
||||||
if (jpegLengths == null || jpegOffsets == null || jpegLengths.length == 0) return false;
|
|
||||||
if (tableEntry != null) {
|
|
||||||
long[] tableOffsets = getValueAsLongArray(tableEntry);
|
|
||||||
for (long offset : tableOffsets) {
|
|
||||||
if (offset < jpegOffsets[0] || offset > (jpegOffsets[0] + jpegLengths[0])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO merge/extract from TIFFReader Jpeg/6 stream reconstruction
|
|
||||||
private Entry mergeTables(Entry qEntry, Entry dcEntry, Entry acEntry) throws IOException {
|
private Entry mergeTables(Entry qEntry, Entry dcEntry, Entry acEntry) throws IOException {
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
DataOutputStream dos = new DataOutputStream(bos);
|
DataOutputStream dos = new DataOutputStream(bos);
|
||||||
@@ -622,16 +494,12 @@ public final class TIFFUtilities {
|
|||||||
long[] off = getValueAsLongArray(qEntry);
|
long[] off = getValueAsLongArray(qEntry);
|
||||||
byte[] table = new byte[64];
|
byte[] table = new byte[64];
|
||||||
for (int tableId = 0; tableId < off.length; tableId++) {
|
for (int tableId = 0; tableId < off.length; tableId++) {
|
||||||
try {
|
stream.seek(off[tableId]);
|
||||||
stream.seek(off[tableId]);
|
stream.readFully(table);
|
||||||
stream.readFully(table);
|
dos.writeShort(JPEG.DQT);
|
||||||
dos.writeShort(JPEG.DQT);
|
dos.writeShort(3 + 64);
|
||||||
dos.writeShort(3 + 64);
|
dos.writeByte(tableId);
|
||||||
dos.writeByte(tableId);
|
dos.write(table);
|
||||||
dos.write(table);
|
|
||||||
} catch (EOFException e) {
|
|
||||||
// invalid table pointer, ignore
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -639,50 +507,30 @@ public final class TIFFUtilities {
|
|||||||
if (dcEntry != null && dcEntry.valueCount() > 0) {
|
if (dcEntry != null && dcEntry.valueCount() > 0) {
|
||||||
long[] off = getValueAsLongArray(dcEntry);
|
long[] off = getValueAsLongArray(dcEntry);
|
||||||
for (int tableId = 0; tableId < off.length; tableId++) {
|
for (int tableId = 0; tableId < off.length; tableId++) {
|
||||||
try {
|
stream.seek(off[tableId]);
|
||||||
stream.seek(off[tableId]);
|
byte[] table = readHUFFTable();
|
||||||
byte[] table = readHUFFTable();
|
dos.writeShort(JPEG.DHT);
|
||||||
if (table.length > (16 + 17)) {
|
dos.writeShort(3 + table.length);
|
||||||
// to long, table is invalid, just ignoe
|
dos.writeByte(tableId);
|
||||||
continue;
|
dos.write(table);
|
||||||
}
|
|
||||||
dos.writeShort(JPEG.DHT);
|
|
||||||
dos.writeShort(3 + table.length);
|
|
||||||
dos.writeByte(tableId);
|
|
||||||
dos.write(table);
|
|
||||||
} catch (EOFException e) {
|
|
||||||
// invalid table pointer, ignore
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (acEntry != null && acEntry.valueCount() > 0) {
|
if (acEntry != null && acEntry.valueCount() > 0) {
|
||||||
long[] off = getValueAsLongArray(acEntry);
|
long[] off = getValueAsLongArray(acEntry);
|
||||||
for (int tableId = 0; tableId < off.length; tableId++) {
|
for (int tableId = 0; tableId < off.length; tableId++) {
|
||||||
try {
|
stream.seek(off[tableId]);
|
||||||
stream.seek(off[tableId]);
|
byte[] table = readHUFFTable();
|
||||||
byte[] table = readHUFFTable();
|
dos.writeShort(JPEG.DHT);
|
||||||
if (table.length > (16 + 256)) {
|
dos.writeShort(3 + table.length);
|
||||||
// to long, table is invalid, just ignoe
|
dos.writeByte(16 | tableId);
|
||||||
continue;
|
dos.write(table);
|
||||||
}
|
|
||||||
dos.writeShort(JPEG.DHT);
|
|
||||||
dos.writeShort(3 + table.length);
|
|
||||||
dos.writeByte(16 | tableId);
|
|
||||||
dos.write(table);
|
|
||||||
} catch (EOFException e) {
|
|
||||||
// invalid table pointer, ignore
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dos.writeShort(JPEG.EOI);
|
dos.writeShort(JPEG.EOI);
|
||||||
|
|
||||||
bos.close();
|
bos.close();
|
||||||
if (bos.size() == 4) {
|
|
||||||
// no valid tables, don't add
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new TIFFEntry(TIFF.TAG_JPEG_TABLES, TIFF.TYPE_UNDEFINED, bos.toByteArray());
|
return new TIFFEntry(TIFF.TAG_JPEG_TABLES, TIFF.TYPE_UNDEFINED, bos.toByteArray());
|
||||||
}
|
}
|
||||||
@@ -692,11 +540,15 @@ public final class TIFFUtilities {
|
|||||||
stream.readFully(lengths);
|
stream.readFully(lengths);
|
||||||
int numCodes = 0;
|
int numCodes = 0;
|
||||||
for (int i = 0; i < lengths.length; i++) {
|
for (int i = 0; i < lengths.length; i++) {
|
||||||
numCodes += ((int) lengths[i]) & 0xff;
|
numCodes += lengths[i];
|
||||||
}
|
}
|
||||||
byte table[] = new byte[16 + numCodes];
|
byte table[] = new byte[16 + numCodes];
|
||||||
System.arraycopy(lengths, 0, table, 0, 16);
|
System.arraycopy(lengths, 0, table, 0, 16);
|
||||||
stream.readFully(table, 16, numCodes);
|
int off = 16;
|
||||||
|
for (int i = 0; i < lengths.length; i++) {
|
||||||
|
stream.read(table, off, lengths[i]);
|
||||||
|
off += lengths[i];
|
||||||
|
}
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -707,11 +559,7 @@ public final class TIFFUtilities {
|
|||||||
stream.seek(offsets[i]);
|
stream.seek(offsets[i]);
|
||||||
|
|
||||||
byte[] buffer = new byte[(int) byteCounts[i]];
|
byte[] buffer = new byte[(int) byteCounts[i]];
|
||||||
try {
|
stream.readFully(buffer);
|
||||||
stream.readFully(buffer);
|
|
||||||
} catch (EOFException e) {
|
|
||||||
// invalid strip length
|
|
||||||
}
|
|
||||||
outputStream.write(buffer);
|
outputStream.write(buffer);
|
||||||
}
|
}
|
||||||
return newOffsets;
|
return newOffsets;
|
||||||
@@ -723,7 +571,7 @@ public final class TIFFUtilities {
|
|||||||
|
|
||||||
if (entry.valueCount() == 1) {
|
if (entry.valueCount() == 1) {
|
||||||
// For single entries, this will be a boxed type
|
// For single entries, this will be a boxed type
|
||||||
value = new long[]{((Number) entry.getValue()).longValue()};
|
value = new long[] {((Number) entry.getValue()).longValue()};
|
||||||
}
|
}
|
||||||
else if (entry.getValue() instanceof short[]) {
|
else if (entry.getValue() instanceof short[]) {
|
||||||
short[] shorts = (short[]) entry.getValue();
|
short[] shorts = (short[]) entry.getValue();
|
||||||
|
|||||||
@@ -1,75 +0,0 @@
|
|||||||
package com.twelvemonkeys.contrib.exif;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static com.twelvemonkeys.contrib.exif.Orientation.*;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OrientationTest.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
|
||||||
* @author last modified by : harald.kuhr$
|
|
||||||
* @version : OrientationTest.java,v 1.0 10/07/2020 harald.kuhr Exp$
|
|
||||||
*/
|
|
||||||
public class OrientationTest {
|
|
||||||
@Test
|
|
||||||
public void testFromMetadataOrientationNull() {
|
|
||||||
assertEquals(Normal, Orientation.fromMetadataOrientation(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testFromMetadataOrientation() {
|
|
||||||
assertEquals(Normal, Orientation.fromMetadataOrientation("Normal"));
|
|
||||||
assertEquals(Rotate90, Orientation.fromMetadataOrientation("Rotate90"));
|
|
||||||
assertEquals(Rotate180, Orientation.fromMetadataOrientation("Rotate180"));
|
|
||||||
assertEquals(Rotate270, Orientation.fromMetadataOrientation("Rotate270"));
|
|
||||||
assertEquals(FlipH, Orientation.fromMetadataOrientation("FlipH"));
|
|
||||||
assertEquals(FlipV, Orientation.fromMetadataOrientation("FlipV"));
|
|
||||||
assertEquals(FlipHRotate90, Orientation.fromMetadataOrientation("FlipHRotate90"));
|
|
||||||
assertEquals(FlipVRotate90, Orientation.fromMetadataOrientation("FlipVRotate90"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testFromMetadataOrientationIgnoreCase() {
|
|
||||||
assertEquals(Normal, Orientation.fromMetadataOrientation("normal"));
|
|
||||||
assertEquals(Rotate90, Orientation.fromMetadataOrientation("rotate90"));
|
|
||||||
assertEquals(Rotate180, Orientation.fromMetadataOrientation("ROTATE180"));
|
|
||||||
assertEquals(Rotate270, Orientation.fromMetadataOrientation("ROTATE270"));
|
|
||||||
assertEquals(FlipH, Orientation.fromMetadataOrientation("FLIPH"));
|
|
||||||
assertEquals(FlipV, Orientation.fromMetadataOrientation("flipv"));
|
|
||||||
assertEquals(FlipHRotate90, Orientation.fromMetadataOrientation("FLIPhrotate90"));
|
|
||||||
assertEquals(FlipVRotate90, Orientation.fromMetadataOrientation("fLiPVRotAte90"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testFromMetadataOrientationUnknown() {
|
|
||||||
assertEquals(Normal, Orientation.fromMetadataOrientation("foo"));
|
|
||||||
assertEquals(Normal, Orientation.fromMetadataOrientation("90"));
|
|
||||||
assertEquals(Normal, Orientation.fromMetadataOrientation("randomStringWithNumbers180"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testFromTIFFOrientation() {
|
|
||||||
assertEquals(Normal, Orientation.fromTIFFOrientation(1));
|
|
||||||
assertEquals(FlipH, Orientation.fromTIFFOrientation(2));
|
|
||||||
assertEquals(Rotate180, Orientation.fromTIFFOrientation(3));
|
|
||||||
assertEquals(FlipV, Orientation.fromTIFFOrientation(4));
|
|
||||||
assertEquals(FlipVRotate90, Orientation.fromTIFFOrientation(5));
|
|
||||||
assertEquals(Rotate270, Orientation.fromTIFFOrientation(6));
|
|
||||||
assertEquals(FlipHRotate90, Orientation.fromTIFFOrientation(7));
|
|
||||||
assertEquals(Rotate90, Orientation.fromTIFFOrientation(8));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testFromTIFFOrientationUnknown() {
|
|
||||||
assertEquals(Normal, Orientation.fromTIFFOrientation(-1));
|
|
||||||
assertEquals(Normal, Orientation.fromTIFFOrientation(0));
|
|
||||||
assertEquals(Normal, Orientation.fromTIFFOrientation(9));
|
|
||||||
for (int i = 10; i < 1024; i++) {
|
|
||||||
assertEquals(Normal, Orientation.fromTIFFOrientation(i));
|
|
||||||
}
|
|
||||||
assertEquals(Normal, Orientation.fromTIFFOrientation(Integer.MAX_VALUE));
|
|
||||||
assertEquals(Normal, Orientation.fromTIFFOrientation(Integer.MIN_VALUE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -31,9 +31,8 @@
|
|||||||
package com.twelvemonkeys.contrib.tiff;
|
package com.twelvemonkeys.contrib.tiff;
|
||||||
|
|
||||||
import com.twelvemonkeys.contrib.tiff.TIFFUtilities.TIFFExtension;
|
import com.twelvemonkeys.contrib.tiff.TIFFUtilities.TIFFExtension;
|
||||||
import com.twelvemonkeys.imageio.plugins.tiff.TIFFImageMetadataFormat;
|
import com.twelvemonkeys.imageio.plugins.tiff.TIFFMedataFormat;
|
||||||
import com.twelvemonkeys.io.FileUtil;
|
import com.twelvemonkeys.io.FileUtil;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
@@ -155,7 +154,7 @@ public class TIFFUtilitiesTest {
|
|||||||
reader.setInput(checkTest1);
|
reader.setInput(checkTest1);
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
Node metaData = reader.getImageMetadata(i)
|
Node metaData = reader.getImageMetadata(i)
|
||||||
.getAsTree(TIFFImageMetadataFormat.SUN_NATIVE_IMAGE_METADATA_FORMAT_NAME);
|
.getAsTree(TIFFMedataFormat.SUN_NATIVE_IMAGE_METADATA_FORMAT_NAME);
|
||||||
short orientation = ((Number) expression.evaluate(metaData, XPathConstants.NUMBER)).shortValue();
|
short orientation = ((Number) expression.evaluate(metaData, XPathConstants.NUMBER)).shortValue();
|
||||||
Assert.assertEquals(orientation, TIFFExtension.ORIENTATION_RIGHTTOP);
|
Assert.assertEquals(orientation, TIFFExtension.ORIENTATION_RIGHTTOP);
|
||||||
}
|
}
|
||||||
@@ -172,7 +171,7 @@ public class TIFFUtilitiesTest {
|
|||||||
reader.setInput(checkTest2);
|
reader.setInput(checkTest2);
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
Node metaData = reader.getImageMetadata(i)
|
Node metaData = reader.getImageMetadata(i)
|
||||||
.getAsTree(TIFFImageMetadataFormat.SUN_NATIVE_IMAGE_METADATA_FORMAT_NAME);
|
.getAsTree(TIFFMedataFormat.SUN_NATIVE_IMAGE_METADATA_FORMAT_NAME);
|
||||||
short orientation = ((Number) expression.evaluate(metaData, XPathConstants.NUMBER)).shortValue();
|
short orientation = ((Number) expression.evaluate(metaData, XPathConstants.NUMBER)).shortValue();
|
||||||
Assert.assertEquals(orientation, i == 1
|
Assert.assertEquals(orientation, i == 1
|
||||||
? TIFFExtension.ORIENTATION_BOTRIGHT
|
? TIFFExtension.ORIENTATION_BOTRIGHT
|
||||||
@@ -203,39 +202,36 @@ public class TIFFUtilitiesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOldStyleJPEGTransform() throws IOException {
|
public void testMergeBogusInterchangeFormatLength() throws IOException {
|
||||||
String[] testFiles = new String[]{
|
String[] testFiles = new String[] {
|
||||||
"/tiff/old-style-jpeg-bogus-jpeginterchangeformatlength.tif", // InterchangeFormat before StripOffset, length not including StripOffset
|
"/tiff/old-style-jpeg-bogus-jpeginterchangeformatlength.tif", // InterchangeFormat before StripOffset, length not including StripOffset
|
||||||
"/tiff/old-style-jpeg-no-jpeginterchangeformatlength.tif", // missing JPEGInterChangeFormatLength and JPEGInterchangeFormat == StipOffset
|
"/tiff/old-style-jpeg-no-jpeginterchangeformatlength.tif", // missing JPEGInterChangeFormatLength and JPEGInterchangeFormat == StipOffset
|
||||||
"/tiff/old-style-jpeg-multiple-strips.tif", // InterchangeFormat with multiple strips
|
"/tiff/old-style-jpeg-multiple-strips.tif" // InterchangeFormat with multiple strips
|
||||||
"/contrib/tiff/old-style-jpeg-invalid-tables.tif", // AC/DC Tables are invalid (to long) and lie within the JPEGInterchangeFormat stream
|
|
||||||
"/contrib/tiff/smallliz.tif", // InterchangeFormat contains whole JPEG, ByteStrip only raw ImageData after SOS
|
|
||||||
"/contrib/tiff/WangJPEG.tif", // multiple strips, first strip contains SOS
|
|
||||||
"/contrib/tiff/zackthecat.tif" // No JPEGInterchangeFormat, ByteStrip contains only raw image data
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for (String testFile : testFiles) {
|
for (String testFile : testFiles) {
|
||||||
try {
|
File output = File.createTempFile("imageiotest", ".tif");
|
||||||
File output = File.createTempFile("imageiotest", ".tif");
|
ImageOutputStream outputStream = ImageIO.createImageOutputStream(output);
|
||||||
ImageOutputStream outputStream = ImageIO.createImageOutputStream(output);
|
InputStream inputStream1 = getClassLoaderResource(testFile).openStream();
|
||||||
InputStream inputStream = getClassLoaderResource(testFile).openStream();
|
ImageInputStream imageInput1 = ImageIO.createImageInputStream(inputStream1);
|
||||||
ImageInputStream imageInput = ImageIO.createImageInputStream(inputStream);
|
InputStream inputStream2 = getClassLoaderResource(testFile).openStream();
|
||||||
List<TIFFUtilities.TIFFPage> pages = TIFFUtilities.getPages(imageInput);
|
ImageInputStream imageInput2 = ImageIO.createImageInputStream(inputStream2);
|
||||||
TIFFUtilities.writePages(outputStream, pages);
|
ArrayList<TIFFUtilities.TIFFPage> pages = new ArrayList<>();
|
||||||
|
pages.addAll(TIFFUtilities.getPages(imageInput1));
|
||||||
|
pages.addAll(TIFFUtilities.getPages(imageInput2));
|
||||||
|
TIFFUtilities.writePages(outputStream, pages);
|
||||||
|
|
||||||
ImageInputStream testOutput = ImageIO.createImageInputStream(output);
|
ImageInputStream testOutput = ImageIO.createImageInputStream(output);
|
||||||
ImageReader reader = ImageIO.getImageReaders(testOutput).next();
|
ImageReader reader = ImageIO.getImageReaders(testOutput).next();
|
||||||
reader.setInput(testOutput);
|
reader.setInput(testOutput);
|
||||||
int numImages = reader.getNumImages(true);
|
int numImages = reader.getNumImages(true);
|
||||||
for (int i = 0; i < numImages; i++) {
|
for (int i = 0; i < numImages; i++) {
|
||||||
reader.read(i);
|
reader.read(i);
|
||||||
}
|
|
||||||
|
|
||||||
imageInput.close();
|
|
||||||
outputStream.close();
|
|
||||||
} catch (Exception exc) {
|
|
||||||
throw new IOException(testFile, exc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
imageInput1.close();
|
||||||
|
imageInput2.close();
|
||||||
|
outputStream.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||||
<artifactId>imageio</artifactId>
|
<artifactId>imageio</artifactId>
|
||||||
<version>3.8.4-SNAPSHOT</version>
|
<version>3.4.4-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>imageio-batik</artifactId>
|
<artifactId>imageio-batik</artifactId>
|
||||||
<name>TwelveMonkeys :: ImageIO :: Batik Plugin</name>
|
<name>TwelveMonkeys :: ImageIO :: Batik Plugin</name>
|
||||||
@@ -15,27 +15,6 @@
|
|||||||
for more information.]]>
|
for more information.]]>
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<project.jpms.module.name>com.twelvemonkeys.imageio.batik</project.jpms.module.name>
|
|
||||||
<batik.version>1.14</batik.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<systemPropertyVariables>
|
|
||||||
<com.twelvemonkeys.imageio.plugins.svg.allowExternalResources>
|
|
||||||
true
|
|
||||||
</com.twelvemonkeys.imageio.plugins.svg.allowExternalResources>
|
|
||||||
</systemPropertyVariables>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||||
@@ -45,14 +24,6 @@
|
|||||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||||
<artifactId>imageio-core</artifactId>
|
<artifactId>imageio-core</artifactId>
|
||||||
<type>test-jar</type>
|
<type>test-jar</type>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-io</groupId>
|
|
||||||
<artifactId>commons-io</artifactId>
|
|
||||||
<version>2.11.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -75,6 +46,13 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.xmlgraphics</groupId>
|
||||||
|
<artifactId>xmlgraphics-commons</artifactId>
|
||||||
|
<version>2.2</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.xmlgraphics</groupId>
|
<groupId>org.apache.xmlgraphics</groupId>
|
||||||
<artifactId>batik-anim</artifactId>
|
<artifactId>batik-anim</artifactId>
|
||||||
@@ -98,7 +76,7 @@
|
|||||||
<!--
|
<!--
|
||||||
There seems to be some weirdness in the
|
There seems to be some weirdness in the
|
||||||
Batik/FOP poms (Batik depends on FOP 0.20-5) that screws things up,
|
Batik/FOP poms (Batik depends on FOP 0.20-5) that screws things up,
|
||||||
making everything end up depending on Batik 1.5, not the specified version
|
making everything end up depending on Batik 1.5, not 1.6
|
||||||
-->
|
-->
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
@@ -108,4 +86,8 @@
|
|||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<batik.version>1.9</batik.version>
|
||||||
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
+84
-141
@@ -33,8 +33,6 @@ package com.twelvemonkeys.imageio.plugins.svg;
|
|||||||
import com.twelvemonkeys.image.ImageUtil;
|
import com.twelvemonkeys.image.ImageUtil;
|
||||||
import com.twelvemonkeys.imageio.ImageReaderBase;
|
import com.twelvemonkeys.imageio.ImageReaderBase;
|
||||||
import com.twelvemonkeys.imageio.util.IIOUtil;
|
import com.twelvemonkeys.imageio.util.IIOUtil;
|
||||||
import com.twelvemonkeys.lang.StringUtil;
|
|
||||||
|
|
||||||
import org.apache.batik.anim.dom.SVGDOMImplementation;
|
import org.apache.batik.anim.dom.SVGDOMImplementation;
|
||||||
import org.apache.batik.anim.dom.SVGOMDocument;
|
import org.apache.batik.anim.dom.SVGOMDocument;
|
||||||
import org.apache.batik.bridge.*;
|
import org.apache.batik.bridge.*;
|
||||||
@@ -45,11 +43,7 @@ import org.apache.batik.gvt.GraphicsNode;
|
|||||||
import org.apache.batik.gvt.renderer.ConcreteImageRendererFactory;
|
import org.apache.batik.gvt.renderer.ConcreteImageRendererFactory;
|
||||||
import org.apache.batik.gvt.renderer.ImageRenderer;
|
import org.apache.batik.gvt.renderer.ImageRenderer;
|
||||||
import org.apache.batik.gvt.renderer.ImageRendererFactory;
|
import org.apache.batik.gvt.renderer.ImageRendererFactory;
|
||||||
import org.apache.batik.transcoder.SVGAbstractTranscoder;
|
import org.apache.batik.transcoder.*;
|
||||||
import org.apache.batik.transcoder.TranscoderException;
|
|
||||||
import org.apache.batik.transcoder.TranscoderInput;
|
|
||||||
import org.apache.batik.transcoder.TranscoderOutput;
|
|
||||||
import org.apache.batik.transcoder.TranscodingHints;
|
|
||||||
import org.apache.batik.transcoder.image.ImageTranscoder;
|
import org.apache.batik.transcoder.image.ImageTranscoder;
|
||||||
import org.apache.batik.util.ParsedURL;
|
import org.apache.batik.util.ParsedURL;
|
||||||
import org.apache.batik.util.SVGConstants;
|
import org.apache.batik.util.SVGConstants;
|
||||||
@@ -62,8 +56,10 @@ import javax.imageio.ImageReadParam;
|
|||||||
import javax.imageio.ImageTypeSpecifier;
|
import javax.imageio.ImageTypeSpecifier;
|
||||||
import javax.imageio.spi.ImageReaderSpi;
|
import javax.imageio.spi.ImageReaderSpi;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.geom.*;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.image.*;
|
import java.awt.geom.Dimension2D;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@@ -77,16 +73,10 @@ import java.util.Map;
|
|||||||
* @author Harald Kuhr
|
* @author Harald Kuhr
|
||||||
* @author Inpspired by code from the Batik Team
|
* @author Inpspired by code from the Batik Team
|
||||||
* @version $Id: $
|
* @version $Id: $
|
||||||
* @see <a href="http://www.mail-archive.com/batik-dev@xml.apache.org/msg00992.html">batik-dev</a>
|
* @see <A href="http://www.mail-archive.com/batik-dev@xml.apache.org/msg00992.html">batik-dev</A>
|
||||||
*/
|
*/
|
||||||
public class SVGImageReader extends ImageReaderBase {
|
public class SVGImageReader extends ImageReaderBase {
|
||||||
|
|
||||||
final static boolean DEFAULT_ALLOW_EXTERNAL_RESOURCES =
|
|
||||||
"true".equalsIgnoreCase(System.getProperty("com.twelvemonkeys.imageio.plugins.svg.allowExternalResources",
|
|
||||||
System.getProperty("com.twelvemonkeys.imageio.plugins.svg.allowexternalresources")));
|
|
||||||
|
|
||||||
private Rasterizer rasterizer;
|
private Rasterizer rasterizer;
|
||||||
private boolean allowExternalResources = DEFAULT_ALLOW_EXTERNAL_RESOURCES;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an {@code SVGImageReader}.
|
* Creates an {@code SVGImageReader}.
|
||||||
@@ -123,9 +113,6 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
if (pParam instanceof SVGReadParam) {
|
if (pParam instanceof SVGReadParam) {
|
||||||
SVGReadParam svgParam = (SVGReadParam) pParam;
|
SVGReadParam svgParam = (SVGReadParam) pParam;
|
||||||
|
|
||||||
// set the external-resource-resolution preference
|
|
||||||
allowExternalResources = svgParam.isAllowExternalResources();
|
|
||||||
|
|
||||||
// Get the base URI
|
// Get the base URI
|
||||||
// This must be done before converting the params to hints
|
// This must be done before converting the params to hints
|
||||||
String baseURI = svgParam.getBaseURI();
|
String baseURI = svgParam.getBaseURI();
|
||||||
@@ -134,7 +121,6 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
// Set ImageReadParams as hints
|
// Set ImageReadParams as hints
|
||||||
// Note: The cast to Map invokes a different method that preserves
|
// Note: The cast to Map invokes a different method that preserves
|
||||||
// unset defaults, DO NOT REMOVE!
|
// unset defaults, DO NOT REMOVE!
|
||||||
//noinspection rawtypes
|
|
||||||
rasterizer.setTranscodingHints((Map) paramsToHints(svgParam));
|
rasterizer.setTranscodingHints((Map) paramsToHints(svgParam));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,23 +135,29 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
BufferedImage destination = getDestination(pParam, getImageTypes(pIndex), size.width, size.height);
|
BufferedImage destination = getDestination(pParam, getImageTypes(pIndex), size.width, size.height);
|
||||||
|
|
||||||
// Read in the image, using the Batik Transcoder
|
// Read in the image, using the Batik Transcoder
|
||||||
processImageStarted(pIndex);
|
|
||||||
|
|
||||||
BufferedImage image = rasterizer.getImage();
|
|
||||||
|
|
||||||
Graphics2D g = destination.createGraphics();
|
|
||||||
try {
|
try {
|
||||||
g.setComposite(AlphaComposite.Src);
|
processImageStarted(pIndex);
|
||||||
g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
|
|
||||||
g.drawImage(image, 0, 0, null); // TODO: Dest offset?
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
g.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
processImageComplete();
|
BufferedImage image = rasterizer.getImage();
|
||||||
|
|
||||||
return destination;
|
Graphics2D g = destination.createGraphics();
|
||||||
|
try {
|
||||||
|
g.setComposite(AlphaComposite.Src);
|
||||||
|
g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
|
||||||
|
g.drawImage(image, 0, 0, null); // TODO: Dest offset?
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
g.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
processImageComplete();
|
||||||
|
|
||||||
|
return destination;
|
||||||
|
}
|
||||||
|
catch (TranscoderException e) {
|
||||||
|
Throwable cause = unwrapException(e);
|
||||||
|
throw new IIOException(cause.getMessage(), cause);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Throwable unwrapException(TranscoderException ex) {
|
private static Throwable unwrapException(TranscoderException ex) {
|
||||||
@@ -180,11 +172,11 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
|
|
||||||
// Set dimensions
|
// Set dimensions
|
||||||
Dimension size = pParam.getSourceRenderSize();
|
Dimension size = pParam.getSourceRenderSize();
|
||||||
Rectangle viewBox = rasterizer.getViewBox();
|
Dimension origSize = new Dimension(getWidth(0), getHeight(0));
|
||||||
if (size == null) {
|
if (size == null) {
|
||||||
// SVG is not a pixel based format, but we'll scale it, according to
|
// SVG is not a pixel based format, but we'll scale it, according to
|
||||||
// the subsampling for compatibility
|
// the subsampling for compatibility
|
||||||
size = getSourceRenderSizeFromSubsamping(pParam, viewBox.getSize());
|
size = getSourceRenderSizeFromSubsamping(pParam, origSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size != null) {
|
if (size != null) {
|
||||||
@@ -204,8 +196,8 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Need to resize here...
|
// Need to resize here...
|
||||||
double xScale = size.getWidth() / viewBox.getWidth();
|
double xScale = size.getWidth() / origSize.getWidth();
|
||||||
double yScale = size.getHeight() / viewBox.getHeight();
|
double yScale = size.getHeight() / origSize.getHeight();
|
||||||
|
|
||||||
hints.put(ImageTranscoder.KEY_WIDTH, (float) (region.getWidth() * xScale));
|
hints.put(ImageTranscoder.KEY_WIDTH, (float) (region.getWidth() * xScale));
|
||||||
hints.put(ImageTranscoder.KEY_HEIGHT, (float) (region.getHeight() * yScale));
|
hints.put(ImageTranscoder.KEY_HEIGHT, (float) (region.getHeight() * yScale));
|
||||||
@@ -213,7 +205,7 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
else if (size != null) {
|
else if (size != null) {
|
||||||
// Allow non-uniform scaling
|
// Allow non-uniform scaling
|
||||||
hints.put(ImageTranscoder.KEY_AOI, viewBox);
|
hints.put(ImageTranscoder.KEY_AOI, new Rectangle(origSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Background color
|
// Background color
|
||||||
@@ -228,7 +220,7 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
private Dimension getSourceRenderSizeFromSubsamping(ImageReadParam pParam, Dimension pOrigSize) {
|
private Dimension getSourceRenderSizeFromSubsamping(ImageReadParam pParam, Dimension pOrigSize) {
|
||||||
if (pParam.getSourceXSubsampling() > 1 || pParam.getSourceYSubsampling() > 1) {
|
if (pParam.getSourceXSubsampling() > 1 || pParam.getSourceYSubsampling() > 1) {
|
||||||
return new Dimension((int) (pOrigSize.width / (float) pParam.getSourceXSubsampling()),
|
return new Dimension((int) (pOrigSize.width / (float) pParam.getSourceXSubsampling()),
|
||||||
(int) (pOrigSize.height / (float) pParam.getSourceYSubsampling()));
|
(int) (pOrigSize.height / (float) pParam.getSourceYSubsampling()));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -239,16 +231,25 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
|
|
||||||
public int getWidth(int pIndex) throws IOException {
|
public int getWidth(int pIndex) throws IOException {
|
||||||
checkBounds(pIndex);
|
checkBounds(pIndex);
|
||||||
|
try {
|
||||||
return rasterizer.getDefaultWidth();
|
return rasterizer.getDefaultWidth();
|
||||||
|
}
|
||||||
|
catch (TranscoderException e) {
|
||||||
|
throw new IIOException(e.getMessage(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeight(int pIndex) throws IOException {
|
public int getHeight(int pIndex) throws IOException {
|
||||||
checkBounds(pIndex);
|
checkBounds(pIndex);
|
||||||
return rasterizer.getDefaultHeight();
|
try {
|
||||||
|
return rasterizer.getDefaultHeight();
|
||||||
|
}
|
||||||
|
catch (TranscoderException e) {
|
||||||
|
throw new IIOException(e.getMessage(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex) {
|
public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex) throws IOException {
|
||||||
return Collections.singleton(ImageTypeSpecifier.createFromRenderedImage(rasterizer.createImage(1, 1))).iterator();
|
return Collections.singleton(ImageTypeSpecifier.createFromRenderedImage(rasterizer.createImage(1, 1))).iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,11 +260,12 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
* and needs major refactoring!
|
* and needs major refactoring!
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
private class Rasterizer extends SVGAbstractTranscoder {
|
private class Rasterizer extends SVGAbstractTranscoder /*ImageTranscoder*/ {
|
||||||
|
|
||||||
private BufferedImage image;
|
private BufferedImage image;
|
||||||
private TranscoderInput transcoderInput;
|
private TranscoderInput transcoderInput;
|
||||||
private final Rectangle2D viewBox = new Rectangle2D.Float();
|
private float defaultWidth;
|
||||||
private final Dimension defaultSize = new Dimension();
|
private float defaultHeight;
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
private SVGOMDocument document;
|
private SVGOMDocument document;
|
||||||
private String uri;
|
private String uri;
|
||||||
@@ -276,7 +278,7 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This is cheating... We don't fully transcode after all
|
// This is cheating... We don't fully transcode after all
|
||||||
protected void transcode(Document document, final String uri, final TranscoderOutput output) {
|
protected void transcode(Document document, final String uri, final TranscoderOutput output) throws TranscoderException {
|
||||||
// Sets up root, curTxf & curAoi
|
// Sets up root, curTxf & curAoi
|
||||||
// ----
|
// ----
|
||||||
if (document != null) {
|
if (document != null) {
|
||||||
@@ -322,66 +324,24 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
SVGSVGElement rootElement = svgDoc.getRootElement();
|
|
||||||
|
|
||||||
// Get the viewBox
|
// get the 'width' and 'height' attributes of the SVG document
|
||||||
String viewBoxStr = rootElement.getAttributeNS(null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE);
|
Dimension2D docSize = ctx.getDocumentSize();
|
||||||
|
if (docSize != null) {
|
||||||
|
defaultWidth = (float) docSize.getWidth();
|
||||||
|
defaultHeight = (float) docSize.getHeight();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
defaultWidth = 200;
|
||||||
|
defaultHeight = 200;
|
||||||
|
}
|
||||||
|
SVGSVGElement rootElement = svgDoc.getRootElement();
|
||||||
|
String viewBoxStr = rootElement.getAttributeNS
|
||||||
|
(null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE);
|
||||||
if (viewBoxStr.length() != 0) {
|
if (viewBoxStr.length() != 0) {
|
||||||
float[] rect = ViewBox.parseViewBoxAttribute(rootElement, viewBoxStr, null);
|
float[] rect = ViewBox.parseViewBoxAttribute(rootElement, viewBoxStr, null);
|
||||||
viewBox.setFrame(rect[0], rect[1], rect[2], rect[3]);
|
defaultWidth = rect[2];
|
||||||
}
|
defaultHeight = rect[3];
|
||||||
|
|
||||||
// Get the 'width' and 'height' attributes of the SVG document
|
|
||||||
double width = 0;
|
|
||||||
double height = 0;
|
|
||||||
UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, rootElement);
|
|
||||||
String widthStr = rootElement.getAttributeNS(null, SVGConstants.SVG_WIDTH_ATTRIBUTE);
|
|
||||||
String heightStr = rootElement.getAttributeNS(null, SVGConstants.SVG_HEIGHT_ATTRIBUTE);
|
|
||||||
if (!StringUtil.isEmpty(widthStr)) {
|
|
||||||
width = UnitProcessor.svgToUserSpace(widthStr, SVGConstants.SVG_WIDTH_ATTRIBUTE, UnitProcessor.HORIZONTAL_LENGTH, uctx);
|
|
||||||
}
|
|
||||||
if (!StringUtil.isEmpty(heightStr)) {
|
|
||||||
height = UnitProcessor.svgToUserSpace(heightStr, SVGConstants.SVG_HEIGHT_ATTRIBUTE, UnitProcessor.VERTICAL_LENGTH, uctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean hasWidth = width > 0.0;
|
|
||||||
boolean hasHeight = height > 0.0;
|
|
||||||
|
|
||||||
if (!hasWidth || !hasHeight) {
|
|
||||||
if (!viewBox.isEmpty()) {
|
|
||||||
// If one dimension is given, calculate other by aspect ratio in viewBox
|
|
||||||
if (hasWidth) {
|
|
||||||
height = width * viewBox.getHeight() / viewBox.getWidth();
|
|
||||||
}
|
|
||||||
else if (hasHeight) {
|
|
||||||
width = height * viewBox.getWidth() / viewBox.getHeight();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// ...or use viewBox if no dimension is given
|
|
||||||
width = viewBox.getWidth();
|
|
||||||
height = viewBox.getHeight();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// No viewBox, just assume square size
|
|
||||||
if (hasHeight) {
|
|
||||||
width = height;
|
|
||||||
}
|
|
||||||
else if (hasWidth) {
|
|
||||||
height = width;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// ...or finally fall back to Batik default sizes
|
|
||||||
width = 400;
|
|
||||||
height = 400;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We now have a size, in the rare case we don't have a viewBox; set it to this size
|
|
||||||
defaultSize.setSize(width, height);
|
|
||||||
if (viewBox.isEmpty()) {
|
|
||||||
viewBox.setRect(0, 0, width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hack to work around exception above
|
// Hack to work around exception above
|
||||||
@@ -396,7 +356,7 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
ctx = null;
|
ctx = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BufferedImage readImage() throws IOException {
|
private BufferedImage readImage() throws TranscoderException {
|
||||||
init();
|
init();
|
||||||
|
|
||||||
if (abortRequested()) {
|
if (abortRequested()) {
|
||||||
@@ -421,8 +381,7 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (gvtRoot == null) {
|
if (gvtRoot == null) {
|
||||||
Throwable cause = unwrapException(exception);
|
throw exception;
|
||||||
throw new IIOException(cause.getMessage(), cause);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx = context;
|
ctx = context;
|
||||||
@@ -440,7 +399,7 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
|
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
setImageSize(defaultSize.width, defaultSize.height);
|
setImageSize(defaultWidth, defaultHeight);
|
||||||
|
|
||||||
if (abortRequested()) {
|
if (abortRequested()) {
|
||||||
processReadAborted();
|
processReadAborted();
|
||||||
@@ -454,17 +413,18 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Px = ViewBox.getViewTransform(ref, root, width, height, null);
|
Px = ViewBox.getViewTransform(ref, root, width, height, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (BridgeException ex) {
|
catch (BridgeException ex) {
|
||||||
throw new IIOException(ex.getMessage(), ex);
|
throw new TranscoderException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Px.isIdentity() && (width != defaultSize.width || height != defaultSize.height)) {
|
if (Px.isIdentity() && (width != defaultWidth || height != defaultHeight)) {
|
||||||
// The document has no viewBox, we need to resize it by hand.
|
// The document has no viewBox, we need to resize it by hand.
|
||||||
// we want to keep the document size ratio
|
// we want to keep the document size ratio
|
||||||
float xscale, yscale;
|
float xscale, yscale;
|
||||||
xscale = width / defaultSize.width;
|
xscale = width / defaultWidth;
|
||||||
yscale = height / defaultSize.height;
|
yscale = height / defaultHeight;
|
||||||
float scale = Math.min(xscale, yscale);
|
float scale = Math.min(xscale, yscale);
|
||||||
Px = AffineTransform.getScaleInstance(scale, scale);
|
Px = AffineTransform.getScaleInstance(scale, scale);
|
||||||
}
|
}
|
||||||
@@ -514,7 +474,7 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (BridgeException ex) {
|
catch (BridgeException ex) {
|
||||||
throw new IIOException(ex.getMessage(), ex);
|
throw new TranscoderException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.root = gvtRoot;
|
this.root = gvtRoot;
|
||||||
@@ -583,7 +543,9 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw new IIOException(ex.getMessage(), ex);
|
TranscoderException exception = new TranscoderException(ex.getMessage());
|
||||||
|
exception.initCause(ex);
|
||||||
|
throw exception;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
@@ -592,7 +554,7 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void init() throws IIOException {
|
private synchronized void init() throws TranscoderException {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
if (transcoderInput == null) {
|
if (transcoderInput == null) {
|
||||||
throw new IllegalStateException("input == null");
|
throw new IllegalStateException("input == null");
|
||||||
@@ -600,17 +562,11 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
|
||||||
try {
|
super.transcode(transcoderInput, null);
|
||||||
super.transcode(transcoderInput, null);
|
|
||||||
}
|
|
||||||
catch (TranscoderException e) {
|
|
||||||
Throwable cause = unwrapException(e);
|
|
||||||
throw new IIOException(cause.getMessage(), cause);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private BufferedImage getImage() throws IOException {
|
private BufferedImage getImage() throws TranscoderException {
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
image = readImage();
|
image = readImage();
|
||||||
}
|
}
|
||||||
@@ -618,19 +574,14 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getDefaultWidth() throws IOException {
|
int getDefaultWidth() throws TranscoderException {
|
||||||
init();
|
init();
|
||||||
return defaultSize.width;
|
return (int) Math.ceil(defaultWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getDefaultHeight() throws IOException {
|
int getDefaultHeight() throws TranscoderException {
|
||||||
init();
|
init();
|
||||||
return defaultSize.height;
|
return (int) Math.ceil(defaultHeight);
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle getViewBox() throws IOException {
|
|
||||||
init();
|
|
||||||
return viewBox.getBounds();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setInput(final TranscoderInput pInput) {
|
void setInput(final TranscoderInput pInput) {
|
||||||
@@ -657,14 +608,6 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
public void displayMessage(String message) {
|
public void displayMessage(String message) {
|
||||||
processWarningOccurred(message.replaceAll("[\\r\\n]+", " "));
|
processWarningOccurred(message.replaceAll("[\\r\\n]+", " "));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ExternalResourceSecurity getExternalResourceSecurity(ParsedURL resourceURL, ParsedURL docURL) {
|
|
||||||
if (allowExternalResources) {
|
|
||||||
return super.getExternalResourceSecurity(resourceURL, docURL);
|
|
||||||
}
|
|
||||||
return new EmbededExternalResourceSecurity(resourceURL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-13
@@ -41,11 +41,6 @@ import java.awt.*;
|
|||||||
public class SVGReadParam extends ImageReadParam {
|
public class SVGReadParam extends ImageReadParam {
|
||||||
private Paint background;
|
private Paint background;
|
||||||
private String baseURI;
|
private String baseURI;
|
||||||
private boolean allowExternalResources = SVGImageReader.DEFAULT_ALLOW_EXTERNAL_RESOURCES;
|
|
||||||
|
|
||||||
public SVGReadParam() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Paint getBackgroundColor() {
|
public Paint getBackgroundColor() {
|
||||||
return background;
|
return background;
|
||||||
@@ -63,14 +58,6 @@ public class SVGReadParam extends ImageReadParam {
|
|||||||
baseURI = pBaseURI;
|
baseURI = pBaseURI;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAllowExternalResources(boolean allow) {
|
|
||||||
allowExternalResources = allow;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAllowExternalResources() {
|
|
||||||
return allowExternalResources;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canSetSourceRenderSize() {
|
public boolean canSetSourceRenderSize() {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+141
-143
@@ -1,143 +1,141 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2008, Harald Kuhr
|
* Copyright (c) 2008, Harald Kuhr
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* * Redistributions of source code must retain the above copyright notice, this
|
||||||
* list of conditions and the following disclaimer.
|
* list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
* and/or other materials provided with the distribution.
|
* and/or other materials provided with the distribution.
|
||||||
*
|
*
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* * Neither the name of the copyright holder nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from
|
* contributors may be used to endorse or promote products derived from
|
||||||
* this software without specific prior written permission.
|
* this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
* 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
|
* 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.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.wmf;
|
package com.twelvemonkeys.imageio.plugins.wmf;
|
||||||
|
|
||||||
import com.twelvemonkeys.imageio.ImageReaderBase;
|
import com.twelvemonkeys.imageio.ImageReaderBase;
|
||||||
import com.twelvemonkeys.imageio.plugins.svg.SVGImageReader;
|
import com.twelvemonkeys.imageio.plugins.svg.SVGImageReader;
|
||||||
import com.twelvemonkeys.imageio.plugins.svg.SVGReadParam;
|
import com.twelvemonkeys.imageio.plugins.svg.SVGReadParam;
|
||||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
import com.twelvemonkeys.imageio.util.IIOUtil;
|
||||||
import com.twelvemonkeys.imageio.util.IIOUtil;
|
import org.apache.batik.transcoder.TranscoderException;
|
||||||
|
import org.apache.batik.transcoder.TranscoderInput;
|
||||||
import org.apache.batik.transcoder.TranscoderException;
|
import org.apache.batik.transcoder.TranscoderOutput;
|
||||||
import org.apache.batik.transcoder.TranscoderInput;
|
import org.apache.batik.transcoder.wmf.tosvg.WMFTranscoder;
|
||||||
import org.apache.batik.transcoder.TranscoderOutput;
|
|
||||||
import org.apache.batik.transcoder.wmf.tosvg.WMFTranscoder;
|
import javax.imageio.IIOException;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
import javax.imageio.IIOException;
|
import javax.imageio.ImageReadParam;
|
||||||
import javax.imageio.ImageReadParam;
|
import javax.imageio.ImageTypeSpecifier;
|
||||||
import javax.imageio.ImageTypeSpecifier;
|
import javax.imageio.spi.ImageReaderSpi;
|
||||||
import javax.imageio.spi.ImageReaderSpi;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.image.*;
|
import java.io.*;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.util.Iterator;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStreamWriter;
|
/**
|
||||||
import java.io.Writer;
|
* WMFImageReader class description.
|
||||||
import java.nio.charset.StandardCharsets;
|
*
|
||||||
import java.util.Iterator;
|
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||||
|
* @author last modified by $Author: haku $
|
||||||
/**
|
* @version $Id: WMFImageReader.java,v 1.0 29.jul.2004 13:00:59 haku Exp $
|
||||||
* WMFImageReader class description.
|
*/
|
||||||
*
|
// TODO: Probably possible to do less wrapping/unwrapping of data...
|
||||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
// TODO: Consider using temp file instead of in-memory stream
|
||||||
* @author last modified by $Author: haku $
|
public final class WMFImageReader extends ImageReaderBase {
|
||||||
* @version $Id: WMFImageReader.java,v 1.0 29.jul.2004 13:00:59 haku Exp $
|
|
||||||
*/
|
private SVGImageReader reader = null;
|
||||||
// TODO: Probably possible to do less wrapping/unwrapping of data...
|
|
||||||
public final class WMFImageReader extends ImageReaderBase {
|
public WMFImageReader(final ImageReaderSpi pProvider) {
|
||||||
|
super(pProvider);
|
||||||
private SVGImageReader reader = null;
|
}
|
||||||
|
|
||||||
public WMFImageReader(final ImageReaderSpi pProvider) {
|
protected void resetMembers() {
|
||||||
super(pProvider);
|
if (reader != null) {
|
||||||
}
|
reader.dispose();
|
||||||
|
}
|
||||||
protected void resetMembers() {
|
|
||||||
if (reader != null) {
|
reader = null;
|
||||||
reader.dispose();
|
}
|
||||||
}
|
|
||||||
|
public BufferedImage read(int pIndex, ImageReadParam pParam) throws IOException {
|
||||||
reader = null;
|
init();
|
||||||
}
|
|
||||||
|
processImageStarted(pIndex);
|
||||||
public BufferedImage read(int pIndex, ImageReadParam pParam) throws IOException {
|
|
||||||
init();
|
BufferedImage image = reader.read(pIndex, pParam);
|
||||||
|
if (abortRequested()) {
|
||||||
processImageStarted(pIndex);
|
processReadAborted();
|
||||||
|
return image;
|
||||||
BufferedImage image = reader.read(pIndex, pParam);
|
}
|
||||||
if (abortRequested()) {
|
processImageProgress(100f);
|
||||||
processReadAborted();
|
|
||||||
return image;
|
processImageComplete();
|
||||||
}
|
|
||||||
processImageProgress(100f);
|
return image;
|
||||||
|
}
|
||||||
processImageComplete();
|
|
||||||
|
private synchronized void init() throws IOException {
|
||||||
return image;
|
// Need the extra test, to avoid throwing an IOException from the Transcoder
|
||||||
}
|
if (imageInput == null) {
|
||||||
|
throw new IllegalStateException("input == null");
|
||||||
private void init() throws IOException {
|
}
|
||||||
// Need the extra test, to avoid throwing an IOException from the Transcoder
|
|
||||||
if (imageInput == null) {
|
if (reader == null) {
|
||||||
throw new IllegalStateException("input == null");
|
WMFTranscoder transcoder = new WMFTranscoder();
|
||||||
}
|
|
||||||
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||||
if (reader == null) {
|
Writer writer = new OutputStreamWriter(output, "UTF8");
|
||||||
WMFTranscoder transcoder = new WMFTranscoder();
|
try {
|
||||||
ByteArrayOutputStream output = new ByteArrayOutputStream(8192);
|
TranscoderInput in = new TranscoderInput(IIOUtil.createStreamAdapter(imageInput));
|
||||||
|
TranscoderOutput out = new TranscoderOutput(writer);
|
||||||
try (Writer writer = new OutputStreamWriter(output, StandardCharsets.UTF_8)) {
|
|
||||||
TranscoderInput in = new TranscoderInput(IIOUtil.createStreamAdapter(imageInput));
|
// TODO: Transcodinghints?
|
||||||
TranscoderOutput out = new TranscoderOutput(writer);
|
|
||||||
|
transcoder.transcode(in, out);
|
||||||
// TODO: Transcodinghints?
|
}
|
||||||
|
catch (TranscoderException e) {
|
||||||
transcoder.transcode(in, out);
|
throw new IIOException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
catch (TranscoderException e) {
|
|
||||||
throw new IIOException(e.getMessage(), e);
|
reader = new SVGImageReader(getOriginatingProvider());
|
||||||
}
|
reader.setInput(ImageIO.createImageInputStream(new ByteArrayInputStream(output.toByteArray())));
|
||||||
|
}
|
||||||
reader = new SVGImageReader(getOriginatingProvider());
|
}
|
||||||
reader.setInput(new ByteArrayImageInputStream(output.toByteArray()));
|
|
||||||
}
|
@Override
|
||||||
}
|
public ImageReadParam getDefaultReadParam() {
|
||||||
|
return new SVGReadParam();
|
||||||
@Override
|
}
|
||||||
public ImageReadParam getDefaultReadParam() {
|
|
||||||
return new SVGReadParam();
|
public int getWidth(int pIndex) throws IOException {
|
||||||
}
|
init();
|
||||||
|
return reader.getWidth(pIndex);
|
||||||
public int getWidth(int pIndex) throws IOException {
|
}
|
||||||
init();
|
|
||||||
return reader.getWidth(pIndex);
|
public int getHeight(int pIndex) throws IOException {
|
||||||
}
|
init();
|
||||||
|
return reader.getHeight(pIndex);
|
||||||
public int getHeight(int pIndex) throws IOException {
|
}
|
||||||
init();
|
|
||||||
return reader.getHeight(pIndex);
|
public Iterator<ImageTypeSpecifier> getImageTypes(final int pImageIndex) throws IOException {
|
||||||
}
|
init();
|
||||||
|
return reader.getImageTypes(pImageIndex);
|
||||||
public Iterator<ImageTypeSpecifier> getImageTypes(final int pImageIndex) throws IOException {
|
}
|
||||||
init();
|
|
||||||
return reader.getImageTypes(pImageIndex);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+36
-138
@@ -31,7 +31,6 @@
|
|||||||
package com.twelvemonkeys.imageio.plugins.svg;
|
package com.twelvemonkeys.imageio.plugins.svg;
|
||||||
|
|
||||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -43,19 +42,21 @@ import javax.imageio.event.IIOReadWarningListener;
|
|||||||
import javax.imageio.spi.ImageReaderSpi;
|
import javax.imageio.spi.ImageReaderSpi;
|
||||||
import javax.imageio.stream.ImageInputStream;
|
import javax.imageio.stream.ImageInputStream;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.*;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.awt.image.ImagingOpException;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.Buffer;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.mockito.Matchers.anyString;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,25 +67,30 @@ import static org.mockito.Mockito.*;
|
|||||||
* @version $Id: SVGImageReaderTest.java,v 1.0 Apr 1, 2008 10:39:17 PM haraldk Exp$
|
* @version $Id: SVGImageReaderTest.java,v 1.0 Apr 1, 2008 10:39:17 PM haraldk Exp$
|
||||||
*/
|
*/
|
||||||
public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader> {
|
public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader> {
|
||||||
|
private SVGImageReaderSpi provider = new SVGImageReaderSpi();
|
||||||
@Override
|
|
||||||
protected ImageReaderSpi createProvider() {
|
|
||||||
return new SVGImageReaderSpi();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<TestData> getTestData() {
|
protected List<TestData> getTestData() {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
new TestData(getClassLoaderResource("/svg/batikLogo.svg"), new Dimension(450, 500)),
|
new TestData(getClassLoaderResource("/svg/batikLogo.svg"), new Dimension(450, 500)),
|
||||||
new TestData(getClassLoaderResource("/svg/red-square.svg"), new Dimension(100, 100)),
|
new TestData(getClassLoaderResource("/svg/red-square.svg"), new Dimension(100, 100)),
|
||||||
new TestData(getClassLoaderResource("/svg/blue-square.svg"), new Dimension(100, 100)),
|
new TestData(getClassLoaderResource("/svg/blue-square.svg"), new Dimension(100, 100)),
|
||||||
new TestData(getClassLoaderResource("/svg/Android_robot.svg"), new Dimension(294, 345)),
|
new TestData(getClassLoaderResource("/svg/Android_robot.svg"), new Dimension(294, 345))
|
||||||
new TestData(getClassLoaderResource("/svg/sizes/w50h50.svg"), new Dimension(50, 50)),
|
|
||||||
new TestData(getClassLoaderResource("/svg/sizes/w50_1to2.svg"), new Dimension(25, 50)),
|
|
||||||
new TestData(getClassLoaderResource("/svg/sizes/h50_1to2.svg"), new Dimension(50, 100)),
|
|
||||||
new TestData(getClassLoaderResource("/svg/sizes/w50noview.svg"), new Dimension(50, 50))
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected ImageReaderSpi createProvider() {
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SVGImageReader createReader() {
|
||||||
|
return new SVGImageReader(createProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Class<SVGImageReader> getReaderClass() {
|
||||||
|
return SVGImageReader.class;
|
||||||
|
}
|
||||||
|
|
||||||
protected List<String> getFormatNames() {
|
protected List<String> getFormatNames() {
|
||||||
return Collections.singletonList("svg");
|
return Collections.singletonList("svg");
|
||||||
}
|
}
|
||||||
@@ -101,6 +107,8 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
|||||||
public void testScaleViewBox() throws IOException {
|
public void testScaleViewBox() throws IOException {
|
||||||
URL svgUrl = getClassLoaderResource("/svg/quadrants.svg");
|
URL svgUrl = getClassLoaderResource("/svg/quadrants.svg");
|
||||||
|
|
||||||
|
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
|
||||||
|
|
||||||
SVGImageReader reader = createReader();
|
SVGImageReader reader = createReader();
|
||||||
SVGReadParam param = new SVGReadParam();
|
SVGReadParam param = new SVGReadParam();
|
||||||
|
|
||||||
@@ -148,11 +156,11 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testReadWithSizeParam() throws IOException {
|
public void testReadWithSizeParam() {
|
||||||
try {
|
try {
|
||||||
super.testReadWithSizeParam();
|
super.testReadWithSizeParam();
|
||||||
}
|
}
|
||||||
catch (AssertionError | IOException failure) {
|
catch (AssertionError failure) {
|
||||||
Throwable cause = failure;
|
Throwable cause = failure;
|
||||||
|
|
||||||
while (cause.getCause() != null) {
|
while (cause.getCause() != null) {
|
||||||
@@ -194,12 +202,12 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
|||||||
TestData redSquare = new TestData(getClassLoaderResource("/svg/red-square.svg"), dim);
|
TestData redSquare = new TestData(getClassLoaderResource("/svg/red-square.svg"), dim);
|
||||||
reader.setInput(redSquare.getInputStream());
|
reader.setInput(redSquare.getInputStream());
|
||||||
BufferedImage imageRed = reader.read(0, param);
|
BufferedImage imageRed = reader.read(0, param);
|
||||||
assertRGBEquals("Expected all red", 0xFF0000, imageRed.getRGB(50, 50) & 0xFFFFFF, 0);
|
assertEquals(0xFF0000, imageRed.getRGB(50, 50) & 0xFFFFFF);
|
||||||
|
|
||||||
TestData blueSquare = new TestData(getClassLoaderResource("/svg/blue-square.svg"), dim);
|
TestData blueSquare = new TestData(getClassLoaderResource("/svg/blue-square.svg"), dim);
|
||||||
reader.setInput(blueSquare.getInputStream());
|
reader.setInput(blueSquare.getInputStream());
|
||||||
BufferedImage imageBlue = reader.read(0, param);
|
BufferedImage imageBlue = reader.read(0, param);
|
||||||
assertRGBEquals("Expected all blue", 0x0000FF, imageBlue.getRGB(50, 50) & 0xFFFFFF, 0);
|
assertEquals(0x0000FF, imageBlue.getRGB(50, 50) & 0xFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -216,7 +224,6 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
|||||||
reader.addIIOReadWarningListener(listener);
|
reader.addIIOReadWarningListener(listener);
|
||||||
|
|
||||||
SVGReadParam param = reader.getDefaultReadParam();
|
SVGReadParam param = reader.getDefaultReadParam();
|
||||||
param.setAllowExternalResources(true);
|
|
||||||
param.setBaseURI(resource.toURI().toASCIIString());
|
param.setBaseURI(resource.toURI().toASCIIString());
|
||||||
BufferedImage image = reader.read(0, param);
|
BufferedImage image = reader.read(0, param);
|
||||||
|
|
||||||
@@ -225,7 +232,7 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
|||||||
assertEquals(500, image.getHeight());
|
assertEquals(500, image.getHeight());
|
||||||
|
|
||||||
// CSS and embedded resources all go!
|
// CSS and embedded resources all go!
|
||||||
verifyNoInteractions(listener);
|
verifyZeroInteractions(listener);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
reader.dispose();
|
reader.dispose();
|
||||||
@@ -237,8 +244,6 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
|||||||
// Asking for metadata, width, height etc, before attempting to read using a param,
|
// Asking for metadata, width, height etc, before attempting to read using a param,
|
||||||
// will cause the document to be parsed without a base URI.
|
// will cause the document to be parsed without a base URI.
|
||||||
// This will work, but may not use the CSS...
|
// This will work, but may not use the CSS...
|
||||||
// since the param is not available before the read operation is invoked,
|
|
||||||
// this test-case MUST use the system-property for backwards compatibility
|
|
||||||
URL resource = getClassLoaderResource("/svg/barChart.svg");
|
URL resource = getClassLoaderResource("/svg/barChart.svg");
|
||||||
|
|
||||||
SVGImageReader reader = createReader();
|
SVGImageReader reader = createReader();
|
||||||
@@ -266,7 +271,7 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
|||||||
assertEquals(500, image.getHeight());
|
assertEquals(500, image.getHeight());
|
||||||
|
|
||||||
// No more warnings now that the base URI is set
|
// No more warnings now that the base URI is set
|
||||||
verifyNoInteractions(listener);
|
verifyZeroInteractions(listener);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
reader.dispose();
|
reader.dispose();
|
||||||
@@ -277,17 +282,18 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
|||||||
public void testEmbeddedNoBaseURI() throws IOException {
|
public void testEmbeddedNoBaseURI() throws IOException {
|
||||||
// With no base URI, we will throw an exception, about the missing embedded resource
|
// With no base URI, we will throw an exception, about the missing embedded resource
|
||||||
URL resource = getClassLoaderResource("/svg/barChart.svg");
|
URL resource = getClassLoaderResource("/svg/barChart.svg");
|
||||||
|
|
||||||
SVGImageReader reader = createReader();
|
SVGImageReader reader = createReader();
|
||||||
|
|
||||||
TestData data = new TestData(resource, (Dimension) null);
|
TestData data = new TestData(resource, (Dimension) null);
|
||||||
try (ImageInputStream stream = data.getInputStream()) {
|
try (ImageInputStream stream = data.getInputStream()) {
|
||||||
reader.setInput(stream);
|
reader.setInput(stream);
|
||||||
|
|
||||||
SVGReadParam params = reader.getDefaultReadParam();
|
BufferedImage image = reader.read(0);
|
||||||
params.setAllowExternalResources(true);
|
|
||||||
reader.read(0, params);
|
|
||||||
|
|
||||||
fail("reader.read should've thrown an exception, but didn't");
|
assertNotNull(image);
|
||||||
|
assertEquals(450, image.getWidth());
|
||||||
|
assertEquals(500, image.getHeight());
|
||||||
}
|
}
|
||||||
catch (IIOException allowed) {
|
catch (IIOException allowed) {
|
||||||
assertTrue(allowed.getMessage().contains("batikLogo.svg")); // The embedded resource we don't find
|
assertTrue(allowed.getMessage().contains("batikLogo.svg")); // The embedded resource we don't find
|
||||||
@@ -296,112 +302,4 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
|||||||
reader.dispose();
|
reader.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Test
|
|
||||||
public void testReadEmbeddedWithDisallowExternalResources() throws IOException{
|
|
||||||
// File using "data:" URLs for embedded resources
|
|
||||||
URL resource = getClassLoaderResource("/svg/embedded-data-resource.svg");
|
|
||||||
SVGImageReader reader = createReader();
|
|
||||||
|
|
||||||
TestData data = new TestData(resource, (Dimension) null);
|
|
||||||
try (ImageInputStream stream = data.getInputStream()) {
|
|
||||||
reader.setInput(stream);
|
|
||||||
|
|
||||||
SVGReadParam param = reader.getDefaultReadParam();
|
|
||||||
param.setAllowExternalResources(false);
|
|
||||||
reader.read(0, param);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
reader.dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = SecurityException.class)
|
|
||||||
public void testDisallowedExternalResources() throws URISyntaxException, IOException {
|
|
||||||
// system-property set to true in surefire-plugin-settings in the pom
|
|
||||||
URL resource = getClassLoaderResource("/svg/barChart.svg");
|
|
||||||
SVGImageReader reader = createReader();
|
|
||||||
|
|
||||||
TestData data = new TestData(resource, (Dimension) null);
|
|
||||||
try (ImageInputStream stream = data.getInputStream()) {
|
|
||||||
reader.setInput(stream);
|
|
||||||
|
|
||||||
SVGReadParam param = reader.getDefaultReadParam();
|
|
||||||
param.setBaseURI(resource.toURI().toASCIIString());
|
|
||||||
param.setAllowExternalResources(false);
|
|
||||||
// even when the system-property is set to true,
|
|
||||||
// `reader.read` for `/svg/barChart.svg` should raise
|
|
||||||
// a SecurityException when External Resources are blocked
|
|
||||||
// because the API invocation gets preference
|
|
||||||
reader.read(0, param);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
reader.dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testReadWitSourceRenderSize() throws IOException {
|
|
||||||
URL resource = getClassLoaderResource("/svg/circle.svg");
|
|
||||||
|
|
||||||
SVGImageReader reader = createReader();
|
|
||||||
|
|
||||||
TestData data = new TestData(resource, (Dimension) null);
|
|
||||||
try (ImageInputStream stream = data.getInputStream()) {
|
|
||||||
reader.setInput(stream);
|
|
||||||
|
|
||||||
SVGReadParam param = reader.getDefaultReadParam();
|
|
||||||
param.setSourceRenderSize(new Dimension(100, 100));
|
|
||||||
BufferedImage image = reader.read(0, param);
|
|
||||||
|
|
||||||
assertNotNull(image);
|
|
||||||
assertEquals(100, image.getWidth());
|
|
||||||
assertEquals(100, image.getHeight());
|
|
||||||
|
|
||||||
// Some quick samples
|
|
||||||
assertRGBEquals("Expected transparent corner", 0, image.getRGB(0, 0), 0);
|
|
||||||
assertRGBEquals("Expected transparent corner", 0, image.getRGB(99, 0), 0);
|
|
||||||
assertRGBEquals("Expected transparent corner", 0, image.getRGB(0, 99), 0);
|
|
||||||
assertRGBEquals("Expected transparent corner", 0, image.getRGB(99, 99), 0);
|
|
||||||
assertRGBEquals("Expected red center", 0xffff0000, image.getRGB(50, 50), 0);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
reader.dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testReadWitSourceRenderSizeViewBoxNegativeXY() throws IOException {
|
|
||||||
URL resource = getClassLoaderResource("/svg/Android_robot.svg");
|
|
||||||
|
|
||||||
SVGImageReader reader = createReader();
|
|
||||||
|
|
||||||
TestData data = new TestData(resource, (Dimension) null);
|
|
||||||
try (ImageInputStream stream = data.getInputStream()) {
|
|
||||||
reader.setInput(stream);
|
|
||||||
|
|
||||||
SVGReadParam param = reader.getDefaultReadParam();
|
|
||||||
param.setSourceRenderSize(new Dimension(219, 256)); // Aspect scaled to 256 boxed
|
|
||||||
BufferedImage image = reader.read(0, param);
|
|
||||||
|
|
||||||
assertNotNull(image);
|
|
||||||
assertEquals(219, image.getWidth());
|
|
||||||
assertEquals(256, image.getHeight());
|
|
||||||
|
|
||||||
// Some quick samples
|
|
||||||
assertRGBEquals("Expected transparent corner", 0, image.getRGB(0, 0), 0);
|
|
||||||
assertRGBEquals("Expected transparent corner", 0, image.getRGB(218, 0), 0);
|
|
||||||
assertRGBEquals("Expected transparent corner", 0, image.getRGB(0, 255), 0);
|
|
||||||
assertRGBEquals("Expected transparent corner", 0, image.getRGB(218, 255), 0);
|
|
||||||
assertRGBEquals("Expected green head", 0xffa4c639, image.getRGB(109, 20), 25);
|
|
||||||
assertRGBEquals("Expected green center", 0xffa4c639, image.getRGB(109, 128), 25);
|
|
||||||
assertRGBEquals("Expected green feet", 0xffa4c639, image.getRGB(80, 246), 25);
|
|
||||||
assertRGBEquals("Expected green feet", 0xffa4c639, image.getRGB(130, 246), 25);
|
|
||||||
assertRGBEquals("Expected white edge", 0xffffffff, image.getRGB(0, 128), 0);
|
|
||||||
assertRGBEquals("Expected white edge", 0xffffffff, image.getRGB(218, 128), 0);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
reader.dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+13
-7
@@ -31,7 +31,6 @@
|
|||||||
package com.twelvemonkeys.imageio.plugins.wmf;
|
package com.twelvemonkeys.imageio.plugins.wmf;
|
||||||
|
|
||||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -50,10 +49,7 @@ import java.util.List;
|
|||||||
* @version $Id: WMFImageReaderTest.java,v 1.0 Apr 1, 2008 10:39:17 PM haraldk Exp$
|
* @version $Id: WMFImageReaderTest.java,v 1.0 Apr 1, 2008 10:39:17 PM haraldk Exp$
|
||||||
*/
|
*/
|
||||||
public class WMFImageReaderTest extends ImageReaderAbstractTest<WMFImageReader> {
|
public class WMFImageReaderTest extends ImageReaderAbstractTest<WMFImageReader> {
|
||||||
@Override
|
private WMFImageReaderSpi provider = new WMFImageReaderSpi();
|
||||||
protected ImageReaderSpi createProvider() {
|
|
||||||
return new WMFImageReaderSpi();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<TestData> getTestData() {
|
protected List<TestData> getTestData() {
|
||||||
return Collections.singletonList(
|
return Collections.singletonList(
|
||||||
@@ -61,17 +57,27 @@ public class WMFImageReaderTest extends ImageReaderAbstractTest<WMFImageReader>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected ImageReaderSpi createProvider() {
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
protected WMFImageReader createReader() {
|
||||||
|
return new WMFImageReader(createProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Class<WMFImageReader> getReaderClass() {
|
||||||
|
return WMFImageReader.class;
|
||||||
|
}
|
||||||
|
|
||||||
protected List<String> getFormatNames() {
|
protected List<String> getFormatNames() {
|
||||||
return Collections.singletonList("wmf");
|
return Collections.singletonList("wmf");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<String> getSuffixes() {
|
protected List<String> getSuffixes() {
|
||||||
return Arrays.asList("wmf", "emf");
|
return Arrays.asList("wmf", "emf");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<String> getMIMETypes() {
|
protected List<String> getMIMETypes() {
|
||||||
return Arrays.asList("image/x-wmf", "application/x-msmetafile");
|
return Arrays.asList("image/x-wmf", "application/x-msmetafile");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
|
||||||
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
||||||
<svg width="100%" height="100%" viewBox="0 0 50 50" version="1.1" xmlns="http://www.w3.org/2000/svg"
|
|
||||||
xml:space="preserve"
|
|
||||||
style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2">
|
|
||||||
<circle cx="25" cy="25" r="25" fill="red"/></svg>
|
|
||||||
|
Before Width: | Height: | Size: 436 B |
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 92 KiB |
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="50" viewBox="0 0 100 200" version="1.1">
|
|
||||||
<g id="layer1">
|
|
||||||
<rect id="rect2985" width="50" height="50" x="0" y="0"
|
|
||||||
style="color:#000000;fill:#0000ff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 427 B |
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" height="50" viewBox="0 0 100 200" version="1.1">
|
|
||||||
<g id="layer1">
|
|
||||||
<rect id="rect2985" width="50" height="50" x="0" y="0"
|
|
||||||
style="color:#000000;fill:#0000ff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 428 B |
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 100 200" version="1.1">
|
|
||||||
<g id="layer1">
|
|
||||||
<rect id="rect2985" width="50" height="50" x="0" y="0"
|
|
||||||
style="color:#000000;fill:#0000ff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 439 B |
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="50" version="1.1">
|
|
||||||
<g id="layer1">
|
|
||||||
<rect id="rect2985" width="50" height="50" x="0" y="0"
|
|
||||||
style="color:#000000;fill:#0000ff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 405 B |
@@ -4,16 +4,12 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||||
<artifactId>imageio</artifactId>
|
<artifactId>imageio</artifactId>
|
||||||
<version>3.8.4-SNAPSHOT</version>
|
<version>3.4.4-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>imageio-bmp</artifactId>
|
<artifactId>imageio-bmp</artifactId>
|
||||||
<name>TwelveMonkeys :: ImageIO :: BMP plugin</name>
|
<name>TwelveMonkeys :: ImageIO :: BMP plugin</name>
|
||||||
<description>ImageIO plugin for Microsoft Device Independent Bitmap (BMP/DIB) format.</description>
|
<description>ImageIO plugin for Microsoft Device Independent Bitmap (BMP/DIB) format.</description>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<project.jpms.module.name>com.twelvemonkeys.imageio.bmp</project.jpms.module.name>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||||
@@ -23,7 +19,6 @@
|
|||||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||||
<artifactId>imageio-core</artifactId>
|
<artifactId>imageio-core</artifactId>
|
||||||
<type>test-jar</type>
|
<type>test-jar</type>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
+19
-21
@@ -4,28 +4,26 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|||||||
+102
-116
@@ -4,28 +4,26 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
@@ -39,11 +37,7 @@ import com.twelvemonkeys.io.LittleEndianDataInputStream;
|
|||||||
import com.twelvemonkeys.io.enc.DecoderStream;
|
import com.twelvemonkeys.io.enc.DecoderStream;
|
||||||
import com.twelvemonkeys.xml.XMLSerializer;
|
import com.twelvemonkeys.xml.XMLSerializer;
|
||||||
|
|
||||||
import javax.imageio.IIOException;
|
import javax.imageio.*;
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import javax.imageio.ImageReadParam;
|
|
||||||
import javax.imageio.ImageReader;
|
|
||||||
import javax.imageio.ImageTypeSpecifier;
|
|
||||||
import javax.imageio.event.IIOReadUpdateListener;
|
import javax.imageio.event.IIOReadUpdateListener;
|
||||||
import javax.imageio.event.IIOReadWarningListener;
|
import javax.imageio.event.IIOReadWarningListener;
|
||||||
import javax.imageio.metadata.IIOMetadata;
|
import javax.imageio.metadata.IIOMetadata;
|
||||||
@@ -51,13 +45,13 @@ import javax.imageio.metadata.IIOMetadataFormatImpl;
|
|||||||
import javax.imageio.spi.ImageReaderSpi;
|
import javax.imageio.spi.ImageReaderSpi;
|
||||||
import javax.imageio.stream.ImageInputStream;
|
import javax.imageio.stream.ImageInputStream;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.color.*;
|
import java.awt.color.ColorSpace;
|
||||||
import java.awt.image.*;
|
import java.awt.image.*;
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.util.Collections;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,8 +59,8 @@ import java.util.Iterator;
|
|||||||
*
|
*
|
||||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||||
* @author last modified by $Author: haraldk$
|
* @author last modified by $Author: haraldk$
|
||||||
* @version $Id: BMPImageReader.java,v 1.0 Apr 20, 2009 11:54:28 AM haraldk Exp$
|
* @version $Id: CURImageReader.java,v 1.0 Apr 20, 2009 11:54:28 AM haraldk Exp$
|
||||||
* @see ICOImageReader
|
* @see com.twelvemonkeys.imageio.plugins.bmp.ICOImageReader
|
||||||
*/
|
*/
|
||||||
public final class BMPImageReader extends ImageReaderBase {
|
public final class BMPImageReader extends ImageReaderBase {
|
||||||
private long pixelOffset;
|
private long pixelOffset;
|
||||||
@@ -81,7 +75,7 @@ public final class BMPImageReader extends ImageReaderBase {
|
|||||||
super(new BMPImageReaderSpi());
|
super(new BMPImageReaderSpi());
|
||||||
}
|
}
|
||||||
|
|
||||||
BMPImageReader(final ImageReaderSpi pProvider) {
|
protected BMPImageReader(final ImageReaderSpi pProvider) {
|
||||||
super(pProvider);
|
super(pProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,10 +123,6 @@ public final class BMPImageReader extends ImageReaderBase {
|
|||||||
|
|
||||||
// Read DIB header
|
// Read DIB header
|
||||||
header = DIBHeader.read(imageInput);
|
header = DIBHeader.read(imageInput);
|
||||||
|
|
||||||
if (pixelOffset < header.size + DIB.BMP_FILE_HEADER_SIZE) {
|
|
||||||
throw new IIOException("Invalid pixel offset: " + pixelOffset);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +194,7 @@ public final class BMPImageReader extends ImageReaderBase {
|
|||||||
checkBounds(pImageIndex);
|
checkBounds(pImageIndex);
|
||||||
|
|
||||||
// TODO: Better implementation, include INT_RGB types for 3BYTE_BGR and 4BYTE_ABGR for INT_ARGB
|
// TODO: Better implementation, include INT_RGB types for 3BYTE_BGR and 4BYTE_ABGR for INT_ARGB
|
||||||
return Collections.singletonList(getRawImageType(pImageIndex)).iterator();
|
return Arrays.asList(getRawImageType(pImageIndex)).iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -215,55 +205,50 @@ public final class BMPImageReader extends ImageReaderBase {
|
|||||||
throw new IIOException("Multiple planes not supported");
|
throw new IIOException("Multiple planes not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
switch (header.getBitCount()) {
|
||||||
switch (header.getBitCount()) {
|
case 1:
|
||||||
case 1:
|
case 2:
|
||||||
case 2:
|
case 4:
|
||||||
case 4:
|
case 8:
|
||||||
case 8:
|
return ImageTypeSpecifiers.createFromIndexColorModel(readColorMap());
|
||||||
return ImageTypeSpecifiers.createFromIndexColorModel(readColorMap());
|
|
||||||
|
|
||||||
case 16:
|
case 16:
|
||||||
if (header.hasMasks()) {
|
if (header.hasMasks()) {
|
||||||
return ImageTypeSpecifiers.createPacked(
|
return ImageTypeSpecifiers.createPacked(
|
||||||
ColorSpace.getInstance(ColorSpace.CS_sRGB),
|
ColorSpace.getInstance(ColorSpace.CS_sRGB),
|
||||||
header.masks[0], header.masks[1], header.masks[2], header.masks[3],
|
header.masks[0], header.masks[1], header.masks[2], header.masks[3],
|
||||||
DataBuffer.TYPE_USHORT, false
|
DataBuffer.TYPE_USHORT, false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default if no mask is 555
|
// Default if no mask is 555
|
||||||
return ImageTypeSpecifiers.createFromBufferedImageType(BufferedImage.TYPE_USHORT_555_RGB);
|
return ImageTypeSpecifiers.createFromBufferedImageType(BufferedImage.TYPE_USHORT_555_RGB);
|
||||||
|
|
||||||
case 24:
|
case 24:
|
||||||
if (header.getCompression() != DIB.COMPRESSION_RGB) {
|
if (header.getCompression() != DIB.COMPRESSION_RGB) {
|
||||||
throw new IIOException("Unsupported compression for RGB: " + header.getCompression());
|
throw new IIOException("Unsupported compression for RGB: " + header.getCompression());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ImageTypeSpecifiers.createFromBufferedImageType(BufferedImage.TYPE_3BYTE_BGR);
|
return ImageTypeSpecifiers.createFromBufferedImageType(BufferedImage.TYPE_3BYTE_BGR);
|
||||||
|
|
||||||
case 32:
|
case 32:
|
||||||
if (header.hasMasks()) {
|
if (header.hasMasks()) {
|
||||||
return ImageTypeSpecifiers.createPacked(
|
return ImageTypeSpecifiers.createPacked(
|
||||||
ColorSpace.getInstance(ColorSpace.CS_sRGB),
|
ColorSpace.getInstance(ColorSpace.CS_sRGB),
|
||||||
header.masks[0], header.masks[1], header.masks[2], header.masks[3],
|
header.masks[0], header.masks[1], header.masks[2], header.masks[3],
|
||||||
DataBuffer.TYPE_INT, false
|
DataBuffer.TYPE_INT, false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default if no mask
|
// Default if no mask
|
||||||
return ImageTypeSpecifiers.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
|
return ImageTypeSpecifiers.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
if (header.getCompression() == DIB.COMPRESSION_JPEG || header.getCompression() == DIB.COMPRESSION_PNG) {
|
if (header.getCompression() == DIB.COMPRESSION_JPEG || header.getCompression() == DIB.COMPRESSION_PNG) {
|
||||||
return initReaderDelegate(header.getCompression()).getRawImageType(0);
|
return initReaderDelegate(header.getCompression()).getRawImageType(0);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
throw new IIOException("Unsupported bit count: " + header.getBitCount());
|
throw new IIOException("Unsupported bit count: " + header.getBitCount());
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException e) {
|
|
||||||
throw new IIOException(e.getMessage(), e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,18 +347,14 @@ public final class BMPImageReader extends ImageReaderBase {
|
|||||||
|
|
||||||
processImageStarted(imageIndex);
|
processImageStarted(imageIndex);
|
||||||
for (int y = 0; y < height; y++) {
|
for (int y = 0; y < height; y++) {
|
||||||
int bitCount = header.getBitCount();
|
switch (header.getBitCount()) {
|
||||||
switch (bitCount) {
|
|
||||||
case 1:
|
case 1:
|
||||||
case 2:
|
case 2:
|
||||||
case 4:
|
case 4:
|
||||||
case 8:
|
case 8:
|
||||||
case 24:
|
case 24:
|
||||||
byte[] rowDataByte = ((DataBufferByte) rowRaster.getDataBuffer()).getData();
|
byte[] rowDataByte = ((DataBufferByte) rowRaster.getDataBuffer()).getData();
|
||||||
int bitsPerSample = bitCount == 24 ? 8 : bitCount;
|
readRowByte(input, height, srcRegion, xSub, ySub, rowDataByte, destRaster, clippedRow, y);
|
||||||
int samplesPerPixel = bitCount == 24 ? 3 : 1;
|
|
||||||
|
|
||||||
readRowByte(input, height, srcRegion, xSub, ySub, bitsPerSample, samplesPerPixel, rowDataByte, destRaster, clippedRow, y);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 16:
|
case 16:
|
||||||
@@ -387,7 +368,7 @@ public final class BMPImageReader extends ImageReaderBase {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new AssertionError("Unsupported pixel depth: " + bitCount);
|
throw new AssertionError("Unsupported pixel depth: " + header.getBitCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
processImageProgress(100f * y / height);
|
processImageProgress(100f * y / height);
|
||||||
@@ -413,13 +394,6 @@ public final class BMPImageReader extends ImageReaderBase {
|
|||||||
|
|
||||||
private ImageReader initReaderDelegate(int compression) throws IOException {
|
private ImageReader initReaderDelegate(int compression) throws IOException {
|
||||||
ImageReader reader = getImageReaderDelegate(compression);
|
ImageReader reader = getImageReaderDelegate(compression);
|
||||||
reader.reset();
|
|
||||||
|
|
||||||
// Install listener
|
|
||||||
ListenerDelegator listenerDelegator = new ListenerDelegator();
|
|
||||||
reader.addIIOReadWarningListener(listenerDelegator);
|
|
||||||
reader.addIIOReadProgressListener(listenerDelegator);
|
|
||||||
reader.addIIOReadUpdateListener(listenerDelegator);
|
|
||||||
|
|
||||||
imageInput.seek(pixelOffset);
|
imageInput.seek(pixelOffset);
|
||||||
reader.setInput(new SubImageInputStream(imageInput, header.getImageSize()));
|
reader.setInput(new SubImageInputStream(imageInput, header.getImageSize()));
|
||||||
@@ -460,6 +434,12 @@ public final class BMPImageReader extends ImageReaderBase {
|
|||||||
|
|
||||||
ImageReader reader = readers.next();
|
ImageReader reader = readers.next();
|
||||||
|
|
||||||
|
// Install listener
|
||||||
|
ListenerDelegator listenerDelegator = new ListenerDelegator();
|
||||||
|
reader.addIIOReadWarningListener(listenerDelegator);
|
||||||
|
reader.addIIOReadProgressListener(listenerDelegator);
|
||||||
|
reader.addIIOReadUpdateListener(listenerDelegator);
|
||||||
|
|
||||||
// Cache for later use
|
// Cache for later use
|
||||||
switch (compression) {
|
switch (compression) {
|
||||||
case DIB.COMPRESSION_JPEG:
|
case DIB.COMPRESSION_JPEG:
|
||||||
@@ -484,14 +464,9 @@ public final class BMPImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void readRowByte(final DataInput input, final int height, final Rectangle srcRegion, final int xSub, final int ySub,
|
private void readRowByte(final DataInput input, final int height, final Rectangle srcRegion, final int xSub, final int ySub,
|
||||||
int bitsPerSample, int samplesPerPixel,
|
|
||||||
final byte[] rowDataByte, final WritableRaster destChannel, final Raster srcChannel, final int y) throws IOException {
|
final byte[] rowDataByte, final WritableRaster destChannel, final Raster srcChannel, final int y) throws IOException {
|
||||||
// Flip into position?
|
|
||||||
int srcY = !header.topDown ? height - 1 - y : y;
|
|
||||||
int dstY = (srcY - srcRegion.y) / ySub;
|
|
||||||
|
|
||||||
// If subsampled or outside source region, skip entire row
|
// If subsampled or outside source region, skip entire row
|
||||||
if (srcY % ySub != 0 || srcY < srcRegion.y || srcY >= srcRegion.y + srcRegion.height) {
|
if (y % ySub != 0 || height - 1 - y < srcRegion.y || height - 1 - y >= srcRegion.y + srcRegion.height) {
|
||||||
input.skipBytes(rowDataByte.length);
|
input.skipBytes(rowDataByte.length);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -501,20 +476,24 @@ public final class BMPImageReader extends ImageReaderBase {
|
|||||||
|
|
||||||
// Subsample horizontal
|
// Subsample horizontal
|
||||||
if (xSub != 1) {
|
if (xSub != 1) {
|
||||||
IIOUtil.subsampleRow(rowDataByte, srcRegion.x, srcRegion.width, rowDataByte, 0, samplesPerPixel, bitsPerSample, xSub);
|
for (int x = 0; x < srcRegion.width / xSub; x++) {
|
||||||
|
rowDataByte[srcRegion.x + x] = rowDataByte[srcRegion.x + x * xSub];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
destChannel.setDataElements(0, dstY, srcChannel);
|
if (header.topDown) {
|
||||||
|
destChannel.setDataElements(0, y, srcChannel);
|
||||||
|
} else {
|
||||||
|
// Flip into position
|
||||||
|
int dstY = (height - 1 - y - srcRegion.y) / ySub;
|
||||||
|
destChannel.setDataElements(0, dstY, srcChannel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readRowUShort(final DataInput input, final int height, final Rectangle srcRegion, final int xSub, final int ySub,
|
private void readRowUShort(final DataInput input, final int height, final Rectangle srcRegion, final int xSub, final int ySub,
|
||||||
final short[] rowDataUShort, final WritableRaster destChannel, final Raster srcChannel, final int y) throws IOException {
|
final short[] rowDataUShort, final WritableRaster destChannel, final Raster srcChannel, final int y) throws IOException {
|
||||||
// Flip into position?
|
|
||||||
int srcY = !header.topDown ? height - 1 - y : y;
|
|
||||||
int dstY = (srcY - srcRegion.y) / ySub;
|
|
||||||
|
|
||||||
// If subsampled or outside source region, skip entire row
|
// If subsampled or outside source region, skip entire row
|
||||||
if (srcY % ySub != 0 || srcY < srcRegion.y || srcY >= srcRegion.y + srcRegion.height) {
|
if (y % ySub != 0 || height - 1 - y < srcRegion.y || height - 1 - y >= srcRegion.y + srcRegion.height) {
|
||||||
input.skipBytes(rowDataUShort.length * 2 + (rowDataUShort.length % 2) * 2);
|
input.skipBytes(rowDataUShort.length * 2 + (rowDataUShort.length % 2) * 2);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -534,17 +513,19 @@ public final class BMPImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
destChannel.setDataElements(0, dstY, srcChannel);
|
if (header.topDown) {
|
||||||
|
destChannel.setDataElements(0, y, srcChannel);
|
||||||
|
} else {
|
||||||
|
// Flip into position
|
||||||
|
int dstY = (height - 1 - y - srcRegion.y) / ySub;
|
||||||
|
destChannel.setDataElements(0, dstY, srcChannel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readRowInt(final DataInput input, final int height, final Rectangle srcRegion, final int xSub, final int ySub,
|
private void readRowInt(final DataInput input, final int height, final Rectangle srcRegion, final int xSub, final int ySub,
|
||||||
final int[] rowDataInt, final WritableRaster destChannel, final Raster srcChannel, final int y) throws IOException {
|
final int[] rowDataInt, final WritableRaster destChannel, final Raster srcChannel, final int y) throws IOException {
|
||||||
// Flip into position?
|
|
||||||
int srcY = !header.topDown ? height - 1 - y : y;
|
|
||||||
int dstY = (srcY - srcRegion.y) / ySub;
|
|
||||||
|
|
||||||
// If subsampled or outside source region, skip entire row
|
// If subsampled or outside source region, skip entire row
|
||||||
if (srcY % ySub != 0 || srcY < srcRegion.y || srcY >= srcRegion.y + srcRegion.height) {
|
if (y % ySub != 0 || height - 1 - y < srcRegion.y || height - 1 - y >= srcRegion.y + srcRegion.height) {
|
||||||
input.skipBytes(rowDataInt.length * 4);
|
input.skipBytes(rowDataInt.length * 4);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -559,7 +540,13 @@ public final class BMPImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
destChannel.setDataElements(0, dstY, srcChannel);
|
if (header.topDown) {
|
||||||
|
destChannel.setDataElements(0, y, srcChannel);
|
||||||
|
} else {
|
||||||
|
// Flip into position
|
||||||
|
int dstY = (height - 1 - y - srcRegion.y) / ySub;
|
||||||
|
destChannel.setDataElements(0, dstY, srcChannel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Candidate util method
|
// TODO: Candidate util method
|
||||||
@@ -625,13 +612,12 @@ public final class BMPImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Why, oh why..? Instead of accepting it's own native format as it should,
|
// Why, oh why..? Instead of accepting it's own native format as it should,
|
||||||
// The DIBImageWriter only accepts instances of com.sun.imageio.plugins.bmp.BMPMetadata...
|
// The BMPImageWriter only accepts instances of com.sun.imageio.plugins.bmp.BMPMetadata...
|
||||||
// TODO: Consider reflectively construct a BMPMetadata and inject fields
|
// TODO: Consider reflectively construct a BMPMetadata and inject fields
|
||||||
return new BMPMetadata(header, colors);
|
return new BMPMetadata(header, colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
public static void main(String[] args) throws IOException {
|
||||||
public static void main(String[] args) {
|
|
||||||
BMPImageReaderSpi provider = new BMPImageReaderSpi();
|
BMPImageReaderSpi provider = new BMPImageReaderSpi();
|
||||||
BMPImageReader reader = new BMPImageReader(provider);
|
BMPImageReader reader = new BMPImageReader(provider);
|
||||||
|
|
||||||
@@ -684,7 +670,7 @@ public final class BMPImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "UnusedDeclaration", "SameParameterValue" })
|
@SuppressWarnings({"unchecked", "UnusedDeclaration"})
|
||||||
static <T extends Throwable> void throwAs(final Class<T> pType, final Throwable pThrowable) throws T {
|
static <T extends Throwable> void throwAs(final Class<T> pType, final Throwable pThrowable) throws T {
|
||||||
throw (T) pThrowable;
|
throw (T) pThrowable;
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-22
@@ -4,28 +4,26 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
@@ -116,7 +114,7 @@ public final class BMPImageReaderSpi extends ImageReaderSpiBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageReader createReaderInstance(final Object pExtension) {
|
public ImageReader createReaderInstance(final Object pExtension) throws IOException {
|
||||||
return new BMPImageReader(this);
|
return new BMPImageReader(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
-150
@@ -1,150 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2017, Harald Kuhr
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * 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.
|
|
||||||
*
|
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
|
||||||
|
|
||||||
import javax.imageio.IIOImage;
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import javax.imageio.ImageTypeSpecifier;
|
|
||||||
import javax.imageio.ImageWriteParam;
|
|
||||||
import javax.imageio.metadata.IIOMetadata;
|
|
||||||
import javax.imageio.plugins.bmp.BMPImageWriteParam;
|
|
||||||
import javax.imageio.spi.ImageWriterSpi;
|
|
||||||
import javax.imageio.stream.ImageOutputStream;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.ByteOrder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BMPImageWriter
|
|
||||||
*/
|
|
||||||
public final class BMPImageWriter extends DIBImageWriter {
|
|
||||||
protected BMPImageWriter(ImageWriterSpi provider) {
|
|
||||||
super(provider);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ImageWriteParam getDefaultWriteParam() {
|
|
||||||
// We can use the existing BMPImageWriteParam, as it's part of the javax.imageio API.
|
|
||||||
return new BMPImageWriteParam(getLocale());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType, ImageWriteParam param) {
|
|
||||||
// TODO
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IIOMetadata convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param) {
|
|
||||||
// TODO: Support both our own and the com.sun.. metadata + standard metadata
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param) throws IOException {
|
|
||||||
assertOutput();
|
|
||||||
|
|
||||||
if (image == null) {
|
|
||||||
throw new IllegalArgumentException("image may not be null");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (image.hasRaster()) {
|
|
||||||
// TODO: The default BMPWriter seems to support this, consider doing so as well
|
|
||||||
throw new UnsupportedOperationException("image has a Raster!");
|
|
||||||
}
|
|
||||||
|
|
||||||
imageOutput.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
|
||||||
|
|
||||||
clearAbortRequest();
|
|
||||||
processImageStarted(0);
|
|
||||||
|
|
||||||
if (param == null) {
|
|
||||||
param = getDefaultWriteParam();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default to bottom-up
|
|
||||||
// TODO: top-down only allowed for RGB and BITFIELDS compressions (not RLE or PNG)!
|
|
||||||
// Though Windows seems to support top-down for RLE too...
|
|
||||||
final boolean isTopDown = param instanceof BMPImageWriteParam && ((BMPImageWriteParam) param).isTopDown();
|
|
||||||
// int compression = DIB.COMPRESSION_ALPHA_BITFIELDS; // BMP can use BIFTFIELDS or ALPHA_BITFIELDS
|
|
||||||
int compression = DIB.COMPRESSION_RGB;
|
|
||||||
|
|
||||||
// TODO: Fix
|
|
||||||
BufferedImage img = (BufferedImage) image.getRenderedImage();
|
|
||||||
|
|
||||||
int height = img.getHeight();
|
|
||||||
int width = img.getWidth();
|
|
||||||
|
|
||||||
// Write File header
|
|
||||||
// TODO: Always use V4/V5 header, when writing with alpha, to avoid ambiguity
|
|
||||||
// TODO: Allow writing normal BITMAP_INFO_HEADER_SIZE with "fake" alpha as well?
|
|
||||||
int infoHeaderSize = DIB.BITMAP_INFO_HEADER_SIZE;
|
|
||||||
boolean hasExtraMasks = infoHeaderSize == DIB.BITMAP_INFO_HEADER_SIZE && (compression == DIB.COMPRESSION_BITFIELDS || compression == DIB.COMPRESSION_ALPHA_BITFIELDS);
|
|
||||||
// TODO: Allow writing without file header for ICO/CUR support
|
|
||||||
writeFileHeader(infoHeaderSize, DIB.BMP_FILE_HEADER_SIZE + infoHeaderSize + width * height * 4, hasExtraMasks);
|
|
||||||
writeDIBHeader(infoHeaderSize, img.getWidth(), img.getHeight(), isTopDown, img.getColorModel().getPixelSize(), compression);
|
|
||||||
// writeDIBHeader(infoHeaderSize, img, isTopDown, DIB.COMPRESSION_RGB);
|
|
||||||
|
|
||||||
if (hasExtraMasks) {
|
|
||||||
imageOutput.writeInt(0x000000FF); // B
|
|
||||||
imageOutput.writeInt(0x0000FF00); // G
|
|
||||||
imageOutput.writeInt(0x00FF0000); // R
|
|
||||||
imageOutput.writeInt(0xFF000000); // A
|
|
||||||
}
|
|
||||||
|
|
||||||
writeUncompressed(isTopDown, img, height, width);
|
|
||||||
|
|
||||||
processImageComplete();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeFileHeader(int infoHeaderSize, int fileSize, boolean hasMasks) throws IOException {
|
|
||||||
// 14 bytes
|
|
||||||
imageOutput.writeShort('M' << 8 | 'B');
|
|
||||||
imageOutput.writeInt(fileSize + (hasMasks ? 16 : 0)); // File size (only known at this time if uncompressed!)
|
|
||||||
imageOutput.writeShort(0); // Reserved
|
|
||||||
imageOutput.writeShort(0); // Reserved
|
|
||||||
|
|
||||||
imageOutput.writeInt(DIB.BMP_FILE_HEADER_SIZE + infoHeaderSize + (hasMasks ? 16 : 0)); // Offset to image data
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
|
||||||
File input = new File(args[0]);
|
|
||||||
File output = new File(args[0].replace('.', '_') + "_copy.bmp");
|
|
||||||
|
|
||||||
try (ImageOutputStream stream = ImageIO.createImageOutputStream(output)) {
|
|
||||||
DIBImageWriter writer = new BMPImageWriter(null);
|
|
||||||
writer.setOutput(stream);
|
|
||||||
writer.write(ImageIO.read(input));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-76
@@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2017, Harald Kuhr
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * 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.
|
|
||||||
*
|
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
|
||||||
|
|
||||||
import com.twelvemonkeys.imageio.spi.ImageWriterSpiBase;
|
|
||||||
|
|
||||||
import javax.imageio.ImageTypeSpecifier;
|
|
||||||
import javax.imageio.spi.ImageWriterSpi;
|
|
||||||
import javax.imageio.spi.ServiceRegistry;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import static com.twelvemonkeys.imageio.util.IIOUtil.lookupProviderByName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BMPImageWriterSpi
|
|
||||||
*/
|
|
||||||
public final class BMPImageWriterSpi extends ImageWriterSpiBase {
|
|
||||||
public BMPImageWriterSpi() {
|
|
||||||
super(new BMPProviderInfo());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRegistration(ServiceRegistry registry, Class<?> category) {
|
|
||||||
// Make sure we register BEHIND the built-in BMP writer
|
|
||||||
ImageWriterSpi sunSpi = lookupProviderByName(registry, "com.sun.imageio.plugins.bmp.BMPImageWriterSpi", ImageWriterSpi.class);
|
|
||||||
|
|
||||||
if (sunSpi != null && sunSpi.getVendorName() != null) {
|
|
||||||
registry.setOrdering((Class<ImageWriterSpi>) category, sunSpi, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canEncodeImage(final ImageTypeSpecifier type) {
|
|
||||||
// TODO: Support more types, as time permits.
|
|
||||||
return type.getBufferedImageType() == BufferedImage.TYPE_4BYTE_ABGR;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BMPImageWriter createWriterInstance(final Object extension) {
|
|
||||||
return new BMPImageWriter(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDescription(final Locale locale) {
|
|
||||||
return "Windows Device Independent Bitmap Format (BMP) Writer";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+97
-104
@@ -4,28 +4,26 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
@@ -170,90 +168,87 @@ final class BMPMetadata extends AbstractMetadata {
|
|||||||
protected IIOMetadataNode getStandardCompressionNode() {
|
protected IIOMetadataNode getStandardCompressionNode() {
|
||||||
IIOMetadataNode compression = new IIOMetadataNode("Compression");
|
IIOMetadataNode compression = new IIOMetadataNode("Compression");
|
||||||
IIOMetadataNode compressionTypeName = addChildNode(compression, "CompressionTypeName", null);
|
IIOMetadataNode compressionTypeName = addChildNode(compression, "CompressionTypeName", null);
|
||||||
|
compressionTypeName.setAttribute("value", "NONE");
|
||||||
// TODO: Should the compression names always match the compression names used in the ImageWriteParam?
|
|
||||||
// OR should they be as standard as possible..?
|
|
||||||
// The built-in plugin uses "BI_RGB", "BI_RLE8", "BI_RLE4", "BI_BITFIELDS", "BI_JPEG and "BI_PNG"
|
|
||||||
switch (header.compression) {
|
|
||||||
case DIB.COMPRESSION_RLE4:
|
|
||||||
case DIB.COMPRESSION_RLE8:
|
|
||||||
compressionTypeName.setAttribute("value", "RLE");
|
|
||||||
break;
|
|
||||||
case DIB.COMPRESSION_JPEG:
|
|
||||||
compressionTypeName.setAttribute("value", "JPEG");
|
|
||||||
break;
|
|
||||||
case DIB.COMPRESSION_PNG:
|
|
||||||
compressionTypeName.setAttribute("value", "PNG");
|
|
||||||
break;
|
|
||||||
case DIB.COMPRESSION_RGB:
|
|
||||||
case DIB.COMPRESSION_BITFIELDS:
|
|
||||||
case DIB.COMPRESSION_ALPHA_BITFIELDS:
|
|
||||||
default:
|
|
||||||
compressionTypeName.setAttribute("value", "NONE");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return compression;
|
return compression;
|
||||||
|
// switch (header.getImageType()) {
|
||||||
|
// case TGA.IMAGETYPE_COLORMAPPED_RLE:
|
||||||
|
// case TGA.IMAGETYPE_TRUECOLOR_RLE:
|
||||||
|
// case TGA.IMAGETYPE_MONOCHROME_RLE:
|
||||||
|
// case TGA.IMAGETYPE_COLORMAPPED_HUFFMAN:
|
||||||
|
// case TGA.IMAGETYPE_COLORMAPPED_HUFFMAN_QUADTREE:
|
||||||
|
// IIOMetadataNode node = new IIOMetadataNode("Compression");
|
||||||
|
// IIOMetadataNode compressionTypeName = new IIOMetadataNode("CompressionTypeName");
|
||||||
|
//
|
||||||
|
// // Compression can be RLE4, RLE8, PNG, JPEG or NONE
|
||||||
|
// String value = header.getImageType() == TGA.IMAGETYPE_COLORMAPPED_HUFFMAN || header.getImageType() == TGA.IMAGETYPE_COLORMAPPED_HUFFMAN_QUADTREE
|
||||||
|
// ? "Uknown" : "RLE";
|
||||||
|
// compressionTypeName.setAttribute("value", value);
|
||||||
|
// node.appendChild(compressionTypeName);
|
||||||
|
//
|
||||||
|
// IIOMetadataNode lossless = new IIOMetadataNode("Lossless");
|
||||||
|
// lossless.setAttribute("value", "TRUE"); // TODO: Unless JPEG!
|
||||||
|
// node.appendChild(lossless);
|
||||||
|
//
|
||||||
|
// return node;
|
||||||
|
// default:
|
||||||
|
// // No compression
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IIOMetadataNode getStandardDataNode() {
|
protected IIOMetadataNode getStandardDataNode() {
|
||||||
IIOMetadataNode node = new IIOMetadataNode("Data");
|
IIOMetadataNode node = new IIOMetadataNode("Data");
|
||||||
|
|
||||||
|
// IIOMetadataNode planarConfiguration = new IIOMetadataNode("PlanarConfiguration");
|
||||||
|
// planarConfiguration.setAttribute("value", "PixelInterleaved");
|
||||||
|
// node.appendChild(planarConfiguration);
|
||||||
|
|
||||||
|
// IIOMetadataNode sampleFormat = new IIOMetadataNode("SampleFormat");
|
||||||
|
// switch (header.getImageType()) {
|
||||||
|
// case TGA.IMAGETYPE_COLORMAPPED:
|
||||||
|
// case TGA.IMAGETYPE_COLORMAPPED_RLE:
|
||||||
|
// case TGA.IMAGETYPE_COLORMAPPED_HUFFMAN:
|
||||||
|
// case TGA.IMAGETYPE_COLORMAPPED_HUFFMAN_QUADTREE:
|
||||||
|
// sampleFormat.setAttribute("value", "Index");
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// sampleFormat.setAttribute("value", "UnsignedIntegral");
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// node.appendChild(sampleFormat);
|
||||||
|
|
||||||
IIOMetadataNode bitsPerSample = new IIOMetadataNode("BitsPerSample");
|
IIOMetadataNode bitsPerSample = new IIOMetadataNode("BitsPerSample");
|
||||||
switch (header.getBitCount()) {
|
switch (header.getBitCount()) {
|
||||||
// TODO: case 0: determined by embedded format (PNG/JPEG)
|
|
||||||
case 1:
|
case 1:
|
||||||
case 2:
|
case 2:
|
||||||
case 4:
|
case 4:
|
||||||
case 8:
|
case 8:
|
||||||
bitsPerSample.setAttribute("value", createListValue(1, Integer.toString(header.getBitCount())));
|
bitsPerSample.setAttribute("value", createListValue(1, Integer.toString(header.getBitCount())));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 16:
|
case 16:
|
||||||
// Default is 555
|
// TODO: Consult masks here!
|
||||||
bitsPerSample.setAttribute("value", header.hasMasks()
|
bitsPerSample.setAttribute("value", createListValue(4, Integer.toString(4)));
|
||||||
? createBitsPerSampleForBitMasks()
|
|
||||||
: createListValue(3, Integer.toString(5)));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 24:
|
case 24:
|
||||||
bitsPerSample.setAttribute("value", createListValue(3, Integer.toString(8)));
|
bitsPerSample.setAttribute("value", createListValue(3, Integer.toString(8)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 32:
|
case 32:
|
||||||
// Default is 888
|
bitsPerSample.setAttribute("value", createListValue(4, Integer.toString(8)));
|
||||||
bitsPerSample.setAttribute("value", header.hasMasks()
|
|
||||||
? createBitsPerSampleForBitMasks()
|
|
||||||
: createListValue(3, Integer.toString(8)));
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
node.appendChild(bitsPerSample);
|
node.appendChild(bitsPerSample);
|
||||||
|
|
||||||
|
// TODO: Do we need MSB?
|
||||||
|
// IIOMetadataNode sampleMSB = new IIOMetadataNode("SampleMSB");
|
||||||
|
// sampleMSB.setAttribute("value", createListValue(header.getChannels(), "0"));
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String createBitsPerSampleForBitMasks() {
|
|
||||||
boolean hasAlpha = header.masks[3] != 0;
|
|
||||||
|
|
||||||
return createListValue(hasAlpha ? 4 : 3,
|
|
||||||
Integer.toString(countMaskBits(header.masks[0])), Integer.toString(countMaskBits(header.masks[1])),
|
|
||||||
Integer.toString(countMaskBits(header.masks[2])), Integer.toString(countMaskBits(header.masks[3])));
|
|
||||||
}
|
|
||||||
|
|
||||||
private int countMaskBits(int mask) {
|
|
||||||
// See https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan
|
|
||||||
int count;
|
|
||||||
|
|
||||||
for (count = 0; mask != 0; count++) {
|
|
||||||
mask &= mask - 1; // clear the least significant bit set
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String createListValue(final int itemCount, final String... values) {
|
private String createListValue(final int itemCount, final String... values) {
|
||||||
StringBuilder buffer = new StringBuilder();
|
StringBuilder buffer = new StringBuilder();
|
||||||
|
|
||||||
@@ -270,31 +265,28 @@ final class BMPMetadata extends AbstractMetadata {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IIOMetadataNode getStandardDimensionNode() {
|
protected IIOMetadataNode getStandardDimensionNode() {
|
||||||
IIOMetadataNode dimension = new IIOMetadataNode("Dimension");
|
if (header.xPixelsPerMeter > 0 || header.yPixelsPerMeter > 0) {
|
||||||
|
IIOMetadataNode dimension = new IIOMetadataNode("Dimension");
|
||||||
|
|
||||||
if (header.xPixelsPerMeter > 0 && header.yPixelsPerMeter > 0) {
|
addChildNode(dimension, "PixelAspectRatio", null);
|
||||||
float ratio = header.xPixelsPerMeter / (float) header.yPixelsPerMeter;
|
addChildNode(dimension, "HorizontalPhysicalPixelSpacing", null);
|
||||||
addChildNode(dimension, "PixelAspectRatio", null)
|
addChildNode(dimension, "VerticalPhysicalPixelSpacing", null);
|
||||||
.setAttribute("value", String.valueOf(ratio));
|
|
||||||
|
|
||||||
addChildNode(dimension, "HorizontalPixelSize", null)
|
// IIOMetadataNode imageOrientation = new IIOMetadataNode("ImageOrientation");
|
||||||
.setAttribute("value", String.valueOf(1f / header.xPixelsPerMeter * 1000));
|
//
|
||||||
addChildNode(dimension, "VerticalPixelSize", null)
|
// if (header.topDown) {
|
||||||
.setAttribute("value", String.valueOf(1f / header.yPixelsPerMeter * 1000));
|
// imageOrientation.setAttribute("value", "FlipH");
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// imageOrientation.setAttribute("value", "Normal");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// dimension.appendChild(imageOrientation);
|
||||||
|
|
||||||
// Hmmm.. The JRE version includes these for some reason, even if values seem to be same as default...
|
return dimension;
|
||||||
addChildNode(dimension, "HorizontalPhysicalPixelSpacing", null)
|
|
||||||
.setAttribute("value", String.valueOf(0));
|
|
||||||
addChildNode(dimension, "VerticalPhysicalPixelSpacing", null)
|
|
||||||
.setAttribute("value", String.valueOf(0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (header.topDown) {
|
return null;
|
||||||
addChildNode(dimension, "ImageOrientation", null)
|
|
||||||
.setAttribute("value", "FlipH"); // For BMP, bottom-up is "normal"...
|
|
||||||
}
|
|
||||||
|
|
||||||
return dimension;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// No document node
|
// No document node
|
||||||
@@ -305,15 +297,16 @@ final class BMPMetadata extends AbstractMetadata {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IIOMetadataNode getStandardTransparencyNode() {
|
protected IIOMetadataNode getStandardTransparencyNode() {
|
||||||
if (header.hasMasks() && header.masks[3] != 0) {
|
|
||||||
IIOMetadataNode transparency = new IIOMetadataNode("Transparency");
|
|
||||||
IIOMetadataNode alpha = new IIOMetadataNode("Alpha");
|
|
||||||
alpha.setAttribute("value", "nonpremultiplied");
|
|
||||||
transparency.appendChild(alpha);
|
|
||||||
|
|
||||||
return transparency;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
// IIOMetadataNode transparency = new IIOMetadataNode("Transparency");
|
||||||
|
//
|
||||||
|
// IIOMetadataNode alpha = new IIOMetadataNode("Alpha");
|
||||||
|
//
|
||||||
|
// // TODO: Consult masks
|
||||||
|
// alpha.setAttribute("value", header.getBitCount() == 32 ? "nonpremultiplied" : "none");
|
||||||
|
// transparency.appendChild(alpha);
|
||||||
|
//
|
||||||
|
// return transparency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-39
@@ -1,33 +1,3 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, Harald Kuhr
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * 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.
|
|
||||||
*
|
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|
||||||
import com.twelvemonkeys.imageio.spi.ReaderWriterProviderInfo;
|
import com.twelvemonkeys.imageio.spi.ReaderWriterProviderInfo;
|
||||||
@@ -40,24 +10,22 @@ import com.twelvemonkeys.imageio.spi.ReaderWriterProviderInfo;
|
|||||||
* @version $Id: BMPProviderInfo.java,v 1.0 20/03/15 harald.kuhr Exp$
|
* @version $Id: BMPProviderInfo.java,v 1.0 20/03/15 harald.kuhr Exp$
|
||||||
*/
|
*/
|
||||||
final class BMPProviderInfo extends ReaderWriterProviderInfo {
|
final class BMPProviderInfo extends ReaderWriterProviderInfo {
|
||||||
BMPProviderInfo() {
|
protected BMPProviderInfo() {
|
||||||
super(
|
super(
|
||||||
BMPProviderInfo.class,
|
BMPProviderInfo.class,
|
||||||
new String[] {"bmp", "BMP"},
|
new String[] {"bmp", "BMP"},
|
||||||
new String[] {"bmp", "rle"},
|
new String[] {"bmp", "rle"},
|
||||||
new String[] {
|
new String[] {
|
||||||
"image/bmp",
|
"image/bmp",
|
||||||
"image/x-bmp",
|
"image/x-bmp"
|
||||||
"image/vnd.microsoft.bitmap"
|
// "image/vnd.microsoft.bitmap", // TODO: Official IANA MIME
|
||||||
},
|
},
|
||||||
"com.twelvemonkeys.imageio.plugins.bmp.BMPImageReader",
|
"com.twelvemonkeys.imageio.plugins.bmp.BMPImageReader",
|
||||||
new String[] {"com.twelvemonkeys.imageio.plugins.bmp.BMPImageReaderSpi"},
|
new String[] {"com.twelvemonkeys.imageio.plugins.bmp.BMPImageReaderSpi"},
|
||||||
"com.twelvemonkeys.imageio.plugins.bmp.BMPImageWriter",
|
"com.sun.imageio.plugins.bmp.BMPImageWriter",
|
||||||
new String[] {"com.twelvemonkeys.imageio.plugins.bmp.BMPImageWriterSpi"},
|
new String[]{"com.sun.imageio.plugins.bmp.BMPImageWriterSpi"}, // We support the same native metadata format
|
||||||
false, null, null,
|
false, null, null, null, null,
|
||||||
null, null,
|
true, BMPMetadata.nativeMetadataFormatName, "com.sun.imageio.plugins.bmp.BMPMetadataFormat", null, null
|
||||||
true, BMPMetadata.nativeMetadataFormatName, "com.sun.imageio.plugins.bmp.BMPMetadataFormat",
|
|
||||||
null, null
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-26
@@ -4,35 +4,33 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|
||||||
import static com.twelvemonkeys.lang.Validate.notNull;
|
import com.twelvemonkeys.lang.Validate;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes a bitmap structure.
|
* Describes a bitmap structure.
|
||||||
@@ -48,11 +46,14 @@ abstract class BitmapDescriptor {
|
|||||||
protected BitmapMask mask;
|
protected BitmapMask mask;
|
||||||
|
|
||||||
public BitmapDescriptor(final DirectoryEntry pEntry, final DIBHeader pHeader) {
|
public BitmapDescriptor(final DirectoryEntry pEntry, final DIBHeader pHeader) {
|
||||||
entry = notNull(pEntry, "entry");;
|
Validate.notNull(pEntry, "entry");
|
||||||
header = notNull(pHeader, "header");
|
Validate.notNull(pHeader, "header");
|
||||||
|
|
||||||
|
entry = pEntry;
|
||||||
|
header = pHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public BufferedImage getImage() throws IOException;
|
abstract public BufferedImage getImage();
|
||||||
|
|
||||||
public final int getWidth() {
|
public final int getWidth() {
|
||||||
return entry.getWidth();
|
return entry.getWidth();
|
||||||
|
|||||||
+20
-22
@@ -4,29 +4,28 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
@@ -163,7 +162,6 @@ class BitmapIndexed extends BitmapDescriptor {
|
|||||||
return transparent;
|
return transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public BufferedImage getImage() {
|
public BufferedImage getImage() {
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
image = createImageIndexed();
|
image = createImageIndexed();
|
||||||
|
|||||||
+19
-21
@@ -4,28 +4,26 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|||||||
+19
-22
@@ -4,28 +4,26 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
@@ -46,7 +44,6 @@ class BitmapRGB extends BitmapDescriptor {
|
|||||||
super(pEntry, pHeader);
|
super(pEntry, pHeader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public BufferedImage getImage() {
|
public BufferedImage getImage() {
|
||||||
// Test is mask != null rather than hasMask(), as 32 bit (w/alpha)
|
// Test is mask != null rather than hasMask(), as 32 bit (w/alpha)
|
||||||
// might still have bitmask, but we don't read or use it.
|
// might still have bitmask, but we don't read or use it.
|
||||||
|
|||||||
+23
-29
@@ -4,36 +4,31 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import javax.imageio.IIOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents bitmap structures we can't read.
|
* Represents bitmap structures we can't read.
|
||||||
@@ -45,14 +40,13 @@ import javax.imageio.IIOException;
|
|||||||
class BitmapUnsupported extends BitmapDescriptor {
|
class BitmapUnsupported extends BitmapDescriptor {
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
public BitmapUnsupported(final DirectoryEntry pEntry, DIBHeader header, final String pMessage) {
|
public BitmapUnsupported(final DirectoryEntry pEntry, final String pMessage) {
|
||||||
super(pEntry, header);
|
super(pEntry, null);
|
||||||
|
|
||||||
message = pMessage;
|
message = pMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public BufferedImage getImage() {
|
||||||
public BufferedImage getImage() throws IOException {
|
throw new IllegalStateException(message);
|
||||||
throw new IIOException(message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-21
@@ -4,28 +4,26 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|||||||
+19
-21
@@ -4,28 +4,26 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|||||||
+20
-22
@@ -4,28 +4,26 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
@@ -40,7 +38,7 @@ import com.twelvemonkeys.imageio.spi.ReaderWriterProviderInfo;
|
|||||||
* @version $Id: CURProviderInfo.java,v 1.0 20/03/15 harald.kuhr Exp$
|
* @version $Id: CURProviderInfo.java,v 1.0 20/03/15 harald.kuhr Exp$
|
||||||
*/
|
*/
|
||||||
final class CURProviderInfo extends ReaderWriterProviderInfo {
|
final class CURProviderInfo extends ReaderWriterProviderInfo {
|
||||||
CURProviderInfo() {
|
protected CURProviderInfo() {
|
||||||
super(
|
super(
|
||||||
CURProviderInfo.class,
|
CURProviderInfo.class,
|
||||||
new String[]{"cur", "CUR"},
|
new String[]{"cur", "CUR"},
|
||||||
|
|||||||
@@ -4,28 +4,26 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|||||||
+3
-30
@@ -30,12 +30,11 @@
|
|||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|
||||||
|
import javax.imageio.IIOException;
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.DataOutput;
|
import java.io.DataOutput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.imageio.IIOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the DIB (Device Independent Bitmap) Information header structure.
|
* Represents the DIB (Device Independent Bitmap) Information header structure.
|
||||||
*
|
*
|
||||||
@@ -214,7 +213,7 @@ abstract class DIBHeader {
|
|||||||
|
|
||||||
// NOTE: Unlike all other headers, width and height are unsigned SHORT values (16 bit)!
|
// NOTE: Unlike all other headers, width and height are unsigned SHORT values (16 bit)!
|
||||||
width = pStream.readUnsignedShort();
|
width = pStream.readUnsignedShort();
|
||||||
height = pStream.readShort();
|
height = pStream.readUnsignedShort();
|
||||||
|
|
||||||
if (height < 0) {
|
if (height < 0) {
|
||||||
height = -height;
|
height = -height;
|
||||||
@@ -241,7 +240,6 @@ abstract class DIBHeader {
|
|||||||
* @see <a href="http://www.fileformat.info/format/os2bmp/egff.htm">OS/2 Bitmap File Format Summary</a>
|
* @see <a href="http://www.fileformat.info/format/os2bmp/egff.htm">OS/2 Bitmap File Format Summary</a>
|
||||||
*/
|
*/
|
||||||
static final class BitmapCoreHeaderV2 extends DIBHeader {
|
static final class BitmapCoreHeaderV2 extends DIBHeader {
|
||||||
@SuppressWarnings("unused")
|
|
||||||
protected void read(final int pSize, final DataInput pStream) throws IOException {
|
protected void read(final int pSize, final DataInput pStream) throws IOException {
|
||||||
if (pSize != DIB.OS2_V2_HEADER_SIZE && pSize != DIB.OS2_V2_HEADER_16_SIZE) {
|
if (pSize != DIB.OS2_V2_HEADER_SIZE && pSize != DIB.OS2_V2_HEADER_16_SIZE) {
|
||||||
throw new IIOException(String.format("Size: %s !=: %s", pSize, DIB.OS2_V2_HEADER_SIZE));
|
throw new IIOException(String.format("Size: %s !=: %s", pSize, DIB.OS2_V2_HEADER_SIZE));
|
||||||
@@ -341,34 +339,9 @@ abstract class DIBHeader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(final DataOutput stream) throws IOException {
|
|
||||||
stream.writeInt(DIB.BITMAP_INFO_HEADER_SIZE);
|
|
||||||
|
|
||||||
stream.writeInt(width);
|
|
||||||
stream.writeInt(topDown ? -height : height);
|
|
||||||
|
|
||||||
stream.writeShort(planes);
|
|
||||||
stream.writeShort(bitCount);
|
|
||||||
stream.writeInt(compression);
|
|
||||||
|
|
||||||
stream.writeInt(imageSize);
|
|
||||||
|
|
||||||
stream.writeInt(xPixelsPerMeter);
|
|
||||||
stream.writeInt(yPixelsPerMeter);
|
|
||||||
|
|
||||||
stream.writeInt(colorsUsed);
|
|
||||||
stream.writeInt(colorsImportant);
|
|
||||||
|
|
||||||
// TODO: Write masks, if bitfields
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBMPVersion() {
|
public String getBMPVersion() {
|
||||||
// This is to be compatible with the native metadata of the original com.sun....BMPMetadata
|
// This is to be compatible with the native metadata of the original com.sun....BMPMetadata
|
||||||
return size > DIB.BITMAP_INFO_HEADER_SIZE
|
return compression == DIB.COMPRESSION_BITFIELDS ? "BMP v. 3.x NT" : "BMP v. 3.x";
|
||||||
? "BMP V2/V3 INFO"
|
|
||||||
: compression == DIB.COMPRESSION_BITFIELDS || compression == DIB.COMPRESSION_ALPHA_BITFIELDS
|
|
||||||
? "BMP v. 3.x NT"
|
|
||||||
: "BMP v. 3.x";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+45
-54
@@ -4,32 +4,40 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|
||||||
|
import com.twelvemonkeys.image.ImageUtil;
|
||||||
|
import com.twelvemonkeys.imageio.ImageReaderBase;
|
||||||
|
import com.twelvemonkeys.imageio.util.IIOUtil;
|
||||||
|
import com.twelvemonkeys.imageio.util.ImageTypeSpecifiers;
|
||||||
|
import com.twelvemonkeys.util.WeakWeakMap;
|
||||||
|
|
||||||
|
import javax.imageio.*;
|
||||||
|
import javax.imageio.spi.ImageReaderSpi;
|
||||||
|
import javax.imageio.stream.ImageInputStream;
|
||||||
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.color.ColorSpace;
|
import java.awt.color.ColorSpace;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
@@ -37,27 +45,10 @@ import java.awt.event.WindowEvent;
|
|||||||
import java.awt.image.*;
|
import java.awt.image.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.*;
|
||||||
import java.util.WeakHashMap;
|
|
||||||
|
|
||||||
import javax.imageio.IIOException;
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import javax.imageio.ImageReadParam;
|
|
||||||
import javax.imageio.ImageReader;
|
|
||||||
import javax.imageio.ImageTypeSpecifier;
|
|
||||||
import javax.imageio.spi.ImageReaderSpi;
|
|
||||||
import javax.imageio.stream.ImageInputStream;
|
|
||||||
import javax.swing.*;
|
|
||||||
|
|
||||||
import com.twelvemonkeys.image.ImageUtil;
|
|
||||||
import com.twelvemonkeys.imageio.ImageReaderBase;
|
|
||||||
import com.twelvemonkeys.imageio.stream.SubImageInputStream;
|
|
||||||
import com.twelvemonkeys.imageio.util.ImageTypeSpecifiers;
|
|
||||||
import com.twelvemonkeys.util.WeakWeakMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ImageReader for Microsoft Windows ICO (icon) format.
|
* ImageReader for Microsoft Windows ICO (icon) format.
|
||||||
@@ -92,7 +83,7 @@ abstract class DIBImageReader extends ImageReaderBase {
|
|||||||
|
|
||||||
protected void resetMembers() {
|
protected void resetMembers() {
|
||||||
directory = null;
|
directory = null;
|
||||||
|
|
||||||
headers.clear();
|
headers.clear();
|
||||||
descriptors.clear();
|
descriptors.clear();
|
||||||
|
|
||||||
@@ -242,9 +233,8 @@ abstract class DIBImageReader extends ImageReaderBase {
|
|||||||
ImageReader pngReader = getPNGReader();
|
ImageReader pngReader = getPNGReader();
|
||||||
|
|
||||||
imageInput.seek(pEntry.getOffset());
|
imageInput.seek(pEntry.getOffset());
|
||||||
// InputStream inputStream = IIOUtil.createStreamAdapter(imageInput, pEntry.getSize());
|
InputStream inputStream = IIOUtil.createStreamAdapter(imageInput, pEntry.getSize());
|
||||||
// ImageInputStream stream = ImageIO.createImageInputStream(inputStream);
|
ImageInputStream stream = ImageIO.createImageInputStream(inputStream);
|
||||||
ImageInputStream stream = new SubImageInputStream(imageInput, pEntry.getSize());
|
|
||||||
|
|
||||||
// NOTE: Will throw IOException on later reads if input is not PNG
|
// NOTE: Will throw IOException on later reads if input is not PNG
|
||||||
pngReader.setInput(stream);
|
pngReader.setInput(stream);
|
||||||
@@ -294,8 +284,8 @@ abstract class DIBImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Support this, it's already in the BMP reader, spec allows RLE4 and RLE8
|
// TODO: Support this, it's already in the BMP reader, spec allows RLE4 and RLE8
|
||||||
if (header.getCompression() != DIB.COMPRESSION_RGB) {
|
if (header.getCompression() != 0) {
|
||||||
descriptor = new BitmapUnsupported(pEntry, header, String.format("Unsupported compression: %d", header.getCompression()));
|
descriptor = new BitmapUnsupported(pEntry, String.format("Unsupported compression: %d", header.getCompression()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int bitCount = header.getBitCount();
|
int bitCount = header.getBitCount();
|
||||||
@@ -323,7 +313,7 @@ abstract class DIBImageReader extends ImageReaderBase {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
descriptor = new BitmapUnsupported(pEntry, header, String.format("Unsupported bit count %d", bitCount));
|
descriptor = new BitmapUnsupported(pEntry, String.format("Unsupported bit count %d", bitCount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,7 +353,7 @@ abstract class DIBImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void readBitmapIndexed1(final BitmapIndexed pBitmap, final boolean pAsMask) throws IOException {
|
private void readBitmapIndexed1(final BitmapIndexed pBitmap, final boolean pAsMask) throws IOException {
|
||||||
int width = adjustToPadding((pBitmap.getWidth() + 7) >> 3);
|
int width = adjustToPadding(pBitmap.getWidth() >> 3);
|
||||||
byte[] row = new byte[width];
|
byte[] row = new byte[width];
|
||||||
|
|
||||||
for (int y = 0; y < pBitmap.getHeight(); y++) {
|
for (int y = 0; y < pBitmap.getHeight(); y++) {
|
||||||
@@ -397,7 +387,7 @@ abstract class DIBImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void readBitmapIndexed4(final BitmapIndexed pBitmap) throws IOException {
|
private void readBitmapIndexed4(final BitmapIndexed pBitmap) throws IOException {
|
||||||
int width = adjustToPadding((pBitmap.getWidth() + 1) >> 1);
|
int width = adjustToPadding(pBitmap.getWidth() >> 1);
|
||||||
byte[] row = new byte[width];
|
byte[] row = new byte[width];
|
||||||
|
|
||||||
for (int y = 0; y < pBitmap.getHeight(); y++) {
|
for (int y = 0; y < pBitmap.getHeight(); y++) {
|
||||||
@@ -465,12 +455,13 @@ abstract class DIBImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void readBitmap16(final BitmapDescriptor pBitmap) throws IOException {
|
private void readBitmap16(final BitmapDescriptor pBitmap) throws IOException {
|
||||||
|
// TODO: No idea if this actually works..
|
||||||
short[] pixels = new short[pBitmap.getWidth() * pBitmap.getHeight()];
|
short[] pixels = new short[pBitmap.getWidth() * pBitmap.getHeight()];
|
||||||
|
|
||||||
// TODO: Support TYPE_USHORT_565 and the RGB 444/ARGB 4444 layouts
|
// TODO: Support TYPE_USHORT_565 and the RGB 444/ARGB 4444 layouts
|
||||||
// Will create TYPE_USHORT_555
|
// Will create TYPE_USHORT_555
|
||||||
DirectColorModel cm = new DirectColorModel(16, 0x7C00, 0x03E0, 0x001F);
|
DirectColorModel cm = new DirectColorModel(16, 0x7C00, 0x03E0, 0x001F);
|
||||||
DataBuffer buffer = new DataBufferUShort(pixels, pixels.length);
|
DataBuffer buffer = new DataBufferShort(pixels, pixels.length);
|
||||||
WritableRaster raster = Raster.createPackedRaster(
|
WritableRaster raster = Raster.createPackedRaster(
|
||||||
buffer, pBitmap.getWidth(), pBitmap.getHeight(), pBitmap.getWidth(), cm.getMasks(), null
|
buffer, pBitmap.getWidth(), pBitmap.getHeight(), pBitmap.getWidth(), cm.getMasks(), null
|
||||||
);
|
);
|
||||||
@@ -558,7 +549,7 @@ abstract class DIBImageReader extends ImageReaderBase {
|
|||||||
if (abortRequested()) {
|
if (abortRequested()) {
|
||||||
processReadAborted();
|
processReadAborted();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
processImageProgress(100 * y / (float) pBitmap.getHeight());
|
processImageProgress(100 * y / (float) pBitmap.getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -598,7 +589,7 @@ abstract class DIBImageReader extends ImageReaderBase {
|
|||||||
|
|
||||||
return directory.getEntry(pImageIndex);
|
return directory.getEntry(pImageIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test code below, ignore.. :-)
|
/// Test code below, ignore.. :-)
|
||||||
public static void main(final String[] pArgs) throws IOException {
|
public static void main(final String[] pArgs) throws IOException {
|
||||||
if (pArgs.length == 0) {
|
if (pArgs.length == 0) {
|
||||||
@@ -708,10 +699,10 @@ abstract class DIBImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
button.setText(image.getWidth() + "x" +
|
button.setText("" + image.getWidth() + "x" +
|
||||||
image.getHeight() + ": "
|
image.getHeight() + ": "
|
||||||
+ ((image.getColorModel() instanceof IndexColorModel) ?
|
+ ((image.getColorModel() instanceof IndexColorModel) ?
|
||||||
String.valueOf(((IndexColorModel) image.getColorModel()).getMapSize()) :
|
"" + ((IndexColorModel) image.getColorModel()).getMapSize() :
|
||||||
"TrueColor"));
|
"TrueColor"));
|
||||||
|
|
||||||
pParent.add(button);
|
pParent.add(button);
|
||||||
|
|||||||
-116
@@ -1,116 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2017, Harald Kuhr
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * 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.
|
|
||||||
*
|
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
|
||||||
|
|
||||||
import com.twelvemonkeys.imageio.ImageWriterBase;
|
|
||||||
import com.twelvemonkeys.imageio.plugins.bmp.DIBHeader.BitmapInfoHeader;
|
|
||||||
|
|
||||||
import javax.imageio.IIOException;
|
|
||||||
import javax.imageio.spi.ImageWriterSpi;
|
|
||||||
import java.awt.image.*;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.ByteOrder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* DIBImageWriter
|
|
||||||
*/
|
|
||||||
abstract class DIBImageWriter extends ImageWriterBase {
|
|
||||||
|
|
||||||
DIBImageWriter(ImageWriterSpi provider) {
|
|
||||||
super(provider);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setOutput(Object output) {
|
|
||||||
super.setOutput(output);
|
|
||||||
if (imageOutput != null) {
|
|
||||||
imageOutput.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void writeDIBHeader(int infoHeaderSize, int width, int height, boolean isTopDown, int pixelSize, int compression) throws IOException {
|
|
||||||
switch (infoHeaderSize) {
|
|
||||||
case DIB.BITMAP_INFO_HEADER_SIZE:
|
|
||||||
BitmapInfoHeader header = new BitmapInfoHeader();
|
|
||||||
// TODO: Consider a constructor/factory for this
|
|
||||||
header.width = width;
|
|
||||||
header.height = height;
|
|
||||||
header.topDown = isTopDown;
|
|
||||||
|
|
||||||
header.planes = 1; // Always 1 plane
|
|
||||||
header.bitCount = pixelSize;
|
|
||||||
header.compression = compression;
|
|
||||||
|
|
||||||
header.colorsUsed = 0; // Means 2 ^ bitCount
|
|
||||||
header.colorsImportant = 0; // Means all colors important
|
|
||||||
|
|
||||||
header.imageSize = header.height * ((header.width * header.bitCount + 31) / 32) * 4; // Rows padded to 32 bit
|
|
||||||
|
|
||||||
header.xPixelsPerMeter = 2835; // 72 DPI
|
|
||||||
header.yPixelsPerMeter = 2835;
|
|
||||||
|
|
||||||
header.write(imageOutput);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IIOException("Unsupported header size: " + infoHeaderSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void writeUncompressed(boolean isTopDown, BufferedImage img, int height, int width) throws IOException {
|
|
||||||
if (img.getType() != BufferedImage.TYPE_4BYTE_ABGR) {
|
|
||||||
throw new IIOException("Only TYPE_4BYTE_ABGR supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Support
|
|
||||||
// - TODO: IndexColorModel (ucompressed, RLE4, RLE8 or BI_PNG)
|
|
||||||
// - TODO: ComponentColorModel (1 channel gray, 3 channel BGR and 4 channel BGRA, uncompressed and RLE8? BI_BITFIELDS? BI_PNG? BI_JPEG?)
|
|
||||||
// - TODO: Packed/DirectColorModel (16 and 32 bit, BI_BITFIELDS, BI_PNG? BI_JPEG?)
|
|
||||||
|
|
||||||
Raster raster = img.getRaster();
|
|
||||||
WritableRaster rowRaster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, 1, width * 4, 4, new int[] {2, 1, 0, 3}, null);
|
|
||||||
byte[] row = ((DataBufferByte) rowRaster.getDataBuffer()).getData();
|
|
||||||
final int[] bandList = {2, 1, 0, 3};
|
|
||||||
|
|
||||||
for (int i = 0; i < height; i++) {
|
|
||||||
int line = isTopDown ? i : height - 1 - i;
|
|
||||||
rowRaster.setDataElements(0, 0, raster.createChild(0, line, width, 1, 0, 0, bandList));
|
|
||||||
|
|
||||||
imageOutput.write(row);
|
|
||||||
|
|
||||||
if (abortRequested()) {
|
|
||||||
processWriteAborted();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
processImageProgress(100f * i / (float) height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+19
-21
@@ -4,28 +4,26 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|||||||
+24
-52
@@ -4,38 +4,33 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|
||||||
import javax.imageio.IIOException;
|
import javax.imageio.IIOException;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.ColorModel;
|
|
||||||
import java.awt.image.IndexColorModel;
|
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.DataOutput;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,13 +42,13 @@ import java.io.IOException;
|
|||||||
* @see <a href="http://en.wikipedia.org/wiki/ICO_(icon_image_file_format)#Directory">Wikipedia</a>
|
* @see <a href="http://en.wikipedia.org/wiki/ICO_(icon_image_file_format)#Directory">Wikipedia</a>
|
||||||
*/
|
*/
|
||||||
abstract class DirectoryEntry {
|
abstract class DirectoryEntry {
|
||||||
int width;
|
private int width;
|
||||||
int height;
|
private int height;
|
||||||
int colorCount;
|
private int colorCount;
|
||||||
int planes;
|
int planes;
|
||||||
int bitCount;
|
int bitCount;
|
||||||
int size;
|
private int size;
|
||||||
int offset;
|
private int offset;
|
||||||
|
|
||||||
DirectoryEntry() {
|
DirectoryEntry() {
|
||||||
}
|
}
|
||||||
@@ -101,18 +96,6 @@ abstract class DirectoryEntry {
|
|||||||
offset = pStream.readInt();
|
offset = pStream.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(final DataOutput output) throws IOException {
|
|
||||||
output.writeByte(width % 256);
|
|
||||||
output.writeByte(height % 256);
|
|
||||||
output.writeByte(colorCount);
|
|
||||||
output.writeByte(0); // Reserved
|
|
||||||
output.writeShort(1); // Color planes 0 or 1
|
|
||||||
output.writeShort(bitCount);
|
|
||||||
output.writeInt(size); // Size, depends on compression...
|
|
||||||
output.writeInt(offset);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format(
|
return String.format(
|
||||||
"%s: width: %d, height: %d, colors: %d, planes: %d, bit count: %d, size: %d, offset: %d",
|
"%s: width: %d, height: %d, colors: %d, planes: %d, bit count: %d, size: %d, offset: %d",
|
||||||
@@ -177,16 +160,5 @@ abstract class DirectoryEntry {
|
|||||||
* Icon directory entry.
|
* Icon directory entry.
|
||||||
*/
|
*/
|
||||||
static final class ICOEntry extends DirectoryEntry {
|
static final class ICOEntry extends DirectoryEntry {
|
||||||
private ICOEntry() {}
|
|
||||||
|
|
||||||
ICOEntry(final int width, final int height, final ColorModel colorModel, int size, final int offset) {
|
|
||||||
this.width = width;
|
|
||||||
this.height = height;
|
|
||||||
this.colorCount = colorModel instanceof IndexColorModel ? ((IndexColorModel) colorModel).getMapSize() : 0;
|
|
||||||
this.planes = 1;
|
|
||||||
this.bitCount = colorModel.getPixelSize();
|
|
||||||
this.size = size;
|
|
||||||
this.offset = offset;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+20
-21
@@ -4,28 +4,26 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
@@ -49,4 +47,5 @@ public final class ICOImageReader extends DIBImageReader {
|
|||||||
protected ICOImageReader(final ImageReaderSpi pProvider) {
|
protected ICOImageReader(final ImageReaderSpi pProvider) {
|
||||||
super(pProvider);
|
super(pProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-21
@@ -4,28 +4,26 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|||||||
-327
@@ -1,327 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2017, Harald Kuhr
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * 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.
|
|
||||||
*
|
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
|
||||||
|
|
||||||
import com.twelvemonkeys.imageio.stream.SubImageOutputStream;
|
|
||||||
import com.twelvemonkeys.imageio.util.ProgressListenerBase;
|
|
||||||
|
|
||||||
import javax.imageio.*;
|
|
||||||
import javax.imageio.event.IIOWriteWarningListener;
|
|
||||||
import javax.imageio.metadata.IIOMetadata;
|
|
||||||
import javax.imageio.spi.ImageWriterSpi;
|
|
||||||
import javax.imageio.stream.ImageInputStream;
|
|
||||||
import javax.imageio.stream.ImageOutputStream;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.awt.image.ColorModel;
|
|
||||||
import java.awt.image.RenderedImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import static com.twelvemonkeys.imageio.plugins.bmp.DirectoryEntry.ICOEntry;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ImageWriter implementation for Windows Icon (ICO) format.
|
|
||||||
*/
|
|
||||||
public final class ICOImageWriter extends DIBImageWriter {
|
|
||||||
|
|
||||||
// TODO: Support appending/updating an existing ICO file?
|
|
||||||
// - canInsertImage/canRemoveImage
|
|
||||||
|
|
||||||
private static final int ENTRY_SIZE = 16;
|
|
||||||
private static final int ICO_MAX_DIMENSION = 256;
|
|
||||||
private static final int INITIAL_ENTRY_COUNT = 8;
|
|
||||||
|
|
||||||
private int sequenceIndex = -1;
|
|
||||||
|
|
||||||
private ImageWriter pngDelegate;
|
|
||||||
|
|
||||||
protected ICOImageWriter(final ImageWriterSpi provider) {
|
|
||||||
super(provider);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void resetMembers() {
|
|
||||||
sequenceIndex = -1;
|
|
||||||
|
|
||||||
if (pngDelegate != null) {
|
|
||||||
pngDelegate.dispose();
|
|
||||||
pngDelegate = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IIOMetadata getDefaultImageMetadata(final ImageTypeSpecifier imageType, final ImageWriteParam param) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IIOMetadata convertImageMetadata(final IIOMetadata inData, final ImageTypeSpecifier imageType, final ImageWriteParam param) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(final IIOMetadata streamMetadata, final IIOImage image, final ImageWriteParam param) throws IOException {
|
|
||||||
prepareWriteSequence(streamMetadata);
|
|
||||||
writeToSequence(image, param);
|
|
||||||
endWriteSequence();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canWriteSequence() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void prepareWriteSequence(final IIOMetadata streamMetadata) throws IOException {
|
|
||||||
assertOutput();
|
|
||||||
|
|
||||||
if (sequenceIndex >= 0) {
|
|
||||||
throw new IllegalStateException("writeSequence already started");
|
|
||||||
}
|
|
||||||
|
|
||||||
writeICOHeader();
|
|
||||||
|
|
||||||
// Count: Needs to be updated for each new image
|
|
||||||
imageOutput.writeShort(0);
|
|
||||||
sequenceIndex = 0;
|
|
||||||
|
|
||||||
// TODO: Allow passing the initial size of the directory in the stream metadata?
|
|
||||||
// - as this is much more efficient than growing...
|
|
||||||
// How do we update the "image directory" containing "image entries",
|
|
||||||
// and which must be written *before* the image data?
|
|
||||||
// - Allocate a block of N * 16 bytes
|
|
||||||
// - If image count % N > N, we need to move the first image backwards in the file and allocate another N items...
|
|
||||||
imageOutput.write(new byte[INITIAL_ENTRY_COUNT * ENTRY_SIZE]); // Allocate room for 8 entries for now
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void endWriteSequence() throws IOException {
|
|
||||||
assertOutput();
|
|
||||||
|
|
||||||
if (sequenceIndex < 0) {
|
|
||||||
throw new IllegalStateException("prepareWriteSequence not called");
|
|
||||||
}
|
|
||||||
|
|
||||||
sequenceIndex = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToSequence(final IIOImage image, final ImageWriteParam param) throws IOException {
|
|
||||||
assertOutput();
|
|
||||||
|
|
||||||
if (sequenceIndex < 0) {
|
|
||||||
throw new IllegalStateException("prepareWriteSequence not called");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (image.hasRaster()) {
|
|
||||||
throw new UnsupportedOperationException("Raster not supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sequenceIndex >= INITIAL_ENTRY_COUNT) {
|
|
||||||
growIfNecessary();
|
|
||||||
}
|
|
||||||
|
|
||||||
int width = image.getRenderedImage().getWidth();
|
|
||||||
int height = image.getRenderedImage().getHeight();
|
|
||||||
ColorModel colorModel = image.getRenderedImage().getColorModel();
|
|
||||||
|
|
||||||
// TODO: The output size may depend on the param (subsampling, source region, etc)
|
|
||||||
if (width > ICO_MAX_DIMENSION || height > ICO_MAX_DIMENSION) {
|
|
||||||
throw new IIOException(String.format("ICO maximum width or height (%d) exceeded", ICO_MAX_DIMENSION));
|
|
||||||
}
|
|
||||||
|
|
||||||
long imageOffset = imageOutput.getStreamPosition();
|
|
||||||
|
|
||||||
if (imageOffset > Integer.MAX_VALUE) {
|
|
||||||
throw new IIOException("ICO file too large");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Uncompressed, RLE4/RLE8 or PNG compressed
|
|
||||||
boolean pngCompression = param != null && "BI_PNG".equals(param.getCompressionType());
|
|
||||||
|
|
||||||
processImageStarted(sequenceIndex);
|
|
||||||
|
|
||||||
if (pngCompression) {
|
|
||||||
// NOTE: Embedding a PNG in a ICO is slightly different than a BMP with BI_PNG compression,
|
|
||||||
// so we'll just handle it directly
|
|
||||||
ImageWriter writer = getPNGDelegate();
|
|
||||||
writer.setOutput(new SubImageOutputStream(imageOutput));
|
|
||||||
writer.write(null, image, copyParam(param, writer));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
RenderedImage img = image.getRenderedImage();
|
|
||||||
// ICO needs height to include height of mask, even if mask isn't written
|
|
||||||
writeDIBHeader(DIB.BITMAP_INFO_HEADER_SIZE, img.getWidth(), img.getHeight() * 2,
|
|
||||||
false, img.getColorModel().getPixelSize(), DIB.COMPRESSION_RGB);
|
|
||||||
writeUncompressed(false, (BufferedImage) img, img.getWidth(), img.getHeight());
|
|
||||||
// TODO: Write mask
|
|
||||||
imageOutput.write(new byte[((width * height + 31) / 32) * 4]);
|
|
||||||
// writeUncompressed(false, new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY), img.getWidth(), img.getHeight());
|
|
||||||
}
|
|
||||||
|
|
||||||
processImageComplete();
|
|
||||||
|
|
||||||
long nextPosition = imageOutput.getStreamPosition();
|
|
||||||
|
|
||||||
// Update count
|
|
||||||
imageOutput.seek(4);
|
|
||||||
imageOutput.writeShort(sequenceIndex + 1);
|
|
||||||
|
|
||||||
// Write entry
|
|
||||||
int entryPosition = 6 + sequenceIndex * ENTRY_SIZE;
|
|
||||||
imageOutput.seek(entryPosition);
|
|
||||||
|
|
||||||
long size = nextPosition - imageOffset;
|
|
||||||
writeEntry(width, height, colorModel, (int) size, (int) imageOffset);
|
|
||||||
|
|
||||||
sequenceIndex++;
|
|
||||||
|
|
||||||
imageOutput.seek(nextPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeICOHeader() throws IOException {
|
|
||||||
if (imageOutput.getStreamPosition() != 0) {
|
|
||||||
throw new IllegalStateException("Stream already written to");
|
|
||||||
}
|
|
||||||
|
|
||||||
imageOutput.writeShort(0);
|
|
||||||
imageOutput.writeShort(DIB.TYPE_ICO);
|
|
||||||
imageOutput.flushBefore(imageOutput.getStreamPosition());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void growIfNecessary() {
|
|
||||||
// TODO: Allow growing the directory index...
|
|
||||||
// Move the first icon to the back, update offset
|
|
||||||
throw new IllegalStateException(String.format("Maximum number of icons supported (%d) exceeded", INITIAL_ENTRY_COUNT));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ImageWriteParam getDefaultWriteParam() {
|
|
||||||
return new ICOImageWriteParam(getLocale());
|
|
||||||
}
|
|
||||||
|
|
||||||
private ImageWriteParam copyParam(final ImageWriteParam param, ImageWriter writer) {
|
|
||||||
if (param == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageWriteParam writeParam = writer.getDefaultWriteParam();
|
|
||||||
writeParam.setSourceSubsampling(param.getSourceXSubsampling(), param.getSourceYSubsampling(), param.getSubsamplingXOffset(), param.getSubsamplingYOffset());
|
|
||||||
writeParam.setSourceRegion(param.getSourceRegion());
|
|
||||||
writeParam.setSourceBands(param.getSourceBands());
|
|
||||||
|
|
||||||
return writeParam;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ImageWriter getPNGDelegate() {
|
|
||||||
if (pngDelegate == null) {
|
|
||||||
// There's always a PNG writer...
|
|
||||||
pngDelegate = ImageIO.getImageWritersByFormatName("PNG").next();
|
|
||||||
pngDelegate.setLocale(getLocale());
|
|
||||||
pngDelegate.addIIOWriteProgressListener(new ProgressListenerBase() {
|
|
||||||
@Override
|
|
||||||
public void imageProgress(ImageWriter source, float percentageDone) {
|
|
||||||
processImageProgress(percentageDone);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeAborted(ImageWriter source) {
|
|
||||||
processWriteAborted();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
pngDelegate.addIIOWriteWarningListener(new IIOWriteWarningListener() {
|
|
||||||
@Override
|
|
||||||
public void warningOccurred(ImageWriter source, int imageIndex, String warning) {
|
|
||||||
processWarningOccurred(sequenceIndex, warning);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return pngDelegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeEntry(final int width, final int height, final ColorModel colorModel, int size, final int offset) throws IOException {
|
|
||||||
new ICOEntry(width, height, colorModel, size, offset)
|
|
||||||
.write(imageOutput);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
|
||||||
boolean pngCompression = false;
|
|
||||||
int firstArg = 0;
|
|
||||||
|
|
||||||
while (args.length > firstArg && args[firstArg].charAt(0) == '-') {
|
|
||||||
if (args[firstArg].equals("-p") || args[firstArg].equals("--png")) {
|
|
||||||
pngCompression = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
firstArg++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.length - firstArg < 2) {
|
|
||||||
System.err.println("Usage: command [-p|--png] <output.ico> <input> [<input>...]");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
try (ImageOutputStream out = ImageIO.createImageOutputStream(new File(args[firstArg++]))) {
|
|
||||||
ImageWriter writer = new ICOImageWriter(null);
|
|
||||||
writer.setOutput(out);
|
|
||||||
|
|
||||||
ImageWriteParam param = writer.getDefaultWriteParam();
|
|
||||||
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
|
||||||
param.setCompressionType(pngCompression ? "BI_PNG" : "BI_RGB");
|
|
||||||
|
|
||||||
writer.prepareWriteSequence(null);
|
|
||||||
|
|
||||||
for (int i = firstArg; i < args.length; i++) {
|
|
||||||
File inFile = new File(args[i]);
|
|
||||||
try (ImageInputStream input = ImageIO.createImageInputStream(inFile)) {
|
|
||||||
Iterator<ImageReader> readers = ImageIO.getImageReaders(input);
|
|
||||||
|
|
||||||
if (!readers.hasNext()) {
|
|
||||||
System.err.printf("Can't read %s\n", inFile.getAbsolutePath());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ImageReader reader = readers.next();
|
|
||||||
reader.setInput(input);
|
|
||||||
for (int j = 0; j < reader.getNumImages(true); j++) {
|
|
||||||
IIOImage image = reader.readAll(j, null);
|
|
||||||
writer.writeToSequence(image, param);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
writer.endWriteSequence();
|
|
||||||
writer.dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+25
-30
@@ -1,31 +1,29 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017, Harald Kuhr
|
* Copyright (c) 2015, Harald Kuhr
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
@@ -33,14 +31,14 @@ package com.twelvemonkeys.imageio.plugins.bmp;
|
|||||||
import com.twelvemonkeys.imageio.spi.ReaderWriterProviderInfo;
|
import com.twelvemonkeys.imageio.spi.ReaderWriterProviderInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ICOProviderInfo.
|
* CURProviderInfo.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||||
* @author last modified by $Author: harald.kuhr$
|
* @author last modified by $Author: harald.kuhr$
|
||||||
* @version $Id: ICOProviderInfo.java,v 1.0 20/03/15 harald.kuhr Exp$
|
* @version $Id: CURProviderInfo.java,v 1.0 20/03/15 harald.kuhr Exp$
|
||||||
*/
|
*/
|
||||||
final class ICOProviderInfo extends ReaderWriterProviderInfo {
|
final class ICOProviderInfo extends ReaderWriterProviderInfo {
|
||||||
ICOProviderInfo() {
|
protected ICOProviderInfo() {
|
||||||
super(
|
super(
|
||||||
ICOProviderInfo.class,
|
ICOProviderInfo.class,
|
||||||
new String[]{"ico", "ICO"},
|
new String[]{"ico", "ICO"},
|
||||||
@@ -52,12 +50,9 @@ final class ICOProviderInfo extends ReaderWriterProviderInfo {
|
|||||||
},
|
},
|
||||||
"com.twelvemonkeys.imageio.plugins.bmp.ICOImageReader",
|
"com.twelvemonkeys.imageio.plugins.bmp.ICOImageReader",
|
||||||
new String[] {"com.twelvemonkeys.imageio.plugins.bmp.ICOImageReaderSpi"},
|
new String[] {"com.twelvemonkeys.imageio.plugins.bmp.ICOImageReaderSpi"},
|
||||||
"com.twelvemonkeys.imageio.plugins.bmp.ICOImageWriter",
|
|
||||||
new String[] {"com.twelvemonkeys.imageio.plugins.bmp.ICOImageWriterSpi"},
|
|
||||||
false, null, null,
|
|
||||||
null, null,
|
null, null,
|
||||||
true, null, null,
|
false, null, null, null, null,
|
||||||
null, null
|
true, null, null, null, null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-26
@@ -4,34 +4,33 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,8 +40,8 @@ import java.util.Arrays;
|
|||||||
* @version $Id: RLE4Decoder.java#1 $
|
* @version $Id: RLE4Decoder.java#1 $
|
||||||
*/
|
*/
|
||||||
final class RLE4Decoder extends AbstractRLEDecoder {
|
final class RLE4Decoder extends AbstractRLEDecoder {
|
||||||
final static int[] BIT_MASKS = {0xf0, 0x0f};
|
final static int BIT_MASKS[] = {0xf0, 0x0f};
|
||||||
final static int[] BIT_SHIFTS = {4, 0};
|
final static int BIT_SHIFTS[] = {4, 0};
|
||||||
|
|
||||||
public RLE4Decoder(final int width) {
|
public RLE4Decoder(final int width) {
|
||||||
super(width, 4);
|
super(width, 4);
|
||||||
@@ -94,7 +93,7 @@ final class RLE4Decoder extends AbstractRLEDecoder {
|
|||||||
boolean paddingByte = (((byte2 + 1) / 2) % 2) != 0;
|
boolean paddingByte = (((byte2 + 1) / 2) % 2) != 0;
|
||||||
|
|
||||||
int packed = 0;
|
int packed = 0;
|
||||||
for (int i = 0; i < byte2 && srcX / 2 < row.length; i++) {
|
for (int i = 0; i < byte2; i++) {
|
||||||
if (i % 2 == 0) {
|
if (i % 2 == 0) {
|
||||||
packed = checkEOF(stream.read());
|
packed = checkEOF(stream.read());
|
||||||
}
|
}
|
||||||
@@ -111,7 +110,7 @@ final class RLE4Decoder extends AbstractRLEDecoder {
|
|||||||
else {
|
else {
|
||||||
// Encoded mode
|
// Encoded mode
|
||||||
// Replicate the two samples in byte2 as many times as byte1 says
|
// Replicate the two samples in byte2 as many times as byte1 says
|
||||||
for (int i = 0; i < byte1 && srcX / 2 < row.length; i++) {
|
for (int i = 0; i < byte1; i++) {
|
||||||
row[srcX / 2] |= (byte) (((byte2 & BIT_MASKS[i % 2]) >> BIT_SHIFTS[i % 2]) << BIT_SHIFTS[srcX % 2]);
|
row[srcX / 2] |= (byte) (((byte2 & BIT_MASKS[i % 2]) >> BIT_SHIFTS[i % 2]) << BIT_SHIFTS[srcX % 2]);
|
||||||
srcX++;
|
srcX++;
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-24
@@ -4,34 +4,32 @@
|
|||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * 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.
|
||||||
|
* * Neither the name "TwelveMonkeys" nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* list of conditions and the following disclaimer.
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
*
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* and/or other materials provided with the distribution.
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
*
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* contributors may be used to endorse or promote products derived from
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* this software without specific prior written permission.
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
*
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,7 +92,7 @@ final class RLE8Decoder extends AbstractRLEDecoder {
|
|||||||
// an additional padding byte is in the stream and must be skipped
|
// an additional padding byte is in the stream and must be skipped
|
||||||
boolean paddingByte = (byte2 % 2) != 0;
|
boolean paddingByte = (byte2 % 2) != 0;
|
||||||
|
|
||||||
while (byte2-- > 0 && srcX < row.length) {
|
while (byte2-- > 0) {
|
||||||
row[srcX++] = (byte) checkEOF(stream.read());
|
row[srcX++] = (byte) checkEOF(stream.read());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +105,7 @@ final class RLE8Decoder extends AbstractRLEDecoder {
|
|||||||
// Encoded mode
|
// Encoded mode
|
||||||
// Replicate byte2 as many times as byte1 says
|
// Replicate byte2 as many times as byte1 says
|
||||||
byte value = (byte) byte2;
|
byte value = (byte) byte2;
|
||||||
while (byte1-- > 0 && srcX < row.length) {
|
while (byte1-- > 0) {
|
||||||
row[srcX++] = value;
|
row[srcX++] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-29
@@ -1,32 +1,3 @@
|
|||||||
#
|
|
||||||
# Copyright (c) 2017, Harald Kuhr
|
|
||||||
# All rights reserved.
|
|
||||||
#
|
|
||||||
# Redistribution and use in source and binary forms, with or without
|
|
||||||
# modification, are permitted provided that the following conditions are met:
|
|
||||||
#
|
|
||||||
# * Redistributions of source code must retain the above copyright notice, this
|
|
||||||
# list of conditions and the following disclaimer.
|
|
||||||
#
|
|
||||||
# * 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.
|
|
||||||
#
|
|
||||||
# * Neither the name of the copyright holder nor the names of its
|
|
||||||
# contributors may be used to endorse or promote products derived from
|
|
||||||
# this software without specific prior written permission.
|
|
||||||
#
|
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
|
|
||||||
com.twelvemonkeys.imageio.plugins.bmp.BMPImageReaderSpi
|
com.twelvemonkeys.imageio.plugins.bmp.BMPImageReaderSpi
|
||||||
com.twelvemonkeys.imageio.plugins.bmp.CURImageReaderSpi
|
com.twelvemonkeys.imageio.plugins.bmp.CURImageReaderSpi
|
||||||
com.twelvemonkeys.imageio.plugins.bmp.ICOImageReaderSpi
|
com.twelvemonkeys.imageio.plugins.bmp.ICOImageReaderSpi
|
||||||
|
|||||||
-31
@@ -1,31 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright (c) 2017, Harald Kuhr
|
|
||||||
# All rights reserved.
|
|
||||||
#
|
|
||||||
# Redistribution and use in source and binary forms, with or without
|
|
||||||
# modification, are permitted provided that the following conditions are met:
|
|
||||||
#
|
|
||||||
# * Redistributions of source code must retain the above copyright notice, this
|
|
||||||
# list of conditions and the following disclaimer.
|
|
||||||
#
|
|
||||||
# * 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.
|
|
||||||
#
|
|
||||||
# * Neither the name of the copyright holder nor the names of its
|
|
||||||
# contributors may be used to endorse or promote products derived from
|
|
||||||
# this software without specific prior written permission.
|
|
||||||
#
|
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
|
|
||||||
com.twelvemonkeys.imageio.plugins.bmp.BMPImageWriterSpi
|
|
||||||
com.twelvemonkeys.imageio.plugins.bmp.ICOImageWriterSpi
|
|
||||||
+55
-103
@@ -1,72 +1,32 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2009, Harald Kuhr
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * 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.
|
|
||||||
*
|
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||||
import static org.junit.Assume.assumeNoException;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyFloat;
|
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
|
||||||
import static org.mockito.Mockito.atLeastOnce;
|
|
||||||
import static org.mockito.Mockito.inOrder;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.imageio.IIOException;
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import javax.imageio.ImageReadParam;
|
|
||||||
import javax.imageio.ImageReader;
|
|
||||||
import javax.imageio.ImageTypeSpecifier;
|
|
||||||
import javax.imageio.event.IIOReadProgressListener;
|
|
||||||
import javax.imageio.metadata.IIOMetadata;
|
|
||||||
import javax.imageio.metadata.IIOMetadataNode;
|
|
||||||
import javax.imageio.spi.ImageReaderSpi;
|
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.InOrder;
|
import org.mockito.InOrder;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
import javax.imageio.*;
|
||||||
import com.twelvemonkeys.xml.XMLSerializer;
|
import javax.imageio.event.IIOReadProgressListener;
|
||||||
|
import javax.imageio.metadata.IIOMetadata;
|
||||||
|
import javax.imageio.metadata.IIOMetadataNode;
|
||||||
|
import javax.imageio.spi.ImageReaderSpi;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.junit.Assume.assumeNoException;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
|
import static org.mockito.Matchers.eq;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BMPImageReaderTest
|
* BMPImageReaderTest
|
||||||
@@ -76,12 +36,6 @@ import com.twelvemonkeys.xml.XMLSerializer;
|
|||||||
* @version $Id: BMPImageReaderTest.java,v 1.0 Apr 1, 2008 10:39:17 PM haraldk Exp$
|
* @version $Id: BMPImageReaderTest.java,v 1.0 Apr 1, 2008 10:39:17 PM haraldk Exp$
|
||||||
*/
|
*/
|
||||||
public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader> {
|
public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader> {
|
||||||
@Override
|
|
||||||
protected ImageReaderSpi createProvider() {
|
|
||||||
return new BMPImageReaderSpi();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<TestData> getTestData() {
|
protected List<TestData> getTestData() {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
// BMP Suite "Good"
|
// BMP Suite "Good"
|
||||||
@@ -158,17 +112,27 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected ImageReaderSpi createProvider() {
|
||||||
|
return new BMPImageReaderSpi();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
protected BMPImageReader createReader() {
|
||||||
|
return new BMPImageReader(createProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Class<BMPImageReader> getReaderClass() {
|
||||||
|
return BMPImageReader.class;
|
||||||
|
}
|
||||||
|
|
||||||
protected List<String> getFormatNames() {
|
protected List<String> getFormatNames() {
|
||||||
return Collections.singletonList("bmp");
|
return Collections.singletonList("bmp");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<String> getSuffixes() {
|
protected List<String> getSuffixes() {
|
||||||
return Arrays.asList("bmp", "rle");
|
return Arrays.asList("bmp", "rle");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<String> getMIMETypes() {
|
protected List<String> getMIMETypes() {
|
||||||
return Collections.singletonList("image/bmp");
|
return Collections.singletonList("image/bmp");
|
||||||
}
|
}
|
||||||
@@ -182,7 +146,7 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
|||||||
|
|
||||||
ImageTypeSpecifier rawType = reader.getRawImageType(0);
|
ImageTypeSpecifier rawType = reader.getRawImageType(0);
|
||||||
|
|
||||||
// As the JPEGImageReader we delegate to may return null for YCbCr, we'll have to do the same
|
// As the JPEGImageReader we delegate to returns null for YCbCr, we'll have to do the same
|
||||||
if (rawType == null && data.getInput().toString().contains("jpeg")) {
|
if (rawType == null && data.getInput().toString().contains("jpeg")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -277,7 +241,7 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddIIOReadProgressListenerCallbacksJPEG() throws IOException {
|
public void testAddIIOReadProgressListenerCallbacksJPEG() {
|
||||||
ImageReader reader = createReader();
|
ImageReader reader = createReader();
|
||||||
TestData data = new TestData(getClassLoaderResource("/bmpsuite/q/rgb24jpeg.bmp"), new Dimension(127, 64));
|
TestData data = new TestData(getClassLoaderResource("/bmpsuite/q/rgb24jpeg.bmp"), new Dimension(127, 64));
|
||||||
reader.setInput(data.getInputStream());
|
reader.setInput(data.getInputStream());
|
||||||
@@ -295,12 +259,12 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
|||||||
// At least imageStarted and imageComplete, plus any number of imageProgress
|
// At least imageStarted and imageComplete, plus any number of imageProgress
|
||||||
InOrder ordered = inOrder(listener);
|
InOrder ordered = inOrder(listener);
|
||||||
ordered.verify(listener).imageStarted(reader, 0);
|
ordered.verify(listener).imageStarted(reader, 0);
|
||||||
ordered.verify(listener, atLeastOnce()).imageProgress(eq(reader), anyFloat());
|
ordered.verify(listener, atLeastOnce()).imageProgress(eq(reader), anyInt());
|
||||||
ordered.verify(listener).imageComplete(reader);
|
ordered.verify(listener).imageComplete(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddIIOReadProgressListenerCallbacksPNG() throws IOException {
|
public void testAddIIOReadProgressListenerCallbacksPNG() {
|
||||||
ImageReader reader = createReader();
|
ImageReader reader = createReader();
|
||||||
TestData data = new TestData(getClassLoaderResource("/bmpsuite/q/rgb24png.bmp"), new Dimension(127, 64));
|
TestData data = new TestData(getClassLoaderResource("/bmpsuite/q/rgb24png.bmp"), new Dimension(127, 64));
|
||||||
reader.setInput(data.getInputStream());
|
reader.setInput(data.getInputStream());
|
||||||
@@ -318,12 +282,12 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
|||||||
// At least imageStarted and imageComplete, plus any number of imageProgress
|
// At least imageStarted and imageComplete, plus any number of imageProgress
|
||||||
InOrder ordered = inOrder(listener);
|
InOrder ordered = inOrder(listener);
|
||||||
ordered.verify(listener).imageStarted(reader, 0);
|
ordered.verify(listener).imageStarted(reader, 0);
|
||||||
ordered.verify(listener, atLeastOnce()).imageProgress(eq(reader), anyFloat());
|
ordered.verify(listener, atLeastOnce()).imageProgress(eq(reader), anyInt());
|
||||||
ordered.verify(listener).imageComplete(reader);
|
ordered.verify(listener).imageComplete(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMetadataEqualsJRE() throws IOException {
|
public void testMetadataEqualsJRE() throws IOException, URISyntaxException {
|
||||||
ImageReader jreReader;
|
ImageReader jreReader;
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -342,7 +306,6 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
|||||||
|
|
||||||
for (TestData data : getTestData()) {
|
for (TestData data : getTestData()) {
|
||||||
if (data.getInput().toString().contains("pal8offs")) {
|
if (data.getInput().toString().contains("pal8offs")) {
|
||||||
// Skip: Contains extra bogus PaletteEntry nodes
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,10 +322,9 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
|||||||
System.err.println("WARNING: Reading " + data + " caused exception: " + e.getMessage());
|
System.err.println("WARNING: Reading " + data + " caused exception: " + e.getMessage());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
IIOMetadata jreMetadata = jreReader.getImageMetadata(0);
|
IIOMetadata jreMetadata = jreReader.getImageMetadata(0);
|
||||||
|
|
||||||
assertTrue(metadata.isStandardMetadataFormatSupported());
|
assertEquals(true, metadata.isStandardMetadataFormatSupported());
|
||||||
assertEquals(jreMetadata.getNativeMetadataFormatName(), metadata.getNativeMetadataFormatName());
|
assertEquals(jreMetadata.getNativeMetadataFormatName(), metadata.getNativeMetadataFormatName());
|
||||||
assertArrayEquals(jreMetadata.getExtraMetadataFormatNames(), metadata.getExtraMetadataFormatNames());
|
assertArrayEquals(jreMetadata.getExtraMetadataFormatNames(), metadata.getExtraMetadataFormatNames());
|
||||||
|
|
||||||
@@ -372,24 +334,23 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
|||||||
String absolutePath = data.toString();
|
String absolutePath = data.toString();
|
||||||
String localPath = absolutePath.substring(absolutePath.lastIndexOf("test-classes") + 12);
|
String localPath = absolutePath.substring(absolutePath.lastIndexOf("test-classes") + 12);
|
||||||
|
|
||||||
// TODO: blauesglas_16_bitmask444 fails BMP Version for 11+
|
|
||||||
Node expectedTree = jreMetadata.getAsTree(format);
|
Node expectedTree = jreMetadata.getAsTree(format);
|
||||||
Node actualTree = metadata.getAsTree(format);
|
Node actualTree = metadata.getAsTree(format);
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
assertNodeEquals(localPath + " - " + format, expectedTree, actualTree);
|
assertNodeEquals(localPath + " - " + format, expectedTree, actualTree);
|
||||||
}
|
// }
|
||||||
catch (AssertionError e) {
|
// catch (AssertionError e) {
|
||||||
ByteArrayOutputStream expected = new ByteArrayOutputStream();
|
// ByteArrayOutputStream expected = new ByteArrayOutputStream();
|
||||||
ByteArrayOutputStream actual = new ByteArrayOutputStream();
|
// ByteArrayOutputStream actual = new ByteArrayOutputStream();
|
||||||
|
//
|
||||||
new XMLSerializer(expected, "UTF-8").serialize(expectedTree, false);
|
// new XMLSerializer(expected, "UTF-8").serialize(expectedTree, false);
|
||||||
new XMLSerializer(actual, "UTF-8").serialize(actualTree, false);
|
// new XMLSerializer(actual, "UTF-8").serialize(actualTree, false);
|
||||||
|
//
|
||||||
assertEquals(e.getMessage(), new String(expected.toByteArray(), StandardCharsets.UTF_8), new String(actual.toByteArray(), StandardCharsets.UTF_8));
|
// assertEquals(e.getMessage(), new String(expected.toByteArray(), "UTF-8"), new String(actual.toByteArray(), "UTF-8"));
|
||||||
|
//
|
||||||
throw e;
|
// throw e;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -411,27 +372,18 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
|||||||
NodeList expectedChildNodes = expected.getChildNodes();
|
NodeList expectedChildNodes = expected.getChildNodes();
|
||||||
NodeList actualChildNodes = actual.getChildNodes();
|
NodeList actualChildNodes = actual.getChildNodes();
|
||||||
|
|
||||||
assertTrue(message + " child length differs: " + toString(expectedChildNodes) + " != " + toString(actualChildNodes),
|
assertEquals(message + " child length differs: " + toString(expectedChildNodes) + " != " + toString(actualChildNodes),
|
||||||
expectedChildNodes.getLength() <= actualChildNodes.getLength());
|
expectedChildNodes.getLength(), actualChildNodes.getLength());
|
||||||
|
|
||||||
for (int i = 0; i < expectedChildNodes.getLength(); i++) {
|
for (int i = 0; i < expectedChildNodes.getLength(); i++) {
|
||||||
Node expectedChild = expectedChildNodes.item(i);
|
Node expectedChild = expectedChildNodes.item(i);
|
||||||
|
|
||||||
Node actualChild = actualChildNodes.item(i);
|
Node actualChild = actualChildNodes.item(i);
|
||||||
|
|
||||||
for (int j = 0; j < actualChildNodes.getLength(); j++) {
|
|
||||||
if (actualChildNodes.item(j).getLocalName().equals(expectedChild.getLocalName())) {
|
|
||||||
actualChild = actualChildNodes.item(j);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(message + " node name differs", expectedChild.getLocalName(), actualChild.getLocalName());
|
assertEquals(message + " node name differs", expectedChild.getLocalName(), actualChild.getLocalName());
|
||||||
assertNodeEquals(message + "/" + expectedChild.getLocalName(), expectedChild, actualChild);
|
assertNodeEquals(message + "/" + expectedChild.getLocalName(), expectedChild, actualChild);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("RedundantIfStatement")
|
|
||||||
private boolean excludeEqualValueTest(final Node expected) {
|
private boolean excludeEqualValueTest(final Node expected) {
|
||||||
if (expected.getLocalName().equals("ImageSize")) {
|
if (expected.getLocalName().equals("ImageSize")) {
|
||||||
// JRE metadata returns 0, even if known in reader...
|
// JRE metadata returns 0, even if known in reader...
|
||||||
|
|||||||
-30
@@ -1,30 +0,0 @@
|
|||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
|
||||||
|
|
||||||
import com.twelvemonkeys.imageio.util.ImageWriterAbstractTest;
|
|
||||||
|
|
||||||
import javax.imageio.spi.ImageWriterSpi;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.awt.image.RenderedImage;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BMPImageWriterTest.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
|
||||||
* @author last modified by : harald.kuhr$
|
|
||||||
* @version : BMPImageWriterTest.java,v 1.0 25/06/2020 harald.kuhr Exp$
|
|
||||||
*/
|
|
||||||
public class BMPImageWriterTest extends ImageWriterAbstractTest<BMPImageWriter> {
|
|
||||||
@Override
|
|
||||||
protected ImageWriterSpi createProvider() {
|
|
||||||
return new BMPImageWriterSpi();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<? extends RenderedImage> getTestData() {
|
|
||||||
return Collections.singletonList(
|
|
||||||
new BufferedImage(10, 10, BufferedImage.TYPE_4BYTE_ABGR)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-30
@@ -1,33 +1,3 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, Harald Kuhr
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * 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.
|
|
||||||
*
|
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|
||||||
import com.twelvemonkeys.imageio.spi.ReaderWriterProviderInfo;
|
import com.twelvemonkeys.imageio.spi.ReaderWriterProviderInfo;
|
||||||
|
|||||||
+13
-40
@@ -1,37 +1,6 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2009, Harald Kuhr
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * 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.
|
|
||||||
*
|
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|
||||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -54,12 +23,6 @@ import static org.junit.Assert.*;
|
|||||||
* @version $Id: CURImageReaderTest.java,v 1.0 Apr 1, 2008 10:39:17 PM haraldk Exp$
|
* @version $Id: CURImageReaderTest.java,v 1.0 Apr 1, 2008 10:39:17 PM haraldk Exp$
|
||||||
*/
|
*/
|
||||||
public class CURImageReaderTest extends ImageReaderAbstractTest<CURImageReader> {
|
public class CURImageReaderTest extends ImageReaderAbstractTest<CURImageReader> {
|
||||||
@Override
|
|
||||||
protected ImageReaderSpi createProvider() {
|
|
||||||
return new CURImageReaderSpi();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<TestData> getTestData() {
|
protected List<TestData> getTestData() {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
new TestData(getClassLoaderResource("/cur/hand.cur"), new Dimension(32, 32)),
|
new TestData(getClassLoaderResource("/cur/hand.cur"), new Dimension(32, 32)),
|
||||||
@@ -67,17 +30,27 @@ public class CURImageReaderTest extends ImageReaderAbstractTest<CURImageReader>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected ImageReaderSpi createProvider() {
|
||||||
|
return new CURImageReaderSpi();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
protected CURImageReader createReader() {
|
||||||
|
return new CURImageReader();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Class<CURImageReader> getReaderClass() {
|
||||||
|
return CURImageReader.class;
|
||||||
|
}
|
||||||
|
|
||||||
protected List<String> getFormatNames() {
|
protected List<String> getFormatNames() {
|
||||||
return Collections.singletonList("cur");
|
return Collections.singletonList("cur");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<String> getSuffixes() {
|
protected List<String> getSuffixes() {
|
||||||
return Collections.singletonList("cur");
|
return Collections.singletonList("cur");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<String> getMIMETypes() {
|
protected List<String> getMIMETypes() {
|
||||||
return Arrays.asList("image/vnd.microsoft.cursor", "image/cursor", "image/x-cursor");
|
return Arrays.asList("image/vnd.microsoft.cursor", "image/cursor", "image/x-cursor");
|
||||||
}
|
}
|
||||||
@@ -96,7 +69,7 @@ public class CURImageReaderTest extends ImageReaderAbstractTest<CURImageReader>
|
|||||||
assertNotNull("Hotspot for cursor not present", hotspot);
|
assertNotNull("Hotspot for cursor not present", hotspot);
|
||||||
|
|
||||||
// Image weirdness
|
// Image weirdness
|
||||||
assertNotSame("Hotspot for cursor undefined (java.awt.Image.UndefinedProperty)", Image.UndefinedProperty, hotspot);
|
assertTrue("Hotspot for cursor undefined (java.awt.Image.UndefinedProperty)", Image.UndefinedProperty != hotspot);
|
||||||
|
|
||||||
assertTrue(String.format("Hotspot not a java.awt.Point: %s", hotspot.getClass()), hotspot instanceof Point);
|
assertTrue(String.format("Hotspot not a java.awt.Point: %s", hotspot.getClass()), hotspot instanceof Point);
|
||||||
assertEquals(pExpected, hotspot);
|
assertEquals(pExpected, hotspot);
|
||||||
|
|||||||
-30
@@ -1,33 +1,3 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, Harald Kuhr
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * 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.
|
|
||||||
*
|
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|
||||||
import com.twelvemonkeys.imageio.spi.ReaderWriterProviderInfo;
|
import com.twelvemonkeys.imageio.spi.ReaderWriterProviderInfo;
|
||||||
|
|||||||
+12
-39
@@ -1,37 +1,6 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2009, Harald Kuhr
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * 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.
|
|
||||||
*
|
|
||||||
* * Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
package com.twelvemonkeys.imageio.plugins.bmp;
|
||||||
|
|
||||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -50,12 +19,6 @@ import java.util.List;
|
|||||||
* @version $Id: ICOImageReaderTest.java,v 1.0 Apr 1, 2008 10:39:17 PM haraldk Exp$
|
* @version $Id: ICOImageReaderTest.java,v 1.0 Apr 1, 2008 10:39:17 PM haraldk Exp$
|
||||||
*/
|
*/
|
||||||
public class ICOImageReaderTest extends ImageReaderAbstractTest<ICOImageReader> {
|
public class ICOImageReaderTest extends ImageReaderAbstractTest<ICOImageReader> {
|
||||||
@Override
|
|
||||||
protected ImageReaderSpi createProvider() {
|
|
||||||
return new ICOImageReaderSpi();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<TestData> getTestData() {
|
protected List<TestData> getTestData() {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
new TestData(
|
new TestData(
|
||||||
@@ -82,17 +45,27 @@ public class ICOImageReaderTest extends ImageReaderAbstractTest<ICOImageReader>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected ImageReaderSpi createProvider() {
|
||||||
|
return new ICOImageReaderSpi();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
protected ICOImageReader createReader() {
|
||||||
|
return new ICOImageReader();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Class<ICOImageReader> getReaderClass() {
|
||||||
|
return ICOImageReader.class;
|
||||||
|
}
|
||||||
|
|
||||||
protected List<String> getFormatNames() {
|
protected List<String> getFormatNames() {
|
||||||
return Collections.singletonList("ico");
|
return Collections.singletonList("ico");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<String> getSuffixes() {
|
protected List<String> getSuffixes() {
|
||||||
return Collections.singletonList("ico");
|
return Collections.singletonList("ico");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<String> getMIMETypes() {
|
protected List<String> getMIMETypes() {
|
||||||
return Arrays.asList("image/vnd.microsoft.icon", "image/ico", "image/x-icon");
|
return Arrays.asList("image/vnd.microsoft.icon", "image/ico", "image/x-icon");
|
||||||
}
|
}
|
||||||
|
|||||||
-34
@@ -1,34 +0,0 @@
|
|||||||
package com.twelvemonkeys.imageio.plugins.bmp;
|
|
||||||
|
|
||||||
import com.twelvemonkeys.imageio.util.ImageWriterAbstractTest;
|
|
||||||
|
|
||||||
import javax.imageio.spi.ImageWriterSpi;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.awt.image.RenderedImage;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ICOImageWriterTest.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
|
||||||
* @author last modified by : harald.kuhr$
|
|
||||||
* @version : ICOImageWriterTest.java,v 1.0 25/06/2020 harald.kuhr Exp$
|
|
||||||
*/
|
|
||||||
public class ICOImageWriterTest extends ImageWriterAbstractTest<ICOImageWriter> {
|
|
||||||
@Override
|
|
||||||
protected ImageWriterSpi createProvider() {
|
|
||||||
return new ICOImageWriterSpi();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<? extends RenderedImage> getTestData() {
|
|
||||||
return Arrays.asList(
|
|
||||||
new BufferedImage(8, 8, BufferedImage.TYPE_4BYTE_ABGR),
|
|
||||||
new BufferedImage(16, 16, BufferedImage.TYPE_4BYTE_ABGR),
|
|
||||||
new BufferedImage(32, 32, BufferedImage.TYPE_4BYTE_ABGR),
|
|
||||||
new BufferedImage(64, 64, BufferedImage.TYPE_4BYTE_ABGR),
|
|
||||||
new BufferedImage(128, 128, BufferedImage.TYPE_4BYTE_ABGR)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user