c# free pdf viewer component : Add a blank page to a pdf control application utility azure html web page visual studio REC-png2-part863

4. CHUNKSPECIFICATIONS
21
Thekeywordandtextstringareseparatedbyazerobyte(nullcharacter). Neitherthekeywordnorthetext
stringcancontainanullcharacter. Notethatthetextstringisnotnull-terminated(thelengthofthechunk
issufficientinformationtolocatetheending).Thekeywordmustbeatleastonecharacterandlessthan80
characterslong.Thetextstringcanbeofanylengthfromzerobytesuptothemaximumpermissiblechunk
sizelessthelengthofthekeywordandseparator.
AnynumberoftEXtchunkscanappear,andmorethanonewiththesamekeywordispermissible.
Thekeywordindicatesthetypeofinformationrepresentedbythetextstring. Thefollowingkeywordsare
predefinedandshouldbeusedwhereappropriate:
Title
Short (one e line) ) title or caption for image
Author
Name of image’s creator
Description
Description of f image (possibly long)
Copyright
Copyright notice
Creation Time
Time of original image creation
Software
Software used to create the image
Disclaimer
Legal disclaimer
Warning
Warning of f nature e of f content
Source
Device used to create e the e image
Comment
Miscellaneous comment; conversion n from
GIF comment
FortheCreationTimekeyword,thedateformatdefinedinsection5.2.14ofRFC1123issuggested,butnot
required[RFC-1123].Decodersshouldallowforfree-formattextassociatedwiththisoranyotherkeyword.
Otherkeywordsmaybeinventedforotherpurposes.Keywordsofgeneralinterestcanberegisteredwiththe
maintainersofthePNGspecification. However,itisalsopermittedtouseprivateunregisteredkeywords.
(Privatekeywordsshouldbereasonablyself-explanatory,inordertominimizethechancethatthesamekey-
wordwillbeusedforincompatiblepurposesbydifferentpeople.)
BothkeywordandtextareinterpretedaccordingtotheISO8859-1(Latin-1)characterset[ISO-8859].The
textstringcancontainanyLatin-1character. Newlinesinthetextstringshouldberepresentedbyasingle
linefeedcharacter(decimal10);useofothercontrolcharactersinthetextisdiscouraged.
KeywordsmustcontainonlyprintableLatin-1charactersandspaces;thatis,onlycharactercodes32-126
and161-255decimalareallowed. Toreducethechancesforhumanmisreadingofakeyword,leadingand
trailingspacesareforbidden,asareconsecutivespaces.Notealsothatthenon-breakingspace(code160)is
notpermittedinkeywords,sinceitisvisuallyindistinguishablefromanordinaryspace.
Keywordsmustbespelledexactlyasregistered,sothatdecoderscanusesimpleliteralcomparisonswhen
lookingforparticularkeywords.Inparticular,keywordsareconsideredcase-sensitive.
SeeRecommendationsforEncoders: Textchunkprocessing(Section9.7)andRecommendationsforDe-
coders:Textchunkprocessing(Section10.11).
Add a blank page to a pdf - 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 numbers pdf files; add page numbers to a pdf file
Add a blank page to a pdf - 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
add and delete pages from pdf; adding page numbers to a pdf file
22
PNG(PORTABLENETWORKGRAPHICS)SPECIFICATION
4.2.8 tIME E Imagelast-modificationtime
ThetIMEchunkgivesthetimeofthelastimagemodification(notthetimeofinitialimagecreation). It
contains:
Year:
2 bytes (complete; for example, 1995,
not
95)
Month:
1 byte (1-12)
Day:
1 byte (1-31)
Hour:
1 byte (0-23)
Minute: 1 byte (0-59)
Second: 1 byte (0-60)
(yes, 60, , for leap p seconds; not t 61,
a common error)
UniversalTime(UTC,alsocalledGMT)shouldbespecifiedratherthanlocaltime.
ThetIMEchunkisintendedforuseasanautomatically-appliedtimestampthatisupdatedwheneverthe
imagedataischanged.ItisrecommendedthattIMEnotbechangedbyPNGeditorsthatdonotchangethe
imagedata.SeealsotheCreationTimetEXtkeyword,whichcanbeusedforauser-suppliedtime.
4.2.9 tRNS S Transparency
ThetRNSchunkspecifiesthattheimageusessimpletransparency: eitheralphavaluesassociatedwith
paletteentries(forindexed-colorimages)orasingletransparentcolor(forgrayscaleandtruecolorimages).
Althoughsimpletransparencyisnotaselegantasthefullalphachannel,itrequireslessstoragespaceandis
sufficientformanycommoncases.
Forcolortype3(indexedcolor),thetRNSchunkcontainsaseriesofone-bytealphavalues,corresponding
toentriesinthePLTEchunk:
Alpha for r palette index 0:
1 byte
Alpha for r palette index 1:
1 byte
... etc ...
Eachentryindicatesthatpixelsofthecorrespondingpaletteindexmustbetreatedashavingthespecified
alphavalue.Alphavalueshavethesameinterpretationasinan8-bitfullalphachannel:0isfullytransparent,
255isfullyopaque,regardlessofimagebitdepth.ThetRNSchunkmustnotcontainmorealphavaluesthan
therearepaletteentries,buttRNScancontainfewervaluesthantherearepaletteentries. Inthiscase,the
alphavalueforallremainingpaletteentriesisassumedtobe255.Inthecommoncaseinwhichonlypalette
index0needbemadetransparent,onlyaone-bytetRNSchunkisneeded.
Forcolortype0(grayscale),thetRNSchunkcontainsasinglegraylevelvalue,storedintheformat:
Gray:
2 bytes, , range 0 0 .. (2ˆbitdepth)-1
(Forconsistency,2bytesareusedregardlessoftheimagebitdepth.)Pixelsofthespecifiedgraylevelareto
betreatedastransparent(equivalenttoalphavalue0);allotherpixelsaretobetreatedasfullyopaque(alpha
value(2ˆbitdepth)-1).
C# PDF Page Delete Library: remove PDF pages in C#.net, ASP.NET
In order to run the sample code, the following steps would be necessary. Add necessary references: pageId, The page index of the deleted blank page.
add document to pdf pages; adding page to pdf
C# Word - Insert Blank Word Page in C#.NET
Add and Insert a blank Page to Word File in C#. This C# demo will help you to insert a Word page to a DOCXDocument object at specified position.
adding page numbers to a pdf in preview; add page number pdf
4. CHUNKSPECIFICATIONS
23
Forcolortype2(truecolor),thetRNSchunkcontainsasingleRGBcolorvalue,storedintheformat:
Red:
2 bytes, , range 0 0 .. (2ˆbitdepth)-1
Green: 2 2 bytes, , range 0 0 .. (2ˆbitdepth)-1
Blue:
2 bytes, , range 0 0 .. (2ˆbitdepth)-1
(Forconsistency,2bytespersampleareusedregardlessoftheimagebitdepth.)Pixelsofthespecifiedcolor
valuearetobetreatedastransparent(equivalenttoalphavalue0);allotherpixelsaretobetreatedasfully
opaque(alphavalue(2ˆbitdepth)-1).
tRNSisprohibitedforcolortypes4and6,sinceafullalphachannelisalreadypresentinthosecases.
Note:whendealingwith16-bitgrayscaleortruecolordata,itisimportanttocomparebothbytesofthesample
valuestodeterminewhetherapixelistransparent. Althoughdecodersmaydropthelow-orderbyteofthe
samplesfordisplay,thismustnotoccuruntilafterthedatahasbeentestedfortransparency.Forexample,if
thegrayscalelevel0x0001isspecifiedtobetransparent,itwouldbeincorrecttocompareonlythehigh-order
byteanddecidethat0x0002isalsotransparent.
Whenpresent,thetRNSchunkmustprecedethefirstIDATchunk,andmustfollowthePLTEchunk,ifany.
4.2.10 zTXt t Compressedtextualdata
ThezTXtchunkcontainstextualdata,justastEXtdoes;however,zTXttakesadvantageofcompression.
zTXtandtEXtchunksaresemanticallyequivalent,butzTXtisrecommendedforstoringlargeblocksof
text.
AzTXtchunkcontains:
Keyword:
1-79 bytes (character string)
Null separator:
1 byte
Compression method: 1 byte
Compressed text:
n bytes
ThekeywordandnullseparatorareexactlythesameasinthetEXtchunk. Notethatthekeywordisnot
compressed. ThecompressionmethodbyteidentifiesthecompressionmethodusedinthiszTXtchunk.
Theonlyvaluepresentlydefinedforitis0(deflate/inflatecompression). Thecompressionmethodbyteis
followedbyacompresseddatastreamthatmakesuptheremainderofthechunk.Forcompressionmethod0,
thisdatastreamadherestothezlibdatastreamformat(seeDeflate/InflateCompression,Chapter5).Decom-
pressionofthisdatastreamyieldsLatin-1textthatisidenticaltothetextthatwouldbestoredinanequivalent
tEXtchunk.
AnynumberofzTXtandtEXtchunkscanappearinthesamefile.SeetheprecedingdefinitionofthetEXt
chunkforthepredefinedkeywordsandtherecommendedformatofthetext.
SeeRecommendationsforEncoders:Textchunkprocessing(Section9.7),andRecommendationsforDe-
coders:Textchunkprocessing(Section10.11).
C# PowerPoint - Insert Blank PowerPoint Page in C#.NET
Add and Insert a blank Page to PowerPoint File in C#. This C# demo will help you to insert a PowerPoint page to a DOCXDocument object at specified position.
adding page to pdf in preview; add and remove pages from pdf file online
C# Create PDF Library SDK to convert PDF from other file formats
Add necessary references: RasterEdge.Imaging.Basic.dll. using RasterEdge.XDoc.PDF; Create a new PDF Document with one Blank Page in C# Project.
add a page to a pdf online; add pages to pdf without acrobat
24
PNG(PORTABLENETWORKGRAPHICS)SPECIFICATION
4.3 Summaryofstandardchunks
Thistablesummarizessomepropertiesofthestandardchunktypes.
Critical chunks (must appear r in n this order, except PLTE
is optional):
Name
Multiple
Ordering constraints
OK?
IHDR
No
Must be e first
PLTE
No
Before IDAT
IDAT
Yes
Multiple IDATs s must be consecutive
IEND
No
Must be e last
Ancillary chunks (need not t appear r in this order):
Name
Multiple
Ordering constraints
OK?
cHRM
No
Before PLTE E and IDAT
gAMA
No
Before PLTE E and IDAT
sBIT
No
Before PLTE E and IDAT
bKGD
No
After PLTE; ; before IDAT
hIST
No
After PLTE; ; before IDAT
tRNS
No
After PLTE; ; before IDAT
pHYs
No
Before IDAT
tIME
No
None
tEXt
Yes
None
zTXt
Yes
None
StandardkeywordsfortEXtandzTXtchunks:
Title
Short (one e line) ) title or caption for image
Author
Name of image’s creator
Description
Description of f image (possibly long)
Copyright
Copyright notice
Creation Time
Time of original image creation
Software
Software used to create the image
Disclaimer
Legal disclaimer
Warning
Warning of f nature e of f content
Source
Device used to create e the e image
Comment
Miscellaneous comment; conversion n from
GIF comment
C# PDF Page Replace Library: replace PDF pages in C#.net, ASP.NET
Add necessary references: RasterEdge.Imaging.Basic.dll. pageIdx, The page index of the deleted blank page. 0
adding page numbers to a pdf document; add page pdf reader
C# PDF: PDF Document Viewer & Reader SDK for Windows Forms
page. AddPage: Prior to the currently displayed PDF page to add a blank page. DeletePage: Delete the currently displayed PDF page.
adding page numbers to a pdf in reader; add page number to pdf print
5. DEFLATE/INFLATECOMPRESSION
25
4.4 Additionalchunktypes
AdditionalpublicPNGchunktypesaredefinedinthedocument“PNGSpecial-PurposePublicChunks”
[PNG-EXTENSIONS].Chunksdescribedthereareexpectedtobelesswidelysupportedthanthosedefined
inthisspecification.However,applicationauthorsareencouragedtousethosechunktypeswheneverappro-
priatefortheirapplications. Additionalchunktypescanbeproposedforinclusioninthatlistbycontacting
thePNGspecificationmaintainersatpng-info@uunet.uu.netoratpng-group@w3.org.
Newpublicchunkswillonlyberegisterediftheyareofusetoothersanddonotviolatethedesignphilosophy
ofPNG.Chunkregistrationisnotautomatic,althoughitistheintentoftheauthorsthatitbestraightforward
whenanewchunkofpotentiallywideapplicationisneeded. Notethatthecreationofnewcriticalchunk
typesisdiscouragedunlessabsolutelynecessary.
Applicationscanalsouseprivatechunktypestocarrydatathatisnotofinteresttootherapplications. See
RecommendationsforEncoders:Useofprivatechunks(Section9.8).
Decodersmustbepreparedtoencounterunrecognizedpublicorprivatechunktypecodes. Unrecognized
chunktypesmustbehandledasdescribedinChunknamingconventions(Section3.3).
5 Deflate/InflateCompression
PNGcompressionmethod0(theonlycompressionmethodpresentlydefinedforPNG)specifiesdeflate/
inflatecompressionwitha32Kslidingwindow.DeflatecompressionisanLZ77derivativeusedinzip,gzip,
pkzipandrelatedprograms. Extensiveresearchhasbeendonesupportingitspatent-freestatus.PortableC
implementationsarefreelyavailable.
Deflate-compresseddatastreamswithinPNGarestoredinthe“zlib”format,whichhasthestructure:
Compression method/flags s code: : 1 byte
Additional flags/check bits:
1 byte
Compressed data blocks:
n bytes
Check value:
4 bytes
Furtherdetailsonthisformataregiveninthezlibspecification[RFC-1950].
ForPNGcompressionmethod0,thezlibcompressionmethod/flagscodemustspecifymethodcode8(“de-
flate”compression)andanLZ77windowsizeofnotmorethan32K.Notethatthezlibcompressionmethod
numberisnotthesameasthePNGcompressionmethodnumber. Theadditionalflagsmustnotspecifya
presetdictionary.
Thecompresseddatawithinthezlibdatastreamisstoredasaseriesofblocks,eachofwhichcanrepresentraw
(uncompressed)data,LZ77-compresseddataencodedwithfixedHuffmancodes,orLZ77-compresseddata
encodedwithcustomHuffmancodes.Amarkerbitinthefinalblockidentifiesitasthelastblock,allowing
thedecodertorecognizetheendofthecompresseddatastream.Furtherdetailsonthecompressionalgorithm
andtheencodingaregiveninthedeflatespecification[RFC-1951].
VB.NET Create PDF Library SDK to convert PDF from other file
In order to run the sample code, the following steps would be necessary. Add necessary references: VB.NET: Create a New PDF Document with One Blank Page.
add remove pages from pdf; add page to pdf in preview
VB.NET PDF: Get Started with PDF Library
with blank page? If so, you will work out this target just by using RasterEdge PDF document creating component within VB web or Windows application. Add
add contents page to pdf; add pages to pdf acrobat
26
PNG(PORTABLENETWORKGRAPHICS)SPECIFICATION
Thecheckvaluestoredattheendofthezlibdatastreamiscalculatedontheuncompresseddatarepresented
bythedatastream.NotethatthealgorithmusedisnotthesameastheCRCcalculationusedforPNGchunk
checkvalues.Thezlibcheckvalueisusefulmainlyasacross-checkthatthedeflateandinflatealgorithms
areimplementedcorrectly. VerifyingthechunkCRCsprovidesadequateconfidencethatthePNGfilehas
beentransmittedundamaged.
InaPNGfile,theconcatenationofthecontentsofalltheIDATchunksmakesupazlibdatastreamasspecified
above.Thisdatastreamdecompressestofilteredimagedataasdescribedelsewhereinthisdocument.
ItisimportanttoemphasizethattheboundariesbetweenIDATchunksarearbitraryandcanfallanywhere
inthezlibdatastream.ThereisnotnecessarilyanycorrelationbetweenIDATchunkboundariesanddeflate
blockboundariesoranyotherfeatureofthezlibdata.Forexample,itisentirelypossiblefortheterminating
zlibcheckvaluetobesplitacrossIDATchunks.
Inthesamevein,thereisnorequiredcorrelationbetweenthestructureoftheimagedata(i.e.,scanlinebound-
aries)anddeflateblockboundariesorIDATchunkboundaries.Thecompleteimagedataisrepresentedbya
singlezlibdatastreamthatisstoredinsomenumberofIDATchunks;adecoderthatassumesanymorethan
thisisincorrect.(Ofcourse,someencoderimplementationsmayemitfilesinwhichsomeofthesestructures
areindeedrelated.Butdecoderscannotrelyonthis.)
PNGalsouseszlibdatastreamsinzTXtchunks. InazTXtchunk,theremainderofthechunkfollowing
thecompressionmethodbyteisazlibdatastreamasspecifiedabove. Thisdatastreamdecompressestothe
user-readabletextdescribedbythechunk’skeyword. Unliketheimagedata,suchdatastreamsarenotsplit
acrosschunks;eachzTXtchunkcontainsanindependentzlibdatastream.
AdditionaldocumentationandportableCcodefordeflateandinflateareavailablefromtheInfo-ZIParchives
at
URL:ftp://ftp.uu.net/pub/archiving/zip/
.
6 FilterAlgorithms
Thischapterdescribesthefilteralgorithmsthatcanbeappliedbeforecompression. Thepurposeofthese
filtersistopreparetheimagedataforoptimumcompression.
6.1 Filtertypes
PNGfiltermethod0definesfivebasicfiltertypes:
Type
Name
0
None
1
Sub
2
Up
3
Average
4
Paeth
6. FILTERALGORITHMS
27
(Notethatfiltermethod0inIHDRspecifiesexactlythissetoffivefiltertypes. Ifthesetoffiltertypesis
everextended,adifferentfiltermethodnumberwillbeassignedtotheextendedset,sothatdecodersneed
notdecompressthedatatodiscoverthatitcontainsunsupportedfiltertypes.)
Theencodercanchoosewhichofthesefilteralgorithmstoapplyonascanline-by-scanline basis. . Inthe
imagedatasenttothecompressionstep,eachscanlineisprecededbyafiltertypebytethatspecifiesthefilter
algorithmusedforthatscanline.
Filteringalgorithmsareappliedtobytes,nottopixels,regardlessofthebitdepthorcolortypeoftheim-
age. Thefilteringalgorithmsworkonthebytesequenceformedbyascanlinethathasbeenrepresentedas
describedinImagelayout(Section2.3).Iftheimageincludesanalphachannel,thealphadataisfilteredin
thesamewayastheimagedata.
Whentheimageisinterlaced,eachpassoftheinterlacepatternistreatedasanindependentimageforfiltering
purposes. Thefiltersworkonthebytesequencesformedbythepixelsactuallytransmittedduringapass,
andthe“previousscanline”istheonepreviouslytransmittedinthesamepass,nottheoneadjacentinthe
completeimage.Notethatthesubimagetransmittedinanyonepassisalwaysrectangular,butisofsmaller
widthand/orheightthanthecompleteimage.Filteringisnotappliedwhenthissubimageisempty.
Forallfilters,thebytes“totheleftof”thefirstpixelinascanlinemustbetreatedasbeingzero.Forfilters
thatrefertothepriorscanline,theentirepriorscanlinemustbetreatedasbeingzeroesforthefirstscanline
ofanimage(orofapassofaninterlacedimage).
Toreversetheeffectofafilter,thedecodermustusethedecodedvaluesofthepriorpixelonthesameline,
thepixelimmediatelyabovethecurrentpixelonthepriorline,andthepixeljusttotheleftofthepixelabove.
Thisimpliesthatatleastonescanline’sworthofimagedatawillhavetobestoredbythedecoderatalltimes.
Eventhoughsomefiltertypesdonotrefertothepriorscanline,thedecoderwillalwaysneedtostoreeach
scanlineasitisdecoded,sincethenextscanlinemightuseafilterthatreferstoit.
PNGimposesnorestrictiononwhichfiltertypescanbeappliedtoanimage. However,thefiltersarenot
equallyeffectiveonalltypesofdata.SeeRecommendationsforEncoders:Filterselection(Section9.6).
SeealsoRationale:Filtering(Section12.9).
6.2 Filtertype0:None
WiththeNonefilter,thescanlineistransmittedunmodified;itisonlynecessarytoinsertafiltertypebyte
beforethedata.
6.3 Filtertype1:Sub
TheSubfiltertransmitsthedifferencebetweeneachbyteandthevalueofthecorrespondingbyteoftheprior
pixel.
TocomputetheSubfilter,applythefollowingformulatoeachbyteofthescanline:
28
PNG(PORTABLENETWORKGRAPHICS)SPECIFICATION
Sub(x) = = Raw(x) ) - Raw(x-bpp)
wherexrangesfromzerotothenumberofbytesrepresentingthescanlineminusone,Raw(x)referstothe
rawdatabyteatthatbytepositioninthescanline,andbppisdefinedasthenumberofbytespercomplete
pixel,roundinguptoone.Forexample,forcolortype2withabitdepthof16,bppisequalto6(threesamples,
twobytespersample);forcolortype0withabitdepthof2,bppisequalto1(roundingup);forcolortype
4withabitdepthof16,bppisequalto4(two-bytegrayscalesample,plustwo-bytealphasample).
Notethiscomputationisdoneforeachbyte,regardlessofbitdepth.Ina16-bitimage,eachMSBispredicted
fromtheprecedingMSBandeachLSBfromtheprecedingLSB,becauseofthewaythatbppisdefined.
Unsignedarithmeticmodulo256isused,sothatboththeinputsandoutputsfitintobytes.Thesequenceof
Subvaluesistransmittedasthefilteredscanline.
Forallx
0,assumeRaw(x)=0.
ToreversetheeffectoftheSubfilterafterdecompression,outputthefollowingvalue:
Sub(x) + + Raw(x-bpp)
(computedmod256),whereRawreferstothebytesalreadydecoded.
6.4 Filtertype2:Up
TheUpfilterisjustliketheSubfilterexceptthatthepixelimmediatelyabovethecurrentpixel,ratherthan
justtoitsleft,isusedasthepredictor.
TocomputetheUpfilter,applythefollowingformulatoeachbyteofthescanline:
Up(x) = = Raw(x) - - Prior(x)
wherexrangesfromzerotothenumberofbytesrepresentingthescanlineminusone,Raw(x)referstothe
rawdatabyteatthatbytepositioninthescanline,andPrior(x)referstotheunfilteredbytesoftheprior
scanline.
Notethisisdoneforeachbyte,regardlessofbitdepth.Unsignedarithmeticmodulo256isused,sothatboth
theinputsandoutputsfitintobytes.ThesequenceofUpvaluesistransmittedasthefilteredscanline.
Onthefirstscanlineofanimage(orofapassofaninterlacedimage),assumePrior(x)=0forallx.
ToreversetheeffectoftheUpfilterafterdecompression,outputthefollowingvalue:
Up(x) + + Prior(x)
(computedmod256),wherePriorreferstothedecodedbytesofthepriorscanline.
6. FILTERALGORITHMS
29
6.5 Filtertype3:Average
TheAveragefilterusestheaverageofthetwoneighboringpixels(leftandabove)topredictthevalueofa
pixel.
TocomputetheAveragefilter,applythefollowingformulatoeachbyteofthescanline:
Average(x) = = Raw(x) ) - floor((Raw(x-bpp)+Prior(x))/2)
wherexrangesfromzerotothenumberofbytesrepresentingthescanlineminusone,Raw(x)refersto
therawdatabyteatthatbytepositioninthescanline,Prior(x)referstotheunfilteredbytesoftheprior
scanline,andbppisdefinedasfortheSubfilter.
Notethisisdoneforeachbyte,regardlessofbitdepth.ThesequenceofAveragevaluesistransmittedas
thefilteredscanline.
Thesubtractionofthepredictedvaluefromtherawbytemustbedonemodulo256,sothatboththeinputs
andoutputsfitintobytes.However,thesumRaw(x-bpp)+Prior(x)mustbeformedwithoutoverflow
(usingatleastnine-bitarithmetic).floor()indicatesthattheresultofthedivisionisroundedtothenext
lowerintegeriffractional;inotherwords,itisanintegerdivisionorrightshiftoperation.
Forallx
0,assumeRaw(x)=0. Onthefirstscanlineofanimage(orofapassofaninterlacedimage),
assumePrior(x)=0forallx.
ToreversetheeffectoftheAveragefilterafterdecompression,outputthefollowingvalue:
Average(x) + + floor((Raw(x-bpp)+Prior(x))/2)
wheretheresultiscomputedmod256,butthepredictioniscalculatedinthesamewayasforencoding.Raw
referstothebytesalreadydecoded,andPriorreferstothedecodedbytesofthepriorscanline.
6.6 Filtertype4:Paeth
ThePaethfiltercomputesasimplelinearfunctionofthethreeneighboringpixels(left,above,upperleft),
thenchoosesaspredictortheneighboringpixelclosesttothecomputedvalue.ThistechniqueisduetoAlan
W.Paeth[PAETH].
TocomputethePaethfilter,applythefollowingformulatoeachbyteofthescanline:
Paeth(x) = Raw(x) - - PaethPredictor(Raw(x-bpp), , Prior(x),
Prior(x-bpp))
wherexrangesfromzerotothenumberofbytesrepresentingthescanlineminusone,Raw(x)refersto
therawdatabyteatthatbytepositioninthescanline,Prior(x)referstotheunfilteredbytesoftheprior
scanline,andbppisdefinedasfortheSubfilter.
Notethisisdoneforeachbyte,regardlessofbitdepth.Unsignedarithmeticmodulo256isused,sothatboth
theinputsandoutputsfitintobytes.ThesequenceofPaethvaluesistransmittedasthefilteredscanline.
ThePaethPredictorfunctionisdefinedbythefollowingpseudocode:
30
PNG(PORTABLENETWORKGRAPHICS)SPECIFICATION
function PaethPredictor (a, , b, c)
begin
; a a = = left, , b b = above, , c c = upper left
p := a a + + b b - - c
; initial estimate
pa := abs(p p - - a)
; distances to o a, , b, c
pb := abs(p p - - b)
pc := abs(p p - - c)
; return nearest of a,b,c,
; breaking ties in n order r a,b,c.
if pa <= pb b AND D pa a <= pc c then n return n a
else if f pb <= = pc then return b
else return n c
end
ThecalculationswithinthePaethPredictorfunctionmustbeperformedexactly,withoutoverflow.Arithmetic
modulo256istobeusedonlyforthefinalstepofsubtractingthefunctionresultfromthetargetbytevalue.
Notethattheorderinwhichtiesarebrokeniscriticalandmustnotbealtered. Thetiebreakorderis:
pixeltotheleft,pixelabove,pixeltotheupperleft.(ThisorderdiffersfromthatgiveninPaeth’sarticle.)
Forallx
0,assumeRaw(x)=0andPrior(x)=0. Onthefirstscanlineofanimage(orofapassofan
interlacedimage),assumePrior(x)=0forallx.
ToreversetheeffectofthePaethfilterafterdecompression,outputthefollowingvalue:
Paeth(x) + PaethPredictor(Raw(x-bpp), Prior(x), Prior(x-bpp))
(computedmod256),whereRawandPriorrefertobytesalreadydecoded.ExactlythesamePaethPredic-
torfunctionisusedbybothencoderanddecoder.
7 ChunkOrderingRules
ToallownewchunktypestobeaddedtoPNG,itisnecessarytoestablishrulesabouttheorderingrequire-
mentsforallchunktypes.OtherwiseaPNGeditingprogramcannotknowwhattodowhenitencountersan
unknownchunk.
Wedefinea“PNGeditor”asaprogramthatmodifiesaPNGfileandwishestopreserveasmuchaspossible
oftheancillaryinformationinthefile. TwoexamplesofPNGeditorsareaprogramthataddsormodifies
textchunks,andaprogramthataddsasuggestedpalettetoatruecolorPNGfile. Ordinaryimageeditors
arenotPNGeditorsinthissense,becausetheyusuallydiscardallunrecognizedinformationwhilereading
inanimage. (Note:westronglyencourageprogramshandlingPNGfilestopreserveancillaryinformation
wheneverpossible.)
Asanexampleofpossibleproblems,considerahypotheticalnewancillarychunktypethatissafe-to-copy
andisrequiredtoappearafterPLTEifPLTEispresent.IfourprogramtoaddasuggestedPLTEdoesnot
recognizethisnewchunk,itmayinsertPLTEinthewrongplace,namelyafterthenewchunk. Wecould
Documents you may be interested
Documents you may be interested