123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351 |
- /*
- * Copyright 2011 The LibYuv Project Authors. All rights reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
- #include <math.h>
- #include <stdlib.h>
- #include <time.h>
- #include "../unit_test/unit_test.h"
- #include "libyuv/compare.h"
- #include "libyuv/convert.h"
- #include "libyuv/convert_argb.h"
- #include "libyuv/convert_from.h"
- #include "libyuv/convert_from_argb.h"
- #include "libyuv/cpu_id.h"
- #include "libyuv/planar_functions.h"
- #include "libyuv/rotate.h"
- #ifdef ENABLE_ROW_TESTS
- // row.h defines SIMD_ALIGNED, overriding unit_test.h
- // TODO(fbarchard): Remove row.h from unittests. Test public functions.
- #include "libyuv/row.h" /* For ScaleSumSamples_Neon */
- #endif
- namespace libyuv {
- TEST_F(LibYUVPlanarTest, TestAttenuate) {
- const int kSize = 1280 * 4;
- align_buffer_page_end(orig_pixels, kSize);
- align_buffer_page_end(atten_pixels, kSize);
- align_buffer_page_end(unatten_pixels, kSize);
- align_buffer_page_end(atten2_pixels, kSize);
- // Test unattenuation clamps
- orig_pixels[0 * 4 + 0] = 200u;
- orig_pixels[0 * 4 + 1] = 129u;
- orig_pixels[0 * 4 + 2] = 127u;
- orig_pixels[0 * 4 + 3] = 128u;
- // Test unattenuation transparent and opaque are unaffected
- orig_pixels[1 * 4 + 0] = 16u;
- orig_pixels[1 * 4 + 1] = 64u;
- orig_pixels[1 * 4 + 2] = 192u;
- orig_pixels[1 * 4 + 3] = 0u;
- orig_pixels[2 * 4 + 0] = 16u;
- orig_pixels[2 * 4 + 1] = 64u;
- orig_pixels[2 * 4 + 2] = 192u;
- orig_pixels[2 * 4 + 3] = 255u;
- orig_pixels[3 * 4 + 0] = 16u;
- orig_pixels[3 * 4 + 1] = 64u;
- orig_pixels[3 * 4 + 2] = 192u;
- orig_pixels[3 * 4 + 3] = 128u;
- ARGBUnattenuate(orig_pixels, 0, unatten_pixels, 0, 4, 1);
- EXPECT_EQ(255u, unatten_pixels[0 * 4 + 0]);
- EXPECT_EQ(255u, unatten_pixels[0 * 4 + 1]);
- EXPECT_EQ(254u, unatten_pixels[0 * 4 + 2]);
- EXPECT_EQ(128u, unatten_pixels[0 * 4 + 3]);
- EXPECT_EQ(0u, unatten_pixels[1 * 4 + 0]);
- EXPECT_EQ(0u, unatten_pixels[1 * 4 + 1]);
- EXPECT_EQ(0u, unatten_pixels[1 * 4 + 2]);
- EXPECT_EQ(0u, unatten_pixels[1 * 4 + 3]);
- EXPECT_EQ(16u, unatten_pixels[2 * 4 + 0]);
- EXPECT_EQ(64u, unatten_pixels[2 * 4 + 1]);
- EXPECT_EQ(192u, unatten_pixels[2 * 4 + 2]);
- EXPECT_EQ(255u, unatten_pixels[2 * 4 + 3]);
- EXPECT_EQ(32u, unatten_pixels[3 * 4 + 0]);
- EXPECT_EQ(128u, unatten_pixels[3 * 4 + 1]);
- EXPECT_EQ(255u, unatten_pixels[3 * 4 + 2]);
- EXPECT_EQ(128u, unatten_pixels[3 * 4 + 3]);
- for (int i = 0; i < 1280; ++i) {
- orig_pixels[i * 4 + 0] = i;
- orig_pixels[i * 4 + 1] = i / 2;
- orig_pixels[i * 4 + 2] = i / 3;
- orig_pixels[i * 4 + 3] = i;
- }
- ARGBAttenuate(orig_pixels, 0, atten_pixels, 0, 1280, 1);
- ARGBUnattenuate(atten_pixels, 0, unatten_pixels, 0, 1280, 1);
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
- ARGBAttenuate(unatten_pixels, 0, atten2_pixels, 0, 1280, 1);
- }
- for (int i = 0; i < 1280; ++i) {
- EXPECT_NEAR(atten_pixels[i * 4 + 0], atten2_pixels[i * 4 + 0], 2);
- EXPECT_NEAR(atten_pixels[i * 4 + 1], atten2_pixels[i * 4 + 1], 2);
- EXPECT_NEAR(atten_pixels[i * 4 + 2], atten2_pixels[i * 4 + 2], 2);
- EXPECT_NEAR(atten_pixels[i * 4 + 3], atten2_pixels[i * 4 + 3], 2);
- }
- // Make sure transparent, 50% and opaque are fully accurate.
- EXPECT_EQ(0, atten_pixels[0 * 4 + 0]);
- EXPECT_EQ(0, atten_pixels[0 * 4 + 1]);
- EXPECT_EQ(0, atten_pixels[0 * 4 + 2]);
- EXPECT_EQ(0, atten_pixels[0 * 4 + 3]);
- EXPECT_EQ(64, atten_pixels[128 * 4 + 0]);
- EXPECT_EQ(32, atten_pixels[128 * 4 + 1]);
- EXPECT_EQ(21, atten_pixels[128 * 4 + 2]);
- EXPECT_EQ(128, atten_pixels[128 * 4 + 3]);
- EXPECT_NEAR(255, atten_pixels[255 * 4 + 0], 1);
- EXPECT_NEAR(127, atten_pixels[255 * 4 + 1], 1);
- EXPECT_NEAR(85, atten_pixels[255 * 4 + 2], 1);
- EXPECT_EQ(255, atten_pixels[255 * 4 + 3]);
- free_aligned_buffer_page_end(atten2_pixels);
- free_aligned_buffer_page_end(unatten_pixels);
- free_aligned_buffer_page_end(atten_pixels);
- free_aligned_buffer_page_end(orig_pixels);
- }
- static int TestAttenuateI(int width,
- int height,
- int benchmark_iterations,
- int disable_cpu_flags,
- int benchmark_cpu_info,
- int invert,
- int off) {
- if (width < 1) {
- width = 1;
- }
- const int kBpp = 4;
- const int kStride = width * kBpp;
- align_buffer_page_end(src_argb, kStride * height + off);
- align_buffer_page_end(dst_argb_c, kStride * height);
- align_buffer_page_end(dst_argb_opt, kStride * height);
- for (int i = 0; i < kStride * height; ++i) {
- src_argb[i + off] = (fastrand() & 0xff);
- }
- memset(dst_argb_c, 0, kStride * height);
- memset(dst_argb_opt, 0, kStride * height);
- MaskCpuFlags(disable_cpu_flags);
- ARGBAttenuate(src_argb + off, kStride, dst_argb_c, kStride, width,
- invert * height);
- MaskCpuFlags(benchmark_cpu_info);
- for (int i = 0; i < benchmark_iterations; ++i) {
- ARGBAttenuate(src_argb + off, kStride, dst_argb_opt, kStride, width,
- invert * height);
- }
- int max_diff = 0;
- for (int i = 0; i < kStride * height; ++i) {
- int abs_diff = abs(static_cast<int>(dst_argb_c[i]) -
- static_cast<int>(dst_argb_opt[i]));
- if (abs_diff > max_diff) {
- max_diff = abs_diff;
- }
- }
- free_aligned_buffer_page_end(src_argb);
- free_aligned_buffer_page_end(dst_argb_c);
- free_aligned_buffer_page_end(dst_argb_opt);
- return max_diff;
- }
- TEST_F(LibYUVPlanarTest, ARGBAttenuate_Any) {
- int max_diff = TestAttenuateI(benchmark_width_ - 1, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, +1, 0);
- EXPECT_LE(max_diff, 2);
- }
- TEST_F(LibYUVPlanarTest, ARGBAttenuate_Unaligned) {
- int max_diff =
- TestAttenuateI(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 1);
- EXPECT_LE(max_diff, 2);
- }
- TEST_F(LibYUVPlanarTest, ARGBAttenuate_Invert) {
- int max_diff =
- TestAttenuateI(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, -1, 0);
- EXPECT_LE(max_diff, 2);
- }
- TEST_F(LibYUVPlanarTest, ARGBAttenuate_Opt) {
- int max_diff =
- TestAttenuateI(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0);
- EXPECT_LE(max_diff, 2);
- }
- static int TestUnattenuateI(int width,
- int height,
- int benchmark_iterations,
- int disable_cpu_flags,
- int benchmark_cpu_info,
- int invert,
- int off) {
- if (width < 1) {
- width = 1;
- }
- const int kBpp = 4;
- const int kStride = width * kBpp;
- align_buffer_page_end(src_argb, kStride * height + off);
- align_buffer_page_end(dst_argb_c, kStride * height);
- align_buffer_page_end(dst_argb_opt, kStride * height);
- for (int i = 0; i < kStride * height; ++i) {
- src_argb[i + off] = (fastrand() & 0xff);
- }
- ARGBAttenuate(src_argb + off, kStride, src_argb + off, kStride, width,
- height);
- memset(dst_argb_c, 0, kStride * height);
- memset(dst_argb_opt, 0, kStride * height);
- MaskCpuFlags(disable_cpu_flags);
- ARGBUnattenuate(src_argb + off, kStride, dst_argb_c, kStride, width,
- invert * height);
- MaskCpuFlags(benchmark_cpu_info);
- for (int i = 0; i < benchmark_iterations; ++i) {
- ARGBUnattenuate(src_argb + off, kStride, dst_argb_opt, kStride, width,
- invert * height);
- }
- int max_diff = 0;
- for (int i = 0; i < kStride * height; ++i) {
- int abs_diff = abs(static_cast<int>(dst_argb_c[i]) -
- static_cast<int>(dst_argb_opt[i]));
- if (abs_diff > max_diff) {
- max_diff = abs_diff;
- }
- }
- free_aligned_buffer_page_end(src_argb);
- free_aligned_buffer_page_end(dst_argb_c);
- free_aligned_buffer_page_end(dst_argb_opt);
- return max_diff;
- }
- TEST_F(LibYUVPlanarTest, ARGBUnattenuate_Any) {
- int max_diff = TestUnattenuateI(benchmark_width_ - 1, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, +1, 0);
- EXPECT_LE(max_diff, 2);
- }
- TEST_F(LibYUVPlanarTest, ARGBUnattenuate_Unaligned) {
- int max_diff = TestUnattenuateI(benchmark_width_, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, +1, 1);
- EXPECT_LE(max_diff, 2);
- }
- TEST_F(LibYUVPlanarTest, ARGBUnattenuate_Invert) {
- int max_diff = TestUnattenuateI(benchmark_width_, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, -1, 0);
- EXPECT_LE(max_diff, 2);
- }
- TEST_F(LibYUVPlanarTest, ARGBUnattenuate_Opt) {
- int max_diff = TestUnattenuateI(benchmark_width_, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, +1, 0);
- EXPECT_LE(max_diff, 2);
- }
- TEST_F(LibYUVPlanarTest, TestARGBComputeCumulativeSum) {
- SIMD_ALIGNED(uint8_t orig_pixels[16][16][4]);
- SIMD_ALIGNED(int32_t added_pixels[16][16][4]);
- for (int y = 0; y < 16; ++y) {
- for (int x = 0; x < 16; ++x) {
- orig_pixels[y][x][0] = 1u;
- orig_pixels[y][x][1] = 2u;
- orig_pixels[y][x][2] = 3u;
- orig_pixels[y][x][3] = 255u;
- }
- }
- ARGBComputeCumulativeSum(&orig_pixels[0][0][0], 16 * 4,
- &added_pixels[0][0][0], 16 * 4, 16, 16);
- for (int y = 0; y < 16; ++y) {
- for (int x = 0; x < 16; ++x) {
- EXPECT_EQ((x + 1) * (y + 1), added_pixels[y][x][0]);
- EXPECT_EQ((x + 1) * (y + 1) * 2, added_pixels[y][x][1]);
- EXPECT_EQ((x + 1) * (y + 1) * 3, added_pixels[y][x][2]);
- EXPECT_EQ((x + 1) * (y + 1) * 255, added_pixels[y][x][3]);
- }
- }
- }
- TEST_F(LibYUVPlanarTest, TestARGBGray) {
- SIMD_ALIGNED(uint8_t orig_pixels[1280][4]);
- memset(orig_pixels, 0, sizeof(orig_pixels));
- // Test blue
- orig_pixels[0][0] = 255u;
- orig_pixels[0][1] = 0u;
- orig_pixels[0][2] = 0u;
- orig_pixels[0][3] = 128u;
- // Test green
- orig_pixels[1][0] = 0u;
- orig_pixels[1][1] = 255u;
- orig_pixels[1][2] = 0u;
- orig_pixels[1][3] = 0u;
- // Test red
- orig_pixels[2][0] = 0u;
- orig_pixels[2][1] = 0u;
- orig_pixels[2][2] = 255u;
- orig_pixels[2][3] = 255u;
- // Test black
- orig_pixels[3][0] = 0u;
- orig_pixels[3][1] = 0u;
- orig_pixels[3][2] = 0u;
- orig_pixels[3][3] = 255u;
- // Test white
- orig_pixels[4][0] = 255u;
- orig_pixels[4][1] = 255u;
- orig_pixels[4][2] = 255u;
- orig_pixels[4][3] = 255u;
- // Test color
- orig_pixels[5][0] = 16u;
- orig_pixels[5][1] = 64u;
- orig_pixels[5][2] = 192u;
- orig_pixels[5][3] = 224u;
- // Do 16 to test asm version.
- ARGBGray(&orig_pixels[0][0], 0, 0, 0, 16, 1);
- EXPECT_EQ(30u, orig_pixels[0][0]);
- EXPECT_EQ(30u, orig_pixels[0][1]);
- EXPECT_EQ(30u, orig_pixels[0][2]);
- EXPECT_EQ(128u, orig_pixels[0][3]);
- EXPECT_EQ(149u, orig_pixels[1][0]);
- EXPECT_EQ(149u, orig_pixels[1][1]);
- EXPECT_EQ(149u, orig_pixels[1][2]);
- EXPECT_EQ(0u, orig_pixels[1][3]);
- EXPECT_EQ(76u, orig_pixels[2][0]);
- EXPECT_EQ(76u, orig_pixels[2][1]);
- EXPECT_EQ(76u, orig_pixels[2][2]);
- EXPECT_EQ(255u, orig_pixels[2][3]);
- EXPECT_EQ(0u, orig_pixels[3][0]);
- EXPECT_EQ(0u, orig_pixels[3][1]);
- EXPECT_EQ(0u, orig_pixels[3][2]);
- EXPECT_EQ(255u, orig_pixels[3][3]);
- EXPECT_EQ(255u, orig_pixels[4][0]);
- EXPECT_EQ(255u, orig_pixels[4][1]);
- EXPECT_EQ(255u, orig_pixels[4][2]);
- EXPECT_EQ(255u, orig_pixels[4][3]);
- EXPECT_EQ(96u, orig_pixels[5][0]);
- EXPECT_EQ(96u, orig_pixels[5][1]);
- EXPECT_EQ(96u, orig_pixels[5][2]);
- EXPECT_EQ(224u, orig_pixels[5][3]);
- for (int i = 0; i < 1280; ++i) {
- orig_pixels[i][0] = i;
- orig_pixels[i][1] = i / 2;
- orig_pixels[i][2] = i / 3;
- orig_pixels[i][3] = i;
- }
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
- ARGBGray(&orig_pixels[0][0], 0, 0, 0, 1280, 1);
- }
- }
- TEST_F(LibYUVPlanarTest, TestARGBGrayTo) {
- SIMD_ALIGNED(uint8_t orig_pixels[1280][4]);
- SIMD_ALIGNED(uint8_t gray_pixels[1280][4]);
- memset(orig_pixels, 0, sizeof(orig_pixels));
- // Test blue
- orig_pixels[0][0] = 255u;
- orig_pixels[0][1] = 0u;
- orig_pixels[0][2] = 0u;
- orig_pixels[0][3] = 128u;
- // Test green
- orig_pixels[1][0] = 0u;
- orig_pixels[1][1] = 255u;
- orig_pixels[1][2] = 0u;
- orig_pixels[1][3] = 0u;
- // Test red
- orig_pixels[2][0] = 0u;
- orig_pixels[2][1] = 0u;
- orig_pixels[2][2] = 255u;
- orig_pixels[2][3] = 255u;
- // Test black
- orig_pixels[3][0] = 0u;
- orig_pixels[3][1] = 0u;
- orig_pixels[3][2] = 0u;
- orig_pixels[3][3] = 255u;
- // Test white
- orig_pixels[4][0] = 255u;
- orig_pixels[4][1] = 255u;
- orig_pixels[4][2] = 255u;
- orig_pixels[4][3] = 255u;
- // Test color
- orig_pixels[5][0] = 16u;
- orig_pixels[5][1] = 64u;
- orig_pixels[5][2] = 192u;
- orig_pixels[5][3] = 224u;
- // Do 16 to test asm version.
- ARGBGrayTo(&orig_pixels[0][0], 0, &gray_pixels[0][0], 0, 16, 1);
- EXPECT_EQ(30u, gray_pixels[0][0]);
- EXPECT_EQ(30u, gray_pixels[0][1]);
- EXPECT_EQ(30u, gray_pixels[0][2]);
- EXPECT_EQ(128u, gray_pixels[0][3]);
- EXPECT_EQ(149u, gray_pixels[1][0]);
- EXPECT_EQ(149u, gray_pixels[1][1]);
- EXPECT_EQ(149u, gray_pixels[1][2]);
- EXPECT_EQ(0u, gray_pixels[1][3]);
- EXPECT_EQ(76u, gray_pixels[2][0]);
- EXPECT_EQ(76u, gray_pixels[2][1]);
- EXPECT_EQ(76u, gray_pixels[2][2]);
- EXPECT_EQ(255u, gray_pixels[2][3]);
- EXPECT_EQ(0u, gray_pixels[3][0]);
- EXPECT_EQ(0u, gray_pixels[3][1]);
- EXPECT_EQ(0u, gray_pixels[3][2]);
- EXPECT_EQ(255u, gray_pixels[3][3]);
- EXPECT_EQ(255u, gray_pixels[4][0]);
- EXPECT_EQ(255u, gray_pixels[4][1]);
- EXPECT_EQ(255u, gray_pixels[4][2]);
- EXPECT_EQ(255u, gray_pixels[4][3]);
- EXPECT_EQ(96u, gray_pixels[5][0]);
- EXPECT_EQ(96u, gray_pixels[5][1]);
- EXPECT_EQ(96u, gray_pixels[5][2]);
- EXPECT_EQ(224u, gray_pixels[5][3]);
- for (int i = 0; i < 1280; ++i) {
- orig_pixels[i][0] = i;
- orig_pixels[i][1] = i / 2;
- orig_pixels[i][2] = i / 3;
- orig_pixels[i][3] = i;
- }
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
- ARGBGrayTo(&orig_pixels[0][0], 0, &gray_pixels[0][0], 0, 1280, 1);
- }
- }
- TEST_F(LibYUVPlanarTest, TestARGBSepia) {
- SIMD_ALIGNED(uint8_t orig_pixels[1280][4]);
- memset(orig_pixels, 0, sizeof(orig_pixels));
- // Test blue
- orig_pixels[0][0] = 255u;
- orig_pixels[0][1] = 0u;
- orig_pixels[0][2] = 0u;
- orig_pixels[0][3] = 128u;
- // Test green
- orig_pixels[1][0] = 0u;
- orig_pixels[1][1] = 255u;
- orig_pixels[1][2] = 0u;
- orig_pixels[1][3] = 0u;
- // Test red
- orig_pixels[2][0] = 0u;
- orig_pixels[2][1] = 0u;
- orig_pixels[2][2] = 255u;
- orig_pixels[2][3] = 255u;
- // Test black
- orig_pixels[3][0] = 0u;
- orig_pixels[3][1] = 0u;
- orig_pixels[3][2] = 0u;
- orig_pixels[3][3] = 255u;
- // Test white
- orig_pixels[4][0] = 255u;
- orig_pixels[4][1] = 255u;
- orig_pixels[4][2] = 255u;
- orig_pixels[4][3] = 255u;
- // Test color
- orig_pixels[5][0] = 16u;
- orig_pixels[5][1] = 64u;
- orig_pixels[5][2] = 192u;
- orig_pixels[5][3] = 224u;
- // Do 16 to test asm version.
- ARGBSepia(&orig_pixels[0][0], 0, 0, 0, 16, 1);
- EXPECT_EQ(33u, orig_pixels[0][0]);
- EXPECT_EQ(43u, orig_pixels[0][1]);
- EXPECT_EQ(47u, orig_pixels[0][2]);
- EXPECT_EQ(128u, orig_pixels[0][3]);
- EXPECT_EQ(135u, orig_pixels[1][0]);
- EXPECT_EQ(175u, orig_pixels[1][1]);
- EXPECT_EQ(195u, orig_pixels[1][2]);
- EXPECT_EQ(0u, orig_pixels[1][3]);
- EXPECT_EQ(69u, orig_pixels[2][0]);
- EXPECT_EQ(89u, orig_pixels[2][1]);
- EXPECT_EQ(99u, orig_pixels[2][2]);
- EXPECT_EQ(255u, orig_pixels[2][3]);
- EXPECT_EQ(0u, orig_pixels[3][0]);
- EXPECT_EQ(0u, orig_pixels[3][1]);
- EXPECT_EQ(0u, orig_pixels[3][2]);
- EXPECT_EQ(255u, orig_pixels[3][3]);
- EXPECT_EQ(239u, orig_pixels[4][0]);
- EXPECT_EQ(255u, orig_pixels[4][1]);
- EXPECT_EQ(255u, orig_pixels[4][2]);
- EXPECT_EQ(255u, orig_pixels[4][3]);
- EXPECT_EQ(88u, orig_pixels[5][0]);
- EXPECT_EQ(114u, orig_pixels[5][1]);
- EXPECT_EQ(127u, orig_pixels[5][2]);
- EXPECT_EQ(224u, orig_pixels[5][3]);
- for (int i = 0; i < 1280; ++i) {
- orig_pixels[i][0] = i;
- orig_pixels[i][1] = i / 2;
- orig_pixels[i][2] = i / 3;
- orig_pixels[i][3] = i;
- }
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
- ARGBSepia(&orig_pixels[0][0], 0, 0, 0, 1280, 1);
- }
- }
- TEST_F(LibYUVPlanarTest, TestARGBColorMatrix) {
- SIMD_ALIGNED(uint8_t orig_pixels[1280][4]);
- SIMD_ALIGNED(uint8_t dst_pixels_opt[1280][4]);
- SIMD_ALIGNED(uint8_t dst_pixels_c[1280][4]);
- // Matrix for Sepia.
- SIMD_ALIGNED(static const int8_t kRGBToSepia[]) = {
- 17 / 2, 68 / 2, 35 / 2, 0, 22 / 2, 88 / 2, 45 / 2, 0,
- 24 / 2, 98 / 2, 50 / 2, 0, 0, 0, 0, 64, // Copy alpha.
- };
- memset(orig_pixels, 0, sizeof(orig_pixels));
- // Test blue
- orig_pixels[0][0] = 255u;
- orig_pixels[0][1] = 0u;
- orig_pixels[0][2] = 0u;
- orig_pixels[0][3] = 128u;
- // Test green
- orig_pixels[1][0] = 0u;
- orig_pixels[1][1] = 255u;
- orig_pixels[1][2] = 0u;
- orig_pixels[1][3] = 0u;
- // Test red
- orig_pixels[2][0] = 0u;
- orig_pixels[2][1] = 0u;
- orig_pixels[2][2] = 255u;
- orig_pixels[2][3] = 255u;
- // Test color
- orig_pixels[3][0] = 16u;
- orig_pixels[3][1] = 64u;
- orig_pixels[3][2] = 192u;
- orig_pixels[3][3] = 224u;
- // Do 16 to test asm version.
- ARGBColorMatrix(&orig_pixels[0][0], 0, &dst_pixels_opt[0][0], 0,
- &kRGBToSepia[0], 16, 1);
- EXPECT_EQ(31u, dst_pixels_opt[0][0]);
- EXPECT_EQ(43u, dst_pixels_opt[0][1]);
- EXPECT_EQ(47u, dst_pixels_opt[0][2]);
- EXPECT_EQ(128u, dst_pixels_opt[0][3]);
- EXPECT_EQ(135u, dst_pixels_opt[1][0]);
- EXPECT_EQ(175u, dst_pixels_opt[1][1]);
- EXPECT_EQ(195u, dst_pixels_opt[1][2]);
- EXPECT_EQ(0u, dst_pixels_opt[1][3]);
- EXPECT_EQ(67u, dst_pixels_opt[2][0]);
- EXPECT_EQ(87u, dst_pixels_opt[2][1]);
- EXPECT_EQ(99u, dst_pixels_opt[2][2]);
- EXPECT_EQ(255u, dst_pixels_opt[2][3]);
- EXPECT_EQ(87u, dst_pixels_opt[3][0]);
- EXPECT_EQ(112u, dst_pixels_opt[3][1]);
- EXPECT_EQ(127u, dst_pixels_opt[3][2]);
- EXPECT_EQ(224u, dst_pixels_opt[3][3]);
- for (int i = 0; i < 1280; ++i) {
- orig_pixels[i][0] = i;
- orig_pixels[i][1] = i / 2;
- orig_pixels[i][2] = i / 3;
- orig_pixels[i][3] = i;
- }
- MaskCpuFlags(disable_cpu_flags_);
- ARGBColorMatrix(&orig_pixels[0][0], 0, &dst_pixels_c[0][0], 0,
- &kRGBToSepia[0], 1280, 1);
- MaskCpuFlags(benchmark_cpu_info_);
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
- ARGBColorMatrix(&orig_pixels[0][0], 0, &dst_pixels_opt[0][0], 0,
- &kRGBToSepia[0], 1280, 1);
- }
- for (int i = 0; i < 1280; ++i) {
- EXPECT_EQ(dst_pixels_c[i][0], dst_pixels_opt[i][0]);
- EXPECT_EQ(dst_pixels_c[i][1], dst_pixels_opt[i][1]);
- EXPECT_EQ(dst_pixels_c[i][2], dst_pixels_opt[i][2]);
- EXPECT_EQ(dst_pixels_c[i][3], dst_pixels_opt[i][3]);
- }
- }
- TEST_F(LibYUVPlanarTest, TestRGBColorMatrix) {
- SIMD_ALIGNED(uint8_t orig_pixels[1280][4]);
- // Matrix for Sepia.
- SIMD_ALIGNED(static const int8_t kRGBToSepia[]) = {
- 17, 68, 35, 0, 22, 88, 45, 0,
- 24, 98, 50, 0, 0, 0, 0, 0, // Unused but makes matrix 16 bytes.
- };
- memset(orig_pixels, 0, sizeof(orig_pixels));
- // Test blue
- orig_pixels[0][0] = 255u;
- orig_pixels[0][1] = 0u;
- orig_pixels[0][2] = 0u;
- orig_pixels[0][3] = 128u;
- // Test green
- orig_pixels[1][0] = 0u;
- orig_pixels[1][1] = 255u;
- orig_pixels[1][2] = 0u;
- orig_pixels[1][3] = 0u;
- // Test red
- orig_pixels[2][0] = 0u;
- orig_pixels[2][1] = 0u;
- orig_pixels[2][2] = 255u;
- orig_pixels[2][3] = 255u;
- // Test color
- orig_pixels[3][0] = 16u;
- orig_pixels[3][1] = 64u;
- orig_pixels[3][2] = 192u;
- orig_pixels[3][3] = 224u;
- // Do 16 to test asm version.
- RGBColorMatrix(&orig_pixels[0][0], 0, &kRGBToSepia[0], 0, 0, 16, 1);
- EXPECT_EQ(31u, orig_pixels[0][0]);
- EXPECT_EQ(43u, orig_pixels[0][1]);
- EXPECT_EQ(47u, orig_pixels[0][2]);
- EXPECT_EQ(128u, orig_pixels[0][3]);
- EXPECT_EQ(135u, orig_pixels[1][0]);
- EXPECT_EQ(175u, orig_pixels[1][1]);
- EXPECT_EQ(195u, orig_pixels[1][2]);
- EXPECT_EQ(0u, orig_pixels[1][3]);
- EXPECT_EQ(67u, orig_pixels[2][0]);
- EXPECT_EQ(87u, orig_pixels[2][1]);
- EXPECT_EQ(99u, orig_pixels[2][2]);
- EXPECT_EQ(255u, orig_pixels[2][3]);
- EXPECT_EQ(87u, orig_pixels[3][0]);
- EXPECT_EQ(112u, orig_pixels[3][1]);
- EXPECT_EQ(127u, orig_pixels[3][2]);
- EXPECT_EQ(224u, orig_pixels[3][3]);
- for (int i = 0; i < 1280; ++i) {
- orig_pixels[i][0] = i;
- orig_pixels[i][1] = i / 2;
- orig_pixels[i][2] = i / 3;
- orig_pixels[i][3] = i;
- }
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
- RGBColorMatrix(&orig_pixels[0][0], 0, &kRGBToSepia[0], 0, 0, 1280, 1);
- }
- }
- TEST_F(LibYUVPlanarTest, TestARGBColorTable) {
- SIMD_ALIGNED(uint8_t orig_pixels[1280][4]);
- memset(orig_pixels, 0, sizeof(orig_pixels));
- // Matrix for Sepia.
- static const uint8_t kARGBTable[256 * 4] = {
- 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u, 16u,
- };
- orig_pixels[0][0] = 0u;
- orig_pixels[0][1] = 0u;
- orig_pixels[0][2] = 0u;
- orig_pixels[0][3] = 0u;
- orig_pixels[1][0] = 1u;
- orig_pixels[1][1] = 1u;
- orig_pixels[1][2] = 1u;
- orig_pixels[1][3] = 1u;
- orig_pixels[2][0] = 2u;
- orig_pixels[2][1] = 2u;
- orig_pixels[2][2] = 2u;
- orig_pixels[2][3] = 2u;
- orig_pixels[3][0] = 0u;
- orig_pixels[3][1] = 1u;
- orig_pixels[3][2] = 2u;
- orig_pixels[3][3] = 3u;
- // Do 16 to test asm version.
- ARGBColorTable(&orig_pixels[0][0], 0, &kARGBTable[0], 0, 0, 16, 1);
- EXPECT_EQ(1u, orig_pixels[0][0]);
- EXPECT_EQ(2u, orig_pixels[0][1]);
- EXPECT_EQ(3u, orig_pixels[0][2]);
- EXPECT_EQ(4u, orig_pixels[0][3]);
- EXPECT_EQ(5u, orig_pixels[1][0]);
- EXPECT_EQ(6u, orig_pixels[1][1]);
- EXPECT_EQ(7u, orig_pixels[1][2]);
- EXPECT_EQ(8u, orig_pixels[1][3]);
- EXPECT_EQ(9u, orig_pixels[2][0]);
- EXPECT_EQ(10u, orig_pixels[2][1]);
- EXPECT_EQ(11u, orig_pixels[2][2]);
- EXPECT_EQ(12u, orig_pixels[2][3]);
- EXPECT_EQ(1u, orig_pixels[3][0]);
- EXPECT_EQ(6u, orig_pixels[3][1]);
- EXPECT_EQ(11u, orig_pixels[3][2]);
- EXPECT_EQ(16u, orig_pixels[3][3]);
- for (int i = 0; i < 1280; ++i) {
- orig_pixels[i][0] = i;
- orig_pixels[i][1] = i / 2;
- orig_pixels[i][2] = i / 3;
- orig_pixels[i][3] = i;
- }
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
- ARGBColorTable(&orig_pixels[0][0], 0, &kARGBTable[0], 0, 0, 1280, 1);
- }
- }
- // Same as TestARGBColorTable except alpha does not change.
- TEST_F(LibYUVPlanarTest, TestRGBColorTable) {
- SIMD_ALIGNED(uint8_t orig_pixels[1280][4]);
- memset(orig_pixels, 0, sizeof(orig_pixels));
- // Matrix for Sepia.
- static const uint8_t kARGBTable[256 * 4] = {
- 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u, 16u,
- };
- orig_pixels[0][0] = 0u;
- orig_pixels[0][1] = 0u;
- orig_pixels[0][2] = 0u;
- orig_pixels[0][3] = 0u;
- orig_pixels[1][0] = 1u;
- orig_pixels[1][1] = 1u;
- orig_pixels[1][2] = 1u;
- orig_pixels[1][3] = 1u;
- orig_pixels[2][0] = 2u;
- orig_pixels[2][1] = 2u;
- orig_pixels[2][2] = 2u;
- orig_pixels[2][3] = 2u;
- orig_pixels[3][0] = 0u;
- orig_pixels[3][1] = 1u;
- orig_pixels[3][2] = 2u;
- orig_pixels[3][3] = 3u;
- // Do 16 to test asm version.
- RGBColorTable(&orig_pixels[0][0], 0, &kARGBTable[0], 0, 0, 16, 1);
- EXPECT_EQ(1u, orig_pixels[0][0]);
- EXPECT_EQ(2u, orig_pixels[0][1]);
- EXPECT_EQ(3u, orig_pixels[0][2]);
- EXPECT_EQ(0u, orig_pixels[0][3]); // Alpha unchanged.
- EXPECT_EQ(5u, orig_pixels[1][0]);
- EXPECT_EQ(6u, orig_pixels[1][1]);
- EXPECT_EQ(7u, orig_pixels[1][2]);
- EXPECT_EQ(1u, orig_pixels[1][3]); // Alpha unchanged.
- EXPECT_EQ(9u, orig_pixels[2][0]);
- EXPECT_EQ(10u, orig_pixels[2][1]);
- EXPECT_EQ(11u, orig_pixels[2][2]);
- EXPECT_EQ(2u, orig_pixels[2][3]); // Alpha unchanged.
- EXPECT_EQ(1u, orig_pixels[3][0]);
- EXPECT_EQ(6u, orig_pixels[3][1]);
- EXPECT_EQ(11u, orig_pixels[3][2]);
- EXPECT_EQ(3u, orig_pixels[3][3]); // Alpha unchanged.
- for (int i = 0; i < 1280; ++i) {
- orig_pixels[i][0] = i;
- orig_pixels[i][1] = i / 2;
- orig_pixels[i][2] = i / 3;
- orig_pixels[i][3] = i;
- }
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
- RGBColorTable(&orig_pixels[0][0], 0, &kARGBTable[0], 0, 0, 1280, 1);
- }
- }
- TEST_F(LibYUVPlanarTest, TestARGBQuantize) {
- SIMD_ALIGNED(uint8_t orig_pixels[1280][4]);
- for (int i = 0; i < 1280; ++i) {
- orig_pixels[i][0] = i;
- orig_pixels[i][1] = i / 2;
- orig_pixels[i][2] = i / 3;
- orig_pixels[i][3] = i;
- }
- ARGBQuantize(&orig_pixels[0][0], 0, (65536 + (8 / 2)) / 8, 8, 8 / 2, 0, 0,
- 1280, 1);
- for (int i = 0; i < 1280; ++i) {
- EXPECT_EQ((i / 8 * 8 + 8 / 2) & 255, orig_pixels[i][0]);
- EXPECT_EQ((i / 2 / 8 * 8 + 8 / 2) & 255, orig_pixels[i][1]);
- EXPECT_EQ((i / 3 / 8 * 8 + 8 / 2) & 255, orig_pixels[i][2]);
- EXPECT_EQ(i & 255, orig_pixels[i][3]);
- }
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
- ARGBQuantize(&orig_pixels[0][0], 0, (65536 + (8 / 2)) / 8, 8, 8 / 2, 0, 0,
- 1280, 1);
- }
- }
- TEST_F(LibYUVPlanarTest, TestARGBMirror) {
- SIMD_ALIGNED(uint8_t orig_pixels[1280][4]);
- SIMD_ALIGNED(uint8_t dst_pixels[1280][4]);
- for (int i = 0; i < 1280; ++i) {
- orig_pixels[i][0] = i;
- orig_pixels[i][1] = i / 2;
- orig_pixels[i][2] = i / 3;
- orig_pixels[i][3] = i / 4;
- }
- ARGBMirror(&orig_pixels[0][0], 0, &dst_pixels[0][0], 0, 1280, 1);
- for (int i = 0; i < 1280; ++i) {
- EXPECT_EQ(i & 255, dst_pixels[1280 - 1 - i][0]);
- EXPECT_EQ((i / 2) & 255, dst_pixels[1280 - 1 - i][1]);
- EXPECT_EQ((i / 3) & 255, dst_pixels[1280 - 1 - i][2]);
- EXPECT_EQ((i / 4) & 255, dst_pixels[1280 - 1 - i][3]);
- }
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
- ARGBMirror(&orig_pixels[0][0], 0, &dst_pixels[0][0], 0, 1280, 1);
- }
- }
- TEST_F(LibYUVPlanarTest, TestShade) {
- SIMD_ALIGNED(uint8_t orig_pixels[1280][4]);
- SIMD_ALIGNED(uint8_t shade_pixels[1280][4]);
- memset(orig_pixels, 0, sizeof(orig_pixels));
- orig_pixels[0][0] = 10u;
- orig_pixels[0][1] = 20u;
- orig_pixels[0][2] = 40u;
- orig_pixels[0][3] = 80u;
- orig_pixels[1][0] = 0u;
- orig_pixels[1][1] = 0u;
- orig_pixels[1][2] = 0u;
- orig_pixels[1][3] = 255u;
- orig_pixels[2][0] = 0u;
- orig_pixels[2][1] = 0u;
- orig_pixels[2][2] = 0u;
- orig_pixels[2][3] = 0u;
- orig_pixels[3][0] = 0u;
- orig_pixels[3][1] = 0u;
- orig_pixels[3][2] = 0u;
- orig_pixels[3][3] = 0u;
- // Do 8 pixels to allow opt version to be used.
- ARGBShade(&orig_pixels[0][0], 0, &shade_pixels[0][0], 0, 8, 1, 0x80ffffff);
- EXPECT_EQ(10u, shade_pixels[0][0]);
- EXPECT_EQ(20u, shade_pixels[0][1]);
- EXPECT_EQ(40u, shade_pixels[0][2]);
- EXPECT_EQ(40u, shade_pixels[0][3]);
- EXPECT_EQ(0u, shade_pixels[1][0]);
- EXPECT_EQ(0u, shade_pixels[1][1]);
- EXPECT_EQ(0u, shade_pixels[1][2]);
- EXPECT_EQ(128u, shade_pixels[1][3]);
- EXPECT_EQ(0u, shade_pixels[2][0]);
- EXPECT_EQ(0u, shade_pixels[2][1]);
- EXPECT_EQ(0u, shade_pixels[2][2]);
- EXPECT_EQ(0u, shade_pixels[2][3]);
- EXPECT_EQ(0u, shade_pixels[3][0]);
- EXPECT_EQ(0u, shade_pixels[3][1]);
- EXPECT_EQ(0u, shade_pixels[3][2]);
- EXPECT_EQ(0u, shade_pixels[3][3]);
- ARGBShade(&orig_pixels[0][0], 0, &shade_pixels[0][0], 0, 8, 1, 0x80808080);
- EXPECT_EQ(5u, shade_pixels[0][0]);
- EXPECT_EQ(10u, shade_pixels[0][1]);
- EXPECT_EQ(20u, shade_pixels[0][2]);
- EXPECT_EQ(40u, shade_pixels[0][3]);
- ARGBShade(&orig_pixels[0][0], 0, &shade_pixels[0][0], 0, 8, 1, 0x10204080);
- EXPECT_EQ(5u, shade_pixels[0][0]);
- EXPECT_EQ(5u, shade_pixels[0][1]);
- EXPECT_EQ(5u, shade_pixels[0][2]);
- EXPECT_EQ(5u, shade_pixels[0][3]);
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
- ARGBShade(&orig_pixels[0][0], 0, &shade_pixels[0][0], 0, 1280, 1,
- 0x80808080);
- }
- }
- TEST_F(LibYUVPlanarTest, TestARGBInterpolate) {
- SIMD_ALIGNED(uint8_t orig_pixels_0[1280][4]);
- SIMD_ALIGNED(uint8_t orig_pixels_1[1280][4]);
- SIMD_ALIGNED(uint8_t interpolate_pixels[1280][4]);
- memset(orig_pixels_0, 0, sizeof(orig_pixels_0));
- memset(orig_pixels_1, 0, sizeof(orig_pixels_1));
- orig_pixels_0[0][0] = 16u;
- orig_pixels_0[0][1] = 32u;
- orig_pixels_0[0][2] = 64u;
- orig_pixels_0[0][3] = 128u;
- orig_pixels_0[1][0] = 0u;
- orig_pixels_0[1][1] = 0u;
- orig_pixels_0[1][2] = 0u;
- orig_pixels_0[1][3] = 255u;
- orig_pixels_0[2][0] = 0u;
- orig_pixels_0[2][1] = 0u;
- orig_pixels_0[2][2] = 0u;
- orig_pixels_0[2][3] = 0u;
- orig_pixels_0[3][0] = 0u;
- orig_pixels_0[3][1] = 0u;
- orig_pixels_0[3][2] = 0u;
- orig_pixels_0[3][3] = 0u;
- orig_pixels_1[0][0] = 0u;
- orig_pixels_1[0][1] = 0u;
- orig_pixels_1[0][2] = 0u;
- orig_pixels_1[0][3] = 0u;
- orig_pixels_1[1][0] = 0u;
- orig_pixels_1[1][1] = 0u;
- orig_pixels_1[1][2] = 0u;
- orig_pixels_1[1][3] = 0u;
- orig_pixels_1[2][0] = 0u;
- orig_pixels_1[2][1] = 0u;
- orig_pixels_1[2][2] = 0u;
- orig_pixels_1[2][3] = 0u;
- orig_pixels_1[3][0] = 255u;
- orig_pixels_1[3][1] = 255u;
- orig_pixels_1[3][2] = 255u;
- orig_pixels_1[3][3] = 255u;
- ARGBInterpolate(&orig_pixels_0[0][0], 0, &orig_pixels_1[0][0], 0,
- &interpolate_pixels[0][0], 0, 4, 1, 128);
- EXPECT_EQ(8u, interpolate_pixels[0][0]);
- EXPECT_EQ(16u, interpolate_pixels[0][1]);
- EXPECT_EQ(32u, interpolate_pixels[0][2]);
- EXPECT_EQ(64u, interpolate_pixels[0][3]);
- EXPECT_EQ(0u, interpolate_pixels[1][0]);
- EXPECT_EQ(0u, interpolate_pixels[1][1]);
- EXPECT_EQ(0u, interpolate_pixels[1][2]);
- EXPECT_EQ(128u, interpolate_pixels[1][3]);
- EXPECT_EQ(0u, interpolate_pixels[2][0]);
- EXPECT_EQ(0u, interpolate_pixels[2][1]);
- EXPECT_EQ(0u, interpolate_pixels[2][2]);
- EXPECT_EQ(0u, interpolate_pixels[2][3]);
- EXPECT_EQ(128u, interpolate_pixels[3][0]);
- EXPECT_EQ(128u, interpolate_pixels[3][1]);
- EXPECT_EQ(128u, interpolate_pixels[3][2]);
- EXPECT_EQ(128u, interpolate_pixels[3][3]);
- ARGBInterpolate(&orig_pixels_0[0][0], 0, &orig_pixels_1[0][0], 0,
- &interpolate_pixels[0][0], 0, 4, 1, 0);
- EXPECT_EQ(16u, interpolate_pixels[0][0]);
- EXPECT_EQ(32u, interpolate_pixels[0][1]);
- EXPECT_EQ(64u, interpolate_pixels[0][2]);
- EXPECT_EQ(128u, interpolate_pixels[0][3]);
- ARGBInterpolate(&orig_pixels_0[0][0], 0, &orig_pixels_1[0][0], 0,
- &interpolate_pixels[0][0], 0, 4, 1, 192);
- EXPECT_EQ(4u, interpolate_pixels[0][0]);
- EXPECT_EQ(8u, interpolate_pixels[0][1]);
- EXPECT_EQ(16u, interpolate_pixels[0][2]);
- EXPECT_EQ(32u, interpolate_pixels[0][3]);
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
- ARGBInterpolate(&orig_pixels_0[0][0], 0, &orig_pixels_1[0][0], 0,
- &interpolate_pixels[0][0], 0, 1280, 1, 128);
- }
- }
- TEST_F(LibYUVPlanarTest, TestInterpolatePlane) {
- SIMD_ALIGNED(uint8_t orig_pixels_0[1280]);
- SIMD_ALIGNED(uint8_t orig_pixels_1[1280]);
- SIMD_ALIGNED(uint8_t interpolate_pixels[1280]);
- memset(orig_pixels_0, 0, sizeof(orig_pixels_0));
- memset(orig_pixels_1, 0, sizeof(orig_pixels_1));
- orig_pixels_0[0] = 16u;
- orig_pixels_0[1] = 32u;
- orig_pixels_0[2] = 64u;
- orig_pixels_0[3] = 128u;
- orig_pixels_0[4] = 0u;
- orig_pixels_0[5] = 0u;
- orig_pixels_0[6] = 0u;
- orig_pixels_0[7] = 255u;
- orig_pixels_0[8] = 0u;
- orig_pixels_0[9] = 0u;
- orig_pixels_0[10] = 0u;
- orig_pixels_0[11] = 0u;
- orig_pixels_0[12] = 0u;
- orig_pixels_0[13] = 0u;
- orig_pixels_0[14] = 0u;
- orig_pixels_0[15] = 0u;
- orig_pixels_1[0] = 0u;
- orig_pixels_1[1] = 0u;
- orig_pixels_1[2] = 0u;
- orig_pixels_1[3] = 0u;
- orig_pixels_1[4] = 0u;
- orig_pixels_1[5] = 0u;
- orig_pixels_1[6] = 0u;
- orig_pixels_1[7] = 0u;
- orig_pixels_1[8] = 0u;
- orig_pixels_1[9] = 0u;
- orig_pixels_1[10] = 0u;
- orig_pixels_1[11] = 0u;
- orig_pixels_1[12] = 255u;
- orig_pixels_1[13] = 255u;
- orig_pixels_1[14] = 255u;
- orig_pixels_1[15] = 255u;
- InterpolatePlane(&orig_pixels_0[0], 0, &orig_pixels_1[0], 0,
- &interpolate_pixels[0], 0, 16, 1, 128);
- EXPECT_EQ(8u, interpolate_pixels[0]);
- EXPECT_EQ(16u, interpolate_pixels[1]);
- EXPECT_EQ(32u, interpolate_pixels[2]);
- EXPECT_EQ(64u, interpolate_pixels[3]);
- EXPECT_EQ(0u, interpolate_pixels[4]);
- EXPECT_EQ(0u, interpolate_pixels[5]);
- EXPECT_EQ(0u, interpolate_pixels[6]);
- EXPECT_EQ(128u, interpolate_pixels[7]);
- EXPECT_EQ(0u, interpolate_pixels[8]);
- EXPECT_EQ(0u, interpolate_pixels[9]);
- EXPECT_EQ(0u, interpolate_pixels[10]);
- EXPECT_EQ(0u, interpolate_pixels[11]);
- EXPECT_EQ(128u, interpolate_pixels[12]);
- EXPECT_EQ(128u, interpolate_pixels[13]);
- EXPECT_EQ(128u, interpolate_pixels[14]);
- EXPECT_EQ(128u, interpolate_pixels[15]);
- InterpolatePlane(&orig_pixels_0[0], 0, &orig_pixels_1[0], 0,
- &interpolate_pixels[0], 0, 16, 1, 0);
- EXPECT_EQ(16u, interpolate_pixels[0]);
- EXPECT_EQ(32u, interpolate_pixels[1]);
- EXPECT_EQ(64u, interpolate_pixels[2]);
- EXPECT_EQ(128u, interpolate_pixels[3]);
- InterpolatePlane(&orig_pixels_0[0], 0, &orig_pixels_1[0], 0,
- &interpolate_pixels[0], 0, 16, 1, 192);
- EXPECT_EQ(4u, interpolate_pixels[0]);
- EXPECT_EQ(8u, interpolate_pixels[1]);
- EXPECT_EQ(16u, interpolate_pixels[2]);
- EXPECT_EQ(32u, interpolate_pixels[3]);
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
- InterpolatePlane(&orig_pixels_0[0], 0, &orig_pixels_1[0], 0,
- &interpolate_pixels[0], 0, 1280, 1, 123);
- }
- }
- #define TESTTERP(FMT_A, BPP_A, STRIDE_A, FMT_B, BPP_B, STRIDE_B, W1280, TERP, \
- N, NEG, OFF) \
- TEST_F(LibYUVPlanarTest, ARGBInterpolate##TERP##N) { \
- const int kWidth = ((W1280) > 0) ? (W1280) : 1; \
- const int kHeight = benchmark_height_; \
- const int kStrideA = \
- (kWidth * BPP_A + STRIDE_A - 1) / STRIDE_A * STRIDE_A; \
- const int kStrideB = \
- (kWidth * BPP_B + STRIDE_B - 1) / STRIDE_B * STRIDE_B; \
- align_buffer_page_end(src_argb_a, kStrideA* kHeight + OFF); \
- align_buffer_page_end(src_argb_b, kStrideA* kHeight + OFF); \
- align_buffer_page_end(dst_argb_c, kStrideB* kHeight); \
- align_buffer_page_end(dst_argb_opt, kStrideB* kHeight); \
- for (int i = 0; i < kStrideA * kHeight; ++i) { \
- src_argb_a[i + OFF] = (fastrand() & 0xff); \
- src_argb_b[i + OFF] = (fastrand() & 0xff); \
- } \
- MaskCpuFlags(disable_cpu_flags_); \
- ARGBInterpolate(src_argb_a + OFF, kStrideA, src_argb_b + OFF, kStrideA, \
- dst_argb_c, kStrideB, kWidth, NEG kHeight, TERP); \
- MaskCpuFlags(benchmark_cpu_info_); \
- for (int i = 0; i < benchmark_iterations_; ++i) { \
- ARGBInterpolate(src_argb_a + OFF, kStrideA, src_argb_b + OFF, kStrideA, \
- dst_argb_opt, kStrideB, kWidth, NEG kHeight, TERP); \
- } \
- for (int i = 0; i < kStrideB * kHeight; ++i) { \
- EXPECT_EQ(dst_argb_c[i], dst_argb_opt[i]); \
- } \
- free_aligned_buffer_page_end(src_argb_a); \
- free_aligned_buffer_page_end(src_argb_b); \
- free_aligned_buffer_page_end(dst_argb_c); \
- free_aligned_buffer_page_end(dst_argb_opt); \
- }
- #define TESTINTERPOLATE(TERP) \
- TESTTERP(ARGB, 4, 1, ARGB, 4, 1, benchmark_width_ - 1, TERP, _Any, +, 0) \
- TESTTERP(ARGB, 4, 1, ARGB, 4, 1, benchmark_width_, TERP, _Unaligned, +, 1) \
- TESTTERP(ARGB, 4, 1, ARGB, 4, 1, benchmark_width_, TERP, _Invert, -, 0) \
- TESTTERP(ARGB, 4, 1, ARGB, 4, 1, benchmark_width_, TERP, _Opt, +, 0)
- TESTINTERPOLATE(0)
- TESTINTERPOLATE(64)
- TESTINTERPOLATE(128)
- TESTINTERPOLATE(192)
- TESTINTERPOLATE(255)
- static int TestBlend(int width,
- int height,
- int benchmark_iterations,
- int disable_cpu_flags,
- int benchmark_cpu_info,
- int invert,
- int off) {
- if (width < 1) {
- width = 1;
- }
- const int kBpp = 4;
- const int kStride = width * kBpp;
- align_buffer_page_end(src_argb_a, kStride * height + off);
- align_buffer_page_end(src_argb_b, kStride * height + off);
- align_buffer_page_end(dst_argb_c, kStride * height);
- align_buffer_page_end(dst_argb_opt, kStride * height);
- for (int i = 0; i < kStride * height; ++i) {
- src_argb_a[i + off] = (fastrand() & 0xff);
- src_argb_b[i + off] = (fastrand() & 0xff);
- }
- ARGBAttenuate(src_argb_a + off, kStride, src_argb_a + off, kStride, width,
- height);
- ARGBAttenuate(src_argb_b + off, kStride, src_argb_b + off, kStride, width,
- height);
- memset(dst_argb_c, 255, kStride * height);
- memset(dst_argb_opt, 255, kStride * height);
- MaskCpuFlags(disable_cpu_flags);
- ARGBBlend(src_argb_a + off, kStride, src_argb_b + off, kStride, dst_argb_c,
- kStride, width, invert * height);
- MaskCpuFlags(benchmark_cpu_info);
- for (int i = 0; i < benchmark_iterations; ++i) {
- ARGBBlend(src_argb_a + off, kStride, src_argb_b + off, kStride,
- dst_argb_opt, kStride, width, invert * height);
- }
- int max_diff = 0;
- for (int i = 0; i < kStride * height; ++i) {
- int abs_diff = abs(static_cast<int>(dst_argb_c[i]) -
- static_cast<int>(dst_argb_opt[i]));
- if (abs_diff > max_diff) {
- max_diff = abs_diff;
- }
- }
- free_aligned_buffer_page_end(src_argb_a);
- free_aligned_buffer_page_end(src_argb_b);
- free_aligned_buffer_page_end(dst_argb_c);
- free_aligned_buffer_page_end(dst_argb_opt);
- return max_diff;
- }
- TEST_F(LibYUVPlanarTest, ARGBBlend_Any) {
- int max_diff =
- TestBlend(benchmark_width_ - 4, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBBlend_Unaligned) {
- int max_diff =
- TestBlend(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 1);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBBlend_Invert) {
- int max_diff =
- TestBlend(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, -1, 0);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBBlend_Opt) {
- int max_diff =
- TestBlend(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0);
- EXPECT_LE(max_diff, 1);
- }
- static void TestBlendPlane(int width,
- int height,
- int benchmark_iterations,
- int disable_cpu_flags,
- int benchmark_cpu_info,
- int invert,
- int off) {
- if (width < 1) {
- width = 1;
- }
- const int kBpp = 1;
- const int kStride = width * kBpp;
- align_buffer_page_end(src_argb_a, kStride * height + off);
- align_buffer_page_end(src_argb_b, kStride * height + off);
- align_buffer_page_end(src_argb_alpha, kStride * height + off);
- align_buffer_page_end(dst_argb_c, kStride * height + off);
- align_buffer_page_end(dst_argb_opt, kStride * height + off);
- memset(dst_argb_c, 255, kStride * height + off);
- memset(dst_argb_opt, 255, kStride * height + off);
- // Test source is maintained exactly if alpha is 255.
- for (int i = 0; i < width; ++i) {
- src_argb_a[i + off] = i & 255;
- src_argb_b[i + off] = 255 - (i & 255);
- }
- memset(src_argb_alpha + off, 255, width);
- BlendPlane(src_argb_a + off, width, src_argb_b + off, width,
- src_argb_alpha + off, width, dst_argb_opt + off, width, width, 1);
- for (int i = 0; i < width; ++i) {
- EXPECT_EQ(src_argb_a[i + off], dst_argb_opt[i + off]);
- }
- // Test destination is maintained exactly if alpha is 0.
- memset(src_argb_alpha + off, 0, width);
- BlendPlane(src_argb_a + off, width, src_argb_b + off, width,
- src_argb_alpha + off, width, dst_argb_opt + off, width, width, 1);
- for (int i = 0; i < width; ++i) {
- EXPECT_EQ(src_argb_b[i + off], dst_argb_opt[i + off]);
- }
- for (int i = 0; i < kStride * height; ++i) {
- src_argb_a[i + off] = (fastrand() & 0xff);
- src_argb_b[i + off] = (fastrand() & 0xff);
- src_argb_alpha[i + off] = (fastrand() & 0xff);
- }
- MaskCpuFlags(disable_cpu_flags);
- BlendPlane(src_argb_a + off, width, src_argb_b + off, width,
- src_argb_alpha + off, width, dst_argb_c + off, width, width,
- invert * height);
- MaskCpuFlags(benchmark_cpu_info);
- for (int i = 0; i < benchmark_iterations; ++i) {
- BlendPlane(src_argb_a + off, width, src_argb_b + off, width,
- src_argb_alpha + off, width, dst_argb_opt + off, width, width,
- invert * height);
- }
- for (int i = 0; i < kStride * height; ++i) {
- EXPECT_EQ(dst_argb_c[i + off], dst_argb_opt[i + off]);
- }
- free_aligned_buffer_page_end(src_argb_a);
- free_aligned_buffer_page_end(src_argb_b);
- free_aligned_buffer_page_end(src_argb_alpha);
- free_aligned_buffer_page_end(dst_argb_c);
- free_aligned_buffer_page_end(dst_argb_opt);
- }
- TEST_F(LibYUVPlanarTest, BlendPlane_Opt) {
- TestBlendPlane(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0);
- }
- TEST_F(LibYUVPlanarTest, BlendPlane_Unaligned) {
- TestBlendPlane(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 1);
- }
- TEST_F(LibYUVPlanarTest, BlendPlane_Any) {
- TestBlendPlane(benchmark_width_ - 4, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 1);
- }
- TEST_F(LibYUVPlanarTest, BlendPlane_Invert) {
- TestBlendPlane(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, -1, 1);
- }
- #define SUBSAMPLE(v, a) ((((v) + (a)-1)) / (a))
- static void TestI420Blend(int width,
- int height,
- int benchmark_iterations,
- int disable_cpu_flags,
- int benchmark_cpu_info,
- int invert,
- int off) {
- width = ((width) > 0) ? (width) : 1;
- const int kStrideUV = SUBSAMPLE(width, 2);
- const int kSizeUV = kStrideUV * SUBSAMPLE(height, 2);
- align_buffer_page_end(src_y0, width * height + off);
- align_buffer_page_end(src_u0, kSizeUV + off);
- align_buffer_page_end(src_v0, kSizeUV + off);
- align_buffer_page_end(src_y1, width * height + off);
- align_buffer_page_end(src_u1, kSizeUV + off);
- align_buffer_page_end(src_v1, kSizeUV + off);
- align_buffer_page_end(src_a, width * height + off);
- align_buffer_page_end(dst_y_c, width * height + off);
- align_buffer_page_end(dst_u_c, kSizeUV + off);
- align_buffer_page_end(dst_v_c, kSizeUV + off);
- align_buffer_page_end(dst_y_opt, width * height + off);
- align_buffer_page_end(dst_u_opt, kSizeUV + off);
- align_buffer_page_end(dst_v_opt, kSizeUV + off);
- MemRandomize(src_y0, width * height + off);
- MemRandomize(src_u0, kSizeUV + off);
- MemRandomize(src_v0, kSizeUV + off);
- MemRandomize(src_y1, width * height + off);
- MemRandomize(src_u1, kSizeUV + off);
- MemRandomize(src_v1, kSizeUV + off);
- MemRandomize(src_a, width * height + off);
- memset(dst_y_c, 255, width * height + off);
- memset(dst_u_c, 255, kSizeUV + off);
- memset(dst_v_c, 255, kSizeUV + off);
- memset(dst_y_opt, 255, width * height + off);
- memset(dst_u_opt, 255, kSizeUV + off);
- memset(dst_v_opt, 255, kSizeUV + off);
- MaskCpuFlags(disable_cpu_flags);
- I420Blend(src_y0 + off, width, src_u0 + off, kStrideUV, src_v0 + off,
- kStrideUV, src_y1 + off, width, src_u1 + off, kStrideUV,
- src_v1 + off, kStrideUV, src_a + off, width, dst_y_c + off, width,
- dst_u_c + off, kStrideUV, dst_v_c + off, kStrideUV, width,
- invert * height);
- MaskCpuFlags(benchmark_cpu_info);
- for (int i = 0; i < benchmark_iterations; ++i) {
- I420Blend(src_y0 + off, width, src_u0 + off, kStrideUV, src_v0 + off,
- kStrideUV, src_y1 + off, width, src_u1 + off, kStrideUV,
- src_v1 + off, kStrideUV, src_a + off, width, dst_y_opt + off,
- width, dst_u_opt + off, kStrideUV, dst_v_opt + off, kStrideUV,
- width, invert * height);
- }
- for (int i = 0; i < width * height; ++i) {
- EXPECT_EQ(dst_y_c[i + off], dst_y_opt[i + off]);
- }
- for (int i = 0; i < kSizeUV; ++i) {
- EXPECT_EQ(dst_u_c[i + off], dst_u_opt[i + off]);
- EXPECT_EQ(dst_v_c[i + off], dst_v_opt[i + off]);
- }
- free_aligned_buffer_page_end(src_y0);
- free_aligned_buffer_page_end(src_u0);
- free_aligned_buffer_page_end(src_v0);
- free_aligned_buffer_page_end(src_y1);
- free_aligned_buffer_page_end(src_u1);
- free_aligned_buffer_page_end(src_v1);
- free_aligned_buffer_page_end(src_a);
- free_aligned_buffer_page_end(dst_y_c);
- free_aligned_buffer_page_end(dst_u_c);
- free_aligned_buffer_page_end(dst_v_c);
- free_aligned_buffer_page_end(dst_y_opt);
- free_aligned_buffer_page_end(dst_u_opt);
- free_aligned_buffer_page_end(dst_v_opt);
- }
- TEST_F(LibYUVPlanarTest, I420Blend_Opt) {
- TestI420Blend(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0);
- }
- TEST_F(LibYUVPlanarTest, I420Blend_Unaligned) {
- TestI420Blend(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 1);
- }
- // TODO(fbarchard): DISABLED because _Any uses C. Avoid C and re-enable.
- TEST_F(LibYUVPlanarTest, DISABLED_I420Blend_Any) {
- TestI420Blend(benchmark_width_ - 4, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0);
- }
- TEST_F(LibYUVPlanarTest, I420Blend_Invert) {
- TestI420Blend(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, -1, 0);
- }
- TEST_F(LibYUVPlanarTest, TestAffine) {
- SIMD_ALIGNED(uint8_t orig_pixels_0[1280][4]);
- SIMD_ALIGNED(uint8_t interpolate_pixels_C[1280][4]);
- for (int i = 0; i < 1280; ++i) {
- for (int j = 0; j < 4; ++j) {
- orig_pixels_0[i][j] = i;
- }
- }
- float uv_step[4] = {0.f, 0.f, 0.75f, 0.f};
- ARGBAffineRow_C(&orig_pixels_0[0][0], 0, &interpolate_pixels_C[0][0], uv_step,
- 1280);
- EXPECT_EQ(0u, interpolate_pixels_C[0][0]);
- EXPECT_EQ(96u, interpolate_pixels_C[128][0]);
- EXPECT_EQ(191u, interpolate_pixels_C[255][3]);
- #if defined(HAS_ARGBAFFINEROW_SSE2)
- SIMD_ALIGNED(uint8_t interpolate_pixels_Opt[1280][4]);
- ARGBAffineRow_SSE2(&orig_pixels_0[0][0], 0, &interpolate_pixels_Opt[0][0],
- uv_step, 1280);
- EXPECT_EQ(0, memcmp(interpolate_pixels_Opt, interpolate_pixels_C, 1280 * 4));
- int has_sse2 = TestCpuFlag(kCpuHasSSE2);
- if (has_sse2) {
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
- ARGBAffineRow_SSE2(&orig_pixels_0[0][0], 0, &interpolate_pixels_Opt[0][0],
- uv_step, 1280);
- }
- }
- #endif
- }
- TEST_F(LibYUVPlanarTest, TestCopyPlane) {
- int err = 0;
- int yw = benchmark_width_;
- int yh = benchmark_height_;
- int b = 12;
- int i, j;
- int y_plane_size = (yw + b * 2) * (yh + b * 2);
- align_buffer_page_end(orig_y, y_plane_size);
- align_buffer_page_end(dst_c, y_plane_size);
- align_buffer_page_end(dst_opt, y_plane_size);
- memset(orig_y, 0, y_plane_size);
- memset(dst_c, 0, y_plane_size);
- memset(dst_opt, 0, y_plane_size);
- // Fill image buffers with random data.
- for (i = b; i < (yh + b); ++i) {
- for (j = b; j < (yw + b); ++j) {
- orig_y[i * (yw + b * 2) + j] = fastrand() & 0xff;
- }
- }
- // Fill destination buffers with random data.
- for (i = 0; i < y_plane_size; ++i) {
- uint8_t random_number = fastrand() & 0x7f;
- dst_c[i] = random_number;
- dst_opt[i] = dst_c[i];
- }
- int y_off = b * (yw + b * 2) + b;
- int y_st = yw + b * 2;
- int stride = 8;
- // Disable all optimizations.
- MaskCpuFlags(disable_cpu_flags_);
- for (j = 0; j < benchmark_iterations_; j++) {
- CopyPlane(orig_y + y_off, y_st, dst_c + y_off, stride, yw, yh);
- }
- // Enable optimizations.
- MaskCpuFlags(benchmark_cpu_info_);
- for (j = 0; j < benchmark_iterations_; j++) {
- CopyPlane(orig_y + y_off, y_st, dst_opt + y_off, stride, yw, yh);
- }
- for (i = 0; i < y_plane_size; ++i) {
- if (dst_c[i] != dst_opt[i]) {
- ++err;
- }
- }
- free_aligned_buffer_page_end(orig_y);
- free_aligned_buffer_page_end(dst_c);
- free_aligned_buffer_page_end(dst_opt);
- EXPECT_EQ(0, err);
- }
- static int TestMultiply(int width,
- int height,
- int benchmark_iterations,
- int disable_cpu_flags,
- int benchmark_cpu_info,
- int invert,
- int off) {
- if (width < 1) {
- width = 1;
- }
- const int kBpp = 4;
- const int kStride = width * kBpp;
- align_buffer_page_end(src_argb_a, kStride * height + off);
- align_buffer_page_end(src_argb_b, kStride * height + off);
- align_buffer_page_end(dst_argb_c, kStride * height);
- align_buffer_page_end(dst_argb_opt, kStride * height);
- for (int i = 0; i < kStride * height; ++i) {
- src_argb_a[i + off] = (fastrand() & 0xff);
- src_argb_b[i + off] = (fastrand() & 0xff);
- }
- memset(dst_argb_c, 0, kStride * height);
- memset(dst_argb_opt, 0, kStride * height);
- MaskCpuFlags(disable_cpu_flags);
- ARGBMultiply(src_argb_a + off, kStride, src_argb_b + off, kStride, dst_argb_c,
- kStride, width, invert * height);
- MaskCpuFlags(benchmark_cpu_info);
- for (int i = 0; i < benchmark_iterations; ++i) {
- ARGBMultiply(src_argb_a + off, kStride, src_argb_b + off, kStride,
- dst_argb_opt, kStride, width, invert * height);
- }
- int max_diff = 0;
- for (int i = 0; i < kStride * height; ++i) {
- int abs_diff = abs(static_cast<int>(dst_argb_c[i]) -
- static_cast<int>(dst_argb_opt[i]));
- if (abs_diff > max_diff) {
- max_diff = abs_diff;
- }
- }
- free_aligned_buffer_page_end(src_argb_a);
- free_aligned_buffer_page_end(src_argb_b);
- free_aligned_buffer_page_end(dst_argb_c);
- free_aligned_buffer_page_end(dst_argb_opt);
- return max_diff;
- }
- TEST_F(LibYUVPlanarTest, ARGBMultiply_Any) {
- int max_diff = TestMultiply(benchmark_width_ - 1, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, +1, 0);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBMultiply_Unaligned) {
- int max_diff =
- TestMultiply(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 1);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBMultiply_Invert) {
- int max_diff =
- TestMultiply(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, -1, 0);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBMultiply_Opt) {
- int max_diff =
- TestMultiply(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0);
- EXPECT_LE(max_diff, 1);
- }
- static int TestAdd(int width,
- int height,
- int benchmark_iterations,
- int disable_cpu_flags,
- int benchmark_cpu_info,
- int invert,
- int off) {
- if (width < 1) {
- width = 1;
- }
- const int kBpp = 4;
- const int kStride = width * kBpp;
- align_buffer_page_end(src_argb_a, kStride * height + off);
- align_buffer_page_end(src_argb_b, kStride * height + off);
- align_buffer_page_end(dst_argb_c, kStride * height);
- align_buffer_page_end(dst_argb_opt, kStride * height);
- for (int i = 0; i < kStride * height; ++i) {
- src_argb_a[i + off] = (fastrand() & 0xff);
- src_argb_b[i + off] = (fastrand() & 0xff);
- }
- memset(dst_argb_c, 0, kStride * height);
- memset(dst_argb_opt, 0, kStride * height);
- MaskCpuFlags(disable_cpu_flags);
- ARGBAdd(src_argb_a + off, kStride, src_argb_b + off, kStride, dst_argb_c,
- kStride, width, invert * height);
- MaskCpuFlags(benchmark_cpu_info);
- for (int i = 0; i < benchmark_iterations; ++i) {
- ARGBAdd(src_argb_a + off, kStride, src_argb_b + off, kStride, dst_argb_opt,
- kStride, width, invert * height);
- }
- int max_diff = 0;
- for (int i = 0; i < kStride * height; ++i) {
- int abs_diff = abs(static_cast<int>(dst_argb_c[i]) -
- static_cast<int>(dst_argb_opt[i]));
- if (abs_diff > max_diff) {
- max_diff = abs_diff;
- }
- }
- free_aligned_buffer_page_end(src_argb_a);
- free_aligned_buffer_page_end(src_argb_b);
- free_aligned_buffer_page_end(dst_argb_c);
- free_aligned_buffer_page_end(dst_argb_opt);
- return max_diff;
- }
- TEST_F(LibYUVPlanarTest, ARGBAdd_Any) {
- int max_diff =
- TestAdd(benchmark_width_ - 1, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBAdd_Unaligned) {
- int max_diff =
- TestAdd(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 1);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBAdd_Invert) {
- int max_diff =
- TestAdd(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, -1, 0);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBAdd_Opt) {
- int max_diff =
- TestAdd(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0);
- EXPECT_LE(max_diff, 1);
- }
- static int TestSubtract(int width,
- int height,
- int benchmark_iterations,
- int disable_cpu_flags,
- int benchmark_cpu_info,
- int invert,
- int off) {
- if (width < 1) {
- width = 1;
- }
- const int kBpp = 4;
- const int kStride = width * kBpp;
- align_buffer_page_end(src_argb_a, kStride * height + off);
- align_buffer_page_end(src_argb_b, kStride * height + off);
- align_buffer_page_end(dst_argb_c, kStride * height);
- align_buffer_page_end(dst_argb_opt, kStride * height);
- for (int i = 0; i < kStride * height; ++i) {
- src_argb_a[i + off] = (fastrand() & 0xff);
- src_argb_b[i + off] = (fastrand() & 0xff);
- }
- memset(dst_argb_c, 0, kStride * height);
- memset(dst_argb_opt, 0, kStride * height);
- MaskCpuFlags(disable_cpu_flags);
- ARGBSubtract(src_argb_a + off, kStride, src_argb_b + off, kStride, dst_argb_c,
- kStride, width, invert * height);
- MaskCpuFlags(benchmark_cpu_info);
- for (int i = 0; i < benchmark_iterations; ++i) {
- ARGBSubtract(src_argb_a + off, kStride, src_argb_b + off, kStride,
- dst_argb_opt, kStride, width, invert * height);
- }
- int max_diff = 0;
- for (int i = 0; i < kStride * height; ++i) {
- int abs_diff = abs(static_cast<int>(dst_argb_c[i]) -
- static_cast<int>(dst_argb_opt[i]));
- if (abs_diff > max_diff) {
- max_diff = abs_diff;
- }
- }
- free_aligned_buffer_page_end(src_argb_a);
- free_aligned_buffer_page_end(src_argb_b);
- free_aligned_buffer_page_end(dst_argb_c);
- free_aligned_buffer_page_end(dst_argb_opt);
- return max_diff;
- }
- TEST_F(LibYUVPlanarTest, ARGBSubtract_Any) {
- int max_diff = TestSubtract(benchmark_width_ - 1, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, +1, 0);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBSubtract_Unaligned) {
- int max_diff =
- TestSubtract(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 1);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBSubtract_Invert) {
- int max_diff =
- TestSubtract(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, -1, 0);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBSubtract_Opt) {
- int max_diff =
- TestSubtract(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0);
- EXPECT_LE(max_diff, 1);
- }
- static int TestSobel(int width,
- int height,
- int benchmark_iterations,
- int disable_cpu_flags,
- int benchmark_cpu_info,
- int invert,
- int off) {
- if (width < 1) {
- width = 1;
- }
- const int kBpp = 4;
- const int kStride = width * kBpp;
- align_buffer_page_end(src_argb_a, kStride * height + off);
- align_buffer_page_end(dst_argb_c, kStride * height);
- align_buffer_page_end(dst_argb_opt, kStride * height);
- memset(src_argb_a, 0, kStride * height + off);
- for (int i = 0; i < kStride * height; ++i) {
- src_argb_a[i + off] = (fastrand() & 0xff);
- }
- memset(dst_argb_c, 0, kStride * height);
- memset(dst_argb_opt, 0, kStride * height);
- MaskCpuFlags(disable_cpu_flags);
- ARGBSobel(src_argb_a + off, kStride, dst_argb_c, kStride, width,
- invert * height);
- MaskCpuFlags(benchmark_cpu_info);
- for (int i = 0; i < benchmark_iterations; ++i) {
- ARGBSobel(src_argb_a + off, kStride, dst_argb_opt, kStride, width,
- invert * height);
- }
- int max_diff = 0;
- for (int i = 0; i < kStride * height; ++i) {
- int abs_diff = abs(static_cast<int>(dst_argb_c[i]) -
- static_cast<int>(dst_argb_opt[i]));
- if (abs_diff > max_diff) {
- max_diff = abs_diff;
- }
- }
- free_aligned_buffer_page_end(src_argb_a);
- free_aligned_buffer_page_end(dst_argb_c);
- free_aligned_buffer_page_end(dst_argb_opt);
- return max_diff;
- }
- TEST_F(LibYUVPlanarTest, ARGBSobel_Any) {
- int max_diff =
- TestSobel(benchmark_width_ - 1, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0);
- EXPECT_EQ(0, max_diff);
- }
- TEST_F(LibYUVPlanarTest, ARGBSobel_Unaligned) {
- int max_diff =
- TestSobel(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 1);
- EXPECT_EQ(0, max_diff);
- }
- TEST_F(LibYUVPlanarTest, ARGBSobel_Invert) {
- int max_diff =
- TestSobel(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, -1, 0);
- EXPECT_EQ(0, max_diff);
- }
- TEST_F(LibYUVPlanarTest, ARGBSobel_Opt) {
- int max_diff =
- TestSobel(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0);
- EXPECT_EQ(0, max_diff);
- }
- static int TestSobelToPlane(int width,
- int height,
- int benchmark_iterations,
- int disable_cpu_flags,
- int benchmark_cpu_info,
- int invert,
- int off) {
- if (width < 1) {
- width = 1;
- }
- const int kSrcBpp = 4;
- const int kDstBpp = 1;
- const int kSrcStride = (width * kSrcBpp + 15) & ~15;
- const int kDstStride = (width * kDstBpp + 15) & ~15;
- align_buffer_page_end(src_argb_a, kSrcStride * height + off);
- align_buffer_page_end(dst_argb_c, kDstStride * height);
- align_buffer_page_end(dst_argb_opt, kDstStride * height);
- memset(src_argb_a, 0, kSrcStride * height + off);
- for (int i = 0; i < kSrcStride * height; ++i) {
- src_argb_a[i + off] = (fastrand() & 0xff);
- }
- memset(dst_argb_c, 0, kDstStride * height);
- memset(dst_argb_opt, 0, kDstStride * height);
- MaskCpuFlags(disable_cpu_flags);
- ARGBSobelToPlane(src_argb_a + off, kSrcStride, dst_argb_c, kDstStride, width,
- invert * height);
- MaskCpuFlags(benchmark_cpu_info);
- for (int i = 0; i < benchmark_iterations; ++i) {
- ARGBSobelToPlane(src_argb_a + off, kSrcStride, dst_argb_opt, kDstStride,
- width, invert * height);
- }
- int max_diff = 0;
- for (int i = 0; i < kDstStride * height; ++i) {
- int abs_diff = abs(static_cast<int>(dst_argb_c[i]) -
- static_cast<int>(dst_argb_opt[i]));
- if (abs_diff > max_diff) {
- max_diff = abs_diff;
- }
- }
- free_aligned_buffer_page_end(src_argb_a);
- free_aligned_buffer_page_end(dst_argb_c);
- free_aligned_buffer_page_end(dst_argb_opt);
- return max_diff;
- }
- TEST_F(LibYUVPlanarTest, ARGBSobelToPlane_Any) {
- int max_diff = TestSobelToPlane(benchmark_width_ - 1, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, +1, 0);
- EXPECT_EQ(0, max_diff);
- }
- TEST_F(LibYUVPlanarTest, ARGBSobelToPlane_Unaligned) {
- int max_diff = TestSobelToPlane(benchmark_width_, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, +1, 1);
- EXPECT_EQ(0, max_diff);
- }
- TEST_F(LibYUVPlanarTest, ARGBSobelToPlane_Invert) {
- int max_diff = TestSobelToPlane(benchmark_width_, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, -1, 0);
- EXPECT_EQ(0, max_diff);
- }
- TEST_F(LibYUVPlanarTest, ARGBSobelToPlane_Opt) {
- int max_diff = TestSobelToPlane(benchmark_width_, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, +1, 0);
- EXPECT_EQ(0, max_diff);
- }
- static int TestSobelXY(int width,
- int height,
- int benchmark_iterations,
- int disable_cpu_flags,
- int benchmark_cpu_info,
- int invert,
- int off) {
- if (width < 1) {
- width = 1;
- }
- const int kBpp = 4;
- const int kStride = width * kBpp;
- align_buffer_page_end(src_argb_a, kStride * height + off);
- align_buffer_page_end(dst_argb_c, kStride * height);
- align_buffer_page_end(dst_argb_opt, kStride * height);
- memset(src_argb_a, 0, kStride * height + off);
- for (int i = 0; i < kStride * height; ++i) {
- src_argb_a[i + off] = (fastrand() & 0xff);
- }
- memset(dst_argb_c, 0, kStride * height);
- memset(dst_argb_opt, 0, kStride * height);
- MaskCpuFlags(disable_cpu_flags);
- ARGBSobelXY(src_argb_a + off, kStride, dst_argb_c, kStride, width,
- invert * height);
- MaskCpuFlags(benchmark_cpu_info);
- for (int i = 0; i < benchmark_iterations; ++i) {
- ARGBSobelXY(src_argb_a + off, kStride, dst_argb_opt, kStride, width,
- invert * height);
- }
- int max_diff = 0;
- for (int i = 0; i < kStride * height; ++i) {
- int abs_diff = abs(static_cast<int>(dst_argb_c[i]) -
- static_cast<int>(dst_argb_opt[i]));
- if (abs_diff > max_diff) {
- max_diff = abs_diff;
- }
- }
- free_aligned_buffer_page_end(src_argb_a);
- free_aligned_buffer_page_end(dst_argb_c);
- free_aligned_buffer_page_end(dst_argb_opt);
- return max_diff;
- }
- TEST_F(LibYUVPlanarTest, ARGBSobelXY_Any) {
- int max_diff = TestSobelXY(benchmark_width_ - 1, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, +1, 0);
- EXPECT_EQ(0, max_diff);
- }
- TEST_F(LibYUVPlanarTest, ARGBSobelXY_Unaligned) {
- int max_diff =
- TestSobelXY(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 1);
- EXPECT_EQ(0, max_diff);
- }
- TEST_F(LibYUVPlanarTest, ARGBSobelXY_Invert) {
- int max_diff =
- TestSobelXY(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, -1, 0);
- EXPECT_EQ(0, max_diff);
- }
- TEST_F(LibYUVPlanarTest, ARGBSobelXY_Opt) {
- int max_diff =
- TestSobelXY(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0);
- EXPECT_EQ(0, max_diff);
- }
- static int TestBlur(int width,
- int height,
- int benchmark_iterations,
- int disable_cpu_flags,
- int benchmark_cpu_info,
- int invert,
- int off,
- int radius) {
- if (width < 1) {
- width = 1;
- }
- const int kBpp = 4;
- const int kStride = width * kBpp;
- align_buffer_page_end(src_argb_a, kStride * height + off);
- align_buffer_page_end(dst_cumsum, width * height * 16);
- align_buffer_page_end(dst_argb_c, kStride * height);
- align_buffer_page_end(dst_argb_opt, kStride * height);
- for (int i = 0; i < kStride * height; ++i) {
- src_argb_a[i + off] = (fastrand() & 0xff);
- }
- memset(dst_cumsum, 0, width * height * 16);
- memset(dst_argb_c, 0, kStride * height);
- memset(dst_argb_opt, 0, kStride * height);
- MaskCpuFlags(disable_cpu_flags);
- ARGBBlur(src_argb_a + off, kStride, dst_argb_c, kStride,
- reinterpret_cast<int32_t*>(dst_cumsum), width * 4, width,
- invert * height, radius);
- MaskCpuFlags(benchmark_cpu_info);
- for (int i = 0; i < benchmark_iterations; ++i) {
- ARGBBlur(src_argb_a + off, kStride, dst_argb_opt, kStride,
- reinterpret_cast<int32_t*>(dst_cumsum), width * 4, width,
- invert * height, radius);
- }
- int max_diff = 0;
- for (int i = 0; i < kStride * height; ++i) {
- int abs_diff = abs(static_cast<int>(dst_argb_c[i]) -
- static_cast<int>(dst_argb_opt[i]));
- if (abs_diff > max_diff) {
- max_diff = abs_diff;
- }
- }
- free_aligned_buffer_page_end(src_argb_a);
- free_aligned_buffer_page_end(dst_cumsum);
- free_aligned_buffer_page_end(dst_argb_c);
- free_aligned_buffer_page_end(dst_argb_opt);
- return max_diff;
- }
- static const int kBlurSize = 55;
- TEST_F(LibYUVPlanarTest, ARGBBlur_Any) {
- int max_diff =
- TestBlur(benchmark_width_ - 1, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0, kBlurSize);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBBlur_Unaligned) {
- int max_diff =
- TestBlur(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 1, kBlurSize);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBBlur_Invert) {
- int max_diff =
- TestBlur(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, -1, 0, kBlurSize);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBBlur_Opt) {
- int max_diff =
- TestBlur(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0, kBlurSize);
- EXPECT_LE(max_diff, 1);
- }
- static const int kBlurSmallSize = 5;
- TEST_F(LibYUVPlanarTest, ARGBBlurSmall_Any) {
- int max_diff =
- TestBlur(benchmark_width_ - 1, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0, kBlurSmallSize);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBBlurSmall_Unaligned) {
- int max_diff =
- TestBlur(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 1, kBlurSmallSize);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBBlurSmall_Invert) {
- int max_diff =
- TestBlur(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, -1, 0, kBlurSmallSize);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBBlurSmall_Opt) {
- int max_diff =
- TestBlur(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0, kBlurSmallSize);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, TestARGBPolynomial) {
- SIMD_ALIGNED(uint8_t orig_pixels[1280][4]);
- SIMD_ALIGNED(uint8_t dst_pixels_opt[1280][4]);
- SIMD_ALIGNED(uint8_t dst_pixels_c[1280][4]);
- memset(orig_pixels, 0, sizeof(orig_pixels));
- SIMD_ALIGNED(static const float kWarmifyPolynomial[16]) = {
- 0.94230f, -3.03300f, -2.92500f, 0.f, // C0
- 0.584500f, 1.112000f, 1.535000f, 1.f, // C1 x
- 0.001313f, -0.002503f, -0.004496f, 0.f, // C2 x * x
- 0.0f, 0.000006965f, 0.000008781f, 0.f, // C3 x * x * x
- };
- // Test blue
- orig_pixels[0][0] = 255u;
- orig_pixels[0][1] = 0u;
- orig_pixels[0][2] = 0u;
- orig_pixels[0][3] = 128u;
- // Test green
- orig_pixels[1][0] = 0u;
- orig_pixels[1][1] = 255u;
- orig_pixels[1][2] = 0u;
- orig_pixels[1][3] = 0u;
- // Test red
- orig_pixels[2][0] = 0u;
- orig_pixels[2][1] = 0u;
- orig_pixels[2][2] = 255u;
- orig_pixels[2][3] = 255u;
- // Test white
- orig_pixels[3][0] = 255u;
- orig_pixels[3][1] = 255u;
- orig_pixels[3][2] = 255u;
- orig_pixels[3][3] = 255u;
- // Test color
- orig_pixels[4][0] = 16u;
- orig_pixels[4][1] = 64u;
- orig_pixels[4][2] = 192u;
- orig_pixels[4][3] = 224u;
- // Do 16 to test asm version.
- ARGBPolynomial(&orig_pixels[0][0], 0, &dst_pixels_opt[0][0], 0,
- &kWarmifyPolynomial[0], 16, 1);
- EXPECT_EQ(235u, dst_pixels_opt[0][0]);
- EXPECT_EQ(0u, dst_pixels_opt[0][1]);
- EXPECT_EQ(0u, dst_pixels_opt[0][2]);
- EXPECT_EQ(128u, dst_pixels_opt[0][3]);
- EXPECT_EQ(0u, dst_pixels_opt[1][0]);
- EXPECT_EQ(233u, dst_pixels_opt[1][1]);
- EXPECT_EQ(0u, dst_pixels_opt[1][2]);
- EXPECT_EQ(0u, dst_pixels_opt[1][3]);
- EXPECT_EQ(0u, dst_pixels_opt[2][0]);
- EXPECT_EQ(0u, dst_pixels_opt[2][1]);
- EXPECT_EQ(241u, dst_pixels_opt[2][2]);
- EXPECT_EQ(255u, dst_pixels_opt[2][3]);
- EXPECT_EQ(235u, dst_pixels_opt[3][0]);
- EXPECT_EQ(233u, dst_pixels_opt[3][1]);
- EXPECT_EQ(241u, dst_pixels_opt[3][2]);
- EXPECT_EQ(255u, dst_pixels_opt[3][3]);
- EXPECT_EQ(10u, dst_pixels_opt[4][0]);
- EXPECT_EQ(59u, dst_pixels_opt[4][1]);
- EXPECT_EQ(188u, dst_pixels_opt[4][2]);
- EXPECT_EQ(224u, dst_pixels_opt[4][3]);
- for (int i = 0; i < 1280; ++i) {
- orig_pixels[i][0] = i;
- orig_pixels[i][1] = i / 2;
- orig_pixels[i][2] = i / 3;
- orig_pixels[i][3] = i;
- }
- MaskCpuFlags(disable_cpu_flags_);
- ARGBPolynomial(&orig_pixels[0][0], 0, &dst_pixels_c[0][0], 0,
- &kWarmifyPolynomial[0], 1280, 1);
- MaskCpuFlags(benchmark_cpu_info_);
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
- ARGBPolynomial(&orig_pixels[0][0], 0, &dst_pixels_opt[0][0], 0,
- &kWarmifyPolynomial[0], 1280, 1);
- }
- for (int i = 0; i < 1280; ++i) {
- EXPECT_EQ(dst_pixels_c[i][0], dst_pixels_opt[i][0]);
- EXPECT_EQ(dst_pixels_c[i][1], dst_pixels_opt[i][1]);
- EXPECT_EQ(dst_pixels_c[i][2], dst_pixels_opt[i][2]);
- EXPECT_EQ(dst_pixels_c[i][3], dst_pixels_opt[i][3]);
- }
- }
- int TestHalfFloatPlane(int benchmark_width,
- int benchmark_height,
- int benchmark_iterations,
- int disable_cpu_flags,
- int benchmark_cpu_info,
- float scale,
- int mask) {
- int i, j;
- const int y_plane_size = benchmark_width * benchmark_height * 2;
- align_buffer_page_end(orig_y, y_plane_size * 3);
- uint8_t* dst_opt = orig_y + y_plane_size;
- uint8_t* dst_c = orig_y + y_plane_size * 2;
- MemRandomize(orig_y, y_plane_size);
- memset(dst_c, 0, y_plane_size);
- memset(dst_opt, 1, y_plane_size);
- for (i = 0; i < y_plane_size / 2; ++i) {
- reinterpret_cast<uint16_t*>(orig_y)[i] &= mask;
- }
- // Disable all optimizations.
- MaskCpuFlags(disable_cpu_flags);
- for (j = 0; j < benchmark_iterations; j++) {
- HalfFloatPlane(reinterpret_cast<uint16_t*>(orig_y), benchmark_width * 2,
- reinterpret_cast<uint16_t*>(dst_c), benchmark_width * 2,
- scale, benchmark_width, benchmark_height);
- }
- // Enable optimizations.
- MaskCpuFlags(benchmark_cpu_info);
- for (j = 0; j < benchmark_iterations; j++) {
- HalfFloatPlane(reinterpret_cast<uint16_t*>(orig_y), benchmark_width * 2,
- reinterpret_cast<uint16_t*>(dst_opt), benchmark_width * 2,
- scale, benchmark_width, benchmark_height);
- }
- int max_diff = 0;
- for (i = 0; i < y_plane_size / 2; ++i) {
- int abs_diff =
- abs(static_cast<int>(reinterpret_cast<uint16_t*>(dst_c)[i]) -
- static_cast<int>(reinterpret_cast<uint16_t*>(dst_opt)[i]));
- if (abs_diff > max_diff) {
- max_diff = abs_diff;
- }
- }
- free_aligned_buffer_page_end(orig_y);
- return max_diff;
- }
- #if defined(__arm__)
- static void EnableFlushDenormalToZero(void) {
- uint32_t cw;
- __asm__ __volatile__(
- "vmrs %0, fpscr \n"
- "orr %0, %0, #0x1000000 \n"
- "vmsr fpscr, %0 \n"
- : "=r"(cw)::"memory");
- }
- #endif
- // 5 bit exponent with bias of 15 will underflow to a denormal if scale causes
- // exponent to be less than 0. 15 - log2(65536) = -1/ This shouldnt normally
- // happen since scale is 1/(1<<bits) where bits is 9, 10 or 12.
- TEST_F(LibYUVPlanarTest, TestHalfFloatPlane_16bit_denormal) {
- // 32 bit arm rounding on denormal case is off by 1 compared to C.
- #if defined(__arm__)
- EnableFlushDenormalToZero();
- #endif
- int diff = TestHalfFloatPlane(benchmark_width_, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, 1.0f / 65536.0f, 65535);
- EXPECT_EQ(0, diff);
- }
- TEST_F(LibYUVPlanarTest, TestHalfFloatPlane_16bit_One) {
- int diff = TestHalfFloatPlane(benchmark_width_, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, 1.0f, 65535);
- EXPECT_LE(diff, 1);
- }
- TEST_F(LibYUVPlanarTest, TestHalfFloatPlane_16bit_Opt) {
- int diff = TestHalfFloatPlane(benchmark_width_, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, 1.0f / 4096.0f, 65535);
- EXPECT_EQ(0, diff);
- }
- TEST_F(LibYUVPlanarTest, TestHalfFloatPlane_10bit_Opt) {
- int diff = TestHalfFloatPlane(benchmark_width_, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, 1.0f / 1024.0f, 1023);
- EXPECT_EQ(0, diff);
- }
- TEST_F(LibYUVPlanarTest, TestHalfFloatPlane_9bit_Opt) {
- int diff = TestHalfFloatPlane(benchmark_width_, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, 1.0f / 512.0f, 511);
- EXPECT_EQ(0, diff);
- }
- TEST_F(LibYUVPlanarTest, TestHalfFloatPlane_Opt) {
- int diff = TestHalfFloatPlane(benchmark_width_, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, 1.0f / 4096.0f, 4095);
- EXPECT_EQ(0, diff);
- }
- TEST_F(LibYUVPlanarTest, TestHalfFloatPlane_Offby1) {
- int diff = TestHalfFloatPlane(benchmark_width_, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, 1.0f / 4095.0f, 4095);
- EXPECT_EQ(0, diff);
- }
- TEST_F(LibYUVPlanarTest, TestHalfFloatPlane_One) {
- int diff = TestHalfFloatPlane(benchmark_width_, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, 1.0f, 2047);
- EXPECT_EQ(0, diff);
- }
- TEST_F(LibYUVPlanarTest, TestHalfFloatPlane_12bit_One) {
- int diff = TestHalfFloatPlane(benchmark_width_, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, 1.0f, 4095);
- EXPECT_LE(diff, 1);
- }
- float TestByteToFloat(int benchmark_width,
- int benchmark_height,
- int benchmark_iterations,
- int disable_cpu_flags,
- int benchmark_cpu_info,
- float scale) {
- int i, j;
- const int y_plane_size = benchmark_width * benchmark_height;
- align_buffer_page_end(orig_y, y_plane_size * (1 + 4 + 4));
- float* dst_opt = reinterpret_cast<float*>(orig_y + y_plane_size);
- float* dst_c = reinterpret_cast<float*>(orig_y + y_plane_size * 5);
- MemRandomize(orig_y, y_plane_size);
- memset(dst_c, 0, y_plane_size * 4);
- memset(dst_opt, 1, y_plane_size * 4);
- // Disable all optimizations.
- MaskCpuFlags(disable_cpu_flags);
- ByteToFloat(orig_y, dst_c, scale, y_plane_size);
- // Enable optimizations.
- MaskCpuFlags(benchmark_cpu_info);
- for (j = 0; j < benchmark_iterations; j++) {
- ByteToFloat(orig_y, dst_opt, scale, y_plane_size);
- }
- float max_diff = 0;
- for (i = 0; i < y_plane_size; ++i) {
- float abs_diff = fabs(dst_c[i] - dst_opt[i]);
- if (abs_diff > max_diff) {
- max_diff = abs_diff;
- }
- }
- free_aligned_buffer_page_end(orig_y);
- return max_diff;
- }
- TEST_F(LibYUVPlanarTest, TestByteToFloat) {
- float diff = TestByteToFloat(benchmark_width_, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, 1.0f);
- EXPECT_EQ(0.f, diff);
- }
- TEST_F(LibYUVPlanarTest, TestARGBLumaColorTable) {
- SIMD_ALIGNED(uint8_t orig_pixels[1280][4]);
- SIMD_ALIGNED(uint8_t dst_pixels_opt[1280][4]);
- SIMD_ALIGNED(uint8_t dst_pixels_c[1280][4]);
- memset(orig_pixels, 0, sizeof(orig_pixels));
- align_buffer_page_end(lumacolortable, 32768);
- int v = 0;
- for (int i = 0; i < 32768; ++i) {
- lumacolortable[i] = v;
- v += 3;
- }
- // Test blue
- orig_pixels[0][0] = 255u;
- orig_pixels[0][1] = 0u;
- orig_pixels[0][2] = 0u;
- orig_pixels[0][3] = 128u;
- // Test green
- orig_pixels[1][0] = 0u;
- orig_pixels[1][1] = 255u;
- orig_pixels[1][2] = 0u;
- orig_pixels[1][3] = 0u;
- // Test red
- orig_pixels[2][0] = 0u;
- orig_pixels[2][1] = 0u;
- orig_pixels[2][2] = 255u;
- orig_pixels[2][3] = 255u;
- // Test color
- orig_pixels[3][0] = 16u;
- orig_pixels[3][1] = 64u;
- orig_pixels[3][2] = 192u;
- orig_pixels[3][3] = 224u;
- // Do 16 to test asm version.
- ARGBLumaColorTable(&orig_pixels[0][0], 0, &dst_pixels_opt[0][0], 0,
- &lumacolortable[0], 16, 1);
- EXPECT_EQ(253u, dst_pixels_opt[0][0]);
- EXPECT_EQ(0u, dst_pixels_opt[0][1]);
- EXPECT_EQ(0u, dst_pixels_opt[0][2]);
- EXPECT_EQ(128u, dst_pixels_opt[0][3]);
- EXPECT_EQ(0u, dst_pixels_opt[1][0]);
- EXPECT_EQ(253u, dst_pixels_opt[1][1]);
- EXPECT_EQ(0u, dst_pixels_opt[1][2]);
- EXPECT_EQ(0u, dst_pixels_opt[1][3]);
- EXPECT_EQ(0u, dst_pixels_opt[2][0]);
- EXPECT_EQ(0u, dst_pixels_opt[2][1]);
- EXPECT_EQ(253u, dst_pixels_opt[2][2]);
- EXPECT_EQ(255u, dst_pixels_opt[2][3]);
- EXPECT_EQ(48u, dst_pixels_opt[3][0]);
- EXPECT_EQ(192u, dst_pixels_opt[3][1]);
- EXPECT_EQ(64u, dst_pixels_opt[3][2]);
- EXPECT_EQ(224u, dst_pixels_opt[3][3]);
- for (int i = 0; i < 1280; ++i) {
- orig_pixels[i][0] = i;
- orig_pixels[i][1] = i / 2;
- orig_pixels[i][2] = i / 3;
- orig_pixels[i][3] = i;
- }
- MaskCpuFlags(disable_cpu_flags_);
- ARGBLumaColorTable(&orig_pixels[0][0], 0, &dst_pixels_c[0][0], 0,
- lumacolortable, 1280, 1);
- MaskCpuFlags(benchmark_cpu_info_);
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
- ARGBLumaColorTable(&orig_pixels[0][0], 0, &dst_pixels_opt[0][0], 0,
- lumacolortable, 1280, 1);
- }
- for (int i = 0; i < 1280; ++i) {
- EXPECT_EQ(dst_pixels_c[i][0], dst_pixels_opt[i][0]);
- EXPECT_EQ(dst_pixels_c[i][1], dst_pixels_opt[i][1]);
- EXPECT_EQ(dst_pixels_c[i][2], dst_pixels_opt[i][2]);
- EXPECT_EQ(dst_pixels_c[i][3], dst_pixels_opt[i][3]);
- }
- free_aligned_buffer_page_end(lumacolortable);
- }
- TEST_F(LibYUVPlanarTest, TestARGBCopyAlpha) {
- const int kSize = benchmark_width_ * benchmark_height_ * 4;
- align_buffer_page_end(orig_pixels, kSize);
- align_buffer_page_end(dst_pixels_opt, kSize);
- align_buffer_page_end(dst_pixels_c, kSize);
- MemRandomize(orig_pixels, kSize);
- MemRandomize(dst_pixels_opt, kSize);
- memcpy(dst_pixels_c, dst_pixels_opt, kSize);
- MaskCpuFlags(disable_cpu_flags_);
- ARGBCopyAlpha(orig_pixels, benchmark_width_ * 4, dst_pixels_c,
- benchmark_width_ * 4, benchmark_width_, benchmark_height_);
- MaskCpuFlags(benchmark_cpu_info_);
- for (int i = 0; i < benchmark_iterations_; ++i) {
- ARGBCopyAlpha(orig_pixels, benchmark_width_ * 4, dst_pixels_opt,
- benchmark_width_ * 4, benchmark_width_, benchmark_height_);
- }
- for (int i = 0; i < kSize; ++i) {
- EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
- }
- free_aligned_buffer_page_end(dst_pixels_c);
- free_aligned_buffer_page_end(dst_pixels_opt);
- free_aligned_buffer_page_end(orig_pixels);
- }
- TEST_F(LibYUVPlanarTest, TestARGBExtractAlpha) {
- // Round count up to multiple of 16
- const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15;
- align_buffer_page_end(src_pixels, kPixels * 4);
- align_buffer_page_end(dst_pixels_opt, kPixels);
- align_buffer_page_end(dst_pixels_c, kPixels);
- MemRandomize(src_pixels, kPixels * 4);
- MemRandomize(dst_pixels_opt, kPixels);
- memcpy(dst_pixels_c, dst_pixels_opt, kPixels);
- MaskCpuFlags(disable_cpu_flags_);
- ARGBExtractAlpha(src_pixels, benchmark_width_ * 4, dst_pixels_c,
- benchmark_width_, benchmark_width_, benchmark_height_);
- MaskCpuFlags(benchmark_cpu_info_);
- for (int i = 0; i < benchmark_iterations_; ++i) {
- ARGBExtractAlpha(src_pixels, benchmark_width_ * 4, dst_pixels_opt,
- benchmark_width_, benchmark_width_, benchmark_height_);
- }
- for (int i = 0; i < kPixels; ++i) {
- EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
- }
- free_aligned_buffer_page_end(dst_pixels_c);
- free_aligned_buffer_page_end(dst_pixels_opt);
- free_aligned_buffer_page_end(src_pixels);
- }
- TEST_F(LibYUVPlanarTest, TestARGBCopyYToAlpha) {
- // Round count up to multiple of 16
- const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15;
- align_buffer_page_end(orig_pixels, kPixels);
- align_buffer_page_end(dst_pixels_opt, kPixels * 4);
- align_buffer_page_end(dst_pixels_c, kPixels * 4);
- MemRandomize(orig_pixels, kPixels);
- MemRandomize(dst_pixels_opt, kPixels * 4);
- memcpy(dst_pixels_c, dst_pixels_opt, kPixels * 4);
- MaskCpuFlags(disable_cpu_flags_);
- ARGBCopyYToAlpha(orig_pixels, benchmark_width_, dst_pixels_c,
- benchmark_width_ * 4, benchmark_width_, benchmark_height_);
- MaskCpuFlags(benchmark_cpu_info_);
- for (int i = 0; i < benchmark_iterations_; ++i) {
- ARGBCopyYToAlpha(orig_pixels, benchmark_width_, dst_pixels_opt,
- benchmark_width_ * 4, benchmark_width_, benchmark_height_);
- }
- for (int i = 0; i < kPixels * 4; ++i) {
- EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
- }
- free_aligned_buffer_page_end(dst_pixels_c);
- free_aligned_buffer_page_end(dst_pixels_opt);
- free_aligned_buffer_page_end(orig_pixels);
- }
- static int TestARGBRect(int width,
- int height,
- int benchmark_iterations,
- int disable_cpu_flags,
- int benchmark_cpu_info,
- int invert,
- int off,
- int bpp) {
- if (width < 1) {
- width = 1;
- }
- const int kStride = width * bpp;
- const int kSize = kStride * height;
- const uint32_t v32 = fastrand() & (bpp == 4 ? 0xffffffff : 0xff);
- align_buffer_page_end(dst_argb_c, kSize + off);
- align_buffer_page_end(dst_argb_opt, kSize + off);
- MemRandomize(dst_argb_c + off, kSize);
- memcpy(dst_argb_opt + off, dst_argb_c + off, kSize);
- MaskCpuFlags(disable_cpu_flags);
- if (bpp == 4) {
- ARGBRect(dst_argb_c + off, kStride, 0, 0, width, invert * height, v32);
- } else {
- SetPlane(dst_argb_c + off, kStride, width, invert * height, v32);
- }
- MaskCpuFlags(benchmark_cpu_info);
- for (int i = 0; i < benchmark_iterations; ++i) {
- if (bpp == 4) {
- ARGBRect(dst_argb_opt + off, kStride, 0, 0, width, invert * height, v32);
- } else {
- SetPlane(dst_argb_opt + off, kStride, width, invert * height, v32);
- }
- }
- int max_diff = 0;
- for (int i = 0; i < kStride * height; ++i) {
- int abs_diff = abs(static_cast<int>(dst_argb_c[i + off]) -
- static_cast<int>(dst_argb_opt[i + off]));
- if (abs_diff > max_diff) {
- max_diff = abs_diff;
- }
- }
- free_aligned_buffer_page_end(dst_argb_c);
- free_aligned_buffer_page_end(dst_argb_opt);
- return max_diff;
- }
- TEST_F(LibYUVPlanarTest, ARGBRect_Any) {
- int max_diff = TestARGBRect(benchmark_width_ - 1, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, +1, 0, 4);
- EXPECT_EQ(0, max_diff);
- }
- TEST_F(LibYUVPlanarTest, ARGBRect_Unaligned) {
- int max_diff =
- TestARGBRect(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 1, 4);
- EXPECT_EQ(0, max_diff);
- }
- TEST_F(LibYUVPlanarTest, ARGBRect_Invert) {
- int max_diff =
- TestARGBRect(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, -1, 0, 4);
- EXPECT_EQ(0, max_diff);
- }
- TEST_F(LibYUVPlanarTest, ARGBRect_Opt) {
- int max_diff =
- TestARGBRect(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0, 4);
- EXPECT_EQ(0, max_diff);
- }
- TEST_F(LibYUVPlanarTest, SetPlane_Any) {
- int max_diff = TestARGBRect(benchmark_width_ - 1, benchmark_height_,
- benchmark_iterations_, disable_cpu_flags_,
- benchmark_cpu_info_, +1, 0, 1);
- EXPECT_EQ(0, max_diff);
- }
- TEST_F(LibYUVPlanarTest, SetPlane_Unaligned) {
- int max_diff =
- TestARGBRect(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 1, 1);
- EXPECT_EQ(0, max_diff);
- }
- TEST_F(LibYUVPlanarTest, SetPlane_Invert) {
- int max_diff =
- TestARGBRect(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, -1, 0, 1);
- EXPECT_EQ(0, max_diff);
- }
- TEST_F(LibYUVPlanarTest, SetPlane_Opt) {
- int max_diff =
- TestARGBRect(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0, 1);
- EXPECT_EQ(0, max_diff);
- }
- TEST_F(LibYUVPlanarTest, MergeUVPlane_Opt) {
- // Round count up to multiple of 16
- const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15;
- align_buffer_page_end(src_pixels, kPixels * 2);
- align_buffer_page_end(tmp_pixels_u, kPixels);
- align_buffer_page_end(tmp_pixels_v, kPixels);
- align_buffer_page_end(dst_pixels_opt, kPixels * 2);
- align_buffer_page_end(dst_pixels_c, kPixels * 2);
- MemRandomize(src_pixels, kPixels * 2);
- MemRandomize(tmp_pixels_u, kPixels);
- MemRandomize(tmp_pixels_v, kPixels);
- MemRandomize(dst_pixels_opt, kPixels * 2);
- MemRandomize(dst_pixels_c, kPixels * 2);
- MaskCpuFlags(disable_cpu_flags_);
- SplitUVPlane(src_pixels, benchmark_width_ * 2, tmp_pixels_u, benchmark_width_,
- tmp_pixels_v, benchmark_width_, benchmark_width_,
- benchmark_height_);
- MergeUVPlane(tmp_pixels_u, benchmark_width_, tmp_pixels_v, benchmark_width_,
- dst_pixels_c, benchmark_width_ * 2, benchmark_width_,
- benchmark_height_);
- MaskCpuFlags(benchmark_cpu_info_);
- SplitUVPlane(src_pixels, benchmark_width_ * 2, tmp_pixels_u, benchmark_width_,
- tmp_pixels_v, benchmark_width_, benchmark_width_,
- benchmark_height_);
- for (int i = 0; i < benchmark_iterations_; ++i) {
- MergeUVPlane(tmp_pixels_u, benchmark_width_, tmp_pixels_v, benchmark_width_,
- dst_pixels_opt, benchmark_width_ * 2, benchmark_width_,
- benchmark_height_);
- }
- for (int i = 0; i < kPixels * 2; ++i) {
- EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
- }
- free_aligned_buffer_page_end(src_pixels);
- free_aligned_buffer_page_end(tmp_pixels_u);
- free_aligned_buffer_page_end(tmp_pixels_v);
- free_aligned_buffer_page_end(dst_pixels_opt);
- free_aligned_buffer_page_end(dst_pixels_c);
- }
- TEST_F(LibYUVPlanarTest, SplitUVPlane_Opt) {
- // Round count up to multiple of 16
- const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15;
- align_buffer_page_end(src_pixels, kPixels * 2);
- align_buffer_page_end(tmp_pixels_u, kPixels);
- align_buffer_page_end(tmp_pixels_v, kPixels);
- align_buffer_page_end(dst_pixels_opt, kPixels * 2);
- align_buffer_page_end(dst_pixels_c, kPixels * 2);
- MemRandomize(src_pixels, kPixels * 2);
- MemRandomize(tmp_pixels_u, kPixels);
- MemRandomize(tmp_pixels_v, kPixels);
- MemRandomize(dst_pixels_opt, kPixels * 2);
- MemRandomize(dst_pixels_c, kPixels * 2);
- MaskCpuFlags(disable_cpu_flags_);
- SplitUVPlane(src_pixels, benchmark_width_ * 2, tmp_pixels_u, benchmark_width_,
- tmp_pixels_v, benchmark_width_, benchmark_width_,
- benchmark_height_);
- MergeUVPlane(tmp_pixels_u, benchmark_width_, tmp_pixels_v, benchmark_width_,
- dst_pixels_c, benchmark_width_ * 2, benchmark_width_,
- benchmark_height_);
- MaskCpuFlags(benchmark_cpu_info_);
- for (int i = 0; i < benchmark_iterations_; ++i) {
- SplitUVPlane(src_pixels, benchmark_width_ * 2, tmp_pixels_u,
- benchmark_width_, tmp_pixels_v, benchmark_width_,
- benchmark_width_, benchmark_height_);
- }
- MergeUVPlane(tmp_pixels_u, benchmark_width_, tmp_pixels_v, benchmark_width_,
- dst_pixels_opt, benchmark_width_ * 2, benchmark_width_,
- benchmark_height_);
- for (int i = 0; i < kPixels * 2; ++i) {
- EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
- }
- free_aligned_buffer_page_end(src_pixels);
- free_aligned_buffer_page_end(tmp_pixels_u);
- free_aligned_buffer_page_end(tmp_pixels_v);
- free_aligned_buffer_page_end(dst_pixels_opt);
- free_aligned_buffer_page_end(dst_pixels_c);
- }
- TEST_F(LibYUVPlanarTest, SwapUVPlane_Opt) {
- // Round count up to multiple of 16
- const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15;
- align_buffer_page_end(src_pixels, kPixels * 2);
- align_buffer_page_end(dst_pixels_opt, kPixels * 2);
- align_buffer_page_end(dst_pixels_c, kPixels * 2);
- MemRandomize(src_pixels, kPixels * 2);
- MemRandomize(dst_pixels_opt, kPixels * 2);
- MemRandomize(dst_pixels_c, kPixels * 2);
- MaskCpuFlags(disable_cpu_flags_);
- SwapUVPlane(src_pixels, benchmark_width_ * 2, dst_pixels_c,
- benchmark_width_ * 2, benchmark_width_, benchmark_height_);
- MaskCpuFlags(benchmark_cpu_info_);
- for (int i = 0; i < benchmark_iterations_; ++i) {
- SwapUVPlane(src_pixels, benchmark_width_ * 2, dst_pixels_opt,
- benchmark_width_ * 2, benchmark_width_, benchmark_height_);
- }
- for (int i = 0; i < kPixels * 2; ++i) {
- EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
- }
- free_aligned_buffer_page_end(src_pixels);
- free_aligned_buffer_page_end(dst_pixels_opt);
- free_aligned_buffer_page_end(dst_pixels_c);
- }
- TEST_F(LibYUVPlanarTest, MergeRGBPlane_Opt) {
- // Round count up to multiple of 16
- const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15;
- align_buffer_page_end(src_pixels, kPixels * 3);
- align_buffer_page_end(tmp_pixels_r, kPixels);
- align_buffer_page_end(tmp_pixels_g, kPixels);
- align_buffer_page_end(tmp_pixels_b, kPixels);
- align_buffer_page_end(dst_pixels_opt, kPixels * 3);
- align_buffer_page_end(dst_pixels_c, kPixels * 3);
- MemRandomize(src_pixels, kPixels * 3);
- MemRandomize(tmp_pixels_r, kPixels);
- MemRandomize(tmp_pixels_g, kPixels);
- MemRandomize(tmp_pixels_b, kPixels);
- MemRandomize(dst_pixels_opt, kPixels * 3);
- MemRandomize(dst_pixels_c, kPixels * 3);
- MaskCpuFlags(disable_cpu_flags_);
- SplitRGBPlane(src_pixels, benchmark_width_ * 3, tmp_pixels_r,
- benchmark_width_, tmp_pixels_g, benchmark_width_, tmp_pixels_b,
- benchmark_width_, benchmark_width_, benchmark_height_);
- MergeRGBPlane(tmp_pixels_r, benchmark_width_, tmp_pixels_g, benchmark_width_,
- tmp_pixels_b, benchmark_width_, dst_pixels_c,
- benchmark_width_ * 3, benchmark_width_, benchmark_height_);
- MaskCpuFlags(benchmark_cpu_info_);
- SplitRGBPlane(src_pixels, benchmark_width_ * 3, tmp_pixels_r,
- benchmark_width_, tmp_pixels_g, benchmark_width_, tmp_pixels_b,
- benchmark_width_, benchmark_width_, benchmark_height_);
- for (int i = 0; i < benchmark_iterations_; ++i) {
- MergeRGBPlane(tmp_pixels_r, benchmark_width_, tmp_pixels_g,
- benchmark_width_, tmp_pixels_b, benchmark_width_,
- dst_pixels_opt, benchmark_width_ * 3, benchmark_width_,
- benchmark_height_);
- }
- for (int i = 0; i < kPixels * 3; ++i) {
- EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
- }
- free_aligned_buffer_page_end(src_pixels);
- free_aligned_buffer_page_end(tmp_pixels_r);
- free_aligned_buffer_page_end(tmp_pixels_g);
- free_aligned_buffer_page_end(tmp_pixels_b);
- free_aligned_buffer_page_end(dst_pixels_opt);
- free_aligned_buffer_page_end(dst_pixels_c);
- }
- TEST_F(LibYUVPlanarTest, SplitRGBPlane_Opt) {
- // Round count up to multiple of 16
- const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15;
- align_buffer_page_end(src_pixels, kPixels * 3);
- align_buffer_page_end(tmp_pixels_r, kPixels);
- align_buffer_page_end(tmp_pixels_g, kPixels);
- align_buffer_page_end(tmp_pixels_b, kPixels);
- align_buffer_page_end(dst_pixels_opt, kPixels * 3);
- align_buffer_page_end(dst_pixels_c, kPixels * 3);
- MemRandomize(src_pixels, kPixels * 3);
- MemRandomize(tmp_pixels_r, kPixels);
- MemRandomize(tmp_pixels_g, kPixels);
- MemRandomize(tmp_pixels_b, kPixels);
- MemRandomize(dst_pixels_opt, kPixels * 3);
- MemRandomize(dst_pixels_c, kPixels * 3);
- MaskCpuFlags(disable_cpu_flags_);
- SplitRGBPlane(src_pixels, benchmark_width_ * 3, tmp_pixels_r,
- benchmark_width_, tmp_pixels_g, benchmark_width_, tmp_pixels_b,
- benchmark_width_, benchmark_width_, benchmark_height_);
- MergeRGBPlane(tmp_pixels_r, benchmark_width_, tmp_pixels_g, benchmark_width_,
- tmp_pixels_b, benchmark_width_, dst_pixels_c,
- benchmark_width_ * 3, benchmark_width_, benchmark_height_);
- MaskCpuFlags(benchmark_cpu_info_);
- for (int i = 0; i < benchmark_iterations_; ++i) {
- SplitRGBPlane(src_pixels, benchmark_width_ * 3, tmp_pixels_r,
- benchmark_width_, tmp_pixels_g, benchmark_width_,
- tmp_pixels_b, benchmark_width_, benchmark_width_,
- benchmark_height_);
- }
- MergeRGBPlane(tmp_pixels_r, benchmark_width_, tmp_pixels_g, benchmark_width_,
- tmp_pixels_b, benchmark_width_, dst_pixels_opt,
- benchmark_width_ * 3, benchmark_width_, benchmark_height_);
- for (int i = 0; i < kPixels * 3; ++i) {
- EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
- }
- free_aligned_buffer_page_end(src_pixels);
- free_aligned_buffer_page_end(tmp_pixels_r);
- free_aligned_buffer_page_end(tmp_pixels_g);
- free_aligned_buffer_page_end(tmp_pixels_b);
- free_aligned_buffer_page_end(dst_pixels_opt);
- free_aligned_buffer_page_end(dst_pixels_c);
- }
- // TODO(fbarchard): improve test for platforms and cpu detect
- #ifdef HAS_MERGEUVROW_16_AVX2
- TEST_F(LibYUVPlanarTest, MergeUVRow_16_Opt) {
- // Round count up to multiple of 16
- const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15;
- align_buffer_page_end(src_pixels_u, kPixels * 2);
- align_buffer_page_end(src_pixels_v, kPixels * 2);
- align_buffer_page_end(dst_pixels_uv_opt, kPixels * 2 * 2);
- align_buffer_page_end(dst_pixels_uv_c, kPixels * 2 * 2);
- MemRandomize(src_pixels_u, kPixels * 2);
- MemRandomize(src_pixels_v, kPixels * 2);
- memset(dst_pixels_uv_opt, 0, kPixels * 2 * 2);
- memset(dst_pixels_uv_c, 1, kPixels * 2 * 2);
- MergeUVRow_16_C(reinterpret_cast<const uint16_t*>(src_pixels_u),
- reinterpret_cast<const uint16_t*>(src_pixels_v),
- reinterpret_cast<uint16_t*>(dst_pixels_uv_c), 64, kPixels);
- int has_avx2 = TestCpuFlag(kCpuHasAVX2);
- for (int i = 0; i < benchmark_iterations_; ++i) {
- if (has_avx2) {
- MergeUVRow_16_AVX2(reinterpret_cast<const uint16_t*>(src_pixels_u),
- reinterpret_cast<const uint16_t*>(src_pixels_v),
- reinterpret_cast<uint16_t*>(dst_pixels_uv_opt), 64,
- kPixels);
- } else {
- MergeUVRow_16_C(reinterpret_cast<const uint16_t*>(src_pixels_u),
- reinterpret_cast<const uint16_t*>(src_pixels_v),
- reinterpret_cast<uint16_t*>(dst_pixels_uv_opt), 64,
- kPixels);
- }
- }
- for (int i = 0; i < kPixels * 2 * 2; ++i) {
- EXPECT_EQ(dst_pixels_uv_opt[i], dst_pixels_uv_c[i]);
- }
- free_aligned_buffer_page_end(src_pixels_u);
- free_aligned_buffer_page_end(src_pixels_v);
- free_aligned_buffer_page_end(dst_pixels_uv_opt);
- free_aligned_buffer_page_end(dst_pixels_uv_c);
- }
- #endif
- // TODO(fbarchard): Improve test for more platforms.
- #ifdef HAS_MULTIPLYROW_16_AVX2
- TEST_F(LibYUVPlanarTest, MultiplyRow_16_Opt) {
- // Round count up to multiple of 16
- const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15;
- align_buffer_page_end(src_pixels_y, kPixels * 2);
- align_buffer_page_end(dst_pixels_y_opt, kPixels * 2);
- align_buffer_page_end(dst_pixels_y_c, kPixels * 2);
- MemRandomize(src_pixels_y, kPixels * 2);
- memset(dst_pixels_y_opt, 0, kPixels * 2);
- memset(dst_pixels_y_c, 1, kPixels * 2);
- MultiplyRow_16_C(reinterpret_cast<const uint16_t*>(src_pixels_y),
- reinterpret_cast<uint16_t*>(dst_pixels_y_c), 64, kPixels);
- int has_avx2 = TestCpuFlag(kCpuHasAVX2);
- for (int i = 0; i < benchmark_iterations_; ++i) {
- if (has_avx2) {
- MultiplyRow_16_AVX2(reinterpret_cast<const uint16_t*>(src_pixels_y),
- reinterpret_cast<uint16_t*>(dst_pixels_y_opt), 64,
- kPixels);
- } else {
- MultiplyRow_16_C(reinterpret_cast<const uint16_t*>(src_pixels_y),
- reinterpret_cast<uint16_t*>(dst_pixels_y_opt), 64,
- kPixels);
- }
- }
- for (int i = 0; i < kPixels * 2; ++i) {
- EXPECT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]);
- }
- free_aligned_buffer_page_end(src_pixels_y);
- free_aligned_buffer_page_end(dst_pixels_y_opt);
- free_aligned_buffer_page_end(dst_pixels_y_c);
- }
- #endif // HAS_MULTIPLYROW_16_AVX2
- TEST_F(LibYUVPlanarTest, Convert16To8Plane) {
- // Round count up to multiple of 16
- const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15;
- align_buffer_page_end(src_pixels_y, kPixels * 2);
- align_buffer_page_end(dst_pixels_y_opt, kPixels);
- align_buffer_page_end(dst_pixels_y_c, kPixels);
- MemRandomize(src_pixels_y, kPixels * 2);
- memset(dst_pixels_y_opt, 0, kPixels);
- memset(dst_pixels_y_c, 1, kPixels);
- MaskCpuFlags(disable_cpu_flags_);
- Convert16To8Plane(reinterpret_cast<const uint16_t*>(src_pixels_y),
- benchmark_width_, dst_pixels_y_c, benchmark_width_, 16384,
- benchmark_width_, benchmark_height_);
- MaskCpuFlags(benchmark_cpu_info_);
- for (int i = 0; i < benchmark_iterations_; ++i) {
- Convert16To8Plane(reinterpret_cast<const uint16_t*>(src_pixels_y),
- benchmark_width_, dst_pixels_y_opt, benchmark_width_,
- 16384, benchmark_width_, benchmark_height_);
- }
- for (int i = 0; i < kPixels; ++i) {
- EXPECT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]);
- }
- free_aligned_buffer_page_end(src_pixels_y);
- free_aligned_buffer_page_end(dst_pixels_y_opt);
- free_aligned_buffer_page_end(dst_pixels_y_c);
- }
- #ifdef ENABLE_ROW_TESTS
- // TODO(fbarchard): Improve test for more platforms.
- #ifdef HAS_CONVERT16TO8ROW_AVX2
- TEST_F(LibYUVPlanarTest, Convert16To8Row_Opt) {
- // AVX2 does multiple of 32, so round count up
- const int kPixels = (benchmark_width_ * benchmark_height_ + 31) & ~31;
- align_buffer_page_end(src_pixels_y, kPixels * 2);
- align_buffer_page_end(dst_pixels_y_opt, kPixels);
- align_buffer_page_end(dst_pixels_y_c, kPixels);
- MemRandomize(src_pixels_y, kPixels * 2);
- // clamp source range to 10 bits.
- for (int i = 0; i < kPixels; ++i) {
- reinterpret_cast<uint16_t*>(src_pixels_y)[i] &= 1023;
- }
- memset(dst_pixels_y_opt, 0, kPixels);
- memset(dst_pixels_y_c, 1, kPixels);
- Convert16To8Row_C(reinterpret_cast<const uint16_t*>(src_pixels_y),
- dst_pixels_y_c, 16384, kPixels);
- int has_avx2 = TestCpuFlag(kCpuHasAVX2);
- int has_ssse3 = TestCpuFlag(kCpuHasSSSE3);
- for (int i = 0; i < benchmark_iterations_; ++i) {
- if (has_avx2) {
- Convert16To8Row_AVX2(reinterpret_cast<const uint16_t*>(src_pixels_y),
- dst_pixels_y_opt, 16384, kPixels);
- } else if (has_ssse3) {
- Convert16To8Row_SSSE3(reinterpret_cast<const uint16_t*>(src_pixels_y),
- dst_pixels_y_opt, 16384, kPixels);
- } else {
- Convert16To8Row_C(reinterpret_cast<const uint16_t*>(src_pixels_y),
- dst_pixels_y_opt, 16384, kPixels);
- }
- }
- for (int i = 0; i < kPixels; ++i) {
- EXPECT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]);
- }
- free_aligned_buffer_page_end(src_pixels_y);
- free_aligned_buffer_page_end(dst_pixels_y_opt);
- free_aligned_buffer_page_end(dst_pixels_y_c);
- }
- #endif // HAS_CONVERT16TO8ROW_AVX2
- #endif // ENABLE_ROW_TESTS
- TEST_F(LibYUVPlanarTest, Convert8To16Plane) {
- // Round count up to multiple of 16
- const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15;
- align_buffer_page_end(src_pixels_y, kPixels);
- align_buffer_page_end(dst_pixels_y_opt, kPixels * 2);
- align_buffer_page_end(dst_pixels_y_c, kPixels * 2);
- MemRandomize(src_pixels_y, kPixels);
- memset(dst_pixels_y_opt, 0, kPixels * 2);
- memset(dst_pixels_y_c, 1, kPixels * 2);
- MaskCpuFlags(disable_cpu_flags_);
- Convert8To16Plane(src_pixels_y, benchmark_width_,
- reinterpret_cast<uint16_t*>(dst_pixels_y_c),
- benchmark_width_, 1024, benchmark_width_,
- benchmark_height_);
- MaskCpuFlags(benchmark_cpu_info_);
- for (int i = 0; i < benchmark_iterations_; ++i) {
- Convert8To16Plane(src_pixels_y, benchmark_width_,
- reinterpret_cast<uint16_t*>(dst_pixels_y_opt),
- benchmark_width_, 1024, benchmark_width_,
- benchmark_height_);
- }
- for (int i = 0; i < kPixels * 2; ++i) {
- EXPECT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]);
- }
- free_aligned_buffer_page_end(src_pixels_y);
- free_aligned_buffer_page_end(dst_pixels_y_opt);
- free_aligned_buffer_page_end(dst_pixels_y_c);
- }
- #ifdef ENABLE_ROW_TESTS
- // TODO(fbarchard): Improve test for more platforms.
- #ifdef HAS_CONVERT8TO16ROW_AVX2
- TEST_F(LibYUVPlanarTest, Convert8To16Row_Opt) {
- const int kPixels = (benchmark_width_ * benchmark_height_ + 31) & ~31;
- align_buffer_page_end(src_pixels_y, kPixels);
- align_buffer_page_end(dst_pixels_y_opt, kPixels * 2);
- align_buffer_page_end(dst_pixels_y_c, kPixels * 2);
- MemRandomize(src_pixels_y, kPixels);
- memset(dst_pixels_y_opt, 0, kPixels * 2);
- memset(dst_pixels_y_c, 1, kPixels * 2);
- Convert8To16Row_C(src_pixels_y, reinterpret_cast<uint16_t*>(dst_pixels_y_c),
- 1024, kPixels);
- int has_avx2 = TestCpuFlag(kCpuHasAVX2);
- int has_sse2 = TestCpuFlag(kCpuHasSSE2);
- for (int i = 0; i < benchmark_iterations_; ++i) {
- if (has_avx2) {
- Convert8To16Row_AVX2(src_pixels_y,
- reinterpret_cast<uint16_t*>(dst_pixels_y_opt), 1024,
- kPixels);
- } else if (has_sse2) {
- Convert8To16Row_SSE2(src_pixels_y,
- reinterpret_cast<uint16_t*>(dst_pixels_y_opt), 1024,
- kPixels);
- } else {
- Convert8To16Row_C(src_pixels_y,
- reinterpret_cast<uint16_t*>(dst_pixels_y_opt), 1024,
- kPixels);
- }
- }
- for (int i = 0; i < kPixels * 2; ++i) {
- EXPECT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]);
- }
- free_aligned_buffer_page_end(src_pixels_y);
- free_aligned_buffer_page_end(dst_pixels_y_opt);
- free_aligned_buffer_page_end(dst_pixels_y_c);
- }
- #endif // HAS_CONVERT8TO16ROW_AVX2
- float TestScaleMaxSamples(int benchmark_width,
- int benchmark_height,
- int benchmark_iterations,
- float scale,
- bool opt) {
- int i, j;
- float max_c, max_opt = 0.f;
- // NEON does multiple of 8, so round count up
- const int kPixels = (benchmark_width * benchmark_height + 7) & ~7;
- align_buffer_page_end(orig_y, kPixels * 4 * 3 + 48);
- uint8_t* dst_c = orig_y + kPixels * 4 + 16;
- uint8_t* dst_opt = orig_y + kPixels * 4 * 2 + 32;
- // Randomize works but may contain some denormals affecting performance.
- // MemRandomize(orig_y, kPixels * 4);
- // large values are problematic. audio is really -1 to 1.
- for (i = 0; i < kPixels; ++i) {
- (reinterpret_cast<float*>(orig_y))[i] = sinf(static_cast<float>(i) * 0.1f);
- }
- memset(dst_c, 0, kPixels * 4);
- memset(dst_opt, 1, kPixels * 4);
- max_c = ScaleMaxSamples_C(reinterpret_cast<float*>(orig_y),
- reinterpret_cast<float*>(dst_c), scale, kPixels);
- for (j = 0; j < benchmark_iterations; j++) {
- if (opt) {
- #ifdef HAS_SCALESUMSAMPLES_NEON
- max_opt = ScaleMaxSamples_NEON(reinterpret_cast<float*>(orig_y),
- reinterpret_cast<float*>(dst_opt), scale,
- kPixels);
- #else
- max_opt =
- ScaleMaxSamples_C(reinterpret_cast<float*>(orig_y),
- reinterpret_cast<float*>(dst_opt), scale, kPixels);
- #endif
- } else {
- max_opt =
- ScaleMaxSamples_C(reinterpret_cast<float*>(orig_y),
- reinterpret_cast<float*>(dst_opt), scale, kPixels);
- }
- }
- float max_diff = FAbs(max_opt - max_c);
- for (i = 0; i < kPixels; ++i) {
- float abs_diff = FAbs((reinterpret_cast<float*>(dst_c)[i]) -
- (reinterpret_cast<float*>(dst_opt)[i]));
- if (abs_diff > max_diff) {
- max_diff = abs_diff;
- }
- }
- free_aligned_buffer_page_end(orig_y);
- return max_diff;
- }
- TEST_F(LibYUVPlanarTest, TestScaleMaxSamples_C) {
- float diff = TestScaleMaxSamples(benchmark_width_, benchmark_height_,
- benchmark_iterations_, 1.2f, false);
- EXPECT_EQ(0, diff);
- }
- TEST_F(LibYUVPlanarTest, TestScaleMaxSamples_Opt) {
- float diff = TestScaleMaxSamples(benchmark_width_, benchmark_height_,
- benchmark_iterations_, 1.2f, true);
- EXPECT_EQ(0, diff);
- }
- float TestScaleSumSamples(int benchmark_width,
- int benchmark_height,
- int benchmark_iterations,
- float scale,
- bool opt) {
- int i, j;
- float sum_c, sum_opt = 0.f;
- // NEON does multiple of 8, so round count up
- const int kPixels = (benchmark_width * benchmark_height + 7) & ~7;
- align_buffer_page_end(orig_y, kPixels * 4 * 3);
- uint8_t* dst_c = orig_y + kPixels * 4;
- uint8_t* dst_opt = orig_y + kPixels * 4 * 2;
- // Randomize works but may contain some denormals affecting performance.
- // MemRandomize(orig_y, kPixels * 4);
- // large values are problematic. audio is really -1 to 1.
- for (i = 0; i < kPixels; ++i) {
- (reinterpret_cast<float*>(orig_y))[i] = sinf(static_cast<float>(i) * 0.1f);
- }
- memset(dst_c, 0, kPixels * 4);
- memset(dst_opt, 1, kPixels * 4);
- sum_c = ScaleSumSamples_C(reinterpret_cast<float*>(orig_y),
- reinterpret_cast<float*>(dst_c), scale, kPixels);
- for (j = 0; j < benchmark_iterations; j++) {
- if (opt) {
- #ifdef HAS_SCALESUMSAMPLES_NEON
- sum_opt = ScaleSumSamples_NEON(reinterpret_cast<float*>(orig_y),
- reinterpret_cast<float*>(dst_opt), scale,
- kPixels);
- #else
- sum_opt =
- ScaleSumSamples_C(reinterpret_cast<float*>(orig_y),
- reinterpret_cast<float*>(dst_opt), scale, kPixels);
- #endif
- } else {
- sum_opt =
- ScaleSumSamples_C(reinterpret_cast<float*>(orig_y),
- reinterpret_cast<float*>(dst_opt), scale, kPixels);
- }
- }
- float mse_opt = sum_opt / kPixels * 4;
- float mse_c = sum_c / kPixels * 4;
- float mse_error = FAbs(mse_opt - mse_c) / mse_c;
- // If the sum of a float is more than 4 million, small adds are round down on
- // float and produce different results with vectorized sum vs scalar sum.
- // Ignore the difference if the sum is large.
- float max_diff = 0.f;
- if (mse_error > 0.0001 && sum_c < 4000000) { // allow .01% difference of mse
- max_diff = mse_error;
- }
- for (i = 0; i < kPixels; ++i) {
- float abs_diff = FAbs((reinterpret_cast<float*>(dst_c)[i]) -
- (reinterpret_cast<float*>(dst_opt)[i]));
- if (abs_diff > max_diff) {
- max_diff = abs_diff;
- }
- }
- free_aligned_buffer_page_end(orig_y);
- return max_diff;
- }
- TEST_F(LibYUVPlanarTest, TestScaleSumSamples_C) {
- float diff = TestScaleSumSamples(benchmark_width_, benchmark_height_,
- benchmark_iterations_, 1.2f, false);
- EXPECT_EQ(0, diff);
- }
- TEST_F(LibYUVPlanarTest, TestScaleSumSamples_Opt) {
- float diff = TestScaleSumSamples(benchmark_width_, benchmark_height_,
- benchmark_iterations_, 1.2f, true);
- EXPECT_EQ(0, diff);
- }
- float TestScaleSamples(int benchmark_width,
- int benchmark_height,
- int benchmark_iterations,
- float scale,
- bool opt) {
- int i, j;
- // NEON does multiple of 8, so round count up
- const int kPixels = (benchmark_width * benchmark_height + 7) & ~7;
- align_buffer_page_end(orig_y, kPixels * 4 * 3);
- uint8_t* dst_c = orig_y + kPixels * 4;
- uint8_t* dst_opt = orig_y + kPixels * 4 * 2;
- // Randomize works but may contain some denormals affecting performance.
- // MemRandomize(orig_y, kPixels * 4);
- // large values are problematic. audio is really -1 to 1.
- for (i = 0; i < kPixels; ++i) {
- (reinterpret_cast<float*>(orig_y))[i] = sinf(static_cast<float>(i) * 0.1f);
- }
- memset(dst_c, 0, kPixels * 4);
- memset(dst_opt, 1, kPixels * 4);
- ScaleSamples_C(reinterpret_cast<float*>(orig_y),
- reinterpret_cast<float*>(dst_c), scale, kPixels);
- for (j = 0; j < benchmark_iterations; j++) {
- if (opt) {
- #ifdef HAS_SCALESUMSAMPLES_NEON
- ScaleSamples_NEON(reinterpret_cast<float*>(orig_y),
- reinterpret_cast<float*>(dst_opt), scale, kPixels);
- #else
- ScaleSamples_C(reinterpret_cast<float*>(orig_y),
- reinterpret_cast<float*>(dst_opt), scale, kPixels);
- #endif
- } else {
- ScaleSamples_C(reinterpret_cast<float*>(orig_y),
- reinterpret_cast<float*>(dst_opt), scale, kPixels);
- }
- }
- float max_diff = 0.f;
- for (i = 0; i < kPixels; ++i) {
- float abs_diff = FAbs((reinterpret_cast<float*>(dst_c)[i]) -
- (reinterpret_cast<float*>(dst_opt)[i]));
- if (abs_diff > max_diff) {
- max_diff = abs_diff;
- }
- }
- free_aligned_buffer_page_end(orig_y);
- return max_diff;
- }
- TEST_F(LibYUVPlanarTest, TestScaleSamples_C) {
- float diff = TestScaleSamples(benchmark_width_, benchmark_height_,
- benchmark_iterations_, 1.2f, false);
- EXPECT_EQ(0, diff);
- }
- TEST_F(LibYUVPlanarTest, TestScaleSamples_Opt) {
- float diff = TestScaleSamples(benchmark_width_, benchmark_height_,
- benchmark_iterations_, 1.2f, true);
- EXPECT_EQ(0, diff);
- }
- float TestCopySamples(int benchmark_width,
- int benchmark_height,
- int benchmark_iterations,
- bool opt) {
- int i, j;
- // NEON does multiple of 16 floats, so round count up
- const int kPixels = (benchmark_width * benchmark_height + 15) & ~15;
- align_buffer_page_end(orig_y, kPixels * 4 * 3);
- uint8_t* dst_c = orig_y + kPixels * 4;
- uint8_t* dst_opt = orig_y + kPixels * 4 * 2;
- // Randomize works but may contain some denormals affecting performance.
- // MemRandomize(orig_y, kPixels * 4);
- // large values are problematic. audio is really -1 to 1.
- for (i = 0; i < kPixels; ++i) {
- (reinterpret_cast<float*>(orig_y))[i] = sinf(static_cast<float>(i) * 0.1f);
- }
- memset(dst_c, 0, kPixels * 4);
- memset(dst_opt, 1, kPixels * 4);
- memcpy(reinterpret_cast<void*>(dst_c), reinterpret_cast<void*>(orig_y),
- kPixels * 4);
- for (j = 0; j < benchmark_iterations; j++) {
- if (opt) {
- #ifdef HAS_COPYROW_NEON
- CopyRow_NEON(orig_y, dst_opt, kPixels * 4);
- #else
- CopyRow_C(orig_y, dst_opt, kPixels * 4);
- #endif
- } else {
- CopyRow_C(orig_y, dst_opt, kPixels * 4);
- }
- }
- float max_diff = 0.f;
- for (i = 0; i < kPixels; ++i) {
- float abs_diff = FAbs((reinterpret_cast<float*>(dst_c)[i]) -
- (reinterpret_cast<float*>(dst_opt)[i]));
- if (abs_diff > max_diff) {
- max_diff = abs_diff;
- }
- }
- free_aligned_buffer_page_end(orig_y);
- return max_diff;
- }
- TEST_F(LibYUVPlanarTest, TestCopySamples_C) {
- float diff = TestCopySamples(benchmark_width_, benchmark_height_,
- benchmark_iterations_, false);
- EXPECT_EQ(0, diff);
- }
- TEST_F(LibYUVPlanarTest, TestCopySamples_Opt) {
- float diff = TestCopySamples(benchmark_width_, benchmark_height_,
- benchmark_iterations_, true);
- EXPECT_EQ(0, diff);
- }
- extern "C" void GaussRow_NEON(const uint32_t* src, uint16_t* dst, int width);
- extern "C" void GaussRow_C(const uint32_t* src, uint16_t* dst, int width);
- TEST_F(LibYUVPlanarTest, TestGaussRow_Opt) {
- SIMD_ALIGNED(uint32_t orig_pixels[640 + 4]);
- SIMD_ALIGNED(uint16_t dst_pixels_c[640]);
- SIMD_ALIGNED(uint16_t dst_pixels_opt[640]);
- memset(orig_pixels, 0, sizeof(orig_pixels));
- memset(dst_pixels_c, 1, sizeof(dst_pixels_c));
- memset(dst_pixels_opt, 2, sizeof(dst_pixels_opt));
- for (int i = 0; i < 640 + 4; ++i) {
- orig_pixels[i] = i * 256;
- }
- GaussRow_C(&orig_pixels[0], &dst_pixels_c[0], 640);
- for (int i = 0; i < benchmark_pixels_div1280_ * 2; ++i) {
- #if !defined(LIBYUV_DISABLE_NEON) && \
- (defined(__aarch64__) || defined(__ARM_NEON__) || defined(LIBYUV_NEON))
- int has_neon = TestCpuFlag(kCpuHasNEON);
- if (has_neon) {
- GaussRow_NEON(&orig_pixels[0], &dst_pixels_opt[0], 640);
- } else {
- GaussRow_C(&orig_pixels[0], &dst_pixels_opt[0], 640);
- }
- #else
- GaussRow_C(&orig_pixels[0], &dst_pixels_opt[0], 640);
- #endif
- }
- for (int i = 0; i < 640; ++i) {
- EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
- }
- EXPECT_EQ(dst_pixels_c[0],
- static_cast<uint16_t>(0 * 1 + 1 * 4 + 2 * 6 + 3 * 4 + 4 * 1));
- EXPECT_EQ(dst_pixels_c[639], static_cast<uint16_t>(10256));
- }
- extern "C" void GaussCol_NEON(const uint16_t* src0,
- const uint16_t* src1,
- const uint16_t* src2,
- const uint16_t* src3,
- const uint16_t* src4,
- uint32_t* dst,
- int width);
- extern "C" void GaussCol_C(const uint16_t* src0,
- const uint16_t* src1,
- const uint16_t* src2,
- const uint16_t* src3,
- const uint16_t* src4,
- uint32_t* dst,
- int width);
- TEST_F(LibYUVPlanarTest, TestGaussCol_Opt) {
- SIMD_ALIGNED(uint16_t orig_pixels[640 * 5]);
- SIMD_ALIGNED(uint32_t dst_pixels_c[640]);
- SIMD_ALIGNED(uint32_t dst_pixels_opt[640]);
- memset(orig_pixels, 0, sizeof(orig_pixels));
- memset(dst_pixels_c, 1, sizeof(dst_pixels_c));
- memset(dst_pixels_opt, 2, sizeof(dst_pixels_opt));
- for (int i = 0; i < 640 * 5; ++i) {
- orig_pixels[i] = i;
- }
- GaussCol_C(&orig_pixels[0], &orig_pixels[640], &orig_pixels[640 * 2],
- &orig_pixels[640 * 3], &orig_pixels[640 * 4], &dst_pixels_c[0],
- 640);
- for (int i = 0; i < benchmark_pixels_div1280_ * 2; ++i) {
- #if !defined(LIBYUV_DISABLE_NEON) && \
- (defined(__aarch64__) || defined(__ARM_NEON__) || defined(LIBYUV_NEON))
- int has_neon = TestCpuFlag(kCpuHasNEON);
- if (has_neon) {
- GaussCol_NEON(&orig_pixels[0], &orig_pixels[640], &orig_pixels[640 * 2],
- &orig_pixels[640 * 3], &orig_pixels[640 * 4],
- &dst_pixels_opt[0], 640);
- } else {
- GaussCol_C(&orig_pixels[0], &orig_pixels[640], &orig_pixels[640 * 2],
- &orig_pixels[640 * 3], &orig_pixels[640 * 4],
- &dst_pixels_opt[0], 640);
- }
- #else
- GaussCol_C(&orig_pixels[0], &orig_pixels[640], &orig_pixels[640 * 2],
- &orig_pixels[640 * 3], &orig_pixels[640 * 4], &dst_pixels_opt[0],
- 640);
- #endif
- }
- for (int i = 0; i < 640; ++i) {
- EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
- }
- EXPECT_EQ(dst_pixels_c[0],
- static_cast<uint32_t>(0 * 1 + 640 * 4 + 640 * 2 * 6 + 640 * 3 * 4 +
- 640 * 4 * 1));
- EXPECT_EQ(dst_pixels_c[639], static_cast<uint32_t>(30704));
- }
- TEST_F(LibYUVPlanarTest, SwapUVRow) {
- const int kPixels = benchmark_width_ * benchmark_height_;
- void (*SwapUVRow)(const uint8_t* src_uv, uint8_t* dst_vu, int width) =
- SwapUVRow_C;
- align_buffer_page_end(src_pixels_vu, kPixels * 2);
- align_buffer_page_end(dst_pixels_uv, kPixels * 2);
- MemRandomize(src_pixels_vu, kPixels * 2);
- memset(dst_pixels_uv, 1, kPixels * 2);
- #if defined(HAS_SWAPUVROW_NEON)
- if (TestCpuFlag(kCpuHasNEON)) {
- SwapUVRow = SwapUVRow_Any_NEON;
- if (IS_ALIGNED(kPixels, 16)) {
- SwapUVRow = SwapUVRow_NEON;
- }
- }
- #endif
- for (int j = 0; j < benchmark_iterations_; j++) {
- SwapUVRow(src_pixels_vu, dst_pixels_uv, kPixels);
- }
- for (int i = 0; i < kPixels; ++i) {
- EXPECT_EQ(dst_pixels_uv[i * 2 + 0], src_pixels_vu[i * 2 + 1]);
- EXPECT_EQ(dst_pixels_uv[i * 2 + 1], src_pixels_vu[i * 2 + 0]);
- }
- free_aligned_buffer_page_end(src_pixels_vu);
- free_aligned_buffer_page_end(dst_pixels_uv);
- }
- #endif
- } // namespace libyuv
|