Author Topic: From a programming perspective, what makes a jpg a jpg?  (Read 1718 times)

0 Members and 1 Guest are viewing this topic.

Offline PsychoRebellious

  • Peasant
  • *
  • Posts: 130
  • Cookies: -6
    • View Profile
    • My Rantings
From a programming perspective, what makes a jpg a jpg?
« on: March 07, 2015, 09:47:25 pm »
I am thinking of going further with c++, and studying file handling in depth. With c++ streams, you can open files of any type (I assume, though I have only worked with txt files yet). Now I am concerned with manipulating those files. Let's say there's a file x of format jpg, then what makes it different from a file of format gif? I don't know how to make.
Please, bear with my ignorance here, I don't even know which domain of computer science deals with this subject. I just want to study file manipulating/handling/accessing in depth. So far, I've read that any file type that is not a txt file is a binary file(feel free to correct me), now what makes one binary file jpg and other gif?
Say I want a c++ program to go through a jpg file and replace all the red pixels in it with blue one, how will I do that? I am not asking anybody to spoonfeed me or write tutorials for me, but guide me in the right direction, and let me know the limitations of the subject.
I've worked with allegro library and there were functions that dealt with images like
getPixel();
putPixel();

What I would want to do is access and manipulate PDFS and XML documents without using a third party library only using the c++ streams. This has got to be possible. Feel free to correct me wherever I stand wrong.

Offline KryDos

  • Serf
  • *
  • Posts: 42
  • Cookies: 8
  • Software Engineer, Emacs uesr
    • View Profile
Re: From a programming perspective, what makes a jpg a jpg?
« Reply #1 on: March 07, 2015, 10:09:23 pm »
Quote
what makes it different from a file of format gif?
I can answer this part, I hope somebody can answer other parts of you question...

So, jpg is a container. And there are lot of other containers (png, gif, etc). Each container has standard and in this standard you can find how to fetch something from the image, what is header, how you can change color of the pixel or of the whole image, etc...

It would be great if you can read this article in wikipedia - http://en.wikipedia.org/wiki/JPEG. I found this article very useful. There also links to the RFC (standard).

So, to process image you need to know what kind of container it has. And then process it based on this information.

btw, in this article you also will see something which is called "magic number" of JPG. It means that first three bytes of the JPG image are special (FF D8 FF - in jpg case). It also means that even you will change extension of the jpg to, say, png it will not "convert" your jpg image to png. The magic numbers came from Unix world where extension do not describe the file type but magic number does.
« Last Edit: March 07, 2015, 10:17:57 pm by KryDos »

Offline flowjob

  • Knight
  • **
  • Posts: 327
  • Cookies: 46
  • Pastafarian
    • View Profile
Re: From a programming perspective, what makes a jpg a jpg?
« Reply #2 on: March 07, 2015, 10:15:34 pm »
Well, when it comes to things this complex (especially images, but also xml, etc) you should consider using someone elses 3rd party library. Reinventing the wheel doesn't really make sense here, as you'd need to put A LOT of time into these libraries, but they still wouldn't be as feature-full as theirs.
But if you don't want to have a lot of different dependencies I'd suggest you look for a more universal framework. If it comes to C++ the Qt framework supports a lot of different tasks, including user interfaces, networking, image manipulation, parsing xml and json and A LOT of other things. Just check out their docs:
http://doc.qt.io/qt-5/index.html
Quote
<phil> I'm gonna DDOS the washing machine with clothes packets.
<deviant_sheep> dont use too much soap or youll cause a bubble overflow

Offline PsychoRebellious

  • Peasant
  • *
  • Posts: 130
  • Cookies: -6
    • View Profile
    • My Rantings
Re: From a programming perspective, what makes a jpg a jpg?
« Reply #3 on: March 07, 2015, 10:31:51 pm »
@kryDos: I was talking about something more precise. As from the perspecitve of a programmer. Perhaps something precise in the way data is stored in a jpg file and how it can be manipulated with a programming language.
@flowjob: I've tried QT long ago with the QT designer kit. It was very stupid, with dragging and dropping all those form fields and working with the UI files, almost as if it wasn't programming at all, I didn't bother studying Qt in depth for other reasons that it was rumored to be dead. Who cares about GUI when it comes to windows anyways? I am interested in something that does a better job, that solves something complex simply, looking pretty is not a recommendation. QT is for GUI based windows/Linux/addyourfavOShere programs(correct me if I'm wrong). I want to have the same power that QT provides with console based programs and not their predefine widgets, because let's get this straight there are already corporations and big companies targetting these platforms with their team of hundreds of developers.

Offline KryDos

  • Serf
  • *
  • Posts: 42
  • Cookies: 8
  • Software Engineer, Emacs uesr
    • View Profile
Re: From a programming perspective, what makes a jpg a jpg?
« Reply #4 on: March 07, 2015, 10:38:39 pm »
@kryDos: I was talking about something more precise.

I can't copy/paste RFC. From programmer stand point you need to know how jpg container is organized.

QT is for GUI based windows/Linux/addyourfavOShere programs(correct me if I'm wrong).

You're wrong here. QT is a framework which has GUI classes and helpers but you can not use them. QT is brilliant framework and it has many many useful classes which you can use in CLI development.
« Last Edit: March 07, 2015, 10:45:21 pm by KryDos »

Offline flowjob

  • Knight
  • **
  • Posts: 327
  • Cookies: 46
  • Pastafarian
    • View Profile
Re: From a programming perspective, what makes a jpg a jpg?
« Reply #5 on: March 07, 2015, 10:49:19 pm »
@flowjob: I've tried QT long ago with the QT designer kit. It was very stupid, with dragging and dropping all those form fields and working with the UI files, almost as if it wasn't programming at all, I didn't bother studying Qt in depth for other reasons that it was rumored to be dead. Who cares about GUI when it comes to windows anyways? I am interested in something that does a better job, that solves something complex simply, looking pretty is not a recommendation. QT is for GUI based windows/Linux/addyourfavOShere programs(correct me if I'm wrong). I want to have the same power that QT provides with console based programs and not their predefine widgets, because let's get this straight there are already corporations and big companies targetting these platforms with their team of hundreds of developers.

As KryDos said, Qt isn't only about user interfaces. It can do lots of different things, it's crossplatform (wich is always a big plus), and it's fairly easy to get used to it (compared to boost). And it's definitly not dead. Qt 5 got realeased, Qt Quick provides a new way to develop user interfaces (with a json-like syntax), and new features (especially for smartphones) get added pretty fast. You can program console-only with Qt too, that's no problem at all. The GUI stuff is (now) just one part of the whole library. Just check out Qt 5, read through the docs, and see if it fits you. Give it another chance  ;)
Quote
<phil> I'm gonna DDOS the washing machine with clothes packets.
<deviant_sheep> dont use too much soap or youll cause a bubble overflow

Offline PsychoRebellious

  • Peasant
  • *
  • Posts: 130
  • Cookies: -6
    • View Profile
    • My Rantings
Re: From a programming perspective, what makes a jpg a jpg?
« Reply #6 on: March 07, 2015, 10:50:54 pm »
I can't copy/paste RFC. From programmer stand point you need to know how jpg container is organized.

You're wrong here. QT is a framework which has GUI classes and helpers but you can not use them. QT is brilliant framework and it has many many useful classes which you can use in CLI development.

Would you suggest QT for doing every day and every type of jobs with c++ ? Those include but are not limited to file handling, database management, networking, graphics, working with audios, and xmls and pdfs?

Offline PsychoRebellious

  • Peasant
  • *
  • Posts: 130
  • Cookies: -6
    • View Profile
    • My Rantings
Re: From a programming perspective, what makes a jpg a jpg?
« Reply #7 on: March 07, 2015, 10:52:54 pm »
As KryDos said, Qt isn't only about user interfaces. It can do lots of different things, it's crossplatform (wich is always a big plus), and it's fairly easy to get used to it (compared to boost). And it's definitly not dead. Qt 5 got realeased, Qt Quick provides a new way to develop user interfaces (with a json-like syntax), and new features (especially for smartphones) get added pretty fast. You can program console-only with Qt too, that's no problem at all. The GUI stuff is (now) just one part of the whole library. Just check out Qt 5, read through the docs, and see if it fits you. Give it another chance  ;)
On it, Thank you  :D

Offline KryDos

  • Serf
  • *
  • Posts: 42
  • Cookies: 8
  • Software Engineer, Emacs uesr
    • View Profile
Re: From a programming perspective, what makes a jpg a jpg?
« Reply #8 on: March 08, 2015, 05:55:33 am »
Would you suggest QT for doing every day and every type of jobs with c++ ? Those include but are not limited to file handling, database management, networking, graphics, working with audios, and xmls and pdfs?

You can but you shouldn't. You have to understand that language (and framework) it's just a tool. С++, in our case, is a Swiss knife but anyway you shouldn't use it for every kind of tasks. If you're using one language or going to use one language for all kind of tasks, then you're stupid, sorry.

Sometimes it's better to write something using Python (Perl, Ruby, PHP) or if you need some simple multicore and concurrency then you can choose some functional language like Erlang (for networking), Clojure (or Common Lisp) or Haskell. 

DON'T USE ONE LANGUAGE FOR ALL. IF YOU'RE DOING THIS, YOU HAVE TO DIE, sorry.
« Last Edit: March 08, 2015, 05:58:21 am by KryDos »

Offline PsychoRebellious

  • Peasant
  • *
  • Posts: 130
  • Cookies: -6
    • View Profile
    • My Rantings
Re: From a programming perspective, what makes a jpg a jpg?
« Reply #9 on: March 08, 2015, 06:33:23 am »
But I don't want to die  :-\ The legend said c++ was the ultimate language. I am learning that and PHP already (Fairly aware of the syntax of the two languages, just learning to use them powerfully i.e: getting used to frameworks/libraries and algorithms). Which language should I learn next then? JaVA is not an option, I've done some android development with it before and for some reasons, perhaps a matter of taste, I can't stand that language. There are python, perl and ruby, i know a little python(the syntax to be precise), but I don't go ahead with it because it might make me create bad programming habits because of the lose syntax of the language, and apart from pygame I don't really find a reason to learn it