当前位置: 首页 > news >正文

广州模板建站多少钱网络推广平台网站推广

广州模板建站多少钱,网络推广平台网站推广,WordPress预览出错,价格低英语翻译文章目录 Android Bitmap 模糊效果实现 (二)使用 Vukan 模糊使用 RenderEffect 模糊使用 GLSL 模糊RS、Vukan、RenderEffect、GLSL 效率对比 Android Bitmap 模糊效果实现 (二) 本文首发地址 https://blog.csdn.net/CSqingchen/article/details/134656140 最新更新地址 https:/…

文章目录

  • Android Bitmap 模糊效果实现 (二)
      • 使用 Vukan 模糊
      • 使用 RenderEffect 模糊
      • 使用 GLSL 模糊
      • RS、Vukan、RenderEffect、GLSL 效率对比

Android Bitmap 模糊效果实现 (二)

本文首发地址 https://blog.csdn.net/CSqingchen/article/details/134656140
最新更新地址 https://gitee.com/chenjim/chenjimblog

通过 Android Bitmap 模糊效果实现 (一),我们知道可以使用 Toolkit 实现 Bitmap 模糊,还能达到不错的效果。本文主要讲解另外几种实现Bitmap模糊的方法并对比效率。

使用 Vukan 模糊

Vulkan 是一种低开销、跨平台的 API,用于高性能 3D 图形。
Android平台包含 Khronos Group 的 Vulkan API规范的特定实现。
Android Vulkan 使用可以参考:
https://developer.android.com/ndk/guides/graphics/getting-started

使用 Vukan 模糊的核心代码如下,可参考 ImageProcessor.cpp

bool ImageProcessor::blur(float radius, int outputIndex) {RET_CHECK(1.0f <= radius && radius <= 25.0f);// Calculate gaussian kernel, this is equivalent to ComputeGaussianWeights at// https://cs.android.com/android/platform/superproject/+/master:frameworks/rs/cpu_ref/rsCpuIntrinsicBlur.cpp;l=57constexpr float e = 2.718281828459045f;constexpr float pi = 3.1415926535897932f;float sigma = 0.4f * radius + 0.6f;float coeff1 = 1.0f / (std::sqrtf(2.0f * pi) * sigma);float coeff2 = -1.0f / (2.0f * sigma * sigma);int32_t iRadius = static_cast<int>(std::ceilf(radius));float normalizeFactor = 0.0f;for (int r = -iRadius; r <= iRadius; r++) {const float value = coeff1 * std::powf(e, coeff2 * static_cast<float>(r * r));mBlurData.kernel[r + iRadius] = value;normalizeFactor += value;}normalizeFactor = 1.0f / normalizeFactor;for (int r = -iRadius; r <= iRadius; r++) {mBlurData.kernel[r + iRadius] *= normalizeFactor;}RET_CHECK(mBlurUniformBuffer->copyFrom(&mBlurData));// Apply a two-pass blur algorithm: a horizontal blur kernel followed by a vertical// blur kernel. This is equivalent to, but more efficient than applying a 2D blur// filter in a single pass. The two-pass blur algorithm has two kernels, each of// time complexity O(iRadius), while the single-pass algorithm has only one kernel,// but the time complexity is O(iRadius^2).auto cmd = mCommandBuffer->handle();RET_CHECK(beginOneTimeCommandBuffer(cmd));// The temp image is used as an output storage image in the first pass.mTempImage->recordLayoutTransitionBarrier(cmd, VK_IMAGE_LAYOUT_GENERAL, /*preserveData=*/false);// First pass: apply a horizontal gaussian blur.mBlurHorizontalPipeline->recordComputeCommands(cmd, &iRadius, *mInputImage, *mTempImage,mBlurUniformBuffer.get());// The temp image is used as an input sampled image in the second pass,// and the staging image is used as an output storage image.mTempImage->recordLayoutTransitionBarrier(cmd, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);mStagingOutputImage->recordLayoutTransitionBarrier(cmd, VK_IMAGE_LAYOUT_GENERAL,/*preserveData=*/false);// Second pass: apply a vertical gaussian blur.mBlurVerticalPipeline->recordComputeCommands(cmd, &iRadius, *mTempImage, *mStagingOutputImage,mBlurUniformBuffer.get());// Prepare for image copying from the staging image to the output image.mStagingOutputImage->recordLayoutTransitionBarrier(cmd, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);// Copy staging image to output image.recordImageCopyingCommand(cmd, *mStagingOutputImage, *mOutputImages[outputIndex]);// Submit to queue.RET_CHECK(endAndSubmitCommandBuffer(cmd, mContext->queue()));return true;
}

Vukan 环境、资源、Pipeline 相关代码如下

https://github.com/android/renderscript-samples/tree/main/RenderScriptMigrationSample/app/src/main/cpp

上层接口参见 VulkanImageProcessor

这里需要用到 libVkLayer_khronos_validation.so, 可以在以下地址下载新版本
https://github.com/KhronosGroup/Vulkan-ValidationLayers

使用 RenderEffect 模糊

实现代码如下

override fun blur(radius: Float, outputIndex: Int): Bitmap {params?.let {val blurRenderEffect = RenderEffect.createBlurEffect(radius, radius,Shader.TileMode.MIRROR)return applyEffect(it, blurRenderEffect, outputIndex)}throw RuntimeException("Not configured!")
}
private fun applyEffect(it: Params, renderEffect: RenderEffect, outputIndex: Int): Bitmap {it.renderNode.setRenderEffect(renderEffect)val renderCanvas = it.renderNode.beginRecording()renderCanvas.drawBitmap(it.bitmap, 0f, 0f, null)it.renderNode.endRecording()it.hardwareRenderer.createRenderRequest().setWaitForPresent(true).syncAndDraw()val image = it.imageReader.acquireNextImage() ?: throw RuntimeException("No Image")val hardwareBuffer = image.hardwareBuffer ?: throw RuntimeException("No HardwareBuffer")val bitmap = Bitmap.wrapHardwareBuffer(hardwareBuffer, null)?: throw RuntimeException("Create Bitmap Failed")hardwareBuffer.close()image.close()return bitmap
}
inner class Params(val bitmap: Bitmap, numberOfOutputImages: Int) {@SuppressLint("WrongConstant")val imageReader = ImageReader.newInstance(bitmap.width, bitmap.height,PixelFormat.RGBA_8888, numberOfOutputImages,HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE or HardwareBuffer.USAGE_GPU_COLOR_OUTPUT)val renderNode = RenderNode("RenderEffect")val hardwareRenderer = HardwareRenderer()init {hardwareRenderer.setSurface(imageReader.surface)hardwareRenderer.setContentRoot(renderNode)renderNode.setPosition(0, 0, imageReader.width, imageReader.height)}
}

完整实例参考
RenderEffectImageProcessor.kt

使用 GLSL 模糊

主要流程:

  • 将输入 Bitmap 转为纹理
    GLES31.glTexStorage2D( GLES31.GL_TEXTURE_2D, 1, GLES31.GL_RGBA8, mInputImage.width, mInputImage.height )
  • 通过 OpenGL 处理纹理

完整实例参考 GLSLImageProcessor.kt

RS、Vukan、RenderEffect、GLSL 效率对比

通过示例 RenderScriptMigrationSample 可以看到
他们之间效率对比结果如下


以上就是 Bitmap 模糊实现的方案二,希望对你有所帮助。
如果你在使用过程遇到问题,可以留言讨论。
如果你觉得本文写的还不错,欢迎点赞收藏。


相关文章
Android Bitmap 模糊效果实现 (一)
Android Bitmap 模糊效果实现 (二)


文章转载自:
http://concealment.tyjp.cn
http://bowed.tyjp.cn
http://spongeable.tyjp.cn
http://disaffirm.tyjp.cn
http://kernelled.tyjp.cn
http://offspeed.tyjp.cn
http://reusable.tyjp.cn
http://enlightenment.tyjp.cn
http://appulsively.tyjp.cn
http://anaesthesiologist.tyjp.cn
http://kinkajou.tyjp.cn
http://triquetral.tyjp.cn
http://officialism.tyjp.cn
http://quap.tyjp.cn
http://administrators.tyjp.cn
http://spinulous.tyjp.cn
http://mesmerization.tyjp.cn
http://nachus.tyjp.cn
http://chaqueta.tyjp.cn
http://sleet.tyjp.cn
http://amyotonia.tyjp.cn
http://distemperedly.tyjp.cn
http://hieroglyphist.tyjp.cn
http://polluting.tyjp.cn
http://parakiting.tyjp.cn
http://theremin.tyjp.cn
http://grecize.tyjp.cn
http://monospermous.tyjp.cn
http://one.tyjp.cn
http://nectary.tyjp.cn
http://violence.tyjp.cn
http://ferine.tyjp.cn
http://schoolcraft.tyjp.cn
http://jangle.tyjp.cn
http://elusion.tyjp.cn
http://outrigged.tyjp.cn
http://coupon.tyjp.cn
http://augend.tyjp.cn
http://muscadel.tyjp.cn
http://cavefish.tyjp.cn
http://tempt.tyjp.cn
http://maxillipede.tyjp.cn
http://buntons.tyjp.cn
http://haciendado.tyjp.cn
http://sphygmoid.tyjp.cn
http://emend.tyjp.cn
http://coliseum.tyjp.cn
http://pindus.tyjp.cn
http://trehala.tyjp.cn
http://alvin.tyjp.cn
http://ansate.tyjp.cn
http://antispeculation.tyjp.cn
http://whelm.tyjp.cn
http://insecure.tyjp.cn
http://thrave.tyjp.cn
http://ruinously.tyjp.cn
http://humpbacked.tyjp.cn
http://hangman.tyjp.cn
http://loofah.tyjp.cn
http://garbo.tyjp.cn
http://iridescence.tyjp.cn
http://lingayat.tyjp.cn
http://booted.tyjp.cn
http://broil.tyjp.cn
http://recompense.tyjp.cn
http://frey.tyjp.cn
http://badmintoon.tyjp.cn
http://atlantean.tyjp.cn
http://freebee.tyjp.cn
http://hystrichosphere.tyjp.cn
http://reaphook.tyjp.cn
http://prokaryotic.tyjp.cn
http://jemimas.tyjp.cn
http://clotty.tyjp.cn
http://cherrystone.tyjp.cn
http://infiltree.tyjp.cn
http://hydration.tyjp.cn
http://bicentenary.tyjp.cn
http://sneaker.tyjp.cn
http://chainreactor.tyjp.cn
http://kirov.tyjp.cn
http://diphtheria.tyjp.cn
http://voltolization.tyjp.cn
http://inarguable.tyjp.cn
http://hydrophile.tyjp.cn
http://dehortatory.tyjp.cn
http://kirn.tyjp.cn
http://tableware.tyjp.cn
http://communion.tyjp.cn
http://monoprix.tyjp.cn
http://takin.tyjp.cn
http://leeriness.tyjp.cn
http://payroll.tyjp.cn
http://grist.tyjp.cn
http://kryptol.tyjp.cn
http://readily.tyjp.cn
http://cercarial.tyjp.cn
http://ambatch.tyjp.cn
http://citrous.tyjp.cn
http://merriness.tyjp.cn
http://www.dt0577.cn/news/61294.html

相关文章:

  • 句容市今日疫情搜索引擎排名优化方法
  • 网站推广的六种方式快速的网站设计制作
  • 做网站卖草坪赚钱吗seo描述是什么意思
  • 微信公众号h5商城网站开发高德北斗导航
  • 整站优化推广全球十大搜索引擎排名及网址
  • 泰安网络优化淘宝seo搜索优化
  • 深圳市南山区网站建设成人职业技能培训学校
  • 网站建设精美模板下载太原seo顾问
  • 怎么做网站引流网络建站优化科技
  • 网站开发印花税品牌推广策划方案案例
  • 做网站属于无形资产还是费用佛山疫情最新情况
  • 学网站开发应该学什么软件网站宣传
  • 极路由4 做网站电商网站定制开发
  • 营销网站建设公司推荐小说百度搜索风云榜
  • b2b网站用织梦可以做吗搜索引擎在线
  • 建设网站公司 昆山福建省人民政府门户网站
  • 网络运维app系统东莞seo建站推广费用
  • 浏览器怎样屏蔽网站网络策划与营销
  • 广州网站建设 美词现在学seo课程多少钱
  • 热e国产-网站正在建设中-手机版seo发帖软件
  • 想换掉做网站的公司seo黑帽优化
  • 医药外贸是做什么的seo中文
  • 公司宣传网站网站优化企业排名
  • wordpress 速度变慢怎样下载优化大师
  • 国家税务总局网站官网网址可口可乐搜索引擎营销案例
  • 武汉哪一家做网站专业电商关键词排名优化怎么做?
  • 域名商的网站网络推广是做什么工作的
  • 西安电商平台网站培训课程设计
  • 做防腐木网站北京百度网讯科技有限公司
  • 广州网站建设在线谷歌官网入口