jpg file transfer using a socket_stream in C - c

I was wondering if sending a file with a jpg extension through a socket_stream, this automatically makes the transformation of bytes to jpg ? or need to implement some algorithm to transform the lot of bytes to image... Please could somebody explain me the way to do?

JPEG images are nothing but a bunch of bytes organized according to the JPEG format. A network socket isn't going to organize random bytes into the JPEG format. You can send the bytes that make up a JPEG formatted image across a socket as a binary blob, receive it on the other end, and write it to a file with a .jpg extension. An application can interpret this file as a JPEG image based on the extension and try to display it. But you are still responsible for providing a set of bytes that are organized as a JPEG image.

Related

Issues while recreating a TIFF file with 1D encoded data

This is regarding Fax Image compression. Initially I had an Uncompressed TIFF file , I wrote a code to extract its tags and the Image data present in it. Once I extracted the image data I performed 1D modefied Huffman coding/ Run length coding on it to get the encoded compressed data which I have stored in a textfile.
Now I am trying to recreate a TIFF file by modifying the tags appropriately to store the encoded compressed data. I have writen a code to recreate the tiff file and when I open the tiff file with an appliction to view all the tags, I find that all the tags I have put are correctly being read. However, when I use an online tiff viewer I do not get the correct image. I am confident that my encoded data is correct according to the Huffman Runlength tables. Anyone has any idea why I am not able to view the same Image with my compressed tiff file?
Note : I have not used any C libraries such as libtiff, The tiff file is just created by opening a tiff file and writing specific values at different offsets based on the tiff file stucture.
Thank you.
The Original Uncompressed file
The 1D encoded compressed file

File extension detection mechanism

How Application will detect file extension?
I knew that every file has header that contains all the information related to that file.
My question is how application will use that header to detect that file?
Every file in file system associated some metadata with it for example, if i changed audio file's extension from .mp3 to .txt and then I opened that file with VLC but still VLC is able to play that file.
I found out that every file has header section which contains all the information related to that file.
I want to know how can I access that header?
Just to give you some more details:
A file extension is basically a way to indicate the format of the data (for example, TIFF image files have a format specification).
This way an application can check if the file it handles is of the right format.
Some applications don't check (or accept wrong) file formats and just tries to use them as the format it needs. So for your .mp3 file, the data in this file is not changed when you simply change the extension to .txt.
When VLC reads the .txt byte by byte and interprets it as a .mp3 it can just extract the correct music data from that file.
Now some files include a header for extra validation of what kind of format the data inside the file is. For example a unicode text file (should) include a BOM to indicate how the data in the file needs to be handled. This way an application can check whether the header tag matches the expected header and so it knows for sure that your '.txt` file actually contains data in the 'mp3' format.
Now there are quite some applications to read those header tags, but they are often specific for each format. This TIFF Tag Viewer for example (I used it in the past to check the header tags from my TIFF files).
So or you could just open your file with some kind of hex viewer and then look at the format specifications what every bytes means, or you search Google for a header viewer for the format you want to see them.

Load wave into array + Subtract channels + Save as wave/mp3

I have a raw stereo audio file.
It is part of a noise cancellation system on the raspberry pi, Microphone 1 records the main voice to the left channel, Microphone 2 the surrounding noises to the right channel. Goal is to subtract the right channel from the left channel. I am going to write what I tried but I don't want you to stick to it and meddle with it if another way is much easier.
Recording takes place using a modified http://freedesktop.org/software/pulseaudio/doxygen/parec-simple_8c-example.html version. I output it to the raw audio file, which is a valid raw file. Advantage of stereo is that they are in sync. See my other question on How to find the right RAW format.
To summarize: How do I
Load a wave file into an array? ( I am asking this because in my other question the wave format never seems right)
Subtract the right channel from the left channel? (I presume sample_left minus sample_right)
Save it as raw or even better mp3 mono. ( I could pipe to lame )
If you are3 giving raw audio file as input or reading raw audio samples from audio device file, You can do following
1.Open raw audio file in binary format and read raw data in to a buffer,if you are using a file to give raw audio data. (or) Read Raw audio samples from audio device fire in to a buffer.
2.We know that Right audio channel is always followed by left audio channel in stereo audio format. So you can simply separate left and right audio channels. For example, if your device is giving 16-bit pcm pulses, that means, first 16-bits are left channel and next 16-bits are right channel.
3.You can simply open a normal binary file and you can make it as a wav file by defining wav header at the stating of the file. Define a wav header and write audio data in to wav file.
For wav file references see here

RGB888 (24 bit) to PNG/JPEG image algorithm

I need to convert 24 bit RGB(888) image data to PNG or JPEG image (whichever possible). Need simpler approach to do this same like converting RGB888 to BMP without any compression. Would be great if it is something like adding PNG/JPEG headers to the RGB data with/without little modification. Ready to provide more details on request..
Thanks in advance..
Language/Platform : C/Linux
Use miniz - a.k.a single C source file Deflate/Inflate compression library with zlib-compatible API, ZIP archive reading/writing, PNG writing.
If you just need an image format then the easiest is probably ppm (or pgm for greyscale)
You just need to add a small ascii header to the uncompressed binary data and most image apps will read it.
P6 <-- magic value for binary data
# a comment if you want
640 480 <-- width x height
255 <-- max pixel value
.... binary data here .......

Save video encoded by libavcodec to an AVI file format

I am able to encode video frames using libavcodec, by calling avcodec_encode_video function. How do I save these encoded frames into an AVI file?
Check this out:
http://forum.doom9.org/archive/index.php/t-112286.html
You must open file for binary write, write header in it, and simultaniosly put binary frames in it, I think.

Resources