Tuesday, March 14, 2017

Differences In Image Formats

So I know a person who back in my Java 1 class thought it would be cool to show me a trick. Essentially the trick was (he thought) that he can convert an image from one format to another simply by changing its extension. Needless to say I wasn't impressed, in fact I got pretty angry. I told him "No you didn't convert the image, you only changed the extension". He continued to state that he did since it worked. Now just because the software you are using is smart enough to detect the actual format of an image or dumb enough to abandon standards to do that is irrelevant. In this post I will describe the basics of what makes an image format different from another.

Now the extension is the first difference which everyone sees and is arguably the first difference to be noticed. It is simply text appended to the end of the filename. In terms of image formats you might have BMP, PNG, GIF, JPG, TIFF, WEBP, etc...
The extension though is only related to the file name, it is NOT related to the actual data of the file. The file name doesn't reside as data in the image, if you look at the file in a hex editor you will not find the filename. The filename and extension is for allocation in the file system used. If you open the allocation table of your drive you then will see it there. So changing the extension doesn't even change a single bit in the image file.

The header of an image format or any file format specification is actually in the data. Changing this might or might not affect the use of the file depending on where in the header you mess with. There are several parts in the header and each format has a different type and number of headers but typically the Magic/Signature is the first thing you will see.

The Magic is the first few bytes which identifies what format the file is in and in some cases provide metadata. Parsing this will allow the ability to know the file's format but even more importantly its structure. Here you can see the Magic between the same image but one in JPG and one in PNG.

I'm not going to explain the entire header of these two formats but I will present them so that the difference can be seen.
JPG Header:

PNG Header:

Note: JPG has several different headers depending on options and type. You can see from the image I posted above that the JPG used here is of the EXIF type.

Now we can see that the structures of the image is completely different. A JPG decoder can not interpret a meaningful image if it tried to decode a PNG and vice versa.

Even if the headers were the same the inner workings of the two formats would be completely different which leads use to the encoding and decoding of the image data.

JPG works by use of huffman tables and quantization tables. These tables are computed and is what gives the image the compression and lossy factors. This is also what allows different encoded images to be decoded the same way.

PNG on the other hand uses compressed chunks. Chunks are used so that PNG can be presented in a streamed manner but the image is encoded typically using a compression algorithm of the lossless kind. This gives per-pixel integrity at the cost of usually producing a larger file size (than JPG).

Thursday, February 23, 2017


This is a tool I made for people who draw on paper and plan to scan their work onto the computer. Typically these scans look very unprofessional due to the paper gradient the drawing is on. for example this drawing I found on google:

Typically its line art which go through this process from what I see my friends do. The process can be done in photoshop or other editing tools but its tedius. I thought hmm, I can make a program which eases everything. The outcome looks like this:

The program has only one option to adjust which is the threshold. The threshold controls how light or how dark a pixel can be to be kept in the image or left out completely (turns it 100 percent transparent). Messing around with this might or might not enable you to get the results you want. Too High and it might keep artifacts or defects in your image which you wanted out, adjust it too low and it might leave out details which you might wanted to keep.

DOWNLOAD: ImageTransparencyInducer

Here are some other before and after examples:

Sunday, September 18, 2016

Learning any base numbering system

In previous tutorials I made, I showed how to work with binary (a base 2 system) and hexadecimal (a base 16 system). There are many things they share and principals in their systems which are true. Knowing these principals you can derive and learn any base system quickly and intuitively.

The first thing you must realize is the BASE of the system. This is the determining factor in knowing the place value for each digit. For example if we use the decimal system what we count with everyday we see that it is base 10. That means there are 10 distinguishing characters used in this system. These characters correlate to the digits and in actuality can be any character but for this example we will use the characters we are all familiar with which would be [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]. As you can see there are 10 distinguishing characters or digits.

Lets talk about place values now. Given any base system each place value to the next is calculated by (BASE ^ PLACE).

So in the base 10 system its like this:
...... 10000(or 10^4), 1000(or 10^3), 100(or 10^2), 10(or 10^1), 1(or 10^0).

so given the decimal(base 10) number 54,321 we can see that there are:
5x10000 or 5x(10^4) = 50000
4x1000 or 4x(10^3) = 4000
3x100 or 3x(10^2) = 300
2x10 or 3x(10^1) = 20
1x1 or 1x(10^0) = 1

if you add these all up (50000 + 4000+ 300 + 20 +1) you get 54,321.

Now lets try duodecimal(base 12).
Lets establish the characters [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B].
(where A can be thought of as 10 and B as 11)
now establish the place values.
.......20736(or 12^4), 1728(or 12^3), 144(or 10^2), 12(or 12^1), 1(or 12^0).
so given A53B7:
Ax20769 or Ax(12^4) = A0000
5x1728 or 5x(12^3) = 5000
3x144 or 3x(12^2) = 300
Bx12 or Bx(12^1) = B0
7x1 or 7x(12^0) = 7

if you add these up you get A53B7.

because every system is base based (lol didn't realize this pun until I wrote it) we can just divide the the bases to go from one base to another. using the remainder as the desired next digit in the resulting base's number.
One way is to do long division with the 2 different bases and help with base 10.
I'll get more into converting from any base to any other base in my next post.

Monday, June 20, 2016

VBES - Saving even more bandwidth with UTF8

So a while ago I came up with an encoding scheme which utilized UTF8's variable byte concept to essentially save bandwidth while chatting in instant messaging scenarios. After that I had thought of improving upon that idea even further but never got around to actually coding it, I had the idea down but I didn't have a solid working scheme much less code. The other day though I thought I'd work on it and after planning it out and finishing the encoder and then the decoder the next day I had come up and made an encoding scheme which meets all the requirements of my previous encoding scheme and performed better (in saving bandwidth). This new scheme implements the idea that some letters are used more often then others and so if I allocate fewer bits to those more likely used letters the final message should be pretty small. I broke up the letters, a few punctuation, a space and an escape for UTF8 fallback into groups of 4bits, 6bits, 8bits, and 9bits. It is completely backwards compatible with UTF8 which is nice in scenarios where VBES would produce larger messages, one can just used the UTF8 version instead and the message would still be decoded. Its a simple concept and I will be opting to use this for my future messenger app.

How it works:
* 0000
e 0010
t 0011
a 0100
o 0101
i 0110
n 0111
s 1000
h 1001
r 1010
d 1011
l 1100
c 1101

u 111000
m 111001
w 111010
f 111011
g 111100
. 111101

y 11111000
p 11111001
b 11111010
v 11111011
k 11111100
j 11111101

, 111111100
x 111111101
q 111111110
z 111111111

The * signifies that there is an escape and a UTF8 encoded character should fill the space.

Demo Encoder/Decoder: Download VBES Encoder Decoder

How much space does this save?
In the best case scenarios the size of the message is 50 percent of the UTF8 message plus 1 byte. So that is (X*.5)+1 bytes.

Where does this 50 percent plus 1 come from?
The half comes from the fact that the most optimized characters are 4 bits long which is half a byte which is half the size of the smallest possible letter in UTF8 which is a byte. The +1 comes from the fact that if a message consisted of all 4bit letters and fit perfectly into multiples of 8bits there would still require 2 more bits for the UTF8 marker. With those 2 included bits there now has to be padding and thus an entire byte has been added to the message.

How does this compare to the previous encoding scheme?
The previous encoding scheme worked on optimizing several characters and allocating 6 bits for each of those optimized characters. Because 6 is 75 percent of 8 and also had the 2 added bits for the UTF8 marker its best scenario efficiency would be (X*.75)+1.

How comes this scheme doesn't optimize capital letters?
By default this scheme will turn the entire input message to lowercase because only the lowercase letters are optimized and thus the message would save the most space this way but you can disable this behavior if you truly wish to send a message with capital letters. The capital letters each will be encoded using standard UTF8 and their placement will be signified with 0000 which is also used to signify the placement of other UTF8 encoded characters.

Source (VB.net):

Open/Free for non-commercial use.

Tuesday, April 26, 2016

Interesting Videos

On the internet there are many sources of information. This post will revolve around videos on YouTube which provided me with knowledge of some form of intellectual interest.

More to come....

Friday, April 22, 2016

Essay Builder

     I have started college again recently (or not so recently) and am nearing the end of my first semester. I am finding myself struggling with one class, English 102 (the research paper). Now this isn't because I hate writing or because I lack the ability to do research but personally I think I am simply lazy to write an essay. When I think of research in terms of gaining knowledge I do just that, gain the knowledge. I do not write things down and I ultimately don't see the need. If knowledge is what I am after and I need a book with me to reference and reread over and over again that simply means I didn't obtain that knowledge (in my opinion). So I had this idea of making a program which makes the essay for me. Now this isn't some magic bullet idea, most of the work will still be done in person like the actual research etc. This program is only going to provide a more seamless and ease the process of structuring, citation etc. I have yet to work on this program and its too late for me to use it on the current paper I am working on but I already have the basic idea and concepts. Once it is done, I will provide it here for people to use so people don't have to suffer from BULLSHIT ass English classes that are ultimately useless in most everyday jobs/careers.


Friday, April 1, 2016

Hacking together a Chess AI

UPDATE: Because of real life and AI being more complicated the competition has been halted until further notice.

     So I am in school again and I have this Java class where I've meet familiar people from years ago. So we have been through this java class for a while now and honestly it isn't all that fun. The algorithms we write are small and not very intellectually challenging. The concepts we have to learn I already mostly know. These days I just walk around class helping others who need it. So I think its safe to say I am bored, oh so VERY BORED. So just recently there was the event of a Go program from google which defeated the work Go champion. The program is an AI which was trained over and over again which means it stores knowledge about the game and plays accordingly instead of say going through and searching through a database of movies or brute forcing the problem. This led to me wanting to do something similar. I proposed to one of my friends from my Java class that we should both make a chess AI and in due time have them face each other in a contest. I eventually persuaded another person to join us. To be honest this was originally supposed to be a connect4 AI but I figured chess would be more fun and challenging. So the three of us are to make a Chess AI and compete hopefully sometime in July. Having said all that, none of us knows anything about programming an AI and thus this is going to be our wits at work here as we frantically piece and hack together a chess AI.

AI cannot have a database of games played (no game look ups), a database of essentially knowledge is okay.
AI is allowed to train during a game through playing.
Games will have 10 minutes on the clock, once that time runs out, the AI will only have 10 seconds to make a move.
Total game time will be 30 minutes per match, if no winner is achieved by that time the game ends in a draw.
If an AI makes an illegal move the game is lost.
5 Games will be played per pair (of contestants).
Winner of the game is determined by best 3 out of 5 but all games will be played.
Winner of the contest is determined by the AI with the most wins among all played games.
If there is a tie, consecutive games will be played, winner is the first to claim a win.
Game will follow these draw rules, but AI doesn't implement this, it just need to know that a game is a draw or when to offer/accept a draw:

More rules maybe added/changed.

Contestants / Implementing Language:
Tim / Java/JavaScript(with extensions)
TizzyT (me) / C#
Dan / C# (maybe Java)
Chris (programming prodigy)/ C#
Phat / Java

Here is some basics I found:

As time goes by we inch closer and closer to the eventual date of the contest. The contest will record every game. The record will include events (moves etc), and the time stamp of each event.

Saturday, January 23, 2016

Introductory to Java

I have started school again recently and one of my classes (for Computer Science) is Java 1. I figure it might be a good idea to make a blog post for it to document and to help classmates who need it. I will cover things in the lessons and explain them in my own way (to help classmates if they so happen to need it) as well as some things I notice, advice, etc. I will try to use illustrations where possible and analogies where concepts are somewhat complex. Also keep in mind that I am not an expert by any means but I thought I would provide this in hopes of people will get at least a feel for how programming is, So while some information for example terms and such might not be completely accurate they should be close enough to use as a stepping stone to reach an understanding on your own that you will develop. Of course if anyone feels as though they need to make corrections or contribute the comment section is open.

[Week 01]
    This week it seems we talked about how a computer system works and how it operates on data. I wont get into much details about that because this is a Java class I don't think this is all that important to know since Java is a high level language. There is no need to worry about things as ALU, or registers etc because they are on a much lower level and programming in Java you will most likely never encounter a scenario where you need to worry about such things.

    Finally towards the end of the first week we got to some code. Although simple there were a couple things we were told not to worry about until later but I feel as though they should have been covered early on so that there is room for familiarity when we do get to them later. We were asked to make a "Hello World" program. This program is typically the first program beginning programs try to make. Keep in mind that I wont be providing code for any other assignments besides the "Hello World" instead I will try to create similar code which will demonstrate the same material.

    Now the code for Hello World will look like this:

    Now there are some other lines before the snippet shown but those wont be important throughout the whole class I believe unless we get into import etc.

We can look at this following code line by line.

Line 1 ("public class HelloWorld {"):
    This specifies that there is a class called HelloWorld. First we have the word "public" this is the access modifier. This states that the "class" can be accessed through the rest of the program. There are other access modifiers like private and such as well and they should be used according to your needs and where appropriate.
Click here to know more about Java Access Modifiers
The next part "class" is usually the Type specifier and will provide information on what kind of thing something is. There are many Types and one can make their own as well. Next we have "HelloWorld". This is a name. This can be anything the programmer wants to call it but typically this should be given a good meaningful name which correlates to it purpose. There are restriction in naming things. You cannot name something that is already taken by a reserved keyword. So words like "String" or "public" will not be allowed. Names also cannot contain any blank spaces in between and to make up for that we have something called CamelCasing which basically has you capitalizing the first letter of each word in place of putting a space. Finally on this line we have a open curly brace "{". In this case this essentially encapsulates the code that will be associated with the class called "HelloWorld", but it will be used to encapsulate code to anything and is used to define the scope. Some people have this placed on the next line but it doesn't really matter as Java is not a line oriented language and so this can be placed anywhere as long as it is directly before the code you want associated with the class also you should pick some convention and stick with it for readability for other people. This easily shows what code is apart of what.

Line 2 ("  public static void main(String[] args) {"):
    The first thing we see here isn't very important in that you can not do this and your program will still run exactly as if you did have it. Its the indentation (the long blank space). Indention is an important thing that one should learn to do as to make it easy for people reading your code to know what level things are at. The more to the right a line is the deeper that code is. The more left means its closer to the general level. Again without it your programs will still work but readability will be lacking and I wont be surprised of the professor took points off for it. "public" was already covered in line 1 and essentially serves the same purpose. "static" states that this is shared among all other instances of the class HelloWorld. You can have a million instances of HelloWorld but they will all use this one main function. "void" essentially means that this is a function which(to the coder) doesn't doesn't return anything back, functions that don't return anything are also called methods. "main" is typically the name of the entry point and where the program begins executing the programmers code. Next we have an open parentheses "(". This is the opening for parameters, just like in Mathematics where you would have a function for example f(x) aka F of x. In pretty much the same idea the parentheses is there to distinguish the function part from the parameter part. Next we have "String[]". In this part there are actually several things happening. First this part syntactically is another Type specifier which was covered above. It is essentially telling what kind of data x is. Here we can see the type is "String". A string can be just thought of as text, so basically a bunch of characters. Then we have the "[]" which specifies that the String is actually an array. You can typically use this along with any Type when you want to make an array of them. So in this case for example instead of just containing one String, this can contain multiple Strings. "args" is the name of the String[] from earlier. This is used for referencing later just like how the x in f(x) is referenced when defining a function, for example f(x) = x + 1. The function name is f, the parameter is x and the function returns basically what ever number you use as x incremented by 1. So if I put in 1 I get 2 and if I put 2 it results in 3. The closing parentheses is used to enclose the parameter portion of the function. Some functions will not contain any parameters and will only show the opening and closing parentheses like this "()". Finally for this line we have another open curly brace "{". This again is to encapsulate anything that is to be associated with (in this case) this function and defines that this is the begin of the encapsulation or defining the beginning of the scope of this function. Scope is the accessibility of something given what level they are on. Remember the indentation. Things on the same level can access each other or on anything that is on a level to the left (as long as it is only to the left, the moment something branches to the right again, anything within that scope that went right will not be accessible).

Line 3 ("    System.out.println("Hello, World");"):
    First we see there is a long blank. This you will see is about twice the length of the blank space from the previous line. This indentation is on another level/scope. This means that anything on this line can access other things on the same scope or anything to the left (in this case things with one indentation). Next we have "System" and is a built in class to Java and has many useful things programmers typically would use. "." is the next thing we see and it is to specify that we are going to reference something that is a part of "System". "out" is the built in output stream object. It is used to output to the console, it is apart of the System class. "println" is a function that is a part of "out". In this case you can think of "System" as some company, "out" is some worker at that company, and "println" is a job that worker knows how to do. Now we see an open parentheses which provides the same functionality as mentioned before. It is there to specify the parameters. In this case (although not shown here) println will be taking in a parameter of Type string. Next we see "Hello World" (including the double quotes). This is called a string literal. A String literal is a string that is used without being assigned to a variable and instead used directly as is. Strings are distinguished with quotes and double quotes. We then see a closing parentheses which indicates the end of the parameters. Finally we see ";" which is used to end the code statement. Because Java is not a line oriented language it needs something in place to indicate and separate statements from one another.

Line 4 ("  }"):
    This is to close the encapsulation or scope of the code block. In this case it closes the function main from earlier.

Line 5 ("}"):
    This is to close the encapsulation or scope of the class HelloWorld.


Comments: Comments are bits of text to note a line of code or note the functionality of a function or the entire program. It can also be used to relay other information as well. Comments can be denoted with two back slashes for small single line comments. Multi-line or block comments can be denoted by beginning with "/*" (without double quotes) and ending them with "*/" (without double quotes). Here are some examples of comments:

Variables: Earlier we talked about String literals and how it wasn't assigned to a variable. Variables are a way of storing things for later referencing/usage. The times we use things such as String literals is when we don't need to reference back to it multiple times and make any changes etc. You create a variable by first specifying an access modifier though not always necessary and can sometimes be skipped. Next you need to specify a variable Type. This can be any of the primitive types such as int, long, float, and double or be specified to a custom Type you made either by creating a class or structure of the same Type name. Next you give the variable a name. This has the same name restrictions as mentioned earlier. Next you can either assign a value to the variable with an equal sign "=" and then close it or just close it without assigning a value with a semicolon ";". Here are some examples of variables:

[Week 02]
    Week two had some basic math and data types. We did addition, subtraction, multiplication, division, and modulus. We also went through unary and binary operators as well as compound operators as well as increments/decrements. Constants were touched on although for me it begs the question "what about readonly" ? It turns out there is no "readonly" in java. Just a mushed together "final". Java seems to be pretty bad if you are trying to do math and with accuracy. For instance in Java it is stated that an integer can store a value between -2,147,483,648 and 2,147,483,647. Now at first one might not see anything wrong with that and I would agree but the problem lies in that there is no unsigned integers. Now this honestly isn't all that big a deal but it unsigned types have their uses. Say we know for a fact that we will never have to deal with negative numbers in our program but we need to store values between 2,147,483,647 up to 4,294,967,295(2^32 - 1). In Java to represent that number we have to instead resort to an 8 byte variable (long) to represent that number instead of the 4 byte variable (int). It is pretty wasteful to allocated twice the amount memory for a number that can be represented with 4 bytes. Of course computers these days have plenty of memory and that is why I said its not such a big deal but it is still a fault and I personally don't know why it was a design choice in Java. Now onto the real problem, lets say we have an integer. Remember that an integer has the specific range -2,147,483,648 to 2,147,483,647 so anything outside that range an integer type simply cannot store it. Lets look at this line of code:

As you can probably figure the answer is -4,000,000,000 but that is outside the range of integer. So one would expect to get an error but instead Java gives the answer 294,967,296. This is very bad in that if you are doing math related things you would get an answer and might unknowingly use the wrong answer thinking it was correct. This also gives us a difficult time when debugging in cases where the input value is unknown and this unwanted behavior is only present in certain inputs. Your program would compile fine, and maybe run fine most of the time but every so often it will give you the wrong answer and nothing to indicate that it did so. After a few tests I figured out the behavior of what Java does in these situations. If the number is outside the range of integer Java will wrap around to the other end of the range and continue the arithmetic from there. I figured this out by taking integer's lowest possible value (-2,147,483,648) and subtracting 1 from it and see where it lands. It lands on the integer's maximum value (2,147,483,647). So Java essentially doesn't underflow or overflows. Now I don't know why Java is designed like this but in this situation one would want some indication of when it underflows or overflows so we don't get wrong answers in our calculations. So in this respect this behavior is pretty bad. The same thing happens when we do 2,000,000,000 + 2,000,000,000. We know the answer is 4,000,000,000 but Java cant store that value in an int, it gives us an answer anyways (-294,967,296)..... How can adding two positive numbers result in a negative number... bad Java BAD! Go to your room!!!

    Now this next problem isn't really a problem and it isn't only Java but several other programming languages as well like C#. The problem here is with the modulus operator. With all positive numbers as parameters it behaves as it should but when you add a negative number into the mix things become off. This is because some languages' modulus and clock arithmetic behave differently. And thus in cases like:

Java and C# gives the answer -1 while clock arithmetic and several other programming languages will give you 2. If you think about it 2 makes sense in that you actually have something left over and that it shows that the number is 2 MORE than a multiple of 3 (-10 is 2 more than -12). It doesn't really make sense to have a negative amount left over, but then again depending on your definition here -1 also makes sense in that it shows that -10 is 1 LESS than a multiple of 3 (-10 is 1 less than -9).
So if you are doing modulus keep the scenario of negative numbers in mind and that remainder and modulus are not always the same thing or defined the same.

    So enough with ints what other variables are there.
First we can look at a boolean. A boolean stores one of 2 states. You can think of it as being one bit (although it does NOT take up only 1 bit in memory). Booleans in Java do not store numeric values it seems and only "true" or "false" states. Now lets take a look at a byte. A byte is a representation of 8 bits in memory. A byte is typically the smallest unit of data after a bit that people use. In Java it can store the values between (inclusive) -128 to 127 with a maximum of 256 possible states. As you can see this has the same fault as int mentioned above. Even though technically it can represent values up to 255 (because 0 is a state you cannot store the value 256) starting from 0 it is wasted on negative numbers when negative numbers aren't needed. Furthermore byte data is usually thought of as being a value between 0 and 255 so again I don't know why Java is designed this way.
Next you might say what if we double the number of bits/bytes. Wouldn't that allow me to store a larger number? And yes you would, for a 16 bit/2 byte type it is usually called a short. This stored the inclusive range of -32,768 to 32,767. And then if you double that to 32 bits/4 bytes you get int which we have discussed above. Finally for whole numbers of primitive types we have long. A long is a 64 bit/8 byte type. It can store the inclusive range -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Besides whole numbers we can also represent fractional numbers. For this we have the floating point types first of which is float. Float is a 32bit/4 byte variable. It stores the value in a specific format as the sign (whether positive or negative), the exponent (power at which to raise to), and the fractional part (value to use in calculating the original number). Now because these numbers use exponents to represent their values their range can be from a very small to very large but at a price. Precision/Accuracy is forsaken due to rounding errors when trying to store a number that is too specific (large number of decimal places). Float types can store values between 1.40129846432481707 * 10^-45 to 3.40282346638528860 * 10^38 (positive or negative) or about 7 digits. We can increase the precision and accuracy by doing what we did with the whole number types and that is to double the number of bits/bytes. In doubling the size of a typical float we then get a 64 bit/8 byte floating point number the double. Now this can store even larger/smaller numbers ranging between 4.94065645841246544 * 10^-324 to 1.79769313486231570 *10^308 (positive or negative) or about 15 digits. Finally there is the char type which is used to represent individual characters. Char has a maximum of 65536 states and can store the numeric values of between 0 and 65535. To get around the unsigned short problem you can do arithmetic with char types if needed but it becomes unclear for others when reading it even thought a character and a number its typically (because of the type name) thought of as characters.

    Lets move onto operators.
In Java there are a couple operators although I personally wished there were a couple more to make out lives easier but essentially we have the following:

Now there are others but these are basically what people will use mostly.

Wednesday, December 23, 2015


While working on my game I needed to be able to see how many different colors there were in an image. I figured there were online tools to do such an easy task but everywhere I looked it either was inaccurate or didn't do what I wanted. So I went out and made a small app which counts the different colors used in an image as well as displays how many times each color was used.

Download: http://www.mediafire.com/download/ochli36xrsy4eq9/ImageColorCounter.exe

Usage: Drag image over application.

Source (VB.Net):

Saturday, December 5, 2015

Game Project

     For several months now I have been working on a project much different and much more interesting than any of my previous ones (in my opinion). It has been very challenging (probably because of the way I decided to do it) and presented many obstacles which I needed to over come. This project is essentially a game or more specifically a game engine (a very simple 2D game engine). I started this project about 2 to 3 years ago with the thought of making a Pokemon game just for friends and family to play. That project eventually saw a dark fate when I managed to mess up my computer and lost all my work regarding it. Jump forward a little bit and I have revived that project though it has been altered a bit. I changed it from GDI+ to DX. Got CPU usage from around 15 to 20 percent (8 threaded CPU) down to less than 1 (depending on configuration used). While I still do plan on making a Pokemon game for friends and family I have been working on a type of fighting game as that has presented me the most challenge. The Pokemon game will most likely be my second project relating to games and will most definitely recycle the work done on the fighting game. There are several other features and updates that I have presented since my initial version which was lost but I don't feel they are interesting nor important enough to mention.

     Typically because I do not know if this project will ever amount to anything (or ever completed) I refrained from posting this on here and instead posted updates on my Facebook but I have recently been kicked out and unable to use my Facebook account (because I refused to use my real name nor do I plan on giving it to them). To continue posting updates I will have to resort to posting on here.

     Updates will be posted in oldest last and latest first order. All updates will have a date attributed to them.

[System Tested]
CPU: Intel Core i7 2600K @3.411Ghz
RAM: 8GB DDR3 @ 1600Mhz
GPU: Nvidia GTX 680

[APR 22 2016]
Moving everything over to MonoGame. Will hopefully provide Windows and Linux versions.

[JAN 21 2016]
I have since made some addition/changes but haven't gotten around to posting until now. I have added a "ColorPalette Management System" and a "PixelData Management System" they are in place to eventually replace the current "Sprite Management System" but currently all three are present for testing and debugging. I have worked out how I want to go about storing game assets (graphics in particular and sounds). Sounds will be in AAC format as there are no royalties involved in the usage of AAC media (unlike MP3). Several other formats are supported but AAC is recommended for reasons stated. Graphics Assets will be stored in a custom format/scheme. The game will have "CPT" (Color Palette Table) files which represent the colors of a particular palette and then another format "PID" (Pixel Image Data) which contains the representation of each pixel in bytes. The images are restricted to an Indexed8 depth meaning each sprite can have up to 256 predefined colors (in the CPT file). The two formats are separate because some sprites may share the same palette in which case it makes sense to reuse a palette instead of making a redundant copy in memory. The idea came about when exploring the GIF animated image format. I added a SoftwareRenderOnly mode for whats it's worth. Finally I moved around some things to better organize the project and workflow.

[JAN 12 2016]
Fixed and optimized my XorUInteger and XorULong structures to use for the engine. They are attempts at cheat prevention (for the simpletons but I'm sure the pros will still get around it). It basically works as you would think the name implies. It XORs the value with a randomly generated token so that the exact value is never stored. It also comes with checks to make sure the token is valid and that the return value hasn't been tampered with.
Source XorUInteger: http://pastebin.com/UVY8feZK
Source XorULong: http://pastebin.com/NJdXe5Ay

[JAN 11 2016]
Added mouse tracking although it isn't complete. Will have to get mouse tracking to properly scale with the window (Right now it works properly when the window is it's native resolution but any smaller and the tracking goes whack).

[JAN 08 2016]
Added a bit to the audio manager. Its able to stop any instance of audio that has been played. During playback an Instance ID is returned and that ID is used to distinguish that audio instance from the rest. That same ID will be used to stop playback of that audio instance if that instance is still playing, if not nothing will happen. Instances start with ID 1, if an ID of 0 is obtained that means the audio instance failed to play (most likely due to missing audio from collection).

[JAN 06 2016]
Improved the fullscreen, now fullscreening from a maximized windowed to fullscreen works and unfullscreening goes back to maximized bordered if it was previously so. Maximizing from a normal boredered window also maximizes and unmaximizes back to a normal window. With the addition of the new GameTimer I found that resizing the window doesn't impact the game much and so I removed the bit where it blacks the screen and suspends the layout until resize has completed so now you can see the game being resized as you resize it. This also gives the plus effect that the game doesn't blacks out when you move the window around. I fixed a problem with the mouse cursor showing over the game when it was specified not to so not when you want to hide the mouse cursor it wont show up anymore. Deleted some unnecessary functions and cleaned up some variables.

[JAN 05 2016]
I implemented my new GameTimer which provides more accurate control over frame-rate which still provides the low CPU usage of the older GameTimer.
I added a third buffer to try and mitigate some stutter I see.
I also hope that this fixes the inconsistencies between FPS on Intel vs AMD machines but will need more testing.
Source for the new GameTimer can be found here: http://tizzyt-archive.blogspot.com/2015/10/ticktimer.html

OLD GameTimer ex:

NEW GameTimer ex:

[JAN 04 2016]
Game now knows when its in focus or not so to grab inputs or not. Changed a bit of the rendering logic so it doesn't have draw queues (was made irrelevant with the buffers but forgot to take it out).

[DEC 30 2015]
Implemented my sound system. I haven't done too much testing but I know that it works. Essentially it is just my previous sound engine code I made a while back. It can do multiple instances of sounds and so a bunch of sound effects going at once shouldn't be a problem. The loading method is similar to the loading method I use for loading graphic assets. What to work on next I wonder.

[DEC 26 2015]
In addition to scaling I have implemented full screen. Full screen is mapped to F11. I might change it to Alt-Enter sometime later.

[DEC 23 2015]
Messing around with different image formats again and I think I will settle for the old fashion GIF format (or more accurately some of its concepts). GIF has a maximum color palette of 256 colors and so each pixel only takes one byte to represent a color. With about 3000 character sprites loaded into memory I figure that will be about a little over 1GB of memory. Of course this is excluding other things like background and effects as well as sound and game logic but I think its much more manageable now memory-wise. I played a bit with vectors and while memory becomes no longer an issue with simple sprites the more complex ones (ones with many angles) seem to be about the same or in some cases worst (though sprites looked so crisp and sharp, its a shame I couldn't use them). I might still use vectors for some things (large but simple effects) but not sure yet, but surprisingly vectors are pretty resource hungry (because they have to be calculated each time where as with an image it only needs to be drawn I figure).

[DEC 22 2015]
After scaling was implemented I had to center the view port but doing so revealed that everything would render to the edges of the window. I went ahead and implemented a constraint on the view port effectively creating a letterbox effect that has the same aspect ratio as the render resolution.
Ex (16:9 ratio):

[DEC 21 2015]
Got to implement scaling so now changing the size of the window wont crop or letterbox anything, instead everything is scaled up/down relative to the window and internal rendering resolution.

[DEC 13 2015]
Finished/Fixed dead zone correction for EZPAD. Download and source updated below.
Changed a couple things in terms of graphics.
Found a weird behavior where a frame sometimes drew an image out of place and of unspecified size, fixed it by having 2 buffers instead of one (buffer isn't used here in the normal sense of back buffers).

[DEC 12 2015]
Decided to redo the XInput lib for ease of use, flexibility and usage more straight forward.
New one is called EZPAD, Download and source is provided below (VB.NET).
     Imports EZPAD
     Dim NewGamePad As New EZPAD(PLAYER.ONE)
Download: http://www.mediafire.com/download/5hfp8k9h4jb7fx7/EZPAD.dll
Source: http://pastebin.com/kPMtLLy6
Old XPadMonitor Source: http://pastebin.com/m9r0cmGa

Sunday, October 18, 2015

Millisecond Timer

   So a while back I discovered that windows can't do microsecond accurate timers (at least not in a straight forward way). Windows is not real time operating system so events are triggered differently for different computers. There are ways like the MicroLib I found on the internet a while back but it is very resource hungry using up almost 100 percent of one of my cores. This is because it is essentially polling a stopwatch and seeing if the number of ticks is equal to or greater than the specified Tick which is calculated per computer. I have tried to modify it to be less resource hungry but my attempts failed. I recently found some code which utilizes the windows multimedia api to achieve a more accurate millisecond but it was only accurate down to the millisecond and cant achieve for example 16.7 milliseconds. I then thought hey I can put the two together. This millisecond timer can achieve closer to the specified millisecond like 16.7ms which is the duration of a frame in a 60FPS game. Now this isn't perfect but I'd think this is as good as it gets (for me its exactly what I needed). If there are better methods/alternatives please comment or if you have any suggestions or improvements.

[UPDATE JAN 05 2016]
I got around to redoing my GameTimer. The previous one was very inaccurate. For example I would specify 240FPS but it would give me ~230FPS and when specifying some other rates it is also all over the place. This new one addresses those as well as keeping all the features of the old one.

Source (VB.NET):

Sunday, September 6, 2015

Transparent JPG

[Update 7] TransparentJPG.Dll quality default is now 80 and smoothing default is now 20. Progressive mode for the JpegEncoder is enabled potentially resulting in smaller file sizes. TransparentJPG has an added parameter for subsampling detail level. Options are 0 low (Default), 1 (medium), 2 (High). 2TJPG.exe has the added parameter as well.

[Revert 1] Changed back to using the LibJpeg.Dll. Smoothing is available again. Updated source below as well as the TransparentJPG.zip download and Latest Builds. The source for the version that is not reliant on LibJpeg.Dll will still be provided for reference.

[UPDATE 6] Removed the dependency for the LibJpeg.Dll which means that smoothing feature which helped save some space is now gone :( . I did so because I was given a 6Kx4K image to convert to TJPG and the converter (2TJPG.exe) kept crashing. I debugged it and found that LibJpeg was the problem. I am guessing that lib doesn't support images with such large resolutions? Either way I had to address the issue so I went and resorted to using Microsoft's built in encoder. It is slightly faster now due to not implementing the smoothing feature but file sizes will be slightly larger. The TransparentJPG.zip below has also been updated and contains (2TJPG.exe, TJPGviewer.exe, TransparentJPG.Dll). So essentially encoding will be different but decoding stays the same. The converter has also been updated in that it no longer supports the "Smoothing" parameter.

[UPDATE 5] Changed the color of the background squares of TJPGviewer.exe to a lighter shade(Grey) as well as made them 3x3 instead of 4x4 making them look less obtrusive.

[UPDATE 4] Optimized the code for saving TJPGs as well as removed all dependencies to LockBitmap.Dll(Removed from package). Also removed the CType to Byte() since it seemed redundant to the Decode method. Also provided SRC to TransparentJPG.DLL below.

[UPDATE 3] Changed the default values for conversion tool to quality=75 and smoothing=25. Also added a Decode method in TransparentJPG.Dll to get the pixel data, width and height of TJPG file. Also cleaned up the LoadTJPG function so that it doesn't rely on the LockBitmap.Dll though other things still need it, I will get to them soon.

[UPDATE 2] Fixed an issue with the converter (2TJPG.exe) where it would error and crash when given file paths that are valid and saying they aren't. Fixed version is provided in the "Latest Builds" link below.

[UPDATE 1] Added averaging when applying the mask to make the other bits of the alpha "useful" as well as provide a bit of compensation for rounding errors that jpeg compression might have. This has no impact on the encoding and only the decoding so file sizes are not affected though there is technically an impact on the resulting image visually it isn't noticeable and so negligible.
Moved all newer builds to a new location so people can grab this independent of the package I provided below:
Latest Builds: https://www.mediafire.com/folder/o2r7is9fsb279/Latest_Build
TransparentJPG: https://www.mediafire.com/folder/kjqpmfazac24c/TransparentJPG

     While working on my game I needed a way to import images and in my game people can share these images among each other via P2P. These images are almost always going to be grouped with tens if not hundreds, if not thousands of other images so I needed to pick an image file that is small in size. My next requirement was that the images needed to have transparency as a capability. Jpeg while small in size isn't capable of transparency. PNG has transparency but is much larger in size due to it being a lossless format. Another requirement was it needed to be compatible, I needed to work with an already existing format that most computers already know how to use so it wouldn't add time and complexity over compatibility. There exists much better solutions today but they are all either proprietary or there are no libs for them in use for .net which I need.

     I first thought hey I'll just take the pixel data from an image and limit it to 6 bits per channel then compress the whole thing which gave rise to a format I called TZI. While TZI proved to be a more acceptable format to my game than PNG I thought why don't I try a lossy attempt.

     I looked at Jpeg and I already knew the complexity behind its compression so I wasn't going to mess with the inner workings of Jpeg. Instead I thought of a hack about way to add transparency as another level on top of Jpeg. I did this by simply creating a mask via the images Alpha channel. I then removed all transparency from the image. The mask was then appended under the original image (with the alpha turned off). What you get then is an image with no transparency on top and a greyscale image of the Alpha channel on the bottom. I couldn't stop there, people randomly running into this image and viewing it as a typical Jpeg would be confused and the image shown isn't even in its intended form. And so I had to change its header so that people don't mix it with Jpeg files (even though this is essentially what this is). To reconstruct the original intended image I made an application which views the TransparentJPG files.

     The image is loaded in memory. The alpha mask is applied and then the image is essentially cropped to half its height. There is actually more detailed aspects going on behind the scenes and the workings is a bit different from how I explained it but I figure just a gist of how it works is good enough and easier to understand.

Code (VB.Net):

Code-not LibJpeg.Dll reliant (VB.Net):

Converter and Viewer Tools: http://www.mediafire.com/download/2p3tkx4yty2d0ai/TransparentJPG.zip

Samples: https://www.mediafire.com/folder/n0p76oq8p1t0v/Samples

Now because of the added height as well as the transparency bit the images will never be smaller than their original non-transparent JPG version (with the same quality etc).

    Here is an exact representation of an image with its header unchanged after the mask has been generated:

    Intended Image:

    Here is another example of how the images are encoded without the header change:

    Intended Image:

Friday, August 14, 2015


[UPDATE 3] Removed the unnecessary function ClearBits() and its calls to result in >3x performance increase on adding bits (benchmark times updated).

[UPDATE 2] Changed out arithmetic operators for bit-wise operators as well as omitting the use of Math.Floor for a result of ~20 percent speed increase in setting bits (benchmark times updated).

[UPDATE 1] Fixed a bug where the 8th bit added is always set to True(1).

I previously made a class called TBitArray with the purpose of storing individual bits. At the time I didn't know that .Net already had a BitArray class which I could use so I made mine. I then thought well if I have an array I might as well make a list version as well. At the time I never got around to it. Then time passed and I started work on my encoding schemes. I needed to store bits that would resize as needed but I was lazy and instead stored each bit as a byte (yeah waste of space I know). This time I am working on a potential image format for my game. For this format everything is encoded and decode by bits and so again I needed something that would resize as needed. This time though I actually got to working on it. I know that one can resize the BitArray that is built into .Net but I did some benchmarks and well its VERY slow. So with speed and dynamic size in mind I set out to create a BitList class to make my life easier for this and potentially future projects. And I am sharing it here for those who may want to use it. I will provide the benchmarks first to show the difference. If anyone has any suggestions please leave a comment :)

As you can see BitList is much faster at adding bits when size is unknown and where size needs to be changed dynamically.
If you know exactly the number of bits needed please use the built in BitArray instead as you can see it is much faster at setting bits.

This class was made for my purpose of adding bits and not the constant manipulation of bits in memory. So if you need to constantly add bits this might be for you. The bit manipulation implemented is only for light use as it is slower than bit manipulation with BitArray, though slow it is still reasonably fast. Just use it where appropriate is all I'm saying.

Note: This class only implements the functionality that I myself needed, it does not provide other functionality that a typical List(Of T) has. If you need them you may implement them yourself or I might add this when my needs apply. I guess this is much closer the a queue then a list but too lazy to rename it lol. I could have also used a BitArray to store the lookup table but anyone who wants to do that is free to.

Code (VB.Net):

Saturday, August 8, 2015

Agar.io with keyboard support

So my little brother's friend found this 'mod' for Agar.io that allows one to play the game via the keyboard but he didn't know how to use it. I took a look and it linked to some survey site which automatically if anyone knew anything about these things online and running into surveys etc... its all crap. So instead I decided to make an app that allows one to play Agar.io with keyboard.

Download: http://www.mediafire.com/download/a36m97k2qaarmag/Agar.io_Key.exe

Info: made in .NET via VB. Uses E, S, D, F for movement, and R to enable/disable keyboard movement support (and shows/hides the mouse cursor).

Saturday, August 1, 2015

Cleaning up a Yamaha PSR-310 keyboard

So I recently got a used keyboard because I wanted to learn piano eventually. The one I got was very dirty and there were scratch marks, the keys were stiff as well as stuck, and the lowest C key didn't even work. I thought hey lets clean this up and thus started my overnight project (started at ~12:30AM).

First I had to disassemble the keyboard of course:

The thing was nasty inside:

Is that semen?

There was a bit of rust

So I got to sanding

The membrane was nasty as all hell, cleaned it with a dirty shirt, I think it has to go in the trash now

SOOOO much better :)

Rubber pads are nice and clean as well

Now to get to the keys

As you can see its pretty nasty on the outside too

Black keys are cleaned though still wet

Put the membrane back into the keypad frame

Placed the rubber pads on aswell

Now to address the original issue, Time for some lube

Lubed highest key and first key pair and assembled

Onto the second




Finally placed the key assembly back into the keyboard enclosure

Consequently the lowest C key now works AWESOME lol. Completed ~5:30 AM.

I used soap, bleach, and alcohol as cleaning solutions.
Cotton swabs for fine cleaning and lubricating.
Regret using toilet paper to clean, as well as using my dirty shirt.