001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.imaging.formats.psd;
018
019import java.io.IOException;
020import java.io.PrintWriter;
021import java.io.StringWriter;
022import java.util.logging.Level;
023import java.util.logging.Logger;
024
025public class PsdHeaderInfo {
026
027    private static final Logger LOGGER = Logger.getLogger(PsdHeaderInfo.class.getName());
028
029    public final int version;
030    private final byte[] reserved;
031    public final int channels;
032    public final int rows;
033    public final int columns;
034    public final int depth;
035    public final int mode;
036
037    public PsdHeaderInfo(final int version, final byte[] reserved, final int channels, final int rows, final int columns, final int depth, final int mode) {
038        this.version = version;
039        this.reserved = reserved.clone();
040        this.channels = channels;
041        this.rows = rows;
042        this.columns = columns;
043        this.depth = depth;
044        this.mode = mode;
045
046    }
047
048    public void dump() {
049        try (StringWriter sw = new StringWriter();
050                PrintWriter pw = new PrintWriter(sw)) {
051            dump(pw);
052            pw.flush();
053            sw.flush();
054            LOGGER.fine(sw.toString());
055        } catch (final IOException e) {
056            LOGGER.log(Level.SEVERE, e.getMessage(), e);
057        }
058    }
059
060    public void dump(final PrintWriter pw) {
061        pw.println("");
062        pw.println("Header");
063        pw.println("Version: " + version + " (" + Integer.toHexString(version) + ")");
064        pw.println("Channels: " + channels + " (" + Integer.toHexString(channels) + ")");
065        pw.println("Rows: " + rows + " (" + Integer.toHexString(rows) + ")");
066        pw.println("Columns: " + columns + " (" + Integer.toHexString(columns) + ")");
067        pw.println("Depth: " + depth + " (" + Integer.toHexString(depth) + ")");
068        pw.println("Mode: " + mode + " (" + Integer.toHexString(mode) + ")");
069        pw.println("Reserved: " + reserved.length);
070        pw.println("");
071        pw.flush();
072    }
073
074    public byte[] getReserved() {
075        return reserved.clone();
076    }
077
078}