All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.bloodshura.x.assets.ext.image.JimiCodec Maven / Gradle / Ivy

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 com.github.bloodshura.x.assets.util.ImageWorker;
import com.sun.jimi.core.Jimi;
import com.sun.jimi.core.JimiException;

import javax.annotation.Nonnull;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class JimiCodec implements ImageCodec {
	@Nonnull
	public String getJIMIMimeType(@Nonnull ImageFormat format) {
		return format.getMimeTypes().first();
	}

	/**
	 * Already implemented decoders:
	 * BMP, CUR, GIF, ICO, JPG (Builtin), PCT, PCX, PNG, PSD, RAS (SunRaster), TGA, TIF, XBM, XPM
	 * 

* Additional decoders: * APF */ @Override public boolean hasDecoder(@Nonnull ImageFormat format) { return format == ImageFormat.APF || format == ImageFormat.BMP || format == ImageFormat.CUR || format == ImageFormat.GIF || format == ImageFormat.JPG || format == ImageFormat.PCT || format == ImageFormat.PCX || format == ImageFormat.PNG || format == ImageFormat.PSD || format == ImageFormat.RAS || format == ImageFormat.TGA || format == ImageFormat.TIFF || format == ImageFormat.XBM || format == ImageFormat.XPM; } /** * Already implemented encoders: * BMP, JPG, PCT, PCX, PNG, PSD, RAS (SunRaster), TGA, XBM, XPM *

* Additional encoders: * APF, CUR */ @Override public boolean hasEncoder(@Nonnull ImageFormat format) { return hasDecoder(format) && format != ImageFormat.GIF && format != ImageFormat.ICO /* JIMI has ICOEncoder, but not ICOEncoderFactory. Possibly implement it? */ && format != ImageFormat.TIFF; } @Nonnull @Override public BufferedImage read(@Nonnull InputStream input) throws IOException { try { return ImageWorker.asBufferedImage(Jimi.getImage(input)); } catch (Exception exception) { throw new IOException(exception.getMessage(), exception.getCause()); } } @Override public void write(@Nonnull BufferedImage image, @Nonnull ImageFormat format, @Nonnull OutputStream output) throws IOException { try { Jimi.putImage(getJIMIMimeType(format), image, output); } catch (JimiException exception) { throw new IOException("ihuuuu" + exception.getMessage(), exception.getCause()); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy