HI if you want "make" formtas like JPG, BMP from scracth without using Libraries, in this book recommended by Hardyx you can find how do it.
I think it's complete and obviously it's free.
It's C++ but not too much complex to understand if you read a bit about C++ language.
http://www.fileformat.info/mirror/egff/ch01_01.htm