ściema czyli misja inspirowana przez CLT

Cheat za cheatem… IDDQD z Dooma czy jak to szło…. 🙂
oczy się palą złotym kolorem….

Zadanie: Misja 011

CLT podesłał i dostał w odpowiedzi, że w co ja mam tu kliknąć itd. itd… oj nieładnie…

 

no ale później pogadaliśmy…. i zadanie z „tych fajnych” no ale „cheat mode=on” – dowiedziałem się że trzeba to rozpakować i że to PCX’y…. i że trza je poskładać 🙂

Wywaliliśmy plik jako tablice bajtów i zaczęliśmy się zastanawiać co by z tym zrobić, ale… przecież można to wczytać jako Bitmap i tyle….

jednak…. .net nie obsługuje „już” (tak mi się wydaje….) PCX’ów! – cóż za challenge, prawie bym się poddał bo mi się nie chciało testować bbliotek – spróbowałem i odniosłem 2 porażki, ale to coś dało radę: klik

wynik:

kodzik:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using System.Drawing;
 
namespace MISJA_011
{
    class Program
    {
        static void Main(string[] args)
        {
            string _dir = @"C:\TEMP\zdjecie_dokumentu";
            string _out = @"C:\TEMP\out.bmp";
            if (File.Exists(_out))
                File.Delete(_out);                        
            var dir = new DirectoryInfo(_dir);
            FileInfo[] files = dir.GetFiles();
            Console.Write(files.Length.ToString());
            int cnt = 0,toFind =0,found=0;            
            Bitmap dest = null;
            var tsStart = DateTime.Now;
            Parallel.ForEach(files, (f) =>            
            {
                var img = new ImageMagick.MagickImage(f);
                var b = img.ToBitmap();
                if (dest == null)
                {
                    dest = new Bitmap(b.Size.Width, b.Size.Height);
                    toFind = b.Size.Width * b.Size.Height;
                }
                for (int i = 0; i < b.Size.Width; i++)
                    for (int j = 0; j < b.Size.Height; j++)
                    {
                        var color = b.GetPixel(i, j);
                        if (color != Color.FromArgb(0, 0, 0))
                        {
                            lock(dest)
                            {
                                dest.SetPixel(i, j, color);
                            }
                            found++;
                            var ts = DateTime.Now - tsStart;
                            Console.WriteLine(string.Format("file: {0} / {1} {2} {3}x{4} - found: {5}/{6} - time: {7}s {8}%"
                                , cnt, files.Length, f.Name
                                , i, j, found, toFind, ts.TotalSeconds
                                ,Math.Round((Convert.ToDouble(found)/Convert.ToDouble(toFind))*100,2)
                                ));
                        }
                    }
                cnt++;
 
            });
            if (dest != null)
                dest.Save(_out);
            Console.ReadKey();
        }
    }
}

czas liczenia: 32 min, 15 s

JAZDA! 🙂