c# free pdf viewer component : Adding page numbers to a pdf in preview Library control class asp.net web page windows ajax REC-png5-part866

10. RECOMMENDATIONSFORDECODERS
51
while col < width
begin
visit (row, col,
min (Block_Height[pass], , height t - row),
min (Block_Width[pass], , width h - col))
col := col + + Col_Increment[pass]
end
row := row + Row_Increment[pass]
end
pass := pass + 1
end
Here,thefunction“visit(row,column,height,width)”obtainsthenexttransmittedpixelandpaintsarectangle
ofthespecifiedheightandwidth,whoseupper-leftcornerisatthespecifiedrowandcolumn,usingthecolor
indicatedbythepixel.Notethatrowandcolumnaremeasuredfrom0,0attheupperleftcorner.
Ifthedecoderismergingthereceivedimagewithabackgroundimage,itmaybemoreconvenientjustto
paintthereceivedpixelpositions;thatis,the“visit()”functionsetsonlythepixelatthespecifiedrowand
column,notthewholerectangle. Thisproducesa“fade-in”effectasthenewimagegraduallyreplacesthe
old.Anadvantageofthisapproachisthatproperalphaortransparencyprocessingcanbedoneaseachpixel
isreplaced. Paintingarectangleasdescribedabovewilloverwritebackground-imagepixelsthatmaybe
neededlater,ifthepixelseventuallyreceivedforthosepositionsturnouttobewhollyorpartiallytransparent.
Ofcourse,thisisonlyaproblemifthebackgroundimageisnotstoredanywhereoffscreen.
10.10 Suggested-paletteandhistogramusage
IntruecolorPNGfiles,theencodermayhaveprovidedasuggestedPLTEchunkforusebyviewersrunning
onindexed-colorhardware.
IftheimagehasatRNSchunk,theviewerwillneedtoadaptthesuggestedpaletteforusewithitsdesired
backgroundcolor.Todothis,replacethepaletteentryclosesttothetRNScolorwiththedesiredbackground
color;orjustaddapaletteentryforthebackgroundcolor,iftheviewercanhandlemorecolorsthanthere
arePLTEentries.
Forimagesofcolortype6(truecolorwithalphachannel),anysuggestedpaletteshouldhavebeendesigned
fordisplayoftheimageagainstauniformbackgroundofthecolorspecifiedbybKGD.Viewersshouldprob-
ablyignorethepaletteiftheyintendtouseadifferentbackground,orifthebKGDchunkismissing.Viewers
canuseasuggestedpalettefordisplayagainstadifferentbackgroundthanitwasintendedfor,buttheresults
maynotbeverygood.
Iftheviewerpresentsatransparenttruecolorimageagainstabackgroundthatismorecomplexthanasingle
color,itisunlikelythatthesuggestedpalettewillbeoptimalforthecompositeimage.Inthiscaseitisbestto
performatruecolorcompositingsteponthetruecolorPNGimageandbackgroundimage,thencolor-quantize
theresultingimage.
Adding page numbers to a pdf in preview - insert pages into PDF file in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
Guide C# Users to Insert (Empty) PDF Page or Pages from a Supported File Format
add page to pdf; add a page to a pdf
Adding page numbers to a pdf in preview - VB.NET PDF Page Insert Library: insert pages into PDF file in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
Easy to Use VB.NET APIs to Add a New Blank Page to PDF Document
adding pages to a pdf; adding page numbers to pdf in
52
PNG(PORTABLENETWORKGRAPHICS)SPECIFICATION
Thehistogramchunkisusefulwhentheviewercannotprovideasmanycolorsasareusedintheimage’s
palette. Iftheviewerisonlyshortafewcolors,itisusuallyadequatetodroptheleast-usedcolorsfromthe
palette. Toreducethenumberofcolorssubstantially,it’sbesttochooseentirelynewrepresentativecolors,
ratherthantryingtouseasubsetoftheexistingpalette.Thisamountstoperforminganewcolorquantization
step;however,theexistingpaletteandhistogramcanbeusedastheinputdata,thusavoidingascanofthe
imagedata.
Ifnopaletteorhistogramchunkisprovided,adecodercandevelopitsown,atthecostofanextrapassover
theimagedata.Alternatively,adefaultpalette(probablyacolorcube)canbeused.
SeealsoRecommendationsforEncoders:Suggestedpalettes(Section9.5).
10.11 Textchunkprocessing
Ifpractical,decodersshouldhaveawaytodisplaytotheuseralltEXtandzTXtchunksfoundinthefile.
Evenifthedecoderdoesnotrecognizeaparticulartextkeyword,theusermightbeabletounderstandit.
PNGtextisnotsupposedtocontainanycharactersoutsidetheISO8859-1“Latin-1”characterset(thatis,
nocodes0-31or127-159),exceptforthenewlinecharacter(decimal10). Butdecodersmightencounter
suchcharactersanyway.Someofthesecharacterscanbesafelydisplayed(e.g.,TAB,FF,andCR,decimal
9,12,and13,respectively),butothers,especiallytheESCcharacter(decimal27),couldposeasecurity
hazardbecauseunexpectedactionsmaybetakenbydisplayhardwareorsoftware.Topreventsuchhazards,
decodersshouldnotattempttodirectlydisplayanynon-Latin-1characters(exceptfornewlineandperhaps
TAB,FF,CR)encounteredinatEXtorzTXtchunk. Instead,ignorethemordisplaytheminavisible
notationsuchas“\nnn”.SeeSecurityconsiderations(Section8.5).
EventhoughencodersaresupposedtorepresentnewlinesasLF,itisrecommendedthatdecodersnotrelyon
this;it’sbesttorecognizeallthecommonnewlinecombinations(CR,LF,andCR-LF)anddisplayeachasa
singlenewline.TABcanbeexpandedtothepropernumberofspacesneededtoarriveatacolumnmultiple
of8.
Decodersrunningonsystemswithnon-Latin-1charactersetencodingshouldprovidecharactercoderemap-
pingsothatLatin-1charactersaredisplayedcorrectly. Somesystemsmaynotprovideallthecharacters
definedinLatin-1. Mappingunavailablecharacterstoavisiblenotationsuchas“\nnn”isagoodfallback.
Inparticular,charactercodes127-255shouldbedisplayedonlyiftheyareprintablecharactersonthedecod-
ingsystem.Somesystemsmayinterpretsuchcodesascontrolcharacters;forsecurity,decodersrunningon
suchsystemsshouldnotdisplaysuchcharactersliterally.
Decodersshouldbepreparedtodisplaytextchunksthatcontainanynumberofprintingcharactersbetween
newlinecharacters,eventhoughencodersareencouragedtoavoidcreatinglinesinexcessof79characters.
11 Glossary
aˆb
C# Create PDF Library SDK to convert PDF from other file formats
PDF document file but also offer them the ability to count the page numbers of generated Besides, using this PDF document metadata adding control, you
add a page to a pdf in acrobat; add page number pdf file
C# Word - Word Create or Build in C#.NET
but also offer them the ability to count the page numbers of generated Besides, using this Word document adding control, you can add some Create Word From PDF.
add pdf pages together; add page numbers pdf file
11. GLOSSARY
53
Exponentiation;araisedtothepowerb.Cprogrammersshouldbecarefulnottomisreadthisnotation
asexclusive-or. Notethatingamma-relatedcalculations,zeroraisedtoanypowerisvalidandmust
giveazeroresult.
Alpha
Avaluerepresentingapixel’sdegreeoftransparency. Themoretransparentapixel,thelessithides
thebackgroundagainstwhichtheimageispresented. InPNG,alphaisreallythedegreeofopacity:
zeroalpharepresentsacompletelytransparentpixel,maximumalpharepresentsacompletelyopaque
pixel.Butmostpeoplerefertoalphaasprovidingtransparencyinformation,notopacityinformation,
andwecontinuethatcustomhere.
Ancillarychunk
Achunkthatprovidesadditionalinformation.Adecodercanstillproduceameaningfulimage,though
notnecessarilythebestpossibleimage,withoutprocessingthechunk.
Bitdepth
Thenumberofbitsperpaletteindex(inindexed-colorPNGs)orpersample(inothercolortypes).This
isthesamevaluethatappearsinIHDR.
Byte
Eightbits;alsocalledanoctet.
Channel
Thesetofallsamplesofthesamekindwithinanimage;forexample,allthebluesamplesinatruecolor
image.(Theterm“component”isalsoused,butnotinthisspecification.)Asampleistheintersection
ofachannelandapixel.
Chromaticity
Apairofvaluesx,ythatpreciselyspecifythehue,thoughnottheabsolutebrightness,ofaperceived
color.
Chunk
AsectionofaPNGfile.Eachchunkhasatypeindicatedbyitschunktypename.Mosttypesofchunks
alsoincludesomedata. Theformatandmeaningofthedatawithinthechunkaredeterminedbythe
typename.
Composite
Asaverb,toformanimagebymergingaforegroundimageandabackgroundimage,usingtrans-
parencyinformationtodeterminewherethebackgroundshouldbevisible. Theforegroundimageis
saidtobe“compositedagainst”thebackground.
CRC
CyclicRedundancyCheck. ACRCisatypeofcheckvaluedesignedtocatchmosttransmissioner-
rors.AdecodercalculatestheCRCforthereceiveddataandcomparesittotheCRCthattheencoder
calculated,whichisappendedtothedata.Amismatchindicatesthatthedatawascorruptedintransit.
54
PNG(PORTABLENETWORKGRAPHICS)SPECIFICATION
Criticalchunk
Achunkthatmustbeunderstoodandprocessedbythedecoderinordertoproduceameaningfulimage
fromaPNGfile.
CRT
CathodeRayTube:acommontypeofcomputerdisplayhardware.
Datastream
Asequenceofbytes. Thistermisusedratherthan“file”todescribeabytesequencethatisonlya
portionofafile.WealsouseittoemphasizethataPNGimagemightbegeneratedandconsumed“on
thefly”,neverappearinginastoredfileatall.
Deflate
ThenameofthecompressionalgorithmusedinstandardPNGfiles,aswellasinzip,gzip,pkzip,and
othercompressionprograms.DeflateisamemberoftheLZ77familyofcompressionmethods.
Filter
Atransformationappliedtoimagedatainhopesofimprovingitscompressibility.PNGusesonlyloss-
less(reversible)filteralgorithms.
Framebuffer
Thefinaldigitalstorageareafortheimageshownbyacomputerdisplay.Softwarecausesanimageto
appearonscreenbyloadingitintotheframebuffer.
Gamma
Thebrightnessofmid-leveltonesinanimage.Moreprecisely,aparameterthatdescribestheshapeof
thetransferfunctionforoneormorestagesinanimagingpipeline.Thetransferfunctionisgivenby
theexpression
output = = input t ˆ gamma
wherebothinputandoutputarescaledtotherange0to1.
Grayscale
Animagerepresentationinwhicheachpixelisrepresentedbyasinglesamplevaluerepresentingover-
allluminance(onascalefromblacktowhite).PNGalsopermitsanalphasampletobestoredforeach
pixelofagrayscaleimage.
Indexedcolor
Animagerepresentationinwhicheachpixelisrepresentedbyasinglesamplethatisanindexintoa
paletteorlookuptable.Theselectedpaletteentrydefinestheactualcolorofthepixel.
Losslesscompression
Anymethodofdatacompressionthatguaranteestheoriginaldatacanbereconstructedexactly,bit-
for-bit.
11. GLOSSARY
55
Lossycompression
Anymethodofdatacompressionthatreconstructstheoriginaldataapproximately,ratherthanexactly.
LSB
LeastSignificantByteofamulti-bytevalue.
Luminance
Perceivedbrightness,orgrayscalelevel,ofacolor.Luminanceandchromaticitytogetherfullydefine
aperceivedcolor.
LUT
LookUpTable.Ingeneral,atableusedtotransformdata.Inframebufferhardware,aLUTcanbeused
tomapindexed-colorpixelsintoaselectedsetoftruecolorvalues,ortoperformgammacorrection.In
software,aLUTcanbeusedasafastwayofimplementinganyone-variablemathematicalfunction.
MSB
MostSignificantByteofamulti-bytevalue.
Palette
Thesetofcolorsavailableinanindexed-colorimage.InPNG,apaletteisanarrayofcolorsdefined
byred,green,andbluesamples. (Alphavaluescanalsobedefinedforpaletteentries,viathetRNS
chunk.)
Pixel
Theinformationstoredforasinglegridpointintheimage.Thecompleteimageisarectangulararray
ofpixels.
PNGeditor
AprogramthatmodifiesaPNGfileandpreservesancillaryinformation,includingchunksthatitdoes
notrecognize.SuchaprogrammustobeytherulesgiveninChunkOrderingRules(Chapter7).
Sample
Asinglenumberintheimagedata;forexample,theredvalueofapixel.Apixeliscomposedofoneor
moresamples.Whendiscussingphysicaldatalayout(inparticular,inImagelayout,Section2.3),we
use“sample”tomeananumberstoredintheimagearray.Itwouldbemoreprecisebutmuchlessread-
abletosay“sampleorpaletteindex”inthatcontext. Elsewhereinthespecification,“sample”means
acolorvalueoralphavalue.Intheindexed-colorcase,thesearepaletteentriesnotpaletteindexes.
Sampledepth
Theprecision,inbits,ofcolorvaluesandalphavalues. Inindexed-colorPNGsthesampledepthis
always8bydefinitionofthePLTEchunk.Inothercolortypesitisthesameasthebitdepth.
Scanline
Onehorizontalrowofpixelswithinanimage.
56
PNG(PORTABLENETWORKGRAPHICS)SPECIFICATION
Truecolor
Animagerepresentationinwhichpixelcolorsaredefinedbystoringthreesamplesforeachpixel,rep-
resentingred,green,andblueintensitiesrespectively.PNGalsopermitsanalphasampletobestored
foreachpixelofatruecolorimage.
Whitepoint
Thechromaticityofacomputerdisplay’snominalwhitevalue.
zlib
Aparticularformatfordatathathasbeencompressedusingdeflate-stylecompression.Alsothename
ofalibraryimplementingthismethod. PNGimplementationsneednotusethezliblibrary,butthey
mustconformtoitsformatforcompresseddata.
12 Appendix:Rationale
(ThisappendixisnotpartoftheformalPNGspecification.)
ThisappendixgivesthereasoningbehindsomeofthedesigndecisionsinPNG.Manyofthesedecisionswere
thesubjectofconsiderabledebate. Theauthorsfreelyadmitthatanothergroupmighthavemadedifferent
decisions;however,webelievethatourchoicesaredefensibleandconsistent.
12.1 Whyanewfileformat?
Doestheworldreallyneedyetanothergraphicsformat?Webelieveso.GIFisnolongerfreelyusable,but
noothercommonlyusedformatcandirectlyreplaceit,asisdiscussedinmoredetailbelow.Wemighthave
usedanadaptationofanexistingformat,forexampleGIFwithanunpatentedcompressionscheme.Butthis
wouldrequirenewcodeanyway;itwouldnotbeallthatmucheasiertoimplementthanawholenewfile
format. (PNGisdesignedtobesimpletoimplement,withtheexceptionofthecompressionengine,which
wouldbeneededinanycase.)Wefeelthatthisisanexcellentopportunitytodesignanewformatthatfixes
someoftheknownlimitationsofGIF.
12.2 Whythesefeatures?
ThefeatureschosenforPNGareintendedtoaddresstheneedsofapplicationsthatpreviouslyusedthespecial
strengthsofGIF.Inparticular,GIFiswelladaptedforonlinecommunicationsbecauseofitsstreamability
andprogressivedisplaycapability.PNGsharesthoseattributes.
WehavealsoaddressedsomeofthewidelyknownshortcomingsofGIF.Inparticular,PNGsupportstrue-
colorimages.Weknowofnowidelyusedimageformatthatlosslesslycompressestruecolorimagesasef-
fectivelyasPNGdoes.WehopethatPNGwillmakeuseoftruecolorimagesmorepracticalandwidespread.
12. APPENDIX:RATIONALE
57
Someformoftransparencycontrolisdesirableforapplicationsinwhichimagesaredisplayedagainstaback-
groundortogetherwithotherimages.GIFprovidedasimpletransparent-colorspecificationforthispurpose.
PNGsupportsafullalphachannelaswellastransparent-colorspecifications.Thisallowsbothhighlyflexible
transparencyandcompressionefficiency.
Robustnessagainsttransmissionerrorshasbeenanimportantconsideration.Forexample,imagestransferred
acrossInternetareoftenmistakenlyprocessedastext,leadingtofilecorruption.PNGisdesignedsothatsuch
errorscanbedetectedquicklyandreliably.
PNGhasbeenexpresslydesignednottobecompletelydependentonasinglecompressiontechnique. Al-
thoughdeflate/inflatecompressionismentionedinthisdocument,PNGwouldstillexistwithoutit.
12.3 Whynotthesefeatures?
SomefeatureshavebeendeliberatelyomittedfromPNG.Thesechoicesweremadetosimplifyimplemen-
tationofPNG,promoteportabilityandinterchangeability,andmaketheformatassimpleandfoolproofas
possibleforusers.Inparticular:
ThereisnouncompressedvariantofPNG.Itispossibletostoreuncompresseddatabyusingonlyun-
compresseddeflateblocks(afeaturenormallyusedtoguaranteethatdeflatedoesnotmakeincompress-
ibledatamuchlarger).However,PNGsoftwaremustsupportfulldeflate/inflate;anysoftwarethatdoes
notisnotcompliantwiththePNGstandard.ThetwomostimportantfeaturesofPNG—portabilityand
compression—areabsoluterequirementsforonlineapplications,andusersdemandthem. Failureto
supportfulldeflate/inflatecompromisesbothoftheseobjectives.
ThereisnolossycompressioninPNG.ExistingformatssuchasJFIFalreadyhandlelossycompres-
sionwell.Furthermore,availablelossycompressionmethods(e.g.,JPEG)arefarfromfoolproof—a
poorchoiceofqualitylevelcanruinanimage.Toavoiduserconfusionandunintentionallossofinfor-
mation,wefeelitisbesttokeeplossyandlosslessformatsstrictlyseparate.Also,lossycompression
iscomplextoimplement.AddingJPEGsupporttoaPNGdecodermightincreaseitssizebyanorder
ofmagnitude.Thiswouldcertainlycausesomedecoderstoomitsupportforthefeature,whichwould
destroyourgoalofinterchangeability.
ThereisnosupportforCMYKorotherunusualcolorspaces.Again,thisisinthenameofpromoting
portability. CMYK,inparticular,isfartoodevice-dependenttobeusefulasaportableimagerepre-
sentation.
Thereisnostandardchunkforthumbnailviewsofimages.Indiscussionswithsoftwarevendorswho
usethumbnailsintheirproducts,ithasbecomeclearthatmostwouldnotusea“standard”thumbnail
chunk.Foronething,everyvendorhasadifferentideaofwhatthedimensionsandcharacteristicsof
athumbnailoughttobe.Also,somevendorskeepthumbnailsinseparatefilestoaccommodatevaried
imageformats;theyarenotgoingtostopdoingthatsimplybecauseofathumbnailchunkinonenew
format.Proprietarychunkscontainingvendor-specificthumbnailsappeartobemorepracticalthana
commonthumbnailformat.
58
PNG(PORTABLENETWORKGRAPHICS)SPECIFICATION
ItisworthnotingthatprivateextensionstoPNGcouldeasilyaddthesefeatures. Wewillnot,however,in-
cludethemaspartofthebasicPNGstandard.
PNGalsodoesnotsupportmultipleimagesinonefile.Thisrestrictionisareflectionoftherealitythatmany
applicationsdonotneedandwillnotsupportmultipleimagesperfile.Inanycase,singleimagesareafunda-
mentallydifferentsortofobjectfromsequencesofimages.Ratherthanmakefalsepromisesofinterchange-
ability,wehavedrawnacleardistinctionbetweensingle-imageandmulti-imageformats.PNGisasingle-
imageformat.(ButseeMultiple-imageextension,Section8.4.)
12.4 WhynotuseformatX?
NumerousexistingformatswereconsideredbeforedecidingtodevelopPNG.Nonecouldmeettherequire-
mentswefeltwereimportantforPNG.
GIFisnolongersuitableasauniversalstandardbecauseoflegalentanglements. Althoughjustreplacing
GIF’scompressionmethodwouldavoidthatproblem,GIFdoesnotsupporttruecolorimages,alphachannels,
orgammacorrection. Thespechasmoresubtleproblemstoo. OnlyasmallsubsetoftheGIF89specis
actuallyportableacrossavarietyofimplementations,butthereisnocodificationofthemostportablepart
ofthespec.
TIFFisfartoocomplextomeetourgoalsofsimplicityandinterchangeability. DefiningaTIFFsubsetwould
meetthatobjection,butwouldfrustrateusersmakingthereasonableassumptionthatafilesavedasTIFFfrom
theirexistingsoftwarewouldloadintoaprogramsupportingourflavorofTIFF.Furthermore,TIFFisnot
designedforstreamprocessing,hasnoprovisionforprogressivedisplay,anddoesnotcurrentlyprovideany
good,legallyunencumbered,losslesscompressionmethod.
IFFhasalsobeensuggested,butisnotsuitableindetail:availableimagerepresentationsaretoomachine-
specificornotadequatelycompressed.TheoverallchunkstructureofIFFisausefulconceptthatPNGhas
liberallyborrowedfrom,butwedidnotattempttobebit-for-bitcompatiblewithIFFchunkstructure.Again
thisisduetodetailedissues,notablythefactthatIFFFORMsarenotdesignedtobeseriallywritable.
LosslessJPEGisnotsuitablebecauseitdoesnotprovideforthestorageofindexed-colorimages.Further-
more,itslosslesstruecolorcompressionisofteninferiortothatofPNG.
12.5 Byteorder
IthasbeenaskedwhyPNGusesnetworkbyteorder.Wehaveselectedonebyteorderinganduseditconsis-
tently.Whichorderinparticularisoflittlerelevance,butnetworkbyteorderhastheadvantagethatroutines
toconverttoandfromitarealreadyavailableonanyplatformthatsupportsTCP/IPnetworking,including
allPCplatforms.Thefunctionsaretrivialandwillbeincludedinthereferenceimplementation.
12. APPENDIX:RATIONALE
59
12.6 Interlacing
PNG’stwo-dimensionalinterlacingschemeismorecomplextoimplementthanGIF’sline-wiseinterlacing.
Italsocostsalittlemoreinfilesize.However,ityieldsaninitialimageeighttimesfasterthanGIF(thefirst
passtransmitsonly1/64thofthepixels,comparedto1/8thforGIF).Althoughthisinitialimageiscoarse,
itisusefulinmanysituations. Forexample,iftheimageisaWorldWideWebimagemapthattheuserhas
seenbefore,PNG’sfirstpassisoftenenoughtodeterminewheretoclick.ThePNGschemealsolooksbetter
thanGIF’s,becausehorizontalandverticalresolutionneverdifferbymorethanafactoroftwo;thisavoids
theodd“stretched”lookseenwheninterlacedGIFsarefilledinbyreplicatingscanlines.Preliminaryresults
showthatsmalltextinaninterlacedPNGimageistypicallyreadableabouttwiceasfastasinanequivalent
GIF,i.e.,afterPNG’sfifthpassor25%oftheimagedata,insteadofafterGIF’sthirdpassor50%. Thisis
againduetoPNG’smorebalancedincreaseinresolution.
12.7 Whygamma?
Itmightseemnaturaltostandardizeonstoringsamplevaluesthatarelinearlyproportionaltolightintensity
(thatis,havegammaof1.0).Butinfact,itiscommonforimagestohaveagammaoflessthan1.Thereare
threegoodreasonsforthis:
ForreasonsdetailedinGammaTutorial(Chapter13),allvideocamerasapplya“gammacorrection”
functiontotheintensityinformation.Thiscausesthevideosignaltohaveagammaofabout0.5relative
tothelightintensityintheoriginalscene.Thus,imagesobtainedbyframe-grabbingvideoalreadyhave
agammaofabout0.5.
Thehumaneyehasanonlinearresponsetointensity,solinearencodingofsampleseitherwastessam-
plecodesinbrightareasoftheimage,orprovidestoofewsamplecodestoavoidbandingartifactsin
darkareasoftheimage,orboth. Atleast12bitspersampleareneededtoavoidvisibleartifactsin
linearencodingwitha100:1imageintensityrange.Animagegammaintherange0.3to0.5allocates
samplevaluesinawaythatroughlycorrespondstotheeye’sresponse,sothat8bits/sampleareenough
toavoidartifactscausedbyinsufficientsampleprecisioninalmostallimages. Thismakes“gamma
encoding”amuchbetterwayofstoringdigitalimagesthanthesimplerlinearencoding.
ManyimagesarecreatedonPCsorworkstationswithnogammacorrectionhardwareandnosoft-
warewillingtoprovidegammacorrectioneither. Inthesecases,theimageshavehadtheirlighting
andcolorchosentolookbestonthisplatform—theycanbethoughtofashaving“manual”gamma
correctionbuiltin.Toseewhattheimageauthorintended,itisnecessarytotreatsuchimagesashav-
ingafile_gammavalueintherange0.4-0.6,dependingontheroomlightinglevelthattheauthorwas
workingin.
Inpractice,imagegammavaluesaround1.0andaround0.5arebothwidelyfound.Olderimagestandards
suchasGIFoftendonotaccountforthisfact.TheJFIFstandardspecifiesthatimagesinthatformatshould
uselinearsamples,butmanyJFIFimagesfoundontheInternetactuallyhaveagammasomewherenear
0.4or0.5. Thevarietyofimagesfoundandthevarietyofsystemsthatpeopledisplaythemonhaveledto
widespreadproblemswithimagesappearing“toodark”or“toolight”.
60
PNG(PORTABLENETWORKGRAPHICS)SPECIFICATION
PNGexpectsviewerstocompensateforimagegammaatthetimethattheimageisdisplayed.Anotherpos-
sibleapproachistoexpectencoderstoconvertallimagestoauniformgammaatencodingtime.Whilethat
methodwouldspeedviewersslightly,ithasfundamentalflaws:
Gammacorrectionisinherentlylossyduetoquantizationandroundofferror.Requiringconversionat
encodingtimethuscausesirreversibleloss.SincePNGisintendedtobealosslessstorageformat,this
isundesirable;weshouldstoreunmodifiedsourcedata.
Theencodermightnotknowthesourcegammavalue.Ifthedecoderdoesgammacorrectionatviewing
time,itcanadjustthegamma(changethedisplayedbrightness)inresponsetofeedbackfromahuman
user.Theencoderhasnosuchrecourse.
Whatever“standard”gammawesettledonwouldbewrongforsomedisplays.Henceviewerswould
stillneedgammacorrectioncapability.
Sincetherewillalwaysbeimageswithnogammaoranincorrectrecordedgamma,goodviewerswillneed
toincorporategammaadjustmentcodeanyway.Gammacorrectionatviewingtimeisthustherightwayto
go.
SeeGammaTutorial(Chapter13)formoreinformation.
12.8 Non-premultipliedalpha
PNGuses“unassociated”or“non-premultiplied”alphasothatimageswithseparatetransparencymaskscan
bestoredlosslessly.Anothercommontechnique,“premultipliedalpha”,storespixelvaluespremultipliedby
thealphafraction;ineffect,theimageisalreadycompositedagainstablackbackground. Anyimagedata
hiddenbythetransparencymaskisirretrievablylostbythatmethod,sincemultiplyingbyazeroalphavalue
alwaysproduceszero.
Someimagerenderingtechniquesgenerateimageswithpremultipliedalpha(thealphavalueactuallyrep-
resentshowmuchofthepixeliscoveredbytheimage). ThisrepresentationcanbeconvertedtoPNGby
dividingthesamplevaluesbyalpha,exceptwherealphaiszero.Theresultwilllookgoodifdisplayedbya
viewerthathandlesalphaproperly,butwillnotlookverygoodiftheviewerignoresthealphachannel.
Althougheachformofalphastoragehasitsadvantages,wedidnotwanttorequireallPNGviewerstohandle
bothforms.Westandardizedonnon-premultipliedalphaasbeingthelosslessandmoregeneralcase.
12.9 Filtering
PNGincludesfilteringcapabilitybecausefilteringcansignificantlyreducethecompressedsizeoftruecolor
andgrayscaleimages. Filteringisalsosometimesofvalueonindexed-colorimages,althoughthisisless
common.
Thefilteralgorithmsaredefinedtooperateonbytes,ratherthanpixels;thisgainssimplicityandspeedwith
verylittlecostincompressionperformance.Testshaveshownthatfilteringisusuallyineffectiveforimages
withfewerthan8bitspersample,soprovidingpixelwisefilteringforsuchimageswouldbepointless.For
Documents you may be interested
Documents you may be interested