CJPEG(1) CJPEG(1) NAME cjpeg−compressanimagefiletoaJPEGfile SYNOPSIS cjpeg[options][filename] DESCRIPTION cjpegcompressesthenamedimagefile,orthestandardinputifnofileisnamed,andproducesa JPEG/JFIFfileonthestandardoutput.Thecurrentlysupportedinputfileformatsare:PPM (PBMPLUScolorformat),PGM(PBMPLUSgray-scaleformat),BMP,Targa,andRLE(Utah RasterToolkitformat).(RLEissupportedonlyiftheURTlibraryisavailable.) OPTIONS Allswitchnamesmaybeabbreviated;forexample,−grayscalemaybewritten−grayor−gr. Mostofthe"basic"switchescanbeabbreviatedtoaslittleasoneletter.Upperandlowercase areequivalent(thus−BMPisthesameas−bmp).Britishspellingsarealsoaccepted(e.g., −greyscale),thoughforbrevitythesearenotmentionedbelow. Thebasicswitchesare: −qualityN Scalequantizationtablestoadjustimagequality.Qualityis0(worst)to100(best); defaultis75.(Seebelowformoreinfo.) −grayscale CreatemonochromeJPEGfilefromcolorinput.BesuretousethisswitchwhencompressingagrayscaleBMPfile,becausecjpegisn’tbrightenoughtonoticewhethera BMPfileusesonlyshadesofgray.Bysaying−grayscale,you’llgetasmallerJPEGfile thattakeslesstimetoprocess. −optimize Performoptimizationofentropyencodingparameters.Withoutthis,defaultencoding parametersareused.−optimizeusuallymakestheJPEGfilealittlesmaller,butcjpeg runssomewhatslowerandneedsmuchmorememory.Imagequalityandspeedofdecompressionareunaffectedby−optimize. −progressive CreateprogressiveJPEGfile(seebelow). −targa InputfileisTargaformat.Targafilesthatcontainan"identification"fieldwillnotbe automaticallyrecognizedbycjpeg;forsuchfilesyoumustspecify−targatomakecjpeg treattheinputasTargaformat.FormostTargafiles,youwon’tneedthisswitch. The−qualityswitchletsyoutradeoffcompressedfilesizeagainstqualityofthereconstructed image:thehigherthequalitysetting,thelargertheJPEGfile,andtheclosertheoutputimage willbetotheoriginalinput.Normallyyouwanttousethelowestqualitysetting(smallestfile) thatdecompressesintosomethingvisuallyindistinguishablefromtheoriginalimage.Forthispurposethequalitysettingshouldbebetween50and95;thedefaultof75isoftenaboutright.If youseedefectsat−quality75,thengoup5or10countsatatimeuntilyouarehappywiththe outputimage.(Theoptimalsettingwillvaryfromoneimagetoanother.) −quality100willgenerateaquantizationtableofall1’s,minimizinglossinthequantizationstep (butthereisstillinformationlossinsubsampling,aswellasroundofferror).Thissettingis mainlyofinterestforexperimentalpurposes.Qualityvaluesaboveabout95arenotrecommendedfornormaluse;thecompressedfilesizegoesupdramaticallyforhardlyanygaininoutputimagequality. Intheotherdirection,qualityvaluesbelow50willproduceverysmallfilesoflowimagequality. Settingsaround5to10mightbeusefulinpreparinganindexofalargeimagelibrary,forexample.Try−quality2(orso)forsomeamusingCubisteffects.(Note:qualityvaluesbelowabout 20March1998 1 CJPEG(1) CJPEG(1) 25generate2-bytequantizationtables,whichareconsideredoptionalintheJPEGstandard. cjpegemitsawarningmessagewhenyougivesuchaqualityvalue,becausesomeotherJPEG programsmaybeunabletodecodetheresultingfile.Use−baselineifyouneedtoensurecompatibilityatlowqualityvalues.) The−progressiveswitchcreatesa"progressiveJPEG"file.InthistypeofJPEGfile,thedata isstoredinmultiplescansofincreasingquality.Ifthefileisbeingtransmittedoveraslowcommunicationslink,thedecodercanusethefirstscantodisplayalow-qualityimageveryquickly, andcanthenimprovethedisplaywitheachsubsequentscan.ThefinalimageisexactlyequivalenttoastandardJPEGfileofthesamequalitysetting,andthetotalfilesizeisaboutthesame ---oftenalittlesmaller.Caution:progressiveJPEGisnotyetwidelyimplemented,somany decoderswillbeunabletoviewaprogressiveJPEGfileatall. Switchesforadvancedusers: −dctint UseintegerDCTmethod(default). −dctfast UsefastintegerDCT(lessaccurate). −dctfloat Usefloating-pointDCTmethod.Thefloatmethodisveryslightlymoreaccuratethan theintmethod,butismuchslowerunlessyourmachinehasveryfastfloating-pointhard-ware.Alsonotethatresultsofthefloating-pointmethodmayvaryslightlyacross machines,whiletheintegermethodsshouldgivethesameresultseverywhere.Thefast integermethodismuchlessaccuratethantheothertwo. −restartN EmitaJPEGrestartmarkereveryNMCUrows,oreveryNMCUblocksif"B"is attachedtothenumber.−restart0(thedefault)meansnorestartmarkers. −smoothN Smooththeinputimagetoeliminateditheringnoise.N,rangingfrom1to100,indicates thestrengthofsmoothing.0(thedefault)meansnosmoothing. −maxmemoryN Setlimitforamountofmemorytouseinprocessinglargeimages.Valueisinthousands ofbytes,ormillionsofbytesif"M"isattachedtothenumber.Forexample,−max4m selects4000000bytes.Ifmorespaceisneeded,temporaryfileswillbeused. −outfilename Sendoutputimagetothenamedfile,nottostandardoutput. −verbose Enabledebugprintout.More−v’sgivemoreoutput.Also,versioninformationisprinted atstartup. −debug Sameas−verbose. The−restartoptioninsertsextramarkersthatallowaJPEGdecodertoresynchronizeaftera transmissionerror.Withoutrestartmarkers,anydamagetoacompressedfilewillusuallyruin theimagefromthepointoftheerrortotheendoftheimage;withrestartmarkers,thedamageis usuallyconfinedtotheportionoftheimageuptothenextrestartmarker.Ofcourse,therestart markersoccupyextraspace.Werecommend−restart1forimagesthatwillbetransmitted acrossunreliablenetworkssuchasUsenet. The−smoothoptionfilterstheinputtoeliminatefine-scalenoise.Thisisoftenusefulwhencon-vertingditheredimagestoJPEG:amoderatesmoothingfactorof10to50getsridofdithering patternsintheinputfile,resultinginasmallerJPEGfileandabetter-lookingimage.Toolargea smoothingfactorwillvisiblyblurtheimage,however. 20March1998 2 CJPEG(1) CJPEG(1) Switchesforwizards: −baseline Forcebaseline-compatiblequantizationtablestobegenerated.Thisclampsquantization valuesto8bitsevenatlowqualitysettings.(Thisswitchispoorlynamed,sinceitdoes notensurethattheoutputisactuallybaselineJPEG.Forexample,youcanuse−baselineand−progressivetogether.) −qtablesfile Usethequantizationtablesgiveninthespecifiedtextfile. −qslotsN[,...] Selectwhichquantizationtabletouseforeachcolorcomponent. −sampleHxV[,...] SetJPEGsamplingfactorsforeachcolorcomponent. −scansfile Usethescanscriptgiveninthespecifiedtextfile. The"wizard"switchesareintendedforexperimentationwithJPEG.Ifyoudon’tknowwhatyou aredoing,don’tusethem.Theseswitchesaredocumentedfurtherinthefilewizard.doc. EXAMPLES ThisexamplecompressesthePPMfilefoo.ppmwithaqualityfactorof60andsavestheoutputas foo.jpg: cjpeg−quality60foo.ppm>foo.jpg HINTS ColorGIFfilesarenottheidealinputforJPEG;JPEGisreallyintendedforcompressingfullcolor(24-bit)images.Inparticular,don’ttrytoconvertcartoons,linedrawings,andotherimages thathaveonlyafewdistinctcolors.GIFworksgreatonthese,JPEGdoesnot.Ifyouwantto convertaGIFtoJPEG,youshouldexperimentwithcjpeg’s−qualityand−smoothoptionsto getasatisfactoryconversion.−smooth10orsoisoftenhelpful. AvoidrunninganimagethroughaseriesofJPEGcompression/decompressioncycles.Image qualitylosswillaccumulate;aftertenorsocyclestheimagemaybenoticeablyworsethanitwas afteronecycle.It’sbesttousealosslessformatwhilemanipulatinganimage,thenconvertto JPEGformatwhenyouarereadytofiletheimageaway. The−optimizeoptiontocjpegisworthusingwhenyouaremakinga"final"versionforposting orarchiving.It’salsoawinwhenyouareusinglowqualitysettingstomakeverysmallJPEG files;thepercentageimprovementisoftenalotmorethanitisonlargerfiles.(Atpresent,−optimizemodeisalwaysselectedwhengeneratingprogressiveJPEGfiles.) ENVIRONMENT JPEGMEM Ifthisenvironmentvariableisset,itsvalueisthedefaultmemorylimit.Thevalueis specifiedasdescribedforthe−maxmemoryswitch.JPEGMEMoverridesthedefault valuespecifiedwhentheprogramwascompiled,anditselfisoverriddenbyanexplicit −maxmemory. SEEALSO djpeg(1),jpegtran(1),rdjpgcom(1),wrjpgcom(1) ppm(5),pgm(5) Wallace,GregoryK."TheJPEGStillPictureCompressionStandard",Communicationsofthe ACM,April1991(vol.34,no.4),pp.30-44. AUTHOR IndependentJPEGGroup 20March1998 3 CJPEG(1) CJPEG(1) BUGS Arithmeticcodingisnotsupportedforlegalreasons. GIFinputfilesarenolongersupported,toavoidtheUnisysLZWpatent.UseaUnisys-licensed programifyouneedtoreadaGIFfile.(ConversionofGIFfilestoJPEGisusuallyabadidea anyway.) NotallvariantsofBMPandTargafileformatsaresupported. The−targaswitchisnotabug,it’safeature.(ItwouldbeabugiftheTargaformatdesigners hadnotbeenclueless.) Stillnotasfastaswe’dlike. 20March1998 4