1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565 |
- /*
- * 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"
- #include "libyuv/scale.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]);
- }
- }
- }
- // near is for legacy platforms.
- 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_NEAR(29u, orig_pixels[0][0], 1);
- EXPECT_NEAR(29u, orig_pixels[0][1], 1);
- EXPECT_NEAR(29u, orig_pixels[0][2], 1);
- 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_NEAR(77u, orig_pixels[2][0], 1);
- EXPECT_NEAR(77u, orig_pixels[2][1], 1);
- EXPECT_NEAR(77u, orig_pixels[2][2], 1);
- 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_NEAR(97u, orig_pixels[5][0], 1);
- EXPECT_NEAR(97u, orig_pixels[5][1], 1);
- EXPECT_NEAR(97u, orig_pixels[5][2], 1);
- 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_NEAR(30u, gray_pixels[0][0], 1);
- EXPECT_NEAR(30u, gray_pixels[0][1], 1);
- EXPECT_NEAR(30u, gray_pixels[0][2], 1);
- EXPECT_NEAR(128u, gray_pixels[0][3], 1);
- EXPECT_NEAR(149u, gray_pixels[1][0], 1);
- EXPECT_NEAR(149u, gray_pixels[1][1], 1);
- EXPECT_NEAR(149u, gray_pixels[1][2], 1);
- EXPECT_NEAR(0u, gray_pixels[1][3], 1);
- EXPECT_NEAR(76u, gray_pixels[2][0], 1);
- EXPECT_NEAR(76u, gray_pixels[2][1], 1);
- EXPECT_NEAR(76u, gray_pixels[2][2], 1);
- EXPECT_NEAR(255u, gray_pixels[2][3], 1);
- EXPECT_NEAR(0u, gray_pixels[3][0], 1);
- EXPECT_NEAR(0u, gray_pixels[3][1], 1);
- EXPECT_NEAR(0u, gray_pixels[3][2], 1);
- EXPECT_NEAR(255u, gray_pixels[3][3], 1);
- EXPECT_NEAR(255u, gray_pixels[4][0], 1);
- EXPECT_NEAR(255u, gray_pixels[4][1], 1);
- EXPECT_NEAR(255u, gray_pixels[4][2], 1);
- EXPECT_NEAR(255u, gray_pixels[4][3], 1);
- EXPECT_NEAR(96u, gray_pixels[5][0], 1);
- EXPECT_NEAR(96u, gray_pixels[5][1], 1);
- EXPECT_NEAR(96u, gray_pixels[5][2], 1);
- EXPECT_NEAR(224u, gray_pixels[5][3], 1);
- 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);
- }
- for (int i = 0; i < 256; ++i) {
- orig_pixels[i][0] = i;
- orig_pixels[i][1] = i;
- orig_pixels[i][2] = i;
- orig_pixels[i][3] = i;
- }
- ARGBGray(&orig_pixels[0][0], 0, 0, 0, 256, 1);
- for (int i = 0; i < 256; ++i) {
- EXPECT_EQ(i, orig_pixels[i][0]);
- EXPECT_EQ(i, orig_pixels[i][1]);
- EXPECT_EQ(i, orig_pixels[i][2]);
- EXPECT_EQ(i, orig_pixels[i][3]);
- }
- }
- 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, ARGBMirror_Opt) {
- align_buffer_page_end(src_pixels, benchmark_width_ * benchmark_height_ * 4);
- align_buffer_page_end(dst_pixels_opt,
- benchmark_width_ * benchmark_height_ * 4);
- align_buffer_page_end(dst_pixels_c, benchmark_width_ * benchmark_height_ * 4);
- MemRandomize(src_pixels, benchmark_width_ * benchmark_height_ * 4);
- MaskCpuFlags(disable_cpu_flags_);
- ARGBMirror(src_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) {
- ARGBMirror(src_pixels, benchmark_width_ * 4, dst_pixels_opt,
- benchmark_width_ * 4, benchmark_width_, benchmark_height_);
- }
- for (int i = 0; i < benchmark_width_ * benchmark_height_ * 4; ++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, MirrorPlane_Opt) {
- align_buffer_page_end(src_pixels, benchmark_width_ * benchmark_height_);
- align_buffer_page_end(dst_pixels_opt, benchmark_width_ * benchmark_height_);
- align_buffer_page_end(dst_pixels_c, benchmark_width_ * benchmark_height_);
- MemRandomize(src_pixels, benchmark_width_ * benchmark_height_);
- MaskCpuFlags(disable_cpu_flags_);
- MirrorPlane(src_pixels, benchmark_width_, dst_pixels_c, benchmark_width_,
- benchmark_width_, benchmark_height_);
- MaskCpuFlags(benchmark_cpu_info_);
- for (int i = 0; i < benchmark_iterations_; ++i) {
- MirrorPlane(src_pixels, benchmark_width_, dst_pixels_opt, benchmark_width_,
- benchmark_width_, benchmark_height_);
- }
- for (int i = 0; i < benchmark_width_ * benchmark_height_; ++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, MirrorUVPlane_Opt) {
- align_buffer_page_end(src_pixels, benchmark_width_ * benchmark_height_ * 2);
- align_buffer_page_end(dst_pixels_opt,
- benchmark_width_ * benchmark_height_ * 2);
- align_buffer_page_end(dst_pixels_c, benchmark_width_ * benchmark_height_ * 2);
- MemRandomize(src_pixels, benchmark_width_ * benchmark_height_ * 2);
- MaskCpuFlags(disable_cpu_flags_);
- MirrorUVPlane(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) {
- MirrorUVPlane(src_pixels, benchmark_width_ * 2, dst_pixels_opt,
- benchmark_width_ * 2, benchmark_width_, benchmark_height_);
- }
- for (int i = 0; i < benchmark_width_ * benchmark_height_ * 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, 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,
- int attenuate) {
- 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);
- }
- MemRandomize(src_argb_a, kStride * height + off);
- MemRandomize(src_argb_b, kStride * height + off);
- if (attenuate) {
- ARGBAttenuate(src_argb_a + off, kStride, src_argb_a + 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, 1);
- 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, 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, 1);
- EXPECT_LE(max_diff, 1);
- }
- TEST_F(LibYUVPlanarTest, ARGBBlend_Unattenuated) {
- int max_diff =
- TestBlend(benchmark_width_, benchmark_height_, benchmark_iterations_,
- disable_cpu_flags_, benchmark_cpu_info_, +1, 0, 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, 1);
- 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[1280 + 8]);
- SIMD_ALIGNED(uint16_t dst_pixels_c[1280]);
- SIMD_ALIGNED(uint16_t dst_pixels_opt[1280]);
- 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 < 1280 + 8; ++i) {
- orig_pixels[i] = i * 256;
- }
- GaussRow_C(&orig_pixels[0], &dst_pixels_c[0], 1280);
- for (int i = 0; i < benchmark_pixels_div1280_; ++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], 1280);
- } else {
- GaussRow_C(&orig_pixels[0], &dst_pixels_opt[0], 1280);
- }
- #else
- GaussRow_C(&orig_pixels[0], &dst_pixels_opt[0], 1280);
- #endif
- }
- for (int i = 0; i < 1280; ++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[1280 * 5]);
- SIMD_ALIGNED(uint32_t dst_pixels_c[1280]);
- SIMD_ALIGNED(uint32_t dst_pixels_opt[1280]);
- 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 < 1280 * 5; ++i) {
- orig_pixels[i] = static_cast<float>(i);
- }
- GaussCol_C(&orig_pixels[0], &orig_pixels[1280], &orig_pixels[1280 * 2],
- &orig_pixels[1280 * 3], &orig_pixels[1280 * 4], &dst_pixels_c[0],
- 1280);
- for (int i = 0; i < benchmark_pixels_div1280_; ++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[1280], &orig_pixels[1280 * 2],
- &orig_pixels[1280 * 3], &orig_pixels[1280 * 4],
- &dst_pixels_opt[0], 1280);
- } else {
- GaussCol_C(&orig_pixels[0], &orig_pixels[1280], &orig_pixels[1280 * 2],
- &orig_pixels[1280 * 3], &orig_pixels[1280 * 4],
- &dst_pixels_opt[0], 1280);
- }
- #else
- GaussCol_C(&orig_pixels[0], &orig_pixels[1280], &orig_pixels[1280 * 2],
- &orig_pixels[1280 * 3], &orig_pixels[1280 * 4],
- &dst_pixels_opt[0], 1280);
- #endif
- }
- for (int i = 0; i < 1280; ++i) {
- EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
- }
- }
- TEST_F(LibYUVPlanarTest, TestGaussRow_F32_Opt) {
- SIMD_ALIGNED(float orig_pixels[1280 + 4]);
- SIMD_ALIGNED(float dst_pixels_c[1280]);
- SIMD_ALIGNED(float dst_pixels_opt[1280]);
- 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 < 1280 + 4; ++i) {
- orig_pixels[i] = static_cast<float>(i);
- }
- GaussRow_F32_C(&orig_pixels[0], &dst_pixels_c[0], 1280);
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
- #if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__)
- int has_neon = TestCpuFlag(kCpuHasNEON);
- if (has_neon) {
- GaussRow_F32_NEON(&orig_pixels[0], &dst_pixels_opt[0], 1280);
- } else {
- GaussRow_F32_C(&orig_pixels[0], &dst_pixels_opt[0], 1280);
- }
- #else
- GaussRow_F32_C(&orig_pixels[0], &dst_pixels_opt[0], 1280);
- #endif
- }
- for (int i = 0; i < 1280; ++i) {
- EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
- }
- }
- TEST_F(LibYUVPlanarTest, TestGaussCol_F32_Opt) {
- SIMD_ALIGNED(float dst_pixels_c[1280]);
- SIMD_ALIGNED(float dst_pixels_opt[1280]);
- align_buffer_page_end(orig_pixels_buf, 1280 * 5 * 4); // 5 rows
- float* orig_pixels = reinterpret_cast<float*>(orig_pixels_buf);
- memset(orig_pixels, 0, 1280 * 5 * 4);
- memset(dst_pixels_c, 1, sizeof(dst_pixels_c));
- memset(dst_pixels_opt, 2, sizeof(dst_pixels_opt));
- for (int i = 0; i < 1280 * 5; ++i) {
- orig_pixels[i] = static_cast<float>(i);
- }
- GaussCol_F32_C(&orig_pixels[0], &orig_pixels[1280], &orig_pixels[1280 * 2],
- &orig_pixels[1280 * 3], &orig_pixels[1280 * 4],
- &dst_pixels_c[0], 1280);
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
- #if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__)
- int has_neon = TestCpuFlag(kCpuHasNEON);
- if (has_neon) {
- GaussCol_F32_NEON(&orig_pixels[0], &orig_pixels[1280],
- &orig_pixels[1280 * 2], &orig_pixels[1280 * 3],
- &orig_pixels[1280 * 4], &dst_pixels_opt[0], 1280);
- } else {
- GaussCol_F32_C(&orig_pixels[0], &orig_pixels[1280],
- &orig_pixels[1280 * 2], &orig_pixels[1280 * 3],
- &orig_pixels[1280 * 4], &dst_pixels_opt[0], 1280);
- }
- #else
- GaussCol_F32_C(&orig_pixels[0], &orig_pixels[1280], &orig_pixels[1280 * 2],
- &orig_pixels[1280 * 3], &orig_pixels[1280 * 4],
- &dst_pixels_opt[0], 1280);
- #endif
- }
- for (int i = 0; i < 1280; ++i) {
- EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
- }
- free_aligned_buffer_page_end(orig_pixels_buf);
- }
- 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 // ENABLE_ROW_TESTS
- TEST_F(LibYUVPlanarTest, TestGaussPlane_F32) {
- 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);
- for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) {
- ((float*)(orig_pixels))[i] = (i & 1023) * 3.14f;
- }
- memset(dst_pixels_opt, 1, kSize);
- memset(dst_pixels_c, 2, kSize);
- MaskCpuFlags(disable_cpu_flags_);
- GaussPlane_F32((const float*)(orig_pixels), benchmark_width_,
- (float*)(dst_pixels_c), benchmark_width_, benchmark_width_,
- benchmark_height_);
- MaskCpuFlags(benchmark_cpu_info_);
- for (int i = 0; i < benchmark_iterations_; ++i) {
- GaussPlane_F32((const float*)(orig_pixels), benchmark_width_,
- (float*)(dst_pixels_opt), benchmark_width_, benchmark_width_,
- benchmark_height_);
- }
- for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) {
- EXPECT_NEAR(((float*)(dst_pixels_c))[i], ((float*)(dst_pixels_opt))[i], 1.f)
- << 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, HalfMergeUVPlane_Opt) {
- int dst_width = (benchmark_width_ + 1) / 2;
- int dst_height = (benchmark_height_ + 1) / 2;
- align_buffer_page_end(src_pixels_u, benchmark_width_ * benchmark_height_);
- align_buffer_page_end(src_pixels_v, benchmark_width_ * benchmark_height_);
- align_buffer_page_end(tmp_pixels_u, dst_width * dst_height);
- align_buffer_page_end(tmp_pixels_v, dst_width * dst_height);
- align_buffer_page_end(dst_pixels_uv_opt, dst_width * 2 * dst_height);
- align_buffer_page_end(dst_pixels_uv_c, dst_width * 2 * dst_height);
- MemRandomize(src_pixels_u, benchmark_width_ * benchmark_height_);
- MemRandomize(src_pixels_v, benchmark_width_ * benchmark_height_);
- MemRandomize(tmp_pixels_u, dst_width * dst_height);
- MemRandomize(tmp_pixels_v, dst_width * dst_height);
- MemRandomize(dst_pixels_uv_opt, dst_width * 2 * dst_height);
- MemRandomize(dst_pixels_uv_c, dst_width * 2 * dst_height);
- MaskCpuFlags(disable_cpu_flags_);
- HalfMergeUVPlane(src_pixels_u, benchmark_width_, src_pixels_v,
- benchmark_width_, dst_pixels_uv_c, dst_width * 2,
- benchmark_width_, benchmark_height_);
- MaskCpuFlags(benchmark_cpu_info_);
- for (int i = 0; i < benchmark_iterations_; ++i) {
- HalfMergeUVPlane(src_pixels_u, benchmark_width_, src_pixels_v,
- benchmark_width_, dst_pixels_uv_opt, dst_width * 2,
- benchmark_width_, benchmark_height_);
- }
- for (int i = 0; i < dst_width * 2 * dst_height; ++i) {
- EXPECT_EQ(dst_pixels_uv_c[i], dst_pixels_uv_opt[i]);
- }
- free_aligned_buffer_page_end(src_pixels_u);
- free_aligned_buffer_page_end(src_pixels_v);
- free_aligned_buffer_page_end(tmp_pixels_u);
- free_aligned_buffer_page_end(tmp_pixels_v);
- free_aligned_buffer_page_end(dst_pixels_uv_opt);
- free_aligned_buffer_page_end(dst_pixels_uv_c);
- }
- } // namespace libyuv
|