/*
 * Copyright 2002-2015 Drew Noakes
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 *
 * More information about this project is available at:
 *
 *    https://drewnoakes.com/code/exif/
 *    https://github.com/drewnoakes/metadata-extractor
 */

package com.drew.metadata.photoshop;

import com.drew.lang.annotations.NotNull;
import com.drew.lang.annotations.Nullable;
import com.drew.metadata.TagDescriptor;

/**
 * @author Drew Noakes https://drewnoakes.com
 */
public class PsdHeaderDescriptor extends TagDescriptor<PsdHeaderDirectory>
{
    public PsdHeaderDescriptor(@NotNull PsdHeaderDirectory directory)
    {
        super(directory);
    }

    @Override
    public String getDescription(int tagType)
    {
        switch (tagType) {
            case PsdHeaderDirectory.TAG_CHANNEL_COUNT:
                return getChannelCountDescription();
            case PsdHeaderDirectory.TAG_BITS_PER_CHANNEL:
                return getBitsPerChannelDescription();
            case PsdHeaderDirectory.TAG_COLOR_MODE:
                return getColorModeDescription();
            case PsdHeaderDirectory.TAG_IMAGE_HEIGHT:
                return getImageHeightDescription();
            case PsdHeaderDirectory.TAG_IMAGE_WIDTH:
                return getImageWidthDescription();
            default:
                return super.getDescription(tagType);
        }
    }

    @Nullable
    public String getChannelCountDescription()
    {
        try {
            // Supported range is 1 to 56.
            Integer value = _directory.getInteger(PsdHeaderDirectory.TAG_CHANNEL_COUNT);
            if (value == null)
                return null;
            return value + " channel" + (value == 1 ? "" : "s");
        } catch (Exception e) {
            return null;
        }
    }

    @Nullable
    public String getBitsPerChannelDescription()
    {
        try {
            // Supported values are 1, 8, 16 and 32.
            Integer value = _directory.getInteger(PsdHeaderDirectory.TAG_BITS_PER_CHANNEL);
            if (value == null)
                return null;
            return value + " bit" + (value == 1 ? "" : "s") + " per channel";
        } catch (Exception e) {
            return null;
        }
    }

    @Nullable
    public String getColorModeDescription()
    {
        // Bitmap = 0; Grayscale = 1; Indexed = 2; RGB = 3; CMYK = 4; Multichannel = 7; Duotone = 8; Lab = 9
        try {
            Integer value = _directory.getInteger(PsdHeaderDirectory.TAG_COLOR_MODE);
            if (value == null)
                return null;
            switch (value){
                case 0: return "Bitmap";
                case 1: return "Grayscale";
                case 2: return "Indexed";
                case 3: return "RGB";
                case 4: return "CMYK";
                case 7: return "Multichannel";
                case 8: return "Duotone";
                case 9: return "Lab";
                default: return "Unknown color mode (" + value + ")";
            }
        } catch (Exception e) {
            return null;
        }
    }

    @Nullable
    public String getImageHeightDescription()
    {
        try {
            Integer value = _directory.getInteger(PsdHeaderDirectory.TAG_IMAGE_HEIGHT);
            if (value == null)
                return null;
            return value + " pixel" + (value == 1 ? "" : "s");
        } catch (Exception e) {
            return null;
        }
    }

    @Nullable
    public String getImageWidthDescription()
    {
        try {
            Integer value = _directory.getInteger(PsdHeaderDirectory.TAG_IMAGE_WIDTH);
            if (value == null)
                return null;
            return value + " pixel" + (value == 1 ? "" : "s");
        } catch (Exception e) {
            return null;
        }
    }
}

@@ -2828,327 +2828,83 @@
     
-// Bitmap = 0; Grayscale = 1; Indexed = 2; RGB = 3; CMYK = 4; Multichannel = 7; Duotone = 8; Lab = 9%0A        try %7B%0A            Integer value = _directory.getInteger(PsdHeaderDirectory.TAG_COLOR_MODE);%0A            if (value == null)%0A                return null;%0A            switch (value)%7B%0A                case 0: return
+return getIndexedDescription(PsdHeaderDirectory.TAG_COLOR_MODE,%0A           
  %22Bi
@@ -2908,17 +2908,17 @@
 %22Bitmap%22
-;
+,
 %0A       
@@ -2926,27 +2926,8 @@
     
-    case 1: return 
 %22Gra
@@ -2933,21 +2933,18 @@
 ayscale%22
-;%0A   
+,%0A
         
@@ -2951,24 +2951,8 @@
     
- case 2: return 
 %22Ind
@@ -2956,17 +2956,17 @@
 Indexed%22
-;
+,
 %0A       
@@ -2974,33 +2974,14 @@
     
-    case 3: return 
 %22RGB%22
-;
+,
 %0A   
@@ -2993,37 +2993,16 @@
     
-    case 4: return 
 %22CMYK%22
-;%0A  
+,%0A
     
@@ -3013,271 +3013,102 @@
     
-  case 7: return %22Multichannel%22;%0A                case 8: return %22Duotone%22;%0A                case 9: return %22Lab%22;%0A                default: return %22Unknown color mode (%22 + value + %22)%22;%0A            %7D%0A        %7D catch (Exception e) %7B%0A            return null;%0A        %7D
+null,%0A            null,%0A            %22Multichannel%22,%0A            %22Duotone%22,%0A            %22Lab%22);
 %0A   

Use getIndexedDescription in PSD header color mode description.