From a06eb10ed8e7c12e3de9bb619b107bc904818d06 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 12 Feb 2020 09:09:34 +0100 Subject: [PATCH] fixed rendering of transparent pdfs; white overlay for very dark pdf --- art/open_pdf_white.svg | 55 ++++++++++++++++++ art/render.rb | 1 + .../persistance/FileBackend.java | 22 ++++++- src/main/res/drawable-hdpi/open_pdf_white.png | Bin 0 -> 1569 bytes src/main/res/drawable-mdpi/open_pdf_white.png | Bin 0 -> 1259 bytes .../res/drawable-xhdpi/open_pdf_white.png | Bin 0 -> 2431 bytes .../res/drawable-xxhdpi/open_pdf_white.png | Bin 0 -> 3301 bytes .../res/drawable-xxxhdpi/open_pdf_white.png | Bin 0 -> 4986 bytes 8 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 art/open_pdf_white.svg create mode 100644 src/main/res/drawable-hdpi/open_pdf_white.png create mode 100644 src/main/res/drawable-mdpi/open_pdf_white.png create mode 100644 src/main/res/drawable-xhdpi/open_pdf_white.png create mode 100644 src/main/res/drawable-xxhdpi/open_pdf_white.png create mode 100644 src/main/res/drawable-xxxhdpi/open_pdf_white.png diff --git a/art/open_pdf_white.svg b/art/open_pdf_white.svg new file mode 100644 index 000000000..a307529bb --- /dev/null +++ b/art/open_pdf_white.svg @@ -0,0 +1,55 @@ + + + + + + image/svg+xml + + + + + + + + + diff --git a/art/render.rb b/art/render.rb index a8f8a6243..86a0ddf79 100755 --- a/art/render.rb +++ b/art/render.rb @@ -24,6 +24,7 @@ images = { 'play_video_black.svg' => ['play_video_black', 128], 'play_gif_black.svg' => ['play_gif_black', 128], 'open_pdf_black.svg' => ['open_pdf_black', 128], + 'open_pdf_white.svg' => ['open_pdf_white', 128], 'conversations_mono.svg' => ['conversations/ic_notification', 24], 'quicksy_mono.svg' => ['quicksy/ic_notification', 24], 'ic_send_text_offline.svg' => ['ic_send_text_offline', 36], diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 906277cea..76d2d7d7b 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -825,7 +825,7 @@ public class FileBackend { } else if (mime.startsWith("video/")) { thumbnail = getVideoPreview(file, size); } else { - Bitmap fullsize = getFullsizeImagePreview(file, size); + Bitmap fullsize = getFullSizeImagePreview(file, size); if (fullsize == null) { throw new FileNotFoundException(); } @@ -844,7 +844,7 @@ public class FileBackend { return thumbnail; } - private Bitmap getFullsizeImagePreview(File file, int size) { + private Bitmap getFullSizeImagePreview(File file, int size) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = calcSampleSize(file, size); try { @@ -886,6 +886,21 @@ public class FileBackend { return record < 0; } + private boolean paintOverlayBlackPdf(final Bitmap bitmap) { + final int h = bitmap.getHeight(); + final int w = bitmap.getWidth(); + int white = 0; + for (int y = 0; y < h; ++y) { + for (int x = 0; x < w; ++x) { + int pixel = bitmap.getPixel(x, y); + if ((Color.red(pixel) * 0.299 + Color.green(pixel) * 0.587 + Color.blue(pixel) * 0.114) > 186) { + white++; + } + } + } + return white > (h * w * 0.4f); + } + private Bitmap cropCenterSquareVideo(Uri uri, int size) { MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever(); Bitmap frame; @@ -925,8 +940,9 @@ public class FileBackend { final PdfRenderer.Page page = pdfRenderer.openPage(0); Dimensions dimensions = scalePdfDimensions(new Dimensions(page.getHeight(), page.getWidth())); final Bitmap rendered = Bitmap.createBitmap(dimensions.width, dimensions.height, Bitmap.Config.ARGB_8888); + rendered.eraseColor(0xffffffff); page.render(rendered, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY); - drawOverlay(rendered, R.drawable.open_pdf_black, 0.75f); + drawOverlay(rendered, paintOverlayBlackPdf(rendered) ? R.drawable.open_pdf_black : R.drawable.open_pdf_white, 0.75f); return rendered; } catch (IOException e) { Log.d(Config.LOGTAG, "unable to render PDF document preview", e); diff --git a/src/main/res/drawable-hdpi/open_pdf_white.png b/src/main/res/drawable-hdpi/open_pdf_white.png new file mode 100644 index 0000000000000000000000000000000000000000..ddfb3365675487b3683e16b48c2deea8dea331dd GIT binary patch literal 1569 zcmbVMYfzI%6x}Z$Bp4DP1stFj1{Dyr7)30~L*x~KpcuhWv4tQBPZ150PzVWCFZ~ zKM9XD!vX;CzWcl=2ufE&2aT+h!FUV;T1*e$ART0+=|u7oz9wET(?IK^Vy+Q1P>7ka~Ai7EB z>?EPfI6%kmY;>`K^9JMS2#>wA3zi2B$>gkarP)TYw5*L0o0c$HjzJqmRd_R9WAYO; zw##Sf87jN|;%MBqsH-x@9>#SAXP7xWnfD@LhRBq)?P4RNzE{_c|&)RfuM7z*DQy5U-=1<~1RwAps>B zR>GmRjnNg1jN61+rsmSQ3alvgk3Bi8<>GwpoE|kfk*eXP48<)ss^ohj2QpX>2AZ+G zTG9!;^4=8T2DU`Juv-3PwB&r-hJSR4xyTnvknz zI){t#ERo<;n1-(gCY*<@4iBeq(2@qqDlB=f3RqzMsX=TBa+m5RXQv=Xt?CV_yx*rf z%mY0^Xbomlz~b>RPr!=O56qV-;8-1ZzhfXaA1aSQi|&~6@)`f1w0zuO#Am1HbH#$~ zu*;K)uit5)PU51~RmYg)BN3&71ATMK1EETkuz@dx)88(0sD2A3?6vIduH2Jl6`Zh< zg|DJ7^EVM@ja6t>fTrka>`32t=;|zf6O;zhuD8%_>y?wbaL8USqftXUPDvFf%)&%! z*X*nyN$aP+^}ovro5qFXhMs2|Dx9w$`Y6damCn0Gsr|?6k=w7~!pVeL3)N{&&YK>I z_%NDyV@?4dKKN1c&O{oSE;Fyb`0_(=8?a_Nrb_K%N2rCZT%(Bk&O7Ay3L#&(xpZ)$ zTzgR>R;Hl?yK(LT4!}_cdUn8{$#K;{yNCF4zJww6!|SKr=sE3cLny@(4pE){@btp@suF14u?+w8nD zDeYE-*14g%>*K4M^IS=)Y^BIlx_;>PGBg^Trf^`(FfTZt=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/src/main/res/drawable-xhdpi/open_pdf_white.png b/src/main/res/drawable-xhdpi/open_pdf_white.png new file mode 100644 index 0000000000000000000000000000000000000000..bba78987ab980a8e6de4e598cea82779483859ca GIT binary patch literal 2431 zcmcguYfw{37Veus!b8A_BG1SKMNxSrfS>^~3=wcZ1mvNFAxI41gP=iz0mmDh8H0#g zJ_!h@Ag_Q@5*0+^wS+;JXh4XvJ}{yKV*m-Vkw6gl;_jcV{W-PU)m?qQ(|x+S`kemG z$=|X$$i&Fn2moLb5*!!_0ECJVFu;$ZU+C6NHN?hL(ZSUjj*aI1xIMKAl{-2G4oCsgMA#?EmIoC20a446X3Ku# zi)I(;_^EiC)5se^HM|n;bQsJYtDLqT!+uAR13!p?8(mda;bn&*Vm{^zud3W9-R=O^ z&~AYZyhi<@js4DBy+(OW=*{qDpWnCymfbbbVlwy|i^8YIh#g^qr8%|DiVnyWctj9R zIjyU_zlrJJ=uf)Am$5y+G9SsJ;1YpZ3@0L%s3)}{tgJh_XJao^G&^+9O1nj4ao|JJ z`NTyYx=`g=6;zVx>!*z#CM#d42qisx0C^Ilj8bgqYa1bRIT~T%E;2ZCaz+|hq4Qh~ z<@!;=#l#zg20u6*IXUBD+X|1=1?>ssLPfT3d325Ghb7l!vIK?0GjR(5LnR$=;}SucFFCu58`UEj-=Sil8!_~6~CsuamhaJQ8Y zOMaUa;mOO0_gXcY&Aim!svdZK;U2aN(- zrHBN#qRmcK^~sX%JL@Ay4)+~npU_Wr0;kzB5Nt;Qk(~?RK6kABf&V?cwbd-{QV?nI zGyQcOI~|{e;b5O&U7#%aOcrUdZrfqGf;HsD+|Y>k#`kx9I#giwrf-Ze@$mS);Xd+Y z3^P$N<{B9e#nlM24YLikHtJONoI&=|43ms~f7~iOCUiguOhc`&dQz6_pmtXpG2`D- z_rk7_#c~pvG`EnDh?N>qG9FWO+s&ATR(6)HU;38lg`6$qQ{GlL>zkR?ucV%|IJiTTG0uAjXBx9 z358`lSj)=82HwvmqX)16&XHsa$z##|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N9{h?sy@CK9?qU%t^E5GZNx!8i+$~ZHfIo!@)5ru7C5O6S(1friWLC4qYkNWl* z|GpY@-c&vbN5}V|&gC`N7s*b2jF$%gq)ejg*3rFVrVY;}@Xl;Jc)RI}`L@Pbr6%yA za{eaIjX4#YlJ8~?1hLm%#J`tZrmCuRp^fnY~RY7d0_5t$Vik`#r^akX$v zb@h!l=I-dzV$7Ac(`5f&$DN7F^Ywc%@tdLCaFC;)QR=JjZPz-6v?PO&fe1ZdFyXQD zBZ;8e11j)cngX`XY9}1&D+@G@qn(Gu{Yc-f!sO8v z=bGl$d+WY(`~W08(mkabkgR0Xrbo3>w1>b*#|(LpU?lGH__uh;^azOdcPuIb*Ci_R zuY-;!T6$TSWVXY9%mI>FydT8MuozZnuy&$v&@pXUE>6l_Q0^+-Mgm2`MGC9VG(32{ zcby(AD+W?7^fRy315lC;QAEZ~J8=Jj&M*)9`Hp4!)f}`=l1(TM1&oVfkwnI8IDTK} zSEP=|@>M375!?12R{G&)62~Z0cD9Boz2wSTDm06P~#pDh2`zB1^1=8JasrE zPwX(1-g$|s3!3;1@idW;0A_j#jR!uJ=akn_TxqseYYTNRvmK|*udmQ#LrW_>aPcg`kG~R{q*WK@&E+U0mV&!!;xiN z5XW57||?(lJuz1&($rpVXAE zyMGAO^=Sn*z}&+U*xWx1r2)hl!jOOKv}Qdl4OWA~IObUtrdq3_$G^Uigb|+YOy$=_ zQt?GU6VdMlu1m@I^ux+0O-P9V5_-=u<&#s;>@iTMQoEZ1^|p*FZDdn0*W z4sV$HT~jJv`X^mOkii;xI@D$nvv%?ltjPu)ZjC z;dEW z`^eCXoV`)I>1h+P1cBA=YkFIa@?dPO<6l{QL)-f_xj2=NJ;jG_x5cs*eQns9%GHdo F{s259T^#@b literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-xxxhdpi/open_pdf_white.png b/src/main/res/drawable-xxxhdpi/open_pdf_white.png new file mode 100644 index 0000000000000000000000000000000000000000..95611f4967f463732587de4a4b80fdf5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