473,387 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to Parse JPEG Header????

Can anyone give me an idea or better yet, a code sample, demonstrating how
to parse a JPEG header and search the header for markers located in the
stream?

Basically, I need to analyze an uploaded JPEG file, search for the markers
C2, C6 and CA in the stream, and then set a variable of some sort to specify
whether or not these markers are present. (The reason I need these is to
determine whether the JPEG is in "Progressive" or "Baseline" format and
perform additional processing on it.) I have been told this should be easy,
but I don't quite know where to start on this. Any example in VB or C# would
be greatly appreciated!

Thanks in advance!

Ryan
Jul 21 '05 #1
10 19456
Ryan Cooper wrote:
Can anyone give me an idea or better yet, a code sample,
demonstrating how to parse a JPEG header and search the header for
markers located in the stream?

Basically, I need to analyze an uploaded JPEG file, search for the
markers C2, C6 and CA in the stream, and then set a variable of some
sort to specify whether or not these markers are present. (The reason
I need these is to determine whether the JPEG is in "Progressive" or
"Baseline" format and perform additional processing on it.) I have
been told this should be easy, but I don't quite know where to start
on this. Any example in VB or C# would be greatly appreciated!

Thanks in advance!


http://www.google.com/search?hl=en&l...file+format+VB
--- and ---
http://groups.google.com/groups?hl=e...VB&sa=N&tab=wg

HTH

-- Mark
Jul 21 '05 #2
Hi Ryan,

Here's a handy site at which you can find loads of file formats, including Jpeg.

http://www.wotsit.org/search.asp?s=jpeg

Regards,
Fergus
Jul 21 '05 #3
Hi Fergus;
Thanks for the link to those files.... Definitely more helpful that the
last guy's reply with nothing but a google query.... lol... as if I havent
already searched google... I've been working on this problem on and off for
months... and as far as I have gotten is to be told it can be done.

However, the info in the files you referred me to is for the most part
information I already have. I have figured out the placement of the JPEG
Markers for progressive encoding determination.... But what I really need is
some direction as to how to actually parse this header information in VB.NET
into an array or string of some kind, and then to search for the presence of
these markers. I get the basic idea of opening streamreaders, using the
system.io class, etc. but I get confused about how to put it all together.
Anyways, if you have any idea how to search the JPEG header for specific
markers, I appreciate any direction you can give me.

Thanks again.
Ryan
"Fergus Cooney" <fi****@post.com> wrote in message
news:O7*************@TK2MSFTNGP10.phx.gbl...
Hi Ryan,

Here's a handy site at which you can find loads of file formats, including Jpeg.
http://www.wotsit.org/search.asp?s=jpeg

Regards,
Fergus

Jul 21 '05 #4
"Ryan Cooper" <in**@ryancooper.com> wrote in message
news:km******************@typhoon.sonic.net...
Can anyone give me an idea or better yet, a code sample, demonstrating how
to parse a JPEG header and search the header for markers located in the
stream?


Maybe something here... they have C source code.

http://www.ijg.org/

-- Alan
Jul 21 '05 #5
Ryan Cooper wrote:
Hi Fergus;
Thanks for the link to those files.... Definitely more helpful
that the last guy's reply with nothing but a google query.... lol...
as if I havent already searched google... I've been working on this
problem on and off for months... and as far as I have gotten is to be
told it can be done.


;-) wotsit.org was the 4th entry on the google search, and VB source code
was all over the first page of the groups.google return.

-- Mark
Jul 21 '05 #6
Uh Mark, not to rain on your parade or sound ungrateful, but replying with a
google search just doesn't seem appropriate for a newsgroup like this. I
mean, anybody with a basic knowledge of the internet can search google, and
I guess I just find it a little frustrating when I get a reply like this,
because it doesn't really serve to answer my question but is more like a
"RTFM" comment. I appreciate the fact that you replied, but it seems to me
that your reply wasn't much more than an attempt to increase the number of
threads you had posted on, and not really a genuine attempt to answer my
question. Maybe some people don't know about search engines, but I doubt
that they would be asking about parsing file headers in .net...!

I understand that the link that Fergus posted was in your list, but at least
he seemed to make a genuine attempt to give me relevant info, even if I
already know all about the jpeg specification and the markers and so forth.
Maybe I'm wrong, but I'd think most people would rather get one decent lead
than 100 vague search results they had already seen.

I was looking for help from someone with actual .NET programming knowledge,
specifically with the ability to give me some direction on how to search a
header's byte stream for a particular marker. Again, I'm not trying to start
a flame war here, I just feel like taking my subject line and doing a google
search does not really provide a valuable informational reply, and it's just
a little insulting to an experienced programmer and web user to be given a
google search in reply to a very specific programming question. I don't
know, maybe I'm just taking it personally, but I wanted to say this because
you took the time to reply to my reply, and I want you to understand where
I'm coming from.

Thanks anyway,
Ryan


"Mark Jerde" <ma********@verizon.no.spam.net> wrote in message
news:ui**************@TK2MSFTNGP12.phx.gbl...
Ryan Cooper wrote:
Hi Fergus;
Thanks for the link to those files.... Definitely more helpful
that the last guy's reply with nothing but a google query.... lol...
as if I havent already searched google... I've been working on this
problem on and off for months... and as far as I have gotten is to be
told it can be done.


;-) wotsit.org was the 4th entry on the google search, and VB source code
was all over the first page of the groups.google return.

-- Mark

Jul 21 '05 #7
I am not familiar with header format. That said if you have issue with
searching through stream of bytes, which I expect you get from BinaryReader
or similar, you might want to consider using Regex if offsets are floating
and you use some specific search patterns.
As Regex support hexadecimal notation you only need to ensure that string
with header information will not translate original bytes.

You can either use standard byte to char loop (e.g. with StringBuilder) to
build string from header stream e.g.
foreach (byte b in data) {
sb.Append((char)b);
}

or Encoding for iso-8859-1 - thanks Jon Skeet! like
sb.Append(System.Text.Encoding.GetEncoding(28591). GetString(br.ReadBytes((in
t)fs.Length)));

sb - StringBuilder, br - BinaryReader for fs - FileStream.

HTH
Alex
"Ryan Cooper" <in**@ryancooper.com> wrote in message
news:uu******************@typhoon.sonic.net...
I was looking for help from someone with actual .NET programming knowledge, specifically with the ability to give me some direction on how to search a
header's byte stream for a particular marker. Again, I'm not trying to start a flame war here, I just feel like taking my subject line and doing a google search does not really provide a valuable informational reply, and it's just a little insulting to an experienced programmer and web user to be given a
google search in reply to a very specific programming question. I don't
know, maybe I'm just taking it personally, but I wanted to say this because you took the time to reply to my reply, and I want you to understand where
I'm coming from.

Thanks anyway,
Ryan

Jul 21 '05 #8
Ryan Cooper wrote:
Uh Mark, not to rain on your parade or sound ungrateful, but replying
with a google search just doesn't seem appropriate for a newsgroup
like this. I mean, anybody with a basic knowledge of the internet can
search google, and I guess I just find it a little frustrating when I
get a reply like this, because it doesn't really serve to answer my
question but is more like a "RTFM" comment. I appreciate the fact
that you replied, but it seems to me that your reply wasn't much more
than an attempt to increase the number of threads you had posted on,
and not really a genuine attempt to answer my question. Maybe some
people don't know about search engines, but I doubt that they would
be asking about parsing file headers in .net...!


Sorry I wasted your time... <g>

I've introduced a number of people to internet searching, especially
effective use of Google's groups. "Thanks! I didn't know that" is not an
uncommon reply.

If your original post had stated you'd googled and google grouped without
success, I obviously wouldn't have posted my "hay foot, straw foot" reply.

Best of luck figuring out your problem.

Now for something potentially helpful: ISTR needing this JPEG info some
time ago in a VB3 or VB5/6 project. I didn't have to bit fiddle, though, as
it was a property of the imaging component I was using. If you're still
stuck in (choose a timeframe) an inexpensive 3rd party component could be
the trick. I don't recall the specific vendor; it was an employer or two
ago, and I had several imaging packages.

-- Mark

Jul 21 '05 #9
Thanks Mark for the thoughtful reply. I understand your point and I guess I
can't generalize too much... there are those who post to newsgroups as a
first resort, I just tend to do so as a last resort after the googling has
run dry. In this case I have googled until I was red in the fingers and
still haven't found a sufficiently detailed explanation to really answer my
needs.

Regarding your suggestion, I HAVE actually contacted several vendors of
imaging related com objects (including SoftArtisans ImgWriter, etc.), and
they all are able to set the progressive property, but none have been able
to actually detect/read it. For some reason all the third party objects
make the progressive encoding property write-only. This is fine if I want to
re-save an image as baseline, but who wants to recompress an already
compressed jpeg if they don't have to (e.g. if it was baseline to begin
with...)? The re-compressed image (even if saved at 100 quality) ends up at
lower visual quality with a considerably larger file size.

I would think this problem would have a solution out there somewhere
considering that flash movies (.swf's) can not display progressive JPG's,
meaning that there is NO WAY to allow user-uploaded images to display in a
flash UI with any kind of proper validation on the upload to ensure the
image is baseline. Agh!

Check it out.,.. this PHP code is supposed to do the trick... but I
absolutely refuse to run php on my server and deal with yet another
programming environment, just for this one feature... it has to be possible
with .net... it just has to:

<php code>
$fp = @fopen( $filename, "rb" );
$imageData = fread( $fp, 100000 );
@fclose( $fp );

function checkImage($imageData) {
if ( strstr( $imageData, pack( "n", 0xFFC2 ) ) ) {
return false;
}
if ( strstr( $imageData, pack( "n", 0xFFC6 ) ) ) {
return false;
}
if ( strstr( $imageData, pack( "n", 0xFFCA ) ) ) {
return false;
}
return true;
}
</php code>


"Mark Jerde" <ma********@verizon.no.spam.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Ryan Cooper wrote:
Uh Mark, not to rain on your parade or sound ungrateful, but replying
with a google search just doesn't seem appropriate for a newsgroup
like this. I mean, anybody with a basic knowledge of the internet can
search google, and I guess I just find it a little frustrating when I
get a reply like this, because it doesn't really serve to answer my
question but is more like a "RTFM" comment. I appreciate the fact
that you replied, but it seems to me that your reply wasn't much more
than an attempt to increase the number of threads you had posted on,
and not really a genuine attempt to answer my question. Maybe some
people don't know about search engines, but I doubt that they would
be asking about parsing file headers in .net...!
Sorry I wasted your time... <g>

I've introduced a number of people to internet searching, especially
effective use of Google's groups. "Thanks! I didn't know that" is not an
uncommon reply.

If your original post had stated you'd googled and google grouped without
success, I obviously wouldn't have posted my "hay foot, straw foot" reply.

Best of luck figuring out your problem.

Now for something potentially helpful: ISTR needing this JPEG info some
time ago in a VB3 or VB5/6 project. I didn't have to bit fiddle, though,

as it was a property of the imaging component I was using. If you're still
stuck in (choose a timeframe) an inexpensive 3rd party component could be
the trick. I don't recall the specific vendor; it was an employer or two
ago, and I had several imaging packages.

-- Mark

Jul 21 '05 #10
Ryan Cooper wrote:
Can anyone give me an idea or better yet, a code sample,
demonstrating how to parse a JPEG header and search the header for
markers located in the stream?

Basically, I need to analyze an uploaded JPEG file, search for the
markers C2, C6 and CA in the stream, and then set a variable of some
sort to specify whether or not these markers are present. (The reason
I need these is to determine whether the JPEG is in "Progressive" or
"Baseline" format and perform additional processing on it.) I have
been told this should be easy, but I don't quite know where to start
on this. Any example in VB or C# would be greatly appreciated!

Thanks in advance!

Ryan


Have you made any progress?

-- Mark
Jul 21 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: ZAPPLE | last post by:
Hi friends, Actually I want to know the jpeg header( data structure). So that I can access the information in the header file. Even if you just post the website where the information may be it...
4
by: THY | last post by:
Hi, After we let the user upload file to the server, how do we actually detect if that is a valid jpeg file ? thanks, Tee
10
by: Ryan Cooper | last post by:
Can anyone give me an idea or better yet, a code sample, demonstrating how to parse a JPEG header and search the header for markers located in the stream? Basically, I need to analyze an...
2
by: On the Sparrow | last post by:
I have a 3rd party API that store compressed JPEG data in a char buffer.ll How do I convert it to either an System::Drawing or somekind of format that I can display in a Windows::Form?
0
by: nhacnhac | last post by:
Hi Guys does anyone knows if the a JPEG file saved as JFIF version 1.02 is always considered progressive? I need to create a program in C# to open JPEG files and upload just the non-progressive...
4
by: Frank Kociemba | last post by:
Hi NG, how can i compare, if a file ends with jpg,jpeg,gif,tif is really such a file and not an unnamed one. Is ther a solution or an example who to do it in c#? Frank
6
by: simonhuntley | last post by:
I'm using a PHP script to raw output jpeg files in thumbnail generation. This works fine as completely server-side - I call it through an <img> tag, like <img...
0
by: jodleren | last post by:
Hi I want to read an image an return it to the user - the point is, that it can be any graphic image, so I need to set it properly. AFAIK there are imaga/jpeg, image/png - then? image/gif and...
5
by: dschu012 | last post by:
I am having trouble figuring out how to parse a http header into a map<string,string> POST /blah HTTP/1.1 Host: example.com Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.