Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Computing > Digital Photography > question about using jpegtran for lossless compression of jpegs

Reply
Thread Tools

question about using jpegtran for lossless compression of jpegs

 
 
ewaguespack@gmail.com
Guest
Posts: n/a
 
      10-10-2006
first of all, sorry for the cross-posting, but I am not sure where to
go for help with this...

I have been using a freeware windows application that strips all non
image info from a jpeg, here are the details:

http://davidcrowell.com/jStrip/Default.aspx
Features

jStrip removes the following from JPEG files:

* Comments (optionally)
* EXIF Data (optionally)
* JFIF Header (optionally)
* Photoshop Image Resource Block (optionally)
* ICC color profile
* Adobe APP14 tag (optionally)
* XMP data (optionally)
* Extra bytes at end of file
* Extra bytes or header at beginning of file
* Extra bytes between JPEG blocks
* Application-specific APPx blocks
* Photoshop thumbnails
* Any other unknown blocks in the JPEG files

in attempting to come up with a solution that does all of the above in
linux, I have played around with a couple of perl solutions, jhead,
exiftool, and jpegtran.

the best thing I have come up with so far is the following:
#jpegtran -optimize -outfile $image $image

or recursively:
# find -type f -name "*.jpg" -exec jpegtran -optimize -copy none
-outfile {} {} \;

other options I played with were the following:
# exiftool -all= $image
# jhead -purejpg $image

so, anyway to finally get to my point, the jpegtran (Linux) solution
does everything that jstrip (windows) does, (and more: optimize,
progressive) except remove the jfif header

so the question is, how do I remove the jfif header in a scripted,
recursive fashion in Linux.

If I am successful at finding a solution with this, it will finally
allow me to move completely to Linux.

finally, if you know where a forum / mailing list is that would be more
appropriate, please let me know.

Thank you in advance.

 
Reply With Quote
 
 
 
 
bugbear
Guest
Posts: n/a
 
      10-10-2006
wrote:
>
> so, anyway to finally get to my point, the jpegtran (Linux) solution
> does everything that jstrip (windows) does, (and more: optimize,
> progressive) except remove the jfif header


jpegtran -copy none a.jpg b.jpg

on my machine strips EXIF (and everything else
perfectly.

My jpeg version is libjpeg-6b-34

Are you sure of your results?

I'm checking for EXIF using
Image-ExifTool-5.62

BugBear
 
Reply With Quote
 
 
 
 
ewaguespack@gmail.com
Guest
Posts: n/a
 
      10-10-2006

bugbear wrote:
> wrote:
> >
> > so, anyway to finally get to my point, the jpegtran (Linux) solution
> > does everything that jstrip (windows) does, (and more: optimize,
> > progressive) except remove the jfif header

>
> jpegtran -copy none a.jpg b.jpg
>
> on my machine strips EXIF (and everything else
> perfectly.
>
> My jpeg version is libjpeg-6b-34
>
> Are you sure of your results?
>
> I'm checking for EXIF using
> Image-ExifTool-5.62
>
> BugBear


well I am not an expert at jpeg file structure, but if you download
that jstrip program and enable the optional "jfif header removal" your
get a 18 byte (i believe) reduction in size beyond what jpegtran
provided.

 
Reply With Quote
 
Ben Rudiak-Gould
Guest
Posts: n/a
 
      10-12-2006
wrote:
> so the question is, how do I remove the jfif header in a scripted,
> recursive fashion in Linux.


I'm curious why you want to do this, as the header takes almost no space and
without it a lot of software probably won't recognize the image. I don't
know of any existing utility that'll strip the JFIF header, but this should
do the trick:


/* Strip JFIF headers from the JPEG image on stdin, and write
the result to stdout. Won't work unmodified on Windows
because of the text/binary problem. Not thoroughly tested. */

#include <stdio.h>
#include <stdlib.h>

void fail(const char* msg)
{
fputs(msg, stderr);
exit(1);
}

void copy_rest(FILE* f, FILE* g)
{
char buf[4096];
int len;
while ((len = fread(buf, 1, sizeof buf, f)) > 0) {
if (fwrite(buf, 1, len, g) != len)
fail("write error");
}
if (len < 0)
fail("read error");
}

void strip_app0(FILE* f, FILE* g)
{
int a,b;
a = getc(f); b = getc(f);
if (a != 0xFF || b != 0xD
fail("not a JPEG file");
putc(a,g); putc(b,g);
while (a = getc(f), b = getc(f), a == 0xFF && b == 0xE0) {
a = getc(f); b = getc(f);
if (a == EOF || b == EOF)
fail("stop confusing me with weird test cases");
fseek(f, a * 256 + b - 2, SEEK_CUR);
}
if (a != EOF) putc(a,g);
if (b != EOF) putc(b,g);
copy_rest(f,g);
}

int main()
{
strip_app0(stdin,stdout);
return 0;
}


-- Ben
 
Reply With Quote
 
bugbear
Guest
Posts: n/a
 
      10-24-2006
wrote:
>
> well I am not an expert at jpeg file structure, but if you download
> that jstrip program and enable the optional "jfif header removal" your
> get a 18 byte (i believe) reduction in size beyond what jpegtran
> provided.
>


Apologies - I was reading "EXIF" and/or IPTC
for jfif.

(btw, jfif isn't technically a header, but comments
in the JPEG stream, but I'm guessing you already knew that)

BugBear
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
'extra' lossless compression for camera raw images Sachin Garg Digital Photography 12 07-08-2008 05:57 PM
'extra' lossless compression for camera raw images Sachin Garg Digital Photography 52 03-25-2008 10:40 PM
lossless compression in hardware: what to do in case of uncompressibility? Denkedran Joe VHDL 15 12-03-2007 12:40 PM
constant bitrate approach with lossless data compression on an FPGA Kurt Kaiser VHDL 5 11-10-2006 05:50 PM
batch lossless auto-rotate jpegs JC Dill Digital Photography 3 03-22-2006 05:31 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57