| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102 |
- // Copyright (C) 2004-2025 Artifex Software, Inc.
- //
- // This file is part of MuPDF.
- //
- // MuPDF is free software: you can redistribute it and/or modify it under the
- // terms of the GNU Affero General Public License as published by the Free
- // Software Foundation, either version 3 of the License, or (at your option)
- // any later version.
- //
- // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
- // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
- // details.
- //
- // You should have received a copy of the GNU Affero General Public License
- // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
- //
- // Alternative licensing terms are available from the licensor.
- // For commercial licensing, see <https://www.artifex.com/> or contact
- // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
- // CA 94129, USA, for further information.
- #include "mupdf/fitz.h"
- #include "draw-imp.h"
- #include "glyph-imp.h"
- #include "pixmap-imp.h"
- #include <string.h>
- #include <assert.h>
- /*
- The functions in this file implement various flavours of Porter-Duff blending.
- We take the following as definitions:
- Cx = Color (from plane x)
- ax = Alpha (from plane x)
- cx = Cx.ax = Premultiplied color (from plane x)
- The general PorterDuff blending equation is:
- Blend Z = X op Y cz = Fx.cx + Fy.cy where Fx and Fy depend on op
- The two operations we use in this file are: '(X in Y) over Z' and
- 'S over Z'. The definitions of the 'over' and 'in' operations are as
- follows:
- For S over Z, Fs = 1, Fz = 1-as
- For X in Y, Fx = ay, Fy = 0
- We have 2 choices; we can either work with premultiplied data, or non
- premultiplied data. Our
- First the premultiplied case:
- Let S = (X in Y)
- Let R = (X in Y) over Z = S over Z
- cs = cx.Fx + cy.Fy (where Fx = ay, Fy = 0)
- = cx.ay
- as = ax.Fx + ay.Fy
- = ax.ay
- cr = cs.Fs + cz.Fz (where Fs = 1, Fz = 1-as)
- = cs + cz.(1-as)
- = cx.ay + cz.(1-ax.ay)
- ar = as.Fs + az.Fz
- = as + az.(1-as)
- = ax.ay + az.(1-ax.ay)
- This has various nice properties, like not needing any divisions, and
- being symmetric in color and alpha, so this is what we use. Because we
- went through the pain of deriving the non premultiplied forms, we list
- them here too, though they are not used.
- Non Pre-multiplied case:
- Cs.as = Fx.Cx.ax + Fy.Cy.ay (where Fx = ay, Fy = 0)
- = Cx.ay.ax
- Cs = (Cx.ay.ax)/(ay.ax)
- = Cx
- Cr.ar = Fs.Cs.as + Fz.Cz.az (where Fs = 1, Fz = 1-as)
- = Cs.as + (1-as).Cz.az
- = Cx.ax.ay + Cz.az.(1-ax.ay)
- Cr = (Cx.ax.ay + Cz.az.(1-ax.ay))/(ax.ay + az.(1-ax.ay))
- Much more complex, it seems. However, if we could restrict ourselves to
- the case where we were always plotting onto an opaque background (i.e.
- az = 1), then:
- Cr = Cx.(ax.ay) + Cz.(1-ax.ay)
- = (Cx-Cz)*(1-ax.ay) + Cz (a single MLA operation)
- ar = 1
- Sadly, this is not true in the general case, so we abandon this effort
- and stick to using the premultiplied form.
- */
- typedef unsigned char byte;
- /* These are used by the non-aa scan converter */
- static fz_forceinline void
- template_solid_color_1_da(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da)
- {
- int sa = FZ_EXPAND(color[1]);
- TRACK_FN();
- if (sa == 0)
- return;
- if (sa == 256)
- {
- do
- {
- dp[0] = color[0];
- dp[1] = 255;
- dp += 2;
- }
- while (--w);
- }
- else
- {
- do
- {
- dp[0] = FZ_BLEND(color[0], dp[0], sa);
- dp[1] = FZ_BLEND(255, dp[1], sa);
- dp += 2;
- }
- while (--w);
- }
- }
- static inline int isbigendian(void)
- {
- union { int i; char c[sizeof(int)]; } u = {1};
- return u.c[0] != 1;
- }
- static fz_forceinline void
- template_solid_color_3_da(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da)
- {
- unsigned int rgba = *(int *)color;
- int sa = FZ_EXPAND(color[3]);
- TRACK_FN();
- if (sa == 0)
- return;
- if (isbigendian())
- rgba |= 0x000000FF;
- else
- rgba |= 0xFF000000;
- if (sa == 256)
- {
- do
- {
- *(unsigned int *)dp = rgba;
- dp += 4;
- }
- while (--w);
- }
- else
- {
- unsigned int mask = 0xFF00FF00;
- unsigned int rb = rgba & (mask>>8);
- unsigned int ga = (rgba & mask)>>8;
- do
- {
- unsigned int RGBA = *(unsigned int *)dp;
- unsigned int RB = (RGBA<<8) & mask;
- unsigned int GA = RGBA & mask;
- RB += (rb-(RB>>8))*sa;
- GA += (ga-(GA>>8))*sa;
- RB &= mask;
- GA &= mask;
- *(unsigned int *)dp = (RB>>8) | GA;
- dp += 4;
- }
- while (--w);
- }
- }
- static fz_forceinline void
- template_solid_color_4_da(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da)
- {
- int sa = FZ_EXPAND(color[4]);
- TRACK_FN();
- if (sa == 0)
- return;
- if (sa == 256)
- {
- #ifdef ARCH_UNALIGNED_OK
- if (w > 4)
- {
- if (isbigendian())
- {
- const uint32_t a = *(uint32_t*)color;
- const uint32_t b = 0xFF000000|(a>>8);
- const uint32_t c = 0x00FF0000|(a>>16)|(a<<24);
- const uint32_t d = 0x0000FF00|(a>>24)|(a<<16);
- const uint32_t e = 0x000000FF|(a<<8);
- w -= 3;
- do
- {
- ((uint32_t *)(void *)dp)[0] = a;
- ((uint32_t *)(void *)dp)[1] = b;
- ((uint32_t *)(void *)dp)[2] = c;
- ((uint32_t *)(void *)dp)[3] = d;
- ((uint32_t *)(void *)dp)[4] = e;
- dp += 20;
- w -= 4;
- }
- while (w > 0);
- }
- else
- {
- const uint32_t a = *(uint32_t*)color;
- const uint32_t b = 0x000000FF|(a<<8);
- const uint32_t c = 0x0000FF00|(a<<16)|(a>>24);
- const uint32_t d = 0x00FF0000|(a<<24)|(a>>16);
- const uint32_t e = 0xFF000000|(a>>8);
- w -= 3;
- do
- {
- ((uint32_t *)(void *)dp)[0] = a;
- ((uint32_t *)(void *)dp)[1] = b;
- ((uint32_t *)(void *)dp)[2] = c;
- ((uint32_t *)(void *)dp)[3] = d;
- ((uint32_t *)(void *)dp)[4] = e;
- dp += 20;
- w -= 4;
- }
- while (w > 0);
- }
- w += 3;
- if (w == 0)
- return;
- }
- #endif
- do
- {
- dp[0] = color[0];
- dp[1] = color[1];
- dp[2] = color[2];
- dp[3] = color[3];
- dp[4] = 255;
- dp += 5;
- }
- while (--w);
- }
- else
- {
- do
- {
- dp[0] = FZ_BLEND(color[0], dp[0], sa);
- dp[1] = FZ_BLEND(color[1], dp[1], sa);
- dp[2] = FZ_BLEND(color[2], dp[2], sa);
- dp[3] = FZ_BLEND(color[3], dp[3], sa);
- dp[4] = FZ_BLEND(255, dp[5], sa);
- dp += 5;
- }
- while (--w);
- }
- }
- static fz_forceinline void
- template_solid_color_N_256(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da)
- {
- int k;
- int n1 = n - da;
- if (n == 3 && da == 0 && w >= 7)
- {
- union {uint32_t w[3]; byte b[12];} u;
- u.b[0] = u.b[3] = u.b[6] = u.b[9] = color[0];
- u.b[1] = u.b[4] = u.b[7] = u.b[10] = color[1];
- u.b[2] = u.b[5] = u.b[8] = u.b[11] = color[2];
- switch (((intptr_t)dp) & 3)
- {
- case 3:
- *dp++ = color[0];
- *(uint32_t *)dp = u.w[1];
- dp += 4;
- *(uint32_t *)dp = u.w[2];
- dp += 4;
- w -= 3;
- break;
- case 2:
- *dp++ = color[0];
- *dp++ = color[1];
- *(uint32_t *)dp = u.w[2];
- dp += 4;
- w -= 2;
- break;
- case 1:
- *dp++ = color[0];
- *dp++ = color[1];
- *dp++ = color[2];
- w -= 1;
- break;
- }
- w -= 4;
- do
- {
- *(uint32_t *)dp = u.w[0];
- dp += 4;
- *(uint32_t *)dp = u.w[1];
- dp += 4;
- *(uint32_t *)dp = u.w[2];
- dp += 4;
- w -= 4;
- }
- while (w > 0);
- w += 4;
- if (w == 0)
- return;
- }
- do
- {
- dp[0] = color[0];
- if (n1 > 1)
- dp[1] = color[1];
- if (n1 > 2)
- dp[2] = color[2];
- for (k = 3; k < n1; k++)
- dp[k] = color[k];
- if (da)
- dp[n1] = 255;
- dp += n;
- }
- while (--w);
- }
- static fz_forceinline void
- template_solid_color_N_256_op(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- int k;
- int n1 = n - da;
- do
- {
- if (fz_overprint_component(eop, 0))
- dp[0] = color[0];
- if (n1 > 1)
- if (fz_overprint_component(eop, 1))
- dp[1] = color[1];
- if (n1 > 2)
- if (fz_overprint_component(eop, 2))
- dp[2] = color[2];
- for (k = 3; k < n1; k++)
- if (fz_overprint_component(eop, k))
- dp[k] = color[k];
- if (da)
- dp[n1] = 255;
- dp += n;
- }
- while (--w);
- }
- static fz_forceinline void
- template_solid_color_N_sa(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, int sa)
- {
- int k;
- int n1 = n - da;
- do
- {
- for (k = 0; k < n1; k++)
- dp[k] = FZ_BLEND(color[k], dp[k], sa);
- if (da)
- dp[k] = FZ_BLEND(255, dp[k], sa);
- dp += n;
- }
- while (--w);
- }
- static fz_forceinline void
- template_solid_color_N_sa_op(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, int sa, const fz_overprint * FZ_RESTRICT eop)
- {
- int k;
- int n1 = n - da;
- do
- {
- for (k = 0; k < n1; k++)
- if (fz_overprint_component(eop, k))
- dp[k] = FZ_BLEND(color[k], dp[k], sa);
- if (da)
- dp[k] = FZ_BLEND(255, dp[k], sa);
- dp += n;
- }
- while (--w);
- }
- #if FZ_PLOTTERS_N
- static fz_forceinline void
- template_solid_color_N_general(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, int sa)
- {
- int k;
- int n1 = n - da;
- if (sa == 256)
- {
- do
- {
- dp[0] = color[0];
- if (n1 > 1)
- dp[1] = color[1];
- if (n1 > 2)
- dp[2] = color[2];
- for (k = 3; k < n1; k++)
- dp[k] = color[k];
- if (da)
- dp[n1] = 255;
- dp += n;
- }
- while (--w);
- }
- else
- {
- do
- {
- for (k = 0; k < n1; k++)
- dp[k] = FZ_BLEND(color[k], dp[k], sa);
- if (da)
- dp[k] = FZ_BLEND(255, dp[k], sa);
- dp += n;
- }
- while (--w);
- }
- }
- static fz_forceinline void
- template_solid_color_N_general_op(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, int sa, const fz_overprint * FZ_RESTRICT eop)
- {
- int k;
- int n1 = n - da;
- if (sa == 256)
- {
- do
- {
- if (fz_overprint_component(eop, 0))
- dp[0] = color[0];
- if (n1 > 1)
- if (fz_overprint_component(eop, 1))
- dp[1] = color[1];
- if (n1 > 2)
- if (fz_overprint_component(eop, 2))
- dp[2] = color[2];
- for (k = 3; k < n1; k++)
- if (fz_overprint_component(eop, k))
- dp[k] = color[k];
- if (da)
- dp[n1] = 255;
- dp += n;
- }
- while (--w);
- }
- else
- {
- do
- {
- for (k = 0; k < n1; k++)
- if (fz_overprint_component(eop, k))
- dp[k] = FZ_BLEND(color[k], dp[k], sa);
- if (da)
- dp[k] = FZ_BLEND(255, dp[k], sa);
- dp += n;
- }
- while (--w);
- }
- }
- #endif
- static fz_forceinline void
- template_solid_color_0_da(byte * FZ_RESTRICT dp, int w, int sa)
- {
- if (sa == 256)
- {
- memset(dp, 255, w);
- }
- else
- {
- do
- {
- *dp = FZ_BLEND(255, *dp, sa);
- dp++;
- }
- while (--w);
- }
- }
- #if FZ_PLOTTERS_G
- static void paint_solid_color_1_alpha(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_solid_color_N_sa(dp, 1, w, color, 0, FZ_EXPAND(color[1]));
- }
- static void paint_solid_color_1(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_solid_color_N_256(dp, 1, w, color, 0);
- }
- static void paint_solid_color_1_da(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_solid_color_1_da(dp, 2, w, color, 1);
- }
- #endif /* FZ_PLOTTERS_G */
- static void paint_solid_color_0_da(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_solid_color_0_da(dp, w, 256);
- }
- #if FZ_PLOTTERS_RGB
- static void paint_solid_color_3_alpha(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_solid_color_N_sa(dp, 3, w, color, 0, FZ_EXPAND(color[3]));
- }
- static void paint_solid_color_3(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_solid_color_N_256(dp, 3, w, color, 0);
- }
- static void paint_solid_color_3_da(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_solid_color_3_da(dp, 4, w, color, 1);
- }
- #endif /* FZ_PLOTTERS_RGB */
- #if FZ_PLOTTERS_CMYK
- static void paint_solid_color_4_alpha(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_solid_color_N_sa(dp, 4, w, color, 0, FZ_EXPAND(color[4]));
- }
- static void paint_solid_color_4(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_solid_color_N_256(dp, 4, w, color, 0);
- }
- static void paint_solid_color_4_da(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_solid_color_4_da(dp, 5, w, color, 1);
- }
- #endif /* FZ_PLOTTERS_CMYK */
- #if FZ_PLOTTERS_N
- static void paint_solid_color_N_alpha(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_solid_color_N_sa(dp, n, w, color, 0, FZ_EXPAND(color[n]));
- }
- static void paint_solid_color_N(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_solid_color_N_256(dp, n, w, color, 0);
- }
- static void paint_solid_color_N_da(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_solid_color_N_general(dp, n, w, color, 1, FZ_EXPAND(color[n-1]));
- }
- #endif /* FZ_PLOTTERS_N */
- #if FZ_ENABLE_SPOT_RENDERING
- static void paint_solid_color_N_alpha_op(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_solid_color_N_sa_op(dp, n, w, color, 0, FZ_EXPAND(color[n]), eop);
- }
- static void paint_solid_color_N_op(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_solid_color_N_256_op(dp, n, w, color, 0, eop);
- }
- static void paint_solid_color_N_da_op(byte * FZ_RESTRICT dp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_solid_color_N_general_op(dp, n, w, color, 1, FZ_EXPAND(color[n-1]), eop);
- }
- #endif /* FZ_ENABLE_SPOT_RENDERING */
- fz_solid_color_painter_t *
- fz_get_solid_color_painter(int n, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- #if FZ_ENABLE_SPOT_RENDERING
- if (fz_overprint_required(eop))
- {
- if (da)
- return paint_solid_color_N_da_op;
- else if (color[n] == 255)
- return paint_solid_color_N_op;
- else
- return paint_solid_color_N_alpha_op;
- }
- #endif /* FZ_ENABLE_SPOT_RENDERING */
- switch (n-da)
- {
- case 0:
- return paint_solid_color_0_da;
- #if FZ_PLOTTERS_G
- case 1:
- if (da)
- return paint_solid_color_1_da;
- else if (color[1] == 255)
- return paint_solid_color_1;
- else
- return paint_solid_color_1_alpha;
- #endif /* FZ_PLOTTERS_G */
- #if FZ_PLOTTERS_RGB
- case 3:
- if (da)
- return paint_solid_color_3_da;
- else if (color[3] == 255)
- return paint_solid_color_3;
- else
- return paint_solid_color_3_alpha;
- #endif /* FZ_PLOTTERS_RGB */
- #if FZ_PLOTTERS_CMYK
- case 4:
- if (da)
- return paint_solid_color_4_da;
- else if (color[4] == 255)
- return paint_solid_color_4;
- else
- return paint_solid_color_4_alpha;
- #endif /* FZ_PLOTTERS_CMYK */
- default:
- #if FZ_PLOTTERS_N
- if (da)
- return paint_solid_color_N_da;
- else if (color[n] == 255)
- return paint_solid_color_N;
- else
- return paint_solid_color_N_alpha;
- #else
- return NULL;
- #endif /* FZ_PLOTTERS_N */
- }
- }
- /* Blend a non-premultiplied color in mask over destination */
- static fz_forceinline void
- template_span_with_color_1_da_solid(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da)
- {
- int g = color[0];
- do
- {
- int ma = *mp++;
- ma = FZ_EXPAND(ma);
- if (ma == 256)
- {
- dp[0] = g;
- dp[1] = 255;
- }
- else if (ma != 0)
- {
- dp[0] = FZ_BLEND(g, dp[0], ma);
- dp[1] = FZ_BLEND(255, dp[1], ma);
- }
- dp += 2;
- }
- while (--w);
- }
- static fz_forceinline void
- template_span_with_color_1_da_alpha(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da)
- {
- int sa = FZ_EXPAND(color[1]);
- int g = color[0];
- do
- {
- int ma = *mp++;
- ma = FZ_EXPAND(ma);
- if (ma != 0)
- {
- ma = FZ_COMBINE(ma, sa);
- dp[0] = FZ_BLEND(g, dp[0], ma);
- dp[1] = FZ_BLEND(255, dp[1], ma);
- }
- dp += 2;
- }
- while (--w);
- }
- static fz_forceinline void
- template_span_with_color_3_da_solid(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da)
- {
- unsigned int rgba = *((const unsigned int *)color);
- unsigned int mask, rb, ga;
- if (isbigendian())
- rgba |= 0x000000FF;
- else
- rgba |= 0xFF000000;
- mask = 0xFF00FF00;
- rb = rgba & (mask>>8);
- ga = (rgba & mask)>>8;
- do
- {
- unsigned int ma = *mp++;
- dp += 4;
- ma = FZ_EXPAND(ma);
- if (ma == 256)
- {
- ((unsigned int *)dp)[-1] = rgba;
- }
- else if (ma != 0)
- {
- unsigned int RGBA = ((unsigned int *)dp)[-1];
- unsigned int RB = (RGBA<<8) & mask;
- unsigned int GA = RGBA & mask;
- RB += (rb-(RB>>8))*ma;
- GA += (ga-(GA>>8))*ma;
- RB &= mask;
- GA &= mask;
- ((unsigned int *)dp)[-1] = (RB>>8) | GA;
- }
- }
- while (--w);
- }
- static fz_forceinline void
- template_span_with_color_3_da_alpha(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da)
- {
- unsigned int rgba = *((const unsigned int *)color);
- unsigned int mask, rb, ga;
- int sa = FZ_EXPAND(color[3]);
- if (isbigendian())
- rgba |= 0x000000FF;
- else
- rgba |= 0xFF000000;
- mask = 0xFF00FF00;
- rb = rgba & (mask>>8);
- ga = (rgba & mask)>>8;
- do
- {
- unsigned int ma = *mp++;
- ma = FZ_COMBINE(FZ_EXPAND(ma), sa);
- dp += 4;
- if (ma != 0)
- {
- unsigned int RGBA = ((unsigned int*)dp)[-1];
- unsigned int RB = (RGBA<<8) & mask;
- unsigned int GA = RGBA & mask;
- RB += (rb-(RB>>8))*ma;
- GA += (ga-(GA>>8))*ma;
- RB &= mask;
- GA &= mask;
- ((unsigned int *)dp)[-1] = (RB>>8) | GA;
- }
- }
- while (--w);
- }
- static fz_forceinline void
- template_span_with_color_4_da_solid(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da)
- {
- int c = color[0];
- int m = color[1];
- int y = color[2];
- int k = color[3];
- TRACK_FN();
- do
- {
- int ma = *mp++;
- ma = FZ_EXPAND(ma);
- if (ma == 256)
- {
- dp[0] = c;
- dp[1] = m;
- dp[2] = y;
- dp[3] = k;
- dp[4] = 255;
- }
- else if (ma != 0)
- {
- dp[0] = FZ_BLEND(c, dp[0], ma);
- dp[1] = FZ_BLEND(m, dp[1], ma);
- dp[2] = FZ_BLEND(y, dp[2], ma);
- dp[3] = FZ_BLEND(k, dp[3], ma);
- dp[4] = FZ_BLEND(255, dp[4], ma);
- }
- dp += 5;
- }
- while (--w);
- }
- static fz_forceinline void
- template_span_with_color_4_da_alpha(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da)
- {
- int sa = FZ_EXPAND(color[4]);
- int c = color[0];
- int m = color[1];
- int y = color[2];
- int k = color[3];
- TRACK_FN();
- do
- {
- int ma = *mp++;
- ma = FZ_EXPAND(ma);
- if (ma != 0)
- {
- ma = FZ_COMBINE(ma, sa);
- dp[0] = FZ_BLEND(c, dp[0], ma);
- dp[1] = FZ_BLEND(m, dp[1], ma);
- dp[2] = FZ_BLEND(y, dp[2], ma);
- dp[3] = FZ_BLEND(k, dp[3], ma);
- dp[4] = FZ_BLEND(255, dp[4], ma);
- }
- dp += 5;
- }
- while (--w);
- }
- static fz_forceinline void
- template_span_with_color_N_general_solid(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da)
- {
- int k;
- int n1 = n - da;
- do
- {
- int ma = *mp++;
- ma = FZ_EXPAND(ma);
- if (ma == 256)
- {
- if (n1 > 0)
- dp[0] = color[0];
- if (n1 > 1)
- dp[1] = color[1];
- if (n1 > 2)
- dp[2] = color[2];
- for (k = 3; k < n1; k++)
- dp[k] = color[k];
- if (da)
- dp[n1] = 255;
- }
- else if (ma != 0)
- {
- if (n1 > 0)
- dp[0] = FZ_BLEND(color[0], dp[0], ma);
- if (n1 > 1)
- dp[1] = FZ_BLEND(color[1], dp[1], ma);
- if (n1 > 2)
- dp[2] = FZ_BLEND(color[2], dp[2], ma);
- for (k = 3; k < n1; k++)
- dp[k] = FZ_BLEND(color[k], dp[k], ma);
- if (da)
- dp[n1] = FZ_BLEND(255, dp[n1], ma);
- }
- dp += n;
- }
- while (--w);
- }
- static fz_forceinline void
- template_span_with_color_N_general_alpha(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da)
- {
- int k;
- int n1 = n - da;
- int sa = FZ_EXPAND(color[n1]);
- do
- {
- int ma = *mp++;
- ma = FZ_COMBINE(FZ_EXPAND(ma), sa);
- if (n1 > 0)
- dp[0] = FZ_BLEND(color[0], dp[0], ma);
- if (n1 > 1)
- dp[1] = FZ_BLEND(color[1], dp[1], ma);
- if (n1 > 2)
- dp[2] = FZ_BLEND(color[2], dp[2], ma);
- for (k = 3; k < n1; k++)
- dp[k] = FZ_BLEND(color[k], dp[k], ma);
- if (da)
- dp[n1] = FZ_BLEND(255, dp[n1], ma);
- dp += n;
- }
- while (--w);
- }
- static fz_forceinline void
- template_span_with_color_N_general_op_solid(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- int k;
- int n1 = n - da;
- do
- {
- int ma = *mp++;
- ma = FZ_EXPAND(ma);
- if (ma == 256)
- {
- if (n1 > 0)
- if (fz_overprint_component(eop, 0))
- dp[0] = color[0];
- if (n1 > 1)
- if (fz_overprint_component(eop, 1))
- dp[1] = color[1];
- if (n1 > 2)
- if (fz_overprint_component(eop, 2))
- dp[2] = color[2];
- for (k = 3; k < n1; k++)
- if (fz_overprint_component(eop, k))
- dp[k] = color[k];
- if (da)
- dp[n1] = 255;
- }
- else if (ma != 0)
- {
- for (k = 0; k < n1; k++)
- if (fz_overprint_component(eop, k))
- dp[k] = FZ_BLEND(color[k], dp[k], ma);
- if (da)
- dp[n1] = FZ_BLEND(255, dp[k], ma);
- }
- dp += n;
- }
- while (--w);
- }
- static fz_forceinline void
- template_span_with_color_N_general_op_alpha(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- int k;
- int n1 = n - da;
- int sa = FZ_EXPAND(color[n1]);
- do
- {
- int ma = *mp++;
- ma = FZ_COMBINE(FZ_EXPAND(ma), sa);
- for (k = 0; k < n1; k++)
- if (fz_overprint_component(eop, k))
- dp[k] = FZ_BLEND(color[k], dp[k], ma);
- if (da)
- dp[k] = FZ_BLEND(255, dp[k], ma);
- dp += n;
- }
- while (--w);
- }
- static void
- paint_span_with_color_0_da_solid(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_N_general_solid(dp, mp, 1, w, color, 1);
- }
- static void
- paint_span_with_color_0_da_alpha(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_N_general_alpha(dp, mp, 1, w, color, 1);
- }
- static void
- paint_span_with_color_1_solid(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_N_general_solid(dp, mp, 1, w, color, 0);
- }
- static void
- paint_span_with_color_1_alpha(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_N_general_alpha(dp, mp, 1, w, color, 0);
- }
- static void
- paint_span_with_color_1_da_solid(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_1_da_solid(dp, mp, 2, w, color, 1);
- }
- static void
- paint_span_with_color_1_da_alpha(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_1_da_alpha(dp, mp, 2, w, color, 1);
- }
- #if FZ_PLOTTERS_RGB
- static void
- paint_span_with_color_3_solid(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_N_general_solid(dp, mp, 3, w, color, 0);
- }
- static void
- paint_span_with_color_3_da_solid(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_3_da_solid(dp, mp, 4, w, color, 1);
- }
- static void
- paint_span_with_color_3_alpha(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_N_general_alpha(dp, mp, 3, w, color, 0);
- }
- static void
- paint_span_with_color_3_da_alpha(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_3_da_alpha(dp, mp, 4, w, color, 1);
- }
- #endif /* FZ_PLOTTERS_RGB */
- #if FZ_PLOTTERS_CMYK
- static void
- paint_span_with_color_4_solid(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_N_general_solid(dp, mp, 4, w, color, 0);
- }
- static void
- paint_span_with_color_4_alpha(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_N_general_alpha(dp, mp, 4, w, color, 0);
- }
- static void
- paint_span_with_color_4_da_solid(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_4_da_solid(dp, mp, 5, w, color, 1);
- }
- static void
- paint_span_with_color_4_da_alpha(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_4_da_alpha(dp, mp, 5, w, color, 1);
- }
- #endif /* FZ_PLOTTERS_CMYK */
- #if FZ_PLOTTERS_N
- static void
- paint_span_with_color_N_solid(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_N_general_solid(dp, mp, n, w, color, 0);
- }
- static void
- paint_span_with_color_N_alpha(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_N_general_alpha(dp, mp, n, w, color, 0);
- }
- static void
- paint_span_with_color_N_da_solid(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_N_general_solid(dp, mp, n, w, color, 1);
- }
- static void
- paint_span_with_color_N_da_alpha(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_N_general_alpha(dp, mp, n, w, color, 1);
- }
- #endif /* FZ_PLOTTERS_N */
- #if FZ_ENABLE_SPOT_RENDERING
- static void
- paint_span_with_color_N_op_solid(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_N_general_op_solid(dp, mp, n, w, color, 0, eop);
- }
- static void
- paint_span_with_color_N_op_alpha(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_N_general_op_alpha(dp, mp, n, w, color, 0, eop);
- }
- static void
- paint_span_with_color_N_da_op_solid(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_N_general_op_solid(dp, mp, n, w, color, 1, eop);
- }
- static void
- paint_span_with_color_N_da_op_alpha(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT mp, int n, int w, const byte * FZ_RESTRICT color, int da, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_color_N_general_op_alpha(dp, mp, n, w, color, 1, eop);
- }
- #endif /* FZ_ENABLE_SPOT_RENDERING */
- fz_span_color_painter_t *
- fz_get_span_color_painter(int n, int da, const byte * FZ_RESTRICT color, const fz_overprint * FZ_RESTRICT eop)
- {
- byte alpha = color[n-da];
- if (alpha == 0)
- return NULL;
- #if FZ_ENABLE_SPOT_RENDERING
- if (fz_overprint_required(eop))
- {
- if (alpha == 255)
- return da ? paint_span_with_color_N_da_op_solid : paint_span_with_color_N_op_solid;
- else
- return da ? paint_span_with_color_N_da_op_alpha : paint_span_with_color_N_op_alpha;
- }
- #endif /* FZ_ENABLE_SPOT_RENDERING */
- switch(n-da)
- {
- case 0:
- if (alpha == 255)
- return da ? paint_span_with_color_0_da_solid : NULL;
- else
- return da ? paint_span_with_color_0_da_alpha : NULL;
- case 1:
- if (alpha == 255)
- return da ? paint_span_with_color_1_da_solid : paint_span_with_color_1_solid;
- else
- return da ? paint_span_with_color_1_da_alpha : paint_span_with_color_1_alpha;
- #if FZ_PLOTTERS_RGB
- case 3:
- if (alpha == 255)
- return da ? paint_span_with_color_3_da_solid : paint_span_with_color_3_solid;
- else
- return da ? paint_span_with_color_3_da_alpha : paint_span_with_color_3_alpha;
- #endif/* FZ_PLOTTERS_RGB */
- #if FZ_PLOTTERS_CMYK
- case 4:
- if (alpha == 255)
- return da ? paint_span_with_color_4_da_solid : paint_span_with_color_4_solid;
- else
- return da ? paint_span_with_color_4_da_alpha : paint_span_with_color_4_alpha;
- #endif/* FZ_PLOTTERS_CMYK */
- #if FZ_PLOTTERS_N
- default:
- if (alpha == 255)
- return da ? paint_span_with_color_N_da_solid : paint_span_with_color_N_solid;
- else
- return da ? paint_span_with_color_N_da_alpha : paint_span_with_color_N_alpha;
- #else
- default: return NULL;
- #endif /* FZ_PLOTTERS_N */
- }
- }
- /* Blend source in mask over destination */
- /* FIXME: There is potential for SWAR optimisation here */
- static fz_forceinline void
- template_span_with_mask_1_general(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT sp, int a, const byte * FZ_RESTRICT mp, int w)
- {
- do
- {
- int ma = *mp++;
- ma = FZ_EXPAND(ma);
- if (ma == 0 || (a && sp[1] == 0))
- {
- dp += 1 + a;
- sp += 1 + a;
- }
- else if (ma == 256)
- {
- *dp++ = *sp++;
- if (a)
- *dp++ = *sp++;
- }
- else
- {
- *dp = FZ_BLEND(*sp, *dp, ma);
- sp++; dp++;
- if (a)
- {
- *dp = FZ_BLEND(*sp, *dp, ma);
- sp++; dp++;
- }
- }
- }
- while (--w);
- }
- static fz_forceinline void
- template_span_with_mask_3_general(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT sp, int a, const byte * FZ_RESTRICT mp, int w)
- {
- do
- {
- int ma = *mp++;
- ma = FZ_EXPAND(ma);
- if (ma == 0 || (a && sp[3] == 0))
- {
- dp += 3 + a;
- sp += 3 + a;
- }
- else if (ma == 256)
- {
- if (a)
- {
- *(int32_t *)dp = *(int32_t *)sp;
- sp += 4; dp += 4;
- }
- else
- {
- *dp++ = *sp++;
- *dp++ = *sp++;
- *dp++ = *sp++;
- }
- }
- else if (a)
- {
- const uint32_t mask = 0x00ff00ff;
- uint32_t d0 = *(uint32_t *)dp;
- uint32_t d1 = d0>>8;
- uint32_t s0 = *(uint32_t *)sp;
- uint32_t s1 = s0>>8;
- d0 &= mask;
- d1 &= mask;
- s0 &= mask;
- s1 &= mask;
- d0 = (((d0<<8) + (s0-d0)*ma)>>8) & mask;
- d1 = ((d1<<8) + (s1-d1)*ma) & ~mask;
- d0 |= d1;
- #ifndef NDEBUG
- if (isbigendian())
- {
- assert((d0 & 0xff) >= (d0>>24));
- assert((d0 & 0xff) >= ((d0>>16) & 0xff));
- assert((d0 & 0xff) >= ((d0>>8) & 0xff));
- }
- else
- {
- assert((d0>>24) >= (d0 & 0xff));
- assert((d0>>24) >= ((d0>>8) & 0xff));
- assert((d0>>24) >= ((d0>>16) & 0xff));
- }
- #endif
- *(uint32_t *)dp = d0;
- sp += 4;
- dp += 4;
- }
- else
- {
- *dp = FZ_BLEND(*sp, *dp, ma);
- sp++; dp++;
- *dp = FZ_BLEND(*sp, *dp, ma);
- sp++; dp++;
- *dp = FZ_BLEND(*sp, *dp, ma);
- sp++; dp++;
- }
- }
- while (--w);
- }
- static fz_forceinline void
- template_span_with_mask_4_general(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT sp, int a, const byte * FZ_RESTRICT mp, int w)
- {
- do
- {
- int ma = *mp++;
- ma = FZ_EXPAND(ma);
- if (ma == 0 || (a && sp[4] == 0))
- {
- dp += 4 + a;
- sp += 4 + a;
- }
- else if (ma == 256)
- {
- if (!a)
- {
- *(uint32_t *)dp = *(uint32_t *)sp;
- dp += 4;
- sp += 4;
- }
- else
- {
- *dp++ = *sp++;
- *dp++ = *sp++;
- *dp++ = *sp++;
- *dp++ = *sp++;
- *dp++ = *sp++;
- }
- }
- else if (a)
- {
- *dp = FZ_BLEND(*sp, *dp, ma);
- sp++; dp++;
- *dp = FZ_BLEND(*sp, *dp, ma);
- sp++; dp++;
- *dp = FZ_BLEND(*sp, *dp, ma);
- sp++; dp++;
- *dp = FZ_BLEND(*sp, *dp, ma);
- sp++; dp++;
- *dp = FZ_BLEND(*sp, *dp, ma);
- sp++; dp++;
- }
- else
- {
- const uint32_t mask = 0x00ff00ff;
- uint32_t d0 = *(uint32_t *)dp;
- uint32_t d1 = d0>>8;
- uint32_t s0 = *(uint32_t *)sp;
- uint32_t s1 = s0>>8;
- sp += 4;
- d0 &= mask;
- d1 &= mask;
- s0 &= mask;
- s1 &= mask;
- d0 = (((d0<<8) + (s0-d0)*ma)>>8) & mask;
- d1 = ((d1<<8) + (s1-d1)*ma) & ~mask;
- d0 |= d1;
- *(uint32_t *)dp = d0;
- dp += 4;
- }
- }
- while (--w);
- }
- static fz_forceinline void
- template_span_with_mask_N_general(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT sp, int a, const byte * FZ_RESTRICT mp, int n, int w)
- {
- do
- {
- int ma = *mp++;
- ma = FZ_EXPAND(ma);
- if (ma == 0 || (a && sp[n] == 0))
- {
- dp += n + a;
- sp += n + a;
- }
- else if (ma == 256)
- {
- int k;
- for (k = 0; k < n; k++)
- *dp++ = *sp++;
- if (a)
- *dp++ = *sp++;
- }
- else
- {
- int k;
- for (k = 0; k < n; k++)
- {
- *dp = FZ_BLEND(*sp, *dp, ma);
- sp++; dp++;
- }
- if (a)
- {
- *dp = FZ_BLEND(*sp, *dp, ma);
- sp++; dp++;
- }
- }
- }
- while (--w);
- }
- static void
- paint_span_with_mask_0_a(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT sp, const byte * FZ_RESTRICT mp, int w, int n, int a, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_mask_N_general(dp, sp, 1, mp, 0, w);
- }
- static void
- paint_span_with_mask_1_a(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT sp, const byte * FZ_RESTRICT mp, int w, int n, int a, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_mask_1_general(dp, sp, 1, mp, w);
- }
- static void
- paint_span_with_mask_1(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT sp, const byte * FZ_RESTRICT mp, int w, int n, int a, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_mask_1_general(dp, sp, 0, mp, w);
- }
- #if FZ_PLOTTERS_RGB
- static void
- paint_span_with_mask_3_a(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT sp, const byte * FZ_RESTRICT mp, int w, int n, int a, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_mask_3_general(dp, sp, 1, mp, w);
- }
- static void
- paint_span_with_mask_3(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT sp, const byte * FZ_RESTRICT mp, int w, int n, int a, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_mask_3_general(dp, sp, 0, mp, w);
- }
- #endif /* FZ_PLOTTERS_RGB */
- #if FZ_PLOTTERS_CMYK
- static void
- paint_span_with_mask_4_a(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT sp, const byte * FZ_RESTRICT mp, int w, int n, int a, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_mask_4_general(dp, sp, 1, mp, w);
- }
- static void
- paint_span_with_mask_4(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT sp, const byte * FZ_RESTRICT mp, int w, int n, int a, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_mask_4_general(dp, sp, 0, mp, w);
- }
- #endif /* FZ_PLOTTERS_CMYK */
- #if FZ_PLOTTERS_N
- static void
- paint_span_with_mask_N_a(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT sp, const byte * FZ_RESTRICT mp, int w, int n, int a, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_mask_N_general(dp, sp, 1, mp, n, w);
- }
- static void
- paint_span_with_mask_N(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT sp, const byte * FZ_RESTRICT mp, int w, int n, int a, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_with_mask_N_general(dp, sp, 0, mp, n, w);
- }
- #endif /* FZ_PLOTTERS_N */
- typedef void (fz_span_mask_painter_t)(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT sp, const byte * FZ_RESTRICT mp, int w, int n, int a, const fz_overprint * FZ_RESTRICT eop);
- static fz_span_mask_painter_t *
- fz_get_span_mask_painter(int a, int n)
- {
- switch(n)
- {
- case 0:
- /* assert(a); */
- return paint_span_with_mask_0_a;
- case 1:
- if (a)
- return paint_span_with_mask_1_a;
- else
- return paint_span_with_mask_1;
- #if FZ_PLOTTERS_RGB
- case 3:
- if (a)
- return paint_span_with_mask_3_a;
- else
- return paint_span_with_mask_3;
- #endif /* FZ_PLOTTERS_RGB */
- #if FZ_PLOTTERS_CMYK
- case 4:
- if (a)
- return paint_span_with_mask_4_a;
- else
- return paint_span_with_mask_4;
- #endif /* FZ_PLOTTERS_CMYK */
- default:
- {
- #if FZ_PLOTTERS_N
- if (a)
- return paint_span_with_mask_N_a;
- else
- return paint_span_with_mask_N;
- #else
- return NULL;
- #endif /* FZ_PLOTTERS_N */
- }
- }
- }
- /* Blend source in constant alpha over destination */
- static fz_forceinline void
- template_span_1_with_alpha_general(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int w, int alpha)
- {
- if (sa)
- alpha = FZ_EXPAND(alpha);
- do
- {
- int masa = (sa ? FZ_COMBINE(sp[1], alpha) : alpha);
- int t = FZ_EXPAND(255-masa);
- *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
- dp++; sp++;
- if (da)
- {
- *dp = masa + FZ_COMBINE(*dp, t);
- dp++;
- }
- if (sa)
- sp++;
- }
- while (--w);
- }
- static fz_forceinline void
- template_span_3_with_alpha_general(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int w, int alpha)
- {
- if (sa)
- alpha = FZ_EXPAND(alpha);
- do
- {
- int masa = (sa ? FZ_COMBINE(sp[3], alpha) : alpha);
- int t = FZ_EXPAND(255-masa);
- *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
- sp++; dp++;
- *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
- sp++; dp++;
- *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
- sp++; dp++;
- if (da)
- {
- *dp = masa + FZ_COMBINE(*dp, t);
- dp++;
- }
- if (sa)
- sp++;
- }
- while (--w);
- }
- static fz_forceinline void
- template_span_4_with_alpha_general(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int w, int alpha)
- {
- if (sa)
- alpha = FZ_EXPAND(alpha);
- do
- {
- int masa = (sa ? FZ_COMBINE(sp[4], alpha) : alpha);
- int t = FZ_EXPAND(255-masa);
- *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
- sp++; dp++;
- *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
- sp++; dp++;
- *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
- sp++; dp++;
- *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
- sp++; dp++;
- if (da)
- {
- *dp = masa + FZ_COMBINE(*dp, t);
- dp++;
- }
- if (sa)
- sp++;
- }
- while (--w);
- }
- #if FZ_PLOTTERS_N
- static fz_forceinline void
- template_span_N_with_alpha_general(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n1, int w, int alpha)
- {
- if (sa)
- alpha = FZ_EXPAND(alpha);
- do
- {
- int masa = (sa ? FZ_COMBINE(sp[n1], alpha) : alpha);
- int t = FZ_EXPAND(255-masa);
- int k;
- for (k = 0; k < n1; k++)
- {
- *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
- sp++; dp++;
- }
- if (da)
- {
- *dp = masa + FZ_COMBINE(*dp, t);
- dp++;
- }
- if (sa)
- sp++;
- }
- while (--w);
- }
- static fz_forceinline void
- template_span_N_with_alpha_general_op(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n1, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- if (sa)
- alpha = FZ_EXPAND(alpha);
- do
- {
- int masa = (sa ? FZ_COMBINE(sp[n1], alpha) : alpha);
- int t = FZ_EXPAND(255-masa);
- int k;
- for (k = 0; k < n1; k++)
- {
- if (fz_overprint_component(eop, k))
- *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
- sp++;
- dp++;
- }
- if (da)
- {
- *dp = masa + FZ_COMBINE(*dp, t);
- dp++;
- }
- if (sa)
- sp++;
- }
- while (--w);
- }
- #endif
- /* Blend source over destination */
- static fz_forceinline void
- template_span_1_general(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int w)
- {
- do
- {
- int t = (sa ? FZ_EXPAND(sp[1]): 256);
- if (t == 0)
- {
- dp += 1 + da; sp += 1 + sa;
- }
- else
- {
- t = 256 - t;
- if (t == 0)
- {
- *dp++ = *sp++;
- if (da)
- *dp++ = (sa ? *sp : 255);
- if (sa)
- sp++;
- }
- else
- {
- *dp = *sp + FZ_COMBINE(*dp, t);
- sp++;
- dp++;
- if (da)
- {
- *dp = *sp + FZ_COMBINE(*dp, t);
- dp++;
- }
- sp++;
- }
- }
- }
- while (--w);
- }
- static fz_forceinline void
- template_span_3_general(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int w)
- {
- do
- {
- int t = (sa ? FZ_EXPAND(sp[3]) : 256);
- if (t == 0)
- {
- dp += 3 + da; sp += 3 + sa;
- }
- else
- {
- t = 256 - t;
- if (t == 0)
- {
- if (da && sa)
- *(int32_t *)dp = *(const int32_t *)sp;
- else
- {
- dp[0] = sp[0];
- dp[1] = sp[1];
- dp[2] = sp[2];
- if (da)
- dp[3] = 255;
- }
- dp += 3+da; sp += 3+sa;
- }
- else
- {
- /* sa != 0 as t != 0 */
- *dp = *sp++ + FZ_COMBINE(*dp, t);
- dp++;
- *dp = *sp++ + FZ_COMBINE(*dp, t);
- dp++;
- *dp = *sp++ + FZ_COMBINE(*dp, t);
- dp++;
- if (da)
- {
- *dp = *sp + FZ_COMBINE(*dp, t);
- dp++;
- }
- sp++;
- }
- }
- }
- while (--w);
- }
- static fz_forceinline void
- template_span_4_general(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int w)
- {
- do
- {
- int t = (sa ? FZ_EXPAND(sp[4]) : 256);
- if (t == 0)
- {
- dp += 4+da; sp += 4+sa;
- }
- else
- {
- t = 256 - t;
- if (t == 0)
- {
- dp[0] = sp[0];
- dp[1] = sp[1];
- dp[2] = sp[2];
- dp[3] = sp[3];
- if (da)
- dp[4] = (sa ? sp[4] : 255);
- dp += 4+da; sp += 4 + sa;
- }
- else
- {
- /* sa != 0 as t != 0 */
- *dp = *sp++ + FZ_COMBINE(*dp, t);
- dp++;
- *dp = *sp++ + FZ_COMBINE(*dp, t);
- dp++;
- *dp = *sp++ + FZ_COMBINE(*dp, t);
- dp++;
- *dp = *sp++ + FZ_COMBINE(*dp, t);
- dp++;
- if (da)
- {
- *dp = *sp + FZ_COMBINE(*dp, t);
- dp++;
- }
- sp++;
- }
- }
- }
- while (--w);
- }
- #if FZ_PLOTTERS_N
- static fz_forceinline void
- template_span_N_general(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n1, int w)
- {
- do
- {
- int t = (sa ? FZ_EXPAND(sp[n1]) : 256);
- if (t == 0)
- {
- dp += n1 + da; sp += n1 + sa;
- }
- else
- {
- t = 256 - t;
- if (t == 0)
- {
- int k;
- for (k = 0; k < n1; k++)
- *dp++ = *sp++;
- if (da)
- *dp++ = (sa ? *sp : 255);
- if (sa)
- sp++;
- }
- else
- {
- /* sa != 0, as t != 0 */
- int k;
- for (k = 0; k < n1; k++)
- {
- *dp = *sp + FZ_COMBINE(*dp, t);
- sp++;
- dp++;
- }
- if (da)
- {
- *dp = *sp + FZ_COMBINE(*dp, t);
- dp++;
- }
- sp++;
- }
- }
- }
- while (--w);
- }
- static fz_forceinline void
- template_span_N_general_op(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n1, int w, const fz_overprint * FZ_RESTRICT eop)
- {
- do
- {
- int t = (sa ? FZ_EXPAND(sp[n1]) : 256);
- if (t == 0)
- {
- dp += n1 + da; sp += n1 + sa;
- }
- else
- {
- t = 256 - t;
- if (t == 0)
- {
- int k;
- for (k = 0; k < n1; k++)
- {
- if (fz_overprint_component(eop, k))
- *dp = *sp;
- dp++;
- sp++;
- }
- if (da)
- *dp++ = (sa ? *sp : 255);
- if (sa)
- sp++;
- }
- else
- {
- int k;
- /* sa can never be 0 here, as t != 0. */
- for (k = 0; k < n1; k++)
- {
- if (fz_overprint_component(eop, k))
- *dp = *sp + FZ_COMBINE(*dp, t);
- sp++;
- dp++;
- }
- if (da)
- {
- *dp = *sp + FZ_COMBINE(*dp, t);
- dp++;
- }
- sp++;
- }
- }
- }
- while (--w);
- }
- #endif
- static void
- paint_span_0_da_sa(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- do
- {
- int s = *sp++;
- int t = FZ_EXPAND(255 - s);
- *dp = s + FZ_COMBINE(*dp, t);
- dp ++;
- }
- while (--w);
- }
- static void
- paint_span_0_da_sa_alpha(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- alpha = FZ_EXPAND(alpha);
- do
- {
- int masa = FZ_COMBINE(sp[0], alpha);
- int t = FZ_EXPAND(255-masa);
- *dp = masa + FZ_COMBINE(*dp, t);
- dp++;
- sp++;
- }
- while (--w);
- }
- static void
- paint_span_1_sa(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_1_general(dp, 0, sp, 1, w);
- }
- static void
- paint_span_1_sa_alpha(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_1_with_alpha_general(dp, 0, sp, 1, w, alpha);
- }
- static void
- paint_span_1_da_sa(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_1_general(dp, 1, sp, 1, w);
- }
- static void
- paint_span_1_da_sa_alpha(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_1_with_alpha_general(dp, 1, sp, 1, w, alpha);
- }
- #if FZ_PLOTTERS_G
- static void
- paint_span_1_da(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_1_general(dp, 1, sp, 0, w);
- }
- static void
- paint_span_1_da_alpha(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_1_with_alpha_general(dp, 1, sp, 0, w, alpha);
- }
- static void
- paint_span_1(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_1_general(dp, 0, sp, 0, w);
- }
- static void
- paint_span_1_alpha(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_1_with_alpha_general(dp, 0, sp, 0, w, alpha);
- }
- #endif /* FZ_PLOTTERS_G */
- #if FZ_PLOTTERS_RGB
- static void
- paint_span_3_da_sa(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_3_general(dp, 1, sp, 1, w);
- }
- static void
- paint_span_3_da_sa_alpha(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_3_with_alpha_general(dp, 1, sp, 1, w, alpha);
- }
- static void
- paint_span_3_da(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_3_general(dp, 1, sp, 0, w);
- }
- static void
- paint_span_3_da_alpha(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_3_with_alpha_general(dp, 1, sp, 0, w, alpha);
- }
- static void
- paint_span_3_sa(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_3_general(dp, 0, sp, 1, w);
- }
- static void
- paint_span_3_sa_alpha(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_3_with_alpha_general(dp, 0, sp, 1, w, alpha);
- }
- static void
- paint_span_3(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_3_general(dp, 0, sp, 0, w);
- }
- static void
- paint_span_3_alpha(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_3_with_alpha_general(dp, 0, sp, 0, w, alpha);
- }
- #endif /* FZ_PLOTTERS_RGB */
- #if FZ_PLOTTERS_CMYK
- static void
- paint_span_4_da_sa(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_4_general(dp, 1, sp, 1, w);
- }
- static void
- paint_span_4_da_sa_alpha(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_4_with_alpha_general(dp, 1, sp, 1, w, alpha);
- }
- static void
- paint_span_4_da(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_4_general(dp, 1, sp, 0, w);
- }
- static void
- paint_span_4_da_alpha(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_4_with_alpha_general(dp, 1, sp, 0, w, alpha);
- }
- static void
- paint_span_4_sa(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_4_general(dp, 0, sp, 1, w);
- }
- static void
- paint_span_4_sa_alpha(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_4_with_alpha_general(dp, 0, sp, 1, w, alpha);
- }
- static void
- paint_span_4(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_4_general(dp, 0, sp, 0, w);
- }
- static void
- paint_span_4_alpha(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_4_with_alpha_general(dp, 0, sp, 0, w, alpha);
- }
- #endif /* FZ_PLOTTERS_CMYK */
- #if FZ_PLOTTERS_N
- static void
- paint_span_N_da_sa(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_N_general(dp, 1, sp, 1, n, w);
- }
- static void
- paint_span_N_da_sa_alpha(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_N_with_alpha_general(dp, 1, sp, 1, n, w, alpha);
- }
- static void
- paint_span_N_da(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_N_general(dp, 1, sp, 0, n, w);
- }
- static void
- paint_span_N_da_alpha(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_N_with_alpha_general(dp, 1, sp, 0, n, w, alpha);
- }
- static void
- paint_span_N_sa(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_N_general(dp, 0, sp, 1, n, w);
- }
- static void
- paint_span_N_sa_alpha(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_N_with_alpha_general(dp, 0, sp, 1, n, w, alpha);
- }
- static void
- paint_span_N(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_N_general(dp, 0, sp, 0, n, w);
- }
- static void
- paint_span_N_alpha(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_N_with_alpha_general(dp, 0, sp, 0, n, w, alpha);
- }
- #endif /* FZ_PLOTTERS_N */
- #if FZ_ENABLE_SPOT_RENDERING
- static void
- paint_span_N_general_op(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_N_general_op(dp, da, sp, sa, n, w, eop);
- }
- static void
- paint_span_N_general_alpha_op(byte * FZ_RESTRICT dp, int da, const byte * FZ_RESTRICT sp, int sa, int n, int w, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- TRACK_FN();
- template_span_N_with_alpha_general_op(dp, da, sp, sa, n, w, alpha, eop);
- }
- #endif /* FZ_ENABLE_SPOT_RENDERING */
- fz_span_painter_t *
- fz_get_span_painter(int da, int sa, int n, int alpha, const fz_overprint * FZ_RESTRICT eop)
- {
- #if FZ_ENABLE_SPOT_RENDERING
- if (fz_overprint_required(eop))
- {
- if (alpha == 255)
- return paint_span_N_general_op;
- else if (alpha > 0)
- return paint_span_N_general_alpha_op;
- else
- return NULL;
- }
- #endif /* FZ_ENABLE_SPOT_RENDERING */
- switch (n)
- {
- case 0:
- if (alpha == 255)
- return paint_span_0_da_sa;
- else if (alpha > 0)
- return paint_span_0_da_sa_alpha;
- break;
- case 1:
- if (sa)
- if (da)
- {
- if (alpha == 255)
- return paint_span_1_da_sa;
- else if (alpha > 0)
- return paint_span_1_da_sa_alpha;
- }
- else
- {
- if (alpha == 255)
- return paint_span_1_sa;
- else if (alpha > 0)
- return paint_span_1_sa_alpha;
- }
- else
- #if FZ_PLOTTERS_G
- if (da)
- {
- if (alpha == 255)
- return paint_span_1_da;
- else if (alpha > 0)
- return paint_span_1_da_alpha;
- }
- else
- {
- if (alpha == 255)
- return paint_span_1;
- else if (alpha > 0)
- return paint_span_1_alpha;
- }
- #else
- goto fallback;
- #endif /* FZ_PLOTTERS_G */
- break;
- #if FZ_PLOTTERS_RGB
- case 3:
- if (da)
- if (sa)
- {
- if (alpha == 255)
- return paint_span_3_da_sa;
- else if (alpha > 0)
- return paint_span_3_da_sa_alpha;
- }
- else
- {
- if (alpha == 255)
- return paint_span_3_da;
- else if (alpha > 0)
- return paint_span_3_da_alpha;
- }
- else
- if (sa)
- {
- if (alpha == 255)
- return paint_span_3_sa;
- else if (alpha > 0)
- return paint_span_3_sa_alpha;
- }
- else
- {
- if (alpha == 255)
- return paint_span_3;
- else if (alpha > 0)
- return paint_span_3_alpha;
- }
- break;
- #endif /* FZ_PLOTTERS_RGB */
- #if FZ_PLOTTERS_CMYK
- case 4:
- if (da)
- if (sa)
- {
- if (alpha == 255)
- return paint_span_4_da_sa;
- else if (alpha > 0)
- return paint_span_4_da_sa_alpha;
- }
- else
- {
- if (alpha == 255)
- return paint_span_4_da;
- else if (alpha > 0)
- return paint_span_4_da_alpha;
- }
- else
- if (sa)
- {
- if (alpha == 255)
- return paint_span_4_sa;
- else if (alpha > 0)
- return paint_span_4_sa_alpha;
- }
- else
- {
- if (alpha == 255)
- return paint_span_4;
- else if (alpha > 0)
- return paint_span_4_alpha;
- }
- break;
- #endif /* FZ_PLOTTERS_CMYK */
- default:
- {
- #if !FZ_PLOTTERS_G
- fallback:{}
- #endif /* FZ_PLOTTERS_G */
- #if FZ_PLOTTERS_N
- if (da)
- if (sa)
- {
- if (alpha == 255)
- return paint_span_N_da_sa;
- else if (alpha > 0)
- return paint_span_N_da_sa_alpha;
- }
- else
- {
- if (alpha == 255)
- return paint_span_N_da;
- else if (alpha > 0)
- return paint_span_N_da_alpha;
- }
- else
- if (sa)
- {
- if (alpha == 255)
- return paint_span_N_sa;
- else if (alpha > 0)
- return paint_span_N_sa_alpha;
- }
- else
- {
- if (alpha == 255)
- return paint_span_N;
- else if (alpha > 0)
- return paint_span_N_alpha;
- }
- #endif /* FZ_PLOTTERS_N */
- break;
- }
- }
- return NULL;
- }
- /*
- * Pixmap blending functions
- */
- void
- fz_paint_pixmap_with_bbox(fz_pixmap * FZ_RESTRICT dst, const fz_pixmap * FZ_RESTRICT src, int alpha, fz_irect bbox)
- {
- const unsigned char *sp;
- unsigned char *dp;
- int x, y, w, h, n, da, sa;
- fz_span_painter_t *fn;
- assert(dst->n - dst->alpha == src->n - src->alpha);
- if (alpha == 0)
- return;
- bbox = fz_intersect_irect(bbox, fz_pixmap_bbox_no_ctx(dst));
- bbox = fz_intersect_irect(bbox, fz_pixmap_bbox_no_ctx(src));
- x = bbox.x0;
- y = bbox.y0;
- w = fz_irect_width(bbox);
- h = fz_irect_height(bbox);
- if (w == 0 || h == 0)
- return;
- n = src->n;
- sp = src->samples + (y - src->y) * (size_t)src->stride + (x - src->x) * (size_t)src->n;
- sa = src->alpha;
- dp = dst->samples + (y - dst->y) * (size_t)dst->stride + (x - dst->x) * (size_t)dst->n;
- da = dst->alpha;
- n -= sa;
- fn = fz_get_span_painter(da, sa, n, alpha, 0);
- if (fn == NULL)
- return;
- while (h--)
- {
- (*fn)(dp, da, sp, sa, n, w, alpha, 0);
- sp += src->stride;
- dp += dst->stride;
- }
- }
- void
- fz_paint_pixmap(fz_pixmap * FZ_RESTRICT dst, const fz_pixmap * FZ_RESTRICT src, int alpha)
- {
- const unsigned char *sp;
- unsigned char *dp;
- fz_irect bbox;
- int x, y, w, h, n, da, sa;
- fz_span_painter_t *fn;
- if (alpha == 0)
- return;
- if (dst->n - dst->alpha != src->n - src->alpha)
- {
- // fprintf(stderr, "fz_paint_pixmap - FIXME\n");
- return;
- }
- assert(dst->n - dst->alpha == src->n - src->alpha);
- bbox = fz_intersect_irect(fz_pixmap_bbox_no_ctx(src), fz_pixmap_bbox_no_ctx(dst));
- x = bbox.x0;
- y = bbox.y0;
- w = fz_irect_width(bbox);
- h = fz_irect_height(bbox);
- if (w == 0 || h == 0)
- return;
- n = src->n;
- sp = src->samples + (y - src->y) * (size_t)src->stride + (x - src->x) * (size_t)src->n;
- sa = src->alpha;
- dp = dst->samples + (y - dst->y) * (size_t)dst->stride + (x - dst->x) * (size_t)dst->n;
- da = dst->alpha;
- n -= sa;
- fn = fz_get_span_painter(da, sa, n, alpha, 0);
- if (fn == NULL)
- return;
- while (h--)
- {
- (*fn)(dp, da, sp, sa, n, w, alpha, 0);
- sp += src->stride;
- dp += dst->stride;
- }
- }
- static fz_forceinline void
- paint_span_alpha_solid(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT sp, int n, int w)
- {
- TRACK_FN();
- sp += n-1;
- do
- {
- int s = *sp;
- int t = FZ_EXPAND(255 - s);
- sp += n;
- *dp = s + FZ_COMBINE(*dp, t);
- dp ++;
- }
- while (--w);
- }
- static fz_forceinline void
- paint_span_alpha_not_solid(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT sp, int n, int w, int alpha)
- {
- TRACK_FN();
- sp += n-1;
- alpha = FZ_EXPAND(alpha);
- do
- {
- int masa = FZ_COMBINE(sp[0], alpha);
- sp += n;
- *dp = FZ_BLEND(*sp, *dp, masa);
- dp++;
- }
- while (--w);
- }
- void
- fz_paint_pixmap_alpha(fz_pixmap * FZ_RESTRICT dst, const fz_pixmap * FZ_RESTRICT src, int alpha)
- {
- const unsigned char *sp;
- unsigned char *dp;
- fz_irect bbox;
- int x, y, w, h, n;
- if (alpha == 0)
- return;
- assert(dst->n == 1 && dst->alpha == 1 && src->n >= 1 && src->alpha == 1);
- bbox = fz_intersect_irect(fz_pixmap_bbox_no_ctx(src), fz_pixmap_bbox_no_ctx(dst));
- x = bbox.x0;
- y = bbox.y0;
- w = fz_irect_width(bbox);
- h = fz_irect_height(bbox);
- if (w == 0 || h == 0)
- return;
- n = src->n;
- sp = src->samples + (y - src->y) * (size_t)src->stride + (x - src->x) * (size_t)src->n;
- dp = dst->samples + (y - dst->y) * (size_t)dst->stride + (x - dst->x) * (size_t)dst->n;
- if (alpha == 255)
- {
- while (h--)
- {
- paint_span_alpha_solid(dp, sp, n, w);
- sp += src->stride;
- dp += dst->stride;
- }
- }
- else
- {
- while (h--)
- {
- paint_span_alpha_not_solid(dp, sp, n, w, alpha);
- sp += src->stride;
- dp += dst->stride;
- }
- }
- }
- void
- fz_paint_pixmap_with_overprint(fz_pixmap * FZ_RESTRICT dst, const fz_pixmap * FZ_RESTRICT src, const fz_overprint * FZ_RESTRICT eop)
- {
- const unsigned char *sp;
- unsigned char *dp;
- fz_irect bbox;
- int x, y, w, h, n, da, sa;
- fz_span_painter_t *fn;
- if (dst->n - dst->alpha != src->n - src->alpha)
- {
- // fprintf(stderr, "fz_paint_pixmap_with_overprint - FIXME\n");
- return;
- }
- assert(dst->n - dst->alpha == src->n - src->alpha);
- bbox = fz_intersect_irect(fz_pixmap_bbox_no_ctx(src), fz_pixmap_bbox_no_ctx(dst));
- x = bbox.x0;
- y = bbox.y0;
- w = fz_irect_width(bbox);
- h = fz_irect_height(bbox);
- if (w == 0 || h == 0)
- return;
- n = src->n;
- sp = src->samples + (y - src->y) * (size_t)src->stride + (x - src->x) * (size_t)src->n;
- sa = src->alpha;
- dp = dst->samples + (y - dst->y) * (size_t)dst->stride + (x - dst->x) * (size_t)dst->n;
- da = dst->alpha;
- n -= sa;
- fn = fz_get_span_painter(da, sa, n, 255, eop);
- if (fn == NULL)
- return;
- while (h--)
- {
- (*fn)(dp, da, sp, sa, n, w, 255, eop);
- sp += src->stride;
- dp += dst->stride;
- }
- }
- void
- fz_paint_pixmap_with_mask(fz_pixmap * FZ_RESTRICT dst, const fz_pixmap * FZ_RESTRICT src, const fz_pixmap * FZ_RESTRICT msk)
- {
- const unsigned char *sp, *mp;
- unsigned char *dp;
- fz_irect bbox;
- int x, y, w, h, n, sa, da;
- fz_span_mask_painter_t *fn;
- assert(dst->n == src->n);
- assert(msk->n == 1);
- bbox = fz_pixmap_bbox_no_ctx(dst);
- bbox = fz_intersect_irect(bbox, fz_pixmap_bbox_no_ctx(src));
- bbox = fz_intersect_irect(bbox, fz_pixmap_bbox_no_ctx(msk));
- x = bbox.x0;
- y = bbox.y0;
- w = fz_irect_width(bbox);
- h = fz_irect_height(bbox);
- if (w == 0 || h == 0)
- return;
- n = src->n;
- sp = src->samples + (y - src->y) * (size_t)src->stride + (x - src->x) * (size_t)src->n;
- sa = src->alpha;
- mp = msk->samples + (y - msk->y) * (size_t)msk->stride + (x - msk->x) * (size_t)msk->n;
- dp = dst->samples + (y - dst->y) * (size_t)dst->stride + (x - dst->x) * (size_t)dst->n;
- da = dst->alpha;
- /* sa == da, or something has gone very wrong! */
- assert(sa == da);
- n -= sa;
- fn = fz_get_span_mask_painter(da, n);
- if (fn == NULL)
- return;
- while (h--)
- {
- (*fn)(dp, sp, mp, w, n, sa, NULL);
- sp += src->stride;
- dp += dst->stride;
- mp += msk->stride;
- }
- }
- static fz_forceinline void
- paint_over_span_with_mask(byte * FZ_RESTRICT dp, const byte * FZ_RESTRICT sp, const byte * FZ_RESTRICT mp, int w)
- {
- do
- {
- int ma = *mp++;
- ma = FZ_EXPAND(ma);
- if (ma == 0 || *sp == 0)
- {
- dp++;
- sp++;
- }
- else
- {
- int a = *sp++;
- if (ma != 256)
- a = fz_mul255(ma, a);
- *dp = 255 - fz_mul255(255 - a, 255 - *dp);
- dp++;
- }
- }
- while (--w);
- }
- void
- fz_paint_over_pixmap_with_mask(fz_pixmap * FZ_RESTRICT dst, const fz_pixmap * FZ_RESTRICT src, const fz_pixmap * FZ_RESTRICT msk)
- {
- const unsigned char *sp, *mp;
- unsigned char *dp;
- fz_irect bbox;
- int x, y, w, h;
- assert(dst->n == src->n);
- assert(msk->n == 1);
- bbox = fz_pixmap_bbox_no_ctx(dst);
- bbox = fz_intersect_irect(bbox, fz_pixmap_bbox_no_ctx(src));
- bbox = fz_intersect_irect(bbox, fz_pixmap_bbox_no_ctx(msk));
- x = bbox.x0;
- y = bbox.y0;
- w = fz_irect_width(bbox);
- h = fz_irect_height(bbox);
- if (w == 0 || h == 0)
- return;
- /* sa == da, or something has gone very wrong! */
- assert(src->alpha == dst->alpha && dst->alpha == 1 && src->n == 1);
- sp = src->samples + (y - src->y) * (size_t)src->stride + (size_t)(x - src->x);
- mp = msk->samples + (y - msk->y) * (size_t)msk->stride + (size_t)(x - msk->x);
- dp = dst->samples + (y - dst->y) * (size_t)dst->stride + (size_t)(x - dst->x);
- while (h--)
- {
- paint_over_span_with_mask(dp, sp, mp, w);
- sp += src->stride;
- dp += dst->stride;
- mp += msk->stride;
- }
- }
- static inline void
- fz_paint_glyph_mask(int span, unsigned char *dp, int da, const fz_glyph *glyph, int w, int h, int skip_x, int skip_y)
- {
- while (h--)
- {
- int skip_xx, ww, len, extend;
- const unsigned char *runp;
- unsigned char *ddp = dp;
- int offset = ((const int *)(glyph->data))[skip_y++];
- if (offset >= 0)
- {
- int eol = 0;
- runp = &glyph->data[offset];
- extend = 0;
- ww = w;
- skip_xx = skip_x;
- while (skip_xx)
- {
- int v = *runp++;
- switch (v & 3)
- {
- case 0: /* Extend */
- extend = v>>2;
- len = 0;
- break;
- case 1: /* Transparent */
- len = (v>>2) + 1 + (extend<<6);
- extend = 0;
- if (len > skip_xx)
- {
- len -= skip_xx;
- goto transparent_run;
- }
- break;
- case 2: /* Solid */
- eol = v & 4;
- len = (v>>3) + 1 + (extend<<5);
- extend = 0;
- if (len > skip_xx)
- {
- len -= skip_xx;
- goto solid_run;
- }
- break;
- default: /* Intermediate */
- eol = v & 4;
- len = (v>>3) + 1 + (extend<<5);
- extend = 0;
- if (len > skip_xx)
- {
- runp += skip_xx;
- len -= skip_xx;
- goto intermediate_run;
- }
- runp += len;
- break;
- }
- if (eol)
- {
- ww = 0;
- break;
- }
- skip_xx -= len;
- }
- while (ww > 0)
- {
- int v = *runp++;
- switch(v & 3)
- {
- case 0: /* Extend */
- extend = v>>2;
- break;
- case 1: /* Transparent */
- len = (v>>2) + 1 + (extend<<6);
- extend = 0;
- transparent_run:
- if (len > ww)
- len = ww;
- ww -= len;
- ddp += len;
- break;
- case 2: /* Solid */
- eol = v & 4;
- len = (v>>3) + 1 + (extend<<5);
- extend = 0;
- solid_run:
- if (len > ww)
- len = ww;
- ww -= len;
- do
- {
- *ddp++ = 0xFF;
- }
- while (--len);
- break;
- default: /* Intermediate */
- eol = v & 4;
- len = (v>>3) + 1 + (extend<<5);
- extend = 0;
- intermediate_run:
- if (len > ww)
- len = ww;
- ww -= len;
- do
- {
- int a = *runp++;
- v = *ddp;
- if (v == 0)
- {
- *ddp++ = a;
- }
- else
- {
- a = FZ_EXPAND(a);
- *ddp = FZ_BLEND(0xFF, v, a);
- ddp++;
- }
- }
- while (--len);
- break;
- }
- if (eol)
- break;
- }
- }
- dp += span;
- }
- }
- static inline void
- fz_paint_glyph_mask_alpha(int span, unsigned char *dp, int da, const fz_glyph *glyph, int w, int h, int skip_x, int skip_y, unsigned char alpha)
- {
- while (h--)
- {
- int skip_xx, ww, len, extend;
- const unsigned char *runp;
- unsigned char *ddp = dp;
- int offset = ((const int *)(glyph->data))[skip_y++];
- if (offset >= 0)
- {
- int eol = 0;
- runp = &glyph->data[offset];
- extend = 0;
- ww = w;
- skip_xx = skip_x;
- while (skip_xx)
- {
- int v = *runp++;
- switch (v & 3)
- {
- case 0: /* Extend */
- extend = v>>2;
- len = 0;
- break;
- case 1: /* Transparent */
- len = (v>>2) + 1 + (extend<<6);
- extend = 0;
- if (len > skip_xx)
- {
- len -= skip_xx;
- goto transparent_run;
- }
- break;
- case 2: /* Solid */
- eol = v & 4;
- len = (v>>3) + 1 + (extend<<5);
- extend = 0;
- if (len > skip_xx)
- {
- len -= skip_xx;
- goto solid_run;
- }
- break;
- default: /* Intermediate */
- eol = v & 4;
- len = (v>>3) + 1 + (extend<<5);
- extend = 0;
- if (len > skip_xx)
- {
- runp += skip_xx;
- len -= skip_xx;
- goto intermediate_run;
- }
- runp += len;
- break;
- }
- if (eol)
- {
- ww = 0;
- break;
- }
- skip_xx -= len;
- }
- while (ww > 0)
- {
- int v = *runp++;
- switch(v & 3)
- {
- case 0: /* Extend */
- extend = v>>2;
- break;
- case 1: /* Transparent */
- len = (v>>2) + 1 + (extend<<6);
- extend = 0;
- transparent_run:
- if (len > ww)
- len = ww;
- ww -= len;
- ddp += len;
- break;
- case 2: /* Solid */
- eol = v & 4;
- len = (v>>3) + 1 + (extend<<5);
- extend = 0;
- solid_run:
- if (len > ww)
- len = ww;
- ww -= len;
- do
- {
- *ddp++ = alpha;
- }
- while (--len);
- break;
- default: /* Intermediate */
- eol = v & 4;
- len = (v>>3) + 1 + (extend<<5);
- extend = 0;
- intermediate_run:
- if (len > ww)
- len = ww;
- ww -= len;
- do
- {
- int a = *runp++;
- v = *ddp;
- if (v == 0)
- {
- *ddp++ = fz_mul255(a, alpha);
- }
- else
- {
- a = FZ_EXPAND(a);
- *ddp = FZ_BLEND(alpha, v, a);
- ddp++;
- }
- }
- while (--len);
- break;
- }
- if (eol)
- break;
- }
- }
- dp += span;
- }
- }
- #define N 1
- #include "paint-glyph.h"
- #define ALPHA
- #define N 1
- #include "paint-glyph.h"
- #if FZ_PLOTTERS_G
- #define DA
- #define N 1
- #include "paint-glyph.h"
- #define DA
- #define ALPHA
- #define N 1
- #include "paint-glyph.h"
- #endif /* FZ_PLOTTERS_G */
- #if FZ_PLOTTERS_RGB
- #define DA
- #define N 3
- #include "paint-glyph.h"
- #define DA
- #define ALPHA
- #define N 3
- #include "paint-glyph.h"
- #define N 3
- #include "paint-glyph.h"
- #define ALPHA
- #define N 3
- #include "paint-glyph.h"
- #endif /* FZ_PLOTTERS_RGB */
- #if FZ_PLOTTERS_CMYK
- #define DA
- #define N 4
- #include "paint-glyph.h"
- #define DA
- #define ALPHA
- #define N 4
- #include "paint-glyph.h"
- #define ALPHA
- #define N 4
- #include "paint-glyph.h"
- #define N 4
- #include "paint-glyph.h"
- #endif /* FZ_PLOTTERS_CMYK */
- #if FZ_PLOTTERS_N
- #define ALPHA
- #include "paint-glyph.h"
- #define DA
- #include "paint-glyph.h"
- #define DA
- #define ALPHA
- #include "paint-glyph.h"
- #include "paint-glyph.h"
- #endif /* FZ_PLOTTERS_N */
- #if FZ_ENABLE_SPOT_RENDERING
- #define ALPHA
- #define EOP
- #include "paint-glyph.h"
- #define DA
- #define EOP
- #include "paint-glyph.h"
- #define DA
- #define ALPHA
- #define EOP
- #include "paint-glyph.h"
- #define EOP
- #include "paint-glyph.h"
- #endif /* FZ_ENABLE_SPOT_RENDERING */
- static void
- fz_paint_glyph_alpha(const unsigned char * FZ_RESTRICT colorbv, int n, int span, unsigned char * FZ_RESTRICT dp, int da, const fz_glyph *glyph, int w, int h, int skip_x, int skip_y, const fz_overprint * FZ_RESTRICT eop)
- {
- #if FZ_ENABLE_SPOT_RENDERING
- if (fz_overprint_required(eop))
- {
- if (da)
- fz_paint_glyph_alpha_N_da_op(colorbv, n, span, dp, glyph, w, h, skip_x, skip_y, eop);
- else
- fz_paint_glyph_alpha_N_op(colorbv, n, span, dp, glyph, w, h, skip_x, skip_y, eop);
- return;
- }
- #endif /* FZ_ENABLE_SPOT_RENDERING */
- switch (n)
- {
- case 1:
- if (da)
- #if FZ_PLOTTERS_G
- fz_paint_glyph_alpha_1_da(colorbv, span, dp, glyph, w, h, skip_x, skip_y);
- #else
- goto fallback;
- #endif /* FZ_PLOTTERS_G */
- else
- fz_paint_glyph_alpha_1(colorbv, span, dp, glyph, w, h, skip_x, skip_y);
- break;
- #if FZ_PLOTTERS_RGB
- case 3:
- if (da)
- fz_paint_glyph_alpha_3_da(colorbv, span, dp, glyph, w, h, skip_x, skip_y);
- else
- fz_paint_glyph_alpha_3(colorbv, span, dp, glyph, w, h, skip_x, skip_y);
- break;
- #endif /* FZ_PLOTTERS_RGB */
- #if FZ_PLOTTERS_CMYK
- case 4:
- if (da)
- fz_paint_glyph_alpha_4_da(colorbv, span, dp, glyph, w, h, skip_x, skip_y);
- else
- fz_paint_glyph_alpha_4(colorbv, span, dp, glyph, w, h, skip_x, skip_y);
- break;
- #endif /* FZ_PLOTTERS_CMYK */
- default:
- {
- #if !FZ_PLOTTERS_G
- fallback:{}
- #endif /* !FZ_PLOTTERS_G */
- #if FZ_PLOTTERS_N
- if (da)
- fz_paint_glyph_alpha_N_da(colorbv, n, span, dp, glyph, w, h, skip_x, skip_y);
- else
- fz_paint_glyph_alpha_N(colorbv, n, span, dp, glyph, w, h, skip_x, skip_y);
- #endif /* FZ_PLOTTERS_N */
- break;
- }
- }
- }
- static void
- fz_paint_glyph_solid(const unsigned char * FZ_RESTRICT colorbv, int n, int span, unsigned char * FZ_RESTRICT dp, int da, const fz_glyph * FZ_RESTRICT glyph, int w, int h, int skip_x, int skip_y, const fz_overprint * FZ_RESTRICT eop)
- {
- #if FZ_ENABLE_SPOT_RENDERING
- if (fz_overprint_required(eop))
- {
- if (da)
- fz_paint_glyph_solid_N_da_op(colorbv, n, span, dp, glyph, w, h, skip_x, skip_y, eop);
- else
- fz_paint_glyph_solid_N_op(colorbv, n, span, dp, glyph, w, h, skip_x, skip_y, eop);
- return;
- }
- #endif /* FZ_ENABLE_SPOT_RENDERING */
- switch (n)
- {
- case 1:
- if (da)
- #if FZ_PLOTTERS_G
- fz_paint_glyph_solid_1_da(colorbv, span, dp, glyph, w, h, skip_x, skip_y);
- #else
- goto fallback;
- #endif /* FZ_PLOTTERS_G */
- else
- fz_paint_glyph_solid_1(colorbv, span, dp, glyph, w, h, skip_x, skip_y);
- break;
- #if FZ_PLOTTERS_RGB
- case 3:
- if (da)
- fz_paint_glyph_solid_3_da(colorbv, span, dp, glyph, w, h, skip_x, skip_y);
- else
- fz_paint_glyph_solid_3(colorbv, span, dp, glyph, w, h, skip_x, skip_y);
- break;
- #endif /* FZ_PLOTTERS_RGB */
- #if FZ_PLOTTERS_CMYK
- case 4:
- if (da)
- fz_paint_glyph_solid_4_da(colorbv, span, dp, glyph, w, h, skip_x, skip_y);
- else
- fz_paint_glyph_solid_4(colorbv, span, dp, glyph, w, h, skip_x, skip_y);
- break;
- #endif /* FZ_PLOTTERS_CMYK */
- default:
- {
- #if !FZ_PLOTTERS_G
- fallback:{}
- #endif /* FZ_PLOTTERS_G */
- #if FZ_PLOTTERS_N
- if (da)
- fz_paint_glyph_solid_N_da(colorbv, n, span, dp, glyph, w, h, skip_x, skip_y);
- else
- fz_paint_glyph_solid_N(colorbv, n, span, dp, glyph, w, h, skip_x, skip_y);
- break;
- #endif /* FZ_PLOTTERS_N */
- }
- }
- }
- void
- fz_paint_glyph(const unsigned char * FZ_RESTRICT colorbv, fz_pixmap * FZ_RESTRICT dst, unsigned char * FZ_RESTRICT dp, const fz_glyph * FZ_RESTRICT glyph, int w, int h, int skip_x, int skip_y, const fz_overprint * FZ_RESTRICT eop)
- {
- int n = dst->n - dst->alpha;
- if (dst->colorspace)
- {
- assert(n > 0);
- if (colorbv[n] == 255)
- fz_paint_glyph_solid(colorbv, n, dst->stride, dp, dst->alpha, glyph, w, h, skip_x, skip_y, eop);
- else if (colorbv[n] != 0)
- fz_paint_glyph_alpha(colorbv, n, dst->stride, dp, dst->alpha, glyph, w, h, skip_x, skip_y, eop);
- }
- else
- {
- assert(dst->alpha && dst->n == 1 && dst->colorspace == NULL && !fz_overprint_required(eop));
- if (colorbv == NULL || colorbv[0] == 255)
- fz_paint_glyph_mask(dst->stride, dp, dst->alpha, glyph, w, h, skip_x, skip_y);
- else
- fz_paint_glyph_mask_alpha(dst->stride, dp, dst->alpha, glyph, w, h, skip_x, skip_y, colorbv[0]);
- }
- }
|