com.github.bloodshura.x.assets.ext.image.IcoCodec Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shurax-assets-ext Show documentation
Show all versions of shurax-assets-ext Show documentation
Extensions for the ShuraX Assets library, including new image and sound codecs.
The newest version!
/*
* Copyright (c) 2013-2018, João Vitor Verona Biazibetti - All Rights Reserved
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
* https://www.github.com/BloodShura
*/
package com.github.bloodshura.x.assets.ext.image;
import com.github.bloodshura.x.assets.image.ImageFormat;
import com.github.bloodshura.x.assets.image.codec.ImageCodec;
import net.sf.image4j.codec.ico.ICODecoder;
import net.sf.image4j.codec.ico.ICOEncoder;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class IcoCodec implements ImageCodec {
@Override
public boolean hasDecoder(@Nonnull ImageFormat format) {
return format == ImageFormat.ICO;
}
@Override
public boolean hasEncoder(@Nonnull ImageFormat format) {
return format == ImageFormat.ICO;
}
@Nullable
@Override
public BufferedImage read(@Nonnull InputStream input) throws IOException {
BufferedImage highestImage = null;
for (BufferedImage image : ICODecoder.read(input)) {
if (highestImage == null || image.getWidth() > highestImage.getWidth()) {
highestImage = image;
}
}
return highestImage;
}
@Override
public void write(@Nonnull BufferedImage image, @Nonnull ImageFormat format, @Nonnull OutputStream output) throws IOException {
ICOEncoder.write(image, output);
}
public void write(@Nonnull BufferedImage image, int bpp, @Nonnull OutputStream output) throws IOException {
ICOEncoder.write(image, bpp, output);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy