001/**
002 * Copyright (c) 2008-2014 Ardor Labs, Inc.
003 *
004 * This file is part of Ardor3D.
005 *
006 * Ardor3D is free software: you can redistribute it and/or modify it 
007 * under the terms of its license which may be found in the accompanying
008 * LICENSE file or at <http://www.ardor3d.com/LICENSE>.
009 */
010
011package com.ardor3d.image.util.dds;
012
013import java.io.IOException;
014
015import com.ardor3d.util.LittleEndianDataInput;
016
017class DdsPixelFormat {
018
019    // ---- VALUES USED IN dwFlags ----
020    // Texture contains alpha data; dwABitMask contains valid data.
021    final static int DDPF_ALPHAPIXELS = 0x1;
022    // Used in some older DDS files for alpha channel only uncompressed data (dwRGBBitCount contains the alpha channel
023    // bitcount; dwABitMask contains valid data)
024    final static int DDPF_ALPHA = 0x2;
025    // Texture contains compressed RGB data; dwFourCC contains valid data.
026    final static int DDPF_FOURCC = 0x4;
027    // Texture contains uncompressed RGB data; dwRGBBitCount and the RGB masks (dwRBitMask, dwGBitMask, dwBBitMask)
028    // contain valid data.
029    final static int DDPF_RGB = 0x40;
030    // Used in some older DDS files for YUV uncompressed data (dwRGBBitCount contains the YUV bit count; dwRBitMask
031    // contains the Y mask, dwGBitMask contains the U mask, dwBBitMask contains the V mask)
032    final static int DDPF_YUV = 0x200;
033    // Used in some older DDS files for single channel color uncompressed data (dwRGBBitCount contains the luminance
034    // channel bit count; dwRBitMask contains the channel mask). Can be combined with DDPF_ALPHAPIXELS for a two channel
035    // DDS file.
036    final static int DDPF_LUMINANCE = 0x20000;
037    // ---- /end VALUES USED IN dwFlags ----
038
039    int dwSize;
040    int dwFlags;
041    int dwFourCC;
042    int dwRGBBitCount;
043    int dwRBitMask;
044    int dwGBitMask;
045    int dwBBitMask;
046    int dwABitMask;
047
048    static DdsPixelFormat read(final LittleEndianDataInput in) throws IOException {
049        final DdsPixelFormat format = new DdsPixelFormat();
050        format.dwSize = in.readInt();
051        if (format.dwSize != 32) {
052            throw new Error("invalid pixel format size: " + format.dwSize);
053        }
054        format.dwFlags = in.readInt();
055        format.dwFourCC = in.readInt();
056        format.dwRGBBitCount = in.readInt();
057        format.dwRBitMask = in.readInt();
058        format.dwGBitMask = in.readInt();
059        format.dwBBitMask = in.readInt();
060        format.dwABitMask = in.readInt();
061        return format;
062    }
063}