Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Resolved Best Image Format?

Discussion in 'Scripting' started by AnimalMan, Oct 6, 2022.

  1. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    Code (CSharp):
    1.  public static string StringToBinary(string data)
    2.     {
    3.         StringBuilder sb = new StringBuilder();
    4.  
    5.         foreach (char c in data.ToCharArray())
    6.         {
    7.             sb.Append(Convert.ToString(c, 2).PadLeft(8, '0'));
    8.         }
    9.         return sb.ToString();
    10.     }
    11.  
    12.     void MakeBinaryKeys2()
    13.     {
    14.         for (int i = 0; i < CHARACTERS.Count; i++)
    15.         {
    16.          
    17.                 BINARYRESULTS.Add(StringToBinary(CHARACTERS[i].ToString()));
    18.          
    19.         }
    20.     }
    Wow Big deal. God Damn. ^_^
    mm.png


    Code (CSharp):
    1.  
    2.         for (int i = 0; i < BINARYRESULTS.Count; i++) // Lets break up those Nodes
    3.         {
    4.             var FIRSTMODULE = "";
    5.             var SECONDMODULE = "";
    6.             var C = BINARYRESULTS[i].ToCharArray();
    7.             for (int x = 0; x < C.Length; x++)
    8.             {
    9.                 if (x < 4)
    10.                     FIRSTMODULE = FIRSTMODULE + C[x];
    11.                 else
    12.                     SECONDMODULE = SECONDMODULE + C[x];
    13.             }
    14.             BINARYRESULTS[i] = "";
    15.             BINARYRESULTS[i] = FIRSTMODULE + " " + SECONDMODULE;
    16.         }
     
    Last edited: Oct 8, 2022
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,683
    TBH I don't see anything above that is making a joke out of you. I think that if you are going to put yourself out there and publically describe stuff you're doing and even ask for feedback, you should be more than prepared, no expect, that other devs will give you that feedback but moreso, expect and accept that you're going to get such feedback in the form of constructive criticism and you should be humble in the face of what you don't know. Sometimes you'll get advice in the form of schooling, maybe links to more fundamental understanding. I see that above with the CS 101 stuff. That's not making a joke of you.

    I personally enjoy finding new stuff that I didn't know each week and I've been writing code for nearly 40 years in one form or another. Rule#1. Be humble. You obviously don't know all the things and that's fine. Same here. Of course, there are times when other devs can be terrible and overbearing with their subjective preferences/opinions (etc) and try to tell you how things work; that's not what's happening above.

    Game engines in particular give you access to stuff that's been written by people who do understand this stuff so they can give you enough power to shoot yourself in the foot. This is good though, it takes many bad paths to know you're on a bad path; that's knowledge but moreso, experience. Sometimes just exploring and doing it the "wrong" way has a lot of value in itself. The difference here is that you're posting publically, in detail, what you're doing so again, you need to accept that you're not just going to be patted on the back for your approach if it's far from optimal and/or it's based upon a potential misunderstanding.

    I'm not making a joke of you either. Above might be obvious, even sound patronising but again, that's not my intent at all! It's not you against anyone else. It's good to post this stuff, it can help you figure it all out but be prepared to get the answers you don't want to hear. :)
     
    Ryiah, angrypenguin and Bunny83 like this.
  3. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    4,207
    Yes, this is just counting up in binary, though you shuffled the values around randomly. With a 4 bit binary number you can represent 16 values, that's correct:

    Code (CSharp):
    1. 0000 - 0
    2. 0001 - 1
    3. 0010 - 2
    4. 0011 - 3
    5. 0100 - 4
    6. 0101 - 5
    7. 0110 - 6
    8. 0111 - 7
    9. 1000 - 8
    10. 1001 - 9
    11. 1010 - 10
    12. 1011 - 11
    13. 1100 - 12
    14. 1101 - 13
    15. 1110 - 14
    16. 1111 - 15
    That is the direct conversion of a 4 bit number into a decimal number. A binary number works EXACTLY the same as a decimal number. In a decimal number each position has a certain value (0 - 9) but each position in a number has a different base value which in the decimal system are powers of 10 (1,10,100,1000,10000,...). In the binary system it works the same way but each position can only have a value between 0 and 1. The base value of each position is a power of 2 (1,2,4,8,16,32,64,128, ...). So for example the binary number "1101" breaks down to

    1 * 2^3 == 1 * 8 == 8
    1 * 2^2 == 1 * 4 == 4
    0 * 2^1 == 0 * 2 == 0
    1 * 2^0 == 1 * 1 == 1
    The "sum" of that is the decimal value 11 (1*10 + 1*1). That's how binary works. Every additional bit doubles the possible combinations as you can use all the previous combinations twice, once with the new bit being 0 and one with the new bit being 1. In decimal adding another digit means you get 10 times as many numbers you can represent. So while a 2 digit number in decimal can represent 100 different values (0 - 99), adding a third digit means we can now represent number between 0 and 999 (1000 values, so 10 times more).

    As I said, binary works exactly the same as any other positional number system. You can even do a long addition manually

    Code (CSharp):
    1.  
    2. //  10010111101   (1213)
    3. // +00101110101  +( 373)
    4. // ------------  -------                
    5. //  |||||||||||   (1586)
    6. //  |||||||||||
    7. //  |||||||||| \_ 1 + 1     == 10 --> 0 +  1 carry
    8. //  ||||||||| \__ 0 + 0 + 1 ==  1 --> 1 + no carry
    9. //  |||||||| \___ 1 + 1 + 0 == 10 --> 0 +  1 carry
    10. //  ||||||| \____ 1 + 0 + 1 == 10 --> 0 +  1 carry
    11. //  |||||| \_____ 1 + 1 + 1 == 11 --> 1 +  1 carry
    12. //  ||||| \______ 1 + 1 + 1 == 11 --> 1 +  1 carry
    13. //  |||| \_______ 0 + 1 + 1 == 10 --> 0 +  1 carry
    14. //  ||| \________ 1 + 0 + 1 == 10 --> 0 +  1 carry
    15. //  |||\_________ 0 + 1 + 1 == 10 --> 0 +  1 carry
    16. //  | \__________ 0 + 0 + 1 ==  1 --> 1 + no carry
    17. //   \___________ 1 + 0 + 0 ==  1 --> 1 + no carry
    18. //                                    |
    19. //                                    |
    20. //                                     \ 11000110010 (1586)
    21.  
    Binary is just a number system and it works exactly like any other positional number system. It just has the base 2 instead of 10. When you add numbers and the sum of two digits is larger than the representable digits for a single position you get a carry to the next position. While in base 10 we have 10 symbols, in base 2 we only have 2. In base 2 it's much more common to have a carry because after just one digit you run out of symbols.

    As it was already said:
    . It's fun to discover how a computer actually works. Though you seem to be curious and determined but then suddenly stop, draw some strange conclusion and switch topic ^^. This is kinda frustrating to observe.

    We're here to offer our help, however if the goal is not really clear this is all like stabbing in the dark. Note. no one wants to belittle anyone here. Everybody has to start at zero and you slowly accumulate knowledge over time. So don't feel bad when you don't fully understand something. There are a lot of things I don't fully understand as well. If I want to know those things, I would sit down and study it, search for sources, examples, experiments and things I can try for myself in order to increase my knowledge. We're not born with that knowledge, it has to be learned if you need it.
     
    MelvMay likes this.
  4. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    Code (CSharp):
    1.  
    2.         for (int x = 0; x < BINARYMODULES.Count; x++) // Lets Sort the Modules by the number of 1'ns
    3.         {
    4.             var MODULE_1 = BINARYMODULES[x][0];
    5.             var MOD1 = MODULE_1.ToCharArray();
    6.             int Count = 0;
    7.             for (int i = 0; i < MOD1.Length; i++)
    8.             {
    9.                 if (MOD1[i] == '1')
    10.                     Count = Count + 1;
    11.             }
    12.             if (Count == 0)
    13.                 if (!NONES.Contains(MODULE_1))
    14.                      NONES.Add(MODULE_1);
    15.             if (Count == 1)
    16.                 if (!ONES.Contains(MODULE_1))
    17.                 ONES.Add(MODULE_1);
    18.             if (Count == 2)
    19.                 if (!TWOS.Contains(MODULE_1))
    20.                 TWOS.Add(MODULE_1);
    21.             if (Count == 3)
    22.                 if (!THREES.Contains(MODULE_1))
    23.                 THREES.Add(MODULE_1);
    24.             if (Count == 4)
    25.                 if (!FOURS.Contains(MODULE_1))
    26.                 FOURS.Add(MODULE_1);
    27.         }
    28.         for (int x = 0; x < BINARYMODULES.Count; x++) // Lets Sort the Modules by the number of 1'ns
    29.         {
    30.             var MODULE_2 = BINARYMODULES[x][1];
    31.             var MOD1 = MODULE_2.ToCharArray();
    32.             int Count = 0;
    33.             for (int i = 0; i < MOD1.Length; i++)
    34.             {
    35.                 if (MOD1[i] == '1')
    36.                     Count = Count + 1;
    37.             }
    38.             if (Count == 0)
    39.                 if (!NONES.Contains(MODULE_2))
    40.                     NONES.Add(MODULE_2);
    41.             if (Count == 1)
    42.                 if (!ONES.Contains(MODULE_2))
    43.                     ONES.Add(MODULE_2);
    44.             if (Count == 2)
    45.                 if (!TWOS.Contains(MODULE_2))
    46.                     TWOS.Add(MODULE_2);
    47.             if (Count == 3)
    48.                 if (!THREES.Contains(MODULE_2))
    49.                     THREES.Add(MODULE_2);
    50.             if (Count == 4)
    51.                 if (!FOURS.Contains(MODULE_2))
    52.                     FOURS.Add(MODULE_2);
    53.         }
    54.  

    In Conclusion

    All Combos.png

    I don't know why it drive me crazy. I just hate having 5 languages that are essentially different ways of doing a one language, that isnt even hards to understand ^_^

    So now you can reduce Micro-Reptition and shrink down to a PNG file size ontop of some structure breakdown like this. As without !Contains you'll see all the dupes of all the modules that are used multiple times. and if they repeat one after the other in the File you are saving. then if that repetition is > 2 then it is worth cutting down to a single byte.

    Understanding Achieved.

    You reduce Macro-Repetition in your File, then you reduce Micro-Repetition in your file. Suddenly you'll have a very small file.

    My apologies for any rudeness, sometimes it is the Adrenaline that solves the problem.

    You are basically breaking up the Binary Bytes into two halfs, and comparing the one half with the next module matching half in the document. And saying well if the next 3 are characters that are using the same module on Mod1 or Mod2 in a row, then we can reference a smaller byte to represent the repetition of those modules. In fact, the algorithm to do this would use the % guess who? The Modulo operator <3

    Welcome to the game modulo operator. Welcome to the Game.
     
    Last edited: Oct 8, 2022
  5. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    WelcomeToTheGame.png

    i am aware I am hyper active and over excitable, proud becoming arrogant and obnoxious, and I couldn’t explain. But sorry if I have hurt anyone during the process of this personal eureka.
    il take a step back take a little break and calm myself down and return composed and ready to help others progress. Have a good weekend guys.
     
    Last edited: Oct 8, 2022
  6. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    YOU DID IT YOU DID IT

    YOU ACTUALLY DID IT


    Code (CSharp):
    1.  
    2.         string RAWNUMBER = "01100001";
    3.         int numOfBytes = RAWNUMBER.Length / 8;
    4.         byte[] BYTE = new byte[numOfBytes];
    5.         for (int i = 0; i < numOfBytes; ++i)
    6.         {
    7.             BYTE[i] = Convert.ToByte(RAWNUMBER.Substring(8 * i, 8), 2);
    8.         }
    9.  
    10.         Debug.Log(Encoding.UTF8.GetString(BYTE, 0, BYTE.Length));
    11.         Debug.Log(Encoding.ASCII.GetString(BYTE, 0, BYTE.Length));
    12.         Debug.Log(Encoding.Unicode.GetString(BYTE, 0, BYTE.Length));
    13.         Debug.Log(Encoding.UTF32.GetString(BYTE, 0, BYTE.Length));
    14.         Debug.Log(Encoding.Default.GetString(BYTE, 0, BYTE.Length));
    15.         Debug.Log(Encoding.BigEndianUnicode.GetString(BYTE, 0, BYTE.Length));
    You actually taught me it!! I was just too ignorant of the pacings and details!
    You guys are smart no question. No question about it. I now know what i didn't know, what that seemed complicated.

    Thanks. This thread is truly finished :)

    Compressor
    Code (CSharp):
    1.  
    2.         for (int i = 0; i < RAWNUMBER.Length; i++)
    3.         {
    4.             if (!SKIPPERS.Contains(i))
    5.             {
    6.                 if (i + 23 < RAWNUMBER.Length && i >= 8)
    7.                 {
    8.                     var MODULE = "";
    9.                     MODULE += RAWNUMBER[i];
    10.                     MODULE += RAWNUMBER[i + 1];
    11.                     MODULE += RAWNUMBER[i + 2];
    12.                     MODULE += RAWNUMBER[i + 3];
    13.                     MODULE += RAWNUMBER[i + 4];
    14.                     MODULE += RAWNUMBER[i + 5];
    15.                     MODULE += RAWNUMBER[i + 6];
    16.                     MODULE += RAWNUMBER[i + 7];
    17.                     var MODULE2 = "";
    18.                     MODULE2 += RAWNUMBER[i + 8];
    19.                     MODULE2 += RAWNUMBER[i + 9];
    20.                     MODULE2 += RAWNUMBER[i + 10];
    21.                     MODULE2 += RAWNUMBER[i + 11];
    22.                     MODULE2 += RAWNUMBER[i + 12];
    23.                     MODULE2 += RAWNUMBER[i + 13];
    24.                     MODULE2 += RAWNUMBER[i + 14];
    25.                     MODULE2 += RAWNUMBER[i + 15];
    26.                     var MODULE3 = "";
    27.                     MODULE3 += RAWNUMBER[i + 16];
    28.                     MODULE3 += RAWNUMBER[i + 17];
    29.                     MODULE3 += RAWNUMBER[i + 18];
    30.                     MODULE3 += RAWNUMBER[i + 19];
    31.                     MODULE3 += RAWNUMBER[i + 20];
    32.                     MODULE3 += RAWNUMBER[i + 21];
    33.                     MODULE3 += RAWNUMBER[i + 22];
    34.                     MODULE3 += RAWNUMBER[i + 23];
    35.                     if (MODULE == MODULE3)
    36.                     {
    37.                         if (MODULE2 != MODULE3)
    38.                         {
    39.                             COMPRESSEDNUMBER += "00100111"; // '?'
    40.                             SKIPPERS.Add(i + 17);
    41.                         }
    42.                         else
    43.                         {
    44.                             COMPRESSEDNUMBER += "00111111"; // '''
    45.                             SKIPPERS.Add(i + 9);
    46.                             SKIPPERS.Add(i + 17);
    47.                         }
    48.                      
    49.                     }
    50.                     if (MODULE != MODULE2 && MODULE2 != MODULE3)
    51.                     {
    52.                         COMPRESSEDNUMBER = COMPRESSEDNUMBER + RAWNUMBER[i];
    53.                         COMPRESSEDNUMBER = COMPRESSEDNUMBER + RAWNUMBER[i + 1];
    54.                         COMPRESSEDNUMBER = COMPRESSEDNUMBER + RAWNUMBER[i + 2];
    55.                         COMPRESSEDNUMBER = COMPRESSEDNUMBER + RAWNUMBER[i + 3];
    56.                         COMPRESSEDNUMBER = COMPRESSEDNUMBER + RAWNUMBER[i + 4];
    57.                         COMPRESSEDNUMBER = COMPRESSEDNUMBER + RAWNUMBER[i + 5];
    58.                         COMPRESSEDNUMBER = COMPRESSEDNUMBER + RAWNUMBER[i + 6];
    59.                         COMPRESSEDNUMBER = COMPRESSEDNUMBER + RAWNUMBER[i + 7];
    60.                     }
    61.                 }
    62.                 else
    63.                 {
    64.                     COMPRESSEDNUMBER = COMPRESSEDNUMBER + RAWNUMBER[i];
    65.                     COMPRESSEDNUMBER = COMPRESSEDNUMBER + RAWNUMBER[i + 1];
    66.                     COMPRESSEDNUMBER = COMPRESSEDNUMBER + RAWNUMBER[i + 2];
    67.                     COMPRESSEDNUMBER = COMPRESSEDNUMBER + RAWNUMBER[i + 3];
    68.                     COMPRESSEDNUMBER = COMPRESSEDNUMBER + RAWNUMBER[i + 4];
    69.                     COMPRESSEDNUMBER = COMPRESSEDNUMBER + RAWNUMBER[i + 5];
    70.                     COMPRESSEDNUMBER = COMPRESSEDNUMBER + RAWNUMBER[i + 6];
    71.                     COMPRESSEDNUMBER = COMPRESSEDNUMBER + RAWNUMBER[i + 7];
    72.              
    73.                 }
    74.             }
    75.             i = i + 7;
    76.         } // YOHOYOHO A COMPRESSORS LYFE 4 ME
     
    Last edited: Oct 8, 2022
  7. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,154
    AnimalMan likes this.
  8. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    nice one, I looked at some techniques. I will be locating unused bytes for example, on the left side of the binary value a specific variety are used, while on the right of the value another specific variety is used. Regarding numbers.
    Regarding text there are unused character combinations I will locate. And use a single byte as an identifier to flag certain repeat sequences. Signalling an offset to the storage position of the following binary pair. But one must be careful to ensure the offsetting is reversible. And that the selected values will never be used in the file format.

    so for example an image format, containing pixel colours and coordinates, at size delta. This will generally be filled with numerical values and so will never use on the left side certain sequences and will never use on the right side other sequences. And so modulo comes in to check the odd or even of these modules and then replace with an appropriate combination and then flipping this combination as it would cause an offset.


    The reconstruction will notice that this sequence is never normally found on the left side or another sequence is never normally found on the right side. And what the reconstructor then does is rebuild the data in accordance to whatever that flag was intended to mean

    this applies after a basic data reduction regarding repeat colour sequences and their pixel locations.
     
  9. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    Code (CSharp):
    1.  
    2.         for (int i = 0; i < CHARACTERS.Count; i++)
    3.         {
    4.             BINARYRESULTS.Add(StringToBinary(CHARACTERS[i].ToString()));
    5.         }
    6.         for (int i = 0; i < BINARYRESULTS.Count; i++) // Lets break up those Nodes
    7.         {
    8.             var FIRSTMODULE = "";
    9.             var SECONDMODULE = "";
    10.             var C = BINARYRESULTS[i].ToCharArray();
    11.             for (int x = 0; x < C.Length; x++)
    12.             {
    13.                 if (x < 4)
    14.                     FIRSTMODULE = FIRSTMODULE + C[x];
    15.                 else
    16.                     SECONDMODULE = SECONDMODULE + C[x];
    17.  
    18.             }
    19.             BINARYRESULTS[i] = "";
    20.             BINARYMODULES.Add(new List<string>());
    21.  
    22.             BINARYMODULES[BINARYMODULES.Count - 1].Add(FIRSTMODULE);
    23.             BINARYMODULES[BINARYMODULES.Count - 1].Add(SECONDMODULE);
    24.             BINARYRESULTS[i] = FIRSTMODULE + " " + SECONDMODULE;
    25.         }
    If the character array of the above code is only filled with values 0123456789 and the decimal place '.' And then only the FIRSTMODULE is collected. You will see all of the combinations used in the first module to represent half of one of these values. Likewise with the Second Module.

    FIRST MODULE
    HalfModule.png

    For values 0-9 in First Module will always contain 0011
    If the file is known to contain only numerical values this means that the first module never even needs to be stored. As the result can be known by the programmer. As its presence repeats for every byte in the file.


    For the Second Module -- these values are used to create the number;

    SECOND MODULE
    SecondModule.png

    If the reconstructor used never stores the first half of the module, then new binary data is written out of only the second half. So that right there is a 50% byte reduction ontop of any other info you may have already simplfied such as repeating colours.

    Effectively, when you have simplfied your file as small as it can be regarding repeating Data. This guy will reduce it by a further 50%. It may then be possible to run a third data reduction algorithm which checks for repeats here, but it would only save additional bytes if a value repeated >= 2 times. Basically 3 in a row. And in that case you would just knock it down 1/3rd And this is because it will cost you 1 byte for every 2 bytes of repeating data and you'll need to keep a reference to the byte you're replacing in addition to the flag which tells your reconstructor whats happening.

    a kean eye here will notice that 1111 is never used to represent numerical data. Well then we can use 1111 as a flag or separator. For example between values, or a double 1111 1111 to flag a change of logic

    a true master of logic production may then notice that 11__ as a double digit is never used. And we can call this identifier a qubit and if we detect a qubit well then we have a logic trigger that applies to the following byte an offset. Thus chasing the dragon size of PNG and hopefully obtaining a close fitting result.
     
    Last edited: Oct 9, 2022
  10. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    BINARYCOMPRESSOR_RESULTS.png
    The New Technique produces a file 3.76x the size of a PNG equivalent

    I wrote a function for anyone to easily test for themselves and check the results :)
    Code (CSharp):
    1.  
    2.     private void MAKE_ANIMALMANS_BINARY_COMPRESSED_FILE(string PATH)
    3.     {
    4.         var PIXELS = TEX.GetPixels32();
    5.         var COLOURS = new List<Color32>();
    6.         List<List<int>> COORDINATES = new List<List<int>>();
    7.         for (int i = 0; i < PIXELS.Length; i++)
    8.         {
    9.             if (!COLOURS.Contains(PIXELS[i]))
    10.             {
    11.                 COLOURS.Add(PIXELS[i]);
    12.                 COORDINATES.Add(new List<int>());
    13.                 COORDINATES[COORDINATES.Count - 1].Add(i);
    14.             }
    15.             else
    16.             {
    17.                 int COLORINDEX = COLOURS.IndexOf(PIXELS[i]);
    18.                 COORDINATES[COLORINDEX].Add(i);
    19.             }
    20.         }
    21.         List<char> FILE_CHARACTERS = new List<char>();
    22.  
    23.         var Width = TEX.width.ToString();
    24.         var Height = TEX.height.ToString();
    25.  
    26.         for (int w = 0; w < Width.Length; w++)
    27.             FILE_CHARACTERS.Add(Width[w]);
    28.         for (int h = 0; h < Height.Length; h++)
    29.             FILE_CHARACTERS.Add(Height[h]);
    30.         FILE_CHARACTERS.Add('_'); // LOGIC SWITCH
    31.  
    32.         for (int x = 0; x < COORDINATES.Count; x++)
    33.         {
    34.             var R = COLOURS[x].r.ToString();
    35.             var G = COLOURS[x].g.ToString();
    36.             var B = COLOURS[x].b.ToString();
    37.             var A = COLOURS[x].a.ToString();
    38.             FILE_CHARACTERS.Add('_'); // NEW COLOUR TRIGGER
    39.             FILE_CHARACTERS.Add('_'); // NEW COLOUR TRIGGER
    40.             for (int r = 0; r < R.Length; r++)
    41.                 FILE_CHARACTERS.Add(R[r]);
    42.             FILE_CHARACTERS.Add('_');// // LOGIC SWITCH R
    43.             for (int g = 0; g < G.Length; g++)
    44.                 FILE_CHARACTERS.Add(G[g]);
    45.             FILE_CHARACTERS.Add('_');// LOGIC SWITCH G
    46.             for (int b = 0; b < B.Length; b++)
    47.                 FILE_CHARACTERS.Add(B[b]);
    48.             FILE_CHARACTERS.Add('_');// LOGIC SWITCH B
    49.             for (int a = 0; a < A.Length; a++)
    50.                 FILE_CHARACTERS.Add(A[a]);
    51.             FILE_CHARACTERS.Add('_');// LOGIC SWITCH A
    52.  
    53.             for (int y = 0; y < COORDINATES[x].Count; y++)
    54.             {
    55.                 var W = COORDINATES[x][y].ToString();
    56.                 for (int z = 0; z < W.Length; z++)
    57.                 {
    58.                     FILE_CHARACTERS.Add(W[z]);
    59.                 }
    60.                 FILE_CHARACTERS.Add('_'); // NEW COORDINATE
    61.             }
    62.         }
    63.         FILE_CHARACTERS.Add('_'); // ENDFILE
    64.         List<string> BINARY_STRINGS = new List<string>();
    65.         for (int c = 0; c < FILE_CHARACTERS.Count; c++)
    66.         {
    67.             BINARY_STRINGS.Add(StringToBinary(FILE_CHARACTERS[c].ToString()));
    68.         }
    69.         List<string> COMPACT_BINARY = new List<string>();
    70.         for (int d = 0; d < BINARY_STRINGS.Count; d++)
    71.         {
    72.    
    73.                 var A = BINARY_STRINGS[d];
    74.                 var B = BINARY_STRINGS[d + 1];
    75.                 var ABSTRACT_BINARY_VALUE = "";
    76.                 for (int a = 0; a < A.Length; a++)
    77.                 {
    78.                     if (a > 3)
    79.                         ABSTRACT_BINARY_VALUE = ABSTRACT_BINARY_VALUE + BINARY_STRINGS[d][a];
    80.                 }
    81.                 for (int b = 0; b < B.Length; b++)
    82.                 {
    83.                     if (b > 3)
    84.                         ABSTRACT_BINARY_VALUE = ABSTRACT_BINARY_VALUE + BINARY_STRINGS[d][b];
    85.                 }
    86.                 COMPACT_BINARY.Add(ABSTRACT_BINARY_VALUE);
    87.                 d = d + 1;
    88.    
    89.         }
    90.         List<byte> BYTES_TO_WRITE = new List<byte>();
    91.         for (int B = 0; B < COMPACT_BINARY.Count; B++)
    92.         {
    93.             var b = MAKEBYTE(COMPACT_BINARY[B]);
    94.             BYTES_TO_WRITE.AddRange(b);
    95.         }
    96.         var C = File.Create(PATH);
    97.         for (int i = 0; i < BYTES_TO_WRITE.Count; i++)
    98.         {
    99.             C.WriteByte(BYTES_TO_WRITE[i]);
    100.             C.Flush();
    101.         }
    102.     } // yoho yoho a compressors lyfe 4 me
    103.  
    104.     public byte[] MAKEBYTE(string DATA)
    105.     {
    106.         int numOfBytes = DATA.Length / 8;
    107.         byte[] BYTE = new byte[numOfBytes];
    108.         for (int i = 0; i < numOfBytes; ++i)
    109.         {
    110.             BYTE[i] = Convert.ToByte(DATA.Substring(8 * i, 8), 2);
    111.         }
    112.         return BYTE;
    113.     }
    114.     public static string StringToBinary(string data)
    115.     {
    116.         StringBuilder sb = new StringBuilder();
    117.         foreach (char c in data.ToCharArray())
    118.         {
    119.             sb.Append(Convert.ToString(c, 2).PadLeft(8, '0'));
    120.         }
    121.         return sb.ToString();
    122.     }
    123.  
    124.  
    using System;
    using System.Text;
    using System.IO;
    Have Fun
     
    Last edited: Oct 9, 2022
  11. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    Unlikely my ‘genius’ solution is decompress-able.
    Though I restore and rebuild the correct quantity of data. At least 50% of restores at incorrect coordinates. Which I had a little research myself and i am not sure I am all that smart in the end. Maybe it will click a solution. But perhaps this technique is not written about very often or at all because it can not work. It seems the 0011 on the 8bit binosaurus plays quite a role behind the scenes on write. Oh yes. I’m talking write string, write int etc. that is what the identifier is for. And without it. On read all bytes vast majority are jumbled. First half is never the same as the first half that was written. Reassembling the value is not a walk in the park. So for now it is what it is. I thought we would have good free control of those chip modules, but apparently other forces are at play involving the binary and read byte functions central around the index establishment. There is no point posting the code I wrote to rebuild but know that it was immaculate. I took a screen of both arrays before write and after read, and tried to draw a web to find the pattern. But not much luck so far.

    one logical reason I could produce as to why free control is not granted over all 8bit binary modules over the first 4 nodes specifically is that data is also relating to telling the screen how and what to display. Although it is an abstract customisable value in terms of a standalone unit, the abstract nature of the system has already been analogged. There is potentially physical engineering that prevents what I am trying to do.

    perhaps I will take a look at the hex editor, at the png file and search for the presence of 0011, which should exist at every saved value if that it is truely unremovable.
     
    Last edited: Oct 10, 2022
  12. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    ENTROPY.png

    Code (CSharp):
    1.  
    2.             A = File.ReadAllText(PATH, Encoding.Default);
    3.             B = File.ReadAllText(PATH, Encoding.UTF7);
    4.             C = File.ReadAllText(PATH, Encoding.UTF32);
    5.             D = File.ReadAllText(PATH, Encoding.Unicode);
    6.             E = File.ReadAllText(PATH, Encoding.ASCII);
    7.             F = File.ReadAllText(PATH, Encoding.BigEndianUnicode);
    8.    
    9.             for (int i = 0; i < B.Length; i++)
    10.             {
    11.                 var T = StringToBinary(B[i].ToString());
    12.                 string MOD1 = "";
    13.                 string MOD2 = "";
    14.                 for (int x = 0; x < T.Length; x++)
    15.                 {
    16.                     if (x <= 3)
    17.                     {
    18.                         MOD1 = MOD1 + T[x];
    19.                     }
    20.                 }
    21.                 for (int x = 0; x < T.Length; x++)
    22.                 {
    23.                     if (x > 3)
    24.                     {
    25.                         MOD2 = MOD2 + T[x];
    26.                     }
    27.                 }
    28.                 MOD1 = MOD1;
    29.                 MOD2 = MOD2;
    30.                 DECODED_TEXT.Add(MOD1);
    31.                 DECODED_TEXT.Add(MOD2);
    32.             }

    I got it

    Code (CSharp):
    1.  
    2.             for (int i = 0; i < DECODED_TEXT.Count; i++)
    3.             {
    4.                 DECODED_TEXT_RESTORED.Add("0011 " + DECODED_TEXT[i]);
    5.             }
    Assemble the number too early --- ENTROPY some random elements are incorrect; SO you must assemble the number carefully :)

    The decoder must be written and referneced

    Code (CSharp):
    1.  
    2.             for (int i = 0; i < DECODED_TEXT_RESTORED.Count; i++)
    3.             {
    4.                 for (int d = 0; d < DECODER.Count; d++)
    5.                 {
    6.                     if (DECODED_TEXT_RESTORED[i] == DECODER[d])
    7.                         FINAL_DATA.Add(ENCODER[d]);
    8.                 }
    9.             }
    ALL_DONE.png
     
    Last edited: Oct 10, 2022
  13. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    Build Em Up
    Code (CSharp):
    1.             for (int i = 0; i < B.Length; i++)
    2.             {
    3.                 var T = StringToBinary(B[i].ToString());
    4.                 string MOD1 = "";
    5.                 string MOD2 = "";
    6.                 for (int x = 0; x < T.Length; x++)
    7.                 {
    8.                     if (x <= 3)
    9.                     {
    10.                         MOD1 = MOD1 + T[x];
    11.                     }
    12.                 }
    13.                 for (int x = 0; x < T.Length; x++)
    14.                 {
    15.                     if (x > 3)
    16.                     {
    17.                         MOD2 = MOD2 + T[x];
    18.                     }
    19.                 }
    20.        
    21.                 DECODED_TEXT.Add(MOD1);
    22.                 DECODED_TEXT.Add(MOD2);
    23.             }
    24.             for (int i = 0; i < DECODED_TEXT.Count; i++)
    25.             {
    26.                 DECODED_TEXT_RESTORED.Add("0011 " + DECODED_TEXT[i]);
    27.             }
    28.    
    29.             for (int i = 0; i < DECODED_TEXT_RESTORED.Count; i++)
    30.             {
    31.                 for (int d = 0; d < DECODER.Count; d++)
    32.                 {
    33.                     if (DECODED_TEXT_RESTORED[i] == DECODER[d])
    34.                         FINAL_DATA.Add(ENCODER[d].ToString());
    35.                 }
    36.             }
    Break Em down
    Code (CSharp):
    1. List<string> BINARY_STRINGS = new List<string>();
    2.         for (int c = 0; c < FILE_CHARACTERS.Count; c++)
    3.         {
    4.             BINARY_STRINGS.Add(StringToBinary(FILE_CHARACTERS[c].ToString()));
    5.             ORIGINAL_TEXT.Add("");
    6.             for (int b = 0; b < BINARY_STRINGS[BINARY_STRINGS.Count - 1].Length; b++)
    7.             {
    8.                 if (b > 3)
    9.                     ORIGINAL_TEXT[ORIGINAL_TEXT.Count - 1] += BINARY_STRINGS[BINARY_STRINGS.Count - 1][b];
    10.             }
    11.         }
    12.         ORIGINAL_BINARIES.AddRange(BINARY_STRINGS);
    13.         List<string> COMPACT_BINARY = new List<string>();
    14.         for (int i = 0; i < ORIGINAL_TEXT.Count; i++)
    15.         {
    16.             COMPACT_BINARY.Add(ORIGINAL_TEXT[i] + ORIGINAL_TEXT[i + 1]);
    17.             i = i + 1;
    18.         }
    19.         List<byte> BYTES_TO_WRITE = new List<byte>();
    20.         for (int B = 0; B < COMPACT_BINARY.Count; B++)
    21.         {
    22.             var b = MAKEBYTE(COMPACT_BINARY[B]);
    23.             BYTES_TO_WRITE.AddRange(b);
    24.         }
    25.  
    26.  
    27.  

    I'd say this Dragon is slayed.


    COMPLETE.png
    My Work here is Done.


    Dwarf Wins
    Flawless Victory
     
    Last edited: Oct 10, 2022
  14. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    Code (CSharp):
    1.  
    2.             int WIDTH = 0;
    3.             int HEIGHT = 0;
    4.             int.TryParse(RAW_WIDTH, out WIDTH);
    5.             int.TryParse(RAW_HEIGHT, out HEIGHT);
    6.             Debug.Log(WIDTH + " " + HEIGHT);
    7.             var COLORS = new List<Color32>();
    8.             var COORDS = new List<List<int>>();
    9.             for (int i = 0; i < GREEN.Count; i++)
    10.             {
    11.                 byte R = 0;
    12.                 byte G = 0;
    13.                 byte B = 0;
    14.                 byte A = 0;
    15.                 byte.TryParse(RED[i], out R);
    16.                 byte.TryParse(GREEN[i], out G);
    17.                 byte.TryParse(BLUE[i], out B);
    18.                 byte.TryParse(ALPHA[i], out A);
    19.                 var C = new Color32(R,G,B,A);
    20.                 C.r = R;
    21.                 C.b = B;
    22.                 C.g = G;
    23.                 C.a = A;
    24.                 COLORS.Add(C);
    25.                 COORDS.Add(new List<int>());
    26.             }
    27.             for (int c = 0; c < COORDS.Count; c++)
    28.             {
    29.                 for (int i = 0; i < COORDINATES[c].Count; i++)
    30.                 {
    31.                     int VALUE = 0;
    32.                     int.TryParse(COORDINATES[c][i], out VALUE);
    33.                 }
    34.             }
    One important thing to note on the final leg of the journey, however you chose to encode the reconstructor. Color32 will take bytes instead of standard ints :)

    Below are the available logic triggers.
    SWITCHES.png

    Perhaps there was a simpler way to achieve this binary compression and revert back to correct values.
    But for now this is the best and only way that I know.

    Concluding Once and for all,

    The Best Available Image Format is PNG in terms of FileSize;
    But Honestly, If you ask me; you're much better off Making your own.

    For Me. The Best Image Format is; My Own Image Format. :)
    For by doing so I have learnt through this process; since Friday.
    Encryption Methods. Binary Compression and Binary Decompression, and Reconstruction.
    Enabling me to have a file that is not too space consuming as it would have been; and one that can easily be expanded to include multiple frames of an animation sequence, compress, decompress and rebuild these frames using logic provided exclusively within my game, unique to my game, and its code. and although I will have a file dump directory for the user to dump their own art and files. For my own graphics and my own Art, for me to even want to bother putting in the highest effort I could. Having this protection and elite exclusivity means I can set boundaries for the player for which that they are not allowed to extract or modify my files without themselves being intellectually and programmatically advanced.

    And with this. Thanks to everyone who helped and pushed me in the direction Orion Especially for his video recommendation which played a huge role in my eventual understanding of binary compression.

    For me the Dragon is as good as Slain.
     
  15. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    Back once again

    I know i had destroyed the dragon but blood still flows from its loins.
    See those two green pixels top right hand corner?
    They are not suppose to be there.
    The new .Animal file shown below has compiled all this little crappy infantry's frames into the one file, and then uncompiles them beautifully for me. But for some reason the top right pixels are never found. I coloured them bright green so we could see them.
    AnimalFile.png
    For now i repair them like this
    Code (CSharp):
    1.  
    2. if (PIXELORDER.Count < P.Length)
    3. {
    4.     for (int i = 0; i < 4; i++)
    5.     {
    6.        var C = new Color32();
    7.        C.r = 0;
    8.        C.g = 255;
    9.        C.b = 0;
    10.        C.a = 255;
    11.        PIXELORDER.Add(C);
    12.        if (PIXELORDER.Count == P.Length)
    13.             break;
    14.     }
    15. }
    Maybe just as I have been fixing things for a few hours the pixels themselves being missing at this corner does not really matter, but as the perfectionist in me wants to find out why. I wondered if anyone is interested in this image format themselves drop me a message for the full script, for yours to keep if you promise to locate the cause of this issue. Otherwise I will probably forget about it and make them transparent.
    Anyways Happy Coding! Have a great evening
     
  16. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    Using (tm) when in doubt print it out!

    I managed to locate the two missing pixels. Which appear to be lost at the transition to end of file.

    Thead.close();