<commit_before>﻿using System;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using RavuAlHemio.PSD;

namespace PSD2PAM
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Usage: PSD2PAM.exe FILE.psd FILE.pam");
                Environment.ExitCode = 1;
                return;
            }

            // read the PSD file
            var photochop = new PSDFile();
            using (var reading = new FileStream(args[0], FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                photochop.Read(reading);

                int width = photochop.Width;
                int height = photochop.Height;
                int channelCount = photochop.NumberOfChannels;
                int depth = photochop.Depth;
                if (depth == 1)
                {
                    Console.WriteLine("PSD2PAM doesn't currently support 1-bit images.");
                    Environment.ExitCode = 1;
                    return;
                }

                long maxValue;
                switch (depth)
                {
                    case 8:
                        maxValue = 0xFF;
                        break;
                    case 16:
                        maxValue = 0xFFFF;
                        break;
                    case 32:
                        maxValue = 0xFFFFFFFF;
                        break;
                    default:<commit_msg>PSD2PAM: complain if PSD does not have a precomposed image<commit_after>﻿using System;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using RavuAlHemio.PSD;

namespace PSD2PAM
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Usage: PSD2PAM.exe FILE.psd FILE.pam");
                Environment.ExitCode = 1;
                return;
            }

            // read the PSD file
            var photochop = new PSDFile();
            using (var reading = new FileStream(args[0], FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                photochop.Read(reading);

                var versionInfo = photochop.ImageResources.FirstOrDefault(ir => ir.ID == 0x0421);
                if (versionInfo?.Data[4] == 0)
                {
                    // does not have valid precomposed image
                    Console.WriteLine("PSD2PAM requires that a valid precomposed image is part of the file.");
                    Environment.ExitCode = 1;
                    return;
                }

                int width = photochop.Width;
                int height = photochop.Height;
                int channelCount = photochop.NumberOfChannels;
                int depth = photochop.Depth;
                if (depth == 1)
                {
                    Console.WriteLine("PSD2PAM doesn't currently support 1-bit images.");
                    Environment.ExitCode = 1;
                    return;
                }

                long maxValue;
                switch (depth)
                {
                    case 8:
                        maxValue = 0xFF;
                        break;
                    case 16:
                        maxValue = 0xFFFF;
                        break;
                    case 32:
                        maxValue = 0xFFFFFFFF;
                        break;
                    default:
{'fraction_non_alphanumeric': 0.07437552624193096, 'fraction_numerical': 0.01234914397979231, 'mean_word_length': 1.0732984293193717, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1730898', 'n_tokens_mistral': 953, 'n_tokens_neox': 837, 'n_words': 219}