Пример #1
0
        public static Tuple <byte[], byte[]> Convert(string rawIconPath, string nxIconPath, uint nxIconMaxSize)
        {
            Bitmap rawIcon = IconConverter.GetRawIcon(rawIconPath);

            byte[] numArray     = IconConverter.EncodeRawIcon(rawIcon);
            Bitmap nxIconBitmap = IconConverter.GetNxIconBitmap(rawIcon, nxIconPath);

            byte[] data = !(nxIconBitmap.RawFormat.Guid != ImageFormat.Jpeg.Guid) ? IconConverter.FixExifData(File.ReadAllBytes(nxIconPath)) : IconConverter.EncodeNxIcon(nxIconBitmap, nxIconMaxSize);
            IconConverter.CheckNxIconJpeg(data, nxIconMaxSize);
            return(new Tuple <byte[], byte[]>(numArray, data));
        }
        private List <NintendoSubmissionPackageExtraData> CreateExtraSource(List <Tuple <string, string> > iconList, List <Tuple <string, string> > nxIconList, uint maxNxIconSize)
        {
            Dictionary <string, Tuple <string, string> > mergedIconPathMap    = IconConverter.GetMergedIconPathMap(iconList, nxIconList);
            List <NintendoSubmissionPackageExtraData>    packageExtraDataList = new List <NintendoSubmissionPackageExtraData>();

            foreach (KeyValuePair <string, Tuple <string, string> > keyValuePair in mergedIconPathMap)
            {
                string key = keyValuePair.Key;
                Tuple <string, string> tuple1 = keyValuePair.Value;
                Tuple <byte[], byte[]> tuple2 = IconConverter.Convert(tuple1.Item1, tuple1.Item2, maxNxIconSize);
                packageExtraDataList.Add(new NintendoSubmissionPackageExtraData(string.Format("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.raw.{0}.jpg", (object)key), (ISource) new MemorySource(tuple2.Item1, 0, tuple2.Item1.Length)));
                packageExtraDataList.Add(new NintendoSubmissionPackageExtraData(string.Format("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.nx.{0}.jpg", (object)key), (ISource) new MemorySource(tuple2.Item2, 0, tuple2.Item2.Length)));
            }
            return(packageExtraDataList);
        }
Пример #3
0
 private static byte[] FixExifData(byte[] originalJpegData)
 {
     using (JpegDecoder jpegDecoder = new JpegDecoder())
     {
         using (ExifExtractor exifExtractor = new ExifExtractor())
         {
             using (ExifBuilder exifBuilder = new ExifBuilder())
             {
                 using (new JpegEncoder())
                 {
                     int        outOffset;
                     byte[]     out1;
                     JpegStatus exifData1 = jpegDecoder.GetExifData(out outOffset, out out1, originalJpegData);
                     if (exifData1 == JpegStatus.WrongFormat)
                     {
                         return(originalJpegData);
                     }
                     IconConverter.ThrowExceptionIfJpegResultFail(exifData1);
                     Exif out2;
                     IconConverter.ThrowExceptionIfJpegResultFail(exifExtractor.Parse(out out2, out1));
                     out2.Thumbnail = (byte[])null;
                     IconConverter.ThrowExceptionIfJpegResultFail(jpegDecoder.SetJpegData(originalJpegData));
                     Size dimension = jpegDecoder.GetDimension();
                     IconConverter.ThrowExceptionIfJpegResultFail(exifBuilder.SetExif(out2));
                     byte[] exifData2 = exifBuilder.GetExifData(dimension.Width, dimension.Height);
                     byte[] numArray  = new byte[originalJpegData.Length - out1.Length + exifData2.Length];
                     int    num1      = 0;
                     Array.Copy((Array)originalJpegData, (Array)numArray, outOffset);
                     int destinationIndex1 = num1 + outOffset;
                     Array.Copy((Array)exifData2, 0, (Array)numArray, destinationIndex1, exifData2.Length);
                     int destinationIndex2 = destinationIndex1 + exifData2.Length;
                     Array.Copy((Array)originalJpegData, outOffset + out1.Length, (Array)numArray, destinationIndex2, originalJpegData.Length - (outOffset + out1.Length));
                     int num2  = exifData2.Length - out1.Length;
                     int index = outOffset - 8;
                     int num3  = ((int)originalJpegData[index] << 8) + (int)originalJpegData[index + 1] + num2;
                     numArray[index]     = (byte)(num3 >> 8);
                     numArray[index + 1] = (byte)num3;
                     return(numArray);
                 }
             }
         }
     }
 }
Пример #4
0
 public static void Generate(string metaPath, List <Tuple <string, string> > iconPathList, List <Tuple <string, string> > nxIconPathList, uint nxIconMaxSize, string outputDirectoryPath, bool cleanup = true)
 {
     if (Directory.Exists(outputDirectoryPath))
     {
         if (cleanup)
         {
             Directory.Delete(outputDirectoryPath, true);
             int num = 0;
             while (num < 3000 && Directory.Exists(outputDirectoryPath))
             {
                 Thread.Sleep(100);
                 num += 100;
             }
             Directory.CreateDirectory(outputDirectoryPath);
         }
     }
     else
     {
         Directory.CreateDirectory(outputDirectoryPath);
     }
     using (FileStream fileStream = new FileStream(outputDirectoryPath + "/control.nacp", FileMode.Create, FileAccess.Write))
     {
         byte[] buffer = ApplicationControl.MakeApplicationControlPropertyBytes(metaPath);
         fileStream.Write(buffer, 0, buffer.Length);
     }
     foreach (KeyValuePair <string, Tuple <string, string> > mergedIconPath in IconConverter.GetMergedIconPathMap(iconPathList, nxIconPathList))
     {
         string key         = mergedIconPath.Key;
         string rawIconPath = mergedIconPath.Value.Item1;
         string nxIconPath  = mergedIconPath.Value.Item2;
         try
         {
             Enum.Parse(typeof(Language), key);
         }
         catch
         {
             throw new ArgumentException(string.Format("Undefined language '{0}' specified.", (object)key));
         }
         byte[] buffer = IconConverter.ConvertNxIcon(rawIconPath, nxIconPath, nxIconMaxSize);
         using (FileStream fileStream = File.OpenWrite(outputDirectoryPath + "/icon_" + key + ".dat"))
             fileStream.Write(buffer, 0, buffer.Length);
     }
 }
Пример #5
0
        private static Bitmap GetNxIconBitmap(Bitmap RawIcon, string nxIconPath)
        {
            if (nxIconPath != null)
            {
                Bitmap icon = new Bitmap(nxIconPath);
                IconConverter.CheckNxIcon(icon);
                return(icon);
            }
            Bitmap   bitmap1   = new Bitmap(512, 512);
            Graphics graphics1 = Graphics.FromImage((Image)bitmap1);

            graphics1.InterpolationMode = InterpolationMode.Bilinear;
            graphics1.DrawImage((Image)RawIcon, 0, 0, 512, 512);
            Bitmap   bitmap2   = new Bitmap(256, 256);
            Graphics graphics2 = Graphics.FromImage((Image)bitmap2);

            graphics2.InterpolationMode = InterpolationMode.Bilinear;
            graphics2.DrawImage((Image)bitmap1, 0, 0, 256, 256);
            return(bitmap2);
        }
Пример #6
0
 private static byte[] Encode(Bitmap icon, int quality)
 {
     using (JpegEncoder jpegEncoder = new JpegEncoder())
     {
         BitmapData bitmapdata = icon.LockBits(new Rectangle(0, 0, icon.Width, icon.Height), ImageLockMode.ReadOnly, icon.PixelFormat);
         byte[]     numArray   = new byte[icon.Height * bitmapdata.Stride];
         Marshal.Copy(bitmapdata.Scan0, numArray, 0, numArray.Length);
         icon.UnlockBits(bitmapdata);
         IconConverter.CorrectRgbChannel(numArray, icon.PixelFormat);
         IconConverter.ThrowExceptionIfJpegResultFail(jpegEncoder.SetPixelData(numArray, icon.PixelFormat, IconConverter.ToSize(icon.PhysicalDimension), 1));
         jpegEncoder.SetQuality(quality);
         jpegEncoder.SetSamplingRatio(SamplingRatio.Ratio_444);
         byte[] outBuffer;
         IconConverter.ThrowExceptionIfJpegResultFail(jpegEncoder.Encode(out outBuffer, new Exif()
         {
             Software = "Nintendo AuthoringTool"
         }));
         return(outBuffer);
     }
 }
Пример #7
0
 public static byte[] ConvertNxIcon(string rawIconPath, string nxIconPath, uint nxIconMaxSize)
 {
     return(IconConverter.Convert(rawIconPath, nxIconPath, nxIconMaxSize).Item2);
 }
Пример #8
0
 private static byte[] EncodeRawIcon(Bitmap icon)
 {
     return(IconConverter.Encode(icon, 98));
 }