Compare commits

..
468 Commits
Author SHA1 Message Date
seven332 0631c2925a 调整阅读界面滑调消失显示动画 2014-11-12 23:55:11 +08:00
seven332 fbd9e93560 在阅读界面初次启动对话框关闭后再次全屏显示 2014-11-12 19:32:51 +08:00
seven332 8b49cfe89c changelog 2014-11-12 19:01:48 +08:00
seven332 8e91fdaffe 调整全屏方式,可能避免部分机型部分系统由于 fitSystemWindows 效果而产生的显示问题 2014-11-12 18:54:46 +08:00
seven332 ea3e246f5b 修正 proguard 导致的错误 2014-11-11 23:53:57 +08:00
seven332 51f79d71ad 修正首次启动识别 2014-11-11 23:05:52 +08:00
seven332 d430a6ddec 更新 string.xml 2014-11-11 22:59:31 +08:00
seven332 feb8788065 changelog 2014-11-11 22:46:01 +08:00
seven332 35095326cd 调整 GalleryActivity 全屏 2014-11-11 22:38:57 +08:00
seven332 c88d7a526e SlidingDrawerLayout 添加 LockMode 2014-11-11 17:42:30 +08:00
seven332 f6b64bc01c 修正 SlidingDrawerLayout 开启状态错误 2014-11-11 15:31:43 +08:00
seven332 2bac87cc9f SlidingDrawerLayout 及时取消打开任务 2014-11-11 08:57:21 +08:00
seven332 d34056eefb SlidingDrawerLayout 使用 ZInterpolator 2014-11-10 22:08:20 +08:00
seven332 72e0b2e9e9 调整 SlidingDrawerLayout 2014-11-10 21:59:18 +08:00
seven332 6d7e638613 update 2014-11-10 19:35:55 +08:00
seven332 cec2b5c490 删除不必要的内容 2014-11-10 19:35:22 +08:00
seven332 4eaea80281 添加 SlidingDrawerLayout 2014-11-10 19:26:53 +08:00
seven332 41a5a423b4 删除多余函数 2014-11-10 14:17:58 +08:00
seven332 a721b3d6a8 调整 actionbar icon 2014-11-09 01:15:10 +08:00
seven332 dccdd2b095 使用 material-menu 2014-11-08 00:31:22 +08:00
seven332 cd393530cb 完善 setting 界面 2014-11-07 22:21:18 +08:00
seven332 7684dbeee7 Merge branch 'dev' of github.com:seven332/EhViewer into dev 2014-11-07 16:36:05 +08:00
seven332 e20100ff74 使用 DrawerLayout 2014-11-07 16:28:42 +08:00
seven332 935ec55745 调整界面 2014-11-06 23:32:30 +08:00
seven332 c88848d829 添加当前状态至快速搜索 2014-11-06 12:09:42 +08:00
seven332 8df82dc573 调整界面 2014-11-04 22:56:14 +08:00
seven332 688e1f0ed2 使用 proguard 以减小 apk 体积 2014-11-04 14:31:11 +08:00
seven332 3a7bc14c01 创建 Hisroty 表 2014-11-04 12:42:03 +08:00
seven332 d23623ac16 update 2014-11-03 20:52:25 +08:00
seven332 432ab6b045 update 2014-11-03 17:04:37 +08:00
seven332 c578cefeea update 2014-11-03 15:17:39 +08:00
seven332 ffdd42851c update 2014-11-03 12:21:41 +08:00
seven332 5c66172bb9 update .gitignore 2014-11-03 11:20:25 +08:00
seven332 415a973a97 调整下载界面 2014-11-03 11:19:38 +08:00
seven332 8149257c27 renameTo 后要等一会儿? 2014-11-02 23:47:16 +08:00
seven332 3bd56377c9 添加单张图像重新下载功能 2014-11-02 23:24:22 +08:00
seven332 9d070fbdf9 更换 clear 图标 2014-11-02 20:14:21 +08:00
seven332 52b62cefee 添加历史过滤 2014-11-02 19:47:18 +08:00
seven332 61992ed2a2 调整侧边栏禁用效果 2014-11-01 21:38:41 +08:00
seven332 71f1077241 添加历史记录显示 2014-11-01 21:32:26 +08:00
seven332 ffe4eb0fa1 调整标题韩文识别 2014-10-31 13:44:53 +08:00
seven332 018b176541 EditTextPreference 添加数值边界判断 2014-10-30 18:36:04 +08:00
seven332 c406f71578 添加历史记录 2014-10-30 16:34:26 +08:00
seven332 133a6dc400 添加gif播放指定index 2014-10-28 20:18:44 +08:00
seven332 0d7e39168e 添加设置屏幕常亮 2014-10-26 21:18:08 +08:00
seven332 f82cfb0540 修正可能的 NullPointerException 2014-10-26 20:40:15 +08:00
seven332 4b4aaa982f Merge branch 'dev' of github.com:seven332/EhViewer into dev 2014-10-25 13:17:17 +08:00
seven332 ba21d1dc7c 调整标题中文识别 2014-10-25 12:29:43 +08:00
seven332 b405c92a6f 添加修改过标题的资源的路径的识别 2014-10-23 15:02:04 +08:00
seven332 1760d16c43 添加 Google Analytics 内容 2014-10-23 12:35:43 +08:00
seven332 329246e155 添加 MaterialProgressDialog 2014-10-22 23:23:28 +08:00
seven332 d54ffee6d2 移除不必要的文件 2014-10-21 22:02:38 +08:00
seven332 4ca72e498b 修正版本号 2014-10-21 16:58:33 +08:00
seven332 0564b5c657 对话框信息居中 2014-10-21 16:36:19 +08:00
seven332 b33817bcc9 完善对话框风格 2014-10-21 16:26:56 +08:00
seven332 4998dd2e86 调整阅读界面控制面板显示隐藏方式 2014-10-20 12:13:16 +08:00
seven332 2f30c23e30 调整阅读效果 2014-10-19 19:28:05 +08:00
seven332 42ae15e3f7 update for 64 2014-10-18 20:35:17 +08:00
seven332 aa04c8cfe7 target=android-21 2014-10-18 14:20:18 +08:00
seven332 16c847b669 滑动时暂停 gif 播放 2014-10-16 18:08:39 +08:00
seven332 a75bb29315 移除不必要的文件 2014-10-15 16:49:13 +08:00
seven332 788631b6ee 避免安装低版本后重新升级导致的下载记录错误 2014-10-14 23:18:27 +08:00
seven332 09229546c6 log 2014-10-14 21:52:47 +08:00
seven332 03582eb9da 自动调整 gallery list item 高度 2014-10-14 21:49:00 +08:00
seven332 e2e794b85c 计算 gallery list item 高度 2014-10-14 17:14:01 +08:00
seven332 ab949d5567 卧槽 2014-10-14 14:29:06 +08:00
seven332 f340279e57 update 2014-10-14 07:43:22 +08:00
seven332 ddb1edb7d1 log 2014-10-13 22:34:52 +08:00
seven332 a7f29a3cd5 更新 string.xml 2014-10-13 22:25:36 +08:00
seven332 d09e4a9215 更新 string.xml 2014-10-13 21:58:17 +08:00
seven332 07335ba49c 自动修正下载文件夹名 2014-10-12 23:54:56 +08:00
seven332 b55d5a1538 添加 twitter 入口 2014-10-12 23:43:05 +08:00
seven332 97fc40a69c 避免大量的 Notification 2014-10-12 23:26:02 +08:00
seven332 cc73666475 update 2014-10-12 22:44:24 +08:00
seven332 0ed34f2eca 添加修改下载文件夹为 gid-title 入口 2014-10-12 22:43:53 +08:00
seven332 a7a3d56c91 添加边界提示控制 2014-10-08 23:22:38 +08:00
seven332 748c5cb812 update 2014-10-07 13:32:30 +08:00
seven332 f5318cf6d3 update 2014-10-07 02:35:17 +08:00
seven332 082dc2e3f5 修正 file select 对话框 2014-10-07 01:54:28 +08:00
seven332 c4ed7a034a 默认为继续阅读 2014-10-07 01:30:04 +08:00
seven332 28f548e565 调整主题 2014-10-07 01:13:06 +08:00
seven332 20927eea63 由服务器获取代理地址 2014-10-07 00:52:06 +08:00
seven332 1a302e5157 修改 checkbox button 2014-10-06 00:07:06 +08:00
seven332 92417cb7b4 避免线程冲突 2014-10-05 21:29:46 +08:00
seven332 1dab2722dd 修正 MaterialAlertDialog 列表显示错误 2014-10-05 19:23:34 +08:00
seven332 3a59e3eaae 修正继续阅读时图片未加载问题 2014-10-05 03:31:01 +08:00
seven332 d56c4e5386 调整下载信息存储,记录阅读位置 2014-10-05 02:37:51 +08:00
seven332 0c3a7301cc 修正当前页面索引错误 2014-10-04 23:35:36 +08:00
seven332 6878de9175 保持下载列表顺序 2014-10-04 22:17:27 +08:00
seven332 97956b98df 调整滑动效果 2014-10-04 01:37:56 +08:00
seven332 52bf4ac74d 使用 L 风格 Dialog 2014-10-04 01:17:21 +08:00
seven332 b53e8b49e0 替换 Notification 图标 2014-09-29 22:42:10 +08:00
seven332 51d648ac6b 添加 Notification 图标 2014-09-29 22:37:37 +08:00
seven332 03a5b75648 使用 L 风格 Dialog 2014-09-29 22:32:27 +08:00
seven332 bea31278a7 重命名下载中间文件 2014-09-24 16:05:14 +08:00
seven332 3bec2e47e3 获取更多错误 2014-09-23 23:53:22 +08:00
seven332 13eb3d291d 在清理冗余时删除 gid 文件 2014-09-23 14:19:44 +08:00
seven332 23225bdb56 搜索显示 suggestion 2014-09-23 14:03:39 +08:00
seven332 8ba3d11c11 添加解码格式选择 2014-09-19 10:35:09 +08:00
seven332 d519179ae2 添加清理阅读冗余 2014-09-19 00:55:51 +08:00
seven332 e8aa39d66d 修正 cmyk_gray_convert 2014-09-18 01:38:13 +08:00
seven332 ee231382f5 修正 cmyk_gray_convert 2014-09-18 01:32:58 +08:00
seven332 0324b87ad6 对 jpeg 解码添加 cmyk->gray 与 cmyk->rgb 2014-09-18 01:24:06 +08:00
seven332 855e4cc61c 修正 armv7 而无 neon 而导致的解码错误 2014-09-17 14:51:24 +08:00
seven332 b759ee0997 update 2014-09-17 11:58:41 +08:00
seven332 f2a1ad7df4 修正 ExpandingListView 计算错误 2014-09-15 16:10:35 +08:00
seven332 33999a317e 修正 ExpandingListView collapse 时的错误 2014-09-15 15:23:48 +08:00
seven332 2d9a54bc0e 修正 onStartCommand 可能的 NullPointerException 2014-09-15 15:09:43 +08:00
seven332 8d1ad9697b ListView 添加 expand 动画效果 2014-09-15 15:01:22 +08:00
seven332 39d9701c75 更新 string.xml 2014-09-14 03:19:36 +08:00
seven332 d886cbe391 update 2014-09-14 03:05:07 +08:00
seven332 5afb351fcc Update 2014-09-14 02:52:02 +08:00
seven332 7f5569a8d9 修正磁吸充电时重新载入问题 2014-09-10 20:57:51 +08:00
seven332 9df26b94c7 通知添加全部停止 2014-09-10 13:16:30 +08:00
seven332 103cfe1749 当搜索栏失去焦点时隐藏 2014-09-10 00:29:07 +08:00
seven332 006a8684ff 下载通知添加停止按钮 2014-09-10 00:12:42 +08:00
seven332 645f0df208 添加清除搜索记录 2014-09-08 23:50:23 +08:00
seven332 60dc0a7f72 添加最近搜索建议 2014-09-08 23:29:36 +08:00
seven332 4c7c06e8dc 修正 ripple 中心不居中 2014-09-07 11:32:42 +08:00
seven332 d361eaf63d 修正自定义解码默认值显示错误 2014-09-07 10:32:44 +08:00
seven332 b44fdcfeec 添加下载链接 2014-09-06 21:26:22 +08:00
seven332 51f050ae7e Release 时 LOG 不显示 2014-09-06 20:53:17 +08:00
seven332 d59685588b 更新 string.xml 2014-09-06 20:15:00 +08:00
seven332 2e188a2cc3 添加解码选择 2014-09-06 19:40:18 +08:00
seven332 b562ec2b50 调整图标 2014-09-06 18:53:53 +08:00
seven332 dab0b0cbfb 添加下载项全部开始下载或停止 2014-09-06 16:17:52 +08:00
seven332 68aea866e1 将部分字符串移动至 string.xml 2014-09-06 14:22:15 +08:00
seven332 82c0208ac8 添加 EH 站点连接最小间隔设置 2014-09-06 03:37:42 +08:00
seven332 0285f82f52 添加 Http 设置 2014-09-06 03:01:14 +08:00
seven332 3d88928ed3 添加下载线程数设置 2014-09-06 02:20:08 +08:00
seven332 f05d123da7 添加 UrlBuilder,release 时不显示 Log 2014-09-03 20:23:58 +08:00
seven332 dcc45c5d81 修正可能出现的除数为零 2014-09-02 01:22:49 +08:00
seven332 d25caafc8b 修正 g 的解析错误 2014-08-30 00:12:59 +08:00
seven332 290c60adab 添加日志文件输出 2014-08-29 21:50:52 +08:00
seven332 3c7a61a863 添加 mips 支持,修正解析判断错误 2014-08-29 11:24:58 +08:00
seven332 5a3b152110 添加 libjpeg-turbo 解码 2014-08-29 00:03:27 +08:00
seven332 446e0aadd1 添加 libpng 解码 2014-08-28 10:40:50 +08:00
seven332 62675a3dd2 gif 解码添加文件路径入口 2014-08-27 15:39:40 +08:00
seven332 6e97c23dda 阅读界面添加电量显示 2014-08-26 16:09:16 +08:00
seven332 d08598ab71 修正由于图片宽度而导致的错位 2014-08-26 09:59:54 +08:00
seven332 007330112e 添加 GL_RGBA GL_LUMINANCE_ALPHA 2014-08-26 00:00:07 +08:00
seven332 eb33529980 update 2014-08-25 22:27:42 +08:00
seven332 22ff864844 update 2014-08-25 16:19:58 +08:00
seven332 51f2ea5bf8 使用 giflib 对 gif 解码 2014-08-25 16:09:39 +08:00
seven332 8f611c5a27 update 2014-08-24 21:06:46 +08:00
seven332 5413b8e40e update 2014-08-24 21:04:23 +08:00
seven332 b1cf11e2bc 修正一些错误 2014-08-24 12:05:44 +08:00
seven332 fb8bc2c364 更新 Gallery2 部分 2014-08-23 13:39:48 +08:00
seven332 570796a610 fix date 2014-08-23 12:00:16 +08:00
seven332 3a1fe8da1d 修正可能的布局错误 2014-08-23 11:32:15 +08:00
seven332 5259f2173d 重用 Notification.Builder 避免可能的闪烁 2014-08-22 23:26:40 +08:00
seven332 5b6f458c60 update 2014-08-22 19:55:43 +08:00
seven332 1998af3d0b update 2014-08-22 19:54:47 +08:00
seven332 e3b5ed840e 详情界面的 Activity 跳转不关闭自身 2014-08-22 16:53:47 +08:00
seven332 e96d91184f string.xml 2014-08-22 16:03:00 +08:00
seven332 5822e58984 完善下载界面 2014-08-22 13:52:08 +08:00
seven332 da90150233 够快关闭免费外链了... 2014-08-20 23:44:54 +08:00
seven332 62d6609b15 添加双击缩放 2014-08-20 22:24:54 +08:00
seven332 e451db6032 完善阅读界面 2014-08-20 17:16:43 +08:00
seven332 a2bbe855e8 完善阅读下载策略 2014-08-19 16:24:36 +08:00
seven332 374ed3a515 新的阅读下载策略 2014-08-17 22:20:43 +08:00
seven332 6f0af8b6ec 允许 Http 请求重试 2014-08-14 15:19:38 +08:00
seven332 a98cd0bc79 使用原生 Toast 样式 2014-08-13 23:06:20 +08:00
seven332 0e125738e2 优化列表 2014-08-12 21:28:05 +08:00
seven332 055fd5e8ae 调整网页分析 2014-08-11 12:14:06 +08:00
seven332 10ba81f5cc 完善详情界面 2014-08-10 22:00:01 +08:00
seven332 08d79aa204 根据网页调整分析方法 2014-08-09 23:05:04 +08:00
seven332 d0e1b4cfee 添加 ResponedScrollView 2014-08-09 00:00:08 +08:00
seven332 90d95c6552 完善详情界面 2014-08-08 16:10:21 +08:00
seven332 53a7cc84a2 完善详情界面 2014-08-08 00:15:13 +08:00
seven332 129b70e15c 修正屏幕转动后 padding 错误 2014-08-07 16:12:58 +08:00
seven332 80282ffd04 完善详情界面 2014-08-06 22:56:46 +08:00
seven332 e3209cd2c0 为 WindowsAnimate 添加 Sprite 2014-08-06 14:39:31 +08:00
seven332 3681bd1dd4 利用 Bitmap 显示过渡动画 2014-08-06 00:35:10 +08:00
seven332 a6fea77b15 完善详情界面与 Ripple 效果 2014-08-05 23:18:21 +08:00
seven332 e08a9bfdfa 部分改善详情界面,添加 Ripple 效果 2014-08-04 22:38:31 +08:00
seven332 ee229b11da 更新 CardView 2014-08-02 11:49:43 +08:00
seven332 dfa5998483 修正 AutoWrapLayout 不完全显示问题 2014-08-01 10:11:41 +08:00
seven332 b743bdb581 添加 SuperButton 2014-07-31 21:28:48 +08:00
seven332 fa5d8380c9 添加图片搜索入口 2014-07-30 14:55:56 +08:00
seven332 79ffce2f3e 添加文件搜索 2014-07-29 23:21:06 +08:00
seven332 d89db7754f 尝试在列表缩略图上显示语言 2014-07-29 11:28:18 +08:00
seven332 ef154867a6 添加快速搜索提示 2014-07-29 09:24:01 +08:00
seven332 8abe21c536 NumberOfColumnsPreference 添加 summary 2014-07-28 23:43:37 +08:00
seven332 333c783a0d 添加列表缩略图与预览图列数设置 2014-07-28 20:24:10 +08:00
seven332 eae2375560 更新感谢 2014-07-28 10:34:06 +08:00
seven332 0a3adfb06b 添加 FixedAspectImageView 与 SimpleGridLayout 2014-07-28 10:28:43 +08:00
seven332 5fda8b792c 添加列表缩略图模式 2014-07-27 13:17:46 +08:00
seven332 0ea49f593b 横屏时移除 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION 2014-07-26 13:11:10 +08:00
seven332 6331c3c86d 修正拼写错误 2014-07-26 11:34:54 +08:00
seven332 99df5be760 修正 FilterDialog 未关闭问题 2014-07-26 10:25:54 +08:00
seven332 53f8f6defc 移除 CardViewDelegate 2014-07-26 10:08:03 +08:00
seven332 c1d39de57c 更愉快的 CardView 2014-07-26 10:02:48 +08:00
seven332 f0c8c14918 调整 CardView 2014-07-25 23:33:06 +08:00
seven332 5b0b1b1614 使用 CardView 2014-07-25 16:29:59 +08:00
seven332 8ffa54dc25 调整代码 2014-07-25 15:54:01 +08:00
seven332 ae4714aa48 不显示 count 2014-07-25 14:30:43 +08:00
seven332 802c11bed1 重命名 2014-07-25 14:26:34 +08:00
seven332 ff2ed3205d 使用预设颜色,避免随机生成的奇怪颜色 2014-07-24 23:06:11 +08:00
seven332 ba7f1a5aed 添加 API 源选择 2014-07-24 17:13:18 +08:00
seven332 43903adcc4 修正 lofi 时收藏夹解析错误 2014-07-24 15:43:13 +08:00
seven332 703fc5f44d 更新翻译 2014-07-24 13:14:31 +08:00
seven332 485f4ba9f2 添加 exclude language 2014-07-24 13:11:25 +08:00
seven332 1d6e6277d8 添加 Exculde Tag Group 2014-07-24 10:19:54 +08:00
seven332 2ed2c08183 添加列表默认分类显示 2014-07-23 17:26:24 +08:00
seven332 eaae310f05 添加 CategoryTable 2014-07-23 16:06:09 +08:00
seven332 ab9b7e59d9 添加 lofi 列表分析 2014-07-23 11:15:22 +08:00
seven332 07614fecef AppHandler 2014-07-20 23:12:09 +08:00
seven332 fae86c1782 显示纯文本错误提示 2014-07-20 23:04:43 +08:00
seven332 b0fc8f4c58 添加 RefreshTextView 2014-07-20 16:58:47 +08:00
seven332 5cdc004829 不显示 tag value 2014-07-13 18:09:25 +08:00
seven332 7efed23ddf 修正横屏下新建 Activity 出现卡顿的问题 2014-07-13 18:04:53 +08:00
seven332 251ed9b687 调整布局 2014-07-13 17:42:19 +08:00
seven332 1b017250a5 使用 AppHandler 2014-07-13 17:25:37 +08:00
seven332 5e9097b1bf 添加 zh-rHK zh-rTW 翻译 2014-07-13 11:47:06 +08:00
seven332 62858aa5d2 添加圆角矩形背景 2014-07-13 11:15:30 +08:00
seven332 8ceb7ca912 允许查看 gallery 上传者的其他上传 2014-07-12 11:06:44 +08:00
seven332 4ce0a60397 由 url 进入详情页,初始仅显示加载等待控件 2014-07-12 00:27:03 +08:00
seven332 75731d5600 修正详情页面切换 gallery 时 title 无变化的问题 2014-07-11 23:48:07 +08:00
seven332 7ddeef682a 调整 user panel 2014-07-11 23:07:34 +08:00
seven332 da076be7fb 第一次启动显示左侧栏 2014-07-11 22:34:06 +08:00
seven332 7235e3abd5 完善下载功能 2014-07-11 21:41:36 +08:00
seven332 05cfabae10 添加 gid token 错误识别 2014-06-29 02:37:26 +08:00
seven332 32e345f9f0 修正 ListActivity 未启动时由 DetailActivity 跳至其会出现的错误 2014-06-28 21:44:33 +08:00
seven332 6b7f314e9f 完善 Activity 跳转 2014-06-28 20:24:18 +08:00
seven332 db3fe7e446 完善 HttpHelper 2014-06-28 02:36:15 +08:00
seven332 d7e42a760c 添加注释,修改函数名 2014-06-26 13:59:15 +08:00
seven332 f90588e79e SetMinimumWidth for modeSpinner 2014-06-26 13:51:20 +08:00
seven332 deefd9b9e3 移除错误的提示 2014-06-26 02:45:46 +08:00
seven332 e01ef1abff 添加默认 cookie,默认模式改为EX 2014-06-26 01:48:51 +08:00
seven332 facb17eac2 修正由于没有显式 host 而导致的头像获取错误 2014-06-25 23:04:38 +08:00
seven332 151c16ad83 修正带有链接的评论无选中反应,长按仍会打开链接的问题 2014-06-25 21:12:13 +08:00
seven332 07d1cc6bf6 Dialog 添加 setMessageAutoLink 2014-06-25 19:16:32 +08:00
seven332 e9bb78ebfc preview num per row 可以被禁用,限制文件名长度 2014-06-25 16:19:45 +08:00
seven332 c154f9b73a 添加 ' 至 ‘ 的转换 2014-06-23 23:12:22 +08:00
seven332 51266d4c3b 移除 OlScollView, OnLayoutListener, 使用 addOnLayoutChangeListener 2014-06-23 23:06:15 +08:00
seven332 f02998b917 添加 StableBitmapDrawable 避免预览图加载后位置大幅变化 2014-06-23 22:49:36 +08:00
seven332 b6f89741ee 添加大预览图模式 2014-06-23 22:13:28 +08:00
seven332 2498be6850 gallery list 使用简易 RatingView 以便更快加载 2014-06-23 02:02:19 +08:00
seven332 ce2907610a 更换 cache,更换图片获取方式,建立 previewlist 类,移除不需要的类 2014-06-23 00:44:20 +08:00
seven332 4e266c160c 获取并显示登陆时的错误 2014-06-22 01:45:53 +08:00
seven332 3e76680aeb 调整 Gallery Detail 获取 2014-06-22 01:28:03 +08:00
seven332 8ad331af60 移除 commons-lang 包 2014-06-22 00:55:30 +08:00
seven332 90a41a1d6b 更改登陆登出方式,可以显示头像 2014-06-22 00:21:46 +08:00
seven332 ce786f4e41 重新 HttpHelper 2014-06-21 18:20:43 +08:00
seven332 3f099969d1 调整 popular 获取与显示 2014-06-19 01:58:01 +08:00
seven332 e0acfa55eb 调整 Analytics 2014-06-18 15:06:49 +08:00
seven332 f4472005b5 修正点击次数显示错误 2014-06-17 18:42:56 +08:00
seven332 1c2263c001 添加列表模式选择 2014-06-16 21:19:41 +08:00
seven332 6f93bb5b88 添加热门点击数显示 2014-06-15 22:42:56 +08:00
seven332 1d2978952b 添加更新时间显示 2014-06-15 21:15:24 +08:00
seven332 937fc619dd 移除不必要的资源 2014-06-15 03:51:17 +08:00
seven332 30c46bd0a2 调整类别识别 2014-06-15 02:46:08 +08:00
seven332 ae90c1b2b1 changlog 2014-06-15 02:28:18 +08:00
seven332 e6e85dc8d4 添加收藏统计 2014-06-15 02:24:43 +08:00
seven332 1a1242cc47 修正翻译 2014-06-15 02:03:34 +08:00
seven332 9b34b561d8 修正时间显示 2014-06-15 02:01:20 +08:00
seven332 ee5cc24a4d 添加 popular 提示 2014-06-15 01:59:04 +08:00
seven332 6ebc172783 Add popular 2014-06-14 23:43:16 +08:00
seven332 a6237f0dc5 规范统计 2014-06-14 20:20:10 +08:00
seven332 66e2727acb 添加阅读信息获取 2014-06-14 02:14:27 +08:00
seven332 78bcb037ac 添加 Google Analytics 2014-06-14 01:49:40 +08:00
seven332 9aecbf9e66 添加默认收藏设置 2014-06-14 00:29:31 +08:00
seven332 bcba2f556b 字符串移至 string.xml 2014-06-13 22:47:24 +08:00
seven332 148f03a175 添加主题颜色设定 2014-06-13 22:01:37 +08:00
seven332 f39cfc7875 随机主题配色 2014-06-13 18:14:41 +08:00
seven332 5bc166d3da Translucent 移至 themes.xml 2014-06-13 00:15:25 +08:00
seven332 7e5a844246 修正收藏切换显示问题 2014-06-12 23:17:53 +08:00
seven332 8cecf200eb 完成账户收藏管理 2014-06-12 23:12:32 +08:00
seven332 535a6297af 注释掉关闭应用时删除文件 2014-06-11 20:19:17 +08:00
seven332 5ea2fdb651 抽象 AbstractGalleryActivity 2014-06-11 20:12:32 +08:00
seven332 bfe9044fda 更名 2014-06-10 23:41:39 +08:00
seven332 d277066d34 更改 Toast 颜色 2014-06-10 23:39:45 +08:00
seven332 cbbe1478ae 收藏界面添加返回键隐藏 ActionableToastBar 2014-06-10 22:52:22 +08:00
seven332 8848e712cc 调整 SuperToast 布局,使其不会横向占满屏幕 2014-06-10 12:50:15 +08:00
seven332 ed693d1742 更新 SuperSwipeRefreshLayout 对 paddingTop 判断方式,并修正其对滑动判断错误 2014-06-10 11:18:04 +08:00
seven332 626def198c 修正以匹配服务器的 json 格式 2014-06-10 08:31:43 +08:00
seven332 b9fc9b054b 更新检查地址改为 http://www.ehviewer.com/API 2014-06-10 08:23:59 +08:00
seven332 602f68e88b dialog 中 message 居中 2014-06-10 00:45:04 +08:00
seven332 dfa00b7605 将 Toast 换为 SuperToast 2014-06-10 00:34:58 +08:00
seven332 27cb0aa260 添加 SuperToast 2014-06-07 02:57:09 +08:00
seven332 416d080eb4 添加 ActionableToastBar 2014-06-07 02:03:26 +08:00
seven332 386c98575d 允许 HfListView 启用或禁用 Header 或 Footer 2014-06-05 23:06:09 +08:00
seven332 84f9aef856 使 SwipeProgressBar 在 paddingTop 不为 0 时正确显示 2014-06-05 20:17:25 +08:00
seven332 13cbb7507e 初步完成收藏 2014-06-05 19:18:59 +08:00
seven332 4a1594f982 调整 list 获取 2014-05-30 20:10:05 +08:00
seven332 761ce507f1 简化字符串 2014-05-30 15:27:01 +08:00
seven332 67884ed9d3 修正媒体扫描错误 2014-05-30 14:40:16 +08:00
seven332 12412d67fb 添加新的缓存管理 2014-05-30 12:29:25 +08:00
seven332 2c58f6c9ae 添加收藏夹批处理 2014-05-30 00:22:57 +08:00
seven332 65e908546b 修正 sad panda 识别 2014-05-29 22:01:40 +08:00
seven332 ea18b8c090 调整 List 获取 2014-05-29 20:39:03 +08:00
seven332 6c182f3bba 添加 ex test 2014-05-28 23:28:52 +08:00
seven332 807c49eea1 Detail Activity ActionBar Translucent 2014-05-28 22:33:38 +08:00
seven332 50dd19222e 添加 Detail Info 显示 2014-05-28 21:33:32 +08:00
seven332 b5bbf19a65 扩充 DetailParser 2014-05-28 20:43:46 +08:00
seven332 9ed06be68b 预先获取 density 2014-05-28 01:19:26 +08:00
seven332 9da0c76da6 调整 preview panel button 背景 2014-05-26 18:01:58 +08:00
seven332 1b06d19059 增加添加至服务器收藏 2014-05-25 23:30:05 +08:00
seven332 e258617c23 Add idear 2014-05-25 22:29:15 +08:00
seven332 839a7227ab 移除可能产生卡顿的不必要操作 2014-05-25 20:27:39 +08:00
seven332 f49b111e15 调整 action bar tag 背景 2014-05-25 17:12:51 +08:00
seven332 d5d6b6fb4c 添加一种列表搜索方式 2014-05-25 15:03:45 +08:00
seven332 7cc794d614 修正 changelog 错误 2014-05-25 14:46:03 +08:00
seven332 f209f5f157 解决 Custom Dialog 标题过长时与 Action Drawable 的冲突 2014-05-24 22:12:54 +08:00
seven332 ca4be438c5 changelog 2014-05-24 22:06:36 +08:00
seven332 d9411b190c 修正无法取消内容警告的错误 2014-05-24 21:49:09 +08:00
seven332 ec2cb356c1 添加 AbstractActivity 2014-05-24 17:55:59 +08:00
seven332 15a2db978c 添加自动更新设置 2014-05-24 17:44:26 +08:00
seven332 a9506b1f53 修正设置中检查更新的 key 错误 2014-05-24 16:32:23 +08:00
seven332 1a8f6752c7 SettingActivity actionbar 添加返回 2014-05-24 01:50:34 +08:00
seven332 637579db5c SettingActivity 为不同 fragment 设置不同 actionbar icon 2014-05-24 00:52:45 +08:00
seven332 534c5506e6 com.hippo.ehviewer.activity 改为 com.hippo.ehviewer.ui 2014-05-23 23:44:08 +08:00
seven332 a2182e0f05 添加 AbstractActivity 2014-05-23 23:34:27 +08:00
seven332 0d0153c6e8 添加 github 入口 2014-05-23 20:17:40 +08:00
seven332 ca6281bf72 调整 SettingActivity 中 padding bottom 2014-05-23 19:06:50 +08:00
seven332 a50df7308f 添加 Copyright 2014-05-23 18:43:48 +08:00
seven332 d31a51ab9a 添加 Copyright 2014-05-23 16:38:32 +08:00
seven332 91aa31503b 删除历史代码 2014-05-23 15:28:21 +08:00
seven332 a5e07a0ebe 选择路径中允许添加路径 2014-05-23 15:02:25 +08:00
seven332 cfa51276bd 调整 FileExplorerView item 布局 2014-05-23 14:25:50 +08:00
seven332 148470e4be SettingsActivity 使用 fragment 2014-05-23 14:18:40 +08:00
seven332 fd72fbf9bd 调整搜索面板类别选择布局 2014-05-21 21:14:32 +08:00
seven332 b37087a69d FileExplorerView 排序忽略大小写 2014-05-20 12:57:56 +08:00
seven332 ec1694347a 部分完成下载路径设置 2014-05-20 12:52:23 +08:00
seven332 a89b001370 替换 settings 图标 2014-05-19 22:43:55 +08:00
seven332 867a0f4ef7 修正标签存储错误 2014-05-19 17:09:20 +08:00
seven332 fee7d87a21 添加小尺寸图标 2014-05-18 21:40:55 +08:00
seven332 ffd0ca0cec change log 2014-05-18 16:17:18 +08:00
seven332 7d819d4ac6 完善 strings.xml 2014-05-18 16:15:54 +08:00
seven332 e08ee26991 change log 2014-05-18 16:10:22 +08:00
seven332 599649200c 未完成的功能添加提示 2014-05-18 16:05:57 +08:00
seven332 4e4c670c97 完成由 comment 搜索发言用户上传 2014-05-18 16:01:48 +08:00
seven332 1def607a80 添加标签跳转搜索 2014-05-18 15:47:31 +08:00
seven332 5bee5d6663 换行符总出错 2014-05-18 15:09:55 +08:00
seven332 834b9b7a2a 修正 GalleryView 中在 onLayout 之前触摸可产生的错误 2014-05-18 14:52:12 +08:00
seven332 4e7bb7aec3 修正登陆窗口弹出 2014-05-18 14:39:41 +08:00
seven332 f4c73e3b32 完善 Detail 界面下载 2014-05-18 14:25:01 +08:00
seven332 bb6f8ded7f 完成 Data 中对 ListUrls tag 模式的支持 2014-05-18 03:27:48 +08:00
seven332 e7753fddec 修正 ModifyTag 时新加 advance 时显示错误 2014-05-18 03:04:05 +08:00
seven332 29e77faec9 DialogBuild 添加 Action,ListUrls 添加 tag 模式 2014-05-18 02:42:23 +08:00
seven332 e0cc198d96 添加更加 uploader 搜索 2014-05-17 23:53:03 +08:00
seven332 cc9d194ddd 修正预览图翻页错误 2014-05-17 21:13:37 +08:00
seven332 0735fa2425 comment 使用 Linkify 2014-05-17 16:04:38 +08:00
seven332 d8fc3f0a51 移动部分 String 至 strings.xml 2014-05-17 15:18:39 +08:00
seven332 c47f124854 完善模式选择 2014-05-17 15:06:12 +08:00
seven332 7dba58b1aa 调整列表界面菜单 2014-05-16 22:50:52 +08:00
seven332 5f34b5aeb0 完善用户面板 2014-05-16 22:27:48 +08:00
seven332 7470a25cbe CheckTextView 替换 CheckImage 2014-05-16 21:12:26 +08:00
seven332 28b31d3439 AutoWrapLayout 的 baseline 属性改名为 alignment 2014-05-16 16:55:39 +08:00
seven332 97d855b546 移除不必要的文件 2014-05-16 16:43:59 +08:00
seven332 711564a0ab 将 FswView 的 visibility 默认设为 gone 2014-05-15 22:13:56 +08:00
seven332 f20bc2c954 修改换行符为 LF 2014-05-15 20:23:11 +08:00
seven332 ed0702068c 调整 refresh color 顺序,使其更自然 2014-05-15 20:15:17 +08:00
seven332 b568082c2d 将 ActionBarPullToRefresh 替换为 SwipRefreshLayout 2014-05-15 19:59:51 +08:00
seven332 f89ae0d1b1 调整 ActionBarPull 参数,更便于操作 2014-05-15 13:49:47 +08:00
seven332 d2c4cf598a 添加 README.md 2014-05-14 21:41:45 +08:00
seven332 f9ceddfabf just fix 2014-05-14 20:18:07 +08:00
seven332 cec40a8f89 更新 changelog 2014-05-12 22:42:15 +08:00
seven332 4a4ec2312a 部分完善用户面板 2014-05-12 20:38:39 +08:00
seven332 5417918382 使用 TextSwitcher 替代 ProgressiveTextView 2014-05-12 02:17:19 +08:00
seven332 f8b2b46172 删除不必要的文件 2014-05-12 01:02:49 +08:00
seven332 d0f07ae62b 修正 preview 自动 2014-05-11 23:24:39 +08:00
seven332 5d7b99e328 修正返回图标 2014-05-11 16:56:13 +08:00
seven332 ae563a7950 comment dialog 中使用更好的 layout 2014-05-11 02:15:49 +08:00
seven332 1f6668cd8c 当 preview 信息已有时也跳至 preview 顶部 2014-05-11 01:08:04 +08:00
seven332 24a384eed7 当获取新 preview 大小时,自动使其最大显示 2014-05-11 00:17:57 +08:00
seven332 b5eeee9b73 完善 ActionBarTab style 2014-05-10 23:27:14 +08:00
seven332 1bd32d97de 初步完成 detail url 接管 2014-05-10 14:52:44 +08:00
seven332 5e6d771dad 调整菜单 2014-05-10 02:58:04 +08:00
seven332 9b80be453c 添加评论查看与发送功能,评论按发布时间排序 2014-05-10 00:08:34 +08:00
seven332 7d0bfc1aa7 添加评论显示 2014-05-09 17:07:50 +08:00
seven332 3d31c32d40 修正由于 Activity 正在关闭后再对 view 修改可能造成的错误 2014-05-09 11:20:27 +08:00
seven332 087a6ee305 添加 详情 tab 2014-05-09 11:17:21 +08:00
seven332 9056d7ced0 搜索标签移至右侧栏 2014-05-08 23:41:40 +08:00
seven332 4a8e01caec 修正语言搜索,完善 search bar 资源 2014-05-08 21:55:59 +08:00
seven332 1088729269 优化 list_item 布局 2014-05-08 20:42:29 +08:00
seven332 21ac176f5f 改用及时响应的 ratingbar,初步添加用户面板 2014-05-08 19:33:50 +08:00
seven332 b3cc1dec4b 创建 ProgressiveTextView,用来简易的显示 TextView 的字符串替换效果 2014-05-08 00:18:15 +08:00
seven332 3da180beb0 添加 tag 投票数显示 2014-05-07 21:41:54 +08:00
seven332 acec30ae5a 完善 vote 功能 2014-05-07 20:29:44 +08:00
seven332 8229007710 完善 gallery 评分 view 2014-05-07 19:16:04 +08:00
seven332 80e0432c73 修正 ratingbar 2014-05-07 16:59:03 +08:00
seven332 c97dccaf04 添加 vote 2014-05-07 01:23:46 +08:00
seven332 f4bdbe1ed1 修正 search bar style 2014-05-07 01:01:49 +08:00
seven332 75a67ae54e 修正列表 2014-05-06 18:28:20 +08:00
seven332 61c3144a48 修正列表 2014-05-06 18:26:09 +08:00
seven332 8158bae9d5 优化列表 2014-05-06 16:45:09 +08:00
seven332 9615aa0b7c 完善界面,修正列表显示 2014-05-06 00:41:35 +08:00
seven332 870153ef88 Just project 2014-05-05 20:00:56 +08:00
seven332 741203ab81 Remove duplicated directory 2014-05-05 19:56:26 +08:00
seven332 0b74bf3fc3 完善界面 2014-05-05 19:28:29 +08:00
seven332 f5f7489093 改用 ActionBar Pull 2014-05-04 22:24:23 +08:00
seven332 05dae37a28 修正 pullListView 2014-05-03 13:48:31 +08:00
seven332 1384a05830 部分优化 2014-05-03 00:10:49 +08:00
seven332 256b4896cb 完善界面 2014-05-01 20:05:09 +08:00
seven332 c44011402f 部分调整详情界面 2014-04-30 00:37:20 +08:00
seven332 eff24ca4b3 部分规范化界面 2014-04-28 22:37:32 +08:00
seven332 8f16044c6b check curShowItem null 2014-04-26 16:02:06 +08:00
seven332 7c46027bd6 dev 2014-04-26 15:47:15 +08:00
seven332 5f7b677db7 wocaocao 2014-04-26 15:45:15 +08:00
seven332 b27e02fed1 unknown 2014-04-26 15:28:42 +08:00
seven332 abe2189acd 调整文件位置 2014-04-14 22:37:07 +08:00
seven332 721659d959 Download sql 2014-04-14 22:32:45 +08:00
seven332 d2e083922e 使用数据库存储 local favourite 2014-04-13 15:49:23 +08:00
seven332 34181ce370 略 2014-04-12 14:13:21 +08:00
seven332 a939c505f9 添加 ActionBar 效果 2014-04-10 23:28:39 +08:00
seven332 5de9fc8134 添加封面图片渐进效果显示 2014-04-08 22:51:40 +08:00
seven332 0c45ddf04d 添加 够快 更新服务器 2014-04-08 22:03:39 +08:00
seven332 74e37ea72d 修改手势,字符串 2014-04-07 11:23:46 +08:00
seven332 c6c060b5e2 0.4.4 2014-04-06 13:49:54 +08:00
seven332 def283de08 添加 charset 识别 2014-04-06 13:45:52 +08:00
seven332 be3d3189ec 学习使用 ProGuard 2014-04-06 11:30:40 +08:00
seven332 0581b7cc53 使用更安全的 Log 2014-04-06 11:11:57 +08:00
seven332 79b75e5de1 0.4.3 2014-04-05 23:57:52 +08:00
seven332 f7be9dec18 添加更新服务器选择 2014-04-05 23:51:48 +08:00
seven332 566226958f 临时解决 endIndex 大于 size 的问题 2014-04-05 23:15:07 +08:00
seven332 e45db97a54 用 json 检查更新 2014-04-05 22:28:45 +08:00
seven332 ea58ffed74 用 json 检查更新 2014-04-05 22:28:11 +08:00
seven332 eb1e49e7c7 更丰富的错误提示 2014-04-05 00:08:10 +08:00
seven332 b69c71a54b 0.4.2 2014-04-04 23:26:37 +08:00
seven332 3aff219639 修正由于 gif 格式图片导致的崩溃 2014-04-04 23:13:33 +08:00
seven332 e1edd00fb0 继续 2014-04-03 20:16:34 +08:00
seven332 70e0aada25 调整EhClient 2014-04-03 19:28:57 +08:00
seven332 1c11ac38ea 添加内置存储空间或 Sd Card 检测 2014-04-02 19:56:49 +08:00
seven332 7ac8878f83 修正网络错误时进入详情界面应用崩溃 2014-04-02 13:05:22 +08:00
seven332 a48a18ba84 0.4.1 2014-04-02 12:54:21 +08:00
seven332 8a2a2061a9 添加断点下载 2014-04-01 21:37:27 +08:00
seven332 b1f772eb2f 修正单点触控缩放错误 2014-04-01 11:39:02 +08:00
seven332 37043c1284 WrongCall 警告 2014-04-01 11:10:55 +08:00
seven332 7f693f4e1d 0.4.0 2014-04-01 11:09:00 +08:00
seven332 529ed71ebe 修正下载阅读文字提示错误 2014-04-01 11:07:20 +08:00
seven332 644d3d6402 检测已存在磁盘中的图片,删除页面缓存 2014-04-01 00:43:42 +08:00
seven332 83395619e7 阅读界面在非下载界面的使用 2014-03-31 23:59:51 +08:00
seven332 cde6904e3f 完成开页方向,单点触控 2014-03-31 00:32:12 +08:00
seven332 74dcbae3dd 初步完成阅读界面 2014-03-30 10:59:41 +08:00
seven332 70f6a2fa78 开启硬件加速 2014-03-29 00:58:41 +08:00
seven332 567b0a2c19 自动更新改为每日检查,user-agent使用默认值 2014-03-28 19:25:54 +08:00
seven332 5e28481684 修正获取网页 2014-03-28 14:38:11 +08:00
seven332 90ed3d40f3 添加注释 2014-03-27 19:59:49 +08:00
seven332 366285f625 修正未判断下载服务获取DownloadInfo为空的错误 2014-03-25 13:11:59 +08:00
seven332 7945b0facd 添加 AutoWrapLayout 每行 baseLine top, center, bottom 功能
修正预览图下沿对齐
2014-03-25 11:50:42 +08:00
seven332 556429a4d6 显示漫画标签组名 2014-03-25 00:14:39 +08:00
seven332 601d426721 完善 AutoWrapLayout onMeasure 函数,图片内存缓存设为 8MB 2014-03-24 23:52:07 +08:00
seven332 aa3d3ca57c update changelog 2014-03-23 23:49:49 +08:00
seven332 471cf5df85 修正更新显示主机错误 2014-03-23 23:48:34 +08:00
seven332 177920a1eb 提升版本号,仅供自动更新测试 2014-03-23 23:27:04 +08:00
seven332 ab4b4ad598 修正图片多次加载错误 2014-03-23 23:12:15 +08:00
seven332 626f7141e9 添加漫画TAG显示 2014-03-23 22:43:30 +08:00
seven332 30c7ac5100 使用自己写的换行控件,onMeasure 有必要修改 2014-03-23 20:50:37 +08:00
seven332 b30489785f 上个保存有错误 2014-03-23 16:48:55 +08:00
seven332 22e042d11d 修正选择发送方式会被下个 Activity 掩盖错误。 2014-03-23 16:48:28 +08:00
seven332 6137e851cd 添加检测登陆状态按钮 2014-03-23 16:26:04 +08:00
seven332 57419fd8d1 添加列表图片加载栈,添加 httpHelper 类,以后完善 2014-03-23 16:00:27 +08:00
seven332 471962e664 自动更新 2014-03-23 10:14:47 +08:00
seven332 7254d9d7a7 修正由于没有上锁导致的disklru清除错误 2014-03-23 10:13:59 +08:00
seven332 ea2418b981 改用 drawerlayout 修改版的侧边栏 2014-03-22 23:03:14 +08:00
seven332 5c4009e435 完成启动界面,自己写的下拉控件 2014-03-21 23:43:51 +08:00
seven332 89c7beda26 添加启动界面,使用自己的滑动控件,完成一大半,明天继续。 2014-03-21 00:51:47 +08:00
seven332 c6109bd0d4 非 ongoing 通知栏点击后消除 2014-03-14 21:14:13 +08:00
seven332 15d6e4f87c 修复点击状态栏不显示下载界面 2014-03-14 14:04:48 +08:00
seven332 7cfd910122 dev download almost completed 2014-03-14 13:04:10 +08:00
seven332 c67619d54c dev 2014.03.13 2014-03-13 23:33:42 +08:00
seven332 38ec446130 dev 2014.03.12 2014-03-12 00:11:11 +08:00
seven332 60a5fd2443 dev download manager 2014-03-11 22:19:02 +08:00
seven332 f8907c6e8f 修正搜索标签重命名错误 2014-03-11 12:54:22 +08:00
seven332 61e318fb6e add other 2014-03-11 11:11:23 +08:00
seven332 1382a83648 add lib 2014-03-11 11:10:32 +08:00
1121 changed files with 19812 additions and 33747 deletions

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
+56
View File
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="com.android.toolchain.gcc.1322280913">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="com.android.toolchain.gcc.1322280913" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="" id="com.android.toolchain.gcc.1322280913" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="com.android.toolchain.gcc.1322280913.1369823253" name="/" resourcePath="">
<toolChain id="com.android.toolchain.gcc.803500692" name="Android GCC" superClass="com.android.toolchain.gcc">
<targetPlatform binaryParser="org.eclipse.cdt.core.ELF" id="com.android.targetPlatform.1260474165" isAbstract="false" superClass="com.android.targetPlatform"/>
<builder arguments="NDK_DEBUG=0" autoBuildTarget="" cleanBuildTarget="clean" command="ndk-build" enableAutoBuild="false" enableCleanBuild="false" enabledIncrementalBuild="true" id="com.android.builder.2127875218" incrementalBuildTarget="" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Android Builder" superClass="com.android.builder">
<outputEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="outputPath" name="obj"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="outputPath" name="libs"/>
</outputEntries>
</builder>
<tool id="com.android.gcc.compiler.877935514" name="Android GCC Compiler" superClass="com.android.gcc.compiler">
<inputType id="com.android.gcc.inputType.68370901" superClass="com.android.gcc.inputType"/>
</tool>
</toolChain>
</folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="jni"/>
</sourceEntries>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="EhViewer.null.1834465747" name="EhViewer"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="com.android.toolchain.gcc.1322280913;com.android.toolchain.gcc.1322280913.1369823253;com.android.gcc.compiler.877935514;com.android.gcc.inputType.68370901">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.android.AndroidPerProjectProfile"/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="refreshScope" versionNumber="1">
<resource resourceType="PROJECT" workspacePath="/EhViewer"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
</cproject>
+12 -8
View File
@@ -1,8 +1,12 @@
.gradle
/local.properties
.DS_Store
/build
/src
*.iml
.idea
/captures
.settings
bin
gen
obj
doc
proguard
lint.xml
libs/armeabi
libs/armeabi-v7a
libs/arm64-v8a
libs/mips
libs/x86
+105
View File
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>EhViewer</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
<dictionary>
<key>?children?</key>
<value>?children?=?name?=entry\\\\\\\|\\\|?name?=entry\\\\\\\|\\\|\|?name?=outputEntries\||</value>
</dictionary>
<dictionary>
<key>?name?</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.append_environment</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.autoBuildTarget</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildArguments</key>
<value>NDK_DEBUG=0</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildCommand</key>
<value>ndk-build</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
<value>clean</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.contents</key>
<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
<value>false</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
<value>false</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.fullBuildTarget</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.stopOnError</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
<value>false</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
@@ -14,9 +14,14 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hippo.ehviewer">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hippo.ehviewer"
android:versionCode="30"
android:versionName="0.6.9" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
@@ -28,17 +33,15 @@
android:allowBackup="true"
android:hardwareAccelerated="true"
android:largeHeap="true"
android:supportsRtl="true"
android:icon="@mipmap/ic_launcher"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme.Normal">
android:theme="@style/AppTheme.Normal" >
<activity
android:name=".StartActivity"
android:configChanges="orientation|screenSize|uiMode"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar.Transparent.Translucent" >
android:theme="@style/AppTheme.NoActionBar.Transparent" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@@ -60,15 +63,6 @@
android:resource="@xml/searchable" />
</activity>
<activity
android:name=".ui.WebViewLoginActivity"
android:configChanges="orientation|screenSize|uiMode"
android:label="@string/login"
android:screenOrientation="behind"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<activity
android:name=".ui.GalleryDetailActivity"
android:configChanges="orientation|screenSize|uiMode"
@@ -79,7 +73,6 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="exhentai.org" />
<data android:host="g.e-hentai.org" />
<data android:host="lofi.e-hentai.org" />
@@ -91,12 +84,13 @@
android:name=".ui.GalleryActivity"
android:configChanges="orientation|screenSize|uiMode"
android:screenOrientation="behind"
android:theme="@style/AppTheme.Dark.NoActionBar" >
android:theme="@style/AppTheme.Gallery" >
</activity>
<activity
android:name=".ui.SettingsActivity"
android:configChanges="orientation|screenSize|uiMode"
android:icon="@drawable/ic_action_settings"
android:label="@string/preference_settings_title"
android:screenOrientation="behind" >
</activity>
@@ -104,6 +98,7 @@
<activity
android:name=".ui.FavouriteActivity"
android:configChanges="orientation|screenSize|uiMode"
android:icon="@drawable/ic_action_favorite"
android:label="@string/favourite"
android:screenOrientation="behind"
android:theme="@style/AppTheme.ListActivity" >
@@ -112,6 +107,7 @@
<activity
android:name=".ui.HistoryActivity"
android:configChanges="orientation|screenSize|uiMode"
android:icon="@drawable/ic_action_history"
android:label="@string/history"
android:screenOrientation="behind"
android:theme="@style/AppTheme.ListActivity" >
@@ -120,6 +116,7 @@
<activity
android:name=".ui.DownloadActivity"
android:configChanges="orientation|screenSize|uiMode"
android:icon="@drawable/ic_setting_download"
android:label="@string/download"
android:launchMode="singleTask"
android:screenOrientation="behind"
@@ -129,29 +126,6 @@
android:value=".ui.GalleryListActivity" />
</activity>
<activity
android:name=".ui.SecretActivity"
android:configChanges="orientation|screenSize|uiMode"
android:screenOrientation="behind"
android:theme="@style/AppTheme.NoActionBar.Transparent" >
</activity>
<activity
android:name=".ui.PatternProtectionActivity"
android:configChanges="orientation|screenSize|uiMode"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme" >
</activity>
<activity
android:name=".ui.EnterPatternActivity"
android:configChanges="orientation|screenSize|uiMode"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme" >
</activity>
<service
android:name=".service.DownloadService"
android:label="DownloadService" />
@@ -161,13 +135,6 @@
android:authorities="com.hippo.ehviewer.SimpleSuggestionProvider"
android:exported="false" />
<receiver android:name=".receiver.RestPatternReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE"/>
<data android:scheme="android_secret_code" android:host="110722"/>
</intent-filter>
</receiver>
</application>
</manifest>
</manifest>
-19
View File
@@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="EhViewer" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
+202
View File
@@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+4 -61
View File
@@ -1,70 +1,13 @@
# EhViewer
这是一个 Android 平台上的 E-Hentai 阅读应用。访问 [EhViewer](http://www.ehviewer.com/) 网站以获取更多信息。<br>
EhViewer is an E-Hentai Application for Android. Visit [EhViewer](http://www.ehviewer.com/)(Chinese Only) website for more information.
# Build
导入 Android Studio 即可。<br>
Just import into Android Studio.
# Thanks
- [android-gif-drawable](https://github.com/koral--/android-gif-drawable)
- 参考 gif 解码
- [ActionBar-PullToRefresh](https://github.com/chrisbanes/ActionBar-PullToRefresh)
- 曾作为刷新控件
- [ActionBarSherlocke](https://github.com/JakeWharton/ActionBarSherlock)
- 曾用来对 4.0 一些系统兼容
- [Android-PullToRefresh](https://github.com/chrisbanes/Android-PullToRefresh)
- 曾作为刷新控件
- [AndroidStaggeredGrid](https://github.com/etsy/AndroidStaggeredGrid)
- 列表控件
- [Apollo-CM](https://github.com/adneal/Apollo-CM)
- 缓存机制
- [DiskLruCache](https://github.com/JakeWharton/DiskLruCache)
- 缓存机制
- [FloatingActionButton](https://github.com/FaizMalkani/FloatingActionButton)
- 按钮控件
- [GIFLIB](http://giflib.sourceforge.net)
- gif 解码
- [Gloria Hallelujah](https://www.google.com/fonts/specimen/Gloria+Hallelujah)
- 启动界面字体
- [ImageLoadingPattern](https://github.com/rnrneverdies/ImageLoadingPattern)
- 图片过渡效果
- [libjpeg-turbo](http://www.libjpeg-turbo.org)
- jpge 解码
- [libpng](http://www.libpng.org/pub/png/libpng.html)
- png 解码
- [material-menu](https://github.com/balysv/material-menu)
- 抽屉指示器
- [OpenCC](https://github.com/BYVoid/OpenCC)
- 繁化工作
- [Slabo](https://github.com/TiroTypeworks/Slabo)
- 图标字体
- [SlidingMenu](https://github.com/jfeinstein10/SlidingMenu)
- 曾作为抽屉控件
- [source-code-pro](https://github.com/adobe/source-code-pro)
- 刷新控件字体
- [svg-android](https://code.google.com/p/svg-android/)
- svg 解析
- [SystemBarTint](https://github.com/jgilfelt/SystemBarTint)
- 状态栏背景设置
- [twoway-view](https://github.com/lucasr/twoway-view)
- RecyclerView 使用方法
- [zlib](http://www.zlib.net)
- 辅助 png 解码
- [Android Open Source Project](http://source.android.com)
- 很多很多
- [commons-lang](http://commons.apache.org/proper/commons-lang)
- 很多很多
这是一个 Android 平台上的 E-Hentai 阅读应用。<br>
E-Hentai Application for Android.
# License
本项目内容采用 [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0) 授权,
部分文件采用 [Creative Commons Attribution 3.0 Unported License](http://creativecommons.org/licenses/by/3.0/) 授权([列表](rc/list1)),
部分文件采用 [SIL Open Font License, 1.1](http://scripts.sil.org/OFL) 授权([列表](rc/list2))。
<br>
部分文件可随意使用([列表](rc/list2))。<br>
The content of this project itself is licensed under the [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0),
some files are licensed under the [Creative Commons Attribution 3.0 Unported License](http://creativecommons.org/licenses/by/3.0/) ([list](rc/list1)),
some files are licensed under the [SIL Open Font License, 1.1](http://scripts.sil.org/OFL) ([list](rc/list2)).
some files are free to use ([list](rc/list2)).
-3
View File
@@ -1,3 +0,0 @@
/build
/src/main/obj
/src/main/libs
-111
View File
@@ -1,111 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="EhViewer" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":app" />
</configuration>
</facet>
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<afterSyncTasks>
<task>generateDebugSources</task>
</afterSyncTasks>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="libGoogleAnalyticsServices" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.1" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-22.2.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.1" level="project" />
<orderEntry type="module" module-name="vector" exported="" />
</component>
</module>
-72
View File
@@ -1,72 +0,0 @@
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "com.hippo.ehviewer"
minSdkVersion 14
targetSdkVersion 22
versionCode 47
versionName "0.6.16.3"
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
// Disable default NdkCompile task
// Set new jni lib dir
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir 'src/main/libs'
}
// noinspection GroovyAssignabilityCheck
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = project.plugins.findPlugin('com.android.application').sdkHandler.getNdkFolder()
def ndkBuilder
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
ndkBuilder = 'ndk-build.cmd'
} else {
ndkBuilder = 'ndk-build'
}
commandLine "$ndkDir\\$ndkBuilder",
'-C', file('src/main').absolutePath,
'NDK_DEBUG=0',
'NDK_TOOLCHAIN_VERSION=clang',
'-j4'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
clean {
delete file('src/main/obj').absolutePath
delete file('src/main/libs').absolutePath
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':vector')
compile 'com.android.support:support-v4:22.2.1'
compile 'com.android.support:recyclerview-v7:22.2.1'
}
@@ -1,13 +0,0 @@
package com.hippo.ehviewer;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
Binary file not shown.
Binary file not shown.
@@ -1,82 +0,0 @@
/*
* Copyright (C) 2014 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.app;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.util.Ui;
import com.hippo.ehviewer.util.ViewUtils;
import com.hippo.ehviewer.widget.FileExplorerView;
public class DirSelectDialog extends MaterialAlertDialog {
private final FileExplorerView mFileExplorerView;
protected DirSelectDialog(Builder builder, FileExplorerView fileExplorerView) {
super(builder);
mFileExplorerView = fileExplorerView;
}
public static DirSelectDialog create(Builder builder, String path) {
View view = ViewUtils.inflateDialogView(R.layout.dir_selection, builder.mDarkTheme);
final FileExplorerView fileExplorerView = (FileExplorerView) view.findViewById(R.id.file_list);
final TextView warningTextView = (TextView) view.findViewById(R.id.warning);
final TextView pathTextView = (TextView) view.findViewById(R.id.path);
if (path != null)
fileExplorerView.setPath(path);
fileExplorerView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
fileExplorerView.onItemClick(parent, view, position, id);
pathTextView.setText(fileExplorerView.getCurPath());
if (fileExplorerView.canWrite())
warningTextView.setVisibility(View.GONE);
else
warningTextView.setVisibility(View.VISIBLE);
}
});
pathTextView.setText(fileExplorerView.getCurPath());
if (fileExplorerView.canWrite())
warningTextView.setVisibility(View.GONE);
else
warningTextView.setVisibility(View.VISIBLE);
builder.setView(view, false,
new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, Ui.dp2pix(360)));
return new DirSelectDialog(builder, fileExplorerView);
}
public String getCurrentPath() {
return mFileExplorerView.getCurPath();
}
public void refresh() {
mFileExplorerView.refresh();
}
public boolean canWrite() {
return mFileExplorerView.canWrite();
}
}
-501
View File
@@ -1,501 +0,0 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.cache;
import android.os.Looper;
import android.support.annotation.Nullable;
import android.support.v4.util.LruCache;
import com.hippo.ehviewer.util.Log;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public abstract class AnyCache<V> {
private static final String TAG = AnyCache.class.getSimpleName();
private LruCache<String, V> mMemoryCache;
private @Nullable DiskCache<V> mDiskCache;
private final boolean mHasMemoryCache;
private final boolean mHasDiskCache;
/**
* Used to temporarily pause the disk cache while scrolling
*/
public boolean mPauseDiskAccess = false;
private final Object mPauseLock = new Object();
private final Object mDiskCacheLock = new Object();
public AnyCache(AnyCacheParams params) {
params.isValid();
mHasMemoryCache = params.hasMemoryCache;
mHasDiskCache = params.hasDiskCache;
if (mHasMemoryCache) {
initMemoryCache(params.memoryCacheMaxSize);
}
if (mHasDiskCache) {
initDiskCache(params.diskCacheDir, params.diskCacheMaxSize);
}
}
private void initMemoryCache(int maxSize) {
mMemoryCache = new MemoryCahce<>(maxSize, this);
}
private void initDiskCache(File cacheDir, int maxSize) {
// Set up disk cache
synchronized (mDiskCacheLock) {
try {
mDiskCache = new DiskCache<>(cacheDir, maxSize, this);
} catch (IOException e) {
Log.e(TAG, "Can't create disk cache", e);
}
}
}
protected abstract int sizeOf(String key, V value);
protected abstract V read(InputStream is);
protected abstract boolean write(OutputStream os, V value);
/**
* Check if have memory cache
*
* @return true if have memory cache
*/
public boolean hasMemoryCache() {
return mHasMemoryCache;
}
/**
* Check if have disk cache
*
* @return true if have disk cache
*/
public boolean hasDiskCache() {
return mHasDiskCache;
}
/**
* Get value from memory cache
*
* @param key the key to get value
* @return the value you get, null for miss or no memory cache
*/
public V getFromMemory(String key) {
if (mHasMemoryCache) {
return mMemoryCache.get(key);
} else {
return null;
}
}
/**
* Get value from memory cache
*
* @param key the key to get value
* @return the value you get, null for miss or no memory cache or get error
*/
public V getFromDisk(String key) {
if (mHasDiskCache) {
// Wait for pause
waitUntilUnpaused();
String diskKey = hashKeyForDisk(key);
synchronized (mDiskCacheLock) {
if (mDiskCache != null) {
return mDiskCache.get(diskKey);
} else {
return null;
}
}
} else {
return null;
}
}
/**
* Get value from memory cache and disk cache. If miss in memory cache and
* get in disk cache, it will put value from disk cache to memory cache.
*
* @param key the key to get value
* @return the value you get
*/
public V get(String key) {
V value = getFromMemory(key);
if (value != null) {
// Get it in memory cache
return value;
}
value = getFromDisk(key);
if (value != null) {
// Get it in disk cache
putToMemory(key, value);
return value;
}
return null;
}
/**
* Put value to memory cache
*
* @param key the key
* @param value the value
* @return false if no memory cache
*/
public boolean putToMemory(String key, V value) {
if (mHasMemoryCache) {
mMemoryCache.put(key, value);
return true;
} else {
return false;
}
}
/**
* Put value to disk cache
*
* @param key the key
* @param value the value
* @return false if no disk cache or get error
*/
public boolean putToDisk(String key, V value) {
if (mHasDiskCache) {
// Wait for pause
waitUntilUnpaused();
String diskKey = hashKeyForDisk(key);
synchronized (mDiskCacheLock) {
if (mDiskCache != null) {
mDiskCache.put(diskKey, value);
return true;
} else {
return false;
}
}
} else {
return false;
}
}
/**
* Put value to memory cache and disk cache
*
* @param key the key
* @param value the value
*/
public void put(String key, V value) {
putToMemory(key, value);
putToDisk(key, value);
}
/**
* Used to temporarily pause the disk cache while the user is scrolling to
* improve scrolling.
*
* @param pause True to temporarily pause the disk cache, false otherwise.
*/
public void setPauseDiskCache(final boolean pause) {
synchronized (mPauseLock) {
if (mPauseDiskAccess != pause) {
mPauseDiskAccess = pause;
if (!pause) {
mPauseLock.notify();
}
}
}
}
private void waitUntilUnpaused() {
synchronized (mPauseLock) {
if (Looper.myLooper() != Looper.getMainLooper()) {
while (mPauseDiskAccess) {
try {
mPauseLock.wait();
} catch (InterruptedException e) {
// ignored, we'll start waiting again
}
}
}
}
}
/**
* Evicts all of the items from the memory cache
*/
public void clearMemory() {
if (mHasMemoryCache) {
mMemoryCache.evictAll();
}
}
/**
* Clear disk cache
*/
public void clearDisk() {
if (mHasDiskCache) {
synchronized (mDiskCacheLock) {
if (mDiskCache != null && !mDiskCache.isClosed()) {
try {
mDiskCache.delete();
} catch (IOException e) {
Log.e(TAG, "AnyCache clearCache", e);
}
File cacheDir = mDiskCache.getCacheDir();
int maxSize = mDiskCache.getMaxSize();
mDiskCache = null;
initDiskCache(cacheDir, maxSize);
}
}
}
}
public void flush() {
if (mHasDiskCache) {
synchronized (mDiskCacheLock) {
if (mDiskCache != null) {
try {
mDiskCache.flush();
} catch (IOException e) {
Log.e(TAG, "AnyCache flush", e);
}
}
}
}
}
/**
* Evicts all of the items from the memory cache and lets the system know
* now would be a good time to garbage collect
*/
public void clear() {
clearMemory();
clearDisk();
}
/**
* A hashing method that changes a string (like a URL) into a hash suitable
* for using as a disk filename.
*
* @param key The key used to store the file
*/
private static String hashKeyForDisk(final String key) {
String cacheKey;
try {
final MessageDigest digest = MessageDigest.getInstance("MD5");
digest.update(key.getBytes());
cacheKey = bytesToHexString(digest.digest());
} catch (final NoSuchAlgorithmException e) {
cacheKey = String.valueOf(key.hashCode());
}
return cacheKey;
}
/**
* http://stackoverflow.com/questions/332079
*
* @param bytes The bytes to convert.
* @return A {@link String} converted from the bytes of a hashable key used
* to store a filename on the disk, to hex digits.
*/
private static String bytesToHexString(final byte[] bytes) {
final StringBuilder builder = new StringBuilder();
for (final byte b : bytes) {
final String hex = Integer.toHexString(0xFF & b);
if (hex.length() == 1) {
builder.append('0');
}
builder.append(hex);
}
return builder.toString();
}
/**
* A holder class that contains cache parameters.
*/
public static class AnyCacheParams {
public boolean hasMemoryCache = false;
public int memoryCacheMaxSize = 0;
public boolean hasDiskCache = false;
public File diskCacheDir = null;
public int diskCacheMaxSize = 0;
/**
* Check AnyCacheParams is valid
*
* @throws IllegalStateException
*/
public void isValid() throws IllegalStateException {
if (!hasMemoryCache && !hasDiskCache) {
throw new IllegalStateException("No memory cache and no disk cache. What can I do for you?");
}
if (hasMemoryCache && memoryCacheMaxSize <= 0) {
throw new IllegalStateException("Memory cache max size must be bigger than 0.");
}
if (hasDiskCache) {
if (diskCacheDir == null) {
throw new IllegalStateException("Disk cache dir can't be null.");
}
if (diskCacheMaxSize <= 0) {
throw new IllegalStateException("Disk cache max size must be bigger than 0.");
}
}
}
}
public class MemoryCahce<E> extends LruCache<String, E> {
public AnyCache<E> mParent;
public MemoryCahce(int maxSize, AnyCache<E> parent) {
super(maxSize);
mParent = parent;
}
@Override
protected int sizeOf(String key, E value) {
return mParent.sizeOf(key, value);
}
}
public static class DiskCache<E> {
private static final int IO_BUFFER_SIZE = 8 * 1024;
private DiskLruCache mDiskLruCache;
private AnyCache<E> mParent;
private File mCacheDir;
private int mMaxSize;
public DiskCache(File cacheDir, int size, AnyCache<E> parent) throws IOException {
mDiskLruCache = DiskLruCache.open(cacheDir, 1, 1, size);
mParent = parent;
mCacheDir = cacheDir;
mMaxSize = size;
}
public File getCacheDir() {
return mCacheDir;
}
public int getMaxSize() {
return mMaxSize;
}
public boolean isClosed() {
return mDiskLruCache.isClosed();
}
public void delete() throws IOException {
mDiskLruCache.delete();
}
public void flush() throws IOException {
mDiskLruCache.flush();
}
public E get(String key) {
DiskLruCache.Snapshot snapshot = null;
try {
snapshot = mDiskLruCache.get(key);
if ( snapshot == null ) {
// Miss
return null;
}
final InputStream in = snapshot.getInputStream(0);
if (in != null) {
final BufferedInputStream buffIn =
new BufferedInputStream(in, IO_BUFFER_SIZE);
return mParent.read(buffIn);
} else {
// Can't get InputStream
return null;
}
} catch (IOException e) {
// e.printStackTrace();
return null;
} finally {
Util.closeQuietly(snapshot);
}
}
public boolean put(String key, E value) {
DiskLruCache.Editor editor = null;
OutputStream os = null;
boolean completeEdit = false;
try {
editor = mDiskLruCache.edit(key);
if (editor == null) {
// The editor is in progress
return false;
}
os = editor.newOutputStream(0);
if (os != null) {
final BufferedOutputStream buffOut =
new BufferedOutputStream(os, IO_BUFFER_SIZE);
boolean result = mParent.write(buffOut, value);
completeEdit = true;
editor.commit();
return result;
} else {
// Can't get OutputStream
completeEdit = true;
editor.abort();
return false;
}
} catch (IOException e) {
Util.closeQuietly(os);
try {
if (!completeEdit && editor != null) {
editor.abort();
}
} catch (IOException ignored) {
}
return false;
}
}
}
}
@@ -1,943 +0,0 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.cache;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* A cache that uses a bounded amount of space on a filesystem. Each cache
* entry has a string key and a fixed number of values. Each key must match
* the regex <strong>[a-z0-9_-]{1,120}</strong>. Values are byte sequences,
* accessible as streams or files. Each value must be between {@code 0} and
* {@code Integer.MAX_VALUE} bytes in length.
*
* <p>The cache stores its data in a directory on the filesystem. This
* directory must be exclusive to the cache; the cache may delete or overwrite
* files from its directory. It is an error for multiple processes to use the
* same cache directory at the same time.
*
* <p>This cache limits the number of bytes that it will store on the
* filesystem. When the number of stored bytes exceeds the limit, the cache will
* remove entries in the background until the limit is satisfied. The limit is
* not strict: the cache may temporarily exceed it while waiting for files to be
* deleted. The limit does not include filesystem overhead or the cache
* journal so space-sensitive applications should set a conservative limit.
*
* <p>Clients call {@link #edit} to create or update the values of an entry. An
* entry may have only one editor at one time; if a value is not available to be
* edited then {@link #edit} will return null.
* <ul>
* <li>When an entry is being <strong>created</strong> it is necessary to
* supply a full set of values; the empty value should be used as a
* placeholder if necessary.
* <li>When an entry is being <strong>edited</strong>, it is not necessary
* to supply data for every value; values default to their previous
* value.
* </ul>
* Every {@link #edit} call must be matched by a call to {@link Editor#commit}
* or {@link Editor#abort}. Committing is atomic: a read observes the full set
* of values as they were before or after the commit, but never a mix of values.
*
* <p>Clients call {@link #get} to read a snapshot of an entry. The read will
* observe the value at the time that {@link #get} was called. Updates and
* removals after the call do not impact ongoing reads.
*
* <p>This class is tolerant of some I/O errors. If files are missing from the
* filesystem, the corresponding entries will be dropped from the cache. If
* an error occurs while writing a cache value, the edit will fail silently.
* Callers should handle other problems by catching {@code IOException} and
* responding appropriately.
*/
public final class DiskLruCache implements Closeable {
static final String JOURNAL_FILE = "journal";
static final String JOURNAL_FILE_TEMP = "journal.tmp";
static final String JOURNAL_FILE_BACKUP = "journal.bkp";
static final String MAGIC = "libcore.io.DiskLruCache";
static final String VERSION_1 = "1";
static final long ANY_SEQUENCE_NUMBER = -1;
static final String STRING_KEY_PATTERN = "[a-z0-9_-]{1,120}";
static final Pattern LEGAL_KEY_PATTERN = Pattern.compile(STRING_KEY_PATTERN);
private static final String CLEAN = "CLEAN";
private static final String DIRTY = "DIRTY";
private static final String REMOVE = "REMOVE";
private static final String READ = "READ";
/*
* This cache uses a journal file named "journal". A typical journal file
* looks like this:
* libcore.io.DiskLruCache
* 1
* 100
* 2
*
* CLEAN 3400330d1dfc7f3f7f4b8d4d803dfcf6 832 21054
* DIRTY 335c4c6028171cfddfbaae1a9c313c52
* CLEAN 335c4c6028171cfddfbaae1a9c313c52 3934 2342
* REMOVE 335c4c6028171cfddfbaae1a9c313c52
* DIRTY 1ab96a171faeeee38496d8b330771a7a
* CLEAN 1ab96a171faeeee38496d8b330771a7a 1600 234
* READ 335c4c6028171cfddfbaae1a9c313c52
* READ 3400330d1dfc7f3f7f4b8d4d803dfcf6
*
* The first five lines of the journal form its header. They are the
* constant string "libcore.io.DiskLruCache", the disk cache's version,
* the application's version, the value count, and a blank line.
*
* Each of the subsequent lines in the file is a record of the state of a
* cache entry. Each line contains space-separated values: a state, a key,
* and optional state-specific values.
* o DIRTY lines track that an entry is actively being created or updated.
* Every successful DIRTY action should be followed by a CLEAN or REMOVE
* action. DIRTY lines without a matching CLEAN or REMOVE indicate that
* temporary files may need to be deleted.
* o CLEAN lines track a cache entry that has been successfully published
* and may be read. A publish line is followed by the lengths of each of
* its values.
* o READ lines track accesses for LRU.
* o REMOVE lines track entries that have been deleted.
*
* The journal file is appended to as cache operations occur. The journal may
* occasionally be compacted by dropping redundant lines. A temporary file named
* "journal.tmp" will be used during compaction; that file should be deleted if
* it exists when the cache is opened.
*/
private final File directory;
private final File journalFile;
private final File journalFileTmp;
private final File journalFileBackup;
private final int appVersion;
private long maxSize;
private final int valueCount;
private long size = 0;
private Writer journalWriter;
private final LinkedHashMap<String, Entry> lruEntries =
new LinkedHashMap<String, Entry>(0, 0.75f, true);
private int redundantOpCount;
/**
* To differentiate between old and current snapshots, each entry is given
* a sequence number each time an edit is committed. A snapshot is stale if
* its sequence number is not equal to its entry's sequence number.
*/
private long nextSequenceNumber = 0;
/** This cache uses a single background thread to evict entries. */
final ThreadPoolExecutor executorService =
new ThreadPoolExecutor(0, 1, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
private final Callable<Void> cleanupCallable = new Callable<Void>() {
public Void call() throws Exception {
synchronized (DiskLruCache.this) {
if (journalWriter == null) {
return null; // Closed.
}
trimToSize();
if (journalRebuildRequired()) {
rebuildJournal();
redundantOpCount = 0;
}
}
return null;
}
};
private DiskLruCache(File directory, int appVersion, int valueCount, long maxSize) {
this.directory = directory;
this.appVersion = appVersion;
this.journalFile = new File(directory, JOURNAL_FILE);
this.journalFileTmp = new File(directory, JOURNAL_FILE_TEMP);
this.journalFileBackup = new File(directory, JOURNAL_FILE_BACKUP);
this.valueCount = valueCount;
this.maxSize = maxSize;
}
/**
* Opens the cache in {@code directory}, creating a cache if none exists
* there.
*
* @param directory a writable directory
* @param valueCount the number of values per cache entry. Must be positive.
* @param maxSize the maximum number of bytes this cache should use to store
* @throws IOException if reading or writing the cache directory fails
*/
public static DiskLruCache open(File directory, int appVersion, int valueCount, long maxSize)
throws IOException {
if (maxSize <= 0) {
throw new IllegalArgumentException("maxSize <= 0");
}
if (valueCount <= 0) {
throw new IllegalArgumentException("valueCount <= 0");
}
// If a bkp file exists, use it instead.
File backupFile = new File(directory, JOURNAL_FILE_BACKUP);
if (backupFile.exists()) {
File journalFile = new File(directory, JOURNAL_FILE);
// If journal file also exists just delete backup file.
if (journalFile.exists()) {
backupFile.delete();
} else {
renameTo(backupFile, journalFile, false);
}
}
// Prefer to pick up where we left off.
DiskLruCache cache = new DiskLruCache(directory, appVersion, valueCount, maxSize);
if (cache.journalFile.exists()) {
try {
cache.readJournal();
cache.processJournal();
return cache;
} catch (IOException journalIsCorrupt) {
System.out
.println("DiskLruCache "
+ directory
+ " is corrupt: "
+ journalIsCorrupt.getMessage()
+ ", removing");
cache.delete();
}
}
// Create a new empty cache.
directory.mkdirs();
cache = new DiskLruCache(directory, appVersion, valueCount, maxSize);
cache.rebuildJournal();
return cache;
}
private void readJournal() throws IOException {
StrictLineReader reader = new StrictLineReader(new FileInputStream(journalFile), Util.US_ASCII);
try {
String magic = reader.readLine();
String version = reader.readLine();
String appVersionString = reader.readLine();
String valueCountString = reader.readLine();
String blank = reader.readLine();
if (!MAGIC.equals(magic)
|| !VERSION_1.equals(version)
|| !Integer.toString(appVersion).equals(appVersionString)
|| !Integer.toString(valueCount).equals(valueCountString)
|| !"".equals(blank)) {
throw new IOException("unexpected journal header: [" + magic + ", " + version + ", "
+ valueCountString + ", " + blank + "]");
}
int lineCount = 0;
while (true) {
try {
readJournalLine(reader.readLine());
lineCount++;
} catch (EOFException endOfJournal) {
break;
}
}
redundantOpCount = lineCount - lruEntries.size();
// If we ended on a truncated line, rebuild the journal before appending to it.
if (reader.hasUnterminatedLine()) {
rebuildJournal();
} else {
journalWriter = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(journalFile, true), Util.US_ASCII));
}
} finally {
Util.closeQuietly(reader);
}
}
private void readJournalLine(String line) throws IOException {
int firstSpace = line.indexOf(' ');
if (firstSpace == -1) {
throw new IOException("unexpected journal line: " + line);
}
int keyBegin = firstSpace + 1;
int secondSpace = line.indexOf(' ', keyBegin);
final String key;
if (secondSpace == -1) {
key = line.substring(keyBegin);
if (firstSpace == REMOVE.length() && line.startsWith(REMOVE)) {
lruEntries.remove(key);
return;
}
} else {
key = line.substring(keyBegin, secondSpace);
}
Entry entry = lruEntries.get(key);
if (entry == null) {
entry = new Entry(key);
lruEntries.put(key, entry);
}
if (secondSpace != -1 && firstSpace == CLEAN.length() && line.startsWith(CLEAN)) {
String[] parts = line.substring(secondSpace + 1).split(" ");
entry.readable = true;
entry.currentEditor = null;
entry.setLengths(parts);
} else if (secondSpace == -1 && firstSpace == DIRTY.length() && line.startsWith(DIRTY)) {
entry.currentEditor = new Editor(entry);
} else if (secondSpace == -1 && firstSpace == READ.length() && line.startsWith(READ)) {
// This work was already done by calling lruEntries.get().
} else {
throw new IOException("unexpected journal line: " + line);
}
}
/**
* Computes the initial size and collects garbage as a part of opening the
* cache. Dirty entries are assumed to be inconsistent and will be deleted.
*/
private void processJournal() throws IOException {
deleteIfExists(journalFileTmp);
for (Iterator<Entry> i = lruEntries.values().iterator(); i.hasNext(); ) {
Entry entry = i.next();
if (entry.currentEditor == null) {
for (int t = 0; t < valueCount; t++) {
size += entry.lengths[t];
}
} else {
entry.currentEditor = null;
for (int t = 0; t < valueCount; t++) {
deleteIfExists(entry.getCleanFile(t));
deleteIfExists(entry.getDirtyFile(t));
}
i.remove();
}
}
}
/**
* Creates a new journal that omits redundant information. This replaces the
* current journal if it exists.
*/
private synchronized void rebuildJournal() throws IOException {
if (journalWriter != null) {
journalWriter.close();
}
Writer writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(journalFileTmp), Util.US_ASCII));
try {
writer.write(MAGIC);
writer.write("\n");
writer.write(VERSION_1);
writer.write("\n");
writer.write(Integer.toString(appVersion));
writer.write("\n");
writer.write(Integer.toString(valueCount));
writer.write("\n");
writer.write("\n");
for (Entry entry : lruEntries.values()) {
if (entry.currentEditor != null) {
writer.write(DIRTY + ' ' + entry.key + '\n');
} else {
writer.write(CLEAN + ' ' + entry.key + entry.getLengths() + '\n');
}
}
} finally {
writer.close();
}
if (journalFile.exists()) {
renameTo(journalFile, journalFileBackup, true);
}
renameTo(journalFileTmp, journalFile, false);
journalFileBackup.delete();
journalWriter = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(journalFile, true), Util.US_ASCII));
}
private static void deleteIfExists(File file) throws IOException {
if (file.exists() && !file.delete()) {
throw new IOException();
}
}
private static void renameTo(File from, File to, boolean deleteDestination) throws IOException {
if (deleteDestination) {
deleteIfExists(to);
}
if (!from.renameTo(to)) {
throw new IOException();
}
}
/**
* Returns a snapshot of the entry named {@code key}, or null if it doesn't
* exist is not currently readable. If a value is returned, it is moved to
* the head of the LRU queue.
*/
public synchronized Snapshot get(String key) throws IOException {
checkNotClosed();
validateKey(key);
Entry entry = lruEntries.get(key);
if (entry == null) {
return null;
}
if (!entry.readable) {
return null;
}
// Open all streams eagerly to guarantee that we see a single published
// snapshot. If we opened streams lazily then the streams could come
// from different edits.
InputStream[] ins = new InputStream[valueCount];
try {
for (int i = 0; i < valueCount; i++) {
ins[i] = new FileInputStream(entry.getCleanFile(i));
}
} catch (FileNotFoundException e) {
// A file must have been deleted manually!
for (int i = 0; i < valueCount; i++) {
if (ins[i] != null) {
Util.closeQuietly(ins[i]);
} else {
break;
}
}
return null;
}
redundantOpCount++;
journalWriter.append(READ + ' ' + key + '\n');
if (journalRebuildRequired()) {
executorService.submit(cleanupCallable);
}
return new Snapshot(key, entry.sequenceNumber, ins, entry.lengths);
}
/**
* Returns an editor for the entry named {@code key}, or null if another
* edit is in progress.
*/
public Editor edit(String key) throws IOException {
return edit(key, ANY_SEQUENCE_NUMBER);
}
private synchronized Editor edit(String key, long expectedSequenceNumber) throws IOException {
checkNotClosed();
validateKey(key);
Entry entry = lruEntries.get(key);
if (expectedSequenceNumber != ANY_SEQUENCE_NUMBER && (entry == null
|| entry.sequenceNumber != expectedSequenceNumber)) {
return null; // Snapshot is stale.
}
if (entry == null) {
entry = new Entry(key);
lruEntries.put(key, entry);
} else if (entry.currentEditor != null) {
return null; // Another edit is in progress.
}
Editor editor = new Editor(entry);
entry.currentEditor = editor;
// Flush the journal before creating files to prevent file leaks.
journalWriter.write(DIRTY + ' ' + key + '\n');
journalWriter.flush();
return editor;
}
/** Returns the directory where this cache stores its data. */
public File getDirectory() {
return directory;
}
/**
* Returns the maximum number of bytes that this cache should use to store
* its data.
*/
public synchronized long getMaxSize() {
return maxSize;
}
/**
* Changes the maximum number of bytes the cache can store and queues a job
* to trim the existing store, if necessary.
*/
public synchronized void setMaxSize(long maxSize) {
this.maxSize = maxSize;
executorService.submit(cleanupCallable);
}
/**
* Returns the number of bytes currently being used to store the values in
* this cache. This may be greater than the max size if a background
* deletion is pending.
*/
public synchronized long size() {
return size;
}
private synchronized void completeEdit(Editor editor, boolean success) throws IOException {
Entry entry = editor.entry;
if (entry.currentEditor != editor) {
throw new IllegalStateException();
}
// If this edit is creating the entry for the first time, every index must have a value.
if (success && !entry.readable) {
for (int i = 0; i < valueCount; i++) {
if (!editor.written[i]) {
editor.abort();
throw new IllegalStateException("Newly created entry didn't create value for index " + i);
}
if (!entry.getDirtyFile(i).exists()) {
editor.abort();
return;
}
}
}
for (int i = 0; i < valueCount; i++) {
File dirty = entry.getDirtyFile(i);
if (success) {
if (dirty.exists()) {
File clean = entry.getCleanFile(i);
dirty.renameTo(clean);
long oldLength = entry.lengths[i];
long newLength = clean.length();
entry.lengths[i] = newLength;
size = size - oldLength + newLength;
}
} else {
deleteIfExists(dirty);
}
}
redundantOpCount++;
entry.currentEditor = null;
if (entry.readable | success) {
entry.readable = true;
journalWriter.write(CLEAN + ' ' + entry.key + entry.getLengths() + '\n');
if (success) {
entry.sequenceNumber = nextSequenceNumber++;
}
} else {
lruEntries.remove(entry.key);
journalWriter.write(REMOVE + ' ' + entry.key + '\n');
}
journalWriter.flush();
if (size > maxSize || journalRebuildRequired()) {
executorService.submit(cleanupCallable);
}
}
/**
* We only rebuild the journal when it will halve the size of the journal
* and eliminate at least 2000 ops.
*/
private boolean journalRebuildRequired() {
final int redundantOpCompactThreshold = 2000;
return redundantOpCount >= redundantOpCompactThreshold //
&& redundantOpCount >= lruEntries.size();
}
/**
* Drops the entry for {@code key} if it exists and can be removed. Entries
* actively being edited cannot be removed.
*
* @return true if an entry was removed.
*/
public synchronized boolean remove(String key) throws IOException {
checkNotClosed();
validateKey(key);
Entry entry = lruEntries.get(key);
if (entry == null || entry.currentEditor != null) {
return false;
}
for (int i = 0; i < valueCount; i++) {
File file = entry.getCleanFile(i);
if (file.exists() && !file.delete()) {
throw new IOException("failed to delete " + file);
}
size -= entry.lengths[i];
entry.lengths[i] = 0;
}
redundantOpCount++;
journalWriter.append(REMOVE + ' ' + key + '\n');
lruEntries.remove(key);
if (journalRebuildRequired()) {
executorService.submit(cleanupCallable);
}
return true;
}
/** Returns true if this cache has been closed. */
public synchronized boolean isClosed() {
return journalWriter == null;
}
private void checkNotClosed() {
if (journalWriter == null) {
throw new IllegalStateException("cache is closed");
}
}
/** Force buffered operations to the filesystem. */
public synchronized void flush() throws IOException {
checkNotClosed();
trimToSize();
journalWriter.flush();
}
/** Closes this cache. Stored values will remain on the filesystem. */
public synchronized void close() throws IOException {
if (journalWriter == null) {
return; // Already closed.
}
for (Entry entry : new ArrayList<Entry>(lruEntries.values())) {
if (entry.currentEditor != null) {
entry.currentEditor.abort();
}
}
trimToSize();
journalWriter.close();
journalWriter = null;
}
private void trimToSize() throws IOException {
while (size > maxSize) {
Map.Entry<String, Entry> toEvict = lruEntries.entrySet().iterator().next();
remove(toEvict.getKey());
}
}
/**
* Closes the cache and deletes all of its stored values. This will delete
* all files in the cache directory including files that weren't created by
* the cache.
*/
public void delete() throws IOException {
close();
Util.deleteContents(directory);
}
private void validateKey(String key) {
Matcher matcher = LEGAL_KEY_PATTERN.matcher(key);
if (!matcher.matches()) {
throw new IllegalArgumentException("keys must match regex "
+ STRING_KEY_PATTERN + ": \"" + key + "\"");
}
}
private static String inputStreamToString(InputStream in) throws IOException {
return Util.readFully(new InputStreamReader(in, Util.UTF_8));
}
/** A snapshot of the values for an entry. */
public final class Snapshot implements Closeable {
private final String key;
private final long sequenceNumber;
private final InputStream[] ins;
private final long[] lengths;
private Snapshot(String key, long sequenceNumber, InputStream[] ins, long[] lengths) {
this.key = key;
this.sequenceNumber = sequenceNumber;
this.ins = ins;
this.lengths = lengths;
}
/**
* Returns an editor for this snapshot's entry, or null if either the
* entry has changed since this snapshot was created or if another edit
* is in progress.
*/
public Editor edit() throws IOException {
return DiskLruCache.this.edit(key, sequenceNumber);
}
/** Returns the unbuffered stream with the value for {@code index}. */
public InputStream getInputStream(int index) {
return ins[index];
}
/** Returns the string value for {@code index}. */
public String getString(int index) throws IOException {
return inputStreamToString(getInputStream(index));
}
/** Returns the byte length of the value for {@code index}. */
public long getLength(int index) {
return lengths[index];
}
public void close() {
for (InputStream in : ins) {
Util.closeQuietly(in);
}
}
}
private static final OutputStream NULL_OUTPUT_STREAM = new OutputStream() {
@Override
public void write(int b) throws IOException {
// Eat all writes silently. Nom nom.
}
};
/** Edits the values for an entry. */
public final class Editor {
private final Entry entry;
private final boolean[] written;
private boolean hasErrors;
private boolean committed;
private Editor(Entry entry) {
this.entry = entry;
this.written = (entry.readable) ? null : new boolean[valueCount];
}
/**
* Returns an unbuffered input stream to read the last committed value,
* or null if no value has been committed.
*/
public InputStream newInputStream(int index) throws IOException {
synchronized (DiskLruCache.this) {
if (entry.currentEditor != this) {
throw new IllegalStateException();
}
if (!entry.readable) {
return null;
}
try {
return new FileInputStream(entry.getCleanFile(index));
} catch (FileNotFoundException e) {
return null;
}
}
}
/**
* Returns the last committed value as a string, or null if no value
* has been committed.
*/
public String getString(int index) throws IOException {
InputStream in = newInputStream(index);
return in != null ? inputStreamToString(in) : null;
}
/**
* Returns a new unbuffered output stream to write the value at
* {@code index}. If the underlying output stream encounters errors
* when writing to the filesystem, this edit will be aborted when
* {@link #commit} is called. The returned output stream does not throw
* IOExceptions.
*/
public OutputStream newOutputStream(int index) throws IOException {
if (index < 0 || index >= valueCount) {
throw new IllegalArgumentException("Expected index " + index + " to "
+ "be greater than 0 and less than the maximum value count "
+ "of " + valueCount);
}
synchronized (DiskLruCache.this) {
if (entry.currentEditor != this) {
throw new IllegalStateException();
}
if (!entry.readable) {
written[index] = true;
}
File dirtyFile = entry.getDirtyFile(index);
FileOutputStream outputStream;
try {
outputStream = new FileOutputStream(dirtyFile);
} catch (FileNotFoundException e) {
// Attempt to recreate the cache directory.
directory.mkdirs();
try {
outputStream = new FileOutputStream(dirtyFile);
} catch (FileNotFoundException e2) {
// We are unable to recover. Silently eat the writes.
return NULL_OUTPUT_STREAM;
}
}
return new FaultHidingOutputStream(outputStream);
}
}
/** Sets the value at {@code index} to {@code value}. */
public void set(int index, String value) throws IOException {
Writer writer = null;
try {
writer = new OutputStreamWriter(newOutputStream(index), Util.UTF_8);
writer.write(value);
} finally {
Util.closeQuietly(writer);
}
}
/**
* Commits this edit so it is visible to readers. This releases the
* edit lock so another edit may be started on the same key.
*/
public void commit() throws IOException {
if (hasErrors) {
completeEdit(this, false);
remove(entry.key); // The previous entry is stale.
} else {
completeEdit(this, true);
}
committed = true;
}
/**
* Aborts this edit. This releases the edit lock so another edit may be
* started on the same key.
*/
public void abort() throws IOException {
completeEdit(this, false);
}
public void abortUnlessCommitted() {
if (!committed) {
try {
abort();
} catch (IOException ignored) {
}
}
}
private class FaultHidingOutputStream extends FilterOutputStream {
private FaultHidingOutputStream(OutputStream out) {
super(out);
}
@Override public void write(int oneByte) {
try {
out.write(oneByte);
} catch (IOException e) {
hasErrors = true;
}
}
@Override public void write(byte[] buffer, int offset, int length) {
try {
out.write(buffer, offset, length);
} catch (IOException e) {
hasErrors = true;
}
}
@Override public void close() {
try {
out.close();
} catch (IOException e) {
hasErrors = true;
}
}
@Override public void flush() {
try {
out.flush();
} catch (IOException e) {
hasErrors = true;
}
}
}
}
private final class Entry {
private final String key;
/** Lengths of this entry's files. */
private final long[] lengths;
/** True if this entry has ever been published. */
private boolean readable;
/** The ongoing edit or null if this entry is not being edited. */
private Editor currentEditor;
/** The sequence number of the most recently committed edit to this entry. */
private long sequenceNumber;
private Entry(String key) {
this.key = key;
this.lengths = new long[valueCount];
}
public String getLengths() throws IOException {
StringBuilder result = new StringBuilder();
for (long size : lengths) {
result.append(' ').append(size);
}
return result.toString();
}
/** Set lengths using decimal numbers like "10123". */
private void setLengths(String[] strings) throws IOException {
if (strings.length != valueCount) {
throw invalidLengths(strings);
}
try {
for (int i = 0; i < strings.length; i++) {
lengths[i] = Long.parseLong(strings[i]);
}
} catch (NumberFormatException e) {
throw invalidLengths(strings);
}
}
private IOException invalidLengths(String[] strings) throws IOException {
throw new IOException("unexpected journal line: " + java.util.Arrays.toString(strings));
}
public File getCleanFile(int i) {
return new File(directory, key + "." + i);
}
public File getDirtyFile(int i) {
return new File(directory, key + "." + i + ".tmp");
}
}
}
@@ -1,113 +0,0 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.cache;
import android.app.ActivityManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.annotation.NonNull;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
public class ImageCache extends AnyCache<Bitmap>{
private static final String TAG = "ImageCache";
/**
* Default memory cache size as a percent of device memory class
*/
private static final float MEM_CACHE_DIVIDER = 0.25f;
/**
* Compression settings when writing images to disk cache
*/
private static final Bitmap.CompressFormat COMPRESS_FORMAT = Bitmap.CompressFormat.JPEG;
/**
* Image compression quality
*/
private static final int COMPRESS_QUALITY = 98;
private static ImageCache sImageCache;
public static @NonNull ImageCache getImageCache(@NonNull Context context) {
if (sImageCache == null) {
final ActivityManager activityManager = (ActivityManager)context
.getSystemService(Context.ACTIVITY_SERVICE);
final int memoryCacheMax = Math.round(MEM_CACHE_DIVIDER * activityManager.getMemoryClass()
* 1024 * 1024);
AnyCacheParams params = new AnyCacheParams();
params.hasMemoryCache = true;
params.memoryCacheMaxSize = memoryCacheMax;
params.hasDiskCache = true;
params.diskCacheDir = getDiskCacheDir(context, TAG);
params.diskCacheMaxSize = 20 * 1024 * 1024;
sImageCache = new ImageCache(params);
}
return sImageCache;
}
public ImageCache(AnyCacheParams params) {
super(params);
}
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getByteCount();
}
@Override
protected Bitmap read(InputStream is) {
return BitmapFactory.decodeStream(is);
}
@Override
protected boolean write(OutputStream os, Bitmap value) {
return value.compress(COMPRESS_FORMAT, COMPRESS_QUALITY, os);
}
/**
* Get the external app cache directory
*
* @param context The {@link Context} to use
* @return The external cache directory
*/
private static File getExternalCacheDir(final Context context) {
return context.getExternalCacheDir();
}
/**
* Get a usable cache directory (external if available, internal otherwise)
*
* @param context The {@link Context} to use
* @param uniqueName A unique directory name to append to the cache
* directory
* @return The cache directory
*/
private static File getDiskCacheDir(final Context context, final String uniqueName) {
// getExternalCacheDir(context) returns null if external storage is not ready
final String cachePath = getExternalCacheDir(context) != null
? getExternalCacheDir(context).getPath()
: context.getCacheDir().getPath();
return new File(cachePath, uniqueName);
}
}
@@ -1,196 +0,0 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.cache;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
/**
* Buffers input from an {@link InputStream} for reading lines.
*
* <p>This class is used for buffered reading of lines. For purposes of this class, a line ends
* with "\n" or "\r\n". End of input is reported by throwing {@code EOFException}. Unterminated
* line at end of input is invalid and will be ignored, the caller may use {@code
* hasUnterminatedLine()} to detect it after catching the {@code EOFException}.
*
* <p>This class is intended for reading input that strictly consists of lines, such as line-based
* cache entries or cache journal. Unlike the {@link java.io.BufferedReader} which in conjunction
* with {@link java.io.InputStreamReader} provides similar functionality, this class uses different
* end-of-input reporting and a more restrictive definition of a line.
*
* <p>This class supports only charsets that encode '\r' and '\n' as a single byte with value 13
* and 10, respectively, and the representation of no other character contains these values.
* We currently check in constructor that the charset is one of US-ASCII, UTF-8 and ISO-8859-1.
* The default charset is US_ASCII.
*/
class StrictLineReader implements Closeable {
private static final byte CR = (byte) '\r';
private static final byte LF = (byte) '\n';
private final InputStream in;
private final Charset charset;
/*
* Buffered data is stored in {@code buf}. As long as no exception occurs, 0 <= pos <= end
* and the data in the range [pos, end) is buffered for reading. At end of input, if there is
* an unterminated line, we set end == -1, otherwise end == pos. If the underlying
* {@code InputStream} throws an {@code IOException}, end may remain as either pos or -1.
*/
private byte[] buf;
private int pos;
private int end;
/**
* Constructs a new {@code LineReader} with the specified charset and the default capacity.
*
* @param in the {@code InputStream} to read data from.
* @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
* supported.
* @throws NullPointerException if {@code in} or {@code charset} is null.
* @throws IllegalArgumentException if the specified charset is not supported.
*/
public StrictLineReader(InputStream in, Charset charset) {
this(in, 8192, charset);
}
/**
* Constructs a new {@code LineReader} with the specified capacity and charset.
*
* @param in the {@code InputStream} to read data from.
* @param capacity the capacity of the buffer.
* @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
* supported.
* @throws NullPointerException if {@code in} or {@code charset} is null.
* @throws IllegalArgumentException if {@code capacity} is negative or zero
* or the specified charset is not supported.
*/
public StrictLineReader(InputStream in, int capacity, Charset charset) {
if (in == null || charset == null) {
throw new NullPointerException();
}
if (capacity < 0) {
throw new IllegalArgumentException("capacity <= 0");
}
if (!(charset.equals(Util.US_ASCII))) {
throw new IllegalArgumentException("Unsupported encoding");
}
this.in = in;
this.charset = charset;
buf = new byte[capacity];
}
/**
* Closes the reader by closing the underlying {@code InputStream} and
* marking this reader as closed.
*
* @throws IOException for errors when closing the underlying {@code InputStream}.
*/
public void close() throws IOException {
synchronized (in) {
if (buf != null) {
buf = null;
in.close();
}
}
}
/**
* Reads the next line. A line ends with {@code "\n"} or {@code "\r\n"},
* this end of line marker is not included in the result.
*
* @return the next line from the input.
* @throws IOException for underlying {@code InputStream} errors.
* @throws EOFException for the end of source stream.
*/
public String readLine() throws IOException {
synchronized (in) {
if (buf == null) {
throw new IOException("LineReader is closed");
}
// Read more data if we are at the end of the buffered data.
// Though it's an error to read after an exception, we will let {@code fillBuf()}
// throw again if that happens; thus we need to handle end == -1 as well as end == pos.
if (pos >= end) {
fillBuf();
}
// Try to find LF in the buffered data and return the line if successful.
for (int i = pos; i != end; ++i) {
if (buf[i] == LF) {
int lineEnd = (i != pos && buf[i - 1] == CR) ? i - 1 : i;
String res = new String(buf, pos, lineEnd - pos, charset.name());
pos = i + 1;
return res;
}
}
// Let's anticipate up to 80 characters on top of those already read.
ByteArrayOutputStream out = new ByteArrayOutputStream(end - pos + 80) {
@Override
public String toString() {
int length = (count > 0 && buf[count - 1] == CR) ? count - 1 : count;
try {
return new String(buf, 0, length, charset.name());
} catch (UnsupportedEncodingException e) {
throw new AssertionError(e); // Since we control the charset this will never happen.
}
}
};
while (true) {
out.write(buf, pos, end - pos);
// Mark unterminated line in case fillBuf throws EOFException or IOException.
end = -1;
fillBuf();
// Try to find LF in the buffered data and return the line if successful.
for (int i = pos; i != end; ++i) {
if (buf[i] == LF) {
if (i != pos) {
out.write(buf, pos, i - pos);
}
pos = i + 1;
return out.toString();
}
}
}
}
}
public boolean hasUnterminatedLine() {
return end == -1;
}
/**
* Reads new input data into the buffer. Call only with pos == end or end == -1,
* depending on the desired outcome if the function throws.
*/
private void fillBuf() throws IOException {
int result = in.read(buf, 0, buf.length);
if (result == -1) {
throw new EOFException();
}
pos = 0;
end = result;
}
}
-77
View File
@@ -1,77 +0,0 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.cache;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.io.StringWriter;
import java.nio.charset.Charset;
/** Junk drawer of utility methods. */
final class Util {
static final Charset US_ASCII = Charset.forName("US-ASCII");
static final Charset UTF_8 = Charset.forName("UTF-8");
private Util() {
}
static String readFully(Reader reader) throws IOException {
try {
StringWriter writer = new StringWriter();
char[] buffer = new char[1024];
int count;
while ((count = reader.read(buffer)) != -1) {
writer.write(buffer, 0, count);
}
return writer.toString();
} finally {
reader.close();
}
}
/**
* Deletes the contents of {@code dir}. Throws an IOException if any file
* could not be deleted, or if {@code dir} is not a readable directory.
*/
static void deleteContents(File dir) throws IOException {
File[] files = dir.listFiles();
if (files == null) {
throw new IOException("not a readable directory: " + dir);
}
for (File file : files) {
if (file.isDirectory()) {
deleteContents(file);
}
if (!file.delete()) {
throw new IOException("failed to delete file: " + file);
}
}
}
static void closeQuietly(/*Auto*/Closeable closeable) {
if (closeable != null) {
try {
closeable.close();
} catch (RuntimeException rethrown) {
throw rethrown;
} catch (Exception ignored) {
}
}
}
}
@@ -1,187 +0,0 @@
/*
* Copyright (C) 2014 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.drawable;
import java.util.Arrays;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import com.hippo.ehviewer.util.MathUtils;
import com.hippo.ehviewer.util.Ui;
public class FreeMaterialDrawable extends Drawable {
private static final String TAG = FreeMaterialDrawable.class.getSimpleName();
private static final int MAX_SPRITE_NUM = 6;
private static final int SPRITE_SHAPE_RECTANGLE = 0;
private static final int SPRITE_SHAPE_ROUND = 1;
private static final int SPRITE_SHAPE_MAX = 2;
private boolean mKeepTop;
private int mBgIndex;
private int mBgColor;
private final Paint mPaint;
private int mSpriteNum;
private final Sprite[] mSpriteArray = new Sprite[MAX_SPRITE_NUM];
private static final int[] sColorArray = new int[] {
0xff9c27b0, 0xff673ab7,
0xff3f51b5, 0xff2196f3, 0xff03a9f4, 0xff00bcd4,
0xff4caf50
};
public FreeMaterialDrawable () {
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setShadowLayer(Ui.dp2pix(3), 0, 0, 0x8a000000);
}
public FreeMaterialDrawable setBgIndex(int bgIndex) {
mBgIndex = bgIndex;
return this;
}
public FreeMaterialDrawable setKeepTop(boolean keepTop) {
mKeepTop = keepTop;
return this;
}
private int getColor(int[] copyOfColorArray) {
int index = MathUtils.random(0, copyOfColorArray.length);
int color = copyOfColorArray[index];
while (color == -1)
color = copyOfColorArray[++index < copyOfColorArray.length ? index : (index = 0)];
copyOfColorArray[index] = -1;
return color;
}
@Override
protected void onBoundsChange(Rect bounds) {
int w = bounds.width();
int h = bounds.height();
Sprite s;
int[] copyOfColorArray = Arrays.copyOf(sColorArray, sColorArray.length);
if (mBgIndex >= 0) {
mBgColor = copyOfColorArray[mBgIndex];
copyOfColorArray[mBgIndex] = -1;
} else {
mBgColor = getColor(copyOfColorArray);
}
mSpriteNum = MathUtils.random(4, MAX_SPRITE_NUM + 1);
for (int i = 0; i < mSpriteNum; i++) {
switch (SPRITE_SHAPE_ROUND) {//MathUtils.random(0, SPRITE_SHAPE_MAX)) {
case SPRITE_SHAPE_RECTANGLE:
s = new Rectangle(w, h, getColor(copyOfColorArray));
break;
default:
case SPRITE_SHAPE_ROUND:
s = new Round(w, h, getColor(copyOfColorArray));
break;
}
mSpriteArray[i] = s;
}
}
@Override
public void draw(Canvas canvas) {
canvas.drawColor(mBgColor);
for (int i = 0; i < mSpriteNum; i++)
mSpriteArray[i].draw(canvas, mPaint);
}
@Override
public void setAlpha(int alpha) {
// Empty
}
@Override
public void setColorFilter(ColorFilter cf) {
// Empty
}
@Override
public int getOpacity() {
return PixelFormat.OPAQUE;
}
private abstract class Sprite {
private final int mColor;
public Sprite(int w, int h, int color) {
mColor = color;
}
public void draw(Canvas canvas, Paint paint) {
paint.setColor(mColor);
doDraw(canvas, paint);
}
public abstract void doDraw(Canvas canvas, Paint paint);
}
private class Rectangle extends Sprite {
private final int left;
private final int top;
private final int right;
private final int bottom;
public Rectangle(int w, int h, int color) {
super(w, h, color);
int width = MathUtils.random(w / 4, w / 2);
int height = MathUtils.random(h / 4, h / 2);
left = MathUtils.random(w - width / 2);
top = MathUtils.random(h - height / 2);
right = left + width;
bottom = top + height;
}
@Override
public void doDraw(Canvas canvas, Paint paint) {
canvas.drawRect(left, top, right, bottom, paint);
}
}
private class Round extends Sprite {
int mX, mY, mRadius;
public Round(int w, int h, int color) {
super(w, h, color);
int t = (w + h) / 2;
mRadius = MathUtils.random(t / 8, t / 4);
mX = MathUtils.random(w);
mY = MathUtils.random(mKeepTop ? mRadius + 10 : 0, h);
}
@Override
public void doDraw(Canvas canvas, Paint paint) {
canvas.drawCircle(mX, mY, mRadius, paint);
}
}
}
@@ -1,695 +0,0 @@
/*
* Copyright (C) 2014 Balys Valentukevicius
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.drawable;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.PixelFormat;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Property;
import android.util.TypedValue;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
public class MaterialIndicatorDrawable extends Drawable implements Animatable {
private static final String STATE_KEY = "material_menu_icon_state";
public enum IconState {
BURGER, ARROW
}
public enum AnimationState {
BURGER_ARROW;
public IconState getFirstState() {
switch (this) {
case BURGER_ARROW:
return IconState.BURGER;
default:
return null;
}
}
public IconState getSecondState() {
switch (this) {
case BURGER_ARROW:
return IconState.ARROW;
default:
return null;
}
}
}
public enum Stroke {
/**
* 3 dip
*/
REGULAR(3),
/**
* 2 dip
*/
THIN(2),
/**
* 1 dip
*/
EXTRA_THIN(1);
private final int strokeWidth;
Stroke(int strokeWidth) {
this.strokeWidth = strokeWidth;
}
protected static Stroke valueOf(int strokeWidth) {
switch (strokeWidth) {
case 3:
return REGULAR;
case 2:
return THIN;
case 1:
return EXTRA_THIN;
default:
return THIN;
}
}
}
public static final int DEFAULT_COLOR = Color.WHITE;
public static final int DEFAULT_SCALE = 1;
public static final int DEFAULT_TRANSFORM_DURATION = 800;
public static final int DEFAULT_PRESSED_DURATION = 400;
private static final int BASE_DRAWABLE_WIDTH = 40;
private static final int BASE_DRAWABLE_HEIGHT = 40;
private static final int BASE_ICON_WIDTH = 20;
private static final int BASE_CIRCLE_RADIUS = 18;
private static final float ARROW_MID_LINE_ANGLE = 180;
private static final float ARROW_TOP_LINE_ANGLE = 135;
private static final float ARROW_BOT_LINE_ANGLE = 225;
private static final float TRANSFORMATION_START = 0;
private static final float TRANSFORMATION_MID = 1.0f;
private static final float TRANSFORMATION_END = 2.0f;
private static final int DEFAULT_CIRCLE_ALPHA = 200;
private final float diph;
private final float dip1;
private final float dip2;
private final float dip3;
private final float dip4;
private final int width;
private final int height;
private final float strokeWidth;
private final float iconWidth;
private final float topPadding;
private final float sidePadding;
private final float circleRadius;
private final Stroke stroke;
private final Object lock = new Object();
private final Paint gridPaint = new Paint();
private final Paint iconPaint = new Paint();
private final Paint circlePaint = new Paint();
private float transformationValue = 0f;
private float pressedProgressValue = 0f;
private boolean transformationRunning = false;
private IconState currentIconState = IconState.BURGER;
private AnimationState animationState = AnimationState.BURGER_ARROW;
private IconState animatingIconState;
private boolean drawTouchCircle;
private boolean neverDrawTouch;
private boolean rtlEnabled;
private ObjectAnimator transformation;
private ObjectAnimator pressedCircle;
private MaterialMenuState materialMenuState;
public MaterialIndicatorDrawable(Context context, int color, Stroke stroke) {
this(context, color, stroke, DEFAULT_SCALE, DEFAULT_TRANSFORM_DURATION, DEFAULT_PRESSED_DURATION);
}
public MaterialIndicatorDrawable(Context context, int color, Stroke stroke, int transformDuration, int pressedDuration) {
this(context, color, stroke, DEFAULT_SCALE, transformDuration, pressedDuration);
}
public MaterialIndicatorDrawable(Context context, int color, Stroke stroke, int scale, int transformDuration, int pressedDuration) {
Resources resources = context.getResources();
// convert each separately due to various densities
this.dip1 = dpToPx(resources, 1) * scale;
this.dip2 = dpToPx(resources, 2) * scale;
this.dip3 = dpToPx(resources, 3) * scale;
this.dip4 = dpToPx(resources, 4) * scale;
this.diph = dip1 / 2;
this.stroke = stroke;
this.width = (int) (dpToPx(resources, BASE_DRAWABLE_WIDTH) * scale);
this.height = (int) (dpToPx(resources, BASE_DRAWABLE_HEIGHT) * scale);
this.iconWidth = dpToPx(resources, BASE_ICON_WIDTH) * scale;
this.circleRadius = dpToPx(resources, BASE_CIRCLE_RADIUS) * scale;
this.strokeWidth = dpToPx(resources, stroke.strokeWidth) * scale;
this.sidePadding = (width - iconWidth) / 2;
this.topPadding = (height - 5 * dip3) / 2;
initPaint(color);
initAnimations(transformDuration, pressedDuration);
materialMenuState = new MaterialMenuState();
}
private MaterialIndicatorDrawable(int color, Stroke stroke, long transformDuration, long pressedDuration,
int width, int height, float iconWidth, float circleRadius, float strokeWidth, float dip1
) {
this.dip1 = dip1;
this.dip2 = dip1 * 2;
this.dip3 = dip1 * 3;
this.dip4 = dip1 * 4;
this.diph = dip1 / 2;
this.stroke = stroke;
this.width = width;
this.height = height;
this.iconWidth = iconWidth;
this.circleRadius = circleRadius;
this.strokeWidth = strokeWidth;
this.sidePadding = (width - iconWidth) / 2;
this.topPadding = (height - 5 * dip3) / 2;
initPaint(color);
initAnimations((int) transformDuration, (int) pressedDuration);
materialMenuState = new MaterialMenuState();
}
private void initPaint(int color) {
gridPaint.setAntiAlias(false);
gridPaint.setColor(Color.GREEN);
gridPaint.setStrokeWidth(1);
iconPaint.setAntiAlias(true);
iconPaint.setStyle(Style.STROKE);
iconPaint.setStrokeWidth(strokeWidth);
iconPaint.setColor(color);
circlePaint.setAntiAlias(true);
circlePaint.setStyle(Style.FILL);
circlePaint.setColor(color);
circlePaint.setAlpha(DEFAULT_CIRCLE_ALPHA);
setBounds(0, 0, width, height);
}
/*
* Drawing
*/
@Override public void draw(Canvas canvas) {
final float ratio = transformationValue <= 1 ? transformationValue : 2 - transformationValue;
if (rtlEnabled) {
canvas.save();
canvas.scale(-1, 1, 0, 0);
canvas.translate(-getIntrinsicWidth(), 0);
}
drawTopLine(canvas, ratio);
drawMiddleLine(canvas, ratio);
drawBottomLine(canvas, ratio);
if (rtlEnabled) {
canvas.restore();
}
if (drawTouchCircle) drawTouchCircle(canvas);
}
private void drawTouchCircle(Canvas canvas) {
canvas.restore();
canvas.drawCircle(width / 2, height / 2, pressedProgressValue, circlePaint);
}
private void drawMiddleLine(Canvas canvas, float ratio) {
canvas.restore();
canvas.save();
float rotation = 0;
float pivotX = width / 2;
float pivotY = width / 2;
float startX = sidePadding;
float startY = topPadding + dip3 / 2 * 5;
float stopX = width - sidePadding;
float stopY = topPadding + dip3 / 2 * 5;
int alpha = 255;
switch (animationState) {
case BURGER_ARROW:
// rotate by 180
if (isMorphingForward()) {
rotation = ratio * ARROW_MID_LINE_ANGLE;
} else {
rotation = ARROW_MID_LINE_ANGLE + (1 - ratio) * ARROW_MID_LINE_ANGLE;
}
// shorten one end
stopX -= ratio * resolveStrokeModifier(ratio) / 2;
break;
}
iconPaint.setAlpha(alpha);
canvas.rotate(rotation, pivotX, pivotY);
canvas.drawLine(startX, startY, stopX, stopY, iconPaint);
iconPaint.setAlpha(255);
}
private void drawTopLine(Canvas canvas, float ratio) {
canvas.save();
float rotation = 0, pivotX = 0, pivotY = 0;
float rotation2 = 0;
// pivot at center of line
float pivotX2 = width / 2 + dip3 / 2;
float pivotY2 = topPadding + dip2;
float startX = sidePadding;
float startY = topPadding + dip2;
float stopX = width - sidePadding;
float stopY = topPadding + dip2;
int alpha = 255;
switch (animationState) {
case BURGER_ARROW:
if (isMorphingForward()) {
// rotate until required angle
rotation = ratio * ARROW_BOT_LINE_ANGLE;
} else {
// rotate back to start doing a 360
rotation = ARROW_BOT_LINE_ANGLE + (1 - ratio) * ARROW_TOP_LINE_ANGLE;
}
// rotate by middle
pivotX = width / 2;
pivotY = height / 2;
// shorten both ends
stopX -= resolveStrokeModifier(ratio);
startX += dip3 * ratio;
break;
}
iconPaint.setAlpha(alpha);
canvas.rotate(rotation, pivotX, pivotY);
canvas.rotate(rotation2, pivotX2, pivotY2);
canvas.drawLine(startX, startY, stopX, stopY, iconPaint);
iconPaint.setAlpha(255);
}
private void drawBottomLine(Canvas canvas, float ratio) {
canvas.restore();
canvas.save();
float rotation = 0, pivotX = 0, pivotY = 0;
float rotation2 = 0;
// pivot at center of line
float pivotX2 = width / 2 + dip3 / 2;
float pivotY2 = height - topPadding - dip2;
float startX = sidePadding;
float startY = height - topPadding - dip2;
float stopX = width - sidePadding;
float stopY = height - topPadding - dip2;
switch (animationState) {
case BURGER_ARROW:
if (isMorphingForward()) {
// rotate to required angle
rotation = ARROW_TOP_LINE_ANGLE * ratio;
} else {
// rotate back to start doing a 360
rotation = ARROW_TOP_LINE_ANGLE + (1 - ratio) * ARROW_BOT_LINE_ANGLE;
}
// pivot center of canvas
pivotX = width / 2;
pivotY = height / 2;
// shorten both ends
stopX = width - sidePadding - resolveStrokeModifier(ratio);
startX = sidePadding + dip3 * ratio;
break;
}
canvas.rotate(rotation, pivotX, pivotY);
canvas.rotate(rotation2, pivotX2, pivotY2);
canvas.drawLine(startX, startY, stopX, stopY, iconPaint);
}
private boolean isMorphingForward() {
return transformationValue <= TRANSFORMATION_MID;
}
private float resolveStrokeModifier(float ratio) {
switch (stroke) {
case REGULAR:
return ratio * dip3;
case THIN:
return ratio * (dip3 + diph);
case EXTRA_THIN:
return ratio * dip4;
}
return 0;
}
@Override public void setAlpha(int alpha) {
iconPaint.setAlpha(alpha);
}
@Override public void setColorFilter(ColorFilter cf) {
iconPaint.setColorFilter(cf);
}
@Override public int getOpacity() {
return PixelFormat.TRANSPARENT;
}
/*
* Accessor methods
*/
public void setColor(int color) {
iconPaint.setColor(color);
circlePaint.setColor(color);
invalidateSelf();
}
public void setTransformationDuration(int duration) {
transformation.setDuration(duration);
}
public void setPressedDuration(int duration) {
pressedCircle.setDuration(duration);
}
public void setInterpolator(Interpolator interpolator) {
transformation.setInterpolator(interpolator);
}
public void setNeverDrawTouch(boolean neverDrawTouch) {
this.neverDrawTouch = neverDrawTouch;
}
public void setIconState(IconState iconState) {
synchronized (lock) {
if (transformationRunning) {
transformation.cancel();
transformationRunning = false;
}
if (currentIconState == iconState) return;
switch (iconState) {
case BURGER:
animationState = AnimationState.BURGER_ARROW;
transformationValue = TRANSFORMATION_START;
break;
case ARROW:
animationState = AnimationState.BURGER_ARROW;
transformationValue = TRANSFORMATION_MID;
break;
}
currentIconState = iconState;
invalidateSelf();
}
}
public void animateIconState(IconState state, boolean drawTouch) {
synchronized (lock) {
if (transformationRunning) {
transformation.end();
pressedCircle.end();
}
drawTouchCircle = drawTouch;
animatingIconState = state;
start();
}
}
public IconState setTransformationOffset(AnimationState animationState, float offset) {
if (offset < TRANSFORMATION_START || offset > TRANSFORMATION_END) {
throw new IllegalArgumentException(
String.format("Value must be between %s and %s", TRANSFORMATION_START, TRANSFORMATION_END)
);
}
this.animationState = animationState;
final boolean isFirstIcon = offset < TRANSFORMATION_MID || offset == TRANSFORMATION_END;
currentIconState = isFirstIcon ? animationState.getFirstState() : animationState.getSecondState();
animatingIconState = isFirstIcon ? animationState.getSecondState() : animationState.getFirstState();
setTransformationValue(offset);
return currentIconState;
}
public void setRTLEnabled(boolean rtlEnabled) {
this.rtlEnabled = rtlEnabled;
invalidateSelf();
}
public IconState getIconState() {
return currentIconState;
}
/*
* Animations
*/
private final Property<MaterialIndicatorDrawable, Float> transformationProperty
= new Property<MaterialIndicatorDrawable, Float>(Float.class, "transformation") {
@Override
public Float get(MaterialIndicatorDrawable object) {
return object.getTransformationValue();
}
@Override
public void set(MaterialIndicatorDrawable object, Float value) {
object.setTransformationValue(value);
}
};
private final Property<MaterialIndicatorDrawable, Float> pressedProgressProperty
= new Property<MaterialIndicatorDrawable, Float>(Float.class, "pressedProgress") {
@Override
public Float get(MaterialIndicatorDrawable object) {
return object.getPressedProgress();
}
@Override
public void set(MaterialIndicatorDrawable object, Float value) {
object.setPressedProgress(value);
}
};
public Float getTransformationValue() {
return transformationValue;
}
public void setTransformationValue(Float value) {
this.transformationValue = value;
invalidateSelf();
}
public Float getPressedProgress() {
return pressedProgressValue;
}
public void setPressedProgress(Float value) {
this.pressedProgressValue = value;
circlePaint.setAlpha((int) (DEFAULT_CIRCLE_ALPHA * (1 - value / (circleRadius * 1.22f))));
invalidateSelf();
}
private void initAnimations(int transformDuration, int pressedDuration) {
transformation = ObjectAnimator.ofFloat(this, transformationProperty, 0);
transformation.setInterpolator(new DecelerateInterpolator(3));
transformation.setDuration(transformDuration);
transformation.addListener(new AnimatorListenerAdapter() {
@Override public void onAnimationEnd(Animator animation) {
transformationRunning = false;
setIconState(animatingIconState);
}
});
pressedCircle = ObjectAnimator.ofFloat(this, pressedProgressProperty, 0, 0);
pressedCircle.setDuration(pressedDuration);
pressedCircle.setInterpolator(new DecelerateInterpolator());
pressedCircle.addListener(new AnimatorListenerAdapter() {
@Override public void onAnimationEnd(Animator animation) {
pressedProgressValue = 0;
}
@Override public void onAnimationCancel(Animator animation) {
pressedProgressValue = 0;
}
});
}
private boolean resolveTransformation() {
boolean isCurrentBurger = currentIconState == IconState.BURGER;
boolean isCurrentArrow = currentIconState == IconState.ARROW;
boolean isAnimatingBurger = animatingIconState == IconState.BURGER;
boolean isAnimatingArrow = animatingIconState == IconState.ARROW;
if ((isCurrentBurger && isAnimatingArrow) || (isCurrentArrow && isAnimatingBurger)) {
animationState = AnimationState.BURGER_ARROW;
return isCurrentBurger;
}
throw new IllegalStateException(
String.format("Animating from %s to %s is not supported", currentIconState, animatingIconState)
);
}
@Override public void start() {
if (transformationRunning || animatingIconState == null || animatingIconState == currentIconState) return;
transformationRunning = true;
final boolean direction = resolveTransformation();
transformation.setFloatValues(
direction ? TRANSFORMATION_START : TRANSFORMATION_MID,
direction ? TRANSFORMATION_MID : TRANSFORMATION_END
);
transformation.start();
if (pressedCircle.isRunning()) {
pressedCircle.cancel();
}
if (drawTouchCircle && !neverDrawTouch) {
pressedCircle.setFloatValues(0, circleRadius * 1.22f);
pressedCircle.start();
}
invalidateSelf();
}
@Override public void stop() {
if (isRunning() && transformation.isRunning()) {
transformation.end();
} else {
transformationRunning = false;
invalidateSelf();
}
}
@Override public boolean isRunning() {
return transformationRunning;
}
@Override
public int getIntrinsicWidth() {
return width;
}
@Override
public int getIntrinsicHeight() {
return height;
}
@Override
public ConstantState getConstantState() {
materialMenuState.changingConfigurations = getChangingConfigurations();
return materialMenuState;
}
@Override
public Drawable mutate() {
materialMenuState = new MaterialMenuState();
return this;
}
/**
* Call from {@link android.app.Activity#onSaveInstanceState(android.os.Bundle)} to store current icon state
*
* @param outState outState
*/
public void onSaveInstanceState(Bundle outState) {
outState.putString(STATE_KEY, currentIconState.name());
}
/**
* Call from {@link android.app.Activity#onPostCreate(android.os.Bundle)} to restore icon state
*
* @param state state
*/
public void syncState(Bundle state) {
if (state != null) {
String iconStateName = state.getString(STATE_KEY);
if (iconStateName == null) {
iconStateName = MaterialIndicatorDrawable.IconState.BURGER.name();
}
setIconState(MaterialIndicatorDrawable.IconState.valueOf(iconStateName));
}
}
private final class MaterialMenuState extends ConstantState {
private int changingConfigurations;
private MaterialMenuState() {
}
@Override
public Drawable newDrawable() {
MaterialIndicatorDrawable drawable = new MaterialIndicatorDrawable(
circlePaint.getColor(), stroke, transformation.getDuration(),
pressedCircle.getDuration(), width, height, iconWidth, circleRadius, strokeWidth, dip1
);
drawable.setIconState(animatingIconState != null ? animatingIconState : currentIconState);
drawable.setRTLEnabled(rtlEnabled);
return drawable;
}
@Override
public int getChangingConfigurations() {
return changingConfigurations;
}
}
static float dpToPx(Resources resources, float dp) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics());
}
}
@@ -1,87 +0,0 @@
/*
* Copyright (C) 2014 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.effect;
import android.animation.ValueAnimator;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.drawable.Drawable;
public class DrawableTransition {
public static void transit(final Drawable drawable, boolean fromDark, long duration) {
final AlphaSatColorMatrixEvaluator evaluator = new AlphaSatColorMatrixEvaluator(fromDark);
evaluator.setFraction(0.0f);
drawable.setColorFilter(new ColorMatrixColorFilter(evaluator.getColorMatrix()));
ValueAnimator animator = ValueAnimator.ofFloat(0.0f, 1.0f);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float f = (Float) animation.getAnimatedValue();
evaluator.setFraction(f);
drawable.setColorFilter(new ColorMatrixColorFilter(evaluator.getColorMatrix()));
}
});
animator.setDuration(duration);
animator.start();
}
// From rnr.tests.imageloadingpattern.AlphaSatColorMatrixEvaluator
// with modification
private static class AlphaSatColorMatrixEvaluator {
private final ColorMatrix colorMatrix;
private final float[] elements = new float[20];
private final boolean mFromDark;
public AlphaSatColorMatrixEvaluator(boolean fromDark) {
colorMatrix = new ColorMatrix ();
mFromDark = fromDark;
}
public ColorMatrix getColorMatrix() {
return colorMatrix;
}
public void setFraction(float fraction) {
// There are 4 phases so we multiply fraction by that amount
float phase = fraction * 4;
// Compute the alpha change over period [0, 2]
float alpha = Math.min(phase, 2.0f) / 2.0f;
elements [19] = Math.round(alpha * 255);
// We substract to make the picture look darker, it will automatically clamp
// This is spread over period [0, 3]
final int MaxBlacker = 50;
float blackening = Math.round((1 - Math.min(phase, 3.0f) / 3.0f) * MaxBlacker);
elements [4] = elements [9] = elements [14] = mFromDark ? -blackening : blackening;
// Finally we desaturate over [0, 4], taken from ColorMatrix.SetSaturation
float invSat = 1 - Math.max(0.2f, fraction);
float R = 0.213f * invSat;
float G = 0.715f * invSat;
float B = 0.072f * invSat;
elements[0] = R + fraction; elements[1] = G; elements[2] = B;
elements[5] = R; elements[6] = G + fraction; elements[7] = B;
elements[10] = R; elements[11] = G; elements[12] = B + fraction;
colorMatrix.set(elements);
}
}
}
@@ -1,423 +0,0 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.effect.ripple;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.os.Build;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import com.hippo.ehviewer.util.MathUtils;
/**
* Draws a Material ripple.
*/
class Ripple {
@SuppressWarnings("unused")
private static final String TAG = Ripple.class.getSimpleName();
private static final Interpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
private static final Interpolator DECEL_INTERPOLATOR = new LogInterpolator();
private static final float GLOBAL_SPEED = 1.0f;
private static final float WAVE_TOUCH_DOWN_ACCELERATION = 1024.0f * GLOBAL_SPEED;
private static final float WAVE_TOUCH_UP_ACCELERATION = 3400.0f * GLOBAL_SPEED;
private static final float WAVE_OPACITY_DECAY_VELOCITY = 3.0f / GLOBAL_SPEED;
private static final long RIPPLE_ENTER_DELAY = 80;
private final RippleOwner mOwner;
/** Bounds used for computing max radius. */
private final Rect mBounds;
/** Full-opacity color for drawing this ripple. */
private int mColorOpaque;
/** Maximum ripple radius. */
private float mOuterRadius;
/** Screen density used to adjust pixel-based velocities. */
private float mDensity;
private float mStartingX;
private float mStartingY;
private float mClampedStartingX;
private float mClampedStartingY;
// Software animators.
private ObjectAnimator mAnimRadius;
private ObjectAnimator mAnimOpacity;
private ObjectAnimator mAnimX;
private ObjectAnimator mAnimY;
// Software rendering properties.
private float mOpacity = 1;
private float mOuterX;
private float mOuterY;
// Values used to tween between the start and end positions.
private float mTweenRadius = 0;
private float mTweenX = 0;
private float mTweenY = 0;
/** Whether we have an explicit maximum radius. */
private boolean mHasMaxRadius;
/** Whether we were canceled externally and should avoid self-removal. */
private boolean mCanceled;
/**
* Creates a new ripple.
*/
public Ripple(RippleOwner owner, Rect bounds, float startingX, float startingY) {
mOwner = owner;
mBounds = bounds;
mStartingX = startingX;
mStartingY = startingY;
}
public void setup(int maxRadius, int color, float density) {
mColorOpaque = color | 0xFF000000;
mOpacity = Color.alpha(color) / 2 / 255.0f;
if (maxRadius != RippleOwner.RADIUS_AUTO) {
mHasMaxRadius = true;
mOuterRadius = maxRadius;
} else {
final float halfWidth = mBounds.width() / 2.0f;
final float halfHeight = mBounds.height() / 2.0f;
mOuterRadius = (float) Math.sqrt(halfWidth * halfWidth + halfHeight * halfHeight);
}
mOuterX = 0;
mOuterY = 0;
mDensity = density;
clampStartingPosition();
}
private void clampStartingPosition() {
final float cX = mBounds.exactCenterX();
final float cY = mBounds.exactCenterY();
final float dX = mStartingX - cX;
final float dY = mStartingY - cY;
final float r = mOuterRadius;
if (dX * dX + dY * dY > r * r) {
// Point is outside the circle, clamp to the circumference.
final double angle = Math.atan2(dY, dX);
mClampedStartingX = cX + (float) (Math.cos(angle) * r);
mClampedStartingY = cY + (float) (Math.sin(angle) * r);
} else {
mClampedStartingX = mStartingX;
mClampedStartingY = mStartingY;
}
}
public void onHotspotBoundsChanged() {
if (!mHasMaxRadius) {
final float halfWidth = mBounds.width() / 2.0f;
final float halfHeight = mBounds.height() / 2.0f;
mOuterRadius = (float) Math.sqrt(halfWidth * halfWidth + halfHeight * halfHeight);
clampStartingPosition();
}
}
public void setOpacity(float a) {
mOpacity = a;
invalidateSelf();
}
public float getOpacity() {
return mOpacity;
}
public void setRadiusGravity(float r) {
mTweenRadius = r;
invalidateSelf();
}
public float getRadiusGravity() {
return mTweenRadius;
}
public void setXGravity(float x) {
mTweenX = x;
invalidateSelf();
}
public float getXGravity() {
return mTweenX;
}
public void setYGravity(float y) {
mTweenY = y;
invalidateSelf();
}
public float getYGravity() {
return mTweenY;
}
/**
* Draws the ripple centered at (0,0) using the specified paint.
*/
public boolean draw(Canvas c, Paint p) {
return drawSoftware(c, p);
}
private boolean drawSoftware(Canvas c, Paint p) {
boolean hasContent = false;
p.setColor(mColorOpaque);
final int alpha = MathUtils.clamp((int) (255 * mOpacity + 0.5f), 0, 255);
final float radius = MathUtils.lerp(0, mOuterRadius, mTweenRadius);
if (alpha > 0 && radius > 0) {
final float x = MathUtils.lerp(
mClampedStartingX - mBounds.exactCenterX(), mOuterX, mTweenX);
final float y = MathUtils.lerp(
mClampedStartingY - mBounds.exactCenterY(), mOuterY, mTweenY);
p.setAlpha(alpha);
p.setStyle(Style.FILL);
c.drawCircle(x, y, radius, p);
hasContent = true;
}
return hasContent;
}
/**
* Returns the maximum bounds of the ripple relative to the ripple center.
*/
public void getBounds(Rect bounds) {
final int outerX = (int) mOuterX;
final int outerY = (int) mOuterY;
final int r = (int) mOuterRadius + 1;
bounds.set(outerX - r, outerY - r, outerX + r, outerY + r);
}
/**
* Specifies the starting position relative to the drawable bounds. No-op if
* the ripple has already entered.
*/
public void move(float x, float y) {
mStartingX = x;
mStartingY = y;
clampStartingPosition();
}
/**
* Starts the enter animation.
*/
public void enter() {
cancel();
final int radiusDuration = (int)
(1000 * Math.sqrt(mOuterRadius / WAVE_TOUCH_DOWN_ACCELERATION * mDensity) + 0.5);
final ObjectAnimator radius = ObjectAnimator.ofFloat(this, "radiusGravity", 1);
radius.setDuration(radiusDuration);
radius.setInterpolator(LINEAR_INTERPOLATOR);
radius.setStartDelay(RIPPLE_ENTER_DELAY);
final ObjectAnimator cX = ObjectAnimator.ofFloat(this, "xGravity", 1);
cX.setDuration(radiusDuration);
cX.setInterpolator(LINEAR_INTERPOLATOR);
cX.setStartDelay(RIPPLE_ENTER_DELAY);
final ObjectAnimator cY = ObjectAnimator.ofFloat(this, "yGravity", 1);
cY.setDuration(radiusDuration);
cY.setInterpolator(LINEAR_INTERPOLATOR);
cY.setStartDelay(RIPPLE_ENTER_DELAY);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
radius.setAutoCancel(true);
cX.setAutoCancel(true);
cY.setAutoCancel(true);
}
mAnimRadius = radius;
mAnimX = cX;
mAnimY = cY;
// Enter animations always run on the UI thread, since it's unlikely
// that anything interesting is happening until the user lifts their
// finger.
radius.start();
cX.start();
cY.start();
}
/**
* Starts the exit animation.
*/
public void exit() {
cancel();
final float radius = MathUtils.lerp(0, mOuterRadius, mTweenRadius);
final float remaining;
if (mAnimRadius != null && mAnimRadius.isRunning()) {
remaining = mOuterRadius - radius;
} else {
remaining = mOuterRadius;
}
final int radiusDuration = (int) (1000 * Math.sqrt(remaining / (WAVE_TOUCH_UP_ACCELERATION
+ WAVE_TOUCH_DOWN_ACCELERATION) * mDensity) + 0.5);
final int opacityDuration = (int) (1000 * 1 / WAVE_OPACITY_DECAY_VELOCITY + 0.5f);
exitSoftware(radiusDuration, opacityDuration);
}
/**
* Jump all animations to their end state. The caller is responsible for
* removing the ripple from the list of animating ripples.
*/
public void jump() {
mCanceled = true;
endSoftwareAnimations();
mCanceled = false;
}
private void endSoftwareAnimations() {
if (mAnimRadius != null) {
mAnimRadius.end();
mAnimRadius = null;
}
if (mAnimOpacity != null) {
mAnimOpacity.end();
mAnimOpacity = null;
}
if (mAnimX != null) {
mAnimX.end();
mAnimX = null;
}
if (mAnimY != null) {
mAnimY.end();
mAnimY = null;
}
}
private void exitSoftware(int radiusDuration, int opacityDuration) {
final ObjectAnimator radiusAnim = ObjectAnimator.ofFloat(this, "radiusGravity", 1);
radiusAnim.setDuration(radiusDuration);
radiusAnim.setInterpolator(DECEL_INTERPOLATOR);
final ObjectAnimator xAnim = ObjectAnimator.ofFloat(this, "xGravity", 1);
xAnim.setDuration(radiusDuration);
xAnim.setInterpolator(DECEL_INTERPOLATOR);
final ObjectAnimator yAnim = ObjectAnimator.ofFloat(this, "yGravity", 1);
yAnim.setDuration(radiusDuration);
yAnim.setInterpolator(DECEL_INTERPOLATOR);
final ObjectAnimator opacityAnim = ObjectAnimator.ofFloat(this, "opacity", 0);
opacityAnim.setDuration(opacityDuration);
opacityAnim.setInterpolator(LINEAR_INTERPOLATOR);
opacityAnim.addListener(mAnimationListener);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
radiusAnim.setAutoCancel(true);
xAnim.setAutoCancel(true);
yAnim.setAutoCancel(true);
opacityAnim.setAutoCancel(true);
}
mAnimRadius = radiusAnim;
mAnimOpacity = opacityAnim;
mAnimX = xAnim;
mAnimY = yAnim;
radiusAnim.start();
opacityAnim.start();
xAnim.start();
yAnim.start();
}
/**
* Cancels all animations. The caller is responsible for removing
* the ripple from the list of animating ripples.
*/
public void cancel() {
mCanceled = true;
cancelSoftwareAnimations();
mCanceled = false;
}
private void cancelSoftwareAnimations() {
if (mAnimRadius != null) {
mAnimRadius.cancel();
mAnimRadius = null;
}
if (mAnimOpacity != null) {
mAnimOpacity.cancel();
mAnimOpacity = null;
}
if (mAnimX != null) {
mAnimX.cancel();
mAnimX = null;
}
if (mAnimY != null) {
mAnimY.cancel();
mAnimY = null;
}
}
private void removeSelf() {
// The owner will invalidate itself.
if (!mCanceled) {
mOwner.removeRipple(this);
}
}
private void invalidateSelf() {
mOwner.invalidateSelf();
}
private final AnimatorListenerAdapter mAnimationListener = new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
removeSelf();
}
};
/**
* Interpolator with a smooth log deceleration
*/
private static final class LogInterpolator implements Interpolator {
@Override
public float getInterpolation(float input) {
return 1 - (float) Math.pow(400, -input * 1.4);
}
}
}
@@ -1,285 +0,0 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.effect.ripple;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.os.Build;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import com.hippo.ehviewer.util.MathUtils;
/**
* Draws a Material ripple.
*/
class RippleBackground {
private static final Interpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
private static final float GLOBAL_SPEED = 1.0f;
private static final float WAVE_OPACITY_DECAY_VELOCITY = 3.0f / GLOBAL_SPEED;
private static final float WAVE_OUTER_OPACITY_EXIT_VELOCITY_MAX = 4.5f * GLOBAL_SPEED;
private static final float WAVE_OUTER_OPACITY_EXIT_VELOCITY_MIN = 1.5f * GLOBAL_SPEED;
private static final float WAVE_OUTER_OPACITY_ENTER_VELOCITY = 10.0f * GLOBAL_SPEED;
private static final float WAVE_OUTER_SIZE_INFLUENCE_MAX = 200f;
private static final float WAVE_OUTER_SIZE_INFLUENCE_MIN = 40f;
private final RippleOwner mOwner;
/** Bounds used for computing max radius. */
private final Rect mBounds;
/** Full-opacity color for drawing this ripple. */
private int mColorOpaque;
/** Maximum alpha value for drawing this ripple. */
private int mColorAlpha;
/** Maximum ripple radius. */
private float mOuterRadius;
/** Screen density used to adjust pixel-based velocities. */
private float mDensity;
// Software animators.
private ObjectAnimator mAnimOuterOpacity;
// Software rendering properties.
private float mOuterOpacity = 0;
private float mOuterX;
private float mOuterY;
/** Whether we have an explicit maximum radius. */
private boolean mHasMaxRadius;
/**
* Creates a new ripple.
*/
public RippleBackground(RippleOwner owner, Rect bounds) {
mOwner = owner;
mBounds = bounds;
}
public void setup(int maxRadius, int color, float density) {
mColorOpaque = color | 0xFF000000;
mColorAlpha = Color.alpha(color) / 2;
if (maxRadius != RippleOwner.RADIUS_AUTO) {
mHasMaxRadius = true;
mOuterRadius = maxRadius;
} else {
final float halfWidth = mBounds.width() / 2.0f;
final float halfHeight = mBounds.height() / 2.0f;
mOuterRadius = (float) Math.sqrt(halfWidth * halfWidth + halfHeight * halfHeight);
}
mOuterX = 0;
mOuterY = 0;
mDensity = density;
}
public void onHotspotBoundsChanged() {
if (!mHasMaxRadius) {
final float halfWidth = mBounds.width() / 2.0f;
final float halfHeight = mBounds.height() / 2.0f;
mOuterRadius = (float) Math.sqrt(halfWidth * halfWidth + halfHeight * halfHeight);
}
}
public void setOuterOpacity(float a) {
mOuterOpacity = a;
invalidateSelf();
}
public float getOuterOpacity() {
return mOuterOpacity;
}
/**
* Draws the ripple centered at (0,0) using the specified paint.
*/
public boolean draw(Canvas c, Paint p) {
return drawSoftware(c, p);
}
public boolean shouldDraw() {
final int outerAlpha = (int) (mColorAlpha * mOuterOpacity + 0.5f);
return outerAlpha > 0 && mOuterRadius > 0;
}
private boolean drawSoftware(Canvas c, Paint p) {
boolean hasContent = false;
p.setColor(mColorOpaque);
final int outerAlpha = (int) (mColorAlpha * mOuterOpacity + 0.5f);
if (outerAlpha > 0 && mOuterRadius > 0) {
p.setAlpha(outerAlpha);
p.setStyle(Style.FILL);
c.drawCircle(mOuterX, mOuterY, mOuterRadius, p);
hasContent = true;
}
return hasContent;
}
/**
* Returns the maximum bounds of the ripple relative to the ripple center.
*/
public void getBounds(Rect bounds) {
final int outerX = (int) mOuterX;
final int outerY = (int) mOuterY;
final int r = (int) mOuterRadius + 1;
bounds.set(outerX - r, outerY - r, outerX + r, outerY + r);
}
/**
* Starts the enter animation.
*/
public void enter() {
cancel();
final int outerDuration = (int) (1000 * 1.0f / WAVE_OUTER_OPACITY_ENTER_VELOCITY);
final ObjectAnimator outer = ObjectAnimator.ofFloat(this, "outerOpacity", 0, 1);
outer.setDuration(outerDuration);
outer.setInterpolator(LINEAR_INTERPOLATOR);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
outer.setAutoCancel(true);
}
mAnimOuterOpacity = outer;
// Enter animations always run on the UI thread, since it's unlikely
// that anything interesting is happening until the user lifts their
// finger.
outer.start();
}
/**
* Starts the exit animation.
*/
public void exit() {
cancel();
// Scale the outer max opacity and opacity velocity based
// on the size of the outer radius.
final int opacityDuration = (int) (1000 / WAVE_OPACITY_DECAY_VELOCITY + 0.5f);
final float outerSizeInfluence = MathUtils.clamp(
(mOuterRadius - WAVE_OUTER_SIZE_INFLUENCE_MIN * mDensity)
/ (WAVE_OUTER_SIZE_INFLUENCE_MAX * mDensity), 0, 1);
final float outerOpacityVelocity = MathUtils.lerp(WAVE_OUTER_OPACITY_EXIT_VELOCITY_MIN,
WAVE_OUTER_OPACITY_EXIT_VELOCITY_MAX, outerSizeInfluence);
// Determine at what time the inner and outer opacity intersect.
// inner(t) = mOpacity - t * WAVE_OPACITY_DECAY_VELOCITY / 1000
// outer(t) = mOuterOpacity + t * WAVE_OUTER_OPACITY_VELOCITY / 1000
final int inflectionDuration = Math.max(0, (int) (1000 * (1 - mOuterOpacity)
/ (WAVE_OPACITY_DECAY_VELOCITY + outerOpacityVelocity) + 0.5f));
final int inflectionOpacity = (int) (mColorAlpha * (mOuterOpacity
+ inflectionDuration * outerOpacityVelocity * outerSizeInfluence / 1000) + 0.5f);
exitSoftware(opacityDuration, inflectionDuration, inflectionOpacity);
}
/**
* Jump all animations to their end state. The caller is responsible for
* removing the ripple from the list of animating ripples.
*/
public void jump() {
endSoftwareAnimations();
}
private void endSoftwareAnimations() {
if (mAnimOuterOpacity != null) {
mAnimOuterOpacity.end();
mAnimOuterOpacity = null;
}
}
private void exitSoftware(int opacityDuration, int inflectionDuration, int inflectionOpacity) {
final ObjectAnimator outerOpacityAnim;
if (inflectionDuration > 0) {
// Outer opacity continues to increase for a bit.
outerOpacityAnim = ObjectAnimator.ofFloat(this,
"outerOpacity", inflectionOpacity / 255.0f);
outerOpacityAnim.setDuration(inflectionDuration);
outerOpacityAnim.setInterpolator(LINEAR_INTERPOLATOR);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
outerOpacityAnim.setAutoCancel(true);
}
// Chain the outer opacity exit animation.
final int outerDuration = opacityDuration - inflectionDuration;
if (outerDuration > 0) {
outerOpacityAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
final ObjectAnimator outerFadeOutAnim = ObjectAnimator.ofFloat(
RippleBackground.this, "outerOpacity", 0);
outerFadeOutAnim.setDuration(outerDuration);
outerFadeOutAnim.setInterpolator(LINEAR_INTERPOLATOR);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
outerFadeOutAnim.setAutoCancel(true);
}
mAnimOuterOpacity = outerFadeOutAnim;
outerFadeOutAnim.start();
}
@Override
public void onAnimationCancel(Animator animation) {
animation.removeListener(this);
}
});
}
} else {
outerOpacityAnim = ObjectAnimator.ofFloat(this, "outerOpacity", 0);
outerOpacityAnim.setDuration(opacityDuration);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
outerOpacityAnim.setAutoCancel(true);
}
}
mAnimOuterOpacity = outerOpacityAnim;
outerOpacityAnim.start();
}
/**
* Cancel all animations. The caller is responsible for removing
* the ripple from the list of animating ripples.
*/
public void cancel() {
cancelSoftwareAnimations();
}
private void cancelSoftwareAnimations() {
if (mAnimOuterOpacity != null) {
mAnimOuterOpacity.cancel();
mAnimOuterOpacity = null;
}
}
private void invalidateSelf() {
mOwner.invalidateSelf();
}
}
@@ -1,579 +0,0 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.effect.ripple;
import android.annotation.TargetApi;
import android.content.res.ColorStateList;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.NonNull;
import com.hippo.ehviewer.widget.Hotspotable;
import java.util.Arrays;
/**
* Drawable that shows a ripple effect in response to state changes. The
* anchoring position of the ripple for a given state may be specified by
* calling {@link #setHotspot(float, float)} with the corresponding state
* attribute identifier.
* <p>
* A touch feedback drawable may contain multiple child layers, including a
* special mask layer that is not drawn to the screen. A single layer may be set
* as the mask by specifying its android:id value as {@link android.R.id#mask}.
* <pre>
* <code>&lt!-- A red ripple masked against an opaque rectangle. --/>
* &ltripple android:color="#ffff0000">
* &ltitem android:id="@android:id/mask"
* android:drawable="@android:color/white" />
* &ltripple /></code>
* </pre>
* <p>
* If a mask layer is set, the ripple effect will be masked against that layer
* before it is drawn over the composite of the remaining child layers.
* <p>
* If no mask layer is set, the ripple effect is masked against the composite
* of the child layers.
* <pre>
* <code>&lt!-- A blue ripple drawn atop a black rectangle. --/>
* &ltripple android:color="#ff00ff00">
* &ltitem android:drawable="@android:color/black" />
* &ltripple />
*
* &lt!-- A red ripple drawn atop a drawable resource. --/>
* &ltripple android:color="#ff00ff00">
* &ltitem android:drawable="@drawable/my_drawable" />
* &ltripple /></code>
* </pre>
* <p>
* If no child layers or mask is specified and the ripple is set as a View
* background, the ripple will be drawn atop the first available parent
* background within the View's hierarchy. In this case, the drawing region
* may extend outside of the Drawable bounds.
* <pre>
* <code>&lt!-- An unbounded green ripple. --/>
* &ltripple android:color="#ff0000ff" /></code>
* </pre>
*
* @attr ref android.R.styleable#RippleDrawable_color
*/
public class RippleDrawable extends Drawable implements RippleOwner, Hotspotable {
@SuppressWarnings("unused")
private static final String TAG = RippleDrawable.class.getSimpleName();
/** The maximum number of ripples supported. */
private static final int MAX_RIPPLES = 10;
/** Current ripple effect bounds, used to constrain ripple effects. */
private final Rect mHotspotBounds = new Rect();
/** The current background. May be actively animating or pending entry. */
private RippleBackground mBackground;
/** Whether we expect to draw a background when visible. */
private boolean mBackgroundActive;
/** The current ripple. May be actively animating or pending entry. */
private Ripple mRipple;
/** Whether we expect to draw a ripple when visible. */
private boolean mRippleActive;
// Hotspot coordinates that are awaiting activation.
private float mPendingX;
private float mPendingY;
private boolean mHasPending;
/**
* Lazily-created array of actively animating ripples. Inactive ripples are
* pruned during draw(). The locations of these will not change.
*/
private Ripple[] mExitingRipples;
private int mExitingRipplesCount = 0;
/** Paint used to control appearance of ripples. */
private Paint mRipplePaint;
/** Target density of the display into which ripples are drawn. */
private final float mDensity = 1.0f;
/** Whether bounds are being overridden. */
private boolean mOverrideBounds;
/**
* Whether the next draw MUST draw something to canvas. Used to work around
* a bug in hardware invalidation following a render thread-accelerated
* animation.
*/
private boolean mNeedsDraw;
private ColorStateList mColor = ColorStateList.valueOf(Color.MAGENTA);
private int mMaxRadius = RADIUS_AUTO;
private final Drawable mContent;
RippleDrawable(ColorStateList color, Drawable content) {
setColor(color);
mContent = content;
}
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void jumpToCurrentState() {
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
super.jumpToCurrentState();
}
boolean needsDraw = false;
if (mRipple != null) {
mRipple.jump();
}
if (mBackground != null) {
mBackground.jump();
}
needsDraw |= cancelExitingRipples();
mNeedsDraw = needsDraw;
invalidateSelf();
}
private boolean cancelExitingRipples() {
final int count = mExitingRipplesCount;
final Ripple[] ripples = mExitingRipples;
for (int i = 0; i < count; i++) {
ripples[i].cancel();
}
if (ripples != null) {
Arrays.fill(ripples, 0, count, null);
}
mExitingRipplesCount = 0;
return false;
}
@Override
public void setAlpha(int alpha) {
mColor.withAlpha(alpha);
}
@Override
public int getAlpha() {
return Color.alpha(mColor.getDefaultColor());
}
@Override
public void setColorFilter(ColorFilter cf) {
//TODO Paint.setColorFilter(filter) ?
}
@Override
public int getOpacity() {
// Worst-case scenario.
return PixelFormat.TRANSLUCENT;
}
@Override
protected boolean onStateChange(int[] stateSet) {
boolean changed = false;
if (mContent != null)
changed |= mContent.setState(stateSet);
boolean enabled = false;
boolean pressed = false;
boolean focused = false;
for (int state : stateSet) {
if (state == android.R.attr.state_enabled) {
enabled = true;
}
if (state == android.R.attr.state_focused) {
focused = true;
}
if (state == android.R.attr.state_pressed) {
pressed = true;
}
}
setRippleActive(enabled && pressed);
setBackgroundActive(focused || (enabled && pressed));
return changed;
}
private void setRippleActive(boolean active) {
if (mRippleActive != active) {
mRippleActive = active;
if (active) {
tryRippleEnter();
} else {
tryRippleExit();
}
}
}
private void setBackgroundActive(boolean active) {
if (mBackgroundActive != active) {
mBackgroundActive = active;
if (active) {
tryBackgroundEnter();
} else {
tryBackgroundExit();
}
}
}
@Override
protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);
if (!mOverrideBounds) {
mHotspotBounds.set(bounds);
onHotspotBoundsChanged();
}
if (mContent != null)
mContent.setBounds(bounds);
invalidateSelf();
}
@Override
public boolean setVisible(boolean visible, boolean restart) {
final boolean changed = super.setVisible(visible, restart);
if (!visible) {
clearHotspots();
} else if (changed) {
// If we just became visible, ensure the background and ripple
// visibilities are consistent with their internal states.
if (mRippleActive) {
tryRippleEnter();
}
if (mBackgroundActive) {
tryBackgroundEnter();
}
}
return changed;
}
@Override
public boolean isStateful() {
return true;
}
public void setColor(ColorStateList color) {
int alpha = Color.alpha(color.getDefaultColor());
mColor = color.withAlpha((int) (alpha * (1 - 0.001f * alpha)));
invalidateSelf();
}
@Override
public void setHotspot(float x, float y) {
if (mRipple == null || mBackground == null) {
mPendingX = x;
mPendingY = y;
mHasPending = true;
}
if (mRipple != null) {
mRipple.move(x, y);
}
}
/**
* Creates an active hotspot at the specified location.
*/
private void tryBackgroundEnter() {
if (mBackground == null) {
mBackground = new RippleBackground(this, mHotspotBounds);
}
final int color = mColor.getColorForState(getState(), Color.TRANSPARENT);
mBackground.setup(mMaxRadius, color, mDensity);
mBackground.enter();
}
private void tryBackgroundExit() {
if (mBackground != null) {
// Don't null out the background, we need it to draw!
mBackground.exit();
}
}
/**
* Attempts to start an enter animation for the active hotspot. Fails if
* there are too many animating ripples.
*/
private void tryRippleEnter() {
if (mExitingRipplesCount >= MAX_RIPPLES) {
// This should never happen unless the user is tapping like a maniac
// or there is a bug that's preventing ripples from being removed.
return;
}
if (mRipple == null) {
final float x;
final float y;
if (mHasPending) {
mHasPending = false;
x = mPendingX;
y = mPendingY;
} else {
x = mHotspotBounds.exactCenterX();
y = mHotspotBounds.exactCenterY();
}
mRipple = new Ripple(this, mHotspotBounds, x, y);
}
final int color = mColor.getColorForState(getState(), Color.TRANSPARENT);
mRipple.setup(mMaxRadius, color, mDensity);
mRipple.enter();
}
/**
* Attempts to start an exit animation for the active hotspot. Fails if
* there is no active hotspot.
*/
private void tryRippleExit() {
if (mRipple != null) {
if (mExitingRipples == null) {
mExitingRipples = new Ripple[MAX_RIPPLES];
}
mExitingRipples[mExitingRipplesCount++] = mRipple;
mRipple.exit();
mRipple = null;
}
}
/**
* Cancels and removes the active ripple, all exiting ripples, and the
* background. Nothing will be drawn after this method is called.
*/
private void clearHotspots() {
boolean needsDraw = false;
if (mRipple != null) {
mRipple.cancel();
mRipple = null;
}
if (mBackground != null) {
mBackground.cancel();
mBackground = null;
}
needsDraw |= cancelExitingRipples();
mNeedsDraw = needsDraw;
invalidateSelf();
}
@Override
public void setHotspotBounds(int left, int top, int right, int bottom) {
mOverrideBounds = true;
mHotspotBounds.set(left, top, right, bottom);
onHotspotBoundsChanged();
}
/** @hide */
public void getHotspotBounds(Rect outRect) {
outRect.set(mHotspotBounds);
}
/**
* Notifies all the animating ripples that the hotspot bounds have changed.
*/
private void onHotspotBoundsChanged() {
final int count = mExitingRipplesCount;
final Ripple[] ripples = mExitingRipples;
for (int i = 0; i < count; i++) {
ripples[i].onHotspotBoundsChanged();
}
if (mRipple != null) {
mRipple.onHotspotBoundsChanged();
}
if (mBackground != null) {
mBackground.onHotspotBoundsChanged();
}
}
@Override
public void draw(@NonNull Canvas canvas) {
final boolean drawNonMaskContent = mContent != null;
final Rect bounds = getDirtyBounds();
final int saveCount = canvas.save(Canvas.CLIP_SAVE_FLAG);
canvas.clipRect(bounds);
// If we have content, draw it into a layer first.
if (drawNonMaskContent) {
drawContentLayer(canvas, bounds);
}
// If we have a background and a non-opaque mask, draw the masking layer.
drawBackgroundLayer(canvas, bounds);
// If we have ripples and a non-opaque mask, draw the masking layer.
drawRippleLayer(canvas, bounds);
// If we failed to draw anything and we just canceled animations, at
// least draw a color so that hardware invalidation works correctly.
if (mNeedsDraw) {
canvas.drawColor(Color.TRANSPARENT);
// Request another draw so we can avoid adding a transparent layer
// during the next display list refresh.
invalidateSelf();
}
mNeedsDraw = false;
canvas.restoreToCount(saveCount);
}
/**
* Removes a ripple from the exiting ripple list.
*
* @param ripple the ripple to remove
*/
@Override
public void removeRipple(Ripple ripple) {
// Ripple ripple ripple ripple. Ripple ripple.
final Ripple[] ripples = mExitingRipples;
final int count = mExitingRipplesCount;
final int index = getRippleIndex(ripple);
if (index >= 0) {
System.arraycopy(ripples, index + 1, ripples, index, count - (index + 1));
ripples[count - 1] = null;
mExitingRipplesCount--;
invalidateSelf();
}
}
private int getRippleIndex(Ripple ripple) {
final Ripple[] ripples = mExitingRipples;
final int count = mExitingRipplesCount;
for (int i = 0; i < count; i++) {
if (ripples[i] == ripple) {
return i;
}
}
return -1;
}
private void drawContentLayer(Canvas canvas, Rect bounds) {
mContent.draw(canvas);
}
private void drawBackgroundLayer(
Canvas canvas, Rect bounds) {
if (mBackground != null && mBackground.shouldDraw()) {
final float x = mHotspotBounds.exactCenterX();
final float y = mHotspotBounds.exactCenterY();
canvas.translate(x, y);
mBackground.draw(canvas, getRipplePaint());
canvas.translate(-x, -y);
}
}
private void drawRippleLayer(Canvas canvas, Rect bounds) {
int restoreTranslate = -1;
// Translate the canvas to the current hotspot bounds.
restoreTranslate = canvas.save();
canvas.translate(mHotspotBounds.exactCenterX(), mHotspotBounds.exactCenterY());
// Draw ripples and update the animating ripples array.
final int count = mExitingRipplesCount;
final Ripple[] ripples = mExitingRipples;
for (int i = 0; i <= count; i++) {
final Ripple ripple;
if (i < count) {
ripple = ripples[i];
} else if (mRipple != null) {
ripple = mRipple;
} else {
continue;
}
ripple.draw(canvas, getRipplePaint());
}
// Always restore the translation.
if (restoreTranslate >= 0) {
canvas.restoreToCount(restoreTranslate);
}
}
private Paint getRipplePaint() {
if (mRipplePaint == null) {
mRipplePaint = new Paint();
mRipplePaint.setAntiAlias(true);
}
return mRipplePaint;
}
@Override
public Rect getDirtyBounds() {
return getBounds();
}
/**
* Sets the maximum ripple radius in pixels. The default value of
* {@link #RADIUS_AUTO} defines the radius as the distance from the center
* of the drawable bounds (or hotspot bounds, if specified) to a corner.
*
* @param maxRadius the maximum ripple radius in pixels or
* {@link #RADIUS_AUTO} to automatically determine the maximum
* radius based on the bounds
* @see #getMaxRadius()
* @see #setHotspotBounds(int, int, int, int)
* @hide
*/
public void setMaxRadius(int maxRadius) {
if (maxRadius != RADIUS_AUTO && maxRadius < 0) {
throw new IllegalArgumentException("maxRadius must be RADIUS_AUTO or >= 0");
}
mMaxRadius = maxRadius;
}
/**
* @return the maximum ripple radius in pixels, or {@link #RADIUS_AUTO} if
* the radius is determined automatically
* @see #setMaxRadius(int)
* @hide
*/
public int getMaxRadius() {
return mMaxRadius;
}
}
@@ -1,29 +0,0 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.effect.ripple;
public interface RippleOwner {
/**
* Constant for automatically determining the maximum ripple radius.
*/
public static final int RADIUS_AUTO = -1;
public void removeRipple(Ripple ripple);
public void invalidateSelf();
}
@@ -1,55 +0,0 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.effect.ripple;
import android.annotation.TargetApi;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.View;
import com.hippo.ehviewer.widget.HotspotTouchHelper;
public final class RippleSalon {
private static final boolean USE_OLD_RIPPLE =
Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP;
private static final Drawable MASK = new ColorDrawable(Color.BLACK);
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void addRipple(View v, ColorStateList color) {
addRipple(v, color, v.getBackground());
}
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void addRipple(View v, ColorStateList color, Drawable content) {
if (USE_OLD_RIPPLE) {
RippleDrawable rippleDrawable = new RippleDrawable(color, content);
v.setOnTouchListener(new HotspotTouchHelper(rippleDrawable));
v.setBackgroundDrawable(rippleDrawable);
} else {
android.graphics.drawable.RippleDrawable rippleDrawable = new android.graphics.drawable.RippleDrawable(color, content, MASK);
v.setBackgroundDrawable(rippleDrawable);
}
}
}
@@ -1,77 +0,0 @@
package com.hippo.ehviewer.ehclient;
import android.support.annotation.Nullable;
import android.util.Pair;
import com.hippo.ehviewer.util.Utils;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TorrentParser {
/**
*
* @return the param or new instance if size changed
*/
public static Pair<String, String>[] parse(String body, @Nullable Pair<String, String>[] torrents) {
List<Pair<String, String>> torrentList;
int arrayLength;
int size = 0;
if (torrents == null) {
arrayLength = 0;
torrentList = new LinkedList<>();
} else {
arrayLength = torrents.length;
torrentList = null;
}
Pattern p = Pattern.compile("<td colspan=\"5\"> &nbsp; <a href=\"([^\"]+)\">([^<>]*)</a></td>");
Matcher m = p.matcher(body);
while (m.find()) {
size++;
if (size > arrayLength && torrentList == null) {
torrentList = new LinkedList<>();
// Copy data
int copySize = size - 1;
for (int i = 0; i < copySize; i++) {
torrentList.add(torrents[i]);
}
}
// Remove ?p= to make torrent redistributable
String url = m.group(1);
if (url == null) {
size--;
continue;
}
int index = url.indexOf("?p=");
if (index != -1) {
url = url.substring(0, index);
}
Pair<String, String> newItem = new Pair<>(url, Utils.unescapeXml(m.group(2)));
if (torrentList != null) {
torrentList.add(newItem);
} else {
torrents[size - 1] = newItem;
}
}
if (torrentList != null) {
//noinspection unchecked,SuspiciousToArrayCall
return (Pair<String, String>[]) torrentList.toArray(new Pair[torrentList.size()]);
} else if (size == arrayLength){
return torrents;
} else {
//noinspection unchecked
Pair<String, String>[] result = new Pair[size];
System.arraycopy(torrents, 0, result, 0, size);
return result;
}
}
}
@@ -1,25 +0,0 @@
/*
* Copyright (C) 2014 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.gallery.glrenderer;
public interface Uploaded {
public boolean isContentValid();
public void updateContent(GLCanvas canvas);
}
@@ -1,65 +0,0 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.miscellaneous;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.widget.MaterialToast;
public final class ActivityHelper {
public static boolean sendEmail(@NonNull Activity from, @NonNull String address,
@Nullable String subject, @Nullable String text) {
Intent i = new Intent(Intent.ACTION_SENDTO);
i.setData(Uri.parse("mailto:" + address));
if (subject != null) {
i.putExtra(Intent.EXTRA_SUBJECT, subject);
}
if (text != null) {
i.putExtra(Intent.EXTRA_TEXT, text);
}
try {
from.startActivity(i);
return true;
} catch (ActivityNotFoundException e) {
MaterialToast.showToast(R.string.em_cant_find_activity);
return false;
}
}
public static boolean share(@NonNull Activity from, String text) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, text);
sendIntent.setType("text/plain");
try {
from.startActivity(sendIntent);
return true;
} catch (ActivityNotFoundException e) {
MaterialToast.showToast(R.string.em_cant_find_activity);
return false;
}
}
}
@@ -1,92 +0,0 @@
package com.hippo.ehviewer.miscellaneous;
import android.content.Context;
import com.hippo.ehviewer.AppHandler;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.network.HttpHelper;
import com.hippo.ehviewer.util.BgThread;
import com.hippo.ehviewer.widget.MaterialToast;
import java.io.File;
public class Downloader implements Runnable, HttpHelper.OnDownloadListener {
private Context mContext;
private String mUrl;
private File mDir;
private String mFilename;
private boolean mIsRunning = false;
public Downloader(Context context, String url, File dir, String filename) {
mContext = context.getApplicationContext();
mUrl = url;
mDir = dir;
mFilename = filename;
}
public boolean isRunning() {
return mIsRunning;
}
public void startDownload() {
if (mIsRunning) {
return;
}
mIsRunning = true;
new BgThread(this).start();
MaterialToast.showToast(R.string.start_saving_torrent);
}
public void post(Runnable runnable) {
AppHandler.getInstance().post(runnable);
}
@Override
public void run() {
HttpHelper.DownloadOption dOpt = new HttpHelper.DownloadOption();
dOpt.setUseProxy(false);
dOpt.setAllowFixingExtension(true);
dOpt.setAllowFixingName(true);
HttpHelper hh = new HttpHelper(mContext);
final boolean ok = HttpHelper.DOWNLOAD_OK_STR.equals(
hh.download(mUrl, mDir, mFilename, null, null, this));
post(new Runnable() {
@Override
public void run() {
MaterialToast.showToast(ok ?
String.format(mContext.getString(R.string.save_torrent_successful),
mDir.getAbsolutePath() + File.separatorChar + mFilename) :
mContext.getString(R.string.save_torrent_failed));
}
});
mIsRunning = false;
}
@Override
public void onDownloadStartConnect() {
// Empty
}
@Override
public void onDownloadStartDownload(int totalSize) {
// Empty
}
@Override
public void onDownloadStatusUpdate(int downloadSize, int totalSize) {
// Empty
}
@Override
public void onDownloadOver(int status, String eMsg) {
// Empty
}
@Override
public void onUpdateFilename(String newFilename) {
mFilename = newFilename;
}
}
@@ -1,4 +0,0 @@
/**
* com.hippo.ehviewer.miscellaneous is a group of stuff combine more than one scopes
*/
package com.hippo.ehviewer.miscellaneous;
@@ -1,106 +0,0 @@
/*
* Copyright (C) 2014 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.preference;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.SeekBar;
import com.hippo.ehviewer.app.MaterialAlertDialog;
import com.hippo.ehviewer.app.MaterialAlertDialog.Builder;
import com.hippo.ehviewer.util.Utils;
public class SeekBarDialogPreference extends DialogPreference {
private SeekBar mSeekBar;
public SeekBarDialogPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0);
}
public SeekBarDialogPreference(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
init(context, attrs, defStyle);
}
private void init(Context context, AttributeSet attrs, int defStyle) {
mSeekBar = new SeekBar(context, attrs);
}
@Override
protected boolean inScrollView() {
return true;
}
@Override
protected View onCreateDialogView() {
// Make sure mEditText is an orphan
ViewParent oldParent = mSeekBar.getParent();
if (oldParent != null)
((ViewGroup) oldParent).removeView(mSeekBar);
return mSeekBar;
}
@Override
protected void onBindDialogView(View view) {
mSeekBar.setProgress(Utils.parseIntSafely(getPersistedString(null), 120));
}
@Override
protected void onPrepareDialogBuilder(Builder builder) {
// Empty
}
@Override
protected Object onGetDefaultValue(TypedArray a, int index) {
return a.getString(index);
}
@Override
protected void onSetInitialValue(boolean restorePersistedValue,
Object defaultValue) {
setSummary(restorePersistedValue ? getPersistedString((String) defaultValue)
: (String) defaultValue);
if (!restorePersistedValue)
persistString((String) defaultValue);
}
@Override
public boolean onClick(MaterialAlertDialog dialog, int which) {
super.onClick(dialog, which);
if (which == MaterialAlertDialog.POSITIVE) {
String value = Integer.toString(mSeekBar.getProgress());
if (callChangeListener(value)) {
persistString(value);
setSummary(value);
return true;
} else {
return false;
}
} else {
return true;
}
}
}
@@ -1,18 +0,0 @@
package com.hippo.ehviewer.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.util.Config;
import com.hippo.ehviewer.widget.MaterialToast;
public class RestPatternReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Config.setPatternProtection("");
MaterialToast.showToast(R.string.reset_pattern_protection);
}
}
@@ -1,95 +0,0 @@
package com.hippo.ehviewer.ui;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.TextView;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.drawable.MaterialIndicatorDrawable;
import com.hippo.ehviewer.util.Config;
import com.hippo.ehviewer.util.Ui;
import com.hippo.ehviewer.widget.LockPatternUtils;
import com.hippo.ehviewer.widget.LockPatternView;
import java.util.List;
public class EnterPatternActivity extends AbsActivity {
private static final String KEY_LAST_BAD_PATTERN_RETRY = "last_bad_pattern_retry";
private static final int MAX_RETRY_TIMES = 5;
private int mRetryTimes = 0;
@SuppressWarnings("ConstantConditions")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_enter_pattern);
// Set random color
int themeColor = Config.getCustomThemeColor() ? Config.getThemeColor() : Ui.THEME_COLOR;
getActionBar().setBackgroundDrawable(new ColorDrawable(themeColor));
Ui.colorStatusBarL(this, themeColor);
// Menu
MaterialIndicatorDrawable materialIndicator = new MaterialIndicatorDrawable(this, Color.WHITE, MaterialIndicatorDrawable.Stroke.THIN);
materialIndicator.setIconState(MaterialIndicatorDrawable.IconState.ARROW);
Ui.setMaterialIndicator(getActionBar(), materialIndicator);
// Can't try if bad retry happened in 10 mins
long lastBadRetry = Config.getLong(KEY_LAST_BAD_PATTERN_RETRY, 0);
if (System.currentTimeMillis() - lastBadRetry < 1000 * 60 * 10) {
mRetryTimes = 10;
}
final TextView textView = (TextView) findViewById(R.id.text);
LockPatternView patternView = (LockPatternView) findViewById(R.id.pattern_view);
patternView.setOnPatternListener(new LockPatternView.OnPatternListener() {
@Override
public void onPatternStart() {
}
@Override
public void onPatternCleared() {
}
@Override
public void onPatternCellAdded(List<LockPatternView.Cell> pattern) {
}
@Override
public void onPatternDetected(List<LockPatternView.Cell> pattern) {
if (mRetryTimes > MAX_RETRY_TIMES) {
textView.setText(R.string.no_more_retries);
Config.setLong(KEY_LAST_BAD_PATTERN_RETRY, System.currentTimeMillis());
} else {
String enterPatter = LockPatternUtils.patternToString(pattern);
if (enterPatter.equals(Config.getPatternProtection())) {
setResult(RESULT_OK);
finish();
} else {
textView.setText(R.string.error_pattern);
}
}
mRetryTimes++;
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}
@@ -1,596 +0,0 @@
/*
* Copyright (C) 2014 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.ui;
import android.annotation.TargetApi;
import android.app.Dialog;
import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TextView;
import com.hippo.ehviewer.AppHandler;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.app.DirSelectDialog;
import com.hippo.ehviewer.app.MaterialAlertDialog;
import com.hippo.ehviewer.data.Data;
import com.hippo.ehviewer.data.GalleryInfo;
import com.hippo.ehviewer.ehclient.ExDownloader;
import com.hippo.ehviewer.gallery.GalleryView;
import com.hippo.ehviewer.gallery.data.ImageSet;
import com.hippo.ehviewer.gallery.ui.GLRootView;
import com.hippo.ehviewer.util.Config;
import com.hippo.ehviewer.util.FullScreenHelper;
import com.hippo.ehviewer.util.MathUtils;
import com.hippo.ehviewer.util.Messenger;
import com.hippo.ehviewer.util.Utils;
import com.hippo.ehviewer.widget.ColorView;
import com.hippo.ehviewer.widget.MaterialToast;
import com.hippo.ehviewer.widget.SlidingLayout;
import java.io.File;
public class GalleryActivity extends StatsActivity
implements GalleryView.GalleryViewListener, SeekBar.OnSeekBarChangeListener,
FullScreenHelper.OnFullScreenBrokenListener, CompoundButton.OnCheckedChangeListener,
SlidingLayout.OnChildHideListener, AdapterView.OnItemSelectedListener,
View.OnClickListener, Utils.OnCopyOverListener, Messenger.Receiver {
@SuppressWarnings("unused")
private final static String TAG = GalleryActivity.class.getSimpleName();
public final static String KEY_GALLERY_INFO = "gallery_info";
public final static String KEY_START_INDEX = "start_index";
public final static String KEY_LIGHTNESS = "lightness";
public final static float DEFAULT_LIGHTNESS = 0.5f;
public final static String KEY_FIRST_READ_CONFIG_V1 = "first_read_config_v1";
public final static boolean DEFAULT_FIRST_READ_CONFIG_V1 = true;
public final static String KEY_LAST_SAVE_IMAGE_FILE_PATH = "last_save_image_file_path";
public final static String DEFAULT_LAST_SAVE_IMAGE_FILE_PATH = null;
private View mClock;
private View mBattery;
private SlidingLayout mConfigSliding;
/** It store index, start from 0, so max is samller than size **/
private TextView mCurrentPage;
private TextView mPageSum;
private SeekBar mPageSeeker;
private TextView mRefresh;
private TextView mSend;
private TextView mMoreSettings;
private Spinner mReadingDirection;
private Spinner mPageScaling;
private Spinner mStartPosition;
private CheckBox mKeepScreenOn;
private CheckBox mShowClock;
private CheckBox mShowBattery;
private CheckBox mCustomLightness;
private SeekBar mCustomLightnessValue;
private CheckBox mCustomCodec;
private Spinner mDecodeFormat;
private ImageSet mImageSet;
private GalleryView mGalleryView;
private ColorView mMaskView;
private GalleryInfo mGi;
private FullScreenHelper mFullScreenHelper;
private File mCurImageFile;
private Dialog mSendDialog;
private boolean mVolumePage;
private final Runnable mFullScreenTask = new Runnable() {
@Override public void run() {
mFullScreenHelper.setFullScreen(true);
}
};
private void startFullScreenTask() {
AppHandler.getInstance().postDelayed(mFullScreenTask, 2000);
}
private void cancelFullScreenTask() {
AppHandler.getInstance().removeCallbacks(mFullScreenTask);
}
@Override
public void onCopyOver(boolean success, File src, File dst) {
MaterialToast.showToast(success ? String.format(getString(R.string.save_successful), dst.getPath()) : getString(R.string.save_failed));
if (success)
Config.setString(KEY_LAST_SAVE_IMAGE_FILE_PATH, dst.getParent());
}
private Dialog createSaveImageDialog() {
return DirSelectDialog.create(
new MaterialAlertDialog.Builder(GalleryActivity.this)
.setDrakTheme(true).setTitle(R.string.select_save_dir)
.setDefaultButton(MaterialAlertDialog.POSITIVE | MaterialAlertDialog.NEGATIVE)
.setButtonListener(new MaterialAlertDialog.OnClickListener() {
@Override
public boolean onClick(MaterialAlertDialog dialog, int which) {
if (which == MaterialAlertDialog.POSITIVE) {
String targetPath = ((DirSelectDialog) dialog).getCurrentPath();
StringBuilder sb = new StringBuilder();
sb.append(mImageSet.getTitle()).append("-").append(mGalleryView.getCurIndex() + 1)
.append(".").append(Utils.getExtension(mCurImageFile.getName(), "jpg"));
Utils.copyInNewThread(mCurImageFile, new File(targetPath, Utils.standardizeFilename(sb.toString())),
GalleryActivity.this);
}
return true;
}
}),
Config.getString(KEY_LAST_SAVE_IMAGE_FILE_PATH, null));
}
private Dialog createSendDialog() {
return new MaterialAlertDialog.Builder(this).setDrakTheme(true).setTitle(R.string.send)
.setItems(R.array.send_entries, new MaterialAlertDialog.OnClickListener() {
@Override
public boolean onClick(MaterialAlertDialog dialog, int which) {
// Check current image file again
if (mCurImageFile == null || !mCurImageFile.exists()) {
MaterialToast.showToast(R.string.current_image_not_downloaded);
return false;
}
switch (which) {
case 0:
createSaveImageDialog().show();
break;
case 1:
Uri uri = Uri.fromFile(mCurImageFile);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setType(Utils.getMimeType(uri.toString()));
startActivity(Intent.createChooser(shareIntent, getString(R.string.share_image)));
break;
}
return true;
}
}).setNegativeButton(android.R.string.cancel).create();
}
@Override
public void onFullScreenBroken(boolean fullScreen) {
// TODO For some MIUI system, onSystemUiVisibilityChange() do not work fine
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
@Override
protected void onResume() {
super.onResume();
updateState();
mFullScreenHelper.setFullScreen(!mConfigSliding.isShowing());
}
private void setScreenLightness(boolean enable, int lightness) {
Window w = getWindow();
WindowManager.LayoutParams lp = w.getAttributes();
if (enable) {
lightness = MathUtils.clamp(lightness, 0, 200);
if (lightness > 100) {
mMaskView.setColor(0);
// Avoid BRIGHTNESS_OVERRIDE_OFF,
// screen may be off when lp.screenBrightness is 0.0f
lp.screenBrightness = Math.max((lightness - 100) / 100.0f, 0.05f);
} else {
mMaskView.setColor(MathUtils.lerp(0xde, 0x00, lightness / 100.0f) << 24);
lp.screenBrightness = 0.05f;
}
} else {
mMaskView.setColor(0);
lp.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
}
w.setAttributes(lp);
}
private void updateState() {
mReadingDirection.setSelection(Config.getReadingDirection());
mPageScaling.setSelection(Config.getPageScaling());
mStartPosition.setSelection(Config.getStartPosition());
mGalleryView.setReadingDirection(Config.getReadingDirection());
mGalleryView.setPageScaling(Config.getPageScaling());
mGalleryView.setStartPosition(Config.getStartPosition());
mKeepScreenOn.setChecked(Config.getKeepSreenOn());
if (Config.getKeepSreenOn())
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
else
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mShowClock.setChecked(Config.getShowClock());
mShowBattery.setChecked(Config.getShowBattery());
mClock.setVisibility(Config.getShowClock() ? View.VISIBLE : View.GONE);
mBattery.setVisibility(Config.getShowBattery() ? View.VISIBLE : View.GONE);
mCustomLightness.setChecked(Config.getCustomLightness());
if (mCustomLightness.isChecked())
mCustomLightnessValue.setEnabled(true);
else
mCustomLightnessValue.setEnabled(false);
mCustomLightnessValue.setProgress(Config.getCustomLightnessValue());
setScreenLightness(mCustomLightness.isChecked(), mCustomLightnessValue.getProgress());
if (Utils.SUPPORT_IMAGE)
mCustomCodec.setEnabled(true);
else
mCustomCodec.setEnabled(false);
mCustomCodec.setChecked(Config.getCustomCodec());
if (Utils.SUPPORT_IMAGE && mCustomCodec.isChecked())
mDecodeFormat.setEnabled(true);
else
mDecodeFormat.setEnabled(false);
mDecodeFormat.setSelection(Config.getDecodeFormatIndex());
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gl_root_group);
mVolumePage = Config.getVolumePage();
Messenger.getInstance().register(Config.MESSENGER_ID_VOLUME_PAGE, this);
mFullScreenHelper = new FullScreenHelper(this);
mFullScreenHelper.setOnFullScreenBrokenListener(this);
mFullScreenHelper.setFullScreen(true);
mMaskView = (ColorView)findViewById(R.id.mask);
mClock = findViewById(R.id.clock);
mBattery = findViewById(R.id.battery);
mConfigSliding = (SlidingLayout) findViewById(R.id.config_sliding);
mCurrentPage = (TextView) mConfigSliding.findViewById(R.id.current_page);
mPageSum = (TextView) mConfigSliding.findViewById(R.id.page_sum);
mPageSeeker = (SeekBar) mConfigSliding.findViewById(R.id.page_seeker);
mRefresh = (TextView) mConfigSliding.findViewById(R.id.refresh);
mSend = (TextView) mConfigSliding.findViewById(R.id.send);
mMoreSettings = (TextView) mConfigSliding.findViewById(R.id.more_settings);
mReadingDirection = (Spinner) mConfigSliding.findViewById(R.id.reading_direction);
mPageScaling = (Spinner) mConfigSliding.findViewById(R.id.page_scaling);
mStartPosition = (Spinner) mConfigSliding.findViewById(R.id.start_position);
mKeepScreenOn = (CheckBox) mConfigSliding.findViewById(R.id.keep_screen_on);
mShowClock = (CheckBox) mConfigSliding.findViewById(R.id.gallery_show_clock);
mShowBattery = (CheckBox) mConfigSliding.findViewById(R.id.gallery_show_battery);
mCustomLightness = (CheckBox) mConfigSliding.findViewById(R.id.custom_lightness);
mCustomLightnessValue = (SeekBar) mConfigSliding.findViewById(R.id.custom_lightness_value);
mCustomCodec = (CheckBox) mConfigSliding.findViewById(R.id.custom_codec);
mDecodeFormat = (Spinner) mConfigSliding.findViewById(R.id.decode_format);
mConfigSliding.hide();
mSendDialog = createSendDialog();
Intent intent = getIntent();
mGi = intent.getParcelableExtra(KEY_GALLERY_INFO);
if (mGi == null) {
// Get error force finish
new MaterialAlertDialog.Builder(this).setTitle(R.string.error)
.setMessage(R.string.ga_data_error)
.setPositiveButton(R.string.close)
.setButtonListener(new MaterialAlertDialog.OnClickListener() {
@Override
public boolean onClick(MaterialAlertDialog dialog, int which) {
finish();
return true;
}
}).show();
} else {
Data.getInstance().addHistory(mGi, Data.READ);
int startIndex = intent.getIntExtra(KEY_START_INDEX, 0);
if (startIndex == -1)
startIndex = ExDownloader.readCurReadIndex(mGi.gid, mGi.title);
mImageSet = new ImageSet(mGi.gid, mGi.token, mGi.title, startIndex);
mGalleryView = new GalleryView(getApplicationContext(), mImageSet, startIndex);
GLRootView glrv= (GLRootView)findViewById(R.id.gl_root_view);
glrv.setContentPane(mGalleryView);
// Set listener
mConfigSliding.setOnChildHideListener(this);
mGalleryView.setGalleryViewListener(this);
mPageSeeker.setOnSeekBarChangeListener(this);
mRefresh.setOnClickListener(this);
mSend.setOnClickListener(this);
mMoreSettings.setOnClickListener(this);
mReadingDirection.setOnItemSelectedListener(this);
mPageScaling.setOnItemSelectedListener(this);
mStartPosition.setOnItemSelectedListener(this);
mDecodeFormat.setOnItemSelectedListener(this);
mKeepScreenOn.setOnCheckedChangeListener(this);
mShowClock.setOnCheckedChangeListener(this);
mShowBattery.setOnCheckedChangeListener(this);
mCustomLightness.setOnCheckedChangeListener(this);
mCustomLightnessValue.setOnSeekBarChangeListener(this);
mCustomCodec.setOnCheckedChangeListener(this);
mKeepScreenOn = (CheckBox) mConfigSliding.findViewById(R.id.keep_screen_on);
mShowClock = (CheckBox) mConfigSliding.findViewById(R.id.gallery_show_clock);
mShowBattery = (CheckBox) mConfigSliding.findViewById(R.id.gallery_show_battery);
mCustomCodec = (CheckBox) mConfigSliding.findViewById(R.id.custom_codec);
mPageSeeker.setMax(mGalleryView.getSize() - 1);
mPageSeeker.setProgress(startIndex);
mCurrentPage.setText(Integer.toString(startIndex + 1));
mPageSum.setText(Integer.toString(mGalleryView.getSize()));
onRightToLeftChanged(mGalleryView.isRightToLeft());
// Show first tip
String keyGalleryFirst = "gallery_first";
if (Config.getBoolean(keyGalleryFirst, true)) {
Config.setBoolean(keyGalleryFirst, false);
new MaterialAlertDialog.Builder(this).setDrakTheme(true).setTitle(R.string.tip)
.setMessage(R.string.gallery_tip)
.setNegativeButton(android.R.string.cancel)
.setButtonListener(new MaterialAlertDialog.OnClickListener() {
@Override
public boolean onClick(MaterialAlertDialog dialog, int which) {
mFullScreenHelper.setFullScreen(true);
return true;
}
}).show();
}
// Update state
updateState();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
Messenger.getInstance().unregister(Config.MESSENGER_ID_VOLUME_PAGE, this);
if (mImageSet != null)
mImageSet.free();
if (mGalleryView != null)
mGalleryView.free();
}
@Override
public void onBackPressed() {
if (mConfigSliding.isInHideAnimate())
return;
if (mConfigSliding.isShowing())
mConfigSliding.toBaseLevel();
else
finish();
}
@Override
public void onClick(View v) {
if (v == mRefresh) {
mImageSet.redownload(mGalleryView.getCurIndex());
} else if (v == mSend) {
mCurImageFile = mImageSet.getImageFile(mGalleryView.getCurIndex());
if (mCurImageFile == null || !mCurImageFile.exists())
MaterialToast.showToast(R.string.current_image_not_downloaded);
else
mSendDialog.show();
} else if (v == mMoreSettings) {
Intent intent = new Intent(GalleryActivity.this, SettingsActivity.class);
startActivity(intent);
}
}
@Override
public boolean onKeyDown (int keyCode, @NonNull KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (mVolumePage) {
mGalleryView.showNextPage();
return true;
} else {
break;
}
case KeyEvent.KEYCODE_VOLUME_UP:
if (mVolumePage) {
mGalleryView.showPreviousPage();
return true;
} else {
break;
}
case KeyEvent.KEYCODE_DPAD_LEFT:
case KeyEvent.KEYCODE_PAGE_UP:
mGalleryView.showPreviousPage();
return true;
case KeyEvent.KEYCODE_DPAD_RIGHT:
case KeyEvent.KEYCODE_PAGE_DOWN:
mGalleryView.showNextPage();
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onReceive(int id, Object obj) {
if (obj instanceof Boolean) {
mVolumePage = (Boolean) obj;
}
}
@Override
public void onTapCenter() {
if (!mConfigSliding.isShowing()) {
if (mFullScreenHelper.willHideNavBar())
cancelFullScreenTask();
mFullScreenHelper.setFullScreen(false);
boolean firstTime = Config.getBoolean(KEY_FIRST_READ_CONFIG_V1, DEFAULT_FIRST_READ_CONFIG_V1);
mConfigSliding.toReservedLevel(firstTime);
if (firstTime)
Config.setBoolean(KEY_FIRST_READ_CONFIG_V1, false);
}
}
@Override
public void onPageChanged(int index) {
mPageSeeker.setProgress(index);
mCurrentPage.setText(Integer.toString(index + 1));
}
@Override
public void onSizeUpdate(int size) {
mPageSeeker.setMax(size - 1);
mPageSeeker.setProgress(mGalleryView.getCurIndex() + 1);
mCurrentPage.setText(Integer.toString(mGalleryView.getCurIndex() + 1));
mPageSum.setText(Integer.toString(size));
}
@Override
public void onSlideBottom(float dx) {
// Empty
}
@Override
public void onSlideBottomOver() {
// Empty
}
@Override
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public void onRightToLeftChanged(boolean value) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
int nevLd = value ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;
if (mPageSeeker.getLayoutDirection() != nevLd) {
mPageSeeker.setLayoutDirection(nevLd);
}
}
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
if (seekBar == mPageSeeker) {
mCurrentPage.setText(Integer.toString(progress + 1));
} else if (seekBar == mCustomLightnessValue) {
setScreenLightness(mCustomLightness.isChecked(), progress);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// Empty
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
if (seekBar == mPageSeeker) {
mGalleryView.goToPage(seekBar.getProgress());
} else if (seekBar == mCustomLightnessValue) {
Config.setCustomLightnessValue(seekBar.getProgress());
}
}
@Override
public void onChildHide() {
if (mFullScreenHelper.willHideNavBar())
startFullScreenTask();
else
mFullScreenHelper.setFullScreen(true);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
if (parent == mReadingDirection) {
Config.setReadingDirection(mReadingDirection.getSelectedItemPosition());
mGalleryView.setReadingDirection(position);
} else if (parent == mPageScaling) {
Config.setPageScaling(mPageScaling.getSelectedItemPosition());
mGalleryView.setPageScaling(position);
} else if (parent == mStartPosition) {
Config.setStartPosition(mStartPosition.getSelectedItemPosition());
mGalleryView.setStartPosition(position);
} else if (parent == mDecodeFormat) {
Config.setDecodeFormatFromIndex(mDecodeFormat.getSelectedItemPosition());
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// Empty
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (buttonView == mShowClock) {
Config.setShowClock(isChecked);
mClock.setVisibility(isChecked ? View.VISIBLE : View.GONE);
} else if (buttonView == mShowBattery) {
Config.setShowBattery(isChecked);
mBattery.setVisibility(isChecked ? View.VISIBLE : View.GONE);
} else if (buttonView == mKeepScreenOn) {
Config.setKeepSreenOn(isChecked);
if (isChecked)
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
else
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
} else if (buttonView == mCustomLightness) {
Config.setCustomLightness(isChecked);
if (isChecked)
mCustomLightnessValue.setEnabled(true);
else
mCustomLightnessValue.setEnabled(false);
setScreenLightness(isChecked, mCustomLightnessValue.getProgress());
} else if (buttonView == mCustomCodec) {
Config.setCustomCodec(isChecked);
if (Utils.SUPPORT_IMAGE && mCustomCodec.isChecked())
mDecodeFormat.setEnabled(true);
else
mDecodeFormat.setEnabled(false);
}
}
}
@@ -1,82 +0,0 @@
package com.hippo.ehviewer.ui;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.drawable.MaterialIndicatorDrawable;
import com.hippo.ehviewer.util.Config;
import com.hippo.ehviewer.util.Ui;
import com.hippo.ehviewer.widget.LockPatternUtils;
import com.hippo.ehviewer.widget.LockPatternView;
public class PatternProtectionActivity extends AbsActivity implements View.OnClickListener{
private TextView mTextView;
private LockPatternView mPatternView;
private View mCancel;
private View mOK;
@SuppressWarnings("ConstantConditions")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pattern_protection);
// Set random color
int themeColor = Config.getCustomThemeColor() ? Config.getThemeColor() : Ui.THEME_COLOR;
getActionBar().setBackgroundDrawable(new ColorDrawable(themeColor));
Ui.colorStatusBarL(this, themeColor);
// Menu
MaterialIndicatorDrawable materialIndicator = new MaterialIndicatorDrawable(this, Color.WHITE, MaterialIndicatorDrawable.Stroke.THIN);
materialIndicator.setIconState(MaterialIndicatorDrawable.IconState.ARROW);
Ui.setMaterialIndicator(getActionBar(), materialIndicator);
mTextView = (TextView) findViewById(R.id.text);
mPatternView = (LockPatternView) findViewById(R.id.pattern_view);
mCancel = findViewById(R.id.cancel);
mOK = findViewById(R.id.ok);
mOK.setOnClickListener(this);
mCancel.setOnClickListener(this);
String pattern = Config.getPatternProtection();
boolean setPattern = LockPatternUtils.isPatternVaild(pattern);
Resources resources = getResources();
int patternProtectionStateId = setPattern ?
R.string.pattern_protection_set : R.string.pattern_protection_not_set;
mTextView.setText(resources.getString(patternProtectionStateId) + "\n\n" +
getString(R.string.pattern_protection_warning));
if (setPattern) {
mPatternView.setPattern(LockPatternView.DisplayMode.Correct, LockPatternUtils.stringToPattern(pattern));
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
if (v == mOK) {
Config.setPatternProtection(mPatternView.getPatternString());
finish();
} else if (v == mCancel) {
finish();
}
}
}
@@ -1,76 +0,0 @@
/*
* Copyright (C) 2014 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.ui;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.ImageView;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.effect.DrawableTransition;
import com.hippo.ehviewer.util.Secret;
import com.hippo.ehviewer.widget.MaterialToast;
import java.util.Arrays;
public class SecretActivity extends AbsActivity implements View.OnClickListener {
private final long[] mHits = new long[3];
private Bitmap mBmp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBmp = Secret.getSecretImage(this);
if (mBmp == null) {
finish();
return;
}
ImageView iv = new ImageView(this);
iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
iv.setImageBitmap(mBmp);
iv.setOnClickListener(this);
iv.setSoundEffectsEnabled(false);
setContentView(iv);
DrawableTransition.transit(iv.getDrawable(), false, 3000);
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mBmp != null) {
mBmp.recycle();
mBmp = null;
}
}
@Override
public void onClick(View v) {
System.arraycopy(mHits, 1, mHits, 0, mHits.length-1);
mHits[mHits.length-1] = SystemClock.uptimeMillis();
if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) {
Arrays.fill(mHits, 0);
MaterialToast.showToast(R.string.photo_footnotes);
}
}
}
@@ -1,159 +0,0 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.ui;
import android.annotation.SuppressLint;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Debug;
import android.os.Handler;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
import com.hippo.ehviewer.AppHandler;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.util.Config;
import com.hippo.ehviewer.util.Constants;
import com.hippo.ehviewer.util.Messenger;
import java.util.Locale;
public abstract class StatsActivity extends AbsActivity {
private static final int DEFAULT_MESSAGE_SIZE = 128;
private static final long STATS_CLOCK_INTERVAL_MS = 1000;
private static final int BYTES_IN_MEGABYTE = 1024 * 1024;
private TextView mStatsTextView;
private boolean mShowStats;
private Runnable mStatsClockTickRunnable;
private Handler mHandler;
private Messenger.Receiver mReceiver = new Messenger.Receiver() {
@Override
public void onReceive(int id, Object obj) {
if (obj instanceof Boolean) {
boolean showStats = (Boolean) obj;
if (mShowStats != showStats) {
mShowStats = showStats;
ViewGroup vg = (ViewGroup) getWindow().getDecorView();
if (showStats) {
vg.addView(mStatsTextView, generateLayoutParams());
updateStats();
scheduleNextStatsClockTick();
} else {
vg.removeView(mStatsTextView);
cancelNextStatsClockTick();
}
}
}
}
};
@SuppressLint("RtlHardcoded")
private ViewGroup.LayoutParams generateLayoutParams() {
Resources resources = getResources();
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.TOP | Gravity.RIGHT;
lp.topMargin = resources.getDimensionPixelOffset(R.dimen.stats_text_view_padding_top);
lp.rightMargin = resources.getDimensionPixelOffset(R.dimen.stats_text_view_padding_right);
return lp;
}
private boolean isShowStats() {
return Config.getShowApplicationStats();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mStatsTextView = new TextView(this);
mHandler = AppHandler.getInstance();
mStatsClockTickRunnable = new Runnable() {
@Override
public void run() {
updateStats();
scheduleNextStatsClockTick();
}
};
Messenger.getInstance().register(
Constants.MESSENGER_ID_SHOW_APP_STATUS, mReceiver);
if (isShowStats()) {
mShowStats = true;
((ViewGroup) getWindow().getDecorView()).addView(mStatsTextView,
generateLayoutParams());
} else {
mShowStats = false;
}
}
@Override
protected void onDestroy() {
super.onDestroy();
Messenger.getInstance().unregister(Constants.MESSENGER_ID_SHOW_APP_STATUS, mReceiver);
}
@Override
protected void onResume() {
super.onResume();
if (mShowStats) {
updateStats();
scheduleNextStatsClockTick();
}
}
@Override
protected void onPause() {
super.onPause();
if (mShowStats) {
cancelNextStatsClockTick();
}
}
private void scheduleNextStatsClockTick() {
mHandler.postDelayed(mStatsClockTickRunnable, STATS_CLOCK_INTERVAL_MS);
}
private void cancelNextStatsClockTick() {
mHandler.removeCallbacks(mStatsClockTickRunnable);
}
private void updateStats() {
final Runtime runtime = Runtime.getRuntime();
final long heapMemory = runtime.totalMemory() - runtime.freeMemory();
final StringBuilder sb = new StringBuilder(DEFAULT_MESSAGE_SIZE);
appendSize(sb, "Java heap size: ", heapMemory, "\n");
appendSize(sb, "Native heap size: ", Debug.getNativeHeapAllocatedSize(), "\n");
mStatsTextView.setText(sb.toString());
}
private static void appendSize(StringBuilder sb, String prefix, long bytes, String suffix) {
String value = String.format(Locale.getDefault(), "%.2f", (float) bytes / BYTES_IN_MEGABYTE);
appendValue(sb, prefix, value + " MB", suffix);
}
private static void appendValue(StringBuilder sb, String prefix, String value, String suffix) {
sb.append(prefix).append(value).append(suffix);
}
}
@@ -1,65 +0,0 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.ui;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.webkit.CookieManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.hippo.ehviewer.ehclient.EhClient;
import com.hippo.ehviewer.ehclient.EhInfo;
public class WebViewLoginActivity extends AbsActivity {
private static final String TITLE_LOGIN_SUCCESS = "Please stand by...";
public static final String KEY_ERROR = "error";
@SuppressLint("SetJavaScriptEnabled")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView wv = new WebView(this);
CookieManager.getInstance().removeAllCookie();
wv.getSettings().setJavaScriptEnabled(true);
wv.setWebViewClient(new LoginWebViewClient());
wv.loadUrl(EhClient.LOGIN_URL);
setContentView(wv);
}
private class LoginWebViewClient extends WebViewClient {
@Override
public void onPageFinished(WebView view, String url) {
if (TITLE_LOGIN_SUCCESS.equals(view.getTitle())) {
// Login OK
String cookies = CookieManager.getInstance().getCookie(url);
if (cookies != null) {
// Store cookie
EhInfo ehInfo = EhInfo.getInstance(WebViewLoginActivity.this);
ehInfo.setCookie(cookies);
ehInfo.login("User", "User");
setResult(RESULT_OK);
} else {
setResult(RESULT_CANCELED);
}
finish();
}
}
}
}
@@ -1,30 +0,0 @@
/*
* Copyright (C) 2014 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.util;
import android.animation.Animator;
import android.animation.ValueAnimator;
public final class AnimatorUtils {
public static Animator createDelayAnimator(long delay) {
Animator anim = ValueAnimator.ofFloat(0f, 1f);
anim.setDuration(delay);;
return anim;
}
}
@@ -1,62 +0,0 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.util;
import android.os.Environment;
import android.support.annotation.Nullable;
import java.io.File;
/**
* Something about this app
*/
public final class AppConfig {
private static final String APP_DIRNAME = "EhViewer";
private static final String CRASH_DIRNAME = "crash";
private static final String DOWNLOAD_DIRNAME = "download";
private static final String TORRENT_DIRNAME = "torrent";
public static @Nullable File getAppDir() {
if (Environment.getExternalStorageState()
.equals(Environment.MEDIA_MOUNTED)) {
return new File(Environment.getExternalStorageDirectory(), APP_DIRNAME);
} else {
return null;
}
}
public static @Nullable File getFileInAppDir(String filename) {
File appFolder = getAppDir();
if (appFolder != null) {
return new File(appFolder, filename);
} else {
return null;
}
}
public static @Nullable File getCrashDir() {
return getFileInAppDir(CRASH_DIRNAME);
}
public static @Nullable File getDownloadDir() {
return getFileInAppDir(DOWNLOAD_DIRNAME);
}
public static @Nullable File getTorrentDir() {
return getFileInAppDir(TORRENT_DIRNAME);
}
}
@@ -1,32 +0,0 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.util;
public final class IntIdGenerator {
private int mId = 0;
private IntIdGenerator() {
// Empty
}
public synchronized int nextId() {
return mId++;
}
public static IntIdGenerator create() {
return new IntIdGenerator();
}
}
@@ -1,87 +0,0 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.util;
import android.util.SparseArray;
import com.hippo.ehviewer.AppHandler;
import java.util.HashSet;
import java.util.Set;
public class Messenger {
private IntIdGenerator mIdGenerator;
private SparseArray<Set<Receiver>> mReceiverSetMap;
private static Messenger sInstance;
public static Messenger getInstance() {
if (sInstance == null) {
sInstance = new Messenger();
}
return sInstance;
}
private Messenger() {
mIdGenerator = IntIdGenerator.create();
mReceiverSetMap = new SparseArray<>();
}
public int newId() {
return mIdGenerator.nextId();
}
public void notify(final int id, final Object obj) {
// Make sure do it in UI thread
AppHandler.getInstance().post(new Runnable() {
@Override
public void run() {
Set<Receiver> receiverSet = mReceiverSetMap.get(id);
if (receiverSet != null) {
for (Receiver receiver : receiverSet) {
receiver.onReceive(id, obj);
}
}
}
});
}
public void register(int id, Receiver receiver) {
Set<Receiver> receiverSet = mReceiverSetMap.get(id);
if (receiverSet == null) {
receiverSet = new HashSet<>();
mReceiverSetMap.put(id, receiverSet);
}
receiverSet.add(receiver);
}
public void unregister(int id, Receiver receiver) {
Set<Receiver> receiverSet = mReceiverSetMap.get(id);
if (receiverSet != null) {
receiverSet.remove(receiver);
if (receiverSet.isEmpty()) {
mReceiverSetMap.remove(id);
}
}
}
public interface Receiver {
void onReceive(final int id, final Object obj);
}
}
@@ -1,28 +0,0 @@
package com.hippo.ehviewer.util;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
public final class PackageUtils {
private static final String TAG = PackageUtils.class.getSimpleName();
public static String getSignature(Context context, String packageName) {
try {
@SuppressLint("PackageManagerGetSignatures")
PackageInfo pi = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
Signature[] ss = pi.signatures;
if (ss != null && ss.length >= 1) {
return Utils.computeSHA1(ss[0].toByteArray());
} else {
Log.e(TAG, "Can't find signature in package " + packageName);
}
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Can't find package " + packageName, e);
}
return null;
}
}
@@ -1,89 +0,0 @@
/*
* Copyright (C) 2014 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.util;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import com.hippo.ehviewer.network.HttpHelper;
import java.io.File;
public final class Secret {
private static final String DIR_NAME = "images";
private static final String IMAGE_NAME = "sercet.jpg";
private static final String SERCET_IMAGE_URL = "http://www.ehviewer.com/static/images/pandas.jpg";
private static volatile boolean sIsGetSecretImage = false;
public static void updateSecretImage(Context context) {
if (sIsGetSecretImage)
return;
sIsGetSecretImage = true;
new UpdateSercetImageThread(context).start();
}
public static boolean hasSecretImage(Context context) {
if (sIsGetSecretImage)
return false;
File dir = context.getExternalFilesDir(DIR_NAME);
File image = new File(dir, IMAGE_NAME);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
BitmapFactory.decodeFile(image.getAbsolutePath(), opts);
return opts.outWidth > 0 && opts.outHeight > 0;
}
public static Bitmap getSecretImage(Context context) {
if (sIsGetSecretImage)
return null;
File dir = context.getExternalFilesDir(DIR_NAME);
File image = new File(dir, IMAGE_NAME);
return BitmapFactory.decodeFile(image.getAbsolutePath(), null);
}
private static class UpdateSercetImageThread extends BgThread {
private final Context mContext;
public UpdateSercetImageThread(Context context) {
mContext = context;
}
@Override
public void run() {
// TODO check usable space
File dir = mContext.getExternalFilesDir(DIR_NAME);
File image = new File(dir, IMAGE_NAME);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
BitmapFactory.decodeFile(image.getAbsolutePath(), opts);
if (opts.outWidth <= 0 || opts.outHeight <= 0) {
// Get image error, try to get image from internet
HttpHelper hh = new HttpHelper(mContext);
hh.download(SERCET_IMAGE_URL, mContext.getExternalFilesDir(DIR_NAME),
IMAGE_NAME, null, null, null);
}
sIsGetSecretImage = false;
}
}
}
@@ -1,59 +0,0 @@
/*
* Copyright (C) 2014 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
public class ColorView extends View {
private int mColor;
public ColorView(Context context) {
super(context);
}
public ColorView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ColorView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ColorView(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public void setColor(int color) {
if (mColor != color) {
mColor = color;
invalidate();
}
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(mColor);
}
}
@@ -1,115 +0,0 @@
/*
* Copyright (C) 2014 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.util.Ui;
public class DrawerListView extends ListView {
private Context mContext;
private DrawerListAdapter mAdapter;
private static final int DRAWABLE_SIDE = Ui.dp2pix(24);
public DrawerListView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public DrawerListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public DrawerListView(Context context, AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context);
}
private void init(Context context) {
mContext = context;
mAdapter = new DrawerListAdapter();
setAdapter(mAdapter);
}
public void setData(Drawable[] drawableArray, CharSequence[] titleArray) {
mAdapter.setData(drawableArray, titleArray);
}
private class DrawerListAdapter extends BaseAdapter {
private Drawable[] mDrawableArray;
private CharSequence[] mTitleArray;
private void setData(Drawable[] drawableArray, CharSequence[] titleArray) {
if (drawableArray != null && titleArray != null) {
if (drawableArray.length != titleArray.length)
throw new java.lang.IllegalStateException("drawableArray.length != titleArray.length");
} else if (drawableArray == null && titleArray == null) {
throw new java.lang.IllegalStateException("drawableArray and titleArray should be all null or not null");
}
mDrawableArray = drawableArray;
mTitleArray = titleArray;
notifyDataSetChanged();
}
@Override
public int getCount() {
return mTitleArray == null ? 0 : mTitleArray.length;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null)
convertView = LayoutInflater.from(mContext).inflate(R.layout.drawer_list_item, parent, false);
TextView tv = (TextView) convertView;
Drawable d = mDrawableArray[position];
CharSequence t = mTitleArray[position];
tv.setText(t);
d.setBounds(0, 0, DRAWABLE_SIDE, DRAWABLE_SIDE);
tv.setCompoundDrawables(d, null, null, null);
return convertView;
}
}
}
@@ -1,151 +0,0 @@
package com.hippo.ehviewer.widget;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import com.hippo.ehviewer.R;
public class FloatingActionButton extends View {
@SuppressWarnings("unused")
private static final String TAG = FloatingActionButton.class.getSimpleName();
private final Paint mButtonPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Paint mDrawablePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Bitmap mBitmap;
private int mColor;
private final int mDrawableSide;
private final float mShadowRadius;
private final float mShadowDx;
private final float mShadowDy;
private int mCircleX;
private int mCircleY;
private int mCircleRadius;
private final Rect mSrc = new Rect();
private final RectF mDst = new RectF();
public FloatingActionButton(Context context) {
this(context, null);
}
public FloatingActionButton(Context context, AttributeSet attributeSet) {
this(context, attributeSet, 0);
}
public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton);
mDrawableSide = a.getDimensionPixelSize(R.styleable.FloatingActionButton_fabDrawableSide, 72);
mColor = a.getColor(R.styleable.FloatingActionButton_fabColor, Color.WHITE);
mButtonPaint.setStyle(Paint.Style.FILL);
mButtonPaint.setColor(mColor);
mShadowRadius = a.getDimension(R.styleable.FloatingActionButton_fabShadowRadius, 10.0f);
mShadowDx = a.getDimension(R.styleable.FloatingActionButton_fabShadowDx, 0.0f);
mShadowDy = a.getDimension(R.styleable.FloatingActionButton_fabShadowDy, 3.0f);
int shadowColor = a.getColor(R.styleable.FloatingActionButton_fabShadowColor, 0x8a000000);
mButtonPaint.setShadowLayer(mShadowRadius, mShadowDx, mShadowDy, shadowColor);
Drawable drawable = a.getDrawable(R.styleable.FloatingActionButton_fabDrawable);
if (drawable != null && drawable instanceof BitmapDrawable)
mBitmap = ((BitmapDrawable) drawable).getBitmap();
a.recycle();
setWillNotDraw(false);
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
public void setColor(int color) {
mColor = color;
mButtonPaint.setColor(mColor);
invalidate();
}
public void setDrawable(Drawable drawable) {
mBitmap = ((BitmapDrawable) drawable).getBitmap();
updateValue();
invalidate();
}
public static int getDefaultSize(int size, int measureSpec) {
int result = size;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
switch (specMode) {
case MeasureSpec.UNSPECIFIED:
case MeasureSpec.AT_MOST:
result = size;
break;
case MeasureSpec.EXACTLY:
result = specSize;
break;
}
return result;
}
private void updateValue() {
float half = Math.min(getWidth(), getHeight()) / 2;
mCircleX = (int) (half - mShadowDx);
mCircleY = (int) (half - mShadowDy);
mCircleRadius = (int) (half - mShadowRadius);
float halfDrawableSide = mDrawableSide / 2.0f;
if (mBitmap != null) {
mSrc.set(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
mDst.set(mCircleX - halfDrawableSide, mCircleY - halfDrawableSide, mCircleX + halfDrawableSide, mCircleY + halfDrawableSide);
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),
getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
updateValue();
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawCircle(mCircleX, mCircleY, mCircleRadius, mButtonPaint);
if (null != mBitmap)
canvas.drawBitmap(mBitmap, mSrc, mDst, mDrawablePaint);
}
@Override
@SuppressLint("ClickableViewAccessibility")
public boolean onTouchEvent(MotionEvent event) {
int color;
if (event.getAction() == MotionEvent.ACTION_UP) {
color = mColor;
} else {
color = darkenColor(mColor);
}
mButtonPaint.setColor(color);
invalidate();
return super.onTouchEvent(event);
}
public static int darkenColor(int color) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
hsv[2] *= 0.8f;
return Color.HSVToColor(hsv);
}
}
@@ -1,826 +0,0 @@
/*
* Copyright (C) 2014 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.os.Build;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
import com.hippo.ehviewer.AppHandler;
import com.hippo.ehviewer.ImageLoader;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.cache.ImageCache;
import com.hippo.ehviewer.cardview.CardViewSalon;
import com.hippo.ehviewer.data.GalleryInfo;
import com.hippo.ehviewer.ehclient.ListParser;
import com.hippo.ehviewer.util.Config;
import com.hippo.ehviewer.util.Ui;
import com.hippo.ehviewer.util.ViewUtils;
import com.hippo.ehviewer.widget.recyclerview.EasyRecyclerView;
import com.hippo.ehviewer.widget.recyclerview.MarginItemDecoration;
import com.hippo.ehviewer.widget.refreshlayout.RefreshLayout;
import java.util.ArrayList;
import java.util.List;
public class GalleryListView extends FrameLayout implements RefreshLayout.OnHeaderRefreshListener,
RefreshLayout.OnFooterRefreshListener {
private static final String TAG = GalleryListView.class.getSimpleName();
public static final int LIST_MODE_DETAIL = 0;
public static final int LIST_MODE_THUMB = 1;
private static final int MODE_REFRESH = 0;
private static final int MODE_NEXT_PAGE = 1;
private static final int MODE_PRE_PAGE = 2;
private static final int MODE_SOMEWHERE = 3;
private Context mContext;
private GalleryListViewHelper mHelper;
private List<GalleryInfo> mGiList;
private RefreshLayout mRefreshLayout;
private EasyRecyclerView mEasyRecyclerView;
private RefreshTextView mRefreshTextView;
private int mListMode = LIST_MODE_DETAIL;
private GalleryAdapter mAdapter;
private StaggeredGridLayoutManager mLayoutManager;
private MarginItemDecoration mItemDecoration;
private final int[] mFirstPositionTemp = new int[50]; // TODO
private long mTaskStamp;
/**
* First index of current page
*/
private int mFirstIndex;
/**
* Last index of current page
*/
private int mLastIndex;
private int mCurPage;
private int mFirstPage = 0;
private int mLastPage = 0;
/**
* The number of page in sum
*/
private int mPageNum;
private int mItemPerPage;
private int mGetMode;
private OnGetListListener mListener;
/**
* If true, list will make showed item not changed after get
*/
private boolean mIsKeepPosition;
private int mTargetPage;
private String mTargetUrl;
private boolean isFootRefresh = false;
private LayoutInflater mInflater;
private int mListDetailThumbWidth;
private int mListDetailThumbHeight;
private int mOldPaddingBottom;
public GalleryListView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0, 0);
}
public GalleryListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs, defStyleAttr, 0);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public GalleryListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs, defStyleAttr, defStyleRes);
}
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
mContext = context;
mGiList = new ArrayList<>();
mListener = new OnGetGalleryListListener();
LayoutInflater.from(mContext).inflate(R.layout.gallery_list_view, this);
mRefreshLayout = (RefreshLayout) findViewById(R.id.refresh_layout);
mEasyRecyclerView = (EasyRecyclerView) mRefreshLayout.findViewById(R.id.easy_recycler_view);
mRefreshTextView = (RefreshTextView) findViewById(R.id.refresh_text);
mAdapter = new GalleryAdapter(mContext, mGiList);
mLayoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
mItemDecoration = new MarginItemDecoration();
mEasyRecyclerView.setOnScrollListener(new OnScrollListener());
mEasyRecyclerView.setClipToPadding(false);
mEasyRecyclerView.setAdapter(mAdapter);
mEasyRecyclerView.setLayoutManager(mLayoutManager);
mEasyRecyclerView.addItemDecoration(mItemDecoration);
mEasyRecyclerView.setItemAnimator(new DefaultItemAnimator());
mEasyRecyclerView.setHasFixedSize(true);
setItemMargin(Ui.dp2pix(8)); // TODO for tablet margin should be greater
mRefreshTextView.setDefaultRefresh(R.string.click_retry, new RefreshTextView.OnRefreshListener() {
@Override
public void onRefresh() {
retry();
}
});
mRefreshLayout.setHeaderEnable(true);
mRefreshLayout.setFooterEnable(true);
mRefreshLayout.setHeaderColorSchemeResources(
R.color.refresh_color_1,
R.color.refresh_color_2,
R.color.refresh_color_3,
R.color.refresh_color_4
);
mRefreshLayout.setFooterColorSchemeResources(
R.color.refresh_color_1,
R.color.refresh_color_2,
R.color.refresh_color_3,
R.color.refresh_color_4
);
mRefreshLayout.setOnHeaderRefreshListener(this);
mRefreshLayout.setOnFooterRefreshListener(this);
mOldPaddingBottom = mEasyRecyclerView.getPaddingBottom();
// Caculate gallery detail height
mInflater = LayoutInflater.from(mContext);
View v = mInflater.inflate(R.layout.test_gallery_list_detail_thumb, null);
((TextView) v.findViewById(R.id.title)).setText("haha\nhaha");
((TextView) v.findViewById(R.id.uploader)).setText("haha");
((RatingView) v.findViewById(R.id.rate)).setRating(2.3f);
((TextView) v.findViewById(R.id.category)).setText("haha");
ViewUtils.measureView(v, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
mListDetailThumbHeight = Math.max(v.getMeasuredHeight(), Ui.dp2pix(120));
mListDetailThumbWidth = mListDetailThumbHeight * 2 / 3;
}
public int getListMode() {
return mListMode;
}
public void setListMode(int listMode) {
if (mListMode != listMode) {
mListMode = listMode;
// Update span
updateSpanCount();
mAdapter.notifyDataSetChanged();
}
}
private boolean isLandscape() {
return getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
}
private static final String[] KEY_SPAN_COUNT_ARRAY = {
"list_detail_columns_portrait", "list_detail_columns_landscape",
"list_thumb_columns_portrait", "list_thumb_columns_landscape"
};
private static final int[] DEFAULT_SPAN_COUNT_ARRAY = {
1, 2, 3, 5
};
public void updateSpanCount() {
int index = mListMode * 2 + (isLandscape() ? 1 : 0);
try {
mLayoutManager.setSpanCount(Config.getInt(KEY_SPAN_COUNT_ARRAY[index],
DEFAULT_SPAN_COUNT_ARRAY[index]));
} catch (Throwable e) {
e.printStackTrace();
}
}
public EasyRecyclerView getEasyRecyclerView() {
return mEasyRecyclerView;
}
public GalleryAdapter getGalleryAdapter() {
return mAdapter;
}
public void setGalleryListViewHelper(GalleryListViewHelper h) {
mHelper = h;
}
public void setPaddingTopAndBottom(int top, int bottom) {
setPadding(getPaddingLeft(), top, getPaddingRight(), getPaddingBottom());
mEasyRecyclerView.setPadding(mEasyRecyclerView.getPaddingLeft(), mEasyRecyclerView.getPaddingTop(),
mEasyRecyclerView.getPaddingRight(), mOldPaddingBottom + bottom);
}
private void setItemMargin(int margin) {
int halfMargin = margin / 2;
mItemDecoration.setMargin(margin);
mEasyRecyclerView.setPadding(halfMargin, halfMargin,
halfMargin, halfMargin);
}
public void setEnabledHeader(boolean enabled) {
mRefreshLayout.setHeaderEnable(enabled);
}
public void setEnabledFooter(boolean enabled) {
mRefreshLayout.setFooterEnable(enabled);
}
public void setHeaderRefreshing(boolean refreshing) {
mRefreshLayout.setHeaderRefreshing(refreshing);
}
public void setOnItemClickListener(EasyRecyclerView.OnItemClickListener l) {
mEasyRecyclerView.setOnItemClickListener(l);
}
public void setOnItemLongClickListener(EasyRecyclerView.OnItemLongClickListener l) {
mEasyRecyclerView.setOnItemLongClickListener(l);
}
public void setChoiceMode(int choiceMode) {
mEasyRecyclerView.setChoiceMode(choiceMode);
}
public void setMultiChoiceModeListener(EasyRecyclerView.MultiChoiceModeListener listener) {
mEasyRecyclerView.setMultiChoiceModeListener(listener);
}
public void addOnItemTouchListener(RecyclerView.OnItemTouchListener listener) {
mEasyRecyclerView.addOnItemTouchListener(listener);
}
public void notifyDataSetChanged() {
mAdapter.notifyDataSetChanged();
}
public void setNoneText(CharSequence text) {
mRefreshTextView.setVisibility(View.VISIBLE);
mRefreshTextView.setEmesg(text, false);
}
public void onlyShowList() {
mRefreshLayout.setVisibility(View.VISIBLE);
mRefreshTextView.setRefreshing(false);
mRefreshTextView.setVisibility(View.GONE);
}
public void onlyShowNone() {
mRefreshLayout.setVisibility(View.GONE);
mRefreshTextView.setVisibility(View.VISIBLE);
mRefreshTextView.setEmesg(R.string.none, false);
}
private void getGallerys() {
setGallerysLayout();
mTaskStamp = System.currentTimeMillis();
mHelper.doGetGallerys(mTargetUrl, mTaskStamp, mListener);
}
@Override
public void onHeaderRefresh() {
// It is invokened by user pull, so no need to
if (mFirstPage > 0) {
getPrePage(true);
} else {
refresh();
}
}
@Override
public boolean onFooterRefresh() {
if (!isRefreshing() && mLastPage < mPageNum - 1) {
isFootRefresh = true;
getNextPage(true);
isFootRefresh = false;
return true;
} else {
return false;
}
}
public void firstTimeRefresh() {
// set mPullViewGroup gone, make wait view show
mRefreshLayout.setVisibility(View.GONE);
mRefreshTextView.setVisibility(View.VISIBLE);
mRefreshTextView.setRefreshing(true);
refresh();
}
private void setGallerysLayout() {
if (mRefreshLayout.getVisibility() == View.VISIBLE) {
if (!isFootRefresh)
mRefreshLayout.setHeaderRefreshing(true);
mRefreshTextView.setVisibility(View.GONE);
} else {
mRefreshLayout.setVisibility(View.GONE);
mRefreshTextView.setVisibility(View.VISIBLE);
mRefreshTextView.setRefreshing(true);
}
}
protected boolean retry() {
// Need to update url, because mode may be changed
mTargetUrl = mHelper.getTargetUrl(mTargetPage);
getGallerys();
return true;
}
/**
* Go to page 0.<br>
* You should know you can refresh or not.
*/
public void refresh() {
mGetMode = MODE_REFRESH;
mTargetPage = 0;
mTargetUrl = mHelper.getTargetUrl(mTargetPage);
mIsKeepPosition = false;
getGallerys();
}
/**
* Get previous page.<br>
* You should know you can get previous page or not
*
* @param isKeepPosition
*/
protected void getPrePage(boolean isKeepPosition) {
mGetMode = MODE_PRE_PAGE;
mTargetPage = mFirstPage - 1;
mTargetUrl = mHelper.getTargetUrl(mTargetPage);
mIsKeepPosition = isKeepPosition;
getGallerys();
}
/**
* Get next page.<br>
* You should know you can get next page or not
*
* @param isKeepPosition
*/
protected void getNextPage(boolean isKeepPosition) {
mGetMode = MODE_NEXT_PAGE;
mTargetPage = mLastPage + 1;
mTargetUrl = mHelper.getTargetUrl(mTargetPage);
mIsKeepPosition = isKeepPosition;
getGallerys();
}
/**
* Get some page.<br>
* You should know you can get that page or not
*
* @param page
*/
protected void getSomewhere(int page) {
mGetMode = MODE_SOMEWHERE;
mTargetPage = page;
mTargetUrl = mHelper.getTargetUrl(mTargetPage);
mIsKeepPosition = false;
getGallerys();
}
public void jumpTo(int page) {
if (page >= mFirstPage && page <= mLastPage) {
int position = (page - mFirstPage) * mItemPerPage;
mLayoutManager.scrollToPosition(position);
} else if (page == mFirstPage - 1) {
getPrePage(false);
} else if (page == mLastPage + 1) {
getNextPage(false);
} else {
getSomewhere(page);
}
}
/**
* @return True if actionbar or footer is refreshing
*/
public boolean isRefreshing() {
return mRefreshLayout.isRefreshing();
}
public boolean isGetGalleryOk() {
return mRefreshLayout.getVisibility() == View.VISIBLE;
}
public int getPageNum() {
return mPageNum;
}
public int getCurPage() {
return mCurPage;
}
public List<GalleryInfo> getGalleryList() {
return mGiList;
}
public GalleryInfo getGalleryInfo(int position) {
return mGiList.get(position);
}
public GalleryInfo removeGalleryInfo(int position) {
return mGiList.remove(position);
}
public static interface OnGetListListener {
public void onSuccess(long taskStamp, List<GalleryInfo> gis, int maxPage);
public void onFailure(long taskStamp, String eMsg);
}
private class OnGetGalleryListListener implements OnGetListListener, Runnable {
@Override
public void run() {
int preIndex = mLayoutManager.findFirstVisibleItemPositions(mFirstPositionTemp)[0] - 1;
if (preIndex >= 0)
mEasyRecyclerView.smoothScrollToPosition(preIndex);
}
public void smoothScrollToPrePosition() {
AppHandler.getInstance().post(this);
}
@Override
public void onSuccess(long taskStamp, List<GalleryInfo> gis, int pageNum) {
if (mTaskStamp != taskStamp)
return;
if (pageNum == ListParser.TARGET_PAGE_IS_LAST)
mPageNum = mTargetPage + 1;
else
mPageNum = pageNum;
int itemPerPage = gis == null ? 0 : gis.size();
if (mItemPerPage < itemPerPage)
mItemPerPage = itemPerPage;
if (mPageNum == 0) { // Get none
onlyShowNone();
mFirstPage = 0;
mLastPage = 0;
mGiList.clear();
mAdapter.notifyDataSetChanged();
} else {
onlyShowList();
int start;
switch (mGetMode) {
case MODE_REFRESH:
mFirstPage = 0;
mLastPage = 0;
mGiList.clear();
mGiList.addAll(gis);
mAdapter.notifyDataSetChanged();
// For current page
mFirstIndex = 0;
mLastIndex = gis.size() - 1;
mCurPage = 0;
mLayoutManager.scrollToPosition(0);
break;
case MODE_PRE_PAGE:
mFirstPage--;
mGiList.addAll(0, gis);
mAdapter.notifyItemRangeInserted(0, gis.size());
if (mIsKeepPosition) {
mFirstIndex += gis.size();
mLastIndex += gis.size();
smoothScrollToPrePosition();
} else {
mFirstIndex = 0;
mLastIndex = gis.size()-1;
mCurPage = mTargetPage;
mLayoutManager.scrollToPosition(0);
}
break;
case MODE_NEXT_PAGE:
mLastPage++;
start = mGiList.size();
mGiList.addAll(gis);
mAdapter.notifyItemRangeInserted(start, gis.size());
if (!mIsKeepPosition) {
mFirstIndex = mGiList.size() - gis.size();
mLastIndex = mGiList.size() - 1;
mCurPage = mTargetPage;
mLayoutManager.scrollToPosition(0);
}
break;
case MODE_SOMEWHERE:
mFirstPage = mTargetPage;
mLastPage = mTargetPage;
mGiList.clear();
mGiList.addAll(gis);
mAdapter.notifyDataSetChanged();
// For current page
mFirstIndex = 0;
mLastIndex = gis.size() - 1;
mCurPage = mTargetPage;
mLayoutManager.scrollToPosition(0);
}
}
mRefreshLayout.setHeaderRefreshing(false);
mRefreshLayout.setFooterRefreshing(false);
}
@Override
public void onFailure(long taskStamp, String eMsg) {
if (mTaskStamp != taskStamp)
return;
switch (mGetMode) {
case MODE_REFRESH:
case MODE_SOMEWHERE:
mRefreshLayout.setVisibility(View.GONE);
mRefreshTextView.setVisibility(View.VISIBLE);
if (eMsg.equals(mContext.getString(R.string.em_index_error))) {
mRefreshTextView.setEmesg(eMsg, mContext.getString(R.string.click_first_page),
new RefreshTextView.OnRefreshListener() {
@Override
public void onRefresh() {
mRefreshTextView.setRefreshing(true);
refresh();
}
});
} else {
mRefreshTextView.setEmesg(eMsg, true);
}
break;
default:
mRefreshTextView.setRefreshing(false);
mRefreshTextView.setVisibility(View.GONE);
MaterialToast.showToast(eMsg);
}
mRefreshLayout.setHeaderRefreshing(false);
mRefreshLayout.setFooterRefreshing(false);
}
}
public static interface GalleryListViewHelper {
/**
* Get url string for very page
*
* @param targetPage
* @return
*/
public String getTargetUrl(int targetPage);
/**
* Do get gallarys here, you shuold invoke the onSuccess or onFailure of
* listener when over
*
* @param url
* @param taskStamp
* @param listener
*/
public void doGetGallerys(String url, long taskStamp, OnGetListListener listener);
}
public class OnScrollListener extends RecyclerView.OnScrollListener {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
/*
switch (newState) {
case RecyclerView.SCROLL_STATE_DRAGGING:
ImageCache.getImageCache(mContext).setPauseDiskCache(true);
break;
case RecyclerView.SCROLL_STATE_IDLE:
ImageCache.getImageCache(mContext).setPauseDiskCache(false);
break;
}
*/
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
// mRefreshLayout.onScrolled(recyclerView, dx, dy);
int itemCount = mLayoutManager.getChildCount();
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPositions(mFirstPositionTemp)[0];
// itemCount might include some view can't be seen
// Just check top line child and bottom line child
int visibleItemCount = itemCount;
int height = mEasyRecyclerView.getHeight();
int span = mLayoutManager.getSpanCount();
// Top line
int start = 0;
int end = Math.min(span, itemCount);
for (int i = start; i < end; i++) {
View view = mLayoutManager.getChildAt(i);
if (view.getBottom() <= 0 || view.getTop() > height)
visibleItemCount--;
}
// Bottom line
start = Math.max(itemCount - 1 - span, 0);
end = itemCount;
for (int i = start; i < end; i++) {
View view = mLayoutManager.getChildAt(i);
if (view.getBottom() <= 0 || view.getTop() > height)
visibleItemCount--;
}
if (mItemPerPage == 0)
return;
if (mLastIndex == 0)
mLastIndex = mItemPerPage - 1;
int pageChanged = (firstVisibleItem - mFirstIndex) / mItemPerPage;
if (pageChanged == 0)
pageChanged = (firstVisibleItem + visibleItemCount - mLastIndex - 1) / mItemPerPage;
if (pageChanged != 0) {
mCurPage = mCurPage + pageChanged;
mFirstIndex += pageChanged * mItemPerPage;
mLastIndex += pageChanged * mItemPerPage;
}
}
}
private class GalleryViewHolder extends RecyclerView.ViewHolder {
public int viewType;
public LoadImageView thumb;
public TextView title;
public TextView uploader;
public TextView category;
public RatingView rate;
public TextView posted;
public TextView simpleLanguage;
public GalleryViewHolder(View itemView, int viewType) {
super(itemView);
this.viewType = viewType;
switch (viewType) {
case LIST_MODE_DETAIL:
thumb = (LoadImageView) itemView.findViewById(R.id.thumb);
title = (TextView) itemView.findViewById(R.id.title);
category = (TextView) itemView.findViewById(R.id.category);
uploader = (TextView) itemView.findViewById(R.id.uploader);
rate = (RatingView) itemView.findViewById(R.id.rate);
posted = (TextView) itemView.findViewById(R.id.posted);
simpleLanguage = (TextView) itemView.findViewById(R.id.simple_language);
ViewGroup.LayoutParams lp = thumb.getLayoutParams();
lp.width = mListDetailThumbWidth;
lp.height = mListDetailThumbHeight;
break;
case LIST_MODE_THUMB:
thumb = (LoadImageView) itemView.findViewById(R.id.thumb);
category = (TextView) itemView.findViewById(R.id.category);
simpleLanguage = (TextView) itemView.findViewById(R.id.simple_language);
}
}
}
public class GalleryAdapter extends RecyclerView.Adapter<GalleryViewHolder> {
private final Context mContext;
private final List<GalleryInfo> mGiList;
private final ImageLoader mImageLoader;
public GalleryAdapter(Context context, List<GalleryInfo> gilist) {
mContext = context;
mGiList = gilist;
mImageLoader = ImageLoader.getInstance(mContext);
}
@Override
public GalleryViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
int resId;
if (viewType == LIST_MODE_DETAIL)
resId = R.layout.gallery_list_detail_item;
else
resId = R.layout.gallery_list_thumb_item;
View view = mInflater.inflate(resId, parent, false);
CardViewSalon.reformWithShadow(view, new int[][]{
new int[]{android.R.attr.state_pressed},
new int[]{android.R.attr.state_activated},
new int[]{}},
new int[]{0xff84cae4, 0xff33b5e5, 0xFFFAFAFA}, null, false);
return new GalleryViewHolder(view, viewType);
}
@Override
public void onBindViewHolder(GalleryViewHolder holder,
int position) {
mEasyRecyclerView.checkItemCheckedState(holder.itemView, position);
GalleryInfo gi = mGiList.get(position);
final LoadImageView thumb = holder.thumb;
final String key = String.valueOf(gi.gid);
if (!key.equals(thumb.getKey())) {
// Set new thumb
thumb.setImageDrawable(null);
thumb.setLoadInfo(gi.thumb, key);
Bitmap b = ImageCache.getImageCache(getContext()).getFromMemory(key);
if (b != null) {
thumb.setContextImage(b, true, false);
} else {
mImageLoader.add(gi.thumb, String.valueOf(gi.gid),
new LoadImageView.SimpleImageGetListener(thumb).setFixScaleType(true));
}
}
// Set simple language
TextView simpleLanguage = holder.simpleLanguage;
if (gi.simpleLanguage == null) {
simpleLanguage.setVisibility(View.GONE);
} else {
simpleLanguage.setVisibility(View.VISIBLE);
simpleLanguage.setText(gi.simpleLanguage);
}
// For detail mode
if (holder.viewType == LIST_MODE_DETAIL) {
// Set category
TextView category = holder.category;
String newText = Ui.getCategoryText(gi.category);
if (!newText.equals(category.getText())) {
category.setText(newText);
category.setBackgroundColor(Ui.getCategoryColor(gi.category));
}
// Set manga title
TextView title = holder.title;
title.setText(gi.title);
// Set uploder
TextView uploader = holder.uploader;
uploader.setText(gi.uploader);
// Set star
RatingView rate = holder.rate;
rate.setRating(gi.rating);
// set posted
TextView posted = holder.posted;
posted.setText(gi.posted);
} else {
// Set category
TextView category = holder.category;
String newText = Ui.getCategoryText(gi.category);
if (!newText.equals(category.getText())) {
category.setText(newText);
category.setBackgroundColor(Ui.getCategoryColor(gi.category)
& 0x00ffffff | 0xca000000);
}
}
}
@Override
public int getItemViewType(int position) {
return mListMode;
}
@Override
public int getItemCount() {
return mGiList.size();
}
}
}
@@ -1,299 +0,0 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget;
import android.annotation.TargetApi;
import android.os.Build;
import android.view.MotionEvent;
import android.view.TouchDelegate;
import android.view.View;
import android.view.ViewConfiguration;
public class HotspotTouchHelper implements View.OnTouchListener {
private final Hotspotable mOwner;
private boolean mPrePressed = false;
private boolean mHasPerformedLongPress = false;
private CheckForLongPress mPendingCheckForLongPress = null;
private CheckForTap mPendingCheckForTap = null;
private PerformClick mPerformClick = null;
private UnsetPressedState mUnsetPressedState = null;
/**
* Cache the touch slop from the context that created the view.
*/
private int mTouchSlop = -1;
public HotspotTouchHelper(Hotspotable owner){
mOwner = owner;
}
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public boolean onTouch(View v, MotionEvent event) {
final float x = event.getX();
final float y = event.getY();
if (event.getAction() == MotionEvent.ACTION_DOWN ||
event.getAction() == MotionEvent.ACTION_MOVE)
mOwner.setHotspot(x, y);
if (!v.isEnabled()) {
if (event.getAction() == MotionEvent.ACTION_UP && v.isPressed()) {
v.setPressed(false);
}
// A disabled view that is clickable still consumes the touch
// events, it just doesn't respond to them.
return (v.isClickable() || v.isLongClickable());
}
TouchDelegate touchDelegate = v.getTouchDelegate();
if (touchDelegate != null) {
if (touchDelegate.onTouchEvent(event)) {
return true;
}
}
if (v.isClickable() || v.isLongClickable()) {
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
if (v.isPressed() || mPrePressed) {
// take focus if we don't have it already and we should in
// touch mode.
boolean focusTaken = false;
if (v.isFocusable() && v.isFocusableInTouchMode() && !v.isFocused()) {
focusTaken = v.requestFocus();
}
if (mPrePressed) {
// The button is being released before we actually
// showed it as pressed. Make it show the pressed
// state now (before scheduling the click) to ensure
// the user sees it.
setPressed(v, true, x, y);
}
if (!mHasPerformedLongPress) {
// This is a tap, so remove the longpress check
removeLongPressCallback(v);
// Only perform take click actions if we were in the pressed state
if (!focusTaken) {
// Use a Runnable and post this rather than calling
// performClick directly. This lets other visual state
// of the view update before click actions start.
if (mPerformClick == null) {
mPerformClick = new PerformClick(v);
}
if (!v.post(mPerformClick)) {
v.performClick();
}
}
}
if (mUnsetPressedState == null) {
mUnsetPressedState = new UnsetPressedState(v);
}
if (mPrePressed) {
v.postDelayed(mUnsetPressedState,
ViewConfiguration.getPressedStateDuration());
} else if (!v.post(mUnsetPressedState)) {
// If the post failed, unpress right now
mUnsetPressedState.run();
}
removeTapCallback(v);
}
break;
case MotionEvent.ACTION_DOWN:
mHasPerformedLongPress = false;
if (performButtonActionOnTouchDown(v, event)) {
break;
}
mPrePressed = true;
if (mPendingCheckForTap == null) {
mPendingCheckForTap = new CheckForTap(v);
}
mPendingCheckForTap.x = event.getX();
mPendingCheckForTap.y = event.getY();
v.postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
break;
case MotionEvent.ACTION_CANCEL:
v.setPressed(false);
removeTapCallback(v);
removeLongPressCallback(v);
break;
case MotionEvent.ACTION_MOVE:
mOwner.setHotspot(x, y);
if (mTouchSlop == -1)
mTouchSlop = ViewConfiguration.get(v.getContext()).getScaledTouchSlop();
// Be lenient about moving outside of buttons
if (!pointInView(v, x, y, mTouchSlop)) {
// Outside button
removeTapCallback(v);
if (v.isPressed()) {
// Remove any future long press/tap checks
removeLongPressCallback(v);
v.setPressed(false);
}
}
break;
}
return true;
}
return false;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setPressed(View v, boolean pressed, float x, float y){
v.setPressed(pressed);
mOwner.setHotspot(x, y);
}
/**
* Utility method to determine whether the given point, in local coordinates,
* is inside the view, where the area of the view is expanded by the slop factor.
* This method is called while processing touch-move events to determine if the event
* is still within the view.
*/
public boolean pointInView(View v, float localX, float localY, float slop) {
return localX >= -slop && localY >= -slop && localX < ((v.getRight() - v.getLeft()) + slop) &&
localY < ((v.getBottom() - v.getTop()) + slop);
}
/**
* Performs button-related actions during a touch down event.
*
* @param event The event.
* @return True if the down was consumed.
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
protected boolean performButtonActionOnTouchDown(View v, MotionEvent event) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) {
if (v.showContextMenu()) {
return true;
}
}
}
return false;
}
/**
* Remove the longpress detection timer.
*/
private void removeLongPressCallback(View v) {
if (mPendingCheckForLongPress != null) {
v.removeCallbacks(mPendingCheckForLongPress);
}
}
/**
* Remove the tap detection timer.
*/
private void removeTapCallback(View v) {
if (mPendingCheckForTap != null) {
mPrePressed = false;
v.removeCallbacks(mPendingCheckForTap);
}
}
private void checkForLongClick(View v, int delayOffset) {
if (v.isLongClickable()) {
mHasPerformedLongPress = false;
if (mPendingCheckForLongPress == null) {
mPendingCheckForLongPress = new CheckForLongPress(v);
}
v.postDelayed(mPendingCheckForLongPress,
ViewConfiguration.getLongPressTimeout() - delayOffset);
}
}
private final class CheckForLongPress implements Runnable {
private final View mView;
public CheckForLongPress(View v) {
mView = v;
}
@Override
public void run() {
if (mView.isPressed() && (mView.getParent() != null)) {
if (mView.performLongClick()) {
mHasPerformedLongPress = true;
}
}
}
}
private final class CheckForTap implements Runnable {
public float x;
public float y;
private final View mView;
public CheckForTap(View v) {
mView = v;
}
@Override
public void run() {
mPrePressed = false;
setPressed(mView, true, x, y);
checkForLongClick(mView, ViewConfiguration.getTapTimeout());
}
}
private final class PerformClick implements Runnable {
private final View mView;
public PerformClick(View v) {
mView = v;
}
@Override
public void run() {
mView.performClick();
}
}
private final class UnsetPressedState implements Runnable {
private final View mView;
public UnsetPressedState(View v) {
mView = v;
}
@Override
public void run() {
mView.setPressed(false);
}
}
}
@@ -1,21 +0,0 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget;
public interface Hotspotable {
public void setHotspot(float x, float y);
}
@@ -1,75 +0,0 @@
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget;
import java.util.ArrayList;
import java.util.List;
/**
* Utilities for the lock pattern and its settings.
*/
public class LockPatternUtils {
/**
* Deserialize a pattern.
* @param string The pattern serialized with {@link #patternToString}
* @return The pattern.
*/
public static List<LockPatternView.Cell> stringToPattern(String string) {
List<LockPatternView.Cell> result = new ArrayList<>();
final byte[] bytes = string.getBytes();
for (int i = 0; i < bytes.length; i++) {
byte b = bytes[i];
result.add(LockPatternView.Cell.of(b / 3, b % 3));
}
return result;
}
/**
* Serialize a pattern.
* @param pattern The pattern.
* @return The pattern in string form.
*/
public static String patternToString(List<LockPatternView.Cell> pattern) {
if (pattern == null) {
return "";
}
final int patternSize = pattern.size();
byte[] res = new byte[patternSize];
for (int i = 0; i < patternSize; i++) {
LockPatternView.Cell cell = pattern.get(i);
res[i] = (byte) (cell.getRow() * 3 + cell.getColumn());
}
return new String(res);
}
public static boolean isPatternVaild(String pattern) {
byte[] bytes = pattern.getBytes();
if (bytes.length <= 9 && bytes.length >= 2) {
for (byte b : bytes) {
if (b >= 9 || b < 0) {
return false;
}
}
return true;
} else {
return false;
}
}
}
File diff suppressed because it is too large. Load diff
@@ -1,64 +0,0 @@
/*
* Copyright (C) 2014 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
import com.hippo.ehviewer.AppContext;
public class RatingView extends TextView {
private static final char START_EMPTY = '\uFA73';
private static final char START_HALF = '\uFA74';
private static final char START_FULL = '\uFA75';
private int mRating = -1;
public RatingView(Context context) {
super(context);
init(context);
}
public RatingView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public RatingView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
private void init(Context context) {
setTypeface(((AppContext)context.getApplicationContext()).getFaceTypeface());
}
public void setRating(float rating) {
mRating = Math.min(10, Math.round(rating * 2));
int fullNum = mRating / 2;
int halfNum = mRating % 2;
int emptyNum = 5 - fullNum - halfNum;
StringBuilder sb = new StringBuilder(5);
for (int i = 0; i < fullNum; i++)
sb.append(START_FULL);
if (halfNum == 1)
sb.append(START_HALF);
for (int i = 0; i < emptyNum; i++)
sb.append(START_EMPTY);
setText(sb.toString());
}
}
@@ -1,64 +0,0 @@
/*
* Copyright (C) 2014 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
public class SearchView extends android.widget.SearchView {
private static final String TAG = SearchView.class.getSimpleName();
private OnActionViewExpandedListener mListener;
public SearchView(Context context) {
super(context);
}
public SearchView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public SearchView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public SearchView(Context context, AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public void onActionViewExpanded() {
super.onActionViewExpanded();
if (mListener != null)
mListener.onActionViewExpanded();
}
public void setOnActionViewExpandedListener(OnActionViewExpandedListener l) {
mListener = l;
}
public interface OnActionViewExpandedListener {
public void onActionViewExpanded();
}
}
@@ -1,137 +0,0 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.view.View;
public class SimpleImageView extends View implements Drawable.Callback {
private Drawable mDrawable;
private boolean mKeepAspect = true;
private static final int[] LAYOUT_ATTRS = new int[] {
android.R.attr.src
};
public SimpleImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public SimpleImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
setDrawable(a.getDrawable(0));
a.recycle();
// Mostly drawable is VectorDrawable, it has cache already
setWillNotCacheDrawing(true);
}
@SuppressWarnings("deprecation")
public void setDrawable(@DrawableRes int resId) {
setDrawable(getContext().getResources().getDrawable(resId));
}
public void setDrawable(Drawable drawable) {
if (mDrawable != null) {
mDrawable.setCallback(null);
}
mDrawable = drawable;
if (mDrawable != null) {
mDrawable.setCallback(this);
}
requestLayout();
}
@Override
public void invalidateDrawable(@NonNull Drawable who) {
invalidate();
}
@Override
protected int getSuggestedMinimumWidth() {
int superMinWidth = super.getSuggestedMinimumWidth();
return (mDrawable == null) ? superMinWidth :
Math.max(superMinWidth, mDrawable.getMinimumWidth() + getPaddingLeft() + getPaddingRight());
}
@Override
protected int getSuggestedMinimumHeight() {
int superMinHeight = super.getSuggestedMinimumHeight();
return (mDrawable == null) ? superMinHeight :
Math.max(superMinHeight, mDrawable.getMinimumHeight() + getPaddingTop() + getPaddingBottom());
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (mDrawable != null) {
int paddingLeft = getPaddingLeft();
int paddingTop = getPaddingTop();
int paddingRight = getPaddingRight();
int paddingBottom = getPaddingBottom();
int canvasWidth = right - left - paddingLeft - paddingRight;
int canvasHeight = bottom - top - paddingTop - paddingBottom;
int intrinsicWidth = mDrawable.getIntrinsicWidth();
int intrinsicHeight = mDrawable.getIntrinsicHeight();
if (mKeepAspect && intrinsicWidth > 0 && intrinsicHeight > 0) {
int drawWidth;
int drawHeight;
float canvasAspect = canvasWidth / canvasHeight;
float drawableAspect = intrinsicWidth / intrinsicHeight;
if (drawableAspect > canvasAspect) {
drawWidth = (int) (canvasHeight * drawableAspect);
drawHeight = canvasHeight;
} else {
drawWidth = canvasWidth;
drawHeight = (int) (canvasWidth / drawableAspect);
}
int drawLeft = paddingLeft + ((canvasWidth - drawWidth) / 2);
int drawTop = paddingTop + ((canvasHeight - drawHeight) / 2);
mDrawable.setBounds(drawLeft, drawTop,
drawLeft + drawWidth, drawTop + drawHeight);
} else {
mDrawable.setBounds(paddingLeft, paddingTop,
paddingLeft + canvasWidth, paddingTop + canvasHeight);
}
}
}
@Override
protected void onDraw(Canvas canvas) {
if (mDrawable != null) {
mDrawable.draw(canvas);
}
}
}
@@ -1,598 +0,0 @@
/*
* Copyright (C) 2014 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.support.v4.view.MotionEventCompat;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.CycleInterpolator;
import com.hippo.ehviewer.util.AnimatorUtils;
import com.hippo.ehviewer.util.MathUtils;
import com.hippo.ehviewer.util.Ui;
import com.hippo.ehviewer.util.ViewUtils;
import com.hippo.ehviewer.util.ZInterpolator;
public class SlidingLayout extends ViewGroup {
private static final String TAG = SlidingLayout.class.getSimpleName();
/*
* There are three level, first is base level, second is reserved level, third is full screen level.
*/
private static final int LEVEL_BASE = 0;
private static final int LEVEL_RESERVED = 1;
private static final int LEVEL_FULL_SCREEN = 2;
private int mLevel = LEVEL_BASE;
private View mChild;
private int mMaxWidth;
private int mSlop;
private float mShowPercent = 0.0f;
private boolean isBottom = true;
private int mPaddingLeft;
private int mPaddingTop;
private int mPaddingRight;
private int mPaddingBottom;
private ValueAnimator mToBaseLevelAnimate;
private ValueAnimator mToReservedLevelAnimate;
private ValueAnimator mToFullScreenLevelAnimate;
private SetYListener mToBaseLevelListener;
private SetYListener mToReservedLevelListener;
private SetYListener mToFullScreenLevelListener;
private float mInitialMotionX;
private float mInitialMotionY;
private float mLastMotionY;
private int mMinTop;
private int mMaxTop;
/*
* ---------------------- mFullScreenTop
*
* ---------------------- m5Top
*
*
* ---------------------- m4Top
*
* ---------------------- mReservedTop
*
* ---------------------- m2Top
*
*
* ---------------------- m1Top
*
* ---------------------- mBaseTop
*/
private int mBaseTop;
private int m1Top;
private int m2Top;
private int mReservedTop;
private int m4Top;
private int m5Top;
private int mFullScreenTop;
private boolean mInHideAnimate = false;
private OnChildHideListener mOnChildHideListener;
private static final ZInterpolator ZINTERPOLATOR = new ZInterpolator();
public interface OnChildHideListener {
public void onChildHide();
}
public SlidingLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public SlidingLayout(Context context, AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public SlidingLayout(Context context, AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private void init() {
mMaxWidth = Ui.dp2pix(480);
mSlop = Ui.dp2pix(0);
mToBaseLevelAnimate = new ValueAnimator();
mToBaseLevelListener = new SetYListener();
mToBaseLevelAnimate.addUpdateListener(mToBaseLevelListener);
mToBaseLevelAnimate.setDuration(300);
mToBaseLevelAnimate.setInterpolator(ZINTERPOLATOR);
mToBaseLevelAnimate.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
mInHideAnimate = true;
}
@Override
public void onAnimationEnd(Animator animation) {
mLevel = LEVEL_BASE;
if (mChild.getVisibility() != View.INVISIBLE)
mChild.setVisibility(View.INVISIBLE);
if (mOnChildHideListener != null)
mOnChildHideListener.onChildHide();
mInHideAnimate = false;
}
@Override
public void onAnimationCancel(Animator animation) {
mInHideAnimate = false;
}
@Override
public void onAnimationRepeat(Animator animation) {
// Empty
}
});
mToReservedLevelAnimate = new ValueAnimator();
mToReservedLevelListener = new SetYListener();
mToReservedLevelAnimate.addUpdateListener(mToReservedLevelListener);
mToReservedLevelAnimate.setDuration(300);
mToReservedLevelAnimate.setInterpolator(ZINTERPOLATOR);
mToReservedLevelAnimate.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
// Empty
}
@Override
public void onAnimationEnd(Animator animation) {
mLevel = LEVEL_RESERVED;
}
@Override
public void onAnimationCancel(Animator animation) {
// Empty
}
@Override
public void onAnimationRepeat(Animator animation) {
// Empty
}
});
mToFullScreenLevelAnimate = new ValueAnimator();
mToFullScreenLevelListener = new SetYListener();
mToFullScreenLevelAnimate.addUpdateListener(mToFullScreenLevelListener);
mToFullScreenLevelAnimate.setDuration(300);
mToFullScreenLevelAnimate.setInterpolator(ZINTERPOLATOR);
mToFullScreenLevelAnimate.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
// Empty
}
@Override
public void onAnimationEnd(Animator animation) {
mLevel = LEVEL_FULL_SCREEN;
}
@Override
public void onAnimationCancel(Animator animation) {
// Empty
}
@Override
public void onAnimationRepeat(Animator animation) {
// Empty
}
});
}
private class SetYListener implements ValueAnimator.AnimatorUpdateListener {
private boolean mFirstShow = false;
private int mStartTop;
public void reset() {
mFirstShow = true;
mStartTop = mChild.getTop();
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int offsetY = (int) (float) (Float) animation.getAnimatedValue() - mChild.getTop();
mChild.offsetTopAndBottom(offsetY);
updateShowPercent();
if (mFirstShow && Math.abs(mStartTop - mChild.getTop()) > 5) {
mFirstShow = false;
invalidate();
}
}
}
public void setOnChildHideListener(OnChildHideListener l) {
mOnChildHideListener = l;
}
@Override
protected void onFinishInflate() {
final int childCount = getChildCount();
if (childCount != 1)
throw new IllegalStateException("There must be only one child");
mChild = getChildAt(0);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
if (widthMode != MeasureSpec.EXACTLY || heightMode != MeasureSpec.EXACTLY)
throw new IllegalArgumentException(
"SlidingDrawerLayout must be measured with MeasureSpec.EXACTLY.");
setMeasuredDimension(widthSize, heightSize);
final View child = mChild;
if (child.getVisibility() != GONE) {
final int childWidthSpec = MeasureSpec.makeMeasureSpec(
Math.min(widthSize - getPaddingLeft() - getPaddingRight(), mMaxWidth), MeasureSpec.EXACTLY);
final int childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
child.measure(childWidthSpec, childHeightSpec);
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final View child = mChild;
final int width = r - l;
final int height = b - t;
final int childWidth = child.getMeasuredWidth();
final int childHeight = child.getMeasuredHeight();
mPaddingLeft = getPaddingLeft();
mPaddingTop = getPaddingTop();
mPaddingRight = getPaddingRight();
mPaddingBottom = getPaddingBottom();
// Set mReservedLength and mFullScreenLength
int heightWithoutPadding = height - mPaddingTop - mPaddingBottom;
int defaultReservedLength = Math.min(heightWithoutPadding - Ui.dp2pix(48), Ui.dp2pix(248));
int defaultFullScreenLength = Math.max(heightWithoutPadding, defaultReservedLength);
int reservedLength = Math.min(defaultReservedLength, childHeight);
int fullScreenLength = Math.min(defaultFullScreenLength, childHeight);
int showHeight = MathUtils.lerp(0, childHeight, mShowPercent);
int childLeft = mPaddingLeft + (width - mPaddingLeft - mPaddingRight - childWidth) / 2;
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
final int maxGap = Ui.dp2pix(32);
final int brGap = Math.min(Math.abs((mBaseTop - mReservedTop) / 3), maxGap);
final int rfGap = Math.min(Math.abs((mReservedTop - mFullScreenTop) / 3), maxGap);
switch (vgrav) {
case Gravity.TOP: {
isBottom = false;
mMinTop = mPaddingTop;
mMaxTop = mMinTop + childHeight;
mBaseTop = mMinTop;
mReservedTop = mMinTop + reservedLength;
mFullScreenTop = mMinTop + fullScreenLength;
m1Top = mBaseTop + brGap;
m2Top = mReservedTop - brGap;
m4Top = mReservedTop + rfGap;
m5Top = mFullScreenTop - rfGap;
int childBottom = mMinTop + showHeight;
child.layout(childLeft, childBottom - childHeight, childLeft + childWidth, childBottom);
break;
}
default:
case Gravity.BOTTOM: {
isBottom = true;
mMaxTop = height - mPaddingBottom;
mMinTop = mMaxTop - childHeight;
mBaseTop = mMaxTop;
mReservedTop = mMaxTop - reservedLength;
mFullScreenTop = mMaxTop - fullScreenLength;
m1Top = mBaseTop - brGap;
m2Top = mReservedTop + brGap;
m4Top = mReservedTop - rfGap;
m5Top = mFullScreenTop + rfGap;
int childTop = mMaxTop - showHeight;
child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
break;
}
}
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
boolean getTouchEvent = false;
final int action = MotionEventCompat.getActionMasked(ev);
final float x = ev.getX();
final float y = ev.getY();
final boolean isChildUnder = ViewUtils.isViewUnder(mChild, (int) x, (int) y);
switch (action) {
case MotionEvent.ACTION_DOWN:
mInitialMotionX = x;
mInitialMotionY = y;
mLastMotionY = mInitialMotionY;
break;
case MotionEvent.ACTION_MOVE:
final float adx = Math.abs(x - mInitialMotionX);
final float ady = Math.abs(y - mInitialMotionY);
if (isChildUnder && adx > mSlop && ady > adx)
getTouchEvent = true;
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
break;
}
return getTouchEvent;
}
private void updateShowPercent() {
int top = mChild.getTop();
mShowPercent = (isBottom ? (mMaxTop - top) : (top - mMinTop)) /
(float) mChild.getHeight();
}
private void cancelAnimator() {
if (mToBaseLevelAnimate.isRunning())
mToBaseLevelAnimate.cancel();
if (mToReservedLevelAnimate.isRunning())
mToReservedLevelAnimate.cancel();
if (mToFullScreenLevelAnimate.isRunning())
mToFullScreenLevelAnimate.cancel();
}
@Override
@SuppressLint("ClickableViewAccessibility")
public boolean onTouchEvent(MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
final float x = ev.getX();
final float y = ev.getY();
boolean getTouchEvent = false;
cancelAnimator();
int top;
switch (action) {
case MotionEvent.ACTION_DOWN:
mInitialMotionX = x;
mInitialMotionY = y;
mLastMotionY = mInitialMotionY;
if (isShowing())
getTouchEvent = true;
break;
case MotionEvent.ACTION_MOVE:
final float dy = y - mLastMotionY;
mLastMotionY = y;
getTouchEvent = true;
top = mChild.getTop();
int newTop = top + (int) dy;
newTop = MathUtils.clamp(newTop, mMinTop, mMaxTop);
mChild.offsetTopAndBottom(newTop - top);
updateShowPercent();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
getTouchEvent = true;
top = mChild.getTop();
if (isBottom) {
switch (mLevel) {
default:
case LEVEL_BASE:
if (top < mFullScreenTop)
;
else if (top < m4Top)
toFullScreenLevel();
else if (top < m1Top)
toReservedLevel(false);
else
toBaseLevel();
break;
case LEVEL_RESERVED:
if (top < mFullScreenTop)
;
else if (top < m4Top)
toFullScreenLevel();
else if (top < m2Top)
toReservedLevel(false);
else
toBaseLevel();
break;
case LEVEL_FULL_SCREEN:
if (top < mFullScreenTop)
;
else if (top < m5Top)
toFullScreenLevel();
else if (top < m2Top)
toReservedLevel(false);
else
toBaseLevel();
break;
}
} else {
// TODO
}
break;
}
return getTouchEvent;
}
public void hide() {
if (mChild.getVisibility() != View.INVISIBLE)
mChild.setVisibility(View.INVISIBLE);
}
public boolean isShowing() {
return mChild.getVisibility() == View.VISIBLE;
}
public boolean isInHideAnimate() {
return mInHideAnimate;
}
public void toReservedLevel(boolean withShake) {
cancelAnimator();
// Show child
if (mChild.getVisibility() != View.VISIBLE)
mChild.setVisibility(View.VISIBLE);
mToReservedLevelListener.reset();
mToReservedLevelAnimate.setFloatValues(mChild.getTop(), mReservedTop);
if (withShake) {
AnimatorSet bouncer = new AnimatorSet();
Animator delayAnimator = AnimatorUtils.createDelayAnimator(200);
ValueAnimator shakeAnimator = ValueAnimator.ofFloat(mReservedTop,
isBottom ? mReservedTop - Ui.dp2pix(8) : mReservedTop + Ui.dp2pix(8));
shakeAnimator.setDuration(500);
shakeAnimator.setInterpolator(new CycleInterpolator(1));
shakeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int offsetY = (int) (float) (Float) animation.getAnimatedValue() - mChild.getTop();
mChild.offsetTopAndBottom(offsetY);
updateShowPercent();
}
});
bouncer.play(mToReservedLevelAnimate).before(delayAnimator);
bouncer.play(delayAnimator).before(shakeAnimator);
bouncer.start();
} else {
mToReservedLevelAnimate.start();
}
}
public void toBaseLevel() {
cancelAnimator();
// Show child
if (mChild.getVisibility() != View.VISIBLE)
mChild.setVisibility(View.VISIBLE);
mToBaseLevelListener.reset();
mToBaseLevelAnimate.setFloatValues(mChild.getTop(), mBaseTop);
mToBaseLevelAnimate.start();
}
public void toFullScreenLevel() {
cancelAnimator();
// Show child
if (mChild.getVisibility() != View.VISIBLE)
mChild.setVisibility(View.VISIBLE);
mToFullScreenLevelListener.reset();
mToFullScreenLevelAnimate.setFloatValues(mChild.getTop(), mFullScreenTop);
mToFullScreenLevelAnimate.start();
}
@Override
protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
}
@Override
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
return p instanceof LayoutParams
? new LayoutParams((LayoutParams) p)
: new LayoutParams(p);
}
@Override
protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
return p instanceof LayoutParams && super.checkLayoutParams(p);
}
@Override
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
return new LayoutParams(getContext(), attrs);
}
public static class LayoutParams extends ViewGroup.LayoutParams {
private static final int[] LAYOUT_ATTRS = new int[] {
android.R.attr.layout_gravity
};
public int gravity = Gravity.BOTTOM;
public LayoutParams(Context c, AttributeSet attrs) {
super(c, attrs);
final TypedArray a = c.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
this.gravity = a.getInt(0, Gravity.BOTTOM);
a.recycle();
}
public LayoutParams(int width, int height) {
super(width, height);
}
public LayoutParams(int width, int height, int gravity) {
this(width, height);
this.gravity = gravity;
}
public LayoutParams(LayoutParams source) {
super(source);
gravity = source.gravity;
}
public LayoutParams(ViewGroup.LayoutParams source) {
super(source);
}
}
}
@@ -1,87 +0,0 @@
/*
* Copyright (C) 2014 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import com.hippo.ehviewer.effect.DrawableTransition;
public class TransitionLayout extends LinearLayout {
private Bitmap mBmp;
private int mOldWidth;
private int mOldHeight;
private static final String TAG = TransitionLayout.class.getSimpleName();
public TransitionLayout(Context context) {
super(context);
}
public TransitionLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TransitionLayout(Context context, AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public TransitionLayout(Context context, AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void dispatchDraw(Canvas canvas) {
int width = getWidth();
int height = getHeight();
if (mOldWidth != width || mOldHeight != height || mBmp == null) {
mOldWidth = width;
mOldHeight = height;
if (mBmp != null && !mBmp.isRecycled())
mBmp.recycle();
mBmp = Bitmap.createBitmap(getWidth(), getHeight(),
Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(mBmp);
c.translate(-getScrollX(), -getScrollY());
super.dispatchDraw(c);
BitmapDrawable b = new BitmapDrawable(getResources(), mBmp);
DrawableTransition.transit(b, false, 3000);
setBackgroundDrawable(b);
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
setBackgroundDrawable(null);
if (mBmp != null && !mBmp.isRecycled())
mBmp.recycle();
}
}
@@ -1,992 +0,0 @@
/*
* Copyright (C) 2014-2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget.recyclerview;
import android.content.Context;
import android.os.Build;
import android.support.v4.util.LongSparseArray;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.util.SparseBooleanArray;
import android.util.TypedValue;
import android.view.ActionMode;
import android.view.HapticFeedbackConstants;
import android.view.InputDevice;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.SoundEffectConstants;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.accessibility.AccessibilityEvent;
import android.widget.Checkable;
import com.hippo.ehviewer.util.MathUtils;
import com.hippo.ehviewer.util.ViewUtils;
/**
* Add setOnItemClickListener, setOnItemLongClickListener and setChoiceMode for
* RecyclerView
*/
// Get some code from twoway-view and AbsListView.
public class EasyRecyclerView extends RecyclerView {
private static final String STATE_KEY_CHOICE_MODE = "choiceMode";
private static final String STATE_KEY_CHECKED_STATES = "checkedStates";
private static final String STATE_KEY_CHECKED_ID_STATES = "checkedIdStates";
private static final String STATE_KEY_CHECKED_COUNT = "checkedCount";
/**
* Represents an invalid position. All valid positions are in the range 0 to 1 less than the
* number of items in the current adapter.
*/
public static final int INVALID_POSITION = -1;
/**
* Normal list that does not indicate choices
*/
public static final int CHOICE_MODE_NONE = 0;
/**
* The list allows up to one choice
*/
public static final int CHOICE_MODE_SINGLE = 1;
/**
* The list allows multiple choices
*/
public static final int CHOICE_MODE_MULTIPLE = 2;
/**
* The list allows multiple choices in a modal selection mode
*/
public static final int CHOICE_MODE_MULTIPLE_MODAL = 3;
/**
* Controls if/how the user may choose/check items in the list
*/
private int mChoiceMode = CHOICE_MODE_NONE;
/**
* Controls CHOICE_MODE_MULTIPLE_MODAL. null when inactive.
*/
private ActionMode mChoiceActionMode;
/**
* Wrapper for the multiple choice mode callback; AbsListView needs to perform
* a few extra actions around what application code does.
*/
MultiChoiceModeWrapper mMultiChoiceModeCallback;
/**
* Running count of how many items are currently checked
*/
private int mCheckedItemCount;
/**
* Running state of which positions are currently checked
*/
private SparseBooleanArray mCheckStates;
/**
* Running state of which IDs are currently checked.
* If there is a value for a given key, the checked state for that ID is true
* and the value holds the last known position in the adapter for that id.
*/
private LongSparseArray<Integer> mCheckedIdStates;
private Adapter mAdapter;
private float mVerticalScrollFactor = 0;
// For click and long click
private boolean mPrePressed = false;
private boolean mHasPerformedLongPress = false;
private View mMotionView;
private int mMotionPosition;
private CheckForTap mPendingCheckForTap;
private CheckForLongPress mPendingCheckForLongPress;
private UnsetPressedState mUnsetPressedState;
private PerformClick mPerformClick;
private final float[] mTmpPoint = new float[2];
private int mTouchSlop = -1;
private float mStartX;
private float mStartY;
private OnItemClickListener mOnItemClickListener;
private OnItemLongClickListener mOnItemLongClickListener;
public EasyRecyclerView(Context context) {
super(context);
}
public EasyRecyclerView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public EasyRecyclerView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
/**
* {@inheritDoc}
*/
@Override
public void setAdapter(RecyclerView.Adapter adapter) {
super.setAdapter(adapter);
mAdapter = adapter;
if (adapter != null) {
if (mChoiceMode != CHOICE_MODE_NONE && adapter.hasStableIds() &&
mCheckedIdStates == null) {
mCheckedIdStates = new LongSparseArray<>();
}
}
if (mCheckStates != null) {
mCheckStates.clear();
}
if (mCheckedIdStates != null) {
mCheckedIdStates.clear();
}
}
/**
* Returns the number of items currently selected. This will only be valid
* if the choice mode is not {@link #CHOICE_MODE_NONE} (default).
*
* <p>To determine the specific items that are currently selected, use one of
* the <code>getChecked*</code> methods.
*
* @return The number of items currently selected
*
* @see #getCheckedItemPosition()
* @see #getCheckedItemPositions()
* @see #getCheckedItemIds()
*/
public int getCheckedItemCount() {
return mCheckedItemCount;
}
/**
* Returns the checked state of the specified position. The result is only
* valid if the choice mode has been set to {@link #CHOICE_MODE_SINGLE}
* or {@link #CHOICE_MODE_MULTIPLE}.
*
* @param position The item whose checked state to return
* @return The item's checked state or <code>false</code> if choice mode
* is invalid
*
* @see #setChoiceMode(int)
*/
public boolean isItemChecked(int position) {
//noinspection SimplifiableIfStatement
if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null) {
return mCheckStates.get(position);
}
return false;
}
/**
* Returns the currently checked item. The result is only valid if the choice
* mode has been set to {@link #CHOICE_MODE_SINGLE}.
*
* @return The position of the currently checked item or
* {@link #INVALID_POSITION} if nothing is selected
*
* @see #setChoiceMode(int)
*/
public int getCheckedItemPosition() {
if (mChoiceMode == CHOICE_MODE_SINGLE && mCheckStates != null && mCheckStates.size() == 1) {
return mCheckStates.keyAt(0);
}
return INVALID_POSITION;
}
/**
* Returns the set of checked items in the list. The result is only valid if
* the choice mode has not been set to {@link #CHOICE_MODE_NONE}.
*
* @return A SparseBooleanArray which will return true for each call to
* get(int position) where position is a checked position in the
* list and false otherwise, or <code>null</code> if the choice
* mode is set to {@link #CHOICE_MODE_NONE}.
*/
public SparseBooleanArray getCheckedItemPositions() {
if (mChoiceMode != CHOICE_MODE_NONE) {
return mCheckStates;
}
return null;
}
/**
* Returns the set of checked items ids. The result is only valid if the
* choice mode has not been set to {@link #CHOICE_MODE_NONE} and the adapter
* has stable IDs. ({@link android.widget.ListAdapter#hasStableIds()} == {@code true})
*
* @return A new array which contains the id of each checked item in the
* list.
*/
public long[] getCheckedItemIds() {
if (mChoiceMode == CHOICE_MODE_NONE || mCheckedIdStates == null || mAdapter == null) {
return new long[0];
}
final LongSparseArray<Integer> idStates = mCheckedIdStates;
final int count = idStates.size();
final long[] ids = new long[count];
for (int i = 0; i < count; i++) {
ids[i] = idStates.keyAt(i);
}
return ids;
}
/**
* Clear any choices previously set
*/
public void clearChoices() {
if (mCheckStates != null) {
mCheckStates.clear();
}
if (mCheckedIdStates != null) {
mCheckedIdStates.clear();
}
mCheckedItemCount = 0;
updateOnScreenCheckedViews();
}
/**
* Sets the checked state of the specified position. The is only valid if
* the choice mode has been set to {@link #CHOICE_MODE_SINGLE} or
* {@link #CHOICE_MODE_MULTIPLE}.
*
* @param position The item whose checked state is to be checked
* @param value The new checked state for the item
*/
public void setItemChecked(int position, boolean value) {
if (mChoiceMode == CHOICE_MODE_NONE) {
return;
}
// Start selection mode if needed. We don't need to if we're unchecking something.
if (value && mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL && mChoiceActionMode == null) {
if (mMultiChoiceModeCallback == null ||
!mMultiChoiceModeCallback.hasWrappedCallback()) {
throw new IllegalStateException("EasyRecyclerView: attempted to start selection mode " +
"for CHOICE_MODE_MULTIPLE_MODAL but no choice mode callback was " +
"supplied. Call setMultiChoiceModeListener to set a callback.");
}
mChoiceActionMode = startActionMode(mMultiChoiceModeCallback);
}
if (mChoiceMode == CHOICE_MODE_MULTIPLE || mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL) {
boolean oldValue = mCheckStates.get(position);
mCheckStates.put(position, value);
if (mCheckedIdStates != null && mAdapter.hasStableIds()) {
if (value) {
mCheckedIdStates.put(mAdapter.getItemId(position), position);
} else {
mCheckedIdStates.delete(mAdapter.getItemId(position));
}
}
if (oldValue != value) {
if (value) {
mCheckedItemCount++;
} else {
mCheckedItemCount--;
}
}
if (mChoiceActionMode != null) {
final long id = mAdapter.getItemId(position);
mMultiChoiceModeCallback.onItemCheckedStateChanged(mChoiceActionMode,
position, id, value);
}
} else {
boolean updateIds = mCheckedIdStates != null && mAdapter.hasStableIds();
// Clear all values if we're checking something, or unchecking the currently
// selected item
if (value || isItemChecked(position)) {
mCheckStates.clear();
if (updateIds) {
mCheckedIdStates.clear();
}
}
// this may end up selecting the value we just cleared but this way
// we ensure length of mCheckStates is 1, a fact getCheckedItemPosition relies on
if (value) {
mCheckStates.put(position, true);
if (updateIds) {
mCheckedIdStates.put(mAdapter.getItemId(position), position);
}
mCheckedItemCount = 1;
} else if (mCheckStates.size() == 0 || !mCheckStates.valueAt(0)) {
mCheckedItemCount = 0;
}
}
updateOnScreenCheckedViews();
}
/**
* @see #setChoiceMode(int)
*
* @return The current choice mode
*/
public int getChoiceMode() {
return mChoiceMode;
}
/**
* Defines the choice behavior for the List. By default, Lists do not have any choice behavior
* ({@link #CHOICE_MODE_NONE}). By setting the choiceMode to {@link #CHOICE_MODE_SINGLE}, the
* List allows up to one item to be in a chosen state. By setting the choiceMode to
* {@link #CHOICE_MODE_MULTIPLE}, the list allows any number of items to be chosen.
*
* @param choiceMode One of {@link #CHOICE_MODE_NONE}, {@link #CHOICE_MODE_SINGLE}, or
* {@link #CHOICE_MODE_MULTIPLE}
*/
public void setChoiceMode(int choiceMode) {
mChoiceMode = choiceMode;
if (mChoiceActionMode != null) {
mChoiceActionMode.finish();
mChoiceActionMode = null;
}
if (mChoiceMode != CHOICE_MODE_NONE) {
if (mCheckStates == null) {
mCheckStates = new SparseBooleanArray(0);
}
if (mCheckedIdStates == null && mAdapter != null && mAdapter.hasStableIds()) {
mCheckedIdStates = new LongSparseArray<>(0);
}
// Modal multi-choice mode only has choices when the mode is active. Clear them.
if (mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL) {
clearChoices();
setLongClickable(true);
}
}
}
/**
* Set a {@link MultiChoiceModeListener} that will manage the lifecycle of the
* selection {@link ActionMode}. Only used when the choice mode is set to
* {@link #CHOICE_MODE_MULTIPLE_MODAL}.
*
* @param listener Listener that will manage the selection mode
*
* @see #setChoiceMode(int)
*/
public void setMultiChoiceModeListener(MultiChoiceModeListener listener) {
if (mMultiChoiceModeCallback == null) {
mMultiChoiceModeCallback = new MultiChoiceModeWrapper();
}
mMultiChoiceModeCallback.setWrapped(listener);
}
/**
* Perform a quick, in-place update of the checked or activated state
* on all visible item views. This should only be called when a valid
* choice mode is active.
*/
private void updateOnScreenCheckedViews() {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
final int position = getChildAdapterPosition(child);
setViewChecked(child, mCheckStates.get(position));
}
}
public static void setViewChecked(View view, boolean checked) {
if (view instanceof Checkable) {
((Checkable) view).setChecked(checked);
} else {
view.setActivated(checked);
}
}
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
switch (event.getAction()) {
case MotionEvent.ACTION_SCROLL: {
if (getScrollState() != SCROLL_STATE_DRAGGING) {
final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
if (vscroll != 0) {
final int delta = (int) (vscroll * getVerticalScrollFactor());
scrollBy(0, -delta);
}
}
}
}
}
return super.onGenericMotionEvent(event);
}
/**
* Gets a scale factor that determines the distance the view should scroll
* vertically in response to {@link android.view.MotionEvent#ACTION_SCROLL}.
* @return The vertical scroll scale factor.
*/
protected float getVerticalScrollFactor() {
if (mVerticalScrollFactor == 0) {
TypedValue outValue = new TypedValue();
if (!getContext().getTheme().resolveAttribute(
0x0101004d, outValue, true)) {//com.android.internal.R.attr.listPreferredItemHeight
throw new IllegalStateException(
"Expected theme to define listPreferredItemHeight.");
}
mVerticalScrollFactor = outValue.getDimension(
getContext().getResources().getDisplayMetrics());
}
return mVerticalScrollFactor;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (!isEnabled()) {
// A disabled view that is clickable still consumes the touch
// events, it just doesn't respond to them.
return isClickable() || isLongClickable();
}
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN: {
onTouchDown(ev);
break;
}
case MotionEvent.ACTION_MOVE: {
onTouchMove(ev);
break;
}
case MotionEvent.ACTION_UP: {
onTouchUp(ev);
break;
}
case MotionEvent.ACTION_CANCEL: {
onTouchCancel();
break;
}
}
super.onTouchEvent(ev);
return true;
}
private void onTouchDown(MotionEvent ev) {
final float x = ev.getX();
final float y = ev.getY();
mStartX = x;
mStartY = y;
mMotionView = findChildViewUnder(x, y);
mMotionPosition = getChildAdapterPosition(mMotionView);
if (mMotionView != null && mMotionPosition >= 0) {
mHasPerformedLongPress = false;
mPrePressed = true;
if (mPendingCheckForTap == null) {
mPendingCheckForTap = new CheckForTap();
}
mPendingCheckForTap.x = x;
mPendingCheckForTap.y = y;
mPendingCheckForTap.v = mMotionView;
mPendingCheckForTap.p = mMotionPosition;
postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
} else {
mMotionView = null;
}
}
private void onTouchMove(MotionEvent ev) {
if (mTouchSlop == -1)
mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
if (mMotionView != null && mMotionPosition >= 0 &&
!MathUtils.near(mStartX, mStartY, ev.getX(), ev.getY(), mTouchSlop)) {
removeTapCallback();
if (mMotionView.isPressed()) {
// Remove any future long press/tap checks
removeLongPressCallback();
mMotionView.setPressed(false);
}
}
}
private void onTouchUp(MotionEvent ev) {
View motionView = mMotionView;
int motionPosition = mMotionPosition;
if (motionView != null && motionPosition >= 0) {
final float x = ev.getX();
final float y = ev.getY();
if (motionView.isPressed() || mPrePressed) {
// The button is being released before we actually
// showed it as pressed. Make it show the pressed
// state now (before scheduling the click) to ensure
// the user sees it.
final float[] point = mTmpPoint;
point[0] = x;
point[1] = y;
ViewUtils.transformPointToViewLocal(point, EasyRecyclerView.this, motionView);
setPressed(motionView, true, point[0], point[1]);
if (!mHasPerformedLongPress) {
// This is a tap, so remove the longpress check
removeLongPressCallback();
// Use a Runnable and post this rather than calling
// performClick directly. This lets other visual state
// of the view update before click actions start.
if (mPerformClick == null) {
mPerformClick = new PerformClick();
}
mPerformClick.v = motionView;
mPerformClick.p = motionPosition;
mPerformClick.rememberWindowAttachCount();
if (!post(mPerformClick)) {
mPerformClick.run();
}
}
if (mUnsetPressedState == null) {
mUnsetPressedState = new UnsetPressedState();
}
mUnsetPressedState.v = motionView;
if (mPrePressed) {
postDelayed(mUnsetPressedState, ViewConfiguration.getPressedStateDuration());
} else if (!post(mUnsetPressedState)) {
// If the post failed, unpress right now
mUnsetPressedState.run();
}
removeTapCallback();
}
// Release
mMotionView = null;
}
}
private void onTouchCancel() {
if (mMotionView != null && mMotionPosition >= 0) {
mMotionView.setPressed(false);
removeTapCallback();
removeLongPressCallback();
// Release motion view
mMotionView = null;
}
}
private void removeTapCallback() {
if (mPendingCheckForTap != null) {
mPrePressed = false;
removeCallbacks(mPendingCheckForTap);
mPendingCheckForTap.v = null;
}
}
private void removeLongPressCallback() {
if (mPendingCheckForLongPress != null) {
removeCallbacks(mPendingCheckForLongPress);
mPendingCheckForLongPress.v = null;
}
}
private void setPressed(View v, boolean pressed, float x, float y){
v.setPressed(pressed);
if (pressed && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
v.drawableHotspotChanged(x, y);
}
}
private boolean performItemClick(View view, int position, long id) {
boolean handled = false;
boolean dispatchItemClick = true;
if (mChoiceMode != CHOICE_MODE_NONE) {
handled = true;
boolean checkedStateChanged = false;
if (mChoiceMode == CHOICE_MODE_MULTIPLE ||
(mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL && mChoiceActionMode != null)) {
boolean checked = !mCheckStates.get(position, false);
mCheckStates.put(position, checked);
if (mCheckedIdStates != null && mAdapter.hasStableIds()) {
if (checked) {
mCheckedIdStates.put(mAdapter.getItemId(position), position);
} else {
mCheckedIdStates.delete(mAdapter.getItemId(position));
}
}
if (checked) {
mCheckedItemCount++;
} else {
mCheckedItemCount--;
}
if (mChoiceActionMode != null) {
mMultiChoiceModeCallback.onItemCheckedStateChanged(mChoiceActionMode,
position, id, checked);
dispatchItemClick = false;
}
checkedStateChanged = true;
} else if (mChoiceMode == CHOICE_MODE_SINGLE) {
boolean checked = !mCheckStates.get(position, false);
if (checked) {
mCheckStates.clear();
mCheckStates.put(position, true);
if (mCheckedIdStates != null && mAdapter.hasStableIds()) {
mCheckedIdStates.clear();
mCheckedIdStates.put(mAdapter.getItemId(position), position);
}
mCheckedItemCount = 1;
} else if (mCheckStates.size() == 0 || !mCheckStates.valueAt(0)) {
mCheckedItemCount = 0;
}
checkedStateChanged = true;
}
if (checkedStateChanged) {
updateOnScreenCheckedViews();
}
}
if (dispatchItemClick) {
if (mOnItemClickListener != null) {
playSoundEffect(SoundEffectConstants.CLICK);
mOnItemClickListener.onItemClick(this, view, position, id);
if (view != null) {
view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
}
handled = true;
}
}
return handled;
}
private boolean performItemLongPress(final View child,
final int longPressPosition, final long longPressId) {
// CHOICE_MODE_MULTIPLE_MODAL takes over long press.
if (mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL) {
if (mChoiceActionMode == null &&
(mChoiceActionMode = startActionMode(mMultiChoiceModeCallback)) != null) {
setItemChecked(longPressPosition, true);
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
}
return true;
}
boolean handled = false;
if (mOnItemLongClickListener != null) {
handled = mOnItemLongClickListener.onItemLongClick(this, child,
longPressPosition, longPressId);
}
if (handled) {
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
}
return handled;
}
/**
* Register a callback to be invoked when an item in this AdapterView has
* been clicked.
*
* @param listener The callback that will be invoked.
*/
public void setOnItemClickListener(OnItemClickListener listener) {
mOnItemClickListener = listener;
}
public void setOnItemLongClickListener(OnItemLongClickListener listener) {
if (!isLongClickable()) {
setLongClickable(true);
}
mOnItemLongClickListener = listener;
}
/**
* If choice mode is set, call it in {@link Adapter#onBindViewHolder}
*/
public void checkItemCheckedState(View view, int position) {
setViewChecked(view, isItemChecked(position));
}
/*
@Override
public Parcelable onSaveInstanceState() {
final Parcelable state = new Bundle(super.onSaveInstanceState());
state.putInt(STATE_KEY_CHOICE_MODE, mChoiceMode);
state.putParcelable(STATE_KEY_CHECKED_STATES, mCheckStates);
state.putParcelable(STATE_KEY_CHECKED_ID_STATES, mCheckedIdStates);
state.putInt(STATE_KEY_CHECKED_COUNT, mCheckedItemCount);
return state;
}
public void onRestoreInstanceState(Bundle state) {
mChoiceMode = ChoiceMode.values()[state.getInt(STATE_KEY_CHOICE_MODE)];
mCheckedStates = state.getParcelable(STATE_KEY_CHECKED_STATES);
mCheckedIdStates = state.getParcelable(STATE_KEY_CHECKED_ID_STATES);
mCheckedCount = state.getInt(STATE_KEY_CHECKED_COUNT);
// TODO confirm ids here
}*/
private final class CheckForTap implements Runnable {
float x;
float y;
View v;
int p;
@Override
public void run() {
View view = v;
int position = p;
if (view != null && position >= 0) {
mPrePressed = false;
final float[] point = mTmpPoint;
point[0] = x;
point[1] = y;
ViewUtils.transformPointToViewLocal(point, EasyRecyclerView.this, view);
setPressed(v, true, point[0], point[1]);
if (isLongClickable()) {
mHasPerformedLongPress = false;
if (mPendingCheckForLongPress == null) {
mPendingCheckForLongPress = new CheckForLongPress();
}
mPendingCheckForLongPress.rememberWindowAttachCount();
mPendingCheckForLongPress.v = view;
mPendingCheckForLongPress.p = position;
postDelayed(mPendingCheckForLongPress, ViewConfiguration.getLongPressTimeout() -
ViewConfiguration.getTapTimeout());
}
}
// Release
v = null;
}
}
private class CheckForLongPress extends WindowRunnnable implements Runnable {
View v;
int p;
@Override
public void run() {
View view = v;
int position = p;
if (view != null && position >= 0 && view.isPressed() && view.getParent() != null) {
boolean handled = false;
if (sameWindow()) {
handled = performItemLongPress(view, position, getAdapter().getItemId(position));
}
if (handled) {
mHasPerformedLongPress = true;
view.setPressed(false);
}
}
// Release
v = null;
}
}
private final class UnsetPressedState implements Runnable {
View v;
@Override
public void run() {
if (v != null) {
v.setPressed(false);
// Release
v = null;
}
}
}
private class PerformClick extends WindowRunnnable implements Runnable {
View v;
int p;
@Override
public void run() {
View view = v;
int position = p;
if (view != null && position >= 0 && sameWindow()) {
performItemClick(view, position, mAdapter.getItemId(position));
}
// Release
v = null;
}
}
/**
* A base class for Runnables that will check that their view is still attached to
* the original window as when the Runnable was created.
*
*/
private class WindowRunnnable {
private int mOriginalAttachCount;
public void rememberWindowAttachCount() {
mOriginalAttachCount = getWindowAttachCount();
}
public boolean sameWindow() {
return getWindowAttachCount() == mOriginalAttachCount;
}
}
/**
* Interface definition for a callback to be invoked when an item in the
* EasyRecyclerView has been clicked.
*/
public interface OnItemClickListener {
/**
* Callback method to be invoked when an item in the EasyRecyclerView
* has been clicked.
*
* @param parent The EasyRecyclerView where the click happened.
* @param view The view within the EasyRecyclerView that was clicked
* @param position The position of the view in the adapter.
* @param id The row id of the item that was clicked.
*
* @return true if the callback consumed the click, false otherwise
*/
boolean onItemClick(EasyRecyclerView parent, View view, int position, long id);
}
/**
* Interface definition for a callback to be invoked when an item in the
* EasyRecyclerView has been clicked and held.
*/
public interface OnItemLongClickListener {
/**
* Callback method to be invoked when an item in the EasyRecyclerView
* has been clicked and held.
*
* @param parent The EasyRecyclerView where the click happened
* @param view The view within the EasyRecyclerView that was clicked
* @param position The position of the view in the list
* @param id The row id of the item that was clicked
*
* @return true if the callback consumed the long click, false otherwise
*/
boolean onItemLongClick(EasyRecyclerView parent, View view, int position, long id);
}
/**
* A MultiChoiceModeListener receives events for {@link android.widget.AbsListView#CHOICE_MODE_MULTIPLE_MODAL}.
* It acts as the {@link ActionMode.Callback} for the selection mode and also receives
* {@link #onItemCheckedStateChanged(ActionMode, int, long, boolean)} events when the user
* selects and deselects list items.
*/
public interface MultiChoiceModeListener extends ActionMode.Callback {
/**
* Called when an item is checked or unchecked during selection mode.
*
* @param mode The {@link ActionMode} providing the selection mode
* @param position Adapter position of the item that was checked or unchecked
* @param id Adapter ID of the item that was checked or unchecked
* @param checked <code>true</code> if the item is now checked, <code>false</code>
* if the item is now unchecked.
*/
void onItemCheckedStateChanged(ActionMode mode,
int position, long id, boolean checked);
}
class MultiChoiceModeWrapper implements MultiChoiceModeListener {
private MultiChoiceModeListener mWrapped;
public void setWrapped(MultiChoiceModeListener wrapped) {
mWrapped = wrapped;
}
public boolean hasWrappedCallback() {
return mWrapped != null;
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
if (mWrapped.onCreateActionMode(mode, menu)) {
// Initialize checked graphic state?
setLongClickable(false);
return true;
}
return false;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return mWrapped.onPrepareActionMode(mode, menu);
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return mWrapped.onActionItemClicked(mode, item);
}
@Override
public void onDestroyActionMode(ActionMode mode) {
mWrapped.onDestroyActionMode(mode);
mChoiceActionMode = null;
// Ending selection mode means deselecting everything.
clearChoices();
requestLayout();
setLongClickable(true);
}
@Override
public void onItemCheckedStateChanged(ActionMode mode,
int position, long id, boolean checked) {
mWrapped.onItemCheckedStateChanged(mode, position, id, checked);
// If there are no items selected we no longer need the selection mode.
if (getCheckedItemCount() == 0) {
mode.finish();
}
}
}
}
@@ -1,162 +0,0 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget.recyclerview;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class LinearDividerItemDecoration extends RecyclerView.ItemDecoration {
public static final int HORIZONTAL = LinearLayoutManager.HORIZONTAL;
public static final int VERTICAL = LinearLayoutManager.VERTICAL;
private boolean mShowFirstDivider = false;
private boolean mShowLastDivider = false;
private final Rect mRect;
private final Paint mPaint;
private int mOrientation;
private int mThickness;
private int mPaddingStart = 0;
private int mPaddingEnd = 0;
public LinearDividerItemDecoration(int orientation, int color, int thickness) {
mRect = new Rect();
mPaint = new Paint();
mPaint.setStyle(Paint.Style.FILL);
setOrientation(orientation);
setColor(color);
setThickness(thickness);
}
public void setOrientation(int orientation) {
if (orientation != HORIZONTAL && orientation != VERTICAL) {
throw new IllegalArgumentException("invalid orientation");
}
mOrientation = orientation;
}
public void setColor(int color) {
mPaint.setColor(color);
}
public void setThickness(int thickness) {
mThickness = thickness;
}
public void setShowFirstDivider(boolean showFirstDivider) {
mShowFirstDivider = showFirstDivider;
}
public void setShowLastDivider(boolean showLastDivider) {
mShowLastDivider = showLastDivider;
}
public void setPadding(int padding) {
setPaddingStart(padding);
setPaddingEnd(padding);
}
public void setPaddingStart(int paddingStart) {
mPaddingStart = paddingStart;
}
public void setPaddingEnd(int paddingEnd) {
mPaddingEnd = paddingEnd;
}
@Override
public void getItemOffsets(Rect outRect, View view,
RecyclerView parent, RecyclerView.State state) {
final int position = parent.getChildPosition(view);
final int itemCount = parent.getAdapter().getItemCount();
if (mOrientation == VERTICAL) {
if (position == 0 && mShowFirstDivider)
outRect.top = mThickness;
outRect.bottom = mThickness;
if (position == itemCount - 1 && !mShowLastDivider)
outRect.bottom = 0;
} else {
if (position == 0 && mShowFirstDivider)
outRect.left = mThickness;
outRect.right = mThickness;
if (position == itemCount - 1 && !mShowLastDivider)
outRect.left = 0;
}
}
@Override
public void onDrawOver(Canvas c, RecyclerView parent,
RecyclerView.State state) {
int itemCount = parent.getAdapter().getItemCount();
if (mOrientation == VERTICAL) {
final int left = parent.getPaddingLeft() + mPaddingStart;
final int right = parent.getWidth() - parent.getPaddingRight() - mPaddingEnd;
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) child.getLayoutParams();
if (i != childCount - 1 || mShowLastDivider
|| parent.getChildPosition(child) != itemCount - 1) {
final int top = child.getBottom() + lp.bottomMargin;
final int bottom = top + mThickness;
mRect.set(left, top, right, bottom);
c.drawRect(mRect, mPaint);
}
if (i == 0 && mShowFirstDivider && parent.getChildPosition(child) == 0) {
final int bottom = child.getTop() + lp.topMargin;
final int top = bottom - mThickness;
mRect.set(left, top, right, bottom);
c.drawRect(mRect, mPaint);
}
}
} else {
final int top = parent.getPaddingTop() + mPaddingStart;
final int bottom = parent.getHeight() - parent.getPaddingBottom() - mPaddingEnd;
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) child.getLayoutParams();
if (i != childCount - 1 || mShowLastDivider
|| parent.getChildPosition(child) != itemCount - 1) {
final int left = child.getRight() + lp.rightMargin;
final int right = left + mThickness;
mRect.set(left, top, right, bottom);
c.drawRect(mRect, mPaint);
}
if (i == 0 && mShowFirstDivider && parent.getChildPosition(child) == 0) {
final int right = child.getLeft() + lp.leftMargin;
final int left = right - mThickness;
mRect.set(left, top, right, bottom);
c.drawRect(mRect, mPaint);
}
}
}
}
}
@@ -1,46 +0,0 @@
/*
* Copyright (C) 2014 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget.recyclerview;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;
/**
* Only work for StaggeredGridLayoutManager, FooterAdapter
*
* @author Hippo
*
*/
public class MarginItemDecoration extends RecyclerView.ItemDecoration {
private int mHalfMargin;
@Override
public void getItemOffsets(Rect outRect, View view,
RecyclerView parent, RecyclerView.State state) {
outRect.set(mHalfMargin, mHalfMargin, mHalfMargin, mHalfMargin);
}
public void setMargin(int margin) {
mHalfMargin = margin / 2;
}
public int getMargin() {
return mHalfMargin * 2;
}
}
@@ -1,376 +0,0 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.hippo.ehviewer.widget.recyclerview;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Based on Roman Nurik's Android-SwipeToDismiss lib <a href="https://github.com/romannurik/Android-SwipeToDismiss">https://github.com/romannurik/Android-SwipeToDismiss</a>
* <p/>
* RecyclerView.OnItemTouchListener that allows items to be swiped and dismissed.
* <p/>
* Typical usage:
* <p/>
* <pre>
* {@code
* swipeToDismissTouchListener = new SwipeToDismissTouchListener(recyclerView, new SwipeToDismissTouchListener.DismissCallbacks() {
* @Override
* public SwipeToDismissTouchListener.SwipeDirection dismissDirection(int position) {
* return SwipeToDismissTouchListener.SwipeDirection.RIGHT;
* }
* @Override
* public void onDismiss(RecyclerView view, List<SwipeToDismissTouchListener.PendingDismissData> dismissData) {
* for (SwipeToDismissTouchListener.PendingDismissData data : dismissData) {
* adapter.removeItem(data.position);
* adapter.notifyItemRemoved(data.position);
* }
* }
* });
*
* }
* </pre>
*/
public class SwipeToDismissTouchListener implements RecyclerView.OnItemTouchListener {
private final RecyclerView mRecyclerView;
private int mSlop;
private int mMinFlingVelocity;
private int mMaxFlingVelocity;
private long mAnimationTime;
private DismissCallbacks mCallbacks;
private int mViewWidth = 1; // 1 and not 0 to prevent dividing by zero
// Transient properties
private float mDownX;
private float mDownY;
private boolean mSwiping;
private int mSwipingSlop;
private VelocityTracker mVelocityTracker;
private float mTranslationX;
private boolean mPaused = false;
private View mSwipeView;
private int mDismissCount = 0;
private List<PendingDismissData> mPendingDismisses = new ArrayList<PendingDismissData>();
private SwipeDirection mAllowedSwipeDirection = SwipeDirection.NONE;
private int[] notToDismissPositionArray;
/**
* Constructs a new swipe-to-dismiss OnItemTouchListener for RecyclerView
*
* @param recyclerView RecyclerView
* @param callbacks The callback to trigger when the user has indicated that she would like to
* dismiss this view.
*/
public SwipeToDismissTouchListener(RecyclerView recyclerView, DismissCallbacks callbacks) {
ViewConfiguration vc = ViewConfiguration.get(recyclerView.getContext());
mSlop = vc.getScaledTouchSlop();
mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 4;
mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
mAnimationTime = recyclerView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);
mRecyclerView = recyclerView;
mCallbacks = callbacks;
}
/**
* Constructs a new swipe-to-dismiss OnItemTouchListener for RecyclerView
*
* @param recyclerView RecyclerView
* @param callbacks The callback to trigger when the user has indicated that she would like to
* dismiss this view.
*/
public SwipeToDismissTouchListener(RecyclerView recyclerView, DismissCallbacks callbacks, int[] notToDismiss) {
ViewConfiguration vc = ViewConfiguration.get(recyclerView.getContext());
mSlop = vc.getScaledTouchSlop();
mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 4;
mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
mAnimationTime = recyclerView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);
mRecyclerView = recyclerView;
mCallbacks = callbacks;
notToDismissPositionArray = notToDismiss;
}
public int[] getNotToDismissPositionArray() {
return notToDismissPositionArray;
}
public void setNotToDismissPositionArray(int[] notToDismissPositionArray) {
this.notToDismissPositionArray = notToDismissPositionArray;
}
public void setEnabled(boolean enabled) {
mPaused = !enabled;
}
@Override
public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
motionEvent.offsetLocation(mTranslationX, 0);
switch (motionEvent.getActionMasked()) {
case MotionEvent.ACTION_UP: {
up(motionEvent);
break;
}
case MotionEvent.ACTION_CANCEL: {
cancel();
break;
}
case MotionEvent.ACTION_MOVE: {
move(motionEvent);
break;
}
}
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean b) {
}
@Override
public boolean onInterceptTouchEvent(final RecyclerView view, MotionEvent motionEvent) {
if (mPaused) return false;
// offset because the view is translated during swipe
motionEvent.offsetLocation(mTranslationX, 0);
if (mViewWidth < 2) {
mViewWidth = view.getWidth();
}
switch (motionEvent.getActionMasked()) {
case MotionEvent.ACTION_DOWN: {
return down(motionEvent);
}
case MotionEvent.ACTION_MOVE: {
return move(motionEvent);
}
}
return false;
}
private boolean down(MotionEvent motionEvent) {
if (mPaused) return false;
mDownX = motionEvent.getRawX();
mDownY = motionEvent.getRawY();
mSwipeView = mRecyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY());
if (mSwipeView == null) return false;
int pos = mRecyclerView.getChildLayoutPosition(mSwipeView);
if (notToDismissPositionArray != null && notToDismissPositionArray.length > 0) {
for (int notToDismiss : notToDismissPositionArray) {
if (pos == notToDismiss) return false;
}
}
mAllowedSwipeDirection = mCallbacks.dismissDirection(pos);
if (mAllowedSwipeDirection != SwipeDirection.NONE) {
mVelocityTracker = VelocityTracker.obtain();
mVelocityTracker.addMovement(motionEvent);
return false;
}
resetMotion();
return false;
}
private void cancel() {
if (mVelocityTracker == null) {
return;
}
mSwipeView.animate()
.translationX(0)
.alpha(1)
.setDuration(mAnimationTime)
.setListener(null);
mVelocityTracker.recycle();
mVelocityTracker = null;
mTranslationX = 0;
mDownX = 0;
mDownY = 0;
mSwiping = false;
mSwipeView = null;
}
private void up(MotionEvent motionEvent) {
if (mPaused || mVelocityTracker == null || mSwipeView == null) {
return;
}
mSwipeView.setPressed(false);
float deltaX = motionEvent.getRawX() - mDownX;
mVelocityTracker.addMovement(motionEvent);
mVelocityTracker.computeCurrentVelocity(1000);
float velocityX = mVelocityTracker.getXVelocity();
float absVelocityX = Math.abs(velocityX);
float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
boolean dismiss = false;
boolean dismissRight = false;
if (Math.abs(deltaX) > mViewWidth / 2 && mSwiping) {
dismiss = true;
dismissRight = deltaX > 0;
} else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity
&& absVelocityY < absVelocityX
&& absVelocityY < absVelocityX && mSwiping) {
// dismiss only if flinging in the same direction as dragging
dismiss = (velocityX < 0) == (deltaX < 0);
dismissRight = mVelocityTracker.getXVelocity() > 0;
}
if (dismiss) {
// dismiss
final int pos = mRecyclerView.getChildLayoutPosition(mSwipeView);
final View swipeViewCopy = mSwipeView;
final SwipeDirection swipeDirection = dismissRight ? SwipeDirection.RIGHT : SwipeDirection.LEFT;
++mDismissCount;
mSwipeView.animate()
.translationX(dismissRight ? mViewWidth : -mViewWidth)
.alpha(0)
.setDuration(mAnimationTime);
//this is instead of unreliable onAnimationEnd callback
swipeViewCopy.postDelayed(new Runnable() {
@Override
public void run() {
performDismiss(swipeViewCopy, pos, swipeDirection);
swipeViewCopy.setTranslationX(0);
// swipeViewCopy.setAlpha(1);
}
}, mAnimationTime + 100);
} else if (mSwiping) {
// cancel
mSwipeView.animate()
.translationX(0)
.alpha(1)
.setDuration(mAnimationTime)
.setListener(null);
}
resetMotion();
}
private boolean move(MotionEvent motionEvent) {
if (mSwipeView == null || mVelocityTracker == null || mPaused) {
return false;
}
mVelocityTracker.addMovement(motionEvent);
float deltaX = motionEvent.getRawX() - mDownX;
float deltaY = motionEvent.getRawY() - mDownY;
if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
mSwiping = true;
mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
mSwipeView.setPressed(false);
MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
mSwipeView.onTouchEvent(cancelEvent);
}
//Prevent swipes to disallowed directions
if ((deltaX < 0 && mAllowedSwipeDirection == SwipeDirection.RIGHT) || (deltaX > 0 && mAllowedSwipeDirection == SwipeDirection.LEFT)) {
resetMotion();
return false;
}
if (mSwiping) {
mCallbacks.onTouchDown();
mTranslationX = deltaX;
mSwipeView.setTranslationX(deltaX - mSwipingSlop);
mSwipeView.setAlpha(Math.max(0f, Math.min(1f,
1f - 2f * Math.abs(deltaX) / mViewWidth)));
return true;
}
return false;
}
private void resetMotion() {
if (mVelocityTracker != null) {
mVelocityTracker.recycle();
mVelocityTracker = null;
}
mCallbacks.onResetMotion();
mTranslationX = 0;
mDownX = 0;
mDownY = 0;
mSwiping = false;
mSwipeView = null;
mAllowedSwipeDirection = SwipeDirection.NONE;
}
private void performDismiss(View dismissView, int pos, SwipeDirection direction) {
--mDismissCount;
mPendingDismisses.add(new PendingDismissData(pos, dismissView, direction));
if (mDismissCount == 0) {
Collections.sort(mPendingDismisses);
List<PendingDismissData> dismissData = new ArrayList<>(mPendingDismisses);
mCallbacks.onDismiss(mRecyclerView, dismissData);
mPendingDismisses.clear();
}
}
public interface DismissCallbacks {
SwipeDirection dismissDirection(int position);
void onDismiss(RecyclerView view, List<PendingDismissData> dismissData);
void onResetMotion();
void onTouchDown();
}
public class PendingDismissData implements Comparable<PendingDismissData> {
public int position;
public View view;
public SwipeDirection direction;
public PendingDismissData(int position, View view, SwipeDirection direction) {
this.position = position;
this.view = view;
this.direction = direction;
}
@Override
public int compareTo(@NonNull PendingDismissData other) {
return other.position - position;
}
}
public enum SwipeDirection {
LEFT, RIGHT, BOTH, NONE
}
}
@@ -1,84 +0,0 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget.refreshlayout;
import android.view.animation.Interpolator;
/**
* A pre-baked bezier-curved interpolator for indeterminate progress animations.
*/
final class BakedBezierInterpolator implements Interpolator {
private static final BakedBezierInterpolator INSTANCE = new BakedBezierInterpolator();
public final static BakedBezierInterpolator getInstance() {
return INSTANCE;
}
/**
* Use getInstance instead of instantiating.
*/
private BakedBezierInterpolator() {
super();
}
/**
* Lookup table values.
* Generated using a Bezier curve from (0,0) to (1,1) with control points:
* P0 (0,0)
* P1 (0.4, 0)
* P2 (0.2, 1.0)
* P3 (1.0, 1.0)
*
* Values sampled with x at regular intervals between 0 and 1.
*/
private static final float[] VALUES = new float[] {
0.0f, 0.0002f, 0.0009f, 0.0019f, 0.0036f, 0.0059f, 0.0086f, 0.0119f, 0.0157f, 0.0209f,
0.0257f, 0.0321f, 0.0392f, 0.0469f, 0.0566f, 0.0656f, 0.0768f, 0.0887f, 0.1033f, 0.1186f,
0.1349f, 0.1519f, 0.1696f, 0.1928f, 0.2121f, 0.237f, 0.2627f, 0.2892f, 0.3109f, 0.3386f,
0.3667f, 0.3952f, 0.4241f, 0.4474f, 0.4766f, 0.5f, 0.5234f, 0.5468f, 0.5701f, 0.5933f,
0.6134f, 0.6333f, 0.6531f, 0.6698f, 0.6891f, 0.7054f, 0.7214f, 0.7346f, 0.7502f, 0.763f,
0.7756f, 0.7879f, 0.8f, 0.8107f, 0.8212f, 0.8326f, 0.8415f, 0.8503f, 0.8588f, 0.8672f,
0.8754f, 0.8833f, 0.8911f, 0.8977f, 0.9041f, 0.9113f, 0.9165f, 0.9232f, 0.9281f, 0.9328f,
0.9382f, 0.9434f, 0.9476f, 0.9518f, 0.9557f, 0.9596f, 0.9632f, 0.9662f, 0.9695f, 0.9722f,
0.9753f, 0.9777f, 0.9805f, 0.9826f, 0.9847f, 0.9866f, 0.9884f, 0.9901f, 0.9917f, 0.9931f,
0.9944f, 0.9955f, 0.9964f, 0.9973f, 0.9981f, 0.9986f, 0.9992f, 0.9995f, 0.9998f, 1.0f, 1.0f
};
private static final float STEP_SIZE = 1.0f / (VALUES.length - 1);
@Override
public float getInterpolation(float input) {
if (input >= 1.0f) {
return 1.0f;
}
if (input <= 0f) {
return 0f;
}
int position = Math.min(
(int)(input * (VALUES.length - 1)),
VALUES.length - 2);
float quantized = position * STEP_SIZE;
float difference = input - quantized;
float weight = difference / STEP_SIZE;
return VALUES[position] + weight * (VALUES[position + 1] - VALUES[position]);
}
}
@@ -1,154 +0,0 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget.refreshlayout;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.support.v4.view.ViewCompat;
import android.view.animation.Animation;
import android.widget.ImageView;
/**
* Private class created to work around issues with AnimationListeners being
* called before the animation is actually complete and support shadows on older
* platforms.
*
* @hide
*/
class CircleImageView extends ImageView {
private static final int KEY_SHADOW_COLOR = 0x1E000000;
private static final int FILL_SHADOW_COLOR = 0x3D000000;
// PX
private static final float X_OFFSET = 0f;
private static final float Y_OFFSET = 1.75f;
private static final float SHADOW_RADIUS = 3.5f;
private static final int SHADOW_ELEVATION = 4;
private Animation.AnimationListener mListener;
private int mShadowRadius;
public CircleImageView(Context context, int color, final float radius) {
super(context);
final float density = getContext().getResources().getDisplayMetrics().density;
final int diameter = (int) (radius * density * 2);
final int shadowYOffset = (int) (density * Y_OFFSET);
final int shadowXOffset = (int) (density * X_OFFSET);
mShadowRadius = (int) (density * SHADOW_RADIUS);
ShapeDrawable circle;
if (elevationSupported()) {
circle = new ShapeDrawable(new OvalShape());
ViewCompat.setElevation(this, SHADOW_ELEVATION * density);
} else {
OvalShape oval = new OvalShadow(mShadowRadius, diameter);
circle = new ShapeDrawable(oval);
ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, circle.getPaint());
circle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset,
KEY_SHADOW_COLOR);
final int padding = mShadowRadius;
// set padding so the inner image sits correctly within the shadow.
setPadding(padding, padding, padding, padding);
}
circle.getPaint().setColor(color);
setBackgroundDrawable(circle);
}
private boolean elevationSupported() {
return android.os.Build.VERSION.SDK_INT >= 21;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (!elevationSupported()) {
setMeasuredDimension(getMeasuredWidth() + mShadowRadius*2, getMeasuredHeight()
+ mShadowRadius*2);
}
}
public void setAnimationListener(Animation.AnimationListener listener) {
mListener = listener;
}
@Override
public void onAnimationStart() {
super.onAnimationStart();
if (mListener != null) {
mListener.onAnimationStart(getAnimation());
}
}
@Override
public void onAnimationEnd() {
super.onAnimationEnd();
if (mListener != null) {
mListener.onAnimationEnd(getAnimation());
}
}
/**
* Update the background color of the circle image view.
*
* @param colorRes Id of a color resource.
*/
public void setBackgroundColorRes(int colorRes) {
setBackgroundColor(getContext().getResources().getColor(colorRes));
}
@Override
public void setBackgroundColor(int color) {
if (getBackground() instanceof ShapeDrawable) {
((ShapeDrawable) getBackground()).getPaint().setColor(color);
}
}
private class OvalShadow extends OvalShape {
private RadialGradient mRadialGradient;
private int mShadowRadius;
private Paint mShadowPaint;
private int mCircleDiameter;
public OvalShadow(int shadowRadius, int circleDiameter) {
super();
mShadowPaint = new Paint();
mShadowRadius = shadowRadius;
mCircleDiameter = circleDiameter;
mRadialGradient = new RadialGradient(mCircleDiameter / 2, mCircleDiameter / 2,
mShadowRadius, new int[] {
FILL_SHADOW_COLOR, Color.TRANSPARENT
}, null, Shader.TileMode.CLAMP);
mShadowPaint.setShader(mRadialGradient);
}
@Override
public void draw(Canvas canvas, Paint paint) {
final int viewWidth = CircleImageView.this.getWidth();
final int viewHeight = CircleImageView.this.getHeight();
canvas.drawCircle(viewWidth / 2, viewHeight / 2, (mCircleDiameter / 2 + mShadowRadius),
mShadowPaint);
canvas.drawCircle(viewWidth / 2, viewHeight / 2, (mCircleDiameter / 2), paint);
}
}
}
@@ -1,714 +0,0 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget.refreshlayout;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
/**
* Fancy progress indicator for Material theme.
*
* @hide
*/
class MaterialProgressDrawable extends Drawable implements Animatable {
private static final Interpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
private static final Interpolator END_CURVE_INTERPOLATOR = new EndCurveInterpolator();
private static final Interpolator START_CURVE_INTERPOLATOR = new StartCurveInterpolator();
private static final Interpolator EASE_INTERPOLATOR = new AccelerateDecelerateInterpolator();
@Retention(RetentionPolicy.CLASS)
@IntDef({LARGE, DEFAULT})
public @interface ProgressDrawableSize {}
// Maps to ProgressBar.Large style
static final int LARGE = 0;
// Maps to ProgressBar default style
static final int DEFAULT = 1;
// Maps to ProgressBar default style
private static final int CIRCLE_DIAMETER = 40;
private static final float CENTER_RADIUS = 8.75f; //should add up to 10 when + stroke_width
private static final float STROKE_WIDTH = 2.5f;
// Maps to ProgressBar.Large style
private static final int CIRCLE_DIAMETER_LARGE = 56;
private static final float CENTER_RADIUS_LARGE = 12.5f;
private static final float STROKE_WIDTH_LARGE = 3f;
private final int[] COLORS = new int[] {
Color.BLACK
};
/** The duration of a single progress spin in milliseconds. */
private static final int ANIMATION_DURATION = 1000 * 80 / 60;
/** The number of points in the progress "star". */
private static final float NUM_POINTS = 5f;
/** The list of animators operating on this drawable. */
private final ArrayList<Animation> mAnimators = new ArrayList<Animation>();
/** The indicator ring, used to manage animation state. */
private final Ring mRing;
/** Canvas rotation in degrees. */
private float mRotation;
/** Layout info for the arrowhead in dp */
private static final int ARROW_WIDTH = 10;
private static final int ARROW_HEIGHT = 5;
private static final float ARROW_OFFSET_ANGLE = 5;
/** Layout info for the arrowhead for the large spinner in dp */
private static final int ARROW_WIDTH_LARGE = 12;
private static final int ARROW_HEIGHT_LARGE = 6;
private static final float MAX_PROGRESS_ARC = .8f;
private Resources mResources;
private View mParent;
private Animation mAnimation;
private float mRotationCount;
private double mWidth;
private double mHeight;
boolean mFinishing;
public MaterialProgressDrawable(Context context, View parent) {
mParent = parent;
mResources = context.getResources();
mRing = new Ring(mCallback);
mRing.setColors(COLORS);
updateSizes(DEFAULT);
setupAnimators();
}
private void setSizeParameters(double progressCircleWidth, double progressCircleHeight,
double centerRadius, double strokeWidth, float arrowWidth, float arrowHeight) {
final Ring ring = mRing;
final DisplayMetrics metrics = mResources.getDisplayMetrics();
final float screenDensity = metrics.density;
mWidth = progressCircleWidth * screenDensity;
mHeight = progressCircleHeight * screenDensity;
ring.setStrokeWidth((float) strokeWidth * screenDensity);
ring.setCenterRadius(centerRadius * screenDensity);
ring.setColorIndex(0);
ring.setArrowDimensions(arrowWidth * screenDensity, arrowHeight * screenDensity);
ring.setInsets((int) mWidth, (int) mHeight);
}
/**
* Set the overall size for the progress spinner. This updates the radius
* and stroke width of the ring.
*
* @param size One of {@link #LARGE} or
* {@link #DEFAULT}
*/
public void updateSizes(@ProgressDrawableSize int size) {
if (size == LARGE) {
setSizeParameters(CIRCLE_DIAMETER_LARGE, CIRCLE_DIAMETER_LARGE, CENTER_RADIUS_LARGE,
STROKE_WIDTH_LARGE, ARROW_WIDTH_LARGE, ARROW_HEIGHT_LARGE);
} else {
setSizeParameters(CIRCLE_DIAMETER, CIRCLE_DIAMETER, CENTER_RADIUS, STROKE_WIDTH,
ARROW_WIDTH, ARROW_HEIGHT);
}
}
/**
* @param show Set to true to display the arrowhead on the progress spinner.
*/
public void showArrow(boolean show) {
mRing.setShowArrow(show);
}
/**
* @param scale Set the scale of the arrowhead for the spinner.
*/
public void setArrowScale(float scale) {
mRing.setArrowScale(scale);
}
/**
* Set the start and end trim for the progress spinner arc.
*
* @param startAngle start angle
* @param endAngle end angle
*/
public void setStartEndTrim(float startAngle, float endAngle) {
mRing.setStartTrim(startAngle);
mRing.setEndTrim(endAngle);
}
/**
* Set the amount of rotation to apply to the progress spinner.
*
* @param rotation Rotation is from [0..1]
*/
public void setProgressRotation(float rotation) {
mRing.setRotation(rotation);
}
/**
* Update the background color of the circle image view.
*/
public void setBackgroundColor(int color) {
mRing.setBackgroundColor(color);
}
/**
* Set the colors used in the progress animation from color resources.
* The first color will also be the color of the bar that grows in response
* to a user swipe gesture.
*
* @param colors
*/
public void setColorSchemeColors(int... colors) {
mRing.setColors(colors);
mRing.setColorIndex(0);
}
@Override
public int getIntrinsicHeight() {
return (int) mHeight;
}
@Override
public int getIntrinsicWidth() {
return (int) mWidth;
}
@Override
public void draw(Canvas c) {
final Rect bounds = getBounds();
final int saveCount = c.save();
c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY());
mRing.draw(c, bounds);
c.restoreToCount(saveCount);
}
@Override
public void setAlpha(int alpha) {
mRing.setAlpha(alpha);
}
public int getAlpha() {
return mRing.getAlpha();
}
@Override
public void setColorFilter(ColorFilter colorFilter) {
mRing.setColorFilter(colorFilter);
}
@SuppressWarnings("unused")
void setRotation(float rotation) {
mRotation = rotation;
invalidateSelf();
}
@SuppressWarnings("unused")
private float getRotation() {
return mRotation;
}
@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}
@Override
public boolean isRunning() {
final ArrayList<Animation> animators = mAnimators;
final int N = animators.size();
for (int i = 0; i < N; i++) {
final Animation animator = animators.get(i);
if (animator.hasStarted() && !animator.hasEnded()) {
return true;
}
}
return false;
}
@Override
public void start() {
mAnimation.reset();
mRing.storeOriginals();
// Already showing some part of the ring
if (mRing.getEndTrim() != mRing.getStartTrim()) {
mFinishing = true;
mAnimation.setDuration(ANIMATION_DURATION/2);
mParent.startAnimation(mAnimation);
} else {
mRing.setColorIndex(0);
mRing.resetOriginals();
mAnimation.setDuration(ANIMATION_DURATION);
mParent.startAnimation(mAnimation);
}
}
@Override
public void stop() {
mParent.clearAnimation();
setRotation(0);
mRing.setShowArrow(false);
mRing.setColorIndex(0);
mRing.resetOriginals();
}
private void applyFinishTranslation(float interpolatedTime, Ring ring) {
// shrink back down and complete a full rotation before
// starting other circles
// Rotation goes between [0..1].
float targetRotation = (float) (Math.floor(ring.getStartingRotation() / MAX_PROGRESS_ARC)
+ 1f);
final float startTrim = ring.getStartingStartTrim()
+ (ring.getStartingEndTrim() - ring.getStartingStartTrim()) * interpolatedTime;
ring.setStartTrim(startTrim);
final float rotation = ring.getStartingRotation()
+ ((targetRotation - ring.getStartingRotation()) * interpolatedTime);
ring.setRotation(rotation);
}
private void setupAnimators() {
final Ring ring = mRing;
final Animation animation = new Animation() {
@Override
public void applyTransformation(float interpolatedTime, Transformation t) {
if (mFinishing) {
applyFinishTranslation(interpolatedTime, ring);
} else {
// The minProgressArc is calculated from 0 to create an
// angle that
// matches the stroke width.
final float minProgressArc = (float) Math.toRadians(
ring.getStrokeWidth() / (2 * Math.PI * ring.getCenterRadius()));
final float startingEndTrim = ring.getStartingEndTrim();
final float startingTrim = ring.getStartingStartTrim();
final float startingRotation = ring.getStartingRotation();
// Offset the minProgressArc to where the endTrim is
// located.
final float minArc = MAX_PROGRESS_ARC - minProgressArc;
final float endTrim = startingEndTrim + (minArc
* START_CURVE_INTERPOLATOR.getInterpolation(interpolatedTime));
ring.setEndTrim(endTrim);
final float startTrim = startingTrim + (MAX_PROGRESS_ARC
* END_CURVE_INTERPOLATOR.getInterpolation(interpolatedTime));
ring.setStartTrim(startTrim);
final float rotation = startingRotation + (0.25f * interpolatedTime);
ring.setRotation(rotation);
float groupRotation = ((720.0f / NUM_POINTS) * interpolatedTime)
+ (720.0f * (mRotationCount / NUM_POINTS));
setRotation(groupRotation);
}
}
};
animation.setRepeatCount(Animation.INFINITE);
animation.setRepeatMode(Animation.RESTART);
animation.setInterpolator(LINEAR_INTERPOLATOR);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
mRotationCount = 0;
}
@Override
public void onAnimationEnd(Animation animation) {
// do nothing
}
@Override
public void onAnimationRepeat(Animation animation) {
ring.storeOriginals();
ring.goToNextColor();
ring.setStartTrim(ring.getEndTrim());
if (mFinishing) {
// finished closing the last ring from the swipe gesture; go
// into progress mode
mFinishing = false;
animation.setDuration(ANIMATION_DURATION);
ring.setShowArrow(false);
} else {
mRotationCount = (mRotationCount + 1) % (NUM_POINTS);
}
}
});
mAnimation = animation;
}
private final Callback mCallback = new Callback() {
@Override
public void invalidateDrawable(Drawable d) {
invalidateSelf();
}
@Override
public void scheduleDrawable(Drawable d, Runnable what, long when) {
scheduleSelf(what, when);
}
@Override
public void unscheduleDrawable(Drawable d, Runnable what) {
unscheduleSelf(what);
}
};
private static class Ring {
private final RectF mTempBounds = new RectF();
private final Paint mPaint = new Paint();
private final Paint mArrowPaint = new Paint();
private final Callback mCallback;
private float mStartTrim = 0.0f;
private float mEndTrim = 0.0f;
private float mRotation = 0.0f;
private float mStrokeWidth = 5.0f;
private float mStrokeInset = 2.5f;
private int[] mColors;
// mColorIndex represents the offset into the available mColors that the
// progress circle should currently display. As the progress circle is
// animating, the mColorIndex moves by one to the next available color.
private int mColorIndex;
private float mStartingStartTrim;
private float mStartingEndTrim;
private float mStartingRotation;
private boolean mShowArrow;
private Path mArrow;
private float mArrowScale;
private double mRingCenterRadius;
private int mArrowWidth;
private int mArrowHeight;
private int mAlpha;
private final Paint mCirclePaint = new Paint();
private int mBackgroundColor;
public Ring(Callback callback) {
mCallback = callback;
mPaint.setStrokeCap(Paint.Cap.SQUARE);
mPaint.setAntiAlias(true);
mPaint.setStyle(Style.STROKE);
mArrowPaint.setStyle(Style.FILL);
mArrowPaint.setAntiAlias(true);
}
public void setBackgroundColor(int color) {
mBackgroundColor = color;
}
/**
* Set the dimensions of the arrowhead.
*
* @param width Width of the hypotenuse of the arrow head
* @param height Height of the arrow point
*/
public void setArrowDimensions(float width, float height) {
mArrowWidth = (int) width;
mArrowHeight = (int) height;
}
/**
* Draw the progress spinner
*/
public void draw(Canvas c, Rect bounds) {
final RectF arcBounds = mTempBounds;
arcBounds.set(bounds);
arcBounds.inset(mStrokeInset, mStrokeInset);
final float startAngle = (mStartTrim + mRotation) * 360;
final float endAngle = (mEndTrim + mRotation) * 360;
float sweepAngle = endAngle - startAngle;
mPaint.setColor(mColors[mColorIndex]);
c.drawArc(arcBounds, startAngle, sweepAngle, false, mPaint);
drawTriangle(c, startAngle, sweepAngle, bounds);
if (mAlpha < 255) {
mCirclePaint.setColor(mBackgroundColor);
mCirclePaint.setAlpha(255 - mAlpha);
c.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), bounds.width() / 2,
mCirclePaint);
}
}
private void drawTriangle(Canvas c, float startAngle, float sweepAngle, Rect bounds) {
if (mShowArrow) {
if (mArrow == null) {
mArrow = new Path();
mArrow.setFillType(Path.FillType.EVEN_ODD);
} else {
mArrow.reset();
}
// Adjust the position of the triangle so that it is inset as
// much as the arc, but also centered on the arc.
float inset = (int) mStrokeInset / 2 * mArrowScale;
float x = (float) (mRingCenterRadius * Math.cos(0) + bounds.exactCenterX());
float y = (float) (mRingCenterRadius * Math.sin(0) + bounds.exactCenterY());
// Update the path each time. This works around an issue in SKIA
// where concatenating a rotation matrix to a scale matrix
// ignored a starting negative rotation. This appears to have
// been fixed as of API 21.
mArrow.moveTo(0, 0);
mArrow.lineTo(mArrowWidth * mArrowScale, 0);
mArrow.lineTo((mArrowWidth * mArrowScale / 2), (mArrowHeight
* mArrowScale));
mArrow.offset(x - inset, y);
mArrow.close();
// draw a triangle
mArrowPaint.setColor(mColors[mColorIndex]);
c.rotate(startAngle + sweepAngle - ARROW_OFFSET_ANGLE, bounds.exactCenterX(),
bounds.exactCenterY());
c.drawPath(mArrow, mArrowPaint);
}
}
/**
* Set the colors the progress spinner alternates between.
*
* @param colors Array of integers describing the colors. Must be non-<code>null</code>.
*/
public void setColors(@NonNull int[] colors) {
mColors = colors;
// if colors are reset, make sure to reset the color index as well
setColorIndex(0);
}
/**
* @param index Index into the color array of the color to display in
* the progress spinner.
*/
public void setColorIndex(int index) {
mColorIndex = index;
}
/**
* Proceed to the next available ring color. This will automatically
* wrap back to the beginning of colors.
*/
public void goToNextColor() {
mColorIndex = (mColorIndex + 1) % (mColors.length);
}
public void setColorFilter(ColorFilter filter) {
mPaint.setColorFilter(filter);
invalidateSelf();
}
/**
* @param alpha Set the alpha of the progress spinner and associated arrowhead.
*/
public void setAlpha(int alpha) {
mAlpha = alpha;
}
/**
* @return Current alpha of the progress spinner and arrowhead.
*/
public int getAlpha() {
return mAlpha;
}
/**
* @param strokeWidth Set the stroke width of the progress spinner in pixels.
*/
public void setStrokeWidth(float strokeWidth) {
mStrokeWidth = strokeWidth;
mPaint.setStrokeWidth(strokeWidth);
invalidateSelf();
}
@SuppressWarnings("unused")
public float getStrokeWidth() {
return mStrokeWidth;
}
@SuppressWarnings("unused")
public void setStartTrim(float startTrim) {
mStartTrim = startTrim;
invalidateSelf();
}
@SuppressWarnings("unused")
public float getStartTrim() {
return mStartTrim;
}
public float getStartingStartTrim() {
return mStartingStartTrim;
}
public float getStartingEndTrim() {
return mStartingEndTrim;
}
@SuppressWarnings("unused")
public void setEndTrim(float endTrim) {
mEndTrim = endTrim;
invalidateSelf();
}
@SuppressWarnings("unused")
public float getEndTrim() {
return mEndTrim;
}
@SuppressWarnings("unused")
public void setRotation(float rotation) {
mRotation = rotation;
invalidateSelf();
}
@SuppressWarnings("unused")
public float getRotation() {
return mRotation;
}
public void setInsets(int width, int height) {
final float minEdge = (float) Math.min(width, height);
float insets;
if (mRingCenterRadius <= 0 || minEdge < 0) {
insets = (float) Math.ceil(mStrokeWidth / 2.0f);
} else {
insets = (float) (minEdge / 2.0f - mRingCenterRadius);
}
mStrokeInset = insets;
}
@SuppressWarnings("unused")
public float getInsets() {
return mStrokeInset;
}
/**
* @param centerRadius Inner radius in px of the circle the progress
* spinner arc traces.
*/
public void setCenterRadius(double centerRadius) {
mRingCenterRadius = centerRadius;
}
public double getCenterRadius() {
return mRingCenterRadius;
}
/**
* @param show Set to true to show the arrow head on the progress spinner.
*/
public void setShowArrow(boolean show) {
if (mShowArrow != show) {
mShowArrow = show;
invalidateSelf();
}
}
/**
* @param scale Set the scale of the arrowhead for the spinner.
*/
public void setArrowScale(float scale) {
if (scale != mArrowScale) {
mArrowScale = scale;
invalidateSelf();
}
}
/**
* @return The amount the progress spinner is currently rotated, between [0..1].
*/
public float getStartingRotation() {
return mStartingRotation;
}
/**
* If the start / end trim are offset to begin with, store them so that
* animation starts from that offset.
*/
public void storeOriginals() {
mStartingStartTrim = mStartTrim;
mStartingEndTrim = mEndTrim;
mStartingRotation = mRotation;
}
/**
* Reset the progress spinner to default rotation, start and end angles.
*/
public void resetOriginals() {
mStartingStartTrim = 0;
mStartingEndTrim = 0;
mStartingRotation = 0;
setStartTrim(0);
setEndTrim(0);
setRotation(0);
}
private void invalidateSelf() {
mCallback.invalidateDrawable(null);
}
}
/**
* Squishes the interpolation curve into the second half of the animation.
*/
private static class EndCurveInterpolator extends AccelerateDecelerateInterpolator {
@Override
public float getInterpolation(float input) {
return super.getInterpolation(Math.max(0, (input - 0.5f) * 2.0f));
}
}
/**
* Squishes the interpolation curve into the first half of the animation.
*/
private static class StartCurveInterpolator extends AccelerateDecelerateInterpolator {
@Override
public float getInterpolation(float input) {
return super.getInterpolation(Math.min(1, input * 2.0f));
}
}
}
File diff suppressed because it is too large. Load diff
@@ -1,276 +0,0 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget.refreshlayout;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.support.v4.view.ViewCompat;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
/**
* Custom progress bar that shows a cycle of colors as widening circles that
* overdraw each other. When finished, the bar is cleared from the inside out as
* the main cycle continues. Before running, this can also indicate how close
* the user is to triggering something (e.g. how far they need to pull down to
* trigger a refresh).
*/
final class SwipeProgressBar {
// Default progress animation colors are grays.
private final static int COLOR1 = 0xB3000000;
private final static int COLOR2 = 0x80000000;
private final static int COLOR3 = 0x4d000000;
private final static int COLOR4 = 0x1a000000;
// The duration of the animation cycle.
private static final int ANIMATION_DURATION_MS = 2000;
// The duration of the animation to clear the bar.
private static final int FINISH_ANIMATION_DURATION_MS = 1000;
// Interpolator for varying the speed of the animation.
private static final Interpolator INTERPOLATOR = BakedBezierInterpolator.getInstance();
private final Paint mPaint = new Paint();
private final RectF mClipRect = new RectF();
private float mTriggerPercentage;
private long mStartTime;
private long mFinishTime;
private boolean mRunning;
// Colors used when rendering the animation,
private int mColor1;
private int mColor2;
private int mColor3;
private int mColor4;
private View mParent;
private Rect mBounds = new Rect();
public SwipeProgressBar(View parent) {
mParent = parent;
mColor1 = COLOR1;
mColor2 = COLOR2;
mColor3 = COLOR3;
mColor4 = COLOR4;
}
/**
* Set the four colors used in the progress animation. The first color will
* also be the color of the bar that grows in response to a user swipe
* gesture.
*
* @param color1 Integer representation of a color.
* @param color2 Integer representation of a color.
* @param color3 Integer representation of a color.
* @param color4 Integer representation of a color.
*/
void setColorScheme(int color1, int color2, int color3, int color4) {
mColor1 = color1;
mColor2 = color2;
mColor3 = color3;
mColor4 = color4;
}
/**
* Update the progress the user has made toward triggering the swipe
* gesture. and use this value to update the percentage of the trigger that
* is shown.
*/
void setTriggerPercentage(float triggerPercentage) {
mTriggerPercentage = triggerPercentage;
mStartTime = 0;
ViewCompat.postInvalidateOnAnimation(
mParent, mBounds.left, mBounds.top, mBounds.right, mBounds.bottom);
}
/**
* Start showing the progress animation.
*/
void start() {
if (!mRunning) {
mTriggerPercentage = 0;
mStartTime = AnimationUtils.currentAnimationTimeMillis();
mRunning = true;
mParent.postInvalidate();
}
}
/**
* Stop showing the progress animation.
*/
void stop() {
if (mRunning) {
mTriggerPercentage = 0;
mFinishTime = AnimationUtils.currentAnimationTimeMillis();
mRunning = false;
mParent.postInvalidate();
}
}
/**
* @return Return whether the progress animation is currently running.
*/
boolean isRunning() {
return mRunning || mFinishTime > 0;
}
void draw(Canvas canvas) {
final int width = mBounds.width();
final int height = mBounds.height();
final int cx = width / 2;
final int cy = height / 2;
boolean drawTriggerWhileFinishing = false;
int restoreCount = canvas.save();
canvas.clipRect(mBounds);
if (mRunning || (mFinishTime > 0)) {
long now = AnimationUtils.currentAnimationTimeMillis();
long elapsed = (now - mStartTime) % ANIMATION_DURATION_MS;
long iterations = (now - mStartTime) / ANIMATION_DURATION_MS;
float rawProgress = (elapsed / (ANIMATION_DURATION_MS / 100f));
// If we're not running anymore, that means we're running through
// the finish animation.
if (!mRunning) {
// If the finish animation is done, don't draw anything, and
// don't repost.
if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) {
mFinishTime = 0;
return;
}
// Otherwise, use a 0 opacity alpha layer to clear the animation
// from the inside out. This layer will prevent the circles from
// drawing within its bounds.
long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS;
float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f));
float pct = (finishProgress / 100f);
// Radius of the circle is half of the screen.
float clearRadius = width / 2 * INTERPOLATOR.getInterpolation(pct);
mClipRect.set(cx - clearRadius, 0, cx + clearRadius, height);
canvas.saveLayerAlpha(mClipRect, 0, 0);
// Only draw the trigger if there is a space in the center of
// this refreshing view that needs to be filled in by the
// trigger. If the progress view is just still animating, let it
// continue animating.
drawTriggerWhileFinishing = true;
}
// First fill in with the last color that would have finished drawing.
if (iterations == 0) {
canvas.drawColor(mColor1);
} else {
if (rawProgress >= 0 && rawProgress < 25) {
canvas.drawColor(mColor4);
} else if (rawProgress >= 25 && rawProgress < 50) {
canvas.drawColor(mColor1);
} else if (rawProgress >= 50 && rawProgress < 75) {
canvas.drawColor(mColor2);
} else {
canvas.drawColor(mColor3);
}
}
// Then draw up to 4 overlapping concentric circles of varying radii, based on how far
// along we are in the cycle.
// progress 0-50 draw mColor2
// progress 25-75 draw mColor3
// progress 50-100 draw mColor4
// progress 75 (wrap to 25) draw mColor1
if ((rawProgress >= 0 && rawProgress <= 25)) {
float pct = (((rawProgress + 25) * 2) / 100f);
drawCircle(canvas, cx, cy, mColor1, pct);
}
if (rawProgress >= 0 && rawProgress <= 50) {
float pct = ((rawProgress * 2) / 100f);
drawCircle(canvas, cx, cy, mColor2, pct);
}
if (rawProgress >= 25 && rawProgress <= 75) {
float pct = (((rawProgress - 25) * 2) / 100f);
drawCircle(canvas, cx, cy, mColor3, pct);
}
if (rawProgress >= 50 && rawProgress <= 100) {
float pct = (((rawProgress - 50) * 2) / 100f);
drawCircle(canvas, cx, cy, mColor4, pct);
}
if ((rawProgress >= 75 && rawProgress <= 100)) {
float pct = (((rawProgress - 75) * 2) / 100f);
drawCircle(canvas, cx, cy, mColor1, pct);
}
if (mTriggerPercentage > 0 && drawTriggerWhileFinishing) {
// There is some portion of trigger to draw. Restore the canvas,
// then draw the trigger. Otherwise, the trigger does not appear
// until after the bar has finished animating and appears to
// just jump in at a larger width than expected.
canvas.restoreToCount(restoreCount);
restoreCount = canvas.save();
canvas.clipRect(mBounds);
drawTrigger(canvas, cx, cy);
}
// Keep running until we finish out the last cycle.
ViewCompat.postInvalidateOnAnimation(
mParent, mBounds.left, mBounds.top, mBounds.right, mBounds.bottom);
} else {
// Otherwise if we're in the middle of a trigger, draw that.
if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) {
drawTrigger(canvas, cx, cy);
}
}
canvas.restoreToCount(restoreCount);
}
private void drawTrigger(Canvas canvas, int cx, int cy) {
mPaint.setColor(mColor1);
canvas.drawCircle(cx, cy, cx * mTriggerPercentage, mPaint);
}
/**
* Draws a circle centered in the view.
*
* @param canvas the canvas to draw on
* @param cx the center x coordinate
* @param cy the center y coordinate
* @param color the color to draw
* @param pct the percentage of the view that the circle should cover
*/
private void drawCircle(Canvas canvas, float cx, float cy, int color, float pct) {
mPaint.setColor(color);
canvas.save();
// Go to bottom
canvas.translate(cx, mParent.getHeight() - cy);
float radiusScale = INTERPOLATOR.getInterpolation(pct);
canvas.scale(radiusScale, radiusScale);
canvas.drawCircle(0, 0, cx, mPaint);
canvas.restore();
}
/**
* Set the drawing bounds of this SwipeProgressBar.
*/
void setBounds(int left, int top, int right, int bottom) {
mBounds.left = left;
mBounds.top = top;
mBounds.right = right;
mBounds.bottom = bottom;
}
}
-3
View File
@@ -1,3 +0,0 @@
APP_ABI := armeabi armeabi-v7a x86
APP_PLATFORM := android-9
APP_OPTIM := release
-72
View File
@@ -1,72 +0,0 @@
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
/* Define to 1 if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the <stdarg.h> header file. */
#define HAVE_STDARG_H 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#define LT_OBJDIR ".libs/"
/* Name of package */
#define PACKAGE "giflib"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "esr@thyrsus.com"
/* Define to the full name of this package. */
#define PACKAGE_NAME "giflib"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "giflib 5.1.1"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "giflib"
/* Define to the home page for this package. */
#define PACKAGE_URL ""
/* Define to the version of this package. */
#define PACKAGE_VERSION "5.1.1"
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Version number of package */
#define VERSION "5.1.1"
-10
View File
@@ -1,10 +0,0 @@
# simd/jsimdext.inc
%define EXTN(name) _ %+ name<br>
to<br>
%define EXTN(name) name<br>
or ld error for x86 and x86_64
# Add cmyk to rgb, cmyk to gray
In jdcolor.c, jdcolext.c
-145
View File
@@ -1,145 +0,0 @@
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
/* use 8 or 12 */
/* #undef BITS_IN_JSAMPLE */
/* libjpeg-turbo build number */
#define BUILD "20150109"
/* Support arithmetic encoding */
#define C_ARITH_CODING_SUPPORTED 1
/* Support arithmetic decoding */
#define D_ARITH_CODING_SUPPORTED 1
/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the <jni.h> header file. */
/* #undef HAVE_JNI_H */
/* Define to 1 if you have the <locale.h> header file. */
#define HAVE_LOCALE_H 1
/* Define to 1 if you have the `memcpy' function. */
#define HAVE_MEMCPY 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the `memset' function. */
#define HAVE_MEMSET 1
/* Define to 1 if you have the <stddef.h> header file. */
#define HAVE_STDDEF_H 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to 1 if the system has the type `unsigned char'. */
#define HAVE_UNSIGNED_CHAR 1
/* Define to 1 if the system has the type `unsigned short'. */
#define HAVE_UNSIGNED_SHORT 1
/* Compiler does not support pointers to undefined structures. */
/* #undef INCOMPLETE_TYPES_BROKEN */
/* How to obtain function inlining. */
#define INLINE inline __attribute__((always_inline))
/* libjpeg API version */
#define JPEG_LIB_VERSION 62
/* libjpeg-turbo version */
#define LIBJPEG_TURBO_VERSION 1.4.0
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#define LT_OBJDIR ".libs/"
/* Support in-memory source/destination managers */
#define MEM_SRCDST_SUPPORTED 1
/* Define if you have BSD-like bzero and bcopy in <strings.h> rather than
memset/memcpy in <string.h>. */
/* #undef NEED_BSD_STRINGS */
/* Define if you need to include <sys/types.h> to get size_t. */
#define NEED_SYS_TYPES_H 1
/* Name of package */
#define PACKAGE "libjpeg-turbo"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""
/* Define to the full name of this package. */
#define PACKAGE_NAME "libjpeg-turbo"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "libjpeg-turbo 1.4.0"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "libjpeg-turbo"
/* Define to the home page for this package. */
#define PACKAGE_URL ""
/* Define to the version of this package. */
#define PACKAGE_VERSION "1.4.0"
/* Define if your (broken) compiler shifts signed values as if they were
unsigned. */
/* #undef RIGHT_SHIFT_IS_UNSIGNED */
/* The size of `long', as computed by sizeof. */
#define SIZEOF_LONG 8
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Version number of package */
#define VERSION "1.4.0"
/* Use accelerated SIMD routines. */
#define WITH_SIMD 1
/* Define to 1 if type `char' is unsigned and you are not using gcc. */
#ifndef __CHAR_UNSIGNED__
/* # undef __CHAR_UNSIGNED__ */
#endif
/* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
/* #undef inline */
#endif
/* Define to `unsigned int' if <sys/types.h> does not define. */
/* #undef size_t */
-389
View File
@@ -1,389 +0,0 @@
/*
* jsimd_none.c
*
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright 2009-2011, 2014 D. R. Commander
*
* Based on the x86 SIMD extension for IJG JPEG library,
* Copyright (C) 1999-2006, MIYASAKA Masaru.
* For conditions of distribution and use, see copyright notice in jsimdext.inc
*
* This file contains stubs for when there is no SIMD support available.
*/
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglib.h"
#include "jsimd.h"
#include "jdct.h"
#include "jsimddct.h"
GLOBAL(int)
jsimd_can_rgb_ycc (void)
{
return 0;
}
GLOBAL(int)
jsimd_can_rgb_gray (void)
{
return 0;
}
GLOBAL(int)
jsimd_can_ycc_rgb (void)
{
return 0;
}
GLOBAL(int)
jsimd_can_ycc_rgb565 (void)
{
return 0;
}
GLOBAL(int)
jsimd_c_can_null_convert (void)
{
return 0;
}
GLOBAL(void)
jsimd_rgb_ycc_convert (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows)
{
}
GLOBAL(void)
jsimd_rgb_gray_convert (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows)
{
}
GLOBAL(void)
jsimd_ycc_rgb_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows)
{
}
GLOBAL(void)
jsimd_ycc_rgb565_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows)
{
}
GLOBAL(void)
jsimd_c_null_convert (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows)
{
}
GLOBAL(int)
jsimd_can_h2v2_downsample (void)
{
return 0;
}
GLOBAL(int)
jsimd_can_h2v1_downsample (void)
{
return 0;
}
GLOBAL(int)
jsimd_can_h2v2_smooth_downsample (void)
{
return 0;
}
GLOBAL(void)
jsimd_h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data)
{
}
GLOBAL(void)
jsimd_h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data)
{
}
GLOBAL(void)
jsimd_h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data)
{
}
GLOBAL(int)
jsimd_can_h2v2_upsample (void)
{
return 0;
}
GLOBAL(int)
jsimd_can_h2v1_upsample (void)
{
return 0;
}
GLOBAL(int)
jsimd_can_int_upsample (void)
{
return 0;
}
GLOBAL(void)
jsimd_int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
{
}
GLOBAL(void)
jsimd_h2v2_upsample (j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JSAMPARRAY input_data,
JSAMPARRAY * output_data_ptr)
{
}
GLOBAL(void)
jsimd_h2v1_upsample (j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JSAMPARRAY input_data,
JSAMPARRAY * output_data_ptr)
{
}
GLOBAL(int)
jsimd_can_h2v2_fancy_upsample (void)
{
return 0;
}
GLOBAL(int)
jsimd_can_h2v1_fancy_upsample (void)
{
return 0;
}
GLOBAL(void)
jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JSAMPARRAY input_data,
JSAMPARRAY * output_data_ptr)
{
}
GLOBAL(void)
jsimd_h2v1_fancy_upsample (j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JSAMPARRAY input_data,
JSAMPARRAY * output_data_ptr)
{
}
GLOBAL(int)
jsimd_can_h2v2_merged_upsample (void)
{
return 0;
}
GLOBAL(int)
jsimd_can_h2v1_merged_upsample (void)
{
return 0;
}
GLOBAL(void)
jsimd_h2v2_merged_upsample (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf)
{
}
GLOBAL(void)
jsimd_h2v1_merged_upsample (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf)
{
}
GLOBAL(int)
jsimd_can_convsamp (void)
{
return 0;
}
GLOBAL(int)
jsimd_can_convsamp_float (void)
{
return 0;
}
GLOBAL(void)
jsimd_convsamp (JSAMPARRAY sample_data, JDIMENSION start_col,
DCTELEM * workspace)
{
}
GLOBAL(void)
jsimd_convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col,
FAST_FLOAT * workspace)
{
}
GLOBAL(int)
jsimd_can_fdct_islow (void)
{
return 0;
}
GLOBAL(int)
jsimd_can_fdct_ifast (void)
{
return 0;
}
GLOBAL(int)
jsimd_can_fdct_float (void)
{
return 0;
}
GLOBAL(void)
jsimd_fdct_islow (DCTELEM * data)
{
}
GLOBAL(void)
jsimd_fdct_ifast (DCTELEM * data)
{
}
GLOBAL(void)
jsimd_fdct_float (FAST_FLOAT * data)
{
}
GLOBAL(int)
jsimd_can_quantize (void)
{
return 0;
}
GLOBAL(int)
jsimd_can_quantize_float (void)
{
return 0;
}
GLOBAL(void)
jsimd_quantize (JCOEFPTR coef_block, DCTELEM * divisors,
DCTELEM * workspace)
{
}
GLOBAL(void)
jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors,
FAST_FLOAT * workspace)
{
}
GLOBAL(int)
jsimd_can_idct_2x2 (void)
{
return 0;
}
GLOBAL(int)
jsimd_can_idct_4x4 (void)
{
return 0;
}
GLOBAL(int)
jsimd_can_idct_6x6 (void)
{
return 0;
}
GLOBAL(int)
jsimd_can_idct_12x12 (void)
{
return 0;
}
GLOBAL(void)
jsimd_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
}
GLOBAL(void)
jsimd_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
}
GLOBAL(void)
jsimd_idct_6x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
}
GLOBAL(void)
jsimd_idct_12x12 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
}
GLOBAL(int)
jsimd_can_idct_islow (void)
{
return 0;
}
GLOBAL(int)
jsimd_can_idct_ifast (void)
{
return 0;
}
GLOBAL(int)
jsimd_can_idct_float (void)
{
return 0;
}
GLOBAL(void)
jsimd_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
}
GLOBAL(void)
jsimd_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
}
GLOBAL(void)
jsimd_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
}
@@ -1,485 +0,0 @@
;
; jccolext.asm - colorspace conversion (64-bit SSE2)
;
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; Copyright (C) 2009, D. R. Commander.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; [TAB8]
%include "jcolsamp.inc"
; --------------------------------------------------------------------------
;
; Convert some rows of samples to the output colorspace.
;
; GLOBAL(void)
; jsimd_rgb_ycc_convert_sse2 (JDIMENSION img_width,
; JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
; JDIMENSION output_row, int num_rows);
;
; r10 = JDIMENSION img_width
; r11 = JSAMPARRAY input_buf
; r12 = JSAMPIMAGE output_buf
; r13 = JDIMENSION output_row
; r14 = int num_rows
%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 8
align 16
global EXTN(jsimd_rgb_ycc_convert_sse2)
EXTN(jsimd_rgb_ycc_convert_sse2):
push rbp
mov rax,rsp ; rax = original rbp
sub rsp, byte 4
and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [rsp],rax
mov rbp,rsp ; rbp = aligned rbp
lea rsp, [wk(0)]
collect_args
push rbx
mov rcx, r10
test rcx,rcx
jz near .return
push rcx
mov rsi, r12
mov rcx, r13
mov rdi, JSAMPARRAY [rsi+0*SIZEOF_JSAMPARRAY]
mov rbx, JSAMPARRAY [rsi+1*SIZEOF_JSAMPARRAY]
mov rdx, JSAMPARRAY [rsi+2*SIZEOF_JSAMPARRAY]
lea rdi, [rdi+rcx*SIZEOF_JSAMPROW]
lea rbx, [rbx+rcx*SIZEOF_JSAMPROW]
lea rdx, [rdx+rcx*SIZEOF_JSAMPROW]
pop rcx
mov rsi, r11
mov eax, r14d
test rax,rax
jle near .return
.rowloop:
push rdx
push rbx
push rdi
push rsi
push rcx ; col
mov rsi, JSAMPROW [rsi] ; inptr
mov rdi, JSAMPROW [rdi] ; outptr0
mov rbx, JSAMPROW [rbx] ; outptr1
mov rdx, JSAMPROW [rdx] ; outptr2
cmp rcx, byte SIZEOF_XMMWORD
jae near .columnloop
%if RGB_PIXELSIZE == 3 ; ---------------
.column_ld1:
push rax
push rdx
lea rcx,[rcx+rcx*2] ; imul ecx,RGB_PIXELSIZE
test cl, SIZEOF_BYTE
jz short .column_ld2
sub rcx, byte SIZEOF_BYTE
movzx rax, BYTE [rsi+rcx]
.column_ld2:
test cl, SIZEOF_WORD
jz short .column_ld4
sub rcx, byte SIZEOF_WORD
movzx rdx, WORD [rsi+rcx]
shl rax, WORD_BIT
or rax,rdx
.column_ld4:
movd xmmA,eax
pop rdx
pop rax
test cl, SIZEOF_DWORD
jz short .column_ld8
sub rcx, byte SIZEOF_DWORD
movd xmmF, XMM_DWORD [rsi+rcx]
pslldq xmmA, SIZEOF_DWORD
por xmmA,xmmF
.column_ld8:
test cl, SIZEOF_MMWORD
jz short .column_ld16
sub rcx, byte SIZEOF_MMWORD
movq xmmB, XMM_MMWORD [rsi+rcx]
pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmB
.column_ld16:
test cl, SIZEOF_XMMWORD
jz short .column_ld32
movdqa xmmF,xmmA
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
mov rcx, SIZEOF_XMMWORD
jmp short .rgb_ycc_cnv
.column_ld32:
test cl, 2*SIZEOF_XMMWORD
mov rcx, SIZEOF_XMMWORD
jz short .rgb_ycc_cnv
movdqa xmmB,xmmA
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
jmp short .rgb_ycc_cnv
.columnloop:
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
movdqu xmmB, XMMWORD [rsi+2*SIZEOF_XMMWORD]
.rgb_ycc_cnv:
; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
movdqa xmmG,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12)
psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A)
pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27)
punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D)
punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F)
movdqa xmmD,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09)
psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D)
pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B)
punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E)
punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F)
movdqa xmmE,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C)
psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D)
punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F)
pxor xmmH,xmmH
movdqa xmmC,xmmA
punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmB,xmmE
punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F)
movdqa xmmF,xmmD
punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F)
punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F)
%else ; RGB_PIXELSIZE == 4 ; -----------
.column_ld1:
test cl, SIZEOF_XMMWORD/16
jz short .column_ld2
sub rcx, byte SIZEOF_XMMWORD/16
movd xmmA, XMM_DWORD [rsi+rcx*RGB_PIXELSIZE]
.column_ld2:
test cl, SIZEOF_XMMWORD/8
jz short .column_ld4
sub rcx, byte SIZEOF_XMMWORD/8
movq xmmE, XMM_MMWORD [rsi+rcx*RGB_PIXELSIZE]
pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmE
.column_ld4:
test cl, SIZEOF_XMMWORD/4
jz short .column_ld8
sub rcx, byte SIZEOF_XMMWORD/4
movdqa xmmE,xmmA
movdqu xmmA, XMMWORD [rsi+rcx*RGB_PIXELSIZE]
.column_ld8:
test cl, SIZEOF_XMMWORD/2
mov rcx, SIZEOF_XMMWORD
jz short .rgb_ycc_cnv
movdqa xmmF,xmmA
movdqa xmmH,xmmE
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
jmp short .rgb_ycc_cnv
.columnloop:
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+2*SIZEOF_XMMWORD]
movdqu xmmH, XMMWORD [rsi+3*SIZEOF_XMMWORD]
.rgb_ycc_cnv:
; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
movdqa xmmD,xmmA
punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35)
punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37)
movdqa xmmC,xmmF
punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D)
punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F)
movdqa xmmB,xmmA
punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C)
punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D)
movdqa xmmG,xmmD
punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E)
punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F)
movdqa xmmE,xmmA
punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E)
movdqa xmmH,xmmB
punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F)
punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F)
pxor xmmF,xmmF
movdqa xmmC,xmmA
punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmD,xmmB
punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F)
movdqa xmmG,xmmE
punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E)
punpcklbw xmmF,xmmH
punpckhbw xmmH,xmmH
psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F)
psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F)
%endif ; RGB_PIXELSIZE ; ---------------
; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE
; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO
; (Original)
; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
;
; (This implementation)
; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=RE
movdqa XMMWORD [wk(1)], xmm1 ; wk(1)=RO
movdqa XMMWORD [wk(2)], xmm4 ; wk(2)=BE
movdqa XMMWORD [wk(3)], xmm5 ; wk(3)=BO
movdqa xmm6,xmm1
punpcklwd xmm1,xmm3
punpckhwd xmm6,xmm3
movdqa xmm7,xmm1
movdqa xmm4,xmm6
pmaddwd xmm1,[rel PW_F0299_F0337] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337)
pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337)
pmaddwd xmm7,[rel PW_MF016_MF033] ; xmm7=ROL*-FIX(0.168)+GOL*-FIX(0.331)
pmaddwd xmm4,[rel PW_MF016_MF033] ; xmm4=ROH*-FIX(0.168)+GOH*-FIX(0.331)
movdqa XMMWORD [wk(4)], xmm1 ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337)
movdqa XMMWORD [wk(5)], xmm6 ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337)
pxor xmm1,xmm1
pxor xmm6,xmm6
punpcklwd xmm1,xmm5 ; xmm1=BOL
punpckhwd xmm6,xmm5 ; xmm6=BOH
psrld xmm1,1 ; xmm1=BOL*FIX(0.500)
psrld xmm6,1 ; xmm6=BOH*FIX(0.500)
movdqa xmm5,[rel PD_ONEHALFM1_CJ] ; xmm5=[PD_ONEHALFM1_CJ]
paddd xmm7,xmm1
paddd xmm4,xmm6
paddd xmm7,xmm5
paddd xmm4,xmm5
psrld xmm7,SCALEBITS ; xmm7=CbOL
psrld xmm4,SCALEBITS ; xmm4=CbOH
packssdw xmm7,xmm4 ; xmm7=CbO
movdqa xmm1, XMMWORD [wk(2)] ; xmm1=BE
movdqa xmm6,xmm0
punpcklwd xmm0,xmm2
punpckhwd xmm6,xmm2
movdqa xmm5,xmm0
movdqa xmm4,xmm6
pmaddwd xmm0,[rel PW_F0299_F0337] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337)
pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337)
pmaddwd xmm5,[rel PW_MF016_MF033] ; xmm5=REL*-FIX(0.168)+GEL*-FIX(0.331)
pmaddwd xmm4,[rel PW_MF016_MF033] ; xmm4=REH*-FIX(0.168)+GEH*-FIX(0.331)
movdqa XMMWORD [wk(6)], xmm0 ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337)
movdqa XMMWORD [wk(7)], xmm6 ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337)
pxor xmm0,xmm0
pxor xmm6,xmm6
punpcklwd xmm0,xmm1 ; xmm0=BEL
punpckhwd xmm6,xmm1 ; xmm6=BEH
psrld xmm0,1 ; xmm0=BEL*FIX(0.500)
psrld xmm6,1 ; xmm6=BEH*FIX(0.500)
movdqa xmm1,[rel PD_ONEHALFM1_CJ] ; xmm1=[PD_ONEHALFM1_CJ]
paddd xmm5,xmm0
paddd xmm4,xmm6
paddd xmm5,xmm1
paddd xmm4,xmm1
psrld xmm5,SCALEBITS ; xmm5=CbEL
psrld xmm4,SCALEBITS ; xmm4=CbEH
packssdw xmm5,xmm4 ; xmm5=CbE
psllw xmm7,BYTE_BIT
por xmm5,xmm7 ; xmm5=Cb
movdqa XMMWORD [rbx], xmm5 ; Save Cb
movdqa xmm0, XMMWORD [wk(3)] ; xmm0=BO
movdqa xmm6, XMMWORD [wk(2)] ; xmm6=BE
movdqa xmm1, XMMWORD [wk(1)] ; xmm1=RO
movdqa xmm4,xmm0
punpcklwd xmm0,xmm3
punpckhwd xmm4,xmm3
movdqa xmm7,xmm0
movdqa xmm5,xmm4
pmaddwd xmm0,[rel PW_F0114_F0250] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250)
pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250)
pmaddwd xmm7,[rel PW_MF008_MF041] ; xmm7=BOL*-FIX(0.081)+GOL*-FIX(0.418)
pmaddwd xmm5,[rel PW_MF008_MF041] ; xmm5=BOH*-FIX(0.081)+GOH*-FIX(0.418)
movdqa xmm3,[rel PD_ONEHALF] ; xmm3=[PD_ONEHALF]
paddd xmm0, XMMWORD [wk(4)]
paddd xmm4, XMMWORD [wk(5)]
paddd xmm0,xmm3
paddd xmm4,xmm3
psrld xmm0,SCALEBITS ; xmm0=YOL
psrld xmm4,SCALEBITS ; xmm4=YOH
packssdw xmm0,xmm4 ; xmm0=YO
pxor xmm3,xmm3
pxor xmm4,xmm4
punpcklwd xmm3,xmm1 ; xmm3=ROL
punpckhwd xmm4,xmm1 ; xmm4=ROH
psrld xmm3,1 ; xmm3=ROL*FIX(0.500)
psrld xmm4,1 ; xmm4=ROH*FIX(0.500)
movdqa xmm1,[rel PD_ONEHALFM1_CJ] ; xmm1=[PD_ONEHALFM1_CJ]
paddd xmm7,xmm3
paddd xmm5,xmm4
paddd xmm7,xmm1
paddd xmm5,xmm1
psrld xmm7,SCALEBITS ; xmm7=CrOL
psrld xmm5,SCALEBITS ; xmm5=CrOH
packssdw xmm7,xmm5 ; xmm7=CrO
movdqa xmm3, XMMWORD [wk(0)] ; xmm3=RE
movdqa xmm4,xmm6
punpcklwd xmm6,xmm2
punpckhwd xmm4,xmm2
movdqa xmm1,xmm6
movdqa xmm5,xmm4
pmaddwd xmm6,[rel PW_F0114_F0250] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250)
pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250)
pmaddwd xmm1,[rel PW_MF008_MF041] ; xmm1=BEL*-FIX(0.081)+GEL*-FIX(0.418)
pmaddwd xmm5,[rel PW_MF008_MF041] ; xmm5=BEH*-FIX(0.081)+GEH*-FIX(0.418)
movdqa xmm2,[rel PD_ONEHALF] ; xmm2=[PD_ONEHALF]
paddd xmm6, XMMWORD [wk(6)]
paddd xmm4, XMMWORD [wk(7)]
paddd xmm6,xmm2
paddd xmm4,xmm2
psrld xmm6,SCALEBITS ; xmm6=YEL
psrld xmm4,SCALEBITS ; xmm4=YEH
packssdw xmm6,xmm4 ; xmm6=YE
psllw xmm0,BYTE_BIT
por xmm6,xmm0 ; xmm6=Y
movdqa XMMWORD [rdi], xmm6 ; Save Y
pxor xmm2,xmm2
pxor xmm4,xmm4
punpcklwd xmm2,xmm3 ; xmm2=REL
punpckhwd xmm4,xmm3 ; xmm4=REH
psrld xmm2,1 ; xmm2=REL*FIX(0.500)
psrld xmm4,1 ; xmm4=REH*FIX(0.500)
movdqa xmm0,[rel PD_ONEHALFM1_CJ] ; xmm0=[PD_ONEHALFM1_CJ]
paddd xmm1,xmm2
paddd xmm5,xmm4
paddd xmm1,xmm0
paddd xmm5,xmm0
psrld xmm1,SCALEBITS ; xmm1=CrEL
psrld xmm5,SCALEBITS ; xmm5=CrEH
packssdw xmm1,xmm5 ; xmm1=CrE
psllw xmm7,BYTE_BIT
por xmm1,xmm7 ; xmm1=Cr
movdqa XMMWORD [rdx], xmm1 ; Save Cr
sub rcx, byte SIZEOF_XMMWORD
add rsi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr
add rdi, byte SIZEOF_XMMWORD ; outptr0
add rbx, byte SIZEOF_XMMWORD ; outptr1
add rdx, byte SIZEOF_XMMWORD ; outptr2
cmp rcx, byte SIZEOF_XMMWORD
jae near .columnloop
test rcx,rcx
jnz near .column_ld1
pop rcx ; col
pop rsi
pop rdi
pop rbx
pop rdx
add rsi, byte SIZEOF_JSAMPROW ; input_buf
add rdi, byte SIZEOF_JSAMPROW
add rbx, byte SIZEOF_JSAMPROW
add rdx, byte SIZEOF_JSAMPROW
dec rax ; num_rows
jg near .rowloop
.return:
pop rbx
uncollect_args
mov rsp,rbp ; rsp <- aligned rbp
pop rsp ; rsp <- original rbp
pop rbp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16
@@ -1,120 +0,0 @@
;
; jccolor.asm - colorspace conversion (64-bit SSE2)
;
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; Copyright (C) 2009, D. R. Commander.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; [TAB8]
%include "jsimdext.inc"
; --------------------------------------------------------------------------
%define SCALEBITS 16
F_0_081 equ 5329 ; FIX(0.08131)
F_0_114 equ 7471 ; FIX(0.11400)
F_0_168 equ 11059 ; FIX(0.16874)
F_0_250 equ 16384 ; FIX(0.25000)
F_0_299 equ 19595 ; FIX(0.29900)
F_0_331 equ 21709 ; FIX(0.33126)
F_0_418 equ 27439 ; FIX(0.41869)
F_0_587 equ 38470 ; FIX(0.58700)
F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000)
; --------------------------------------------------------------------------
SECTION SEG_CONST
alignz 16
global EXTN(jconst_rgb_ycc_convert_sse2)
EXTN(jconst_rgb_ycc_convert_sse2):
PW_F0299_F0337 times 4 dw F_0_299, F_0_337
PW_F0114_F0250 times 4 dw F_0_114, F_0_250
PW_MF016_MF033 times 4 dw -F_0_168,-F_0_331
PW_MF008_MF041 times 4 dw -F_0_081,-F_0_418
PD_ONEHALFM1_CJ times 4 dd (1 << (SCALEBITS-1)) - 1 + (CENTERJSAMPLE << SCALEBITS)
PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
alignz 16
; --------------------------------------------------------------------------
SECTION SEG_TEXT
BITS 64
%include "jccolext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_RGB_RED
%define RGB_GREEN EXT_RGB_GREEN
%define RGB_BLUE EXT_RGB_BLUE
%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extrgb_ycc_convert_sse2
%include "jccolext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_RGBX_RED
%define RGB_GREEN EXT_RGBX_GREEN
%define RGB_BLUE EXT_RGBX_BLUE
%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extrgbx_ycc_convert_sse2
%include "jccolext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_BGR_RED
%define RGB_GREEN EXT_BGR_GREEN
%define RGB_BLUE EXT_BGR_BLUE
%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extbgr_ycc_convert_sse2
%include "jccolext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_BGRX_RED
%define RGB_GREEN EXT_BGRX_GREEN
%define RGB_BLUE EXT_BGRX_BLUE
%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extbgrx_ycc_convert_sse2
%include "jccolext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_XBGR_RED
%define RGB_GREEN EXT_XBGR_GREEN
%define RGB_BLUE EXT_XBGR_BLUE
%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extxbgr_ycc_convert_sse2
%include "jccolext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_XRGB_RED
%define RGB_GREEN EXT_XRGB_GREEN
%define RGB_BLUE EXT_XRGB_BLUE
%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extxrgb_ycc_convert_sse2
%include "jccolext-sse2-64.asm"
@@ -1,113 +0,0 @@
;
; jcgray.asm - grayscale colorspace conversion (64-bit SSE2)
;
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; Copyright (C) 2011, D. R. Commander.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; [TAB8]
%include "jsimdext.inc"
; --------------------------------------------------------------------------
%define SCALEBITS 16
F_0_114 equ 7471 ; FIX(0.11400)
F_0_250 equ 16384 ; FIX(0.25000)
F_0_299 equ 19595 ; FIX(0.29900)
F_0_587 equ 38470 ; FIX(0.58700)
F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000)
; --------------------------------------------------------------------------
SECTION SEG_CONST
alignz 16
global EXTN(jconst_rgb_gray_convert_sse2)
EXTN(jconst_rgb_gray_convert_sse2):
PW_F0299_F0337 times 4 dw F_0_299, F_0_337
PW_F0114_F0250 times 4 dw F_0_114, F_0_250
PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
alignz 16
; --------------------------------------------------------------------------
SECTION SEG_TEXT
BITS 64
%include "jcgryext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_RGB_RED
%define RGB_GREEN EXT_RGB_GREEN
%define RGB_BLUE EXT_RGB_BLUE
%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE
%define jsimd_rgb_gray_convert_sse2 jsimd_extrgb_gray_convert_sse2
%include "jcgryext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_RGBX_RED
%define RGB_GREEN EXT_RGBX_GREEN
%define RGB_BLUE EXT_RGBX_BLUE
%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE
%define jsimd_rgb_gray_convert_sse2 jsimd_extrgbx_gray_convert_sse2
%include "jcgryext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_BGR_RED
%define RGB_GREEN EXT_BGR_GREEN
%define RGB_BLUE EXT_BGR_BLUE
%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE
%define jsimd_rgb_gray_convert_sse2 jsimd_extbgr_gray_convert_sse2
%include "jcgryext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_BGRX_RED
%define RGB_GREEN EXT_BGRX_GREEN
%define RGB_BLUE EXT_BGRX_BLUE
%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE
%define jsimd_rgb_gray_convert_sse2 jsimd_extbgrx_gray_convert_sse2
%include "jcgryext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_XBGR_RED
%define RGB_GREEN EXT_XBGR_GREEN
%define RGB_BLUE EXT_XBGR_BLUE
%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE
%define jsimd_rgb_gray_convert_sse2 jsimd_extxbgr_gray_convert_sse2
%include "jcgryext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_XRGB_RED
%define RGB_GREEN EXT_XRGB_GREEN
%define RGB_BLUE EXT_XRGB_BLUE
%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE
%define jsimd_rgb_gray_convert_sse2 jsimd_extxrgb_gray_convert_sse2
%include "jcgryext-sse2-64.asm"
@@ -1,364 +0,0 @@
;
; jcgryext.asm - grayscale colorspace conversion (64-bit SSE2)
;
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; Copyright (C) 2011, D. R. Commander.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; [TAB8]
%include "jcolsamp.inc"
; --------------------------------------------------------------------------
;
; Convert some rows of samples to the output colorspace.
;
; GLOBAL(void)
; jsimd_rgb_gray_convert_sse2 (JDIMENSION img_width,
; JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
; JDIMENSION output_row, int num_rows);
;
; r10 = JDIMENSION img_width
; r11 = JSAMPARRAY input_buf
; r12 = JSAMPIMAGE output_buf
; r13 = JDIMENSION output_row
; r14 = int num_rows
%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 2
align 16
global EXTN(jsimd_rgb_gray_convert_sse2)
EXTN(jsimd_rgb_gray_convert_sse2):
push rbp
mov rax,rsp ; rax = original rbp
sub rsp, byte 4
and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [rsp],rax
mov rbp,rsp ; rbp = aligned rbp
lea rsp, [wk(0)]
collect_args
push rbx
mov rcx, r10
test rcx,rcx
jz near .return
push rcx
mov rsi, r12
mov rcx, r13
mov rdi, JSAMPARRAY [rsi+0*SIZEOF_JSAMPARRAY]
lea rdi, [rdi+rcx*SIZEOF_JSAMPROW]
pop rcx
mov rsi, r11
mov eax, r14d
test rax,rax
jle near .return
.rowloop:
push rdi
push rsi
push rcx ; col
mov rsi, JSAMPROW [rsi] ; inptr
mov rdi, JSAMPROW [rdi] ; outptr0
cmp rcx, byte SIZEOF_XMMWORD
jae near .columnloop
%if RGB_PIXELSIZE == 3 ; ---------------
.column_ld1:
push rax
push rdx
lea rcx,[rcx+rcx*2] ; imul ecx,RGB_PIXELSIZE
test cl, SIZEOF_BYTE
jz short .column_ld2
sub rcx, byte SIZEOF_BYTE
movzx rax, BYTE [rsi+rcx]
.column_ld2:
test cl, SIZEOF_WORD
jz short .column_ld4
sub rcx, byte SIZEOF_WORD
movzx rdx, WORD [rsi+rcx]
shl rax, WORD_BIT
or rax,rdx
.column_ld4:
movd xmmA,eax
pop rdx
pop rax
test cl, SIZEOF_DWORD
jz short .column_ld8
sub rcx, byte SIZEOF_DWORD
movd xmmF, XMM_DWORD [rsi+rcx]
pslldq xmmA, SIZEOF_DWORD
por xmmA,xmmF
.column_ld8:
test cl, SIZEOF_MMWORD
jz short .column_ld16
sub rcx, byte SIZEOF_MMWORD
movq xmmB, XMM_MMWORD [rsi+rcx]
pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmB
.column_ld16:
test cl, SIZEOF_XMMWORD
jz short .column_ld32
movdqa xmmF,xmmA
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
mov rcx, SIZEOF_XMMWORD
jmp short .rgb_gray_cnv
.column_ld32:
test cl, 2*SIZEOF_XMMWORD
mov rcx, SIZEOF_XMMWORD
jz short .rgb_gray_cnv
movdqa xmmB,xmmA
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
jmp short .rgb_gray_cnv
.columnloop:
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
movdqu xmmB, XMMWORD [rsi+2*SIZEOF_XMMWORD]
.rgb_gray_cnv:
; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
movdqa xmmG,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12)
psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A)
pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27)
punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D)
punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F)
movdqa xmmD,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09)
psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D)
pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B)
punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E)
punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F)
movdqa xmmE,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C)
psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D)
punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F)
pxor xmmH,xmmH
movdqa xmmC,xmmA
punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmB,xmmE
punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F)
movdqa xmmF,xmmD
punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F)
punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F)
%else ; RGB_PIXELSIZE == 4 ; -----------
.column_ld1:
test cl, SIZEOF_XMMWORD/16
jz short .column_ld2
sub rcx, byte SIZEOF_XMMWORD/16
movd xmmA, XMM_DWORD [rsi+rcx*RGB_PIXELSIZE]
.column_ld2:
test cl, SIZEOF_XMMWORD/8
jz short .column_ld4
sub rcx, byte SIZEOF_XMMWORD/8
movq xmmE, XMM_MMWORD [rsi+rcx*RGB_PIXELSIZE]
pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmE
.column_ld4:
test cl, SIZEOF_XMMWORD/4
jz short .column_ld8
sub rcx, byte SIZEOF_XMMWORD/4
movdqa xmmE,xmmA
movdqu xmmA, XMMWORD [rsi+rcx*RGB_PIXELSIZE]
.column_ld8:
test cl, SIZEOF_XMMWORD/2
mov rcx, SIZEOF_XMMWORD
jz short .rgb_gray_cnv
movdqa xmmF,xmmA
movdqa xmmH,xmmE
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
jmp short .rgb_gray_cnv
.columnloop:
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+2*SIZEOF_XMMWORD]
movdqu xmmH, XMMWORD [rsi+3*SIZEOF_XMMWORD]
.rgb_gray_cnv:
; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
movdqa xmmD,xmmA
punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35)
punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37)
movdqa xmmC,xmmF
punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D)
punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F)
movdqa xmmB,xmmA
punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C)
punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D)
movdqa xmmG,xmmD
punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E)
punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F)
movdqa xmmE,xmmA
punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E)
movdqa xmmH,xmmB
punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F)
punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F)
pxor xmmF,xmmF
movdqa xmmC,xmmA
punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmD,xmmB
punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F)
movdqa xmmG,xmmE
punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E)
punpcklbw xmmF,xmmH
punpckhbw xmmH,xmmH
psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F)
psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F)
%endif ; RGB_PIXELSIZE ; ---------------
; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE
; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO
; (Original)
; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
;
; (This implementation)
; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
movdqa xmm6,xmm1
punpcklwd xmm1,xmm3
punpckhwd xmm6,xmm3
pmaddwd xmm1,[rel PW_F0299_F0337] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337)
pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337)
movdqa xmm7, xmm6 ; xmm7=ROH*FIX(0.299)+GOH*FIX(0.337)
movdqa xmm6,xmm0
punpcklwd xmm0,xmm2
punpckhwd xmm6,xmm2
pmaddwd xmm0,[rel PW_F0299_F0337] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337)
pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337)
movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=REL*FIX(0.299)+GEL*FIX(0.337)
movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=REH*FIX(0.299)+GEH*FIX(0.337)
movdqa xmm0, xmm5 ; xmm0=BO
movdqa xmm6, xmm4 ; xmm6=BE
movdqa xmm4,xmm0
punpcklwd xmm0,xmm3
punpckhwd xmm4,xmm3
pmaddwd xmm0,[rel PW_F0114_F0250] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250)
pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250)
movdqa xmm3,[rel PD_ONEHALF] ; xmm3=[PD_ONEHALF]
paddd xmm0, xmm1
paddd xmm4, xmm7
paddd xmm0,xmm3
paddd xmm4,xmm3
psrld xmm0,SCALEBITS ; xmm0=YOL
psrld xmm4,SCALEBITS ; xmm4=YOH
packssdw xmm0,xmm4 ; xmm0=YO
movdqa xmm4,xmm6
punpcklwd xmm6,xmm2
punpckhwd xmm4,xmm2
pmaddwd xmm6,[rel PW_F0114_F0250] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250)
pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250)
movdqa xmm2,[rel PD_ONEHALF] ; xmm2=[PD_ONEHALF]
paddd xmm6, XMMWORD [wk(0)]
paddd xmm4, XMMWORD [wk(1)]
paddd xmm6,xmm2
paddd xmm4,xmm2
psrld xmm6,SCALEBITS ; xmm6=YEL
psrld xmm4,SCALEBITS ; xmm4=YEH
packssdw xmm6,xmm4 ; xmm6=YE
psllw xmm0,BYTE_BIT
por xmm6,xmm0 ; xmm6=Y
movdqa XMMWORD [rdi], xmm6 ; Save Y
sub rcx, byte SIZEOF_XMMWORD
add rsi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr
add rdi, byte SIZEOF_XMMWORD ; outptr0
cmp rcx, byte SIZEOF_XMMWORD
jae near .columnloop
test rcx,rcx
jnz near .column_ld1
pop rcx ; col
pop rsi
pop rdi
add rsi, byte SIZEOF_JSAMPROW ; input_buf
add rdi, byte SIZEOF_JSAMPROW
dec rax ; num_rows
jg near .rowloop
.return:
pop rbx
uncollect_args
mov rsp,rbp ; rsp <- aligned rbp
pop rsp ; rsp <- original rbp
pop rbp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16
@@ -1,330 +0,0 @@
;
; jcsample.asm - downsampling (64-bit SSE2)
;
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2009 D. R. Commander
;
; Based on
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; [TAB8]
%include "jsimdext.inc"
; --------------------------------------------------------------------------
SECTION SEG_TEXT
BITS 64
;
; Downsample pixel values of a single component.
; This version handles the common case of 2:1 horizontal and 1:1 vertical,
; without smoothing.
;
; GLOBAL(void)
; jsimd_h2v1_downsample_sse2 (JDIMENSION image_width, int max_v_samp_factor,
; JDIMENSION v_samp_factor, JDIMENSION width_blocks,
; JSAMPARRAY input_data, JSAMPARRAY output_data);
;
; r10 = JDIMENSION image_width
; r11 = int max_v_samp_factor
; r12 = JDIMENSION v_samp_factor
; r13 = JDIMENSION width_blocks
; r14 = JSAMPARRAY input_data
; r15 = JSAMPARRAY output_data
align 16
global EXTN(jsimd_h2v1_downsample_sse2)
EXTN(jsimd_h2v1_downsample_sse2):
push rbp
mov rax,rsp
mov rbp,rsp
collect_args
mov rcx, r13
shl rcx,3 ; imul rcx,DCTSIZE (rcx = output_cols)
jz near .return
mov rdx, r10
; -- expand_right_edge
push rcx
shl rcx,1 ; output_cols * 2
sub rcx,rdx
jle short .expand_end
mov rax, r11
test rax,rax
jle short .expand_end
cld
mov rsi, r14 ; input_data
.expandloop:
push rax
push rcx
mov rdi, JSAMPROW [rsi]
add rdi,rdx
mov al, JSAMPLE [rdi-1]
rep stosb
pop rcx
pop rax
add rsi, byte SIZEOF_JSAMPROW
dec rax
jg short .expandloop
.expand_end:
pop rcx ; output_cols
; -- h2v1_downsample
mov rax, r12 ; rowctr
test eax,eax
jle near .return
mov rdx, 0x00010000 ; bias pattern
movd xmm7,edx
pcmpeqw xmm6,xmm6
pshufd xmm7,xmm7,0x00 ; xmm7={0, 1, 0, 1, 0, 1, 0, 1}
psrlw xmm6,BYTE_BIT ; xmm6={0xFF 0x00 0xFF 0x00 ..}
mov rsi, r14 ; input_data
mov rdi, r15 ; output_data
.rowloop:
push rcx
push rdi
push rsi
mov rsi, JSAMPROW [rsi] ; inptr
mov rdi, JSAMPROW [rdi] ; outptr
cmp rcx, byte SIZEOF_XMMWORD
jae short .columnloop
.columnloop_r8:
movdqa xmm0, XMMWORD [rsi+0*SIZEOF_XMMWORD]
pxor xmm1,xmm1
mov rcx, SIZEOF_XMMWORD
jmp short .downsample
.columnloop:
movdqa xmm0, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqa xmm1, XMMWORD [rsi+1*SIZEOF_XMMWORD]
.downsample:
movdqa xmm2,xmm0
movdqa xmm3,xmm1
pand xmm0,xmm6
psrlw xmm2,BYTE_BIT
pand xmm1,xmm6
psrlw xmm3,BYTE_BIT
paddw xmm0,xmm2
paddw xmm1,xmm3
paddw xmm0,xmm7
paddw xmm1,xmm7
psrlw xmm0,1
psrlw xmm1,1
packuswb xmm0,xmm1
movdqa XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm0
sub rcx, byte SIZEOF_XMMWORD ; outcol
add rsi, byte 2*SIZEOF_XMMWORD ; inptr
add rdi, byte 1*SIZEOF_XMMWORD ; outptr
cmp rcx, byte SIZEOF_XMMWORD
jae short .columnloop
test rcx,rcx
jnz short .columnloop_r8
pop rsi
pop rdi
pop rcx
add rsi, byte SIZEOF_JSAMPROW ; input_data
add rdi, byte SIZEOF_JSAMPROW ; output_data
dec rax ; rowctr
jg near .rowloop
.return:
uncollect_args
pop rbp
ret
; --------------------------------------------------------------------------
;
; Downsample pixel values of a single component.
; This version handles the standard case of 2:1 horizontal and 2:1 vertical,
; without smoothing.
;
; GLOBAL(void)
; jsimd_h2v2_downsample_sse2 (JDIMENSION image_width, int max_v_samp_factor,
; JDIMENSION v_samp_factor, JDIMENSION width_blocks,
; JSAMPARRAY input_data, JSAMPARRAY output_data);
;
; r10 = JDIMENSION image_width
; r11 = int max_v_samp_factor
; r12 = JDIMENSION v_samp_factor
; r13 = JDIMENSION width_blocks
; r14 = JSAMPARRAY input_data
; r15 = JSAMPARRAY output_data
align 16
global EXTN(jsimd_h2v2_downsample_sse2)
EXTN(jsimd_h2v2_downsample_sse2):
push rbp
mov rax,rsp
mov rbp,rsp
collect_args
mov rcx, r13
shl rcx,3 ; imul rcx,DCTSIZE (rcx = output_cols)
jz near .return
mov rdx, r10
; -- expand_right_edge
push rcx
shl rcx,1 ; output_cols * 2
sub rcx,rdx
jle short .expand_end
mov rax, r11
test rax,rax
jle short .expand_end
cld
mov rsi, r14 ; input_data
.expandloop:
push rax
push rcx
mov rdi, JSAMPROW [rsi]
add rdi,rdx
mov al, JSAMPLE [rdi-1]
rep stosb
pop rcx
pop rax
add rsi, byte SIZEOF_JSAMPROW
dec rax
jg short .expandloop
.expand_end:
pop rcx ; output_cols
; -- h2v2_downsample
mov rax, r12 ; rowctr
test rax,rax
jle near .return
mov rdx, 0x00020001 ; bias pattern
movd xmm7,edx
pcmpeqw xmm6,xmm6
pshufd xmm7,xmm7,0x00 ; xmm7={1, 2, 1, 2, 1, 2, 1, 2}
psrlw xmm6,BYTE_BIT ; xmm6={0xFF 0x00 0xFF 0x00 ..}
mov rsi, r14 ; input_data
mov rdi, r15 ; output_data
.rowloop:
push rcx
push rdi
push rsi
mov rdx, JSAMPROW [rsi+0*SIZEOF_JSAMPROW] ; inptr0
mov rsi, JSAMPROW [rsi+1*SIZEOF_JSAMPROW] ; inptr1
mov rdi, JSAMPROW [rdi] ; outptr
cmp rcx, byte SIZEOF_XMMWORD
jae short .columnloop
.columnloop_r8:
movdqa xmm0, XMMWORD [rdx+0*SIZEOF_XMMWORD]
movdqa xmm1, XMMWORD [rsi+0*SIZEOF_XMMWORD]
pxor xmm2,xmm2
pxor xmm3,xmm3
mov rcx, SIZEOF_XMMWORD
jmp short .downsample
.columnloop:
movdqa xmm0, XMMWORD [rdx+0*SIZEOF_XMMWORD]
movdqa xmm1, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqa xmm2, XMMWORD [rdx+1*SIZEOF_XMMWORD]
movdqa xmm3, XMMWORD [rsi+1*SIZEOF_XMMWORD]
.downsample:
movdqa xmm4,xmm0
movdqa xmm5,xmm1
pand xmm0,xmm6
psrlw xmm4,BYTE_BIT
pand xmm1,xmm6
psrlw xmm5,BYTE_BIT
paddw xmm0,xmm4
paddw xmm1,xmm5
movdqa xmm4,xmm2
movdqa xmm5,xmm3
pand xmm2,xmm6
psrlw xmm4,BYTE_BIT
pand xmm3,xmm6
psrlw xmm5,BYTE_BIT
paddw xmm2,xmm4
paddw xmm3,xmm5
paddw xmm0,xmm1
paddw xmm2,xmm3
paddw xmm0,xmm7
paddw xmm2,xmm7
psrlw xmm0,2
psrlw xmm2,2
packuswb xmm0,xmm2
movdqa XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm0
sub rcx, byte SIZEOF_XMMWORD ; outcol
add rdx, byte 2*SIZEOF_XMMWORD ; inptr0
add rsi, byte 2*SIZEOF_XMMWORD ; inptr1
add rdi, byte 1*SIZEOF_XMMWORD ; outptr
cmp rcx, byte SIZEOF_XMMWORD
jae near .columnloop
test rcx,rcx
jnz near .columnloop_r8
pop rsi
pop rdi
pop rcx
add rsi, byte 2*SIZEOF_JSAMPROW ; input_data
add rdi, byte 1*SIZEOF_JSAMPROW ; output_data
dec rax ; rowctr
jg near .rowloop
.return:
uncollect_args
pop rbp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16
@@ -1,441 +0,0 @@
;
; jdcolext.asm - colorspace conversion (64-bit SSE2)
;
; Copyright 2009, 2012 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2009, 2012 D. R. Commander
;
; Based on
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; [TAB8]
%include "jcolsamp.inc"
; --------------------------------------------------------------------------
;
; Convert some rows of samples to the output colorspace.
;
; GLOBAL(void)
; jsimd_ycc_rgb_convert_sse2 (JDIMENSION out_width,
; JSAMPIMAGE input_buf, JDIMENSION input_row,
; JSAMPARRAY output_buf, int num_rows)
;
; r10 = JDIMENSION out_width
; r11 = JSAMPIMAGE input_buf
; r12 = JDIMENSION input_row
; r13 = JSAMPARRAY output_buf
; r14 = int num_rows
%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 2
align 16
global EXTN(jsimd_ycc_rgb_convert_sse2)
EXTN(jsimd_ycc_rgb_convert_sse2):
push rbp
mov rax,rsp ; rax = original rbp
sub rsp, byte 4
and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [rsp],rax
mov rbp,rsp ; rbp = aligned rbp
lea rsp, [wk(0)]
collect_args
push rbx
mov rcx, r10 ; num_cols
test rcx,rcx
jz near .return
push rcx
mov rdi, r11
mov rcx, r12
mov rsi, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY]
mov rbx, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY]
mov rdx, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY]
lea rsi, [rsi+rcx*SIZEOF_JSAMPROW]
lea rbx, [rbx+rcx*SIZEOF_JSAMPROW]
lea rdx, [rdx+rcx*SIZEOF_JSAMPROW]
pop rcx
mov rdi, r13
mov eax, r14d
test rax,rax
jle near .return
.rowloop:
push rax
push rdi
push rdx
push rbx
push rsi
push rcx ; col
mov rsi, JSAMPROW [rsi] ; inptr0
mov rbx, JSAMPROW [rbx] ; inptr1
mov rdx, JSAMPROW [rdx] ; inptr2
mov rdi, JSAMPROW [rdi] ; outptr
.columnloop:
movdqa xmm5, XMMWORD [rbx] ; xmm5=Cb(0123456789ABCDEF)
movdqa xmm1, XMMWORD [rdx] ; xmm1=Cr(0123456789ABCDEF)
pcmpeqw xmm4,xmm4
pcmpeqw xmm7,xmm7
psrlw xmm4,BYTE_BIT
psllw xmm7,7 ; xmm7={0xFF80 0xFF80 0xFF80 0xFF80 ..}
movdqa xmm0,xmm4 ; xmm0=xmm4={0xFF 0x00 0xFF 0x00 ..}
pand xmm4,xmm5 ; xmm4=Cb(02468ACE)=CbE
psrlw xmm5,BYTE_BIT ; xmm5=Cb(13579BDF)=CbO
pand xmm0,xmm1 ; xmm0=Cr(02468ACE)=CrE
psrlw xmm1,BYTE_BIT ; xmm1=Cr(13579BDF)=CrO
paddw xmm4,xmm7
paddw xmm5,xmm7
paddw xmm0,xmm7
paddw xmm1,xmm7
; (Original)
; R = Y + 1.40200 * Cr
; G = Y - 0.34414 * Cb - 0.71414 * Cr
; B = Y + 1.77200 * Cb
;
; (This implementation)
; R = Y + 0.40200 * Cr + Cr
; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
; B = Y - 0.22800 * Cb + Cb + Cb
movdqa xmm2,xmm4 ; xmm2=CbE
movdqa xmm3,xmm5 ; xmm3=CbO
paddw xmm4,xmm4 ; xmm4=2*CbE
paddw xmm5,xmm5 ; xmm5=2*CbO
movdqa xmm6,xmm0 ; xmm6=CrE
movdqa xmm7,xmm1 ; xmm7=CrO
paddw xmm0,xmm0 ; xmm0=2*CrE
paddw xmm1,xmm1 ; xmm1=2*CrO
pmulhw xmm4,[rel PW_MF0228] ; xmm4=(2*CbE * -FIX(0.22800))
pmulhw xmm5,[rel PW_MF0228] ; xmm5=(2*CbO * -FIX(0.22800))
pmulhw xmm0,[rel PW_F0402] ; xmm0=(2*CrE * FIX(0.40200))
pmulhw xmm1,[rel PW_F0402] ; xmm1=(2*CrO * FIX(0.40200))
paddw xmm4,[rel PW_ONE]
paddw xmm5,[rel PW_ONE]
psraw xmm4,1 ; xmm4=(CbE * -FIX(0.22800))
psraw xmm5,1 ; xmm5=(CbO * -FIX(0.22800))
paddw xmm0,[rel PW_ONE]
paddw xmm1,[rel PW_ONE]
psraw xmm0,1 ; xmm0=(CrE * FIX(0.40200))
psraw xmm1,1 ; xmm1=(CrO * FIX(0.40200))
paddw xmm4,xmm2
paddw xmm5,xmm3
paddw xmm4,xmm2 ; xmm4=(CbE * FIX(1.77200))=(B-Y)E
paddw xmm5,xmm3 ; xmm5=(CbO * FIX(1.77200))=(B-Y)O
paddw xmm0,xmm6 ; xmm0=(CrE * FIX(1.40200))=(R-Y)E
paddw xmm1,xmm7 ; xmm1=(CrO * FIX(1.40200))=(R-Y)O
movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=(B-Y)E
movdqa XMMWORD [wk(1)], xmm5 ; wk(1)=(B-Y)O
movdqa xmm4,xmm2
movdqa xmm5,xmm3
punpcklwd xmm2,xmm6
punpckhwd xmm4,xmm6
pmaddwd xmm2,[rel PW_MF0344_F0285]
pmaddwd xmm4,[rel PW_MF0344_F0285]
punpcklwd xmm3,xmm7
punpckhwd xmm5,xmm7
pmaddwd xmm3,[rel PW_MF0344_F0285]
pmaddwd xmm5,[rel PW_MF0344_F0285]
paddd xmm2,[rel PD_ONEHALF]
paddd xmm4,[rel PD_ONEHALF]
psrad xmm2,SCALEBITS
psrad xmm4,SCALEBITS
paddd xmm3,[rel PD_ONEHALF]
paddd xmm5,[rel PD_ONEHALF]
psrad xmm3,SCALEBITS
psrad xmm5,SCALEBITS
packssdw xmm2,xmm4 ; xmm2=CbE*-FIX(0.344)+CrE*FIX(0.285)
packssdw xmm3,xmm5 ; xmm3=CbO*-FIX(0.344)+CrO*FIX(0.285)
psubw xmm2,xmm6 ; xmm2=CbE*-FIX(0.344)+CrE*-FIX(0.714)=(G-Y)E
psubw xmm3,xmm7 ; xmm3=CbO*-FIX(0.344)+CrO*-FIX(0.714)=(G-Y)O
movdqa xmm5, XMMWORD [rsi] ; xmm5=Y(0123456789ABCDEF)
pcmpeqw xmm4,xmm4
psrlw xmm4,BYTE_BIT ; xmm4={0xFF 0x00 0xFF 0x00 ..}
pand xmm4,xmm5 ; xmm4=Y(02468ACE)=YE
psrlw xmm5,BYTE_BIT ; xmm5=Y(13579BDF)=YO
paddw xmm0,xmm4 ; xmm0=((R-Y)E+YE)=RE=R(02468ACE)
paddw xmm1,xmm5 ; xmm1=((R-Y)O+YO)=RO=R(13579BDF)
packuswb xmm0,xmm0 ; xmm0=R(02468ACE********)
packuswb xmm1,xmm1 ; xmm1=R(13579BDF********)
paddw xmm2,xmm4 ; xmm2=((G-Y)E+YE)=GE=G(02468ACE)
paddw xmm3,xmm5 ; xmm3=((G-Y)O+YO)=GO=G(13579BDF)
packuswb xmm2,xmm2 ; xmm2=G(02468ACE********)
packuswb xmm3,xmm3 ; xmm3=G(13579BDF********)
paddw xmm4, XMMWORD [wk(0)] ; xmm4=(YE+(B-Y)E)=BE=B(02468ACE)
paddw xmm5, XMMWORD [wk(1)] ; xmm5=(YO+(B-Y)O)=BO=B(13579BDF)
packuswb xmm4,xmm4 ; xmm4=B(02468ACE********)
packuswb xmm5,xmm5 ; xmm5=B(13579BDF********)
%if RGB_PIXELSIZE == 3 ; ---------------
; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **)
punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
punpcklbw xmmE,xmmB ; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F)
punpcklbw xmmD,xmmF ; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F)
movdqa xmmG,xmmA
movdqa xmmH,xmmA
punpcklwd xmmA,xmmE ; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07)
punpckhwd xmmG,xmmE ; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F)
psrldq xmmH,2 ; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --)
psrldq xmmE,2 ; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --)
movdqa xmmC,xmmD
movdqa xmmB,xmmD
punpcklwd xmmD,xmmH ; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18)
punpckhwd xmmC,xmmH ; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --)
psrldq xmmB,2 ; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --)
movdqa xmmF,xmmE
punpcklwd xmmE,xmmB ; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29)
punpckhwd xmmF,xmmB ; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --)
pshufd xmmH,xmmA,0x4E; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03)
movdqa xmmB,xmmE
punpckldq xmmA,xmmD ; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14)
punpckldq xmmE,xmmH ; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07)
punpckhdq xmmD,xmmB ; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29)
pshufd xmmH,xmmG,0x4E; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B)
movdqa xmmB,xmmF
punpckldq xmmG,xmmC ; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C)
punpckldq xmmF,xmmH ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F)
punpckhdq xmmC,xmmB ; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --)
punpcklqdq xmmA,xmmE ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
punpcklqdq xmmD,xmmG ; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
punpcklqdq xmmF,xmmC ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
cmp rcx, byte SIZEOF_XMMWORD
jb short .column_st32
test rdi, SIZEOF_XMMWORD-1
jnz short .out1
; --(aligned)-------------------
movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF
jmp short .out0
.out1: ; --(unaligned)-----------------
movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
movdqu XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF
.out0:
add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr
sub rcx, byte SIZEOF_XMMWORD
jz near .nextrow
add rsi, byte SIZEOF_XMMWORD ; inptr0
add rbx, byte SIZEOF_XMMWORD ; inptr1
add rdx, byte SIZEOF_XMMWORD ; inptr2
jmp near .columnloop
.column_st32:
lea rcx, [rcx+rcx*2] ; imul ecx, RGB_PIXELSIZE
cmp rcx, byte 2*SIZEOF_XMMWORD
jb short .column_st16
movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
add rdi, byte 2*SIZEOF_XMMWORD ; outptr
movdqa xmmA,xmmF
sub rcx, byte 2*SIZEOF_XMMWORD
jmp short .column_st15
.column_st16:
cmp rcx, byte SIZEOF_XMMWORD
jb short .column_st15
movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
add rdi, byte SIZEOF_XMMWORD ; outptr
movdqa xmmA,xmmD
sub rcx, byte SIZEOF_XMMWORD
.column_st15:
; Store the lower 8 bytes of xmmA to the output when it has enough
; space.
cmp rcx, byte SIZEOF_MMWORD
jb short .column_st7
movq XMM_MMWORD [rdi], xmmA
add rdi, byte SIZEOF_MMWORD
sub rcx, byte SIZEOF_MMWORD
psrldq xmmA, SIZEOF_MMWORD
.column_st7:
; Store the lower 4 bytes of xmmA to the output when it has enough
; space.
cmp rcx, byte SIZEOF_DWORD
jb short .column_st3
movd XMM_DWORD [rdi], xmmA
add rdi, byte SIZEOF_DWORD
sub rcx, byte SIZEOF_DWORD
psrldq xmmA, SIZEOF_DWORD
.column_st3:
; Store the lower 2 bytes of rax to the output when it has enough
; space.
movd eax, xmmA
cmp rcx, byte SIZEOF_WORD
jb short .column_st1
mov WORD [rdi], ax
add rdi, byte SIZEOF_WORD
sub rcx, byte SIZEOF_WORD
shr rax, 16
.column_st1:
; Store the lower 1 byte of rax to the output when it has enough
; space.
test rcx, rcx
jz short .nextrow
mov BYTE [rdi], al
%else ; RGB_PIXELSIZE == 4 ; -----------
%ifdef RGBX_FILLER_0XFF
pcmpeqb xmm6,xmm6 ; xmm6=XE=X(02468ACE********)
pcmpeqb xmm7,xmm7 ; xmm7=XO=X(13579BDF********)
%else
pxor xmm6,xmm6 ; xmm6=XE=X(02468ACE********)
pxor xmm7,xmm7 ; xmm7=XO=X(13579BDF********)
%endif
; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **)
punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
punpcklbw xmmE,xmmG ; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E)
punpcklbw xmmB,xmmD ; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F)
punpcklbw xmmF,xmmH ; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F)
movdqa xmmC,xmmA
punpcklwd xmmA,xmmE ; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36)
punpckhwd xmmC,xmmE ; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E)
movdqa xmmG,xmmB
punpcklwd xmmB,xmmF ; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37)
punpckhwd xmmG,xmmF ; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F)
movdqa xmmD,xmmA
punpckldq xmmA,xmmB ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
punpckhdq xmmD,xmmB ; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
movdqa xmmH,xmmC
punpckldq xmmC,xmmG ; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
punpckhdq xmmH,xmmG ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
cmp rcx, byte SIZEOF_XMMWORD
jb short .column_st32
test rdi, SIZEOF_XMMWORD-1
jnz short .out1
; --(aligned)-------------------
movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC
movntdq XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH
jmp short .out0
.out1: ; --(unaligned)-----------------
movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
movdqu XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC
movdqu XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH
.out0:
add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr
sub rcx, byte SIZEOF_XMMWORD
jz near .nextrow
add rsi, byte SIZEOF_XMMWORD ; inptr0
add rbx, byte SIZEOF_XMMWORD ; inptr1
add rdx, byte SIZEOF_XMMWORD ; inptr2
jmp near .columnloop
.column_st32:
cmp rcx, byte SIZEOF_XMMWORD/2
jb short .column_st16
movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
add rdi, byte 2*SIZEOF_XMMWORD ; outptr
movdqa xmmA,xmmC
movdqa xmmD,xmmH
sub rcx, byte SIZEOF_XMMWORD/2
.column_st16:
cmp rcx, byte SIZEOF_XMMWORD/4
jb short .column_st15
movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
add rdi, byte SIZEOF_XMMWORD ; outptr
movdqa xmmA,xmmD
sub rcx, byte SIZEOF_XMMWORD/4
.column_st15:
; Store two pixels (8 bytes) of xmmA to the output when it has enough
; space.
cmp rcx, byte SIZEOF_XMMWORD/8
jb short .column_st7
movq MMWORD [rdi], xmmA
add rdi, byte SIZEOF_XMMWORD/8*4
sub rcx, byte SIZEOF_XMMWORD/8
psrldq xmmA, SIZEOF_XMMWORD/8*4
.column_st7:
; Store one pixel (4 bytes) of xmmA to the output when it has enough
; space.
test rcx, rcx
jz short .nextrow
movd XMM_DWORD [rdi], xmmA
%endif ; RGB_PIXELSIZE ; ---------------
.nextrow:
pop rcx
pop rsi
pop rbx
pop rdx
pop rdi
pop rax
add rsi, byte SIZEOF_JSAMPROW
add rbx, byte SIZEOF_JSAMPROW
add rdx, byte SIZEOF_JSAMPROW
add rdi, byte SIZEOF_JSAMPROW ; output_buf
dec rax ; num_rows
jg near .rowloop
sfence ; flush the write buffer
.return:
pop rbx
uncollect_args
mov rsp,rbp ; rsp <- aligned rbp
pop rsp ; rsp <- original rbp
pop rbp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16
@@ -1,120 +0,0 @@
;
; jdcolor.asm - colorspace conversion (64-bit SSE2)
;
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2009 D. R. Commander
;
; Based on
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; [TAB8]
%include "jsimdext.inc"
; --------------------------------------------------------------------------
%define SCALEBITS 16
F_0_344 equ 22554 ; FIX(0.34414)
F_0_714 equ 46802 ; FIX(0.71414)
F_1_402 equ 91881 ; FIX(1.40200)
F_1_772 equ 116130 ; FIX(1.77200)
F_0_402 equ (F_1_402 - 65536) ; FIX(1.40200) - FIX(1)
F_0_285 equ ( 65536 - F_0_714) ; FIX(1) - FIX(0.71414)
F_0_228 equ (131072 - F_1_772) ; FIX(2) - FIX(1.77200)
; --------------------------------------------------------------------------
SECTION SEG_CONST
alignz 16
global EXTN(jconst_ycc_rgb_convert_sse2)
EXTN(jconst_ycc_rgb_convert_sse2):
PW_F0402 times 8 dw F_0_402
PW_MF0228 times 8 dw -F_0_228
PW_MF0344_F0285 times 4 dw -F_0_344, F_0_285
PW_ONE times 8 dw 1
PD_ONEHALF times 4 dd 1 << (SCALEBITS-1)
alignz 16
; --------------------------------------------------------------------------
SECTION SEG_TEXT
BITS 64
%include "jdcolext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_RGB_RED
%define RGB_GREEN EXT_RGB_GREEN
%define RGB_BLUE EXT_RGB_BLUE
%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE
%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extrgb_convert_sse2
%include "jdcolext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_RGBX_RED
%define RGB_GREEN EXT_RGBX_GREEN
%define RGB_BLUE EXT_RGBX_BLUE
%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE
%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extrgbx_convert_sse2
%include "jdcolext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_BGR_RED
%define RGB_GREEN EXT_BGR_GREEN
%define RGB_BLUE EXT_BGR_BLUE
%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE
%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extbgr_convert_sse2
%include "jdcolext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_BGRX_RED
%define RGB_GREEN EXT_BGRX_GREEN
%define RGB_BLUE EXT_BGRX_BLUE
%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE
%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extbgrx_convert_sse2
%include "jdcolext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_XBGR_RED
%define RGB_GREEN EXT_XBGR_GREEN
%define RGB_BLUE EXT_XBGR_BLUE
%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE
%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extxbgr_convert_sse2
%include "jdcolext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_XRGB_RED
%define RGB_GREEN EXT_XRGB_GREEN
%define RGB_BLUE EXT_XRGB_BLUE
%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE
%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extxrgb_convert_sse2
%include "jdcolext-sse2-64.asm"
@@ -1,126 +0,0 @@
;
; jdmerge.asm - merged upsampling/color conversion (64-bit SSE2)
;
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2009 D. R. Commander
;
; Based on
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; [TAB8]
%include "jsimdext.inc"
; --------------------------------------------------------------------------
%define SCALEBITS 16
F_0_344 equ 22554 ; FIX(0.34414)
F_0_714 equ 46802 ; FIX(0.71414)
F_1_402 equ 91881 ; FIX(1.40200)
F_1_772 equ 116130 ; FIX(1.77200)
F_0_402 equ (F_1_402 - 65536) ; FIX(1.40200) - FIX(1)
F_0_285 equ ( 65536 - F_0_714) ; FIX(1) - FIX(0.71414)
F_0_228 equ (131072 - F_1_772) ; FIX(2) - FIX(1.77200)
; --------------------------------------------------------------------------
SECTION SEG_CONST
alignz 16
global EXTN(jconst_merged_upsample_sse2)
EXTN(jconst_merged_upsample_sse2):
PW_F0402 times 8 dw F_0_402
PW_MF0228 times 8 dw -F_0_228
PW_MF0344_F0285 times 4 dw -F_0_344, F_0_285
PW_ONE times 8 dw 1
PD_ONEHALF times 4 dd 1 << (SCALEBITS-1)
alignz 16
; --------------------------------------------------------------------------
SECTION SEG_TEXT
BITS 64
%include "jdmrgext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_RGB_RED
%define RGB_GREEN EXT_RGB_GREEN
%define RGB_BLUE EXT_RGB_BLUE
%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE
%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extrgb_merged_upsample_sse2
%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extrgb_merged_upsample_sse2
%include "jdmrgext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_RGBX_RED
%define RGB_GREEN EXT_RGBX_GREEN
%define RGB_BLUE EXT_RGBX_BLUE
%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE
%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extrgbx_merged_upsample_sse2
%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extrgbx_merged_upsample_sse2
%include "jdmrgext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_BGR_RED
%define RGB_GREEN EXT_BGR_GREEN
%define RGB_BLUE EXT_BGR_BLUE
%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE
%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extbgr_merged_upsample_sse2
%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extbgr_merged_upsample_sse2
%include "jdmrgext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_BGRX_RED
%define RGB_GREEN EXT_BGRX_GREEN
%define RGB_BLUE EXT_BGRX_BLUE
%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE
%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extbgrx_merged_upsample_sse2
%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extbgrx_merged_upsample_sse2
%include "jdmrgext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_XBGR_RED
%define RGB_GREEN EXT_XBGR_GREEN
%define RGB_BLUE EXT_XBGR_BLUE
%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE
%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extxbgr_merged_upsample_sse2
%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extxbgr_merged_upsample_sse2
%include "jdmrgext-sse2-64.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_XRGB_RED
%define RGB_GREEN EXT_XRGB_GREEN
%define RGB_BLUE EXT_XRGB_BLUE
%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE
%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extxrgb_merged_upsample_sse2
%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extxrgb_merged_upsample_sse2
%include "jdmrgext-sse2-64.asm"
@@ -1,538 +0,0 @@
;
; jdmrgext.asm - merged upsampling/color conversion (64-bit SSE2)
;
; Copyright 2009, 2012 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2009, 2012 D. R. Commander
;
; Based on
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; [TAB8]
%include "jcolsamp.inc"
; --------------------------------------------------------------------------
;
; Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
;
; GLOBAL(void)
; jsimd_h2v1_merged_upsample_sse2 (JDIMENSION output_width,
; JSAMPIMAGE input_buf,
; JDIMENSION in_row_group_ctr,
; JSAMPARRAY output_buf);
;
; r10 = JDIMENSION output_width
; r11 = JSAMPIMAGE input_buf
; r12 = JDIMENSION in_row_group_ctr
; r13 = JSAMPARRAY output_buf
%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 3
align 16
global EXTN(jsimd_h2v1_merged_upsample_sse2)
EXTN(jsimd_h2v1_merged_upsample_sse2):
push rbp
mov rax,rsp ; rax = original rbp
sub rsp, byte 4
and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [rsp],rax
mov rbp,rsp ; rbp = aligned rbp
lea rsp, [wk(0)]
collect_args
push rbx
mov rcx, r10 ; col
test rcx,rcx
jz near .return
push rcx
mov rdi, r11
mov rcx, r12
mov rsi, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY]
mov rbx, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY]
mov rdx, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY]
mov rdi, r13
mov rsi, JSAMPROW [rsi+rcx*SIZEOF_JSAMPROW] ; inptr0
mov rbx, JSAMPROW [rbx+rcx*SIZEOF_JSAMPROW] ; inptr1
mov rdx, JSAMPROW [rdx+rcx*SIZEOF_JSAMPROW] ; inptr2
mov rdi, JSAMPROW [rdi] ; outptr
pop rcx ; col
.columnloop:
movdqa xmm6, XMMWORD [rbx] ; xmm6=Cb(0123456789ABCDEF)
movdqa xmm7, XMMWORD [rdx] ; xmm7=Cr(0123456789ABCDEF)
pxor xmm1,xmm1 ; xmm1=(all 0's)
pcmpeqw xmm3,xmm3
psllw xmm3,7 ; xmm3={0xFF80 0xFF80 0xFF80 0xFF80 ..}
movdqa xmm4,xmm6
punpckhbw xmm6,xmm1 ; xmm6=Cb(89ABCDEF)=CbH
punpcklbw xmm4,xmm1 ; xmm4=Cb(01234567)=CbL
movdqa xmm0,xmm7
punpckhbw xmm7,xmm1 ; xmm7=Cr(89ABCDEF)=CrH
punpcklbw xmm0,xmm1 ; xmm0=Cr(01234567)=CrL
paddw xmm6,xmm3
paddw xmm4,xmm3
paddw xmm7,xmm3
paddw xmm0,xmm3
; (Original)
; R = Y + 1.40200 * Cr
; G = Y - 0.34414 * Cb - 0.71414 * Cr
; B = Y + 1.77200 * Cb
;
; (This implementation)
; R = Y + 0.40200 * Cr + Cr
; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
; B = Y - 0.22800 * Cb + Cb + Cb
movdqa xmm5,xmm6 ; xmm5=CbH
movdqa xmm2,xmm4 ; xmm2=CbL
paddw xmm6,xmm6 ; xmm6=2*CbH
paddw xmm4,xmm4 ; xmm4=2*CbL
movdqa xmm1,xmm7 ; xmm1=CrH
movdqa xmm3,xmm0 ; xmm3=CrL
paddw xmm7,xmm7 ; xmm7=2*CrH
paddw xmm0,xmm0 ; xmm0=2*CrL
pmulhw xmm6,[rel PW_MF0228] ; xmm6=(2*CbH * -FIX(0.22800))
pmulhw xmm4,[rel PW_MF0228] ; xmm4=(2*CbL * -FIX(0.22800))
pmulhw xmm7,[rel PW_F0402] ; xmm7=(2*CrH * FIX(0.40200))
pmulhw xmm0,[rel PW_F0402] ; xmm0=(2*CrL * FIX(0.40200))
paddw xmm6,[rel PW_ONE]
paddw xmm4,[rel PW_ONE]
psraw xmm6,1 ; xmm6=(CbH * -FIX(0.22800))
psraw xmm4,1 ; xmm4=(CbL * -FIX(0.22800))
paddw xmm7,[rel PW_ONE]
paddw xmm0,[rel PW_ONE]
psraw xmm7,1 ; xmm7=(CrH * FIX(0.40200))
psraw xmm0,1 ; xmm0=(CrL * FIX(0.40200))
paddw xmm6,xmm5
paddw xmm4,xmm2
paddw xmm6,xmm5 ; xmm6=(CbH * FIX(1.77200))=(B-Y)H
paddw xmm4,xmm2 ; xmm4=(CbL * FIX(1.77200))=(B-Y)L
paddw xmm7,xmm1 ; xmm7=(CrH * FIX(1.40200))=(R-Y)H
paddw xmm0,xmm3 ; xmm0=(CrL * FIX(1.40200))=(R-Y)L
movdqa XMMWORD [wk(0)], xmm6 ; wk(0)=(B-Y)H
movdqa XMMWORD [wk(1)], xmm7 ; wk(1)=(R-Y)H
movdqa xmm6,xmm5
movdqa xmm7,xmm2
punpcklwd xmm5,xmm1
punpckhwd xmm6,xmm1
pmaddwd xmm5,[rel PW_MF0344_F0285]
pmaddwd xmm6,[rel PW_MF0344_F0285]
punpcklwd xmm2,xmm3
punpckhwd xmm7,xmm3
pmaddwd xmm2,[rel PW_MF0344_F0285]
pmaddwd xmm7,[rel PW_MF0344_F0285]
paddd xmm5,[rel PD_ONEHALF]
paddd xmm6,[rel PD_ONEHALF]
psrad xmm5,SCALEBITS
psrad xmm6,SCALEBITS
paddd xmm2,[rel PD_ONEHALF]
paddd xmm7,[rel PD_ONEHALF]
psrad xmm2,SCALEBITS
psrad xmm7,SCALEBITS
packssdw xmm5,xmm6 ; xmm5=CbH*-FIX(0.344)+CrH*FIX(0.285)
packssdw xmm2,xmm7 ; xmm2=CbL*-FIX(0.344)+CrL*FIX(0.285)
psubw xmm5,xmm1 ; xmm5=CbH*-FIX(0.344)+CrH*-FIX(0.714)=(G-Y)H
psubw xmm2,xmm3 ; xmm2=CbL*-FIX(0.344)+CrL*-FIX(0.714)=(G-Y)L
movdqa XMMWORD [wk(2)], xmm5 ; wk(2)=(G-Y)H
mov al,2 ; Yctr
jmp short .Yloop_1st
.Yloop_2nd:
movdqa xmm0, XMMWORD [wk(1)] ; xmm0=(R-Y)H
movdqa xmm2, XMMWORD [wk(2)] ; xmm2=(G-Y)H
movdqa xmm4, XMMWORD [wk(0)] ; xmm4=(B-Y)H
.Yloop_1st:
movdqa xmm7, XMMWORD [rsi] ; xmm7=Y(0123456789ABCDEF)
pcmpeqw xmm6,xmm6
psrlw xmm6,BYTE_BIT ; xmm6={0xFF 0x00 0xFF 0x00 ..}
pand xmm6,xmm7 ; xmm6=Y(02468ACE)=YE
psrlw xmm7,BYTE_BIT ; xmm7=Y(13579BDF)=YO
movdqa xmm1,xmm0 ; xmm1=xmm0=(R-Y)(L/H)
movdqa xmm3,xmm2 ; xmm3=xmm2=(G-Y)(L/H)
movdqa xmm5,xmm4 ; xmm5=xmm4=(B-Y)(L/H)
paddw xmm0,xmm6 ; xmm0=((R-Y)+YE)=RE=R(02468ACE)
paddw xmm1,xmm7 ; xmm1=((R-Y)+YO)=RO=R(13579BDF)
packuswb xmm0,xmm0 ; xmm0=R(02468ACE********)
packuswb xmm1,xmm1 ; xmm1=R(13579BDF********)
paddw xmm2,xmm6 ; xmm2=((G-Y)+YE)=GE=G(02468ACE)
paddw xmm3,xmm7 ; xmm3=((G-Y)+YO)=GO=G(13579BDF)
packuswb xmm2,xmm2 ; xmm2=G(02468ACE********)
packuswb xmm3,xmm3 ; xmm3=G(13579BDF********)
paddw xmm4,xmm6 ; xmm4=((B-Y)+YE)=BE=B(02468ACE)
paddw xmm5,xmm7 ; xmm5=((B-Y)+YO)=BO=B(13579BDF)
packuswb xmm4,xmm4 ; xmm4=B(02468ACE********)
packuswb xmm5,xmm5 ; xmm5=B(13579BDF********)
%if RGB_PIXELSIZE == 3 ; ---------------
; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **)
punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
punpcklbw xmmE,xmmB ; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F)
punpcklbw xmmD,xmmF ; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F)
movdqa xmmG,xmmA
movdqa xmmH,xmmA
punpcklwd xmmA,xmmE ; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07)
punpckhwd xmmG,xmmE ; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F)
psrldq xmmH,2 ; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --)
psrldq xmmE,2 ; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --)
movdqa xmmC,xmmD
movdqa xmmB,xmmD
punpcklwd xmmD,xmmH ; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18)
punpckhwd xmmC,xmmH ; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --)
psrldq xmmB,2 ; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --)
movdqa xmmF,xmmE
punpcklwd xmmE,xmmB ; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29)
punpckhwd xmmF,xmmB ; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --)
pshufd xmmH,xmmA,0x4E; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03)
movdqa xmmB,xmmE
punpckldq xmmA,xmmD ; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14)
punpckldq xmmE,xmmH ; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07)
punpckhdq xmmD,xmmB ; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29)
pshufd xmmH,xmmG,0x4E; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B)
movdqa xmmB,xmmF
punpckldq xmmG,xmmC ; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C)
punpckldq xmmF,xmmH ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F)
punpckhdq xmmC,xmmB ; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --)
punpcklqdq xmmA,xmmE ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
punpcklqdq xmmD,xmmG ; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
punpcklqdq xmmF,xmmC ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
cmp rcx, byte SIZEOF_XMMWORD
jb short .column_st32
test rdi, SIZEOF_XMMWORD-1
jnz short .out1
; --(aligned)-------------------
movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF
jmp short .out0
.out1: ; --(unaligned)-----------------
movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
movdqu XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF
.out0:
add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr
sub rcx, byte SIZEOF_XMMWORD
jz near .endcolumn
add rsi, byte SIZEOF_XMMWORD ; inptr0
dec al ; Yctr
jnz near .Yloop_2nd
add rbx, byte SIZEOF_XMMWORD ; inptr1
add rdx, byte SIZEOF_XMMWORD ; inptr2
jmp near .columnloop
.column_st32:
lea rcx, [rcx+rcx*2] ; imul ecx, RGB_PIXELSIZE
cmp rcx, byte 2*SIZEOF_XMMWORD
jb short .column_st16
movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
add rdi, byte 2*SIZEOF_XMMWORD ; outptr
movdqa xmmA,xmmF
sub rcx, byte 2*SIZEOF_XMMWORD
jmp short .column_st15
.column_st16:
cmp rcx, byte SIZEOF_XMMWORD
jb short .column_st15
movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
add rdi, byte SIZEOF_XMMWORD ; outptr
movdqa xmmA,xmmD
sub rcx, byte SIZEOF_XMMWORD
.column_st15:
; Store the lower 8 bytes of xmmA to the output when it has enough
; space.
cmp rcx, byte SIZEOF_MMWORD
jb short .column_st7
movq XMM_MMWORD [rdi], xmmA
add rdi, byte SIZEOF_MMWORD
sub rcx, byte SIZEOF_MMWORD
psrldq xmmA, SIZEOF_MMWORD
.column_st7:
; Store the lower 4 bytes of xmmA to the output when it has enough
; space.
cmp rcx, byte SIZEOF_DWORD
jb short .column_st3
movd XMM_DWORD [rdi], xmmA
add rdi, byte SIZEOF_DWORD
sub rcx, byte SIZEOF_DWORD
psrldq xmmA, SIZEOF_DWORD
.column_st3:
; Store the lower 2 bytes of rax to the output when it has enough
; space.
movd eax, xmmA
cmp rcx, byte SIZEOF_WORD
jb short .column_st1
mov WORD [rdi], ax
add rdi, byte SIZEOF_WORD
sub rcx, byte SIZEOF_WORD
shr rax, 16
.column_st1:
; Store the lower 1 byte of rax to the output when it has enough
; space.
test rcx, rcx
jz short .endcolumn
mov BYTE [rdi], al
%else ; RGB_PIXELSIZE == 4 ; -----------
%ifdef RGBX_FILLER_0XFF
pcmpeqb xmm6,xmm6 ; xmm6=XE=X(02468ACE********)
pcmpeqb xmm7,xmm7 ; xmm7=XO=X(13579BDF********)
%else
pxor xmm6,xmm6 ; xmm6=XE=X(02468ACE********)
pxor xmm7,xmm7 ; xmm7=XO=X(13579BDF********)
%endif
; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **)
punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
punpcklbw xmmE,xmmG ; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E)
punpcklbw xmmB,xmmD ; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F)
punpcklbw xmmF,xmmH ; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F)
movdqa xmmC,xmmA
punpcklwd xmmA,xmmE ; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36)
punpckhwd xmmC,xmmE ; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E)
movdqa xmmG,xmmB
punpcklwd xmmB,xmmF ; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37)
punpckhwd xmmG,xmmF ; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F)
movdqa xmmD,xmmA
punpckldq xmmA,xmmB ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
punpckhdq xmmD,xmmB ; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
movdqa xmmH,xmmC
punpckldq xmmC,xmmG ; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
punpckhdq xmmH,xmmG ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
cmp rcx, byte SIZEOF_XMMWORD
jb short .column_st32
test rdi, SIZEOF_XMMWORD-1
jnz short .out1
; --(aligned)-------------------
movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC
movntdq XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH
jmp short .out0
.out1: ; --(unaligned)-----------------
movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
movdqu XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC
movdqu XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH
.out0:
add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr
sub rcx, byte SIZEOF_XMMWORD
jz near .endcolumn
add rsi, byte SIZEOF_XMMWORD ; inptr0
dec al ; Yctr
jnz near .Yloop_2nd
add rbx, byte SIZEOF_XMMWORD ; inptr1
add rdx, byte SIZEOF_XMMWORD ; inptr2
jmp near .columnloop
.column_st32:
cmp rcx, byte SIZEOF_XMMWORD/2
jb short .column_st16
movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
add rdi, byte 2*SIZEOF_XMMWORD ; outptr
movdqa xmmA,xmmC
movdqa xmmD,xmmH
sub rcx, byte SIZEOF_XMMWORD/2
.column_st16:
cmp rcx, byte SIZEOF_XMMWORD/4
jb short .column_st15
movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
add rdi, byte SIZEOF_XMMWORD ; outptr
movdqa xmmA,xmmD
sub rcx, byte SIZEOF_XMMWORD/4
.column_st15:
; Store two pixels (8 bytes) of xmmA to the output when it has enough
; space.
cmp rcx, byte SIZEOF_XMMWORD/8
jb short .column_st7
movq XMM_MMWORD [rdi], xmmA
add rdi, byte SIZEOF_XMMWORD/8*4
sub rcx, byte SIZEOF_XMMWORD/8
psrldq xmmA, SIZEOF_XMMWORD/8*4
.column_st7:
; Store one pixel (4 bytes) of xmmA to the output when it has enough
; space.
test rcx, rcx
jz short .endcolumn
movd XMM_DWORD [rdi], xmmA
%endif ; RGB_PIXELSIZE ; ---------------
.endcolumn:
sfence ; flush the write buffer
.return:
pop rbx
uncollect_args
mov rsp,rbp ; rsp <- aligned rbp
pop rsp ; rsp <- original rbp
pop rbp
ret
; --------------------------------------------------------------------------
;
; Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
;
; GLOBAL(void)
; jsimd_h2v2_merged_upsample_sse2 (JDIMENSION output_width,
; JSAMPIMAGE input_buf,
; JDIMENSION in_row_group_ctr,
; JSAMPARRAY output_buf);
;
; r10 = JDIMENSION output_width
; r11 = JSAMPIMAGE input_buf
; r12 = JDIMENSION in_row_group_ctr
; r13 = JSAMPARRAY output_buf
align 16
global EXTN(jsimd_h2v2_merged_upsample_sse2)
EXTN(jsimd_h2v2_merged_upsample_sse2):
push rbp
mov rax,rsp
mov rbp,rsp
collect_args
push rbx
mov rax, r10
mov rdi, r11
mov rcx, r12
mov rsi, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY]
mov rbx, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY]
mov rdx, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY]
mov rdi, r13
lea rsi, [rsi+rcx*SIZEOF_JSAMPROW]
push rdx ; inptr2
push rbx ; inptr1
push rsi ; inptr00
mov rbx,rsp
push rdi
push rcx
push rax
%ifdef WIN64
mov r8, rcx
mov r9, rdi
mov rcx, rax
mov rdx, rbx
%else
mov rdx, rcx
mov rcx, rdi
mov rdi, rax
mov rsi, rbx
%endif
call EXTN(jsimd_h2v1_merged_upsample_sse2)
pop rax
pop rcx
pop rdi
pop rsi
pop rbx
pop rdx
add rdi, byte SIZEOF_JSAMPROW ; outptr1
add rsi, byte SIZEOF_JSAMPROW ; inptr01
push rdx ; inptr2
push rbx ; inptr1
push rsi ; inptr00
mov rbx,rsp
push rdi
push rcx
push rax
%ifdef WIN64
mov r8, rcx
mov r9, rdi
mov rcx, rax
mov rdx, rbx
%else
mov rdx, rcx
mov rcx, rdi
mov rdi, rax
mov rsi, rbx
%endif
call EXTN(jsimd_h2v1_merged_upsample_sse2)
pop rax
pop rcx
pop rdi
pop rsi
pop rbx
pop rdx
pop rbx
uncollect_args
pop rbp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16
@@ -1,671 +0,0 @@
;
; jdsample.asm - upsampling (64-bit SSE2)
;
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2009 D. R. Commander
;
; Based on
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; [TAB8]
%include "jsimdext.inc"
; --------------------------------------------------------------------------
SECTION SEG_CONST
alignz 16
global EXTN(jconst_fancy_upsample_sse2)
EXTN(jconst_fancy_upsample_sse2):
PW_ONE times 8 dw 1
PW_TWO times 8 dw 2
PW_THREE times 8 dw 3
PW_SEVEN times 8 dw 7
PW_EIGHT times 8 dw 8
alignz 16
; --------------------------------------------------------------------------
SECTION SEG_TEXT
BITS 64
;
; Fancy processing for the common case of 2:1 horizontal and 1:1 vertical.
;
; The upsampling algorithm is linear interpolation between pixel centers,
; also known as a "triangle filter". This is a good compromise between
; speed and visual quality. The centers of the output pixels are 1/4 and 3/4
; of the way between input pixel centers.
;
; GLOBAL(void)
; jsimd_h2v1_fancy_upsample_sse2 (int max_v_samp_factor,
; JDIMENSION downsampled_width,
; JSAMPARRAY input_data,
; JSAMPARRAY * output_data_ptr);
;
; r10 = int max_v_samp_factor
; r11 = JDIMENSION downsampled_width
; r12 = JSAMPARRAY input_data
; r13 = JSAMPARRAY * output_data_ptr
align 16
global EXTN(jsimd_h2v1_fancy_upsample_sse2)
EXTN(jsimd_h2v1_fancy_upsample_sse2):
push rbp
mov rax,rsp
mov rbp,rsp
collect_args
mov rax, r11 ; colctr
test rax,rax
jz near .return
mov rcx, r10 ; rowctr
test rcx,rcx
jz near .return
mov rsi, r12 ; input_data
mov rdi, r13
mov rdi, JSAMPARRAY [rdi] ; output_data
.rowloop:
push rax ; colctr
push rdi
push rsi
mov rsi, JSAMPROW [rsi] ; inptr
mov rdi, JSAMPROW [rdi] ; outptr
test rax, SIZEOF_XMMWORD-1
jz short .skip
mov dl, JSAMPLE [rsi+(rax-1)*SIZEOF_JSAMPLE]
mov JSAMPLE [rsi+rax*SIZEOF_JSAMPLE], dl ; insert a dummy sample
.skip:
pxor xmm0,xmm0 ; xmm0=(all 0's)
pcmpeqb xmm7,xmm7
psrldq xmm7,(SIZEOF_XMMWORD-1)
pand xmm7, XMMWORD [rsi+0*SIZEOF_XMMWORD]
add rax, byte SIZEOF_XMMWORD-1
and rax, byte -SIZEOF_XMMWORD
cmp rax, byte SIZEOF_XMMWORD
ja short .columnloop
.columnloop_last:
pcmpeqb xmm6,xmm6
pslldq xmm6,(SIZEOF_XMMWORD-1)
pand xmm6, XMMWORD [rsi+0*SIZEOF_XMMWORD]
jmp short .upsample
.columnloop:
movdqa xmm6, XMMWORD [rsi+1*SIZEOF_XMMWORD]
pslldq xmm6,(SIZEOF_XMMWORD-1)
.upsample:
movdqa xmm1, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqa xmm2,xmm1
movdqa xmm3,xmm1 ; xmm1=( 0 1 2 ... 13 14 15)
pslldq xmm2,1 ; xmm2=(-- 0 1 ... 12 13 14)
psrldq xmm3,1 ; xmm3=( 1 2 3 ... 14 15 --)
por xmm2,xmm7 ; xmm2=(-1 0 1 ... 12 13 14)
por xmm3,xmm6 ; xmm3=( 1 2 3 ... 14 15 16)
movdqa xmm7,xmm1
psrldq xmm7,(SIZEOF_XMMWORD-1) ; xmm7=(15 -- -- ... -- -- --)
movdqa xmm4,xmm1
punpcklbw xmm1,xmm0 ; xmm1=( 0 1 2 3 4 5 6 7)
punpckhbw xmm4,xmm0 ; xmm4=( 8 9 10 11 12 13 14 15)
movdqa xmm5,xmm2
punpcklbw xmm2,xmm0 ; xmm2=(-1 0 1 2 3 4 5 6)
punpckhbw xmm5,xmm0 ; xmm5=( 7 8 9 10 11 12 13 14)
movdqa xmm6,xmm3
punpcklbw xmm3,xmm0 ; xmm3=( 1 2 3 4 5 6 7 8)
punpckhbw xmm6,xmm0 ; xmm6=( 9 10 11 12 13 14 15 16)
pmullw xmm1,[rel PW_THREE]
pmullw xmm4,[rel PW_THREE]
paddw xmm2,[rel PW_ONE]
paddw xmm5,[rel PW_ONE]
paddw xmm3,[rel PW_TWO]
paddw xmm6,[rel PW_TWO]
paddw xmm2,xmm1
paddw xmm5,xmm4
psrlw xmm2,2 ; xmm2=OutLE=( 0 2 4 6 8 10 12 14)
psrlw xmm5,2 ; xmm5=OutHE=(16 18 20 22 24 26 28 30)
paddw xmm3,xmm1
paddw xmm6,xmm4
psrlw xmm3,2 ; xmm3=OutLO=( 1 3 5 7 9 11 13 15)
psrlw xmm6,2 ; xmm6=OutHO=(17 19 21 23 25 27 29 31)
psllw xmm3,BYTE_BIT
psllw xmm6,BYTE_BIT
por xmm2,xmm3 ; xmm2=OutL=( 0 1 2 ... 13 14 15)
por xmm5,xmm6 ; xmm5=OutH=(16 17 18 ... 29 30 31)
movdqa XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm2
movdqa XMMWORD [rdi+1*SIZEOF_XMMWORD], xmm5
sub rax, byte SIZEOF_XMMWORD
add rsi, byte 1*SIZEOF_XMMWORD ; inptr
add rdi, byte 2*SIZEOF_XMMWORD ; outptr
cmp rax, byte SIZEOF_XMMWORD
ja near .columnloop
test eax,eax
jnz near .columnloop_last
pop rsi
pop rdi
pop rax
add rsi, byte SIZEOF_JSAMPROW ; input_data
add rdi, byte SIZEOF_JSAMPROW ; output_data
dec rcx ; rowctr
jg near .rowloop
.return:
uncollect_args
pop rbp
ret
; --------------------------------------------------------------------------
;
; Fancy processing for the common case of 2:1 horizontal and 2:1 vertical.
; Again a triangle filter; see comments for h2v1 case, above.
;
; GLOBAL(void)
; jsimd_h2v2_fancy_upsample_sse2 (int max_v_samp_factor,
; JDIMENSION downsampled_width,
; JSAMPARRAY input_data,
; JSAMPARRAY * output_data_ptr);
;
; r10 = int max_v_samp_factor
; r11 = JDIMENSION downsampled_width
; r12 = JSAMPARRAY input_data
; r13 = JSAMPARRAY * output_data_ptr
%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 4
align 16
global EXTN(jsimd_h2v2_fancy_upsample_sse2)
EXTN(jsimd_h2v2_fancy_upsample_sse2):
push rbp
mov rax,rsp ; rax = original rbp
sub rsp, byte 4
and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [rsp],rax
mov rbp,rsp ; rbp = aligned rbp
lea rsp, [wk(0)]
collect_args
push rbx
mov rax, r11 ; colctr
test rax,rax
jz near .return
mov rcx, r10 ; rowctr
test rcx,rcx
jz near .return
mov rsi, r12 ; input_data
mov rdi, r13
mov rdi, JSAMPARRAY [rdi] ; output_data
.rowloop:
push rax ; colctr
push rcx
push rdi
push rsi
mov rcx, JSAMPROW [rsi-1*SIZEOF_JSAMPROW] ; inptr1(above)
mov rbx, JSAMPROW [rsi+0*SIZEOF_JSAMPROW] ; inptr0
mov rsi, JSAMPROW [rsi+1*SIZEOF_JSAMPROW] ; inptr1(below)
mov rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW] ; outptr0
mov rdi, JSAMPROW [rdi+1*SIZEOF_JSAMPROW] ; outptr1
test rax, SIZEOF_XMMWORD-1
jz short .skip
push rdx
mov dl, JSAMPLE [rcx+(rax-1)*SIZEOF_JSAMPLE]
mov JSAMPLE [rcx+rax*SIZEOF_JSAMPLE], dl
mov dl, JSAMPLE [rbx+(rax-1)*SIZEOF_JSAMPLE]
mov JSAMPLE [rbx+rax*SIZEOF_JSAMPLE], dl
mov dl, JSAMPLE [rsi+(rax-1)*SIZEOF_JSAMPLE]
mov JSAMPLE [rsi+rax*SIZEOF_JSAMPLE], dl ; insert a dummy sample
pop rdx
.skip:
; -- process the first column block
movdqa xmm0, XMMWORD [rbx+0*SIZEOF_XMMWORD] ; xmm0=row[ 0][0]
movdqa xmm1, XMMWORD [rcx+0*SIZEOF_XMMWORD] ; xmm1=row[-1][0]
movdqa xmm2, XMMWORD [rsi+0*SIZEOF_XMMWORD] ; xmm2=row[+1][0]
pxor xmm3,xmm3 ; xmm3=(all 0's)
movdqa xmm4,xmm0
punpcklbw xmm0,xmm3 ; xmm0=row[ 0]( 0 1 2 3 4 5 6 7)
punpckhbw xmm4,xmm3 ; xmm4=row[ 0]( 8 9 10 11 12 13 14 15)
movdqa xmm5,xmm1
punpcklbw xmm1,xmm3 ; xmm1=row[-1]( 0 1 2 3 4 5 6 7)
punpckhbw xmm5,xmm3 ; xmm5=row[-1]( 8 9 10 11 12 13 14 15)
movdqa xmm6,xmm2
punpcklbw xmm2,xmm3 ; xmm2=row[+1]( 0 1 2 3 4 5 6 7)
punpckhbw xmm6,xmm3 ; xmm6=row[+1]( 8 9 10 11 12 13 14 15)
pmullw xmm0,[rel PW_THREE]
pmullw xmm4,[rel PW_THREE]
pcmpeqb xmm7,xmm7
psrldq xmm7,(SIZEOF_XMMWORD-2)
paddw xmm1,xmm0 ; xmm1=Int0L=( 0 1 2 3 4 5 6 7)
paddw xmm5,xmm4 ; xmm5=Int0H=( 8 9 10 11 12 13 14 15)
paddw xmm2,xmm0 ; xmm2=Int1L=( 0 1 2 3 4 5 6 7)
paddw xmm6,xmm4 ; xmm6=Int1H=( 8 9 10 11 12 13 14 15)
movdqa XMMWORD [rdx+0*SIZEOF_XMMWORD], xmm1 ; temporarily save
movdqa XMMWORD [rdx+1*SIZEOF_XMMWORD], xmm5 ; the intermediate data
movdqa XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm2
movdqa XMMWORD [rdi+1*SIZEOF_XMMWORD], xmm6
pand xmm1,xmm7 ; xmm1=( 0 -- -- -- -- -- -- --)
pand xmm2,xmm7 ; xmm2=( 0 -- -- -- -- -- -- --)
movdqa XMMWORD [wk(0)], xmm1
movdqa XMMWORD [wk(1)], xmm2
add rax, byte SIZEOF_XMMWORD-1
and rax, byte -SIZEOF_XMMWORD
cmp rax, byte SIZEOF_XMMWORD
ja short .columnloop
.columnloop_last:
; -- process the last column block
pcmpeqb xmm1,xmm1
pslldq xmm1,(SIZEOF_XMMWORD-2)
movdqa xmm2,xmm1
pand xmm1, XMMWORD [rdx+1*SIZEOF_XMMWORD]
pand xmm2, XMMWORD [rdi+1*SIZEOF_XMMWORD]
movdqa XMMWORD [wk(2)], xmm1 ; xmm1=(-- -- -- -- -- -- -- 15)
movdqa XMMWORD [wk(3)], xmm2 ; xmm2=(-- -- -- -- -- -- -- 15)
jmp near .upsample
.columnloop:
; -- process the next column block
movdqa xmm0, XMMWORD [rbx+1*SIZEOF_XMMWORD] ; xmm0=row[ 0][1]
movdqa xmm1, XMMWORD [rcx+1*SIZEOF_XMMWORD] ; xmm1=row[-1][1]
movdqa xmm2, XMMWORD [rsi+1*SIZEOF_XMMWORD] ; xmm2=row[+1][1]
pxor xmm3,xmm3 ; xmm3=(all 0's)
movdqa xmm4,xmm0
punpcklbw xmm0,xmm3 ; xmm0=row[ 0]( 0 1 2 3 4 5 6 7)
punpckhbw xmm4,xmm3 ; xmm4=row[ 0]( 8 9 10 11 12 13 14 15)
movdqa xmm5,xmm1
punpcklbw xmm1,xmm3 ; xmm1=row[-1]( 0 1 2 3 4 5 6 7)
punpckhbw xmm5,xmm3 ; xmm5=row[-1]( 8 9 10 11 12 13 14 15)
movdqa xmm6,xmm2
punpcklbw xmm2,xmm3 ; xmm2=row[+1]( 0 1 2 3 4 5 6 7)
punpckhbw xmm6,xmm3 ; xmm6=row[+1]( 8 9 10 11 12 13 14 15)
pmullw xmm0,[rel PW_THREE]
pmullw xmm4,[rel PW_THREE]
paddw xmm1,xmm0 ; xmm1=Int0L=( 0 1 2 3 4 5 6 7)
paddw xmm5,xmm4 ; xmm5=Int0H=( 8 9 10 11 12 13 14 15)
paddw xmm2,xmm0 ; xmm2=Int1L=( 0 1 2 3 4 5 6 7)
paddw xmm6,xmm4 ; xmm6=Int1H=( 8 9 10 11 12 13 14 15)
movdqa XMMWORD [rdx+2*SIZEOF_XMMWORD], xmm1 ; temporarily save
movdqa XMMWORD [rdx+3*SIZEOF_XMMWORD], xmm5 ; the intermediate data
movdqa XMMWORD [rdi+2*SIZEOF_XMMWORD], xmm2
movdqa XMMWORD [rdi+3*SIZEOF_XMMWORD], xmm6
pslldq xmm1,(SIZEOF_XMMWORD-2) ; xmm1=(-- -- -- -- -- -- -- 0)
pslldq xmm2,(SIZEOF_XMMWORD-2) ; xmm2=(-- -- -- -- -- -- -- 0)
movdqa XMMWORD [wk(2)], xmm1
movdqa XMMWORD [wk(3)], xmm2
.upsample:
; -- process the upper row
movdqa xmm7, XMMWORD [rdx+0*SIZEOF_XMMWORD]
movdqa xmm3, XMMWORD [rdx+1*SIZEOF_XMMWORD]
movdqa xmm0,xmm7 ; xmm7=Int0L=( 0 1 2 3 4 5 6 7)
movdqa xmm4,xmm3 ; xmm3=Int0H=( 8 9 10 11 12 13 14 15)
psrldq xmm0,2 ; xmm0=( 1 2 3 4 5 6 7 --)
pslldq xmm4,(SIZEOF_XMMWORD-2) ; xmm4=(-- -- -- -- -- -- -- 8)
movdqa xmm5,xmm7
movdqa xmm6,xmm3
psrldq xmm5,(SIZEOF_XMMWORD-2) ; xmm5=( 7 -- -- -- -- -- -- --)
pslldq xmm6,2 ; xmm6=(-- 8 9 10 11 12 13 14)
por xmm0,xmm4 ; xmm0=( 1 2 3 4 5 6 7 8)
por xmm5,xmm6 ; xmm5=( 7 8 9 10 11 12 13 14)
movdqa xmm1,xmm7
movdqa xmm2,xmm3
pslldq xmm1,2 ; xmm1=(-- 0 1 2 3 4 5 6)
psrldq xmm2,2 ; xmm2=( 9 10 11 12 13 14 15 --)
movdqa xmm4,xmm3
psrldq xmm4,(SIZEOF_XMMWORD-2) ; xmm4=(15 -- -- -- -- -- -- --)
por xmm1, XMMWORD [wk(0)] ; xmm1=(-1 0 1 2 3 4 5 6)
por xmm2, XMMWORD [wk(2)] ; xmm2=( 9 10 11 12 13 14 15 16)
movdqa XMMWORD [wk(0)], xmm4
pmullw xmm7,[rel PW_THREE]
pmullw xmm3,[rel PW_THREE]
paddw xmm1,[rel PW_EIGHT]
paddw xmm5,[rel PW_EIGHT]
paddw xmm0,[rel PW_SEVEN]
paddw xmm2,[rel PW_SEVEN]
paddw xmm1,xmm7
paddw xmm5,xmm3
psrlw xmm1,4 ; xmm1=Out0LE=( 0 2 4 6 8 10 12 14)
psrlw xmm5,4 ; xmm5=Out0HE=(16 18 20 22 24 26 28 30)
paddw xmm0,xmm7
paddw xmm2,xmm3
psrlw xmm0,4 ; xmm0=Out0LO=( 1 3 5 7 9 11 13 15)
psrlw xmm2,4 ; xmm2=Out0HO=(17 19 21 23 25 27 29 31)
psllw xmm0,BYTE_BIT
psllw xmm2,BYTE_BIT
por xmm1,xmm0 ; xmm1=Out0L=( 0 1 2 ... 13 14 15)
por xmm5,xmm2 ; xmm5=Out0H=(16 17 18 ... 29 30 31)
movdqa XMMWORD [rdx+0*SIZEOF_XMMWORD], xmm1
movdqa XMMWORD [rdx+1*SIZEOF_XMMWORD], xmm5
; -- process the lower row
movdqa xmm6, XMMWORD [rdi+0*SIZEOF_XMMWORD]
movdqa xmm4, XMMWORD [rdi+1*SIZEOF_XMMWORD]
movdqa xmm7,xmm6 ; xmm6=Int1L=( 0 1 2 3 4 5 6 7)
movdqa xmm3,xmm4 ; xmm4=Int1H=( 8 9 10 11 12 13 14 15)
psrldq xmm7,2 ; xmm7=( 1 2 3 4 5 6 7 --)
pslldq xmm3,(SIZEOF_XMMWORD-2) ; xmm3=(-- -- -- -- -- -- -- 8)
movdqa xmm0,xmm6
movdqa xmm2,xmm4
psrldq xmm0,(SIZEOF_XMMWORD-2) ; xmm0=( 7 -- -- -- -- -- -- --)
pslldq xmm2,2 ; xmm2=(-- 8 9 10 11 12 13 14)
por xmm7,xmm3 ; xmm7=( 1 2 3 4 5 6 7 8)
por xmm0,xmm2 ; xmm0=( 7 8 9 10 11 12 13 14)
movdqa xmm1,xmm6
movdqa xmm5,xmm4
pslldq xmm1,2 ; xmm1=(-- 0 1 2 3 4 5 6)
psrldq xmm5,2 ; xmm5=( 9 10 11 12 13 14 15 --)
movdqa xmm3,xmm4
psrldq xmm3,(SIZEOF_XMMWORD-2) ; xmm3=(15 -- -- -- -- -- -- --)
por xmm1, XMMWORD [wk(1)] ; xmm1=(-1 0 1 2 3 4 5 6)
por xmm5, XMMWORD [wk(3)] ; xmm5=( 9 10 11 12 13 14 15 16)
movdqa XMMWORD [wk(1)], xmm3
pmullw xmm6,[rel PW_THREE]
pmullw xmm4,[rel PW_THREE]
paddw xmm1,[rel PW_EIGHT]
paddw xmm0,[rel PW_EIGHT]
paddw xmm7,[rel PW_SEVEN]
paddw xmm5,[rel PW_SEVEN]
paddw xmm1,xmm6
paddw xmm0,xmm4
psrlw xmm1,4 ; xmm1=Out1LE=( 0 2 4 6 8 10 12 14)
psrlw xmm0,4 ; xmm0=Out1HE=(16 18 20 22 24 26 28 30)
paddw xmm7,xmm6
paddw xmm5,xmm4
psrlw xmm7,4 ; xmm7=Out1LO=( 1 3 5 7 9 11 13 15)
psrlw xmm5,4 ; xmm5=Out1HO=(17 19 21 23 25 27 29 31)
psllw xmm7,BYTE_BIT
psllw xmm5,BYTE_BIT
por xmm1,xmm7 ; xmm1=Out1L=( 0 1 2 ... 13 14 15)
por xmm0,xmm5 ; xmm0=Out1H=(16 17 18 ... 29 30 31)
movdqa XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm1
movdqa XMMWORD [rdi+1*SIZEOF_XMMWORD], xmm0
sub rax, byte SIZEOF_XMMWORD
add rcx, byte 1*SIZEOF_XMMWORD ; inptr1(above)
add rbx, byte 1*SIZEOF_XMMWORD ; inptr0
add rsi, byte 1*SIZEOF_XMMWORD ; inptr1(below)
add rdx, byte 2*SIZEOF_XMMWORD ; outptr0
add rdi, byte 2*SIZEOF_XMMWORD ; outptr1
cmp rax, byte SIZEOF_XMMWORD
ja near .columnloop
test rax,rax
jnz near .columnloop_last
pop rsi
pop rdi
pop rcx
pop rax
add rsi, byte 1*SIZEOF_JSAMPROW ; input_data
add rdi, byte 2*SIZEOF_JSAMPROW ; output_data
sub rcx, byte 2 ; rowctr
jg near .rowloop
.return:
pop rbx
uncollect_args
mov rsp,rbp ; rsp <- aligned rbp
pop rsp ; rsp <- original rbp
pop rbp
ret
; --------------------------------------------------------------------------
;
; Fast processing for the common case of 2:1 horizontal and 1:1 vertical.
; It's still a box filter.
;
; GLOBAL(void)
; jsimd_h2v1_upsample_sse2 (int max_v_samp_factor,
; JDIMENSION output_width,
; JSAMPARRAY input_data,
; JSAMPARRAY * output_data_ptr);
;
; r10 = int max_v_samp_factor
; r11 = JDIMENSION output_width
; r12 = JSAMPARRAY input_data
; r13 = JSAMPARRAY * output_data_ptr
align 16
global EXTN(jsimd_h2v1_upsample_sse2)
EXTN(jsimd_h2v1_upsample_sse2):
push rbp
mov rax,rsp
mov rbp,rsp
collect_args
mov rdx, r11
add rdx, byte (2*SIZEOF_XMMWORD)-1
and rdx, byte -(2*SIZEOF_XMMWORD)
jz near .return
mov rcx, r10 ; rowctr
test rcx,rcx
jz short .return
mov rsi, r12 ; input_data
mov rdi, r13
mov rdi, JSAMPARRAY [rdi] ; output_data
.rowloop:
push rdi
push rsi
mov rsi, JSAMPROW [rsi] ; inptr
mov rdi, JSAMPROW [rdi] ; outptr
mov rax,rdx ; colctr
.columnloop:
movdqa xmm0, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqa xmm1,xmm0
punpcklbw xmm0,xmm0
punpckhbw xmm1,xmm1
movdqa XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm0
movdqa XMMWORD [rdi+1*SIZEOF_XMMWORD], xmm1
sub rax, byte 2*SIZEOF_XMMWORD
jz short .nextrow
movdqa xmm2, XMMWORD [rsi+1*SIZEOF_XMMWORD]
movdqa xmm3,xmm2
punpcklbw xmm2,xmm2
punpckhbw xmm3,xmm3
movdqa XMMWORD [rdi+2*SIZEOF_XMMWORD], xmm2
movdqa XMMWORD [rdi+3*SIZEOF_XMMWORD], xmm3
sub rax, byte 2*SIZEOF_XMMWORD
jz short .nextrow
add rsi, byte 2*SIZEOF_XMMWORD ; inptr
add rdi, byte 4*SIZEOF_XMMWORD ; outptr
jmp short .columnloop
.nextrow:
pop rsi
pop rdi
add rsi, byte SIZEOF_JSAMPROW ; input_data
add rdi, byte SIZEOF_JSAMPROW ; output_data
dec rcx ; rowctr
jg short .rowloop
.return:
uncollect_args
pop rbp
ret
; --------------------------------------------------------------------------
;
; Fast processing for the common case of 2:1 horizontal and 2:1 vertical.
; It's still a box filter.
;
; GLOBAL(void)
; jsimd_h2v2_upsample_sse2 (nt max_v_samp_factor,
; JDIMENSION output_width,
; JSAMPARRAY input_data,
; JSAMPARRAY * output_data_ptr);
;
; r10 = int max_v_samp_factor
; r11 = JDIMENSION output_width
; r12 = JSAMPARRAY input_data
; r13 = JSAMPARRAY * output_data_ptr
align 16
global EXTN(jsimd_h2v2_upsample_sse2)
EXTN(jsimd_h2v2_upsample_sse2):
push rbp
mov rax,rsp
mov rbp,rsp
collect_args
push rbx
mov rdx, r11
add rdx, byte (2*SIZEOF_XMMWORD)-1
and rdx, byte -(2*SIZEOF_XMMWORD)
jz near .return
mov rcx, r10 ; rowctr
test rcx,rcx
jz near .return
mov rsi, r12 ; input_data
mov rdi, r13
mov rdi, JSAMPARRAY [rdi] ; output_data
.rowloop:
push rdi
push rsi
mov rsi, JSAMPROW [rsi] ; inptr
mov rbx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW] ; outptr0
mov rdi, JSAMPROW [rdi+1*SIZEOF_JSAMPROW] ; outptr1
mov rax,rdx ; colctr
.columnloop:
movdqa xmm0, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqa xmm1,xmm0
punpcklbw xmm0,xmm0
punpckhbw xmm1,xmm1
movdqa XMMWORD [rbx+0*SIZEOF_XMMWORD], xmm0
movdqa XMMWORD [rbx+1*SIZEOF_XMMWORD], xmm1
movdqa XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm0
movdqa XMMWORD [rdi+1*SIZEOF_XMMWORD], xmm1
sub rax, byte 2*SIZEOF_XMMWORD
jz short .nextrow
movdqa xmm2, XMMWORD [rsi+1*SIZEOF_XMMWORD]
movdqa xmm3,xmm2
punpcklbw xmm2,xmm2
punpckhbw xmm3,xmm3
movdqa XMMWORD [rbx+2*SIZEOF_XMMWORD], xmm2
movdqa XMMWORD [rbx+3*SIZEOF_XMMWORD], xmm3
movdqa XMMWORD [rdi+2*SIZEOF_XMMWORD], xmm2
movdqa XMMWORD [rdi+3*SIZEOF_XMMWORD], xmm3
sub rax, byte 2*SIZEOF_XMMWORD
jz short .nextrow
add rsi, byte 2*SIZEOF_XMMWORD ; inptr
add rbx, byte 4*SIZEOF_XMMWORD ; outptr0
add rdi, byte 4*SIZEOF_XMMWORD ; outptr1
jmp short .columnloop
.nextrow:
pop rsi
pop rdi
add rsi, byte 1*SIZEOF_JSAMPROW ; input_data
add rdi, byte 2*SIZEOF_JSAMPROW ; output_data
sub rcx, byte 2 ; rowctr
jg near .rowloop
.return:
pop rbx
uncollect_args
pop rbp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16
@@ -1,358 +0,0 @@
;
; jfdctflt.asm - floating-point FDCT (64-bit SSE)
;
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2009 D. R. Commander
;
; Based on
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; This file contains a floating-point implementation of the forward DCT
; (Discrete Cosine Transform). The following code is based directly on
; the IJG's original jfdctflt.c; see the jfdctflt.c for more details.
;
; [TAB8]
%include "jsimdext.inc"
%include "jdct.inc"
; --------------------------------------------------------------------------
%macro unpcklps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(0 1 4 5)
shufps %1,%2,0x44
%endmacro
%macro unpckhps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(2 3 6 7)
shufps %1,%2,0xEE
%endmacro
; --------------------------------------------------------------------------
SECTION SEG_CONST
alignz 16
global EXTN(jconst_fdct_float_sse)
EXTN(jconst_fdct_float_sse):
PD_0_382 times 4 dd 0.382683432365089771728460
PD_0_707 times 4 dd 0.707106781186547524400844
PD_0_541 times 4 dd 0.541196100146196984399723
PD_1_306 times 4 dd 1.306562964876376527856643
alignz 16
; --------------------------------------------------------------------------
SECTION SEG_TEXT
BITS 64
;
; Perform the forward DCT on one block of samples.
;
; GLOBAL(void)
; jsimd_fdct_float_sse (FAST_FLOAT * data)
;
; r10 = FAST_FLOAT * data
%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 2
align 16
global EXTN(jsimd_fdct_float_sse)
EXTN(jsimd_fdct_float_sse):
push rbp
mov rax,rsp ; rax = original rbp
sub rsp, byte 4
and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [rsp],rax
mov rbp,rsp ; rbp = aligned rbp
lea rsp, [wk(0)]
collect_args
; ---- Pass 1: process rows.
mov rdx, r10 ; (FAST_FLOAT *)
mov rcx, DCTSIZE/4
.rowloop:
movaps xmm0, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_FAST_FLOAT)]
movaps xmm1, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_FAST_FLOAT)]
movaps xmm2, XMMWORD [XMMBLOCK(2,1,rdx,SIZEOF_FAST_FLOAT)]
movaps xmm3, XMMWORD [XMMBLOCK(3,1,rdx,SIZEOF_FAST_FLOAT)]
; xmm0=(20 21 22 23), xmm2=(24 25 26 27)
; xmm1=(30 31 32 33), xmm3=(34 35 36 37)
movaps xmm4,xmm0 ; transpose coefficients(phase 1)
unpcklps xmm0,xmm1 ; xmm0=(20 30 21 31)
unpckhps xmm4,xmm1 ; xmm4=(22 32 23 33)
movaps xmm5,xmm2 ; transpose coefficients(phase 1)
unpcklps xmm2,xmm3 ; xmm2=(24 34 25 35)
unpckhps xmm5,xmm3 ; xmm5=(26 36 27 37)
movaps xmm6, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FAST_FLOAT)]
movaps xmm7, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FAST_FLOAT)]
movaps xmm1, XMMWORD [XMMBLOCK(0,1,rdx,SIZEOF_FAST_FLOAT)]
movaps xmm3, XMMWORD [XMMBLOCK(1,1,rdx,SIZEOF_FAST_FLOAT)]
; xmm6=(00 01 02 03), xmm1=(04 05 06 07)
; xmm7=(10 11 12 13), xmm3=(14 15 16 17)
movaps XMMWORD [wk(0)], xmm4 ; wk(0)=(22 32 23 33)
movaps XMMWORD [wk(1)], xmm2 ; wk(1)=(24 34 25 35)
movaps xmm4,xmm6 ; transpose coefficients(phase 1)
unpcklps xmm6,xmm7 ; xmm6=(00 10 01 11)
unpckhps xmm4,xmm7 ; xmm4=(02 12 03 13)
movaps xmm2,xmm1 ; transpose coefficients(phase 1)
unpcklps xmm1,xmm3 ; xmm1=(04 14 05 15)
unpckhps xmm2,xmm3 ; xmm2=(06 16 07 17)
movaps xmm7,xmm6 ; transpose coefficients(phase 2)
unpcklps2 xmm6,xmm0 ; xmm6=(00 10 20 30)=data0
unpckhps2 xmm7,xmm0 ; xmm7=(01 11 21 31)=data1
movaps xmm3,xmm2 ; transpose coefficients(phase 2)
unpcklps2 xmm2,xmm5 ; xmm2=(06 16 26 36)=data6
unpckhps2 xmm3,xmm5 ; xmm3=(07 17 27 37)=data7
movaps xmm0,xmm7
movaps xmm5,xmm6
subps xmm7,xmm2 ; xmm7=data1-data6=tmp6
subps xmm6,xmm3 ; xmm6=data0-data7=tmp7
addps xmm0,xmm2 ; xmm0=data1+data6=tmp1
addps xmm5,xmm3 ; xmm5=data0+data7=tmp0
movaps xmm2, XMMWORD [wk(0)] ; xmm2=(22 32 23 33)
movaps xmm3, XMMWORD [wk(1)] ; xmm3=(24 34 25 35)
movaps XMMWORD [wk(0)], xmm7 ; wk(0)=tmp6
movaps XMMWORD [wk(1)], xmm6 ; wk(1)=tmp7
movaps xmm7,xmm4 ; transpose coefficients(phase 2)
unpcklps2 xmm4,xmm2 ; xmm4=(02 12 22 32)=data2
unpckhps2 xmm7,xmm2 ; xmm7=(03 13 23 33)=data3
movaps xmm6,xmm1 ; transpose coefficients(phase 2)
unpcklps2 xmm1,xmm3 ; xmm1=(04 14 24 34)=data4
unpckhps2 xmm6,xmm3 ; xmm6=(05 15 25 35)=data5
movaps xmm2,xmm7
movaps xmm3,xmm4
addps xmm7,xmm1 ; xmm7=data3+data4=tmp3
addps xmm4,xmm6 ; xmm4=data2+data5=tmp2
subps xmm2,xmm1 ; xmm2=data3-data4=tmp4
subps xmm3,xmm6 ; xmm3=data2-data5=tmp5
; -- Even part
movaps xmm1,xmm5
movaps xmm6,xmm0
subps xmm5,xmm7 ; xmm5=tmp13
subps xmm0,xmm4 ; xmm0=tmp12
addps xmm1,xmm7 ; xmm1=tmp10
addps xmm6,xmm4 ; xmm6=tmp11
addps xmm0,xmm5
mulps xmm0,[rel PD_0_707] ; xmm0=z1
movaps xmm7,xmm1
movaps xmm4,xmm5
subps xmm1,xmm6 ; xmm1=data4
subps xmm5,xmm0 ; xmm5=data6
addps xmm7,xmm6 ; xmm7=data0
addps xmm4,xmm0 ; xmm4=data2
movaps XMMWORD [XMMBLOCK(0,1,rdx,SIZEOF_FAST_FLOAT)], xmm1
movaps XMMWORD [XMMBLOCK(2,1,rdx,SIZEOF_FAST_FLOAT)], xmm5
movaps XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FAST_FLOAT)], xmm7
movaps XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_FAST_FLOAT)], xmm4
; -- Odd part
movaps xmm6, XMMWORD [wk(0)] ; xmm6=tmp6
movaps xmm0, XMMWORD [wk(1)] ; xmm0=tmp7
addps xmm2,xmm3 ; xmm2=tmp10
addps xmm3,xmm6 ; xmm3=tmp11
addps xmm6,xmm0 ; xmm6=tmp12, xmm0=tmp7
mulps xmm3,[rel PD_0_707] ; xmm3=z3
movaps xmm1,xmm2 ; xmm1=tmp10
subps xmm2,xmm6
mulps xmm2,[rel PD_0_382] ; xmm2=z5
mulps xmm1,[rel PD_0_541] ; xmm1=MULTIPLY(tmp10,FIX_0_541196)
mulps xmm6,[rel PD_1_306] ; xmm6=MULTIPLY(tmp12,FIX_1_306562)
addps xmm1,xmm2 ; xmm1=z2
addps xmm6,xmm2 ; xmm6=z4
movaps xmm5,xmm0
subps xmm0,xmm3 ; xmm0=z13
addps xmm5,xmm3 ; xmm5=z11
movaps xmm7,xmm0
movaps xmm4,xmm5
subps xmm0,xmm1 ; xmm0=data3
subps xmm5,xmm6 ; xmm5=data7
addps xmm7,xmm1 ; xmm7=data5
addps xmm4,xmm6 ; xmm4=data1
movaps XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_FAST_FLOAT)], xmm0
movaps XMMWORD [XMMBLOCK(3,1,rdx,SIZEOF_FAST_FLOAT)], xmm5
movaps XMMWORD [XMMBLOCK(1,1,rdx,SIZEOF_FAST_FLOAT)], xmm7
movaps XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FAST_FLOAT)], xmm4
add rdx, 4*DCTSIZE*SIZEOF_FAST_FLOAT
dec rcx
jnz near .rowloop
; ---- Pass 2: process columns.
mov rdx, r10 ; (FAST_FLOAT *)
mov rcx, DCTSIZE/4
.columnloop:
movaps xmm0, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_FAST_FLOAT)]
movaps xmm1, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_FAST_FLOAT)]
movaps xmm2, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_FAST_FLOAT)]
movaps xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_FAST_FLOAT)]
; xmm0=(02 12 22 32), xmm2=(42 52 62 72)
; xmm1=(03 13 23 33), xmm3=(43 53 63 73)
movaps xmm4,xmm0 ; transpose coefficients(phase 1)
unpcklps xmm0,xmm1 ; xmm0=(02 03 12 13)
unpckhps xmm4,xmm1 ; xmm4=(22 23 32 33)
movaps xmm5,xmm2 ; transpose coefficients(phase 1)
unpcklps xmm2,xmm3 ; xmm2=(42 43 52 53)
unpckhps xmm5,xmm3 ; xmm5=(62 63 72 73)
movaps xmm6, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FAST_FLOAT)]
movaps xmm7, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FAST_FLOAT)]
movaps xmm1, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_FAST_FLOAT)]
movaps xmm3, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_FAST_FLOAT)]
; xmm6=(00 10 20 30), xmm1=(40 50 60 70)
; xmm7=(01 11 21 31), xmm3=(41 51 61 71)
movaps XMMWORD [wk(0)], xmm4 ; wk(0)=(22 23 32 33)
movaps XMMWORD [wk(1)], xmm2 ; wk(1)=(42 43 52 53)
movaps xmm4,xmm6 ; transpose coefficients(phase 1)
unpcklps xmm6,xmm7 ; xmm6=(00 01 10 11)
unpckhps xmm4,xmm7 ; xmm4=(20 21 30 31)
movaps xmm2,xmm1 ; transpose coefficients(phase 1)
unpcklps xmm1,xmm3 ; xmm1=(40 41 50 51)
unpckhps xmm2,xmm3 ; xmm2=(60 61 70 71)
movaps xmm7,xmm6 ; transpose coefficients(phase 2)
unpcklps2 xmm6,xmm0 ; xmm6=(00 01 02 03)=data0
unpckhps2 xmm7,xmm0 ; xmm7=(10 11 12 13)=data1
movaps xmm3,xmm2 ; transpose coefficients(phase 2)
unpcklps2 xmm2,xmm5 ; xmm2=(60 61 62 63)=data6
unpckhps2 xmm3,xmm5 ; xmm3=(70 71 72 73)=data7
movaps xmm0,xmm7
movaps xmm5,xmm6
subps xmm7,xmm2 ; xmm7=data1-data6=tmp6
subps xmm6,xmm3 ; xmm6=data0-data7=tmp7
addps xmm0,xmm2 ; xmm0=data1+data6=tmp1
addps xmm5,xmm3 ; xmm5=data0+data7=tmp0
movaps xmm2, XMMWORD [wk(0)] ; xmm2=(22 23 32 33)
movaps xmm3, XMMWORD [wk(1)] ; xmm3=(42 43 52 53)
movaps XMMWORD [wk(0)], xmm7 ; wk(0)=tmp6
movaps XMMWORD [wk(1)], xmm6 ; wk(1)=tmp7
movaps xmm7,xmm4 ; transpose coefficients(phase 2)
unpcklps2 xmm4,xmm2 ; xmm4=(20 21 22 23)=data2
unpckhps2 xmm7,xmm2 ; xmm7=(30 31 32 33)=data3
movaps xmm6,xmm1 ; transpose coefficients(phase 2)
unpcklps2 xmm1,xmm3 ; xmm1=(40 41 42 43)=data4
unpckhps2 xmm6,xmm3 ; xmm6=(50 51 52 53)=data5
movaps xmm2,xmm7
movaps xmm3,xmm4
addps xmm7,xmm1 ; xmm7=data3+data4=tmp3
addps xmm4,xmm6 ; xmm4=data2+data5=tmp2
subps xmm2,xmm1 ; xmm2=data3-data4=tmp4
subps xmm3,xmm6 ; xmm3=data2-data5=tmp5
; -- Even part
movaps xmm1,xmm5
movaps xmm6,xmm0
subps xmm5,xmm7 ; xmm5=tmp13
subps xmm0,xmm4 ; xmm0=tmp12
addps xmm1,xmm7 ; xmm1=tmp10
addps xmm6,xmm4 ; xmm6=tmp11
addps xmm0,xmm5
mulps xmm0,[rel PD_0_707] ; xmm0=z1
movaps xmm7,xmm1
movaps xmm4,xmm5
subps xmm1,xmm6 ; xmm1=data4
subps xmm5,xmm0 ; xmm5=data6
addps xmm7,xmm6 ; xmm7=data0
addps xmm4,xmm0 ; xmm4=data2
movaps XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_FAST_FLOAT)], xmm1
movaps XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_FAST_FLOAT)], xmm5
movaps XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FAST_FLOAT)], xmm7
movaps XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_FAST_FLOAT)], xmm4
; -- Odd part
movaps xmm6, XMMWORD [wk(0)] ; xmm6=tmp6
movaps xmm0, XMMWORD [wk(1)] ; xmm0=tmp7
addps xmm2,xmm3 ; xmm2=tmp10
addps xmm3,xmm6 ; xmm3=tmp11
addps xmm6,xmm0 ; xmm6=tmp12, xmm0=tmp7
mulps xmm3,[rel PD_0_707] ; xmm3=z3
movaps xmm1,xmm2 ; xmm1=tmp10
subps xmm2,xmm6
mulps xmm2,[rel PD_0_382] ; xmm2=z5
mulps xmm1,[rel PD_0_541] ; xmm1=MULTIPLY(tmp10,FIX_0_541196)
mulps xmm6,[rel PD_1_306] ; xmm6=MULTIPLY(tmp12,FIX_1_306562)
addps xmm1,xmm2 ; xmm1=z2
addps xmm6,xmm2 ; xmm6=z4
movaps xmm5,xmm0
subps xmm0,xmm3 ; xmm0=z13
addps xmm5,xmm3 ; xmm5=z11
movaps xmm7,xmm0
movaps xmm4,xmm5
subps xmm0,xmm1 ; xmm0=data3
subps xmm5,xmm6 ; xmm5=data7
addps xmm7,xmm1 ; xmm7=data5
addps xmm4,xmm6 ; xmm4=data1
movaps XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_FAST_FLOAT)], xmm0
movaps XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_FAST_FLOAT)], xmm5
movaps XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_FAST_FLOAT)], xmm7
movaps XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FAST_FLOAT)], xmm4
add rdx, byte 4*SIZEOF_FAST_FLOAT
dec rcx
jnz near .columnloop
uncollect_args
mov rsp,rbp ; rsp <- aligned rbp
pop rsp ; rsp <- original rbp
pop rbp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16
@@ -1,392 +0,0 @@
;
; jfdctfst.asm - fast integer FDCT (64-bit SSE2)
;
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2009 D. R. Commander
;
; Based on
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; This file contains a fast, not so accurate integer implementation of
; the forward DCT (Discrete Cosine Transform). The following code is
; based directly on the IJG's original jfdctfst.c; see the jfdctfst.c
; for more details.
;
; [TAB8]
%include "jsimdext.inc"
%include "jdct.inc"
; --------------------------------------------------------------------------
%define CONST_BITS 8 ; 14 is also OK.
%if CONST_BITS == 8
F_0_382 equ 98 ; FIX(0.382683433)
F_0_541 equ 139 ; FIX(0.541196100)
F_0_707 equ 181 ; FIX(0.707106781)
F_1_306 equ 334 ; FIX(1.306562965)
%else
; NASM cannot do compile-time arithmetic on floating-point constants.
%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n))
F_0_382 equ DESCALE( 410903207,30-CONST_BITS) ; FIX(0.382683433)
F_0_541 equ DESCALE( 581104887,30-CONST_BITS) ; FIX(0.541196100)
F_0_707 equ DESCALE( 759250124,30-CONST_BITS) ; FIX(0.707106781)
F_1_306 equ DESCALE(1402911301,30-CONST_BITS) ; FIX(1.306562965)
%endif
; --------------------------------------------------------------------------
SECTION SEG_CONST
; PRE_MULTIPLY_SCALE_BITS <= 2 (to avoid overflow)
; CONST_BITS + CONST_SHIFT + PRE_MULTIPLY_SCALE_BITS == 16 (for pmulhw)
%define PRE_MULTIPLY_SCALE_BITS 2
%define CONST_SHIFT (16 - PRE_MULTIPLY_SCALE_BITS - CONST_BITS)
alignz 16
global EXTN(jconst_fdct_ifast_sse2)
EXTN(jconst_fdct_ifast_sse2):
PW_F0707 times 8 dw F_0_707 << CONST_SHIFT
PW_F0382 times 8 dw F_0_382 << CONST_SHIFT
PW_F0541 times 8 dw F_0_541 << CONST_SHIFT
PW_F1306 times 8 dw F_1_306 << CONST_SHIFT
alignz 16
; --------------------------------------------------------------------------
SECTION SEG_TEXT
BITS 64
;
; Perform the forward DCT on one block of samples.
;
; GLOBAL(void)
; jsimd_fdct_ifast_sse2 (DCTELEM * data)
;
; r10 = DCTELEM * data
%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 2
align 16
global EXTN(jsimd_fdct_ifast_sse2)
EXTN(jsimd_fdct_ifast_sse2):
push rbp
mov rax,rsp ; rax = original rbp
sub rsp, byte 4
and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [rsp],rax
mov rbp,rsp ; rbp = aligned rbp
lea rsp, [wk(0)]
collect_args
; ---- Pass 1: process rows.
mov rdx, r10 ; (DCTELEM *)
movdqa xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_DCTELEM)]
movdqa xmm1, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_DCTELEM)]
movdqa xmm2, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_DCTELEM)]
movdqa xmm3, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_DCTELEM)]
; xmm0=(00 01 02 03 04 05 06 07), xmm2=(20 21 22 23 24 25 26 27)
; xmm1=(10 11 12 13 14 15 16 17), xmm3=(30 31 32 33 34 35 36 37)
movdqa xmm4,xmm0 ; transpose coefficients(phase 1)
punpcklwd xmm0,xmm1 ; xmm0=(00 10 01 11 02 12 03 13)
punpckhwd xmm4,xmm1 ; xmm4=(04 14 05 15 06 16 07 17)
movdqa xmm5,xmm2 ; transpose coefficients(phase 1)
punpcklwd xmm2,xmm3 ; xmm2=(20 30 21 31 22 32 23 33)
punpckhwd xmm5,xmm3 ; xmm5=(24 34 25 35 26 36 27 37)
movdqa xmm6, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_DCTELEM)]
movdqa xmm7, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_DCTELEM)]
movdqa xmm1, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_DCTELEM)]
movdqa xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_DCTELEM)]
; xmm6=( 4 12 20 28 36 44 52 60), xmm1=( 6 14 22 30 38 46 54 62)
; xmm7=( 5 13 21 29 37 45 53 61), xmm3=( 7 15 23 31 39 47 55 63)
movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=(20 30 21 31 22 32 23 33)
movdqa XMMWORD [wk(1)], xmm5 ; wk(1)=(24 34 25 35 26 36 27 37)
movdqa xmm2,xmm6 ; transpose coefficients(phase 1)
punpcklwd xmm6,xmm7 ; xmm6=(40 50 41 51 42 52 43 53)
punpckhwd xmm2,xmm7 ; xmm2=(44 54 45 55 46 56 47 57)
movdqa xmm5,xmm1 ; transpose coefficients(phase 1)
punpcklwd xmm1,xmm3 ; xmm1=(60 70 61 71 62 72 63 73)
punpckhwd xmm5,xmm3 ; xmm5=(64 74 65 75 66 76 67 77)
movdqa xmm7,xmm6 ; transpose coefficients(phase 2)
punpckldq xmm6,xmm1 ; xmm6=(40 50 60 70 41 51 61 71)
punpckhdq xmm7,xmm1 ; xmm7=(42 52 62 72 43 53 63 73)
movdqa xmm3,xmm2 ; transpose coefficients(phase 2)
punpckldq xmm2,xmm5 ; xmm2=(44 54 64 74 45 55 65 75)
punpckhdq xmm3,xmm5 ; xmm3=(46 56 66 76 47 57 67 77)
movdqa xmm1, XMMWORD [wk(0)] ; xmm1=(20 30 21 31 22 32 23 33)
movdqa xmm5, XMMWORD [wk(1)] ; xmm5=(24 34 25 35 26 36 27 37)
movdqa XMMWORD [wk(0)], xmm7 ; wk(0)=(42 52 62 72 43 53 63 73)
movdqa XMMWORD [wk(1)], xmm2 ; wk(1)=(44 54 64 74 45 55 65 75)
movdqa xmm7,xmm0 ; transpose coefficients(phase 2)
punpckldq xmm0,xmm1 ; xmm0=(00 10 20 30 01 11 21 31)
punpckhdq xmm7,xmm1 ; xmm7=(02 12 22 32 03 13 23 33)
movdqa xmm2,xmm4 ; transpose coefficients(phase 2)
punpckldq xmm4,xmm5 ; xmm4=(04 14 24 34 05 15 25 35)
punpckhdq xmm2,xmm5 ; xmm2=(06 16 26 36 07 17 27 37)
movdqa xmm1,xmm0 ; transpose coefficients(phase 3)
punpcklqdq xmm0,xmm6 ; xmm0=(00 10 20 30 40 50 60 70)=data0
punpckhqdq xmm1,xmm6 ; xmm1=(01 11 21 31 41 51 61 71)=data1
movdqa xmm5,xmm2 ; transpose coefficients(phase 3)
punpcklqdq xmm2,xmm3 ; xmm2=(06 16 26 36 46 56 66 76)=data6
punpckhqdq xmm5,xmm3 ; xmm5=(07 17 27 37 47 57 67 77)=data7
movdqa xmm6,xmm1
movdqa xmm3,xmm0
psubw xmm1,xmm2 ; xmm1=data1-data6=tmp6
psubw xmm0,xmm5 ; xmm0=data0-data7=tmp7
paddw xmm6,xmm2 ; xmm6=data1+data6=tmp1
paddw xmm3,xmm5 ; xmm3=data0+data7=tmp0
movdqa xmm2, XMMWORD [wk(0)] ; xmm2=(42 52 62 72 43 53 63 73)
movdqa xmm5, XMMWORD [wk(1)] ; xmm5=(44 54 64 74 45 55 65 75)
movdqa XMMWORD [wk(0)], xmm1 ; wk(0)=tmp6
movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=tmp7
movdqa xmm1,xmm7 ; transpose coefficients(phase 3)
punpcklqdq xmm7,xmm2 ; xmm7=(02 12 22 32 42 52 62 72)=data2
punpckhqdq xmm1,xmm2 ; xmm1=(03 13 23 33 43 53 63 73)=data3
movdqa xmm0,xmm4 ; transpose coefficients(phase 3)
punpcklqdq xmm4,xmm5 ; xmm4=(04 14 24 34 44 54 64 74)=data4
punpckhqdq xmm0,xmm5 ; xmm0=(05 15 25 35 45 55 65 75)=data5
movdqa xmm2,xmm1
movdqa xmm5,xmm7
paddw xmm1,xmm4 ; xmm1=data3+data4=tmp3
paddw xmm7,xmm0 ; xmm7=data2+data5=tmp2
psubw xmm2,xmm4 ; xmm2=data3-data4=tmp4
psubw xmm5,xmm0 ; xmm5=data2-data5=tmp5
; -- Even part
movdqa xmm4,xmm3
movdqa xmm0,xmm6
psubw xmm3,xmm1 ; xmm3=tmp13
psubw xmm6,xmm7 ; xmm6=tmp12
paddw xmm4,xmm1 ; xmm4=tmp10
paddw xmm0,xmm7 ; xmm0=tmp11
paddw xmm6,xmm3
psllw xmm6,PRE_MULTIPLY_SCALE_BITS
pmulhw xmm6,[rel PW_F0707] ; xmm6=z1
movdqa xmm1,xmm4
movdqa xmm7,xmm3
psubw xmm4,xmm0 ; xmm4=data4
psubw xmm3,xmm6 ; xmm3=data6
paddw xmm1,xmm0 ; xmm1=data0
paddw xmm7,xmm6 ; xmm7=data2
movdqa xmm0, XMMWORD [wk(0)] ; xmm0=tmp6
movdqa xmm6, XMMWORD [wk(1)] ; xmm6=tmp7
movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=data4
movdqa XMMWORD [wk(1)], xmm3 ; wk(1)=data6
; -- Odd part
paddw xmm2,xmm5 ; xmm2=tmp10
paddw xmm5,xmm0 ; xmm5=tmp11
paddw xmm0,xmm6 ; xmm0=tmp12, xmm6=tmp7
psllw xmm2,PRE_MULTIPLY_SCALE_BITS
psllw xmm0,PRE_MULTIPLY_SCALE_BITS
psllw xmm5,PRE_MULTIPLY_SCALE_BITS
pmulhw xmm5,[rel PW_F0707] ; xmm5=z3
movdqa xmm4,xmm2 ; xmm4=tmp10
psubw xmm2,xmm0
pmulhw xmm2,[rel PW_F0382] ; xmm2=z5
pmulhw xmm4,[rel PW_F0541] ; xmm4=MULTIPLY(tmp10,FIX_0_541196)
pmulhw xmm0,[rel PW_F1306] ; xmm0=MULTIPLY(tmp12,FIX_1_306562)
paddw xmm4,xmm2 ; xmm4=z2
paddw xmm0,xmm2 ; xmm0=z4
movdqa xmm3,xmm6
psubw xmm6,xmm5 ; xmm6=z13
paddw xmm3,xmm5 ; xmm3=z11
movdqa xmm2,xmm6
movdqa xmm5,xmm3
psubw xmm6,xmm4 ; xmm6=data3
psubw xmm3,xmm0 ; xmm3=data7
paddw xmm2,xmm4 ; xmm2=data5
paddw xmm5,xmm0 ; xmm5=data1
; ---- Pass 2: process columns.
; xmm1=(00 10 20 30 40 50 60 70), xmm7=(02 12 22 32 42 52 62 72)
; xmm5=(01 11 21 31 41 51 61 71), xmm6=(03 13 23 33 43 53 63 73)
movdqa xmm4,xmm1 ; transpose coefficients(phase 1)
punpcklwd xmm1,xmm5 ; xmm1=(00 01 10 11 20 21 30 31)
punpckhwd xmm4,xmm5 ; xmm4=(40 41 50 51 60 61 70 71)
movdqa xmm0,xmm7 ; transpose coefficients(phase 1)
punpcklwd xmm7,xmm6 ; xmm7=(02 03 12 13 22 23 32 33)
punpckhwd xmm0,xmm6 ; xmm0=(42 43 52 53 62 63 72 73)
movdqa xmm5, XMMWORD [wk(0)] ; xmm5=col4
movdqa xmm6, XMMWORD [wk(1)] ; xmm6=col6
; xmm5=(04 14 24 34 44 54 64 74), xmm6=(06 16 26 36 46 56 66 76)
; xmm2=(05 15 25 35 45 55 65 75), xmm3=(07 17 27 37 47 57 67 77)
movdqa XMMWORD [wk(0)], xmm7 ; wk(0)=(02 03 12 13 22 23 32 33)
movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=(42 43 52 53 62 63 72 73)
movdqa xmm7,xmm5 ; transpose coefficients(phase 1)
punpcklwd xmm5,xmm2 ; xmm5=(04 05 14 15 24 25 34 35)
punpckhwd xmm7,xmm2 ; xmm7=(44 45 54 55 64 65 74 75)
movdqa xmm0,xmm6 ; transpose coefficients(phase 1)
punpcklwd xmm6,xmm3 ; xmm6=(06 07 16 17 26 27 36 37)
punpckhwd xmm0,xmm3 ; xmm0=(46 47 56 57 66 67 76 77)
movdqa xmm2,xmm5 ; transpose coefficients(phase 2)
punpckldq xmm5,xmm6 ; xmm5=(04 05 06 07 14 15 16 17)
punpckhdq xmm2,xmm6 ; xmm2=(24 25 26 27 34 35 36 37)
movdqa xmm3,xmm7 ; transpose coefficients(phase 2)
punpckldq xmm7,xmm0 ; xmm7=(44 45 46 47 54 55 56 57)
punpckhdq xmm3,xmm0 ; xmm3=(64 65 66 67 74 75 76 77)
movdqa xmm6, XMMWORD [wk(0)] ; xmm6=(02 03 12 13 22 23 32 33)
movdqa xmm0, XMMWORD [wk(1)] ; xmm0=(42 43 52 53 62 63 72 73)
movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=(24 25 26 27 34 35 36 37)
movdqa XMMWORD [wk(1)], xmm7 ; wk(1)=(44 45 46 47 54 55 56 57)
movdqa xmm2,xmm1 ; transpose coefficients(phase 2)
punpckldq xmm1,xmm6 ; xmm1=(00 01 02 03 10 11 12 13)
punpckhdq xmm2,xmm6 ; xmm2=(20 21 22 23 30 31 32 33)
movdqa xmm7,xmm4 ; transpose coefficients(phase 2)
punpckldq xmm4,xmm0 ; xmm4=(40 41 42 43 50 51 52 53)
punpckhdq xmm7,xmm0 ; xmm7=(60 61 62 63 70 71 72 73)
movdqa xmm6,xmm1 ; transpose coefficients(phase 3)
punpcklqdq xmm1,xmm5 ; xmm1=(00 01 02 03 04 05 06 07)=data0
punpckhqdq xmm6,xmm5 ; xmm6=(10 11 12 13 14 15 16 17)=data1
movdqa xmm0,xmm7 ; transpose coefficients(phase 3)
punpcklqdq xmm7,xmm3 ; xmm7=(60 61 62 63 64 65 66 67)=data6
punpckhqdq xmm0,xmm3 ; xmm0=(70 71 72 73 74 75 76 77)=data7
movdqa xmm5,xmm6
movdqa xmm3,xmm1
psubw xmm6,xmm7 ; xmm6=data1-data6=tmp6
psubw xmm1,xmm0 ; xmm1=data0-data7=tmp7
paddw xmm5,xmm7 ; xmm5=data1+data6=tmp1
paddw xmm3,xmm0 ; xmm3=data0+data7=tmp0
movdqa xmm7, XMMWORD [wk(0)] ; xmm7=(24 25 26 27 34 35 36 37)
movdqa xmm0, XMMWORD [wk(1)] ; xmm0=(44 45 46 47 54 55 56 57)
movdqa XMMWORD [wk(0)], xmm6 ; wk(0)=tmp6
movdqa XMMWORD [wk(1)], xmm1 ; wk(1)=tmp7
movdqa xmm6,xmm2 ; transpose coefficients(phase 3)
punpcklqdq xmm2,xmm7 ; xmm2=(20 21 22 23 24 25 26 27)=data2
punpckhqdq xmm6,xmm7 ; xmm6=(30 31 32 33 34 35 36 37)=data3
movdqa xmm1,xmm4 ; transpose coefficients(phase 3)
punpcklqdq xmm4,xmm0 ; xmm4=(40 41 42 43 44 45 46 47)=data4
punpckhqdq xmm1,xmm0 ; xmm1=(50 51 52 53 54 55 56 57)=data5
movdqa xmm7,xmm6
movdqa xmm0,xmm2
paddw xmm6,xmm4 ; xmm6=data3+data4=tmp3
paddw xmm2,xmm1 ; xmm2=data2+data5=tmp2
psubw xmm7,xmm4 ; xmm7=data3-data4=tmp4
psubw xmm0,xmm1 ; xmm0=data2-data5=tmp5
; -- Even part
movdqa xmm4,xmm3
movdqa xmm1,xmm5
psubw xmm3,xmm6 ; xmm3=tmp13
psubw xmm5,xmm2 ; xmm5=tmp12
paddw xmm4,xmm6 ; xmm4=tmp10
paddw xmm1,xmm2 ; xmm1=tmp11
paddw xmm5,xmm3
psllw xmm5,PRE_MULTIPLY_SCALE_BITS
pmulhw xmm5,[rel PW_F0707] ; xmm5=z1
movdqa xmm6,xmm4
movdqa xmm2,xmm3
psubw xmm4,xmm1 ; xmm4=data4
psubw xmm3,xmm5 ; xmm3=data6
paddw xmm6,xmm1 ; xmm6=data0
paddw xmm2,xmm5 ; xmm2=data2
movdqa XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_DCTELEM)], xmm4
movdqa XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_DCTELEM)], xmm3
movdqa XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_DCTELEM)], xmm6
movdqa XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_DCTELEM)], xmm2
; -- Odd part
movdqa xmm1, XMMWORD [wk(0)] ; xmm1=tmp6
movdqa xmm5, XMMWORD [wk(1)] ; xmm5=tmp7
paddw xmm7,xmm0 ; xmm7=tmp10
paddw xmm0,xmm1 ; xmm0=tmp11
paddw xmm1,xmm5 ; xmm1=tmp12, xmm5=tmp7
psllw xmm7,PRE_MULTIPLY_SCALE_BITS
psllw xmm1,PRE_MULTIPLY_SCALE_BITS
psllw xmm0,PRE_MULTIPLY_SCALE_BITS
pmulhw xmm0,[rel PW_F0707] ; xmm0=z3
movdqa xmm4,xmm7 ; xmm4=tmp10
psubw xmm7,xmm1
pmulhw xmm7,[rel PW_F0382] ; xmm7=z5
pmulhw xmm4,[rel PW_F0541] ; xmm4=MULTIPLY(tmp10,FIX_0_541196)
pmulhw xmm1,[rel PW_F1306] ; xmm1=MULTIPLY(tmp12,FIX_1_306562)
paddw xmm4,xmm7 ; xmm4=z2
paddw xmm1,xmm7 ; xmm1=z4
movdqa xmm3,xmm5
psubw xmm5,xmm0 ; xmm5=z13
paddw xmm3,xmm0 ; xmm3=z11
movdqa xmm6,xmm5
movdqa xmm2,xmm3
psubw xmm5,xmm4 ; xmm5=data3
psubw xmm3,xmm1 ; xmm3=data7
paddw xmm6,xmm4 ; xmm6=data5
paddw xmm2,xmm1 ; xmm2=data1
movdqa XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_DCTELEM)], xmm5
movdqa XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_DCTELEM)], xmm3
movdqa XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_DCTELEM)], xmm6
movdqa XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_DCTELEM)], xmm2
uncollect_args
mov rsp,rbp ; rsp <- aligned rbp
pop rsp ; rsp <- original rbp
pop rbp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16
@@ -1,622 +0,0 @@
;
; jfdctint.asm - accurate integer FDCT (64-bit SSE2)
;
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2009 D. R. Commander
;
; Based on
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; This file contains a slow-but-accurate integer implementation of the
; forward DCT (Discrete Cosine Transform). The following code is based
; directly on the IJG's original jfdctint.c; see the jfdctint.c for
; more details.
;
; [TAB8]
%include "jsimdext.inc"
%include "jdct.inc"
; --------------------------------------------------------------------------
%define CONST_BITS 13
%define PASS1_BITS 2
%define DESCALE_P1 (CONST_BITS-PASS1_BITS)
%define DESCALE_P2 (CONST_BITS+PASS1_BITS)
%if CONST_BITS == 13
F_0_298 equ 2446 ; FIX(0.298631336)
F_0_390 equ 3196 ; FIX(0.390180644)
F_0_541 equ 4433 ; FIX(0.541196100)
F_0_765 equ 6270 ; FIX(0.765366865)
F_0_899 equ 7373 ; FIX(0.899976223)
F_1_175 equ 9633 ; FIX(1.175875602)
F_1_501 equ 12299 ; FIX(1.501321110)
F_1_847 equ 15137 ; FIX(1.847759065)
F_1_961 equ 16069 ; FIX(1.961570560)
F_2_053 equ 16819 ; FIX(2.053119869)
F_2_562 equ 20995 ; FIX(2.562915447)
F_3_072 equ 25172 ; FIX(3.072711026)
%else
; NASM cannot do compile-time arithmetic on floating-point constants.
%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n))
F_0_298 equ DESCALE( 320652955,30-CONST_BITS) ; FIX(0.298631336)
F_0_390 equ DESCALE( 418953276,30-CONST_BITS) ; FIX(0.390180644)
F_0_541 equ DESCALE( 581104887,30-CONST_BITS) ; FIX(0.541196100)
F_0_765 equ DESCALE( 821806413,30-CONST_BITS) ; FIX(0.765366865)
F_0_899 equ DESCALE( 966342111,30-CONST_BITS) ; FIX(0.899976223)
F_1_175 equ DESCALE(1262586813,30-CONST_BITS) ; FIX(1.175875602)
F_1_501 equ DESCALE(1612031267,30-CONST_BITS) ; FIX(1.501321110)
F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065)
F_1_961 equ DESCALE(2106220350,30-CONST_BITS) ; FIX(1.961570560)
F_2_053 equ DESCALE(2204520673,30-CONST_BITS) ; FIX(2.053119869)
F_2_562 equ DESCALE(2751909506,30-CONST_BITS) ; FIX(2.562915447)
F_3_072 equ DESCALE(3299298341,30-CONST_BITS) ; FIX(3.072711026)
%endif
; --------------------------------------------------------------------------
SECTION SEG_CONST
alignz 16
global EXTN(jconst_fdct_islow_sse2)
EXTN(jconst_fdct_islow_sse2):
PW_F130_F054 times 4 dw (F_0_541+F_0_765), F_0_541
PW_F054_MF130 times 4 dw F_0_541, (F_0_541-F_1_847)
PW_MF078_F117 times 4 dw (F_1_175-F_1_961), F_1_175
PW_F117_F078 times 4 dw F_1_175, (F_1_175-F_0_390)
PW_MF060_MF089 times 4 dw (F_0_298-F_0_899),-F_0_899
PW_MF089_F060 times 4 dw -F_0_899, (F_1_501-F_0_899)
PW_MF050_MF256 times 4 dw (F_2_053-F_2_562),-F_2_562
PW_MF256_F050 times 4 dw -F_2_562, (F_3_072-F_2_562)
PD_DESCALE_P1 times 4 dd 1 << (DESCALE_P1-1)
PD_DESCALE_P2 times 4 dd 1 << (DESCALE_P2-1)
PW_DESCALE_P2X times 8 dw 1 << (PASS1_BITS-1)
alignz 16
; --------------------------------------------------------------------------
SECTION SEG_TEXT
BITS 64
;
; Perform the forward DCT on one block of samples.
;
; GLOBAL(void)
; jsimd_fdct_islow_sse2 (DCTELEM * data)
;
; r10 = DCTELEM * data
%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 6
align 16
global EXTN(jsimd_fdct_islow_sse2)
EXTN(jsimd_fdct_islow_sse2):
push rbp
mov rax,rsp ; rax = original rbp
sub rsp, byte 4
and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [rsp],rax
mov rbp,rsp ; rbp = aligned rbp
lea rsp, [wk(0)]
collect_args
; ---- Pass 1: process rows.
mov rdx, r10 ; (DCTELEM *)
movdqa xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_DCTELEM)]
movdqa xmm1, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_DCTELEM)]
movdqa xmm2, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_DCTELEM)]
movdqa xmm3, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_DCTELEM)]
; xmm0=(00 01 02 03 04 05 06 07), xmm2=(20 21 22 23 24 25 26 27)
; xmm1=(10 11 12 13 14 15 16 17), xmm3=(30 31 32 33 34 35 36 37)
movdqa xmm4,xmm0 ; transpose coefficients(phase 1)
punpcklwd xmm0,xmm1 ; xmm0=(00 10 01 11 02 12 03 13)
punpckhwd xmm4,xmm1 ; xmm4=(04 14 05 15 06 16 07 17)
movdqa xmm5,xmm2 ; transpose coefficients(phase 1)
punpcklwd xmm2,xmm3 ; xmm2=(20 30 21 31 22 32 23 33)
punpckhwd xmm5,xmm3 ; xmm5=(24 34 25 35 26 36 27 37)
movdqa xmm6, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_DCTELEM)]
movdqa xmm7, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_DCTELEM)]
movdqa xmm1, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_DCTELEM)]
movdqa xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_DCTELEM)]
; xmm6=( 4 12 20 28 36 44 52 60), xmm1=( 6 14 22 30 38 46 54 62)
; xmm7=( 5 13 21 29 37 45 53 61), xmm3=( 7 15 23 31 39 47 55 63)
movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=(20 30 21 31 22 32 23 33)
movdqa XMMWORD [wk(1)], xmm5 ; wk(1)=(24 34 25 35 26 36 27 37)
movdqa xmm2,xmm6 ; transpose coefficients(phase 1)
punpcklwd xmm6,xmm7 ; xmm6=(40 50 41 51 42 52 43 53)
punpckhwd xmm2,xmm7 ; xmm2=(44 54 45 55 46 56 47 57)
movdqa xmm5,xmm1 ; transpose coefficients(phase 1)
punpcklwd xmm1,xmm3 ; xmm1=(60 70 61 71 62 72 63 73)
punpckhwd xmm5,xmm3 ; xmm5=(64 74 65 75 66 76 67 77)
movdqa xmm7,xmm6 ; transpose coefficients(phase 2)
punpckldq xmm6,xmm1 ; xmm6=(40 50 60 70 41 51 61 71)
punpckhdq xmm7,xmm1 ; xmm7=(42 52 62 72 43 53 63 73)
movdqa xmm3,xmm2 ; transpose coefficients(phase 2)
punpckldq xmm2,xmm5 ; xmm2=(44 54 64 74 45 55 65 75)
punpckhdq xmm3,xmm5 ; xmm3=(46 56 66 76 47 57 67 77)
movdqa xmm1, XMMWORD [wk(0)] ; xmm1=(20 30 21 31 22 32 23 33)
movdqa xmm5, XMMWORD [wk(1)] ; xmm5=(24 34 25 35 26 36 27 37)
movdqa XMMWORD [wk(2)], xmm7 ; wk(2)=(42 52 62 72 43 53 63 73)
movdqa XMMWORD [wk(3)], xmm2 ; wk(3)=(44 54 64 74 45 55 65 75)
movdqa xmm7,xmm0 ; transpose coefficients(phase 2)
punpckldq xmm0,xmm1 ; xmm0=(00 10 20 30 01 11 21 31)
punpckhdq xmm7,xmm1 ; xmm7=(02 12 22 32 03 13 23 33)
movdqa xmm2,xmm4 ; transpose coefficients(phase 2)
punpckldq xmm4,xmm5 ; xmm4=(04 14 24 34 05 15 25 35)
punpckhdq xmm2,xmm5 ; xmm2=(06 16 26 36 07 17 27 37)
movdqa xmm1,xmm0 ; transpose coefficients(phase 3)
punpcklqdq xmm0,xmm6 ; xmm0=(00 10 20 30 40 50 60 70)=data0
punpckhqdq xmm1,xmm6 ; xmm1=(01 11 21 31 41 51 61 71)=data1
movdqa xmm5,xmm2 ; transpose coefficients(phase 3)
punpcklqdq xmm2,xmm3 ; xmm2=(06 16 26 36 46 56 66 76)=data6
punpckhqdq xmm5,xmm3 ; xmm5=(07 17 27 37 47 57 67 77)=data7
movdqa xmm6,xmm1
movdqa xmm3,xmm0
psubw xmm1,xmm2 ; xmm1=data1-data6=tmp6
psubw xmm0,xmm5 ; xmm0=data0-data7=tmp7
paddw xmm6,xmm2 ; xmm6=data1+data6=tmp1
paddw xmm3,xmm5 ; xmm3=data0+data7=tmp0
movdqa xmm2, XMMWORD [wk(2)] ; xmm2=(42 52 62 72 43 53 63 73)
movdqa xmm5, XMMWORD [wk(3)] ; xmm5=(44 54 64 74 45 55 65 75)
movdqa XMMWORD [wk(0)], xmm1 ; wk(0)=tmp6
movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=tmp7
movdqa xmm1,xmm7 ; transpose coefficients(phase 3)
punpcklqdq xmm7,xmm2 ; xmm7=(02 12 22 32 42 52 62 72)=data2
punpckhqdq xmm1,xmm2 ; xmm1=(03 13 23 33 43 53 63 73)=data3
movdqa xmm0,xmm4 ; transpose coefficients(phase 3)
punpcklqdq xmm4,xmm5 ; xmm4=(04 14 24 34 44 54 64 74)=data4
punpckhqdq xmm0,xmm5 ; xmm0=(05 15 25 35 45 55 65 75)=data5
movdqa xmm2,xmm1
movdqa xmm5,xmm7
paddw xmm1,xmm4 ; xmm1=data3+data4=tmp3
paddw xmm7,xmm0 ; xmm7=data2+data5=tmp2
psubw xmm2,xmm4 ; xmm2=data3-data4=tmp4
psubw xmm5,xmm0 ; xmm5=data2-data5=tmp5
; -- Even part
movdqa xmm4,xmm3
movdqa xmm0,xmm6
paddw xmm3,xmm1 ; xmm3=tmp10
paddw xmm6,xmm7 ; xmm6=tmp11
psubw xmm4,xmm1 ; xmm4=tmp13
psubw xmm0,xmm7 ; xmm0=tmp12
movdqa xmm1,xmm3
paddw xmm3,xmm6 ; xmm3=tmp10+tmp11
psubw xmm1,xmm6 ; xmm1=tmp10-tmp11
psllw xmm3,PASS1_BITS ; xmm3=data0
psllw xmm1,PASS1_BITS ; xmm1=data4
movdqa XMMWORD [wk(2)], xmm3 ; wk(2)=data0
movdqa XMMWORD [wk(3)], xmm1 ; wk(3)=data4
; (Original)
; z1 = (tmp12 + tmp13) * 0.541196100;
; data2 = z1 + tmp13 * 0.765366865;
; data6 = z1 + tmp12 * -1.847759065;
;
; (This implementation)
; data2 = tmp13 * (0.541196100 + 0.765366865) + tmp12 * 0.541196100;
; data6 = tmp13 * 0.541196100 + tmp12 * (0.541196100 - 1.847759065);
movdqa xmm7,xmm4 ; xmm4=tmp13
movdqa xmm6,xmm4
punpcklwd xmm7,xmm0 ; xmm0=tmp12
punpckhwd xmm6,xmm0
movdqa xmm4,xmm7
movdqa xmm0,xmm6
pmaddwd xmm7,[rel PW_F130_F054] ; xmm7=data2L
pmaddwd xmm6,[rel PW_F130_F054] ; xmm6=data2H
pmaddwd xmm4,[rel PW_F054_MF130] ; xmm4=data6L
pmaddwd xmm0,[rel PW_F054_MF130] ; xmm0=data6H
paddd xmm7,[rel PD_DESCALE_P1]
paddd xmm6,[rel PD_DESCALE_P1]
psrad xmm7,DESCALE_P1
psrad xmm6,DESCALE_P1
paddd xmm4,[rel PD_DESCALE_P1]
paddd xmm0,[rel PD_DESCALE_P1]
psrad xmm4,DESCALE_P1
psrad xmm0,DESCALE_P1
packssdw xmm7,xmm6 ; xmm7=data2
packssdw xmm4,xmm0 ; xmm4=data6
movdqa XMMWORD [wk(4)], xmm7 ; wk(4)=data2
movdqa XMMWORD [wk(5)], xmm4 ; wk(5)=data6
; -- Odd part
movdqa xmm3, XMMWORD [wk(0)] ; xmm3=tmp6
movdqa xmm1, XMMWORD [wk(1)] ; xmm1=tmp7
movdqa xmm6,xmm2 ; xmm2=tmp4
movdqa xmm0,xmm5 ; xmm5=tmp5
paddw xmm6,xmm3 ; xmm6=z3
paddw xmm0,xmm1 ; xmm0=z4
; (Original)
; z5 = (z3 + z4) * 1.175875602;
; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644;
; z3 += z5; z4 += z5;
;
; (This implementation)
; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
movdqa xmm7,xmm6
movdqa xmm4,xmm6
punpcklwd xmm7,xmm0
punpckhwd xmm4,xmm0
movdqa xmm6,xmm7
movdqa xmm0,xmm4
pmaddwd xmm7,[rel PW_MF078_F117] ; xmm7=z3L
pmaddwd xmm4,[rel PW_MF078_F117] ; xmm4=z3H
pmaddwd xmm6,[rel PW_F117_F078] ; xmm6=z4L
pmaddwd xmm0,[rel PW_F117_F078] ; xmm0=z4H
movdqa XMMWORD [wk(0)], xmm7 ; wk(0)=z3L
movdqa XMMWORD [wk(1)], xmm4 ; wk(1)=z3H
; (Original)
; z1 = tmp4 + tmp7; z2 = tmp5 + tmp6;
; tmp4 = tmp4 * 0.298631336; tmp5 = tmp5 * 2.053119869;
; tmp6 = tmp6 * 3.072711026; tmp7 = tmp7 * 1.501321110;
; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447;
; data7 = tmp4 + z1 + z3; data5 = tmp5 + z2 + z4;
; data3 = tmp6 + z2 + z3; data1 = tmp7 + z1 + z4;
;
; (This implementation)
; tmp4 = tmp4 * (0.298631336 - 0.899976223) + tmp7 * -0.899976223;
; tmp5 = tmp5 * (2.053119869 - 2.562915447) + tmp6 * -2.562915447;
; tmp6 = tmp5 * -2.562915447 + tmp6 * (3.072711026 - 2.562915447);
; tmp7 = tmp4 * -0.899976223 + tmp7 * (1.501321110 - 0.899976223);
; data7 = tmp4 + z3; data5 = tmp5 + z4;
; data3 = tmp6 + z3; data1 = tmp7 + z4;
movdqa xmm7,xmm2
movdqa xmm4,xmm2
punpcklwd xmm7,xmm1
punpckhwd xmm4,xmm1
movdqa xmm2,xmm7
movdqa xmm1,xmm4
pmaddwd xmm7,[rel PW_MF060_MF089] ; xmm7=tmp4L
pmaddwd xmm4,[rel PW_MF060_MF089] ; xmm4=tmp4H
pmaddwd xmm2,[rel PW_MF089_F060] ; xmm2=tmp7L
pmaddwd xmm1,[rel PW_MF089_F060] ; xmm1=tmp7H
paddd xmm7, XMMWORD [wk(0)] ; xmm7=data7L
paddd xmm4, XMMWORD [wk(1)] ; xmm4=data7H
paddd xmm2,xmm6 ; xmm2=data1L
paddd xmm1,xmm0 ; xmm1=data1H
paddd xmm7,[rel PD_DESCALE_P1]
paddd xmm4,[rel PD_DESCALE_P1]
psrad xmm7,DESCALE_P1
psrad xmm4,DESCALE_P1
paddd xmm2,[rel PD_DESCALE_P1]
paddd xmm1,[rel PD_DESCALE_P1]
psrad xmm2,DESCALE_P1
psrad xmm1,DESCALE_P1
packssdw xmm7,xmm4 ; xmm7=data7
packssdw xmm2,xmm1 ; xmm2=data1
movdqa xmm4,xmm5
movdqa xmm1,xmm5
punpcklwd xmm4,xmm3
punpckhwd xmm1,xmm3
movdqa xmm5,xmm4
movdqa xmm3,xmm1
pmaddwd xmm4,[rel PW_MF050_MF256] ; xmm4=tmp5L
pmaddwd xmm1,[rel PW_MF050_MF256] ; xmm1=tmp5H
pmaddwd xmm5,[rel PW_MF256_F050] ; xmm5=tmp6L
pmaddwd xmm3,[rel PW_MF256_F050] ; xmm3=tmp6H
paddd xmm4,xmm6 ; xmm4=data5L
paddd xmm1,xmm0 ; xmm1=data5H
paddd xmm5, XMMWORD [wk(0)] ; xmm5=data3L
paddd xmm3, XMMWORD [wk(1)] ; xmm3=data3H
paddd xmm4,[rel PD_DESCALE_P1]
paddd xmm1,[rel PD_DESCALE_P1]
psrad xmm4,DESCALE_P1
psrad xmm1,DESCALE_P1
paddd xmm5,[rel PD_DESCALE_P1]
paddd xmm3,[rel PD_DESCALE_P1]
psrad xmm5,DESCALE_P1
psrad xmm3,DESCALE_P1
packssdw xmm4,xmm1 ; xmm4=data5
packssdw xmm5,xmm3 ; xmm5=data3
; ---- Pass 2: process columns.
movdqa xmm6, XMMWORD [wk(2)] ; xmm6=col0
movdqa xmm0, XMMWORD [wk(4)] ; xmm0=col2
; xmm6=(00 10 20 30 40 50 60 70), xmm0=(02 12 22 32 42 52 62 72)
; xmm2=(01 11 21 31 41 51 61 71), xmm5=(03 13 23 33 43 53 63 73)
movdqa xmm1,xmm6 ; transpose coefficients(phase 1)
punpcklwd xmm6,xmm2 ; xmm6=(00 01 10 11 20 21 30 31)
punpckhwd xmm1,xmm2 ; xmm1=(40 41 50 51 60 61 70 71)
movdqa xmm3,xmm0 ; transpose coefficients(phase 1)
punpcklwd xmm0,xmm5 ; xmm0=(02 03 12 13 22 23 32 33)
punpckhwd xmm3,xmm5 ; xmm3=(42 43 52 53 62 63 72 73)
movdqa xmm2, XMMWORD [wk(3)] ; xmm2=col4
movdqa xmm5, XMMWORD [wk(5)] ; xmm5=col6
; xmm2=(04 14 24 34 44 54 64 74), xmm5=(06 16 26 36 46 56 66 76)
; xmm4=(05 15 25 35 45 55 65 75), xmm7=(07 17 27 37 47 57 67 77)
movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=(02 03 12 13 22 23 32 33)
movdqa XMMWORD [wk(1)], xmm3 ; wk(1)=(42 43 52 53 62 63 72 73)
movdqa xmm0,xmm2 ; transpose coefficients(phase 1)
punpcklwd xmm2,xmm4 ; xmm2=(04 05 14 15 24 25 34 35)
punpckhwd xmm0,xmm4 ; xmm0=(44 45 54 55 64 65 74 75)
movdqa xmm3,xmm5 ; transpose coefficients(phase 1)
punpcklwd xmm5,xmm7 ; xmm5=(06 07 16 17 26 27 36 37)
punpckhwd xmm3,xmm7 ; xmm3=(46 47 56 57 66 67 76 77)
movdqa xmm4,xmm2 ; transpose coefficients(phase 2)
punpckldq xmm2,xmm5 ; xmm2=(04 05 06 07 14 15 16 17)
punpckhdq xmm4,xmm5 ; xmm4=(24 25 26 27 34 35 36 37)
movdqa xmm7,xmm0 ; transpose coefficients(phase 2)
punpckldq xmm0,xmm3 ; xmm0=(44 45 46 47 54 55 56 57)
punpckhdq xmm7,xmm3 ; xmm7=(64 65 66 67 74 75 76 77)
movdqa xmm5, XMMWORD [wk(0)] ; xmm5=(02 03 12 13 22 23 32 33)
movdqa xmm3, XMMWORD [wk(1)] ; xmm3=(42 43 52 53 62 63 72 73)
movdqa XMMWORD [wk(2)], xmm4 ; wk(2)=(24 25 26 27 34 35 36 37)
movdqa XMMWORD [wk(3)], xmm0 ; wk(3)=(44 45 46 47 54 55 56 57)
movdqa xmm4,xmm6 ; transpose coefficients(phase 2)
punpckldq xmm6,xmm5 ; xmm6=(00 01 02 03 10 11 12 13)
punpckhdq xmm4,xmm5 ; xmm4=(20 21 22 23 30 31 32 33)
movdqa xmm0,xmm1 ; transpose coefficients(phase 2)
punpckldq xmm1,xmm3 ; xmm1=(40 41 42 43 50 51 52 53)
punpckhdq xmm0,xmm3 ; xmm0=(60 61 62 63 70 71 72 73)
movdqa xmm5,xmm6 ; transpose coefficients(phase 3)
punpcklqdq xmm6,xmm2 ; xmm6=(00 01 02 03 04 05 06 07)=data0
punpckhqdq xmm5,xmm2 ; xmm5=(10 11 12 13 14 15 16 17)=data1
movdqa xmm3,xmm0 ; transpose coefficients(phase 3)
punpcklqdq xmm0,xmm7 ; xmm0=(60 61 62 63 64 65 66 67)=data6
punpckhqdq xmm3,xmm7 ; xmm3=(70 71 72 73 74 75 76 77)=data7
movdqa xmm2,xmm5
movdqa xmm7,xmm6
psubw xmm5,xmm0 ; xmm5=data1-data6=tmp6
psubw xmm6,xmm3 ; xmm6=data0-data7=tmp7
paddw xmm2,xmm0 ; xmm2=data1+data6=tmp1
paddw xmm7,xmm3 ; xmm7=data0+data7=tmp0
movdqa xmm0, XMMWORD [wk(2)] ; xmm0=(24 25 26 27 34 35 36 37)
movdqa xmm3, XMMWORD [wk(3)] ; xmm3=(44 45 46 47 54 55 56 57)
movdqa XMMWORD [wk(0)], xmm5 ; wk(0)=tmp6
movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=tmp7
movdqa xmm5,xmm4 ; transpose coefficients(phase 3)
punpcklqdq xmm4,xmm0 ; xmm4=(20 21 22 23 24 25 26 27)=data2
punpckhqdq xmm5,xmm0 ; xmm5=(30 31 32 33 34 35 36 37)=data3
movdqa xmm6,xmm1 ; transpose coefficients(phase 3)
punpcklqdq xmm1,xmm3 ; xmm1=(40 41 42 43 44 45 46 47)=data4
punpckhqdq xmm6,xmm3 ; xmm6=(50 51 52 53 54 55 56 57)=data5
movdqa xmm0,xmm5
movdqa xmm3,xmm4
paddw xmm5,xmm1 ; xmm5=data3+data4=tmp3
paddw xmm4,xmm6 ; xmm4=data2+data5=tmp2
psubw xmm0,xmm1 ; xmm0=data3-data4=tmp4
psubw xmm3,xmm6 ; xmm3=data2-data5=tmp5
; -- Even part
movdqa xmm1,xmm7
movdqa xmm6,xmm2
paddw xmm7,xmm5 ; xmm7=tmp10
paddw xmm2,xmm4 ; xmm2=tmp11
psubw xmm1,xmm5 ; xmm1=tmp13
psubw xmm6,xmm4 ; xmm6=tmp12
movdqa xmm5,xmm7
paddw xmm7,xmm2 ; xmm7=tmp10+tmp11
psubw xmm5,xmm2 ; xmm5=tmp10-tmp11
paddw xmm7,[rel PW_DESCALE_P2X]
paddw xmm5,[rel PW_DESCALE_P2X]
psraw xmm7,PASS1_BITS ; xmm7=data0
psraw xmm5,PASS1_BITS ; xmm5=data4
movdqa XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_DCTELEM)], xmm7
movdqa XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_DCTELEM)], xmm5
; (Original)
; z1 = (tmp12 + tmp13) * 0.541196100;
; data2 = z1 + tmp13 * 0.765366865;
; data6 = z1 + tmp12 * -1.847759065;
;
; (This implementation)
; data2 = tmp13 * (0.541196100 + 0.765366865) + tmp12 * 0.541196100;
; data6 = tmp13 * 0.541196100 + tmp12 * (0.541196100 - 1.847759065);
movdqa xmm4,xmm1 ; xmm1=tmp13
movdqa xmm2,xmm1
punpcklwd xmm4,xmm6 ; xmm6=tmp12
punpckhwd xmm2,xmm6
movdqa xmm1,xmm4
movdqa xmm6,xmm2
pmaddwd xmm4,[rel PW_F130_F054] ; xmm4=data2L
pmaddwd xmm2,[rel PW_F130_F054] ; xmm2=data2H
pmaddwd xmm1,[rel PW_F054_MF130] ; xmm1=data6L
pmaddwd xmm6,[rel PW_F054_MF130] ; xmm6=data6H
paddd xmm4,[rel PD_DESCALE_P2]
paddd xmm2,[rel PD_DESCALE_P2]
psrad xmm4,DESCALE_P2
psrad xmm2,DESCALE_P2
paddd xmm1,[rel PD_DESCALE_P2]
paddd xmm6,[rel PD_DESCALE_P2]
psrad xmm1,DESCALE_P2
psrad xmm6,DESCALE_P2
packssdw xmm4,xmm2 ; xmm4=data2
packssdw xmm1,xmm6 ; xmm1=data6
movdqa XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_DCTELEM)], xmm4
movdqa XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_DCTELEM)], xmm1
; -- Odd part
movdqa xmm7, XMMWORD [wk(0)] ; xmm7=tmp6
movdqa xmm5, XMMWORD [wk(1)] ; xmm5=tmp7
movdqa xmm2,xmm0 ; xmm0=tmp4
movdqa xmm6,xmm3 ; xmm3=tmp5
paddw xmm2,xmm7 ; xmm2=z3
paddw xmm6,xmm5 ; xmm6=z4
; (Original)
; z5 = (z3 + z4) * 1.175875602;
; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644;
; z3 += z5; z4 += z5;
;
; (This implementation)
; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
movdqa xmm4,xmm2
movdqa xmm1,xmm2
punpcklwd xmm4,xmm6
punpckhwd xmm1,xmm6
movdqa xmm2,xmm4
movdqa xmm6,xmm1
pmaddwd xmm4,[rel PW_MF078_F117] ; xmm4=z3L
pmaddwd xmm1,[rel PW_MF078_F117] ; xmm1=z3H
pmaddwd xmm2,[rel PW_F117_F078] ; xmm2=z4L
pmaddwd xmm6,[rel PW_F117_F078] ; xmm6=z4H
movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=z3L
movdqa XMMWORD [wk(1)], xmm1 ; wk(1)=z3H
; (Original)
; z1 = tmp4 + tmp7; z2 = tmp5 + tmp6;
; tmp4 = tmp4 * 0.298631336; tmp5 = tmp5 * 2.053119869;
; tmp6 = tmp6 * 3.072711026; tmp7 = tmp7 * 1.501321110;
; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447;
; data7 = tmp4 + z1 + z3; data5 = tmp5 + z2 + z4;
; data3 = tmp6 + z2 + z3; data1 = tmp7 + z1 + z4;
;
; (This implementation)
; tmp4 = tmp4 * (0.298631336 - 0.899976223) + tmp7 * -0.899976223;
; tmp5 = tmp5 * (2.053119869 - 2.562915447) + tmp6 * -2.562915447;
; tmp6 = tmp5 * -2.562915447 + tmp6 * (3.072711026 - 2.562915447);
; tmp7 = tmp4 * -0.899976223 + tmp7 * (1.501321110 - 0.899976223);
; data7 = tmp4 + z3; data5 = tmp5 + z4;
; data3 = tmp6 + z3; data1 = tmp7 + z4;
movdqa xmm4,xmm0
movdqa xmm1,xmm0
punpcklwd xmm4,xmm5
punpckhwd xmm1,xmm5
movdqa xmm0,xmm4
movdqa xmm5,xmm1
pmaddwd xmm4,[rel PW_MF060_MF089] ; xmm4=tmp4L
pmaddwd xmm1,[rel PW_MF060_MF089] ; xmm1=tmp4H
pmaddwd xmm0,[rel PW_MF089_F060] ; xmm0=tmp7L
pmaddwd xmm5,[rel PW_MF089_F060] ; xmm5=tmp7H
paddd xmm4, XMMWORD [wk(0)] ; xmm4=data7L
paddd xmm1, XMMWORD [wk(1)] ; xmm1=data7H
paddd xmm0,xmm2 ; xmm0=data1L
paddd xmm5,xmm6 ; xmm5=data1H
paddd xmm4,[rel PD_DESCALE_P2]
paddd xmm1,[rel PD_DESCALE_P2]
psrad xmm4,DESCALE_P2
psrad xmm1,DESCALE_P2
paddd xmm0,[rel PD_DESCALE_P2]
paddd xmm5,[rel PD_DESCALE_P2]
psrad xmm0,DESCALE_P2
psrad xmm5,DESCALE_P2
packssdw xmm4,xmm1 ; xmm4=data7
packssdw xmm0,xmm5 ; xmm0=data1
movdqa XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_DCTELEM)], xmm4
movdqa XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_DCTELEM)], xmm0
movdqa xmm1,xmm3
movdqa xmm5,xmm3
punpcklwd xmm1,xmm7
punpckhwd xmm5,xmm7
movdqa xmm3,xmm1
movdqa xmm7,xmm5
pmaddwd xmm1,[rel PW_MF050_MF256] ; xmm1=tmp5L
pmaddwd xmm5,[rel PW_MF050_MF256] ; xmm5=tmp5H
pmaddwd xmm3,[rel PW_MF256_F050] ; xmm3=tmp6L
pmaddwd xmm7,[rel PW_MF256_F050] ; xmm7=tmp6H
paddd xmm1,xmm2 ; xmm1=data5L
paddd xmm5,xmm6 ; xmm5=data5H
paddd xmm3, XMMWORD [wk(0)] ; xmm3=data3L
paddd xmm7, XMMWORD [wk(1)] ; xmm7=data3H
paddd xmm1,[rel PD_DESCALE_P2]
paddd xmm5,[rel PD_DESCALE_P2]
psrad xmm1,DESCALE_P2
psrad xmm5,DESCALE_P2
paddd xmm3,[rel PD_DESCALE_P2]
paddd xmm7,[rel PD_DESCALE_P2]
psrad xmm3,DESCALE_P2
psrad xmm7,DESCALE_P2
packssdw xmm1,xmm5 ; xmm1=data5
packssdw xmm3,xmm7 ; xmm3=data3
movdqa XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_DCTELEM)], xmm1
movdqa XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_DCTELEM)], xmm3
uncollect_args
mov rsp,rbp ; rsp <- aligned rbp
pop rsp ; rsp <- original rbp
pop rbp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16
@@ -1,483 +0,0 @@
;
; jidctflt.asm - floating-point IDCT (64-bit SSE & SSE2)
;
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2009 D. R. Commander
;
; Based on
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; This file contains a floating-point implementation of the inverse DCT
; (Discrete Cosine Transform). The following code is based directly on
; the IJG's original jidctflt.c; see the jidctflt.c for more details.
;
; [TAB8]
%include "jsimdext.inc"
%include "jdct.inc"
; --------------------------------------------------------------------------
%macro unpcklps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(0 1 4 5)
shufps %1,%2,0x44
%endmacro
%macro unpckhps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(2 3 6 7)
shufps %1,%2,0xEE
%endmacro
; --------------------------------------------------------------------------
SECTION SEG_CONST
alignz 16
global EXTN(jconst_idct_float_sse2)
EXTN(jconst_idct_float_sse2):
PD_1_414 times 4 dd 1.414213562373095048801689
PD_1_847 times 4 dd 1.847759065022573512256366
PD_1_082 times 4 dd 1.082392200292393968799446
PD_M2_613 times 4 dd -2.613125929752753055713286
PD_RNDINT_MAGIC times 4 dd 100663296.0 ; (float)(0x00C00000 << 3)
PB_CENTERJSAMP times 16 db CENTERJSAMPLE
alignz 16
; --------------------------------------------------------------------------
SECTION SEG_TEXT
BITS 64
;
; Perform dequantization and inverse DCT on one block of coefficients.
;
; GLOBAL(void)
; jsimd_idct_float_sse2 (void * dct_table, JCOEFPTR coef_block,
; JSAMPARRAY output_buf, JDIMENSION output_col)
;
; r10 = void * dct_table
; r11 = JCOEFPTR coef_block
; r12 = JSAMPARRAY output_buf
; r13 = JDIMENSION output_col
%define original_rbp rbp+0
%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 2
%define workspace wk(0)-DCTSIZE2*SIZEOF_FAST_FLOAT
; FAST_FLOAT workspace[DCTSIZE2]
align 16
global EXTN(jsimd_idct_float_sse2)
EXTN(jsimd_idct_float_sse2):
push rbp
mov rax,rsp ; rax = original rbp
sub rsp, byte 4
and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [rsp],rax
mov rbp,rsp ; rbp = aligned rbp
lea rsp, [workspace]
collect_args
push rbx
; ---- Pass 1: process columns from input, store into work array.
mov rdx, r10 ; quantptr
mov rsi, r11 ; inptr
lea rdi, [workspace] ; FAST_FLOAT * wsptr
mov rcx, DCTSIZE/4 ; ctr
.columnloop:
%ifndef NO_ZERO_COLUMN_TEST_FLOAT_SSE
mov eax, DWORD [DWBLOCK(1,0,rsi,SIZEOF_JCOEF)]
or eax, DWORD [DWBLOCK(2,0,rsi,SIZEOF_JCOEF)]
jnz near .columnDCT
movq xmm1, XMM_MMWORD [MMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
movq xmm2, XMM_MMWORD [MMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
movq xmm3, XMM_MMWORD [MMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
movq xmm4, XMM_MMWORD [MMBLOCK(4,0,rsi,SIZEOF_JCOEF)]
movq xmm5, XMM_MMWORD [MMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
movq xmm6, XMM_MMWORD [MMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
movq xmm7, XMM_MMWORD [MMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
por xmm1,xmm2
por xmm3,xmm4
por xmm5,xmm6
por xmm1,xmm3
por xmm5,xmm7
por xmm1,xmm5
packsswb xmm1,xmm1
movd eax,xmm1
test rax,rax
jnz short .columnDCT
; -- AC terms all zero
movq xmm0, XMM_MMWORD [MMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
punpcklwd xmm0,xmm0 ; xmm0=(00 00 01 01 02 02 03 03)
psrad xmm0,(DWORD_BIT-WORD_BIT) ; xmm0=in0=(00 01 02 03)
cvtdq2ps xmm0,xmm0 ; xmm0=in0=(00 01 02 03)
mulps xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FLOAT_MULT_TYPE)]
movaps xmm1,xmm0
movaps xmm2,xmm0
movaps xmm3,xmm0
shufps xmm0,xmm0,0x00 ; xmm0=(00 00 00 00)
shufps xmm1,xmm1,0x55 ; xmm1=(01 01 01 01)
shufps xmm2,xmm2,0xAA ; xmm2=(02 02 02 02)
shufps xmm3,xmm3,0xFF ; xmm3=(03 03 03 03)
movaps XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_FAST_FLOAT)], xmm0
movaps XMMWORD [XMMBLOCK(0,1,rdi,SIZEOF_FAST_FLOAT)], xmm0
movaps XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_FAST_FLOAT)], xmm1
movaps XMMWORD [XMMBLOCK(1,1,rdi,SIZEOF_FAST_FLOAT)], xmm1
movaps XMMWORD [XMMBLOCK(2,0,rdi,SIZEOF_FAST_FLOAT)], xmm2
movaps XMMWORD [XMMBLOCK(2,1,rdi,SIZEOF_FAST_FLOAT)], xmm2
movaps XMMWORD [XMMBLOCK(3,0,rdi,SIZEOF_FAST_FLOAT)], xmm3
movaps XMMWORD [XMMBLOCK(3,1,rdi,SIZEOF_FAST_FLOAT)], xmm3
jmp near .nextcolumn
%endif
.columnDCT:
; -- Even part
movq xmm0, XMM_MMWORD [MMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
movq xmm1, XMM_MMWORD [MMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
movq xmm2, XMM_MMWORD [MMBLOCK(4,0,rsi,SIZEOF_JCOEF)]
movq xmm3, XMM_MMWORD [MMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
punpcklwd xmm0,xmm0 ; xmm0=(00 00 01 01 02 02 03 03)
punpcklwd xmm1,xmm1 ; xmm1=(20 20 21 21 22 22 23 23)
psrad xmm0,(DWORD_BIT-WORD_BIT) ; xmm0=in0=(00 01 02 03)
psrad xmm1,(DWORD_BIT-WORD_BIT) ; xmm1=in2=(20 21 22 23)
cvtdq2ps xmm0,xmm0 ; xmm0=in0=(00 01 02 03)
cvtdq2ps xmm1,xmm1 ; xmm1=in2=(20 21 22 23)
punpcklwd xmm2,xmm2 ; xmm2=(40 40 41 41 42 42 43 43)
punpcklwd xmm3,xmm3 ; xmm3=(60 60 61 61 62 62 63 63)
psrad xmm2,(DWORD_BIT-WORD_BIT) ; xmm2=in4=(40 41 42 43)
psrad xmm3,(DWORD_BIT-WORD_BIT) ; xmm3=in6=(60 61 62 63)
cvtdq2ps xmm2,xmm2 ; xmm2=in4=(40 41 42 43)
cvtdq2ps xmm3,xmm3 ; xmm3=in6=(60 61 62 63)
mulps xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FLOAT_MULT_TYPE)]
mulps xmm1, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_FLOAT_MULT_TYPE)]
mulps xmm2, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_FLOAT_MULT_TYPE)]
mulps xmm3, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_FLOAT_MULT_TYPE)]
movaps xmm4,xmm0
movaps xmm5,xmm1
subps xmm0,xmm2 ; xmm0=tmp11
subps xmm1,xmm3
addps xmm4,xmm2 ; xmm4=tmp10
addps xmm5,xmm3 ; xmm5=tmp13
mulps xmm1,[rel PD_1_414]
subps xmm1,xmm5 ; xmm1=tmp12
movaps xmm6,xmm4
movaps xmm7,xmm0
subps xmm4,xmm5 ; xmm4=tmp3
subps xmm0,xmm1 ; xmm0=tmp2
addps xmm6,xmm5 ; xmm6=tmp0
addps xmm7,xmm1 ; xmm7=tmp1
movaps XMMWORD [wk(1)], xmm4 ; tmp3
movaps XMMWORD [wk(0)], xmm0 ; tmp2
; -- Odd part
movq xmm2, XMM_MMWORD [MMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
movq xmm3, XMM_MMWORD [MMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
movq xmm5, XMM_MMWORD [MMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
movq xmm1, XMM_MMWORD [MMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
punpcklwd xmm2,xmm2 ; xmm2=(10 10 11 11 12 12 13 13)
punpcklwd xmm3,xmm3 ; xmm3=(30 30 31 31 32 32 33 33)
psrad xmm2,(DWORD_BIT-WORD_BIT) ; xmm2=in1=(10 11 12 13)
psrad xmm3,(DWORD_BIT-WORD_BIT) ; xmm3=in3=(30 31 32 33)
cvtdq2ps xmm2,xmm2 ; xmm2=in1=(10 11 12 13)
cvtdq2ps xmm3,xmm3 ; xmm3=in3=(30 31 32 33)
punpcklwd xmm5,xmm5 ; xmm5=(50 50 51 51 52 52 53 53)
punpcklwd xmm1,xmm1 ; xmm1=(70 70 71 71 72 72 73 73)
psrad xmm5,(DWORD_BIT-WORD_BIT) ; xmm5=in5=(50 51 52 53)
psrad xmm1,(DWORD_BIT-WORD_BIT) ; xmm1=in7=(70 71 72 73)
cvtdq2ps xmm5,xmm5 ; xmm5=in5=(50 51 52 53)
cvtdq2ps xmm1,xmm1 ; xmm1=in7=(70 71 72 73)
mulps xmm2, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FLOAT_MULT_TYPE)]
mulps xmm3, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_FLOAT_MULT_TYPE)]
mulps xmm5, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_FLOAT_MULT_TYPE)]
mulps xmm1, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_FLOAT_MULT_TYPE)]
movaps xmm4,xmm2
movaps xmm0,xmm5
addps xmm2,xmm1 ; xmm2=z11
addps xmm5,xmm3 ; xmm5=z13
subps xmm4,xmm1 ; xmm4=z12
subps xmm0,xmm3 ; xmm0=z10
movaps xmm1,xmm2
subps xmm2,xmm5
addps xmm1,xmm5 ; xmm1=tmp7
mulps xmm2,[rel PD_1_414] ; xmm2=tmp11
movaps xmm3,xmm0
addps xmm0,xmm4
mulps xmm0,[rel PD_1_847] ; xmm0=z5
mulps xmm3,[rel PD_M2_613] ; xmm3=(z10 * -2.613125930)
mulps xmm4,[rel PD_1_082] ; xmm4=(z12 * 1.082392200)
addps xmm3,xmm0 ; xmm3=tmp12
subps xmm4,xmm0 ; xmm4=tmp10
; -- Final output stage
subps xmm3,xmm1 ; xmm3=tmp6
movaps xmm5,xmm6
movaps xmm0,xmm7
addps xmm6,xmm1 ; xmm6=data0=(00 01 02 03)
addps xmm7,xmm3 ; xmm7=data1=(10 11 12 13)
subps xmm5,xmm1 ; xmm5=data7=(70 71 72 73)
subps xmm0,xmm3 ; xmm0=data6=(60 61 62 63)
subps xmm2,xmm3 ; xmm2=tmp5
movaps xmm1,xmm6 ; transpose coefficients(phase 1)
unpcklps xmm6,xmm7 ; xmm6=(00 10 01 11)
unpckhps xmm1,xmm7 ; xmm1=(02 12 03 13)
movaps xmm3,xmm0 ; transpose coefficients(phase 1)
unpcklps xmm0,xmm5 ; xmm0=(60 70 61 71)
unpckhps xmm3,xmm5 ; xmm3=(62 72 63 73)
movaps xmm7, XMMWORD [wk(0)] ; xmm7=tmp2
movaps xmm5, XMMWORD [wk(1)] ; xmm5=tmp3
movaps XMMWORD [wk(0)], xmm0 ; wk(0)=(60 70 61 71)
movaps XMMWORD [wk(1)], xmm3 ; wk(1)=(62 72 63 73)
addps xmm4,xmm2 ; xmm4=tmp4
movaps xmm0,xmm7
movaps xmm3,xmm5
addps xmm7,xmm2 ; xmm7=data2=(20 21 22 23)
addps xmm5,xmm4 ; xmm5=data4=(40 41 42 43)
subps xmm0,xmm2 ; xmm0=data5=(50 51 52 53)
subps xmm3,xmm4 ; xmm3=data3=(30 31 32 33)
movaps xmm2,xmm7 ; transpose coefficients(phase 1)
unpcklps xmm7,xmm3 ; xmm7=(20 30 21 31)
unpckhps xmm2,xmm3 ; xmm2=(22 32 23 33)
movaps xmm4,xmm5 ; transpose coefficients(phase 1)
unpcklps xmm5,xmm0 ; xmm5=(40 50 41 51)
unpckhps xmm4,xmm0 ; xmm4=(42 52 43 53)
movaps xmm3,xmm6 ; transpose coefficients(phase 2)
unpcklps2 xmm6,xmm7 ; xmm6=(00 10 20 30)
unpckhps2 xmm3,xmm7 ; xmm3=(01 11 21 31)
movaps xmm0,xmm1 ; transpose coefficients(phase 2)
unpcklps2 xmm1,xmm2 ; xmm1=(02 12 22 32)
unpckhps2 xmm0,xmm2 ; xmm0=(03 13 23 33)
movaps xmm7, XMMWORD [wk(0)] ; xmm7=(60 70 61 71)
movaps xmm2, XMMWORD [wk(1)] ; xmm2=(62 72 63 73)
movaps XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_FAST_FLOAT)], xmm6
movaps XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_FAST_FLOAT)], xmm3
movaps XMMWORD [XMMBLOCK(2,0,rdi,SIZEOF_FAST_FLOAT)], xmm1
movaps XMMWORD [XMMBLOCK(3,0,rdi,SIZEOF_FAST_FLOAT)], xmm0
movaps xmm6,xmm5 ; transpose coefficients(phase 2)
unpcklps2 xmm5,xmm7 ; xmm5=(40 50 60 70)
unpckhps2 xmm6,xmm7 ; xmm6=(41 51 61 71)
movaps xmm3,xmm4 ; transpose coefficients(phase 2)
unpcklps2 xmm4,xmm2 ; xmm4=(42 52 62 72)
unpckhps2 xmm3,xmm2 ; xmm3=(43 53 63 73)
movaps XMMWORD [XMMBLOCK(0,1,rdi,SIZEOF_FAST_FLOAT)], xmm5
movaps XMMWORD [XMMBLOCK(1,1,rdi,SIZEOF_FAST_FLOAT)], xmm6
movaps XMMWORD [XMMBLOCK(2,1,rdi,SIZEOF_FAST_FLOAT)], xmm4
movaps XMMWORD [XMMBLOCK(3,1,rdi,SIZEOF_FAST_FLOAT)], xmm3
.nextcolumn:
add rsi, byte 4*SIZEOF_JCOEF ; coef_block
add rdx, byte 4*SIZEOF_FLOAT_MULT_TYPE ; quantptr
add rdi, 4*DCTSIZE*SIZEOF_FAST_FLOAT ; wsptr
dec rcx ; ctr
jnz near .columnloop
; -- Prefetch the next coefficient block
prefetchnta [rsi + (DCTSIZE2-8)*SIZEOF_JCOEF + 0*32]
prefetchnta [rsi + (DCTSIZE2-8)*SIZEOF_JCOEF + 1*32]
prefetchnta [rsi + (DCTSIZE2-8)*SIZEOF_JCOEF + 2*32]
prefetchnta [rsi + (DCTSIZE2-8)*SIZEOF_JCOEF + 3*32]
; ---- Pass 2: process rows from work array, store into output array.
mov rax, [original_rbp]
lea rsi, [workspace] ; FAST_FLOAT * wsptr
mov rdi, r12 ; (JSAMPROW *)
mov rax, r13
mov rcx, DCTSIZE/4 ; ctr
.rowloop:
; -- Even part
movaps xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_FAST_FLOAT)]
movaps xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_FAST_FLOAT)]
movaps xmm2, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_FAST_FLOAT)]
movaps xmm3, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_FAST_FLOAT)]
movaps xmm4,xmm0
movaps xmm5,xmm1
subps xmm0,xmm2 ; xmm0=tmp11
subps xmm1,xmm3
addps xmm4,xmm2 ; xmm4=tmp10
addps xmm5,xmm3 ; xmm5=tmp13
mulps xmm1,[rel PD_1_414]
subps xmm1,xmm5 ; xmm1=tmp12
movaps xmm6,xmm4
movaps xmm7,xmm0
subps xmm4,xmm5 ; xmm4=tmp3
subps xmm0,xmm1 ; xmm0=tmp2
addps xmm6,xmm5 ; xmm6=tmp0
addps xmm7,xmm1 ; xmm7=tmp1
movaps XMMWORD [wk(1)], xmm4 ; tmp3
movaps XMMWORD [wk(0)], xmm0 ; tmp2
; -- Odd part
movaps xmm2, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_FAST_FLOAT)]
movaps xmm3, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_FAST_FLOAT)]
movaps xmm5, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_FAST_FLOAT)]
movaps xmm1, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_FAST_FLOAT)]
movaps xmm4,xmm2
movaps xmm0,xmm5
addps xmm2,xmm1 ; xmm2=z11
addps xmm5,xmm3 ; xmm5=z13
subps xmm4,xmm1 ; xmm4=z12
subps xmm0,xmm3 ; xmm0=z10
movaps xmm1,xmm2
subps xmm2,xmm5
addps xmm1,xmm5 ; xmm1=tmp7
mulps xmm2,[rel PD_1_414] ; xmm2=tmp11
movaps xmm3,xmm0
addps xmm0,xmm4
mulps xmm0,[rel PD_1_847] ; xmm0=z5
mulps xmm3,[rel PD_M2_613] ; xmm3=(z10 * -2.613125930)
mulps xmm4,[rel PD_1_082] ; xmm4=(z12 * 1.082392200)
addps xmm3,xmm0 ; xmm3=tmp12
subps xmm4,xmm0 ; xmm4=tmp10
; -- Final output stage
subps xmm3,xmm1 ; xmm3=tmp6
movaps xmm5,xmm6
movaps xmm0,xmm7
addps xmm6,xmm1 ; xmm6=data0=(00 10 20 30)
addps xmm7,xmm3 ; xmm7=data1=(01 11 21 31)
subps xmm5,xmm1 ; xmm5=data7=(07 17 27 37)
subps xmm0,xmm3 ; xmm0=data6=(06 16 26 36)
subps xmm2,xmm3 ; xmm2=tmp5
movaps xmm1,[rel PD_RNDINT_MAGIC] ; xmm1=[rel PD_RNDINT_MAGIC]
pcmpeqd xmm3,xmm3
psrld xmm3,WORD_BIT ; xmm3={0xFFFF 0x0000 0xFFFF 0x0000 ..}
addps xmm6,xmm1 ; xmm6=roundint(data0/8)=(00 ** 10 ** 20 ** 30 **)
addps xmm7,xmm1 ; xmm7=roundint(data1/8)=(01 ** 11 ** 21 ** 31 **)
addps xmm0,xmm1 ; xmm0=roundint(data6/8)=(06 ** 16 ** 26 ** 36 **)
addps xmm5,xmm1 ; xmm5=roundint(data7/8)=(07 ** 17 ** 27 ** 37 **)
pand xmm6,xmm3 ; xmm6=(00 -- 10 -- 20 -- 30 --)
pslld xmm7,WORD_BIT ; xmm7=(-- 01 -- 11 -- 21 -- 31)
pand xmm0,xmm3 ; xmm0=(06 -- 16 -- 26 -- 36 --)
pslld xmm5,WORD_BIT ; xmm5=(-- 07 -- 17 -- 27 -- 37)
por xmm6,xmm7 ; xmm6=(00 01 10 11 20 21 30 31)
por xmm0,xmm5 ; xmm0=(06 07 16 17 26 27 36 37)
movaps xmm1, XMMWORD [wk(0)] ; xmm1=tmp2
movaps xmm3, XMMWORD [wk(1)] ; xmm3=tmp3
addps xmm4,xmm2 ; xmm4=tmp4
movaps xmm7,xmm1
movaps xmm5,xmm3
addps xmm1,xmm2 ; xmm1=data2=(02 12 22 32)
addps xmm3,xmm4 ; xmm3=data4=(04 14 24 34)
subps xmm7,xmm2 ; xmm7=data5=(05 15 25 35)
subps xmm5,xmm4 ; xmm5=data3=(03 13 23 33)
movaps xmm2,[rel PD_RNDINT_MAGIC] ; xmm2=[rel PD_RNDINT_MAGIC]
pcmpeqd xmm4,xmm4
psrld xmm4,WORD_BIT ; xmm4={0xFFFF 0x0000 0xFFFF 0x0000 ..}
addps xmm3,xmm2 ; xmm3=roundint(data4/8)=(04 ** 14 ** 24 ** 34 **)
addps xmm7,xmm2 ; xmm7=roundint(data5/8)=(05 ** 15 ** 25 ** 35 **)
addps xmm1,xmm2 ; xmm1=roundint(data2/8)=(02 ** 12 ** 22 ** 32 **)
addps xmm5,xmm2 ; xmm5=roundint(data3/8)=(03 ** 13 ** 23 ** 33 **)
pand xmm3,xmm4 ; xmm3=(04 -- 14 -- 24 -- 34 --)
pslld xmm7,WORD_BIT ; xmm7=(-- 05 -- 15 -- 25 -- 35)
pand xmm1,xmm4 ; xmm1=(02 -- 12 -- 22 -- 32 --)
pslld xmm5,WORD_BIT ; xmm5=(-- 03 -- 13 -- 23 -- 33)
por xmm3,xmm7 ; xmm3=(04 05 14 15 24 25 34 35)
por xmm1,xmm5 ; xmm1=(02 03 12 13 22 23 32 33)
movdqa xmm2,[rel PB_CENTERJSAMP] ; xmm2=[rel PB_CENTERJSAMP]
packsswb xmm6,xmm3 ; xmm6=(00 01 10 11 20 21 30 31 04 05 14 15 24 25 34 35)
packsswb xmm1,xmm0 ; xmm1=(02 03 12 13 22 23 32 33 06 07 16 17 26 27 36 37)
paddb xmm6,xmm2
paddb xmm1,xmm2
movdqa xmm4,xmm6 ; transpose coefficients(phase 2)
punpcklwd xmm6,xmm1 ; xmm6=(00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33)
punpckhwd xmm4,xmm1 ; xmm4=(04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37)
movdqa xmm7,xmm6 ; transpose coefficients(phase 3)
punpckldq xmm6,xmm4 ; xmm6=(00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17)
punpckhdq xmm7,xmm4 ; xmm7=(20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37)
pshufd xmm5,xmm6,0x4E ; xmm5=(10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07)
pshufd xmm3,xmm7,0x4E ; xmm3=(30 31 32 33 34 35 36 37 20 21 22 23 24 25 26 27)
mov rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW]
mov rbx, JSAMPROW [rdi+2*SIZEOF_JSAMPROW]
movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm6
movq XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE], xmm7
mov rdx, JSAMPROW [rdi+1*SIZEOF_JSAMPROW]
mov rbx, JSAMPROW [rdi+3*SIZEOF_JSAMPROW]
movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm5
movq XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE], xmm3
add rsi, byte 4*SIZEOF_FAST_FLOAT ; wsptr
add rdi, byte 4*SIZEOF_JSAMPROW
dec rcx ; ctr
jnz near .rowloop
pop rbx
uncollect_args
mov rsp,rbp ; rsp <- aligned rbp
pop rsp ; rsp <- original rbp
pop rbp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16
@@ -1,492 +0,0 @@
;
; jidctfst.asm - fast integer IDCT (64-bit SSE2)
;
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2009 D. R. Commander
;
; Based on
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/projecpt/showfiles.php?group_id=6208
;
; This file contains a fast, not so accurate integer implementation of
; the inverse DCT (Discrete Cosine Transform). The following code is
; based directly on the IJG's original jidctfst.c; see the jidctfst.c
; for more details.
;
; [TAB8]
%include "jsimdext.inc"
%include "jdct.inc"
; --------------------------------------------------------------------------
%define CONST_BITS 8 ; 14 is also OK.
%define PASS1_BITS 2
%if IFAST_SCALE_BITS != PASS1_BITS
%error "'IFAST_SCALE_BITS' must be equal to 'PASS1_BITS'."
%endif
%if CONST_BITS == 8
F_1_082 equ 277 ; FIX(1.082392200)
F_1_414 equ 362 ; FIX(1.414213562)
F_1_847 equ 473 ; FIX(1.847759065)
F_2_613 equ 669 ; FIX(2.613125930)
F_1_613 equ (F_2_613 - 256) ; FIX(2.613125930) - FIX(1)
%else
; NASM cannot do compile-time arithmetic on floating-point constants.
%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n))
F_1_082 equ DESCALE(1162209775,30-CONST_BITS) ; FIX(1.082392200)
F_1_414 equ DESCALE(1518500249,30-CONST_BITS) ; FIX(1.414213562)
F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065)
F_2_613 equ DESCALE(2805822602,30-CONST_BITS) ; FIX(2.613125930)
F_1_613 equ (F_2_613 - (1 << CONST_BITS)) ; FIX(2.613125930) - FIX(1)
%endif
; --------------------------------------------------------------------------
SECTION SEG_CONST
; PRE_MULTIPLY_SCALE_BITS <= 2 (to avoid overflow)
; CONST_BITS + CONST_SHIFT + PRE_MULTIPLY_SCALE_BITS == 16 (for pmulhw)
%define PRE_MULTIPLY_SCALE_BITS 2
%define CONST_SHIFT (16 - PRE_MULTIPLY_SCALE_BITS - CONST_BITS)
alignz 16
global EXTN(jconst_idct_ifast_sse2)
EXTN(jconst_idct_ifast_sse2):
PW_F1414 times 8 dw F_1_414 << CONST_SHIFT
PW_F1847 times 8 dw F_1_847 << CONST_SHIFT
PW_MF1613 times 8 dw -F_1_613 << CONST_SHIFT
PW_F1082 times 8 dw F_1_082 << CONST_SHIFT
PB_CENTERJSAMP times 16 db CENTERJSAMPLE
alignz 16
; --------------------------------------------------------------------------
SECTION SEG_TEXT
BITS 64
;
; Perform dequantization and inverse DCT on one block of coefficients.
;
; GLOBAL(void)
; jsimd_idct_ifast_sse2 (void * dct_table, JCOEFPTR coef_block,
; JSAMPARRAY output_buf, JDIMENSION output_col)
;
; r10 = jpeg_component_info * compptr
; r11 = JCOEFPTR coef_block
; r12 = JSAMPARRAY output_buf
; r13 = JDIMENSION output_col
%define original_rbp rbp+0
%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 2
align 16
global EXTN(jsimd_idct_ifast_sse2)
EXTN(jsimd_idct_ifast_sse2):
push rbp
mov rax,rsp ; rax = original rbp
sub rsp, byte 4
and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [rsp],rax
mov rbp,rsp ; rbp = aligned rbp
lea rsp, [wk(0)]
collect_args
; ---- Pass 1: process columns from input.
mov rdx, r10 ; quantptr
mov rsi, r11 ; inptr
%ifndef NO_ZERO_COLUMN_TEST_IFAST_SSE2
mov eax, DWORD [DWBLOCK(1,0,rsi,SIZEOF_JCOEF)]
or eax, DWORD [DWBLOCK(2,0,rsi,SIZEOF_JCOEF)]
jnz near .columnDCT
movdqa xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
movdqa xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
por xmm0, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
por xmm1, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_JCOEF)]
por xmm0, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
por xmm1, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
por xmm0, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
por xmm1,xmm0
packsswb xmm1,xmm1
packsswb xmm1,xmm1
movd eax,xmm1
test rax,rax
jnz short .columnDCT
; -- AC terms all zero
movdqa xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
pmullw xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
movdqa xmm7,xmm0 ; xmm0=in0=(00 01 02 03 04 05 06 07)
punpcklwd xmm0,xmm0 ; xmm0=(00 00 01 01 02 02 03 03)
punpckhwd xmm7,xmm7 ; xmm7=(04 04 05 05 06 06 07 07)
pshufd xmm6,xmm0,0x00 ; xmm6=col0=(00 00 00 00 00 00 00 00)
pshufd xmm2,xmm0,0x55 ; xmm2=col1=(01 01 01 01 01 01 01 01)
pshufd xmm5,xmm0,0xAA ; xmm5=col2=(02 02 02 02 02 02 02 02)
pshufd xmm0,xmm0,0xFF ; xmm0=col3=(03 03 03 03 03 03 03 03)
pshufd xmm1,xmm7,0x00 ; xmm1=col4=(04 04 04 04 04 04 04 04)
pshufd xmm4,xmm7,0x55 ; xmm4=col5=(05 05 05 05 05 05 05 05)
pshufd xmm3,xmm7,0xAA ; xmm3=col6=(06 06 06 06 06 06 06 06)
pshufd xmm7,xmm7,0xFF ; xmm7=col7=(07 07 07 07 07 07 07 07)
movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=col1
movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=col3
jmp near .column_end
%endif
.columnDCT:
; -- Even part
movdqa xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
movdqa xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
pmullw xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
pmullw xmm1, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
movdqa xmm2, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_JCOEF)]
movdqa xmm3, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
pmullw xmm2, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
pmullw xmm3, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
movdqa xmm4,xmm0
movdqa xmm5,xmm1
psubw xmm0,xmm2 ; xmm0=tmp11
psubw xmm1,xmm3
paddw xmm4,xmm2 ; xmm4=tmp10
paddw xmm5,xmm3 ; xmm5=tmp13
psllw xmm1,PRE_MULTIPLY_SCALE_BITS
pmulhw xmm1,[rel PW_F1414]
psubw xmm1,xmm5 ; xmm1=tmp12
movdqa xmm6,xmm4
movdqa xmm7,xmm0
psubw xmm4,xmm5 ; xmm4=tmp3
psubw xmm0,xmm1 ; xmm0=tmp2
paddw xmm6,xmm5 ; xmm6=tmp0
paddw xmm7,xmm1 ; xmm7=tmp1
movdqa XMMWORD [wk(1)], xmm4 ; wk(1)=tmp3
movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=tmp2
; -- Odd part
movdqa xmm2, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
movdqa xmm3, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
pmullw xmm2, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
pmullw xmm3, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
movdqa xmm5, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
movdqa xmm1, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
pmullw xmm5, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
pmullw xmm1, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
movdqa xmm4,xmm2
movdqa xmm0,xmm5
psubw xmm2,xmm1 ; xmm2=z12
psubw xmm5,xmm3 ; xmm5=z10
paddw xmm4,xmm1 ; xmm4=z11
paddw xmm0,xmm3 ; xmm0=z13
movdqa xmm1,xmm5 ; xmm1=z10(unscaled)
psllw xmm2,PRE_MULTIPLY_SCALE_BITS
psllw xmm5,PRE_MULTIPLY_SCALE_BITS
movdqa xmm3,xmm4
psubw xmm4,xmm0
paddw xmm3,xmm0 ; xmm3=tmp7
psllw xmm4,PRE_MULTIPLY_SCALE_BITS
pmulhw xmm4,[rel PW_F1414] ; xmm4=tmp11
; To avoid overflow...
;
; (Original)
; tmp12 = -2.613125930 * z10 + z5;
;
; (This implementation)
; tmp12 = (-1.613125930 - 1) * z10 + z5;
; = -1.613125930 * z10 - z10 + z5;
movdqa xmm0,xmm5
paddw xmm5,xmm2
pmulhw xmm5,[rel PW_F1847] ; xmm5=z5
pmulhw xmm0,[rel PW_MF1613]
pmulhw xmm2,[rel PW_F1082]
psubw xmm0,xmm1
psubw xmm2,xmm5 ; xmm2=tmp10
paddw xmm0,xmm5 ; xmm0=tmp12
; -- Final output stage
psubw xmm0,xmm3 ; xmm0=tmp6
movdqa xmm1,xmm6
movdqa xmm5,xmm7
paddw xmm6,xmm3 ; xmm6=data0=(00 01 02 03 04 05 06 07)
paddw xmm7,xmm0 ; xmm7=data1=(10 11 12 13 14 15 16 17)
psubw xmm1,xmm3 ; xmm1=data7=(70 71 72 73 74 75 76 77)
psubw xmm5,xmm0 ; xmm5=data6=(60 61 62 63 64 65 66 67)
psubw xmm4,xmm0 ; xmm4=tmp5
movdqa xmm3,xmm6 ; transpose coefficients(phase 1)
punpcklwd xmm6,xmm7 ; xmm6=(00 10 01 11 02 12 03 13)
punpckhwd xmm3,xmm7 ; xmm3=(04 14 05 15 06 16 07 17)
movdqa xmm0,xmm5 ; transpose coefficients(phase 1)
punpcklwd xmm5,xmm1 ; xmm5=(60 70 61 71 62 72 63 73)
punpckhwd xmm0,xmm1 ; xmm0=(64 74 65 75 66 76 67 77)
movdqa xmm7, XMMWORD [wk(0)] ; xmm7=tmp2
movdqa xmm1, XMMWORD [wk(1)] ; xmm1=tmp3
movdqa XMMWORD [wk(0)], xmm5 ; wk(0)=(60 70 61 71 62 72 63 73)
movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=(64 74 65 75 66 76 67 77)
paddw xmm2,xmm4 ; xmm2=tmp4
movdqa xmm5,xmm7
movdqa xmm0,xmm1
paddw xmm7,xmm4 ; xmm7=data2=(20 21 22 23 24 25 26 27)
paddw xmm1,xmm2 ; xmm1=data4=(40 41 42 43 44 45 46 47)
psubw xmm5,xmm4 ; xmm5=data5=(50 51 52 53 54 55 56 57)
psubw xmm0,xmm2 ; xmm0=data3=(30 31 32 33 34 35 36 37)
movdqa xmm4,xmm7 ; transpose coefficients(phase 1)
punpcklwd xmm7,xmm0 ; xmm7=(20 30 21 31 22 32 23 33)
punpckhwd xmm4,xmm0 ; xmm4=(24 34 25 35 26 36 27 37)
movdqa xmm2,xmm1 ; transpose coefficients(phase 1)
punpcklwd xmm1,xmm5 ; xmm1=(40 50 41 51 42 52 43 53)
punpckhwd xmm2,xmm5 ; xmm2=(44 54 45 55 46 56 47 57)
movdqa xmm0,xmm3 ; transpose coefficients(phase 2)
punpckldq xmm3,xmm4 ; xmm3=(04 14 24 34 05 15 25 35)
punpckhdq xmm0,xmm4 ; xmm0=(06 16 26 36 07 17 27 37)
movdqa xmm5,xmm6 ; transpose coefficients(phase 2)
punpckldq xmm6,xmm7 ; xmm6=(00 10 20 30 01 11 21 31)
punpckhdq xmm5,xmm7 ; xmm5=(02 12 22 32 03 13 23 33)
movdqa xmm4, XMMWORD [wk(0)] ; xmm4=(60 70 61 71 62 72 63 73)
movdqa xmm7, XMMWORD [wk(1)] ; xmm7=(64 74 65 75 66 76 67 77)
movdqa XMMWORD [wk(0)], xmm3 ; wk(0)=(04 14 24 34 05 15 25 35)
movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=(06 16 26 36 07 17 27 37)
movdqa xmm3,xmm1 ; transpose coefficients(phase 2)
punpckldq xmm1,xmm4 ; xmm1=(40 50 60 70 41 51 61 71)
punpckhdq xmm3,xmm4 ; xmm3=(42 52 62 72 43 53 63 73)
movdqa xmm0,xmm2 ; transpose coefficients(phase 2)
punpckldq xmm2,xmm7 ; xmm2=(44 54 64 74 45 55 65 75)
punpckhdq xmm0,xmm7 ; xmm0=(46 56 66 76 47 57 67 77)
movdqa xmm4,xmm6 ; transpose coefficients(phase 3)
punpcklqdq xmm6,xmm1 ; xmm6=col0=(00 10 20 30 40 50 60 70)
punpckhqdq xmm4,xmm1 ; xmm4=col1=(01 11 21 31 41 51 61 71)
movdqa xmm7,xmm5 ; transpose coefficients(phase 3)
punpcklqdq xmm5,xmm3 ; xmm5=col2=(02 12 22 32 42 52 62 72)
punpckhqdq xmm7,xmm3 ; xmm7=col3=(03 13 23 33 43 53 63 73)
movdqa xmm1, XMMWORD [wk(0)] ; xmm1=(04 14 24 34 05 15 25 35)
movdqa xmm3, XMMWORD [wk(1)] ; xmm3=(06 16 26 36 07 17 27 37)
movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=col1
movdqa XMMWORD [wk(1)], xmm7 ; wk(1)=col3
movdqa xmm4,xmm1 ; transpose coefficients(phase 3)
punpcklqdq xmm1,xmm2 ; xmm1=col4=(04 14 24 34 44 54 64 74)
punpckhqdq xmm4,xmm2 ; xmm4=col5=(05 15 25 35 45 55 65 75)
movdqa xmm7,xmm3 ; transpose coefficients(phase 3)
punpcklqdq xmm3,xmm0 ; xmm3=col6=(06 16 26 36 46 56 66 76)
punpckhqdq xmm7,xmm0 ; xmm7=col7=(07 17 27 37 47 57 67 77)
.column_end:
; -- Prefetch the next coefficient block
prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 0*32]
prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 1*32]
prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 2*32]
prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 3*32]
; ---- Pass 2: process rows from work array, store into output array.
mov rax, [original_rbp]
mov rdi, r12 ; (JSAMPROW *)
mov rax, r13
; -- Even part
; xmm6=col0, xmm5=col2, xmm1=col4, xmm3=col6
movdqa xmm2,xmm6
movdqa xmm0,xmm5
psubw xmm6,xmm1 ; xmm6=tmp11
psubw xmm5,xmm3
paddw xmm2,xmm1 ; xmm2=tmp10
paddw xmm0,xmm3 ; xmm0=tmp13
psllw xmm5,PRE_MULTIPLY_SCALE_BITS
pmulhw xmm5,[rel PW_F1414]
psubw xmm5,xmm0 ; xmm5=tmp12
movdqa xmm1,xmm2
movdqa xmm3,xmm6
psubw xmm2,xmm0 ; xmm2=tmp3
psubw xmm6,xmm5 ; xmm6=tmp2
paddw xmm1,xmm0 ; xmm1=tmp0
paddw xmm3,xmm5 ; xmm3=tmp1
movdqa xmm0, XMMWORD [wk(0)] ; xmm0=col1
movdqa xmm5, XMMWORD [wk(1)] ; xmm5=col3
movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=tmp3
movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=tmp2
; -- Odd part
; xmm0=col1, xmm5=col3, xmm4=col5, xmm7=col7
movdqa xmm2,xmm0
movdqa xmm6,xmm4
psubw xmm0,xmm7 ; xmm0=z12
psubw xmm4,xmm5 ; xmm4=z10
paddw xmm2,xmm7 ; xmm2=z11
paddw xmm6,xmm5 ; xmm6=z13
movdqa xmm7,xmm4 ; xmm7=z10(unscaled)
psllw xmm0,PRE_MULTIPLY_SCALE_BITS
psllw xmm4,PRE_MULTIPLY_SCALE_BITS
movdqa xmm5,xmm2
psubw xmm2,xmm6
paddw xmm5,xmm6 ; xmm5=tmp7
psllw xmm2,PRE_MULTIPLY_SCALE_BITS
pmulhw xmm2,[rel PW_F1414] ; xmm2=tmp11
; To avoid overflow...
;
; (Original)
; tmp12 = -2.613125930 * z10 + z5;
;
; (This implementation)
; tmp12 = (-1.613125930 - 1) * z10 + z5;
; = -1.613125930 * z10 - z10 + z5;
movdqa xmm6,xmm4
paddw xmm4,xmm0
pmulhw xmm4,[rel PW_F1847] ; xmm4=z5
pmulhw xmm6,[rel PW_MF1613]
pmulhw xmm0,[rel PW_F1082]
psubw xmm6,xmm7
psubw xmm0,xmm4 ; xmm0=tmp10
paddw xmm6,xmm4 ; xmm6=tmp12
; -- Final output stage
psubw xmm6,xmm5 ; xmm6=tmp6
movdqa xmm7,xmm1
movdqa xmm4,xmm3
paddw xmm1,xmm5 ; xmm1=data0=(00 10 20 30 40 50 60 70)
paddw xmm3,xmm6 ; xmm3=data1=(01 11 21 31 41 51 61 71)
psraw xmm1,(PASS1_BITS+3) ; descale
psraw xmm3,(PASS1_BITS+3) ; descale
psubw xmm7,xmm5 ; xmm7=data7=(07 17 27 37 47 57 67 77)
psubw xmm4,xmm6 ; xmm4=data6=(06 16 26 36 46 56 66 76)
psraw xmm7,(PASS1_BITS+3) ; descale
psraw xmm4,(PASS1_BITS+3) ; descale
psubw xmm2,xmm6 ; xmm2=tmp5
packsswb xmm1,xmm4 ; xmm1=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76)
packsswb xmm3,xmm7 ; xmm3=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77)
movdqa xmm5, XMMWORD [wk(1)] ; xmm5=tmp2
movdqa xmm6, XMMWORD [wk(0)] ; xmm6=tmp3
paddw xmm0,xmm2 ; xmm0=tmp4
movdqa xmm4,xmm5
movdqa xmm7,xmm6
paddw xmm5,xmm2 ; xmm5=data2=(02 12 22 32 42 52 62 72)
paddw xmm6,xmm0 ; xmm6=data4=(04 14 24 34 44 54 64 74)
psraw xmm5,(PASS1_BITS+3) ; descale
psraw xmm6,(PASS1_BITS+3) ; descale
psubw xmm4,xmm2 ; xmm4=data5=(05 15 25 35 45 55 65 75)
psubw xmm7,xmm0 ; xmm7=data3=(03 13 23 33 43 53 63 73)
psraw xmm4,(PASS1_BITS+3) ; descale
psraw xmm7,(PASS1_BITS+3) ; descale
movdqa xmm2,[rel PB_CENTERJSAMP] ; xmm2=[rel PB_CENTERJSAMP]
packsswb xmm5,xmm6 ; xmm5=(02 12 22 32 42 52 62 72 04 14 24 34 44 54 64 74)
packsswb xmm7,xmm4 ; xmm7=(03 13 23 33 43 53 63 73 05 15 25 35 45 55 65 75)
paddb xmm1,xmm2
paddb xmm3,xmm2
paddb xmm5,xmm2
paddb xmm7,xmm2
movdqa xmm0,xmm1 ; transpose coefficients(phase 1)
punpcklbw xmm1,xmm3 ; xmm1=(00 01 10 11 20 21 30 31 40 41 50 51 60 61 70 71)
punpckhbw xmm0,xmm3 ; xmm0=(06 07 16 17 26 27 36 37 46 47 56 57 66 67 76 77)
movdqa xmm6,xmm5 ; transpose coefficients(phase 1)
punpcklbw xmm5,xmm7 ; xmm5=(02 03 12 13 22 23 32 33 42 43 52 53 62 63 72 73)
punpckhbw xmm6,xmm7 ; xmm6=(04 05 14 15 24 25 34 35 44 45 54 55 64 65 74 75)
movdqa xmm4,xmm1 ; transpose coefficients(phase 2)
punpcklwd xmm1,xmm5 ; xmm1=(00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33)
punpckhwd xmm4,xmm5 ; xmm4=(40 41 42 43 50 51 52 53 60 61 62 63 70 71 72 73)
movdqa xmm2,xmm6 ; transpose coefficients(phase 2)
punpcklwd xmm6,xmm0 ; xmm6=(04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37)
punpckhwd xmm2,xmm0 ; xmm2=(44 45 46 47 54 55 56 57 64 65 66 67 74 75 76 77)
movdqa xmm3,xmm1 ; transpose coefficients(phase 3)
punpckldq xmm1,xmm6 ; xmm1=(00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17)
punpckhdq xmm3,xmm6 ; xmm3=(20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37)
movdqa xmm7,xmm4 ; transpose coefficients(phase 3)
punpckldq xmm4,xmm2 ; xmm4=(40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57)
punpckhdq xmm7,xmm2 ; xmm7=(60 61 62 63 64 65 66 67 70 71 72 73 74 75 76 77)
pshufd xmm5,xmm1,0x4E ; xmm5=(10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07)
pshufd xmm0,xmm3,0x4E ; xmm0=(30 31 32 33 34 35 36 37 20 21 22 23 24 25 26 27)
pshufd xmm6,xmm4,0x4E ; xmm6=(50 51 52 53 54 55 56 57 40 41 42 43 44 45 46 47)
pshufd xmm2,xmm7,0x4E ; xmm2=(70 71 72 73 74 75 76 77 60 61 62 63 64 65 66 67)
mov rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW]
mov rsi, JSAMPROW [rdi+2*SIZEOF_JSAMPROW]
movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm1
movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm3
mov rdx, JSAMPROW [rdi+4*SIZEOF_JSAMPROW]
mov rsi, JSAMPROW [rdi+6*SIZEOF_JSAMPROW]
movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm4
movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm7
mov rdx, JSAMPROW [rdi+1*SIZEOF_JSAMPROW]
mov rsi, JSAMPROW [rdi+3*SIZEOF_JSAMPROW]
movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm5
movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm0
mov rdx, JSAMPROW [rdi+5*SIZEOF_JSAMPROW]
mov rsi, JSAMPROW [rdi+7*SIZEOF_JSAMPROW]
movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm6
movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm2
uncollect_args
mov rsp,rbp ; rsp <- aligned rbp
pop rsp ; rsp <- original rbp
pop rbp
ret
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16
@@ -1,848 +0,0 @@
;
; jidctint.asm - accurate integer IDCT (64-bit SSE2)
;
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2009 D. R. Commander
;
; Based on
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; This file contains a slow-but-accurate integer implementation of the
; inverse DCT (Discrete Cosine Transform). The following code is based
; directly on the IJG's original jidctint.c; see the jidctint.c for
; more details.
;
; [TAB8]
%include "jsimdext.inc"
%include "jdct.inc"
; --------------------------------------------------------------------------
%define CONST_BITS 13
%define PASS1_BITS 2
%define DESCALE_P1 (CONST_BITS-PASS1_BITS)
%define DESCALE_P2 (CONST_BITS+PASS1_BITS+3)
%if CONST_BITS == 13
F_0_298 equ 2446 ; FIX(0.298631336)
F_0_390 equ 3196 ; FIX(0.390180644)
F_0_541 equ 4433 ; FIX(0.541196100)
F_0_765 equ 6270 ; FIX(0.765366865)
F_0_899 equ 7373 ; FIX(0.899976223)
F_1_175 equ 9633 ; FIX(1.175875602)
F_1_501 equ 12299 ; FIX(1.501321110)
F_1_847 equ 15137 ; FIX(1.847759065)
F_1_961 equ 16069 ; FIX(1.961570560)
F_2_053 equ 16819 ; FIX(2.053119869)
F_2_562 equ 20995 ; FIX(2.562915447)
F_3_072 equ 25172 ; FIX(3.072711026)
%else
; NASM cannot do compile-time arithmetic on floating-point constants.
%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n))
F_0_298 equ DESCALE( 320652955,30-CONST_BITS) ; FIX(0.298631336)
F_0_390 equ DESCALE( 418953276,30-CONST_BITS) ; FIX(0.390180644)
F_0_541 equ DESCALE( 581104887,30-CONST_BITS) ; FIX(0.541196100)
F_0_765 equ DESCALE( 821806413,30-CONST_BITS) ; FIX(0.765366865)
F_0_899 equ DESCALE( 966342111,30-CONST_BITS) ; FIX(0.899976223)
F_1_175 equ DESCALE(1262586813,30-CONST_BITS) ; FIX(1.175875602)
F_1_501 equ DESCALE(1612031267,30-CONST_BITS) ; FIX(1.501321110)
F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065)
F_1_961 equ DESCALE(2106220350,30-CONST_BITS) ; FIX(1.961570560)
F_2_053 equ DESCALE(2204520673,30-CONST_BITS) ; FIX(2.053119869)
F_2_562 equ DESCALE(2751909506,30-CONST_BITS) ; FIX(2.562915447)
F_3_072 equ DESCALE(3299298341,30-CONST_BITS) ; FIX(3.072711026)
%endif
; --------------------------------------------------------------------------
SECTION SEG_CONST
alignz 16
global EXTN(jconst_idct_islow_sse2)
EXTN(jconst_idct_islow_sse2):
PW_F130_F054 times 4 dw (F_0_541+F_0_765), F_0_541
PW_F054_MF130 times 4 dw F_0_541, (F_0_541-F_1_847)
PW_MF078_F117 times 4 dw (F_1_175-F_1_961), F_1_175
PW_F117_F078 times 4 dw F_1_175, (F_1_175-F_0_390)
PW_MF060_MF089 times 4 dw (F_0_298-F_0_899),-F_0_899
PW_MF089_F060 times 4 dw -F_0_899, (F_1_501-F_0_899)
PW_MF050_MF256 times 4 dw (F_2_053-F_2_562),-F_2_562
PW_MF256_F050 times 4 dw -F_2_562, (F_3_072-F_2_562)
PD_DESCALE_P1 times 4 dd 1 << (DESCALE_P1-1)
PD_DESCALE_P2 times 4 dd 1 << (DESCALE_P2-1)
PB_CENTERJSAMP times 16 db CENTERJSAMPLE
alignz 16
; --------------------------------------------------------------------------
SECTION SEG_TEXT
BITS 64
;
; Perform dequantization and inverse DCT on one block of coefficients.
;
; GLOBAL(void)
; jsimd_idct_islow_sse2 (void * dct_table, JCOEFPTR coef_block,
; JSAMPARRAY output_buf, JDIMENSION output_col)
;
; r10 = jpeg_component_info * compptr
; r11 = JCOEFPTR coef_block
; r12 = JSAMPARRAY output_buf
; r13 = JDIMENSION output_col
%define original_rbp rbp+0
%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 12
align 16
global EXTN(jsimd_idct_islow_sse2)
EXTN(jsimd_idct_islow_sse2):
push rbp
mov rax,rsp ; rax = original rbp
sub rsp, byte 4
and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [rsp],rax
mov rbp,rsp ; rbp = aligned rbp
lea rsp, [wk(0)]
collect_args
; ---- Pass 1: process columns from input.
mov rdx, r10 ; quantptr
mov rsi, r11 ; inptr
%ifndef NO_ZERO_COLUMN_TEST_ISLOW_SSE2
mov eax, DWORD [DWBLOCK(1,0,rsi,SIZEOF_JCOEF)]
or eax, DWORD [DWBLOCK(2,0,rsi,SIZEOF_JCOEF)]
jnz near .columnDCT
movdqa xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
movdqa xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
por xmm0, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
por xmm1, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_JCOEF)]
por xmm0, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
por xmm1, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
por xmm0, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
por xmm1,xmm0
packsswb xmm1,xmm1
packsswb xmm1,xmm1
movd eax,xmm1
test rax,rax
jnz short .columnDCT
; -- AC terms all zero
movdqa xmm5, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
pmullw xmm5, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
psllw xmm5,PASS1_BITS
movdqa xmm4,xmm5 ; xmm5=in0=(00 01 02 03 04 05 06 07)
punpcklwd xmm5,xmm5 ; xmm5=(00 00 01 01 02 02 03 03)
punpckhwd xmm4,xmm4 ; xmm4=(04 04 05 05 06 06 07 07)
pshufd xmm7,xmm5,0x00 ; xmm7=col0=(00 00 00 00 00 00 00 00)
pshufd xmm6,xmm5,0x55 ; xmm6=col1=(01 01 01 01 01 01 01 01)
pshufd xmm1,xmm5,0xAA ; xmm1=col2=(02 02 02 02 02 02 02 02)
pshufd xmm5,xmm5,0xFF ; xmm5=col3=(03 03 03 03 03 03 03 03)
pshufd xmm0,xmm4,0x00 ; xmm0=col4=(04 04 04 04 04 04 04 04)
pshufd xmm3,xmm4,0x55 ; xmm3=col5=(05 05 05 05 05 05 05 05)
pshufd xmm2,xmm4,0xAA ; xmm2=col6=(06 06 06 06 06 06 06 06)
pshufd xmm4,xmm4,0xFF ; xmm4=col7=(07 07 07 07 07 07 07 07)
movdqa XMMWORD [wk(8)], xmm6 ; wk(8)=col1
movdqa XMMWORD [wk(9)], xmm5 ; wk(9)=col3
movdqa XMMWORD [wk(10)], xmm3 ; wk(10)=col5
movdqa XMMWORD [wk(11)], xmm4 ; wk(11)=col7
jmp near .column_end
%endif
.columnDCT:
; -- Even part
movdqa xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
movdqa xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
pmullw xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
pmullw xmm1, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
movdqa xmm2, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_JCOEF)]
movdqa xmm3, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
pmullw xmm2, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
pmullw xmm3, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
; (Original)
; z1 = (z2 + z3) * 0.541196100;
; tmp2 = z1 + z3 * -1.847759065;
; tmp3 = z1 + z2 * 0.765366865;
;
; (This implementation)
; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065);
; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100;
movdqa xmm4,xmm1 ; xmm1=in2=z2
movdqa xmm5,xmm1
punpcklwd xmm4,xmm3 ; xmm3=in6=z3
punpckhwd xmm5,xmm3
movdqa xmm1,xmm4
movdqa xmm3,xmm5
pmaddwd xmm4,[rel PW_F130_F054] ; xmm4=tmp3L
pmaddwd xmm5,[rel PW_F130_F054] ; xmm5=tmp3H
pmaddwd xmm1,[rel PW_F054_MF130] ; xmm1=tmp2L
pmaddwd xmm3,[rel PW_F054_MF130] ; xmm3=tmp2H
movdqa xmm6,xmm0
paddw xmm0,xmm2 ; xmm0=in0+in4
psubw xmm6,xmm2 ; xmm6=in0-in4
pxor xmm7,xmm7
pxor xmm2,xmm2
punpcklwd xmm7,xmm0 ; xmm7=tmp0L
punpckhwd xmm2,xmm0 ; xmm2=tmp0H
psrad xmm7,(16-CONST_BITS) ; psrad xmm7,16 & pslld xmm7,CONST_BITS
psrad xmm2,(16-CONST_BITS) ; psrad xmm2,16 & pslld xmm2,CONST_BITS
movdqa xmm0,xmm7
paddd xmm7,xmm4 ; xmm7=tmp10L
psubd xmm0,xmm4 ; xmm0=tmp13L
movdqa xmm4,xmm2
paddd xmm2,xmm5 ; xmm2=tmp10H
psubd xmm4,xmm5 ; xmm4=tmp13H
movdqa XMMWORD [wk(0)], xmm7 ; wk(0)=tmp10L
movdqa XMMWORD [wk(1)], xmm2 ; wk(1)=tmp10H
movdqa XMMWORD [wk(2)], xmm0 ; wk(2)=tmp13L
movdqa XMMWORD [wk(3)], xmm4 ; wk(3)=tmp13H
pxor xmm5,xmm5
pxor xmm7,xmm7
punpcklwd xmm5,xmm6 ; xmm5=tmp1L
punpckhwd xmm7,xmm6 ; xmm7=tmp1H
psrad xmm5,(16-CONST_BITS) ; psrad xmm5,16 & pslld xmm5,CONST_BITS
psrad xmm7,(16-CONST_BITS) ; psrad xmm7,16 & pslld xmm7,CONST_BITS
movdqa xmm2,xmm5
paddd xmm5,xmm1 ; xmm5=tmp11L
psubd xmm2,xmm1 ; xmm2=tmp12L
movdqa xmm0,xmm7
paddd xmm7,xmm3 ; xmm7=tmp11H
psubd xmm0,xmm3 ; xmm0=tmp12H
movdqa XMMWORD [wk(4)], xmm5 ; wk(4)=tmp11L
movdqa XMMWORD [wk(5)], xmm7 ; wk(5)=tmp11H
movdqa XMMWORD [wk(6)], xmm2 ; wk(6)=tmp12L
movdqa XMMWORD [wk(7)], xmm0 ; wk(7)=tmp12H
; -- Odd part
movdqa xmm4, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
movdqa xmm6, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
pmullw xmm4, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
pmullw xmm6, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
movdqa xmm1, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
movdqa xmm3, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
pmullw xmm1, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
pmullw xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
movdqa xmm5,xmm6
movdqa xmm7,xmm4
paddw xmm5,xmm3 ; xmm5=z3
paddw xmm7,xmm1 ; xmm7=z4
; (Original)
; z5 = (z3 + z4) * 1.175875602;
; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644;
; z3 += z5; z4 += z5;
;
; (This implementation)
; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
movdqa xmm2,xmm5
movdqa xmm0,xmm5
punpcklwd xmm2,xmm7
punpckhwd xmm0,xmm7
movdqa xmm5,xmm2
movdqa xmm7,xmm0
pmaddwd xmm2,[rel PW_MF078_F117] ; xmm2=z3L
pmaddwd xmm0,[rel PW_MF078_F117] ; xmm0=z3H
pmaddwd xmm5,[rel PW_F117_F078] ; xmm5=z4L
pmaddwd xmm7,[rel PW_F117_F078] ; xmm7=z4H
movdqa XMMWORD [wk(10)], xmm2 ; wk(10)=z3L
movdqa XMMWORD [wk(11)], xmm0 ; wk(11)=z3H
; (Original)
; z1 = tmp0 + tmp3; z2 = tmp1 + tmp2;
; tmp0 = tmp0 * 0.298631336; tmp1 = tmp1 * 2.053119869;
; tmp2 = tmp2 * 3.072711026; tmp3 = tmp3 * 1.501321110;
; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447;
; tmp0 += z1 + z3; tmp1 += z2 + z4;
; tmp2 += z2 + z3; tmp3 += z1 + z4;
;
; (This implementation)
; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223;
; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447;
; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447);
; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223);
; tmp0 += z3; tmp1 += z4;
; tmp2 += z3; tmp3 += z4;
movdqa xmm2,xmm3
movdqa xmm0,xmm3
punpcklwd xmm2,xmm4
punpckhwd xmm0,xmm4
movdqa xmm3,xmm2
movdqa xmm4,xmm0
pmaddwd xmm2,[rel PW_MF060_MF089] ; xmm2=tmp0L
pmaddwd xmm0,[rel PW_MF060_MF089] ; xmm0=tmp0H
pmaddwd xmm3,[rel PW_MF089_F060] ; xmm3=tmp3L
pmaddwd xmm4,[rel PW_MF089_F060] ; xmm4=tmp3H
paddd xmm2, XMMWORD [wk(10)] ; xmm2=tmp0L
paddd xmm0, XMMWORD [wk(11)] ; xmm0=tmp0H
paddd xmm3,xmm5 ; xmm3=tmp3L
paddd xmm4,xmm7 ; xmm4=tmp3H
movdqa XMMWORD [wk(8)], xmm2 ; wk(8)=tmp0L
movdqa XMMWORD [wk(9)], xmm0 ; wk(9)=tmp0H
movdqa xmm2,xmm1
movdqa xmm0,xmm1
punpcklwd xmm2,xmm6
punpckhwd xmm0,xmm6
movdqa xmm1,xmm2
movdqa xmm6,xmm0
pmaddwd xmm2,[rel PW_MF050_MF256] ; xmm2=tmp1L
pmaddwd xmm0,[rel PW_MF050_MF256] ; xmm0=tmp1H
pmaddwd xmm1,[rel PW_MF256_F050] ; xmm1=tmp2L
pmaddwd xmm6,[rel PW_MF256_F050] ; xmm6=tmp2H
paddd xmm2,xmm5 ; xmm2=tmp1L
paddd xmm0,xmm7 ; xmm0=tmp1H
paddd xmm1, XMMWORD [wk(10)] ; xmm1=tmp2L
paddd xmm6, XMMWORD [wk(11)] ; xmm6=tmp2H
movdqa XMMWORD [wk(10)], xmm2 ; wk(10)=tmp1L
movdqa XMMWORD [wk(11)], xmm0 ; wk(11)=tmp1H
; -- Final output stage
movdqa xmm5, XMMWORD [wk(0)] ; xmm5=tmp10L
movdqa xmm7, XMMWORD [wk(1)] ; xmm7=tmp10H
movdqa xmm2,xmm5
movdqa xmm0,xmm7
paddd xmm5,xmm3 ; xmm5=data0L
paddd xmm7,xmm4 ; xmm7=data0H
psubd xmm2,xmm3 ; xmm2=data7L
psubd xmm0,xmm4 ; xmm0=data7H
movdqa xmm3,[rel PD_DESCALE_P1] ; xmm3=[rel PD_DESCALE_P1]
paddd xmm5,xmm3
paddd xmm7,xmm3
psrad xmm5,DESCALE_P1
psrad xmm7,DESCALE_P1
paddd xmm2,xmm3
paddd xmm0,xmm3
psrad xmm2,DESCALE_P1
psrad xmm0,DESCALE_P1
packssdw xmm5,xmm7 ; xmm5=data0=(00 01 02 03 04 05 06 07)
packssdw xmm2,xmm0 ; xmm2=data7=(70 71 72 73 74 75 76 77)
movdqa xmm4, XMMWORD [wk(4)] ; xmm4=tmp11L
movdqa xmm3, XMMWORD [wk(5)] ; xmm3=tmp11H
movdqa xmm7,xmm4
movdqa xmm0,xmm3
paddd xmm4,xmm1 ; xmm4=data1L
paddd xmm3,xmm6 ; xmm3=data1H
psubd xmm7,xmm1 ; xmm7=data6L
psubd xmm0,xmm6 ; xmm0=data6H
movdqa xmm1,[rel PD_DESCALE_P1] ; xmm1=[rel PD_DESCALE_P1]
paddd xmm4,xmm1
paddd xmm3,xmm1
psrad xmm4,DESCALE_P1
psrad xmm3,DESCALE_P1
paddd xmm7,xmm1
paddd xmm0,xmm1
psrad xmm7,DESCALE_P1
psrad xmm0,DESCALE_P1
packssdw xmm4,xmm3 ; xmm4=data1=(10 11 12 13 14 15 16 17)
packssdw xmm7,xmm0 ; xmm7=data6=(60 61 62 63 64 65 66 67)
movdqa xmm6,xmm5 ; transpose coefficients(phase 1)
punpcklwd xmm5,xmm4 ; xmm5=(00 10 01 11 02 12 03 13)
punpckhwd xmm6,xmm4 ; xmm6=(04 14 05 15 06 16 07 17)
movdqa xmm1,xmm7 ; transpose coefficients(phase 1)
punpcklwd xmm7,xmm2 ; xmm7=(60 70 61 71 62 72 63 73)
punpckhwd xmm1,xmm2 ; xmm1=(64 74 65 75 66 76 67 77)
movdqa xmm3, XMMWORD [wk(6)] ; xmm3=tmp12L
movdqa xmm0, XMMWORD [wk(7)] ; xmm0=tmp12H
movdqa xmm4, XMMWORD [wk(10)] ; xmm4=tmp1L
movdqa xmm2, XMMWORD [wk(11)] ; xmm2=tmp1H
movdqa XMMWORD [wk(0)], xmm5 ; wk(0)=(00 10 01 11 02 12 03 13)
movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=(04 14 05 15 06 16 07 17)
movdqa XMMWORD [wk(4)], xmm7 ; wk(4)=(60 70 61 71 62 72 63 73)
movdqa XMMWORD [wk(5)], xmm1 ; wk(5)=(64 74 65 75 66 76 67 77)
movdqa xmm5,xmm3
movdqa xmm6,xmm0
paddd xmm3,xmm4 ; xmm3=data2L
paddd xmm0,xmm2 ; xmm0=data2H
psubd xmm5,xmm4 ; xmm5=data5L
psubd xmm6,xmm2 ; xmm6=data5H
movdqa xmm7,[rel PD_DESCALE_P1] ; xmm7=[rel PD_DESCALE_P1]
paddd xmm3,xmm7
paddd xmm0,xmm7
psrad xmm3,DESCALE_P1
psrad xmm0,DESCALE_P1
paddd xmm5,xmm7
paddd xmm6,xmm7
psrad xmm5,DESCALE_P1
psrad xmm6,DESCALE_P1
packssdw xmm3,xmm0 ; xmm3=data2=(20 21 22 23 24 25 26 27)
packssdw xmm5,xmm6 ; xmm5=data5=(50 51 52 53 54 55 56 57)
movdqa xmm1, XMMWORD [wk(2)] ; xmm1=tmp13L
movdqa xmm4, XMMWORD [wk(3)] ; xmm4=tmp13H
movdqa xmm2, XMMWORD [wk(8)] ; xmm2=tmp0L
movdqa xmm7, XMMWORD [wk(9)] ; xmm7=tmp0H
movdqa xmm0,xmm1
movdqa xmm6,xmm4
paddd xmm1,xmm2 ; xmm1=data3L
paddd xmm4,xmm7 ; xmm4=data3H
psubd xmm0,xmm2 ; xmm0=data4L
psubd xmm6,xmm7 ; xmm6=data4H
movdqa xmm2,[rel PD_DESCALE_P1] ; xmm2=[rel PD_DESCALE_P1]
paddd xmm1,xmm2
paddd xmm4,xmm2
psrad xmm1,DESCALE_P1
psrad xmm4,DESCALE_P1
paddd xmm0,xmm2
paddd xmm6,xmm2
psrad xmm0,DESCALE_P1
psrad xmm6,DESCALE_P1
packssdw xmm1,xmm4 ; xmm1=data3=(30 31 32 33 34 35 36 37)
packssdw xmm0,xmm6 ; xmm0=data4=(40 41 42 43 44 45 46 47)
movdqa xmm7, XMMWORD [wk(0)] ; xmm7=(00 10 01 11 02 12 03 13)
movdqa xmm2, XMMWORD [wk(1)] ; xmm2=(04 14 05 15 06 16 07 17)
movdqa xmm4,xmm3 ; transpose coefficients(phase 1)
punpcklwd xmm3,xmm1 ; xmm3=(20 30 21 31 22 32 23 33)
punpckhwd xmm4,xmm1 ; xmm4=(24 34 25 35 26 36 27 37)
movdqa xmm6,xmm0 ; transpose coefficients(phase 1)
punpcklwd xmm0,xmm5 ; xmm0=(40 50 41 51 42 52 43 53)
punpckhwd xmm6,xmm5 ; xmm6=(44 54 45 55 46 56 47 57)
movdqa xmm1,xmm7 ; transpose coefficients(phase 2)
punpckldq xmm7,xmm3 ; xmm7=(00 10 20 30 01 11 21 31)
punpckhdq xmm1,xmm3 ; xmm1=(02 12 22 32 03 13 23 33)
movdqa xmm5,xmm2 ; transpose coefficients(phase 2)
punpckldq xmm2,xmm4 ; xmm2=(04 14 24 34 05 15 25 35)
punpckhdq xmm5,xmm4 ; xmm5=(06 16 26 36 07 17 27 37)
movdqa xmm3, XMMWORD [wk(4)] ; xmm3=(60 70 61 71 62 72 63 73)
movdqa xmm4, XMMWORD [wk(5)] ; xmm4=(64 74 65 75 66 76 67 77)
movdqa XMMWORD [wk(6)], xmm2 ; wk(6)=(04 14 24 34 05 15 25 35)
movdqa XMMWORD [wk(7)], xmm5 ; wk(7)=(06 16 26 36 07 17 27 37)
movdqa xmm2,xmm0 ; transpose coefficients(phase 2)
punpckldq xmm0,xmm3 ; xmm0=(40 50 60 70 41 51 61 71)
punpckhdq xmm2,xmm3 ; xmm2=(42 52 62 72 43 53 63 73)
movdqa xmm5,xmm6 ; transpose coefficients(phase 2)
punpckldq xmm6,xmm4 ; xmm6=(44 54 64 74 45 55 65 75)
punpckhdq xmm5,xmm4 ; xmm5=(46 56 66 76 47 57 67 77)
movdqa xmm3,xmm7 ; transpose coefficients(phase 3)
punpcklqdq xmm7,xmm0 ; xmm7=col0=(00 10 20 30 40 50 60 70)
punpckhqdq xmm3,xmm0 ; xmm3=col1=(01 11 21 31 41 51 61 71)
movdqa xmm4,xmm1 ; transpose coefficients(phase 3)
punpcklqdq xmm1,xmm2 ; xmm1=col2=(02 12 22 32 42 52 62 72)
punpckhqdq xmm4,xmm2 ; xmm4=col3=(03 13 23 33 43 53 63 73)
movdqa xmm0, XMMWORD [wk(6)] ; xmm0=(04 14 24 34 05 15 25 35)
movdqa xmm2, XMMWORD [wk(7)] ; xmm2=(06 16 26 36 07 17 27 37)
movdqa XMMWORD [wk(8)], xmm3 ; wk(8)=col1
movdqa XMMWORD [wk(9)], xmm4 ; wk(9)=col3
movdqa xmm3,xmm0 ; transpose coefficients(phase 3)
punpcklqdq xmm0,xmm6 ; xmm0=col4=(04 14 24 34 44 54 64 74)
punpckhqdq xmm3,xmm6 ; xmm3=col5=(05 15 25 35 45 55 65 75)
movdqa xmm4,xmm2 ; transpose coefficients(phase 3)
punpcklqdq xmm2,xmm5 ; xmm2=col6=(06 16 26 36 46 56 66 76)
punpckhqdq xmm4,xmm5 ; xmm4=col7=(07 17 27 37 47 57 67 77)
movdqa XMMWORD [wk(10)], xmm3 ; wk(10)=col5
movdqa XMMWORD [wk(11)], xmm4 ; wk(11)=col7
.column_end:
; -- Prefetch the next coefficient block
prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 0*32]
prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 1*32]
prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 2*32]
prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 3*32]
; ---- Pass 2: process rows from work array, store into output array.
mov rax, [original_rbp]
mov rdi, r12 ; (JSAMPROW *)
mov rax, r13
; -- Even part
; xmm7=col0, xmm1=col2, xmm0=col4, xmm2=col6
; (Original)
; z1 = (z2 + z3) * 0.541196100;
; tmp2 = z1 + z3 * -1.847759065;
; tmp3 = z1 + z2 * 0.765366865;
;
; (This implementation)
; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065);
; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100;
movdqa xmm6,xmm1 ; xmm1=in2=z2
movdqa xmm5,xmm1
punpcklwd xmm6,xmm2 ; xmm2=in6=z3
punpckhwd xmm5,xmm2
movdqa xmm1,xmm6
movdqa xmm2,xmm5
pmaddwd xmm6,[rel PW_F130_F054] ; xmm6=tmp3L
pmaddwd xmm5,[rel PW_F130_F054] ; xmm5=tmp3H
pmaddwd xmm1,[rel PW_F054_MF130] ; xmm1=tmp2L
pmaddwd xmm2,[rel PW_F054_MF130] ; xmm2=tmp2H
movdqa xmm3,xmm7
paddw xmm7,xmm0 ; xmm7=in0+in4
psubw xmm3,xmm0 ; xmm3=in0-in4
pxor xmm4,xmm4
pxor xmm0,xmm0
punpcklwd xmm4,xmm7 ; xmm4=tmp0L
punpckhwd xmm0,xmm7 ; xmm0=tmp0H
psrad xmm4,(16-CONST_BITS) ; psrad xmm4,16 & pslld xmm4,CONST_BITS
psrad xmm0,(16-CONST_BITS) ; psrad xmm0,16 & pslld xmm0,CONST_BITS
movdqa xmm7,xmm4
paddd xmm4,xmm6 ; xmm4=tmp10L
psubd xmm7,xmm6 ; xmm7=tmp13L
movdqa xmm6,xmm0
paddd xmm0,xmm5 ; xmm0=tmp10H
psubd xmm6,xmm5 ; xmm6=tmp13H
movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=tmp10L
movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=tmp10H
movdqa XMMWORD [wk(2)], xmm7 ; wk(2)=tmp13L
movdqa XMMWORD [wk(3)], xmm6 ; wk(3)=tmp13H
pxor xmm5,xmm5
pxor xmm4,xmm4
punpcklwd xmm5,xmm3 ; xmm5=tmp1L
punpckhwd xmm4,xmm3 ; xmm4=tmp1H
psrad xmm5,(16-CONST_BITS) ; psrad xmm5,16 & pslld xmm5,CONST_BITS
psrad xmm4,(16-CONST_BITS) ; psrad xmm4,16 & pslld xmm4,CONST_BITS
movdqa xmm0,xmm5
paddd xmm5,xmm1 ; xmm5=tmp11L
psubd xmm0,xmm1 ; xmm0=tmp12L
movdqa xmm7,xmm4
paddd xmm4,xmm2 ; xmm4=tmp11H
psubd xmm7,xmm2 ; xmm7=tmp12H
movdqa XMMWORD [wk(4)], xmm5 ; wk(4)=tmp11L
movdqa XMMWORD [wk(5)], xmm4 ; wk(5)=tmp11H
movdqa XMMWORD [wk(6)], xmm0 ; wk(6)=tmp12L
movdqa XMMWORD [wk(7)], xmm7 ; wk(7)=tmp12H
; -- Odd part
movdqa xmm6, XMMWORD [wk(9)] ; xmm6=col3
movdqa xmm3, XMMWORD [wk(8)] ; xmm3=col1
movdqa xmm1, XMMWORD [wk(11)] ; xmm1=col7
movdqa xmm2, XMMWORD [wk(10)] ; xmm2=col5
movdqa xmm5,xmm6
movdqa xmm4,xmm3
paddw xmm5,xmm1 ; xmm5=z3
paddw xmm4,xmm2 ; xmm4=z4
; (Original)
; z5 = (z3 + z4) * 1.175875602;
; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644;
; z3 += z5; z4 += z5;
;
; (This implementation)
; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
movdqa xmm0,xmm5
movdqa xmm7,xmm5
punpcklwd xmm0,xmm4
punpckhwd xmm7,xmm4
movdqa xmm5,xmm0
movdqa xmm4,xmm7
pmaddwd xmm0,[rel PW_MF078_F117] ; xmm0=z3L
pmaddwd xmm7,[rel PW_MF078_F117] ; xmm7=z3H
pmaddwd xmm5,[rel PW_F117_F078] ; xmm5=z4L
pmaddwd xmm4,[rel PW_F117_F078] ; xmm4=z4H
movdqa XMMWORD [wk(10)], xmm0 ; wk(10)=z3L
movdqa XMMWORD [wk(11)], xmm7 ; wk(11)=z3H
; (Original)
; z1 = tmp0 + tmp3; z2 = tmp1 + tmp2;
; tmp0 = tmp0 * 0.298631336; tmp1 = tmp1 * 2.053119869;
; tmp2 = tmp2 * 3.072711026; tmp3 = tmp3 * 1.501321110;
; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447;
; tmp0 += z1 + z3; tmp1 += z2 + z4;
; tmp2 += z2 + z3; tmp3 += z1 + z4;
;
; (This implementation)
; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223;
; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447;
; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447);
; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223);
; tmp0 += z3; tmp1 += z4;
; tmp2 += z3; tmp3 += z4;
movdqa xmm0,xmm1
movdqa xmm7,xmm1
punpcklwd xmm0,xmm3
punpckhwd xmm7,xmm3
movdqa xmm1,xmm0
movdqa xmm3,xmm7
pmaddwd xmm0,[rel PW_MF060_MF089] ; xmm0=tmp0L
pmaddwd xmm7,[rel PW_MF060_MF089] ; xmm7=tmp0H
pmaddwd xmm1,[rel PW_MF089_F060] ; xmm1=tmp3L
pmaddwd xmm3,[rel PW_MF089_F060] ; xmm3=tmp3H
paddd xmm0, XMMWORD [wk(10)] ; xmm0=tmp0L
paddd xmm7, XMMWORD [wk(11)] ; xmm7=tmp0H
paddd xmm1,xmm5 ; xmm1=tmp3L
paddd xmm3,xmm4 ; xmm3=tmp3H
movdqa XMMWORD [wk(8)], xmm0 ; wk(8)=tmp0L
movdqa XMMWORD [wk(9)], xmm7 ; wk(9)=tmp0H
movdqa xmm0,xmm2
movdqa xmm7,xmm2
punpcklwd xmm0,xmm6
punpckhwd xmm7,xmm6
movdqa xmm2,xmm0
movdqa xmm6,xmm7
pmaddwd xmm0,[rel PW_MF050_MF256] ; xmm0=tmp1L
pmaddwd xmm7,[rel PW_MF050_MF256] ; xmm7=tmp1H
pmaddwd xmm2,[rel PW_MF256_F050] ; xmm2=tmp2L
pmaddwd xmm6,[rel PW_MF256_F050] ; xmm6=tmp2H
paddd xmm0,xmm5 ; xmm0=tmp1L
paddd xmm7,xmm4 ; xmm7=tmp1H
paddd xmm2, XMMWORD [wk(10)] ; xmm2=tmp2L
paddd xmm6, XMMWORD [wk(11)] ; xmm6=tmp2H
movdqa XMMWORD [wk(10)], xmm0 ; wk(10)=tmp1L
movdqa XMMWORD [wk(11)], xmm7 ; wk(11)=tmp1H
; -- Final output stage
movdqa xmm5, XMMWORD [wk(0)] ; xmm5=tmp10L
movdqa xmm4, XMMWORD [wk(1)] ; xmm4=tmp10H
movdqa xmm0,xmm5
movdqa xmm7,xmm4
paddd xmm5,xmm1 ; xmm5=data0L
paddd xmm4,xmm3 ; xmm4=data0H
psubd xmm0,xmm1 ; xmm0=data7L
psubd xmm7,xmm3 ; xmm7=data7H
movdqa xmm1,[rel PD_DESCALE_P2] ; xmm1=[rel PD_DESCALE_P2]
paddd xmm5,xmm1
paddd xmm4,xmm1
psrad xmm5,DESCALE_P2
psrad xmm4,DESCALE_P2
paddd xmm0,xmm1
paddd xmm7,xmm1
psrad xmm0,DESCALE_P2
psrad xmm7,DESCALE_P2
packssdw xmm5,xmm4 ; xmm5=data0=(00 10 20 30 40 50 60 70)
packssdw xmm0,xmm7 ; xmm0=data7=(07 17 27 37 47 57 67 77)
movdqa xmm3, XMMWORD [wk(4)] ; xmm3=tmp11L
movdqa xmm1, XMMWORD [wk(5)] ; xmm1=tmp11H
movdqa xmm4,xmm3
movdqa xmm7,xmm1
paddd xmm3,xmm2 ; xmm3=data1L
paddd xmm1,xmm6 ; xmm1=data1H
psubd xmm4,xmm2 ; xmm4=data6L
psubd xmm7,xmm6 ; xmm7=data6H
movdqa xmm2,[rel PD_DESCALE_P2] ; xmm2=[rel PD_DESCALE_P2]
paddd xmm3,xmm2
paddd xmm1,xmm2
psrad xmm3,DESCALE_P2
psrad xmm1,DESCALE_P2
paddd xmm4,xmm2
paddd xmm7,xmm2
psrad xmm4,DESCALE_P2
psrad xmm7,DESCALE_P2
packssdw xmm3,xmm1 ; xmm3=data1=(01 11 21 31 41 51 61 71)
packssdw xmm4,xmm7 ; xmm4=data6=(06 16 26 36 46 56 66 76)
packsswb xmm5,xmm4 ; xmm5=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76)
packsswb xmm3,xmm0 ; xmm3=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77)
movdqa xmm6, XMMWORD [wk(6)] ; xmm6=tmp12L
movdqa xmm2, XMMWORD [wk(7)] ; xmm2=tmp12H
movdqa xmm1, XMMWORD [wk(10)] ; xmm1=tmp1L
movdqa xmm7, XMMWORD [wk(11)] ; xmm7=tmp1H
movdqa XMMWORD [wk(0)], xmm5 ; wk(0)=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76)
movdqa XMMWORD [wk(1)], xmm3 ; wk(1)=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77)
movdqa xmm4,xmm6
movdqa xmm0,xmm2
paddd xmm6,xmm1 ; xmm6=data2L
paddd xmm2,xmm7 ; xmm2=data2H
psubd xmm4,xmm1 ; xmm4=data5L
psubd xmm0,xmm7 ; xmm0=data5H
movdqa xmm5,[rel PD_DESCALE_P2] ; xmm5=[rel PD_DESCALE_P2]
paddd xmm6,xmm5
paddd xmm2,xmm5
psrad xmm6,DESCALE_P2
psrad xmm2,DESCALE_P2
paddd xmm4,xmm5
paddd xmm0,xmm5
psrad xmm4,DESCALE_P2
psrad xmm0,DESCALE_P2
packssdw xmm6,xmm2 ; xmm6=data2=(02 12 22 32 42 52 62 72)
packssdw xmm4,xmm0 ; xmm4=data5=(05 15 25 35 45 55 65 75)
movdqa xmm3, XMMWORD [wk(2)] ; xmm3=tmp13L
movdqa xmm1, XMMWORD [wk(3)] ; xmm1=tmp13H
movdqa xmm7, XMMWORD [wk(8)] ; xmm7=tmp0L
movdqa xmm5, XMMWORD [wk(9)] ; xmm5=tmp0H
movdqa xmm2,xmm3
movdqa xmm0,xmm1
paddd xmm3,xmm7 ; xmm3=data3L
paddd xmm1,xmm5 ; xmm1=data3H
psubd xmm2,xmm7 ; xmm2=data4L
psubd xmm0,xmm5 ; xmm0=data4H
movdqa xmm7,[rel PD_DESCALE_P2] ; xmm7=[rel PD_DESCALE_P2]
paddd xmm3,xmm7
paddd xmm1,xmm7
psrad xmm3,DESCALE_P2
psrad xmm1,DESCALE_P2
paddd xmm2,xmm7
paddd xmm0,xmm7
psrad xmm2,DESCALE_P2
psrad xmm0,DESCALE_P2
movdqa xmm5,[rel PB_CENTERJSAMP] ; xmm5=[rel PB_CENTERJSAMP]
packssdw xmm3,xmm1 ; xmm3=data3=(03 13 23 33 43 53 63 73)
packssdw xmm2,xmm0 ; xmm2=data4=(04 14 24 34 44 54 64 74)
movdqa xmm7, XMMWORD [wk(0)] ; xmm7=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76)
movdqa xmm1, XMMWORD [wk(1)] ; xmm1=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77)
packsswb xmm6,xmm2 ; xmm6=(02 12 22 32 42 52 62 72 04 14 24 34 44 54 64 74)
packsswb xmm3,xmm4 ; xmm3=(03 13 23 33 43 53 63 73 05 15 25 35 45 55 65 75)
paddb xmm7,xmm5
paddb xmm1,xmm5
paddb xmm6,xmm5
paddb xmm3,xmm5
movdqa xmm0,xmm7 ; transpose coefficients(phase 1)
punpcklbw xmm7,xmm1 ; xmm7=(00 01 10 11 20 21 30 31 40 41 50 51 60 61 70 71)
punpckhbw xmm0,xmm1 ; xmm0=(06 07 16 17 26 27 36 37 46 47 56 57 66 67 76 77)
movdqa xmm2,xmm6 ; transpose coefficients(phase 1)
punpcklbw xmm6,xmm3 ; xmm6=(02 03 12 13 22 23 32 33 42 43 52 53 62 63 72 73)
punpckhbw xmm2,xmm3 ; xmm2=(04 05 14 15 24 25 34 35 44 45 54 55 64 65 74 75)
movdqa xmm4,xmm7 ; transpose coefficients(phase 2)
punpcklwd xmm7,xmm6 ; xmm7=(00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33)
punpckhwd xmm4,xmm6 ; xmm4=(40 41 42 43 50 51 52 53 60 61 62 63 70 71 72 73)
movdqa xmm5,xmm2 ; transpose coefficients(phase 2)
punpcklwd xmm2,xmm0 ; xmm2=(04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37)
punpckhwd xmm5,xmm0 ; xmm5=(44 45 46 47 54 55 56 57 64 65 66 67 74 75 76 77)
movdqa xmm1,xmm7 ; transpose coefficients(phase 3)
punpckldq xmm7,xmm2 ; xmm7=(00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17)
punpckhdq xmm1,xmm2 ; xmm1=(20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37)
movdqa xmm3,xmm4 ; transpose coefficients(phase 3)
punpckldq xmm4,xmm5 ; xmm4=(40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57)
punpckhdq xmm3,xmm5 ; xmm3=(60 61 62 63 64 65 66 67 70 71 72 73 74 75 76 77)
pshufd xmm6,xmm7,0x4E ; xmm6=(10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07)
pshufd xmm0,xmm1,0x4E ; xmm0=(30 31 32 33 34 35 36 37 20 21 22 23 24 25 26 27)
pshufd xmm2,xmm4,0x4E ; xmm2=(50 51 52 53 54 55 56 57 40 41 42 43 44 45 46 47)
pshufd xmm5,xmm3,0x4E ; xmm5=(70 71 72 73 74 75 76 77 60 61 62 63 64 65 66 67)
mov rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW]
mov rsi, JSAMPROW [rdi+2*SIZEOF_JSAMPROW]
movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm7
movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm1
mov rdx, JSAMPROW [rdi+4*SIZEOF_JSAMPROW]
mov rsi, JSAMPROW [rdi+6*SIZEOF_JSAMPROW]
movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm4
movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm3
mov rdx, JSAMPROW [rdi+1*SIZEOF_JSAMPROW]
mov rsi, JSAMPROW [rdi+3*SIZEOF_JSAMPROW]
movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm6
movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm0
mov rdx, JSAMPROW [rdi+5*SIZEOF_JSAMPROW]
mov rsi, JSAMPROW [rdi+7*SIZEOF_JSAMPROW]
movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm2
movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm5
uncollect_args
mov rsp,rbp ; rsp <- aligned rbp
pop rsp ; rsp <- original rbp
pop rbp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16
@@ -1,576 +0,0 @@
;
; jidctred.asm - reduced-size IDCT (64-bit SSE2)
;
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2009 D. R. Commander
;
; Based on
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; This file contains inverse-DCT routines that produce reduced-size
; output: either 4x4 or 2x2 pixels from an 8x8 DCT block.
; The following code is based directly on the IJG's original jidctred.c;
; see the jidctred.c for more details.
;
; [TAB8]
%include "jsimdext.inc"
%include "jdct.inc"
; --------------------------------------------------------------------------
%define CONST_BITS 13
%define PASS1_BITS 2
%define DESCALE_P1_4 (CONST_BITS-PASS1_BITS+1)
%define DESCALE_P2_4 (CONST_BITS+PASS1_BITS+3+1)
%define DESCALE_P1_2 (CONST_BITS-PASS1_BITS+2)
%define DESCALE_P2_2 (CONST_BITS+PASS1_BITS+3+2)
%if CONST_BITS == 13
F_0_211 equ 1730 ; FIX(0.211164243)
F_0_509 equ 4176 ; FIX(0.509795579)
F_0_601 equ 4926 ; FIX(0.601344887)
F_0_720 equ 5906 ; FIX(0.720959822)
F_0_765 equ 6270 ; FIX(0.765366865)
F_0_850 equ 6967 ; FIX(0.850430095)
F_0_899 equ 7373 ; FIX(0.899976223)
F_1_061 equ 8697 ; FIX(1.061594337)
F_1_272 equ 10426 ; FIX(1.272758580)
F_1_451 equ 11893 ; FIX(1.451774981)
F_1_847 equ 15137 ; FIX(1.847759065)
F_2_172 equ 17799 ; FIX(2.172734803)
F_2_562 equ 20995 ; FIX(2.562915447)
F_3_624 equ 29692 ; FIX(3.624509785)
%else
; NASM cannot do compile-time arithmetic on floating-point constants.
%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n))
F_0_211 equ DESCALE( 226735879,30-CONST_BITS) ; FIX(0.211164243)
F_0_509 equ DESCALE( 547388834,30-CONST_BITS) ; FIX(0.509795579)
F_0_601 equ DESCALE( 645689155,30-CONST_BITS) ; FIX(0.601344887)
F_0_720 equ DESCALE( 774124714,30-CONST_BITS) ; FIX(0.720959822)
F_0_765 equ DESCALE( 821806413,30-CONST_BITS) ; FIX(0.765366865)
F_0_850 equ DESCALE( 913142361,30-CONST_BITS) ; FIX(0.850430095)
F_0_899 equ DESCALE( 966342111,30-CONST_BITS) ; FIX(0.899976223)
F_1_061 equ DESCALE(1139878239,30-CONST_BITS) ; FIX(1.061594337)
F_1_272 equ DESCALE(1366614119,30-CONST_BITS) ; FIX(1.272758580)
F_1_451 equ DESCALE(1558831516,30-CONST_BITS) ; FIX(1.451774981)
F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065)
F_2_172 equ DESCALE(2332956230,30-CONST_BITS) ; FIX(2.172734803)
F_2_562 equ DESCALE(2751909506,30-CONST_BITS) ; FIX(2.562915447)
F_3_624 equ DESCALE(3891787747,30-CONST_BITS) ; FIX(3.624509785)
%endif
; --------------------------------------------------------------------------
SECTION SEG_CONST
alignz 16
global EXTN(jconst_idct_red_sse2)
EXTN(jconst_idct_red_sse2):
PW_F184_MF076 times 4 dw F_1_847,-F_0_765
PW_F256_F089 times 4 dw F_2_562, F_0_899
PW_F106_MF217 times 4 dw F_1_061,-F_2_172
PW_MF060_MF050 times 4 dw -F_0_601,-F_0_509
PW_F145_MF021 times 4 dw F_1_451,-F_0_211
PW_F362_MF127 times 4 dw F_3_624,-F_1_272
PW_F085_MF072 times 4 dw F_0_850,-F_0_720
PD_DESCALE_P1_4 times 4 dd 1 << (DESCALE_P1_4-1)
PD_DESCALE_P2_4 times 4 dd 1 << (DESCALE_P2_4-1)
PD_DESCALE_P1_2 times 4 dd 1 << (DESCALE_P1_2-1)
PD_DESCALE_P2_2 times 4 dd 1 << (DESCALE_P2_2-1)
PB_CENTERJSAMP times 16 db CENTERJSAMPLE
alignz 16
; --------------------------------------------------------------------------
SECTION SEG_TEXT
BITS 64
;
; Perform dequantization and inverse DCT on one block of coefficients,
; producing a reduced-size 4x4 output block.
;
; GLOBAL(void)
; jsimd_idct_4x4_sse2 (void * dct_table, JCOEFPTR coef_block,
; JSAMPARRAY output_buf, JDIMENSION output_col)
;
; r10 = void * dct_table
; r11 = JCOEFPTR coef_block
; r12 = JSAMPARRAY output_buf
; r13 = JDIMENSION output_col
%define original_rbp rbp+0
%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 2
align 16
global EXTN(jsimd_idct_4x4_sse2)
EXTN(jsimd_idct_4x4_sse2):
push rbp
mov rax,rsp ; rax = original rbp
sub rsp, byte 4
and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [rsp],rax
mov rbp,rsp ; rbp = aligned rbp
lea rsp, [wk(0)]
collect_args
; ---- Pass 1: process columns from input.
mov rdx, r10 ; quantptr
mov rsi, r11 ; inptr
%ifndef NO_ZERO_COLUMN_TEST_4X4_SSE2
mov eax, DWORD [DWBLOCK(1,0,rsi,SIZEOF_JCOEF)]
or eax, DWORD [DWBLOCK(2,0,rsi,SIZEOF_JCOEF)]
jnz short .columnDCT
movdqa xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
movdqa xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
por xmm0, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
por xmm1, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
por xmm0, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
por xmm1, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
por xmm0,xmm1
packsswb xmm0,xmm0
packsswb xmm0,xmm0
movd eax,xmm0
test rax,rax
jnz short .columnDCT
; -- AC terms all zero
movdqa xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
pmullw xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
psllw xmm0,PASS1_BITS
movdqa xmm3,xmm0 ; xmm0=in0=(00 01 02 03 04 05 06 07)
punpcklwd xmm0,xmm0 ; xmm0=(00 00 01 01 02 02 03 03)
punpckhwd xmm3,xmm3 ; xmm3=(04 04 05 05 06 06 07 07)
pshufd xmm1,xmm0,0x50 ; xmm1=[col0 col1]=(00 00 00 00 01 01 01 01)
pshufd xmm0,xmm0,0xFA ; xmm0=[col2 col3]=(02 02 02 02 03 03 03 03)
pshufd xmm6,xmm3,0x50 ; xmm6=[col4 col5]=(04 04 04 04 05 05 05 05)
pshufd xmm3,xmm3,0xFA ; xmm3=[col6 col7]=(06 06 06 06 07 07 07 07)
jmp near .column_end
%endif
.columnDCT:
; -- Odd part
movdqa xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
movdqa xmm1, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
pmullw xmm0, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
pmullw xmm1, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
movdqa xmm2, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
movdqa xmm3, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
pmullw xmm2, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
pmullw xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
movdqa xmm4,xmm0
movdqa xmm5,xmm0
punpcklwd xmm4,xmm1
punpckhwd xmm5,xmm1
movdqa xmm0,xmm4
movdqa xmm1,xmm5
pmaddwd xmm4,[rel PW_F256_F089] ; xmm4=(tmp2L)
pmaddwd xmm5,[rel PW_F256_F089] ; xmm5=(tmp2H)
pmaddwd xmm0,[rel PW_F106_MF217] ; xmm0=(tmp0L)
pmaddwd xmm1,[rel PW_F106_MF217] ; xmm1=(tmp0H)
movdqa xmm6,xmm2
movdqa xmm7,xmm2
punpcklwd xmm6,xmm3
punpckhwd xmm7,xmm3
movdqa xmm2,xmm6
movdqa xmm3,xmm7
pmaddwd xmm6,[rel PW_MF060_MF050] ; xmm6=(tmp2L)
pmaddwd xmm7,[rel PW_MF060_MF050] ; xmm7=(tmp2H)
pmaddwd xmm2,[rel PW_F145_MF021] ; xmm2=(tmp0L)
pmaddwd xmm3,[rel PW_F145_MF021] ; xmm3=(tmp0H)
paddd xmm6,xmm4 ; xmm6=tmp2L
paddd xmm7,xmm5 ; xmm7=tmp2H
paddd xmm2,xmm0 ; xmm2=tmp0L
paddd xmm3,xmm1 ; xmm3=tmp0H
movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=tmp0L
movdqa XMMWORD [wk(1)], xmm3 ; wk(1)=tmp0H
; -- Even part
movdqa xmm4, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
movdqa xmm5, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
movdqa xmm0, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
pmullw xmm4, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
pmullw xmm5, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
pmullw xmm0, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
pxor xmm1,xmm1
pxor xmm2,xmm2
punpcklwd xmm1,xmm4 ; xmm1=tmp0L
punpckhwd xmm2,xmm4 ; xmm2=tmp0H
psrad xmm1,(16-CONST_BITS-1) ; psrad xmm1,16 & pslld xmm1,CONST_BITS+1
psrad xmm2,(16-CONST_BITS-1) ; psrad xmm2,16 & pslld xmm2,CONST_BITS+1
movdqa xmm3,xmm5 ; xmm5=in2=z2
punpcklwd xmm5,xmm0 ; xmm0=in6=z3
punpckhwd xmm3,xmm0
pmaddwd xmm5,[rel PW_F184_MF076] ; xmm5=tmp2L
pmaddwd xmm3,[rel PW_F184_MF076] ; xmm3=tmp2H
movdqa xmm4,xmm1
movdqa xmm0,xmm2
paddd xmm1,xmm5 ; xmm1=tmp10L
paddd xmm2,xmm3 ; xmm2=tmp10H
psubd xmm4,xmm5 ; xmm4=tmp12L
psubd xmm0,xmm3 ; xmm0=tmp12H
; -- Final output stage
movdqa xmm5,xmm1
movdqa xmm3,xmm2
paddd xmm1,xmm6 ; xmm1=data0L
paddd xmm2,xmm7 ; xmm2=data0H
psubd xmm5,xmm6 ; xmm5=data3L
psubd xmm3,xmm7 ; xmm3=data3H
movdqa xmm6,[rel PD_DESCALE_P1_4] ; xmm6=[rel PD_DESCALE_P1_4]
paddd xmm1,xmm6
paddd xmm2,xmm6
psrad xmm1,DESCALE_P1_4
psrad xmm2,DESCALE_P1_4
paddd xmm5,xmm6
paddd xmm3,xmm6
psrad xmm5,DESCALE_P1_4
psrad xmm3,DESCALE_P1_4
packssdw xmm1,xmm2 ; xmm1=data0=(00 01 02 03 04 05 06 07)
packssdw xmm5,xmm3 ; xmm5=data3=(30 31 32 33 34 35 36 37)
movdqa xmm7, XMMWORD [wk(0)] ; xmm7=tmp0L
movdqa xmm6, XMMWORD [wk(1)] ; xmm6=tmp0H
movdqa xmm2,xmm4
movdqa xmm3,xmm0
paddd xmm4,xmm7 ; xmm4=data1L
paddd xmm0,xmm6 ; xmm0=data1H
psubd xmm2,xmm7 ; xmm2=data2L
psubd xmm3,xmm6 ; xmm3=data2H
movdqa xmm7,[rel PD_DESCALE_P1_4] ; xmm7=[rel PD_DESCALE_P1_4]
paddd xmm4,xmm7
paddd xmm0,xmm7
psrad xmm4,DESCALE_P1_4
psrad xmm0,DESCALE_P1_4
paddd xmm2,xmm7
paddd xmm3,xmm7
psrad xmm2,DESCALE_P1_4
psrad xmm3,DESCALE_P1_4
packssdw xmm4,xmm0 ; xmm4=data1=(10 11 12 13 14 15 16 17)
packssdw xmm2,xmm3 ; xmm2=data2=(20 21 22 23 24 25 26 27)
movdqa xmm6,xmm1 ; transpose coefficients(phase 1)
punpcklwd xmm1,xmm4 ; xmm1=(00 10 01 11 02 12 03 13)
punpckhwd xmm6,xmm4 ; xmm6=(04 14 05 15 06 16 07 17)
movdqa xmm7,xmm2 ; transpose coefficients(phase 1)
punpcklwd xmm2,xmm5 ; xmm2=(20 30 21 31 22 32 23 33)
punpckhwd xmm7,xmm5 ; xmm7=(24 34 25 35 26 36 27 37)
movdqa xmm0,xmm1 ; transpose coefficients(phase 2)
punpckldq xmm1,xmm2 ; xmm1=[col0 col1]=(00 10 20 30 01 11 21 31)
punpckhdq xmm0,xmm2 ; xmm0=[col2 col3]=(02 12 22 32 03 13 23 33)
movdqa xmm3,xmm6 ; transpose coefficients(phase 2)
punpckldq xmm6,xmm7 ; xmm6=[col4 col5]=(04 14 24 34 05 15 25 35)
punpckhdq xmm3,xmm7 ; xmm3=[col6 col7]=(06 16 26 36 07 17 27 37)
.column_end:
; -- Prefetch the next coefficient block
prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 0*32]
prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 1*32]
prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 2*32]
prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 3*32]
; ---- Pass 2: process rows, store into output array.
mov rax, [original_rbp]
mov rdi, r12 ; (JSAMPROW *)
mov rax, r13
; -- Even part
pxor xmm4,xmm4
punpcklwd xmm4,xmm1 ; xmm4=tmp0
psrad xmm4,(16-CONST_BITS-1) ; psrad xmm4,16 & pslld xmm4,CONST_BITS+1
; -- Odd part
punpckhwd xmm1,xmm0
punpckhwd xmm6,xmm3
movdqa xmm5,xmm1
movdqa xmm2,xmm6
pmaddwd xmm1,[rel PW_F256_F089] ; xmm1=(tmp2)
pmaddwd xmm6,[rel PW_MF060_MF050] ; xmm6=(tmp2)
pmaddwd xmm5,[rel PW_F106_MF217] ; xmm5=(tmp0)
pmaddwd xmm2,[rel PW_F145_MF021] ; xmm2=(tmp0)
paddd xmm6,xmm1 ; xmm6=tmp2
paddd xmm2,xmm5 ; xmm2=tmp0
; -- Even part
punpcklwd xmm0,xmm3
pmaddwd xmm0,[rel PW_F184_MF076] ; xmm0=tmp2
movdqa xmm7,xmm4
paddd xmm4,xmm0 ; xmm4=tmp10
psubd xmm7,xmm0 ; xmm7=tmp12
; -- Final output stage
movdqa xmm1,[rel PD_DESCALE_P2_4] ; xmm1=[rel PD_DESCALE_P2_4]
movdqa xmm5,xmm4
movdqa xmm3,xmm7
paddd xmm4,xmm6 ; xmm4=data0=(00 10 20 30)
paddd xmm7,xmm2 ; xmm7=data1=(01 11 21 31)
psubd xmm5,xmm6 ; xmm5=data3=(03 13 23 33)
psubd xmm3,xmm2 ; xmm3=data2=(02 12 22 32)
paddd xmm4,xmm1
paddd xmm7,xmm1
psrad xmm4,DESCALE_P2_4
psrad xmm7,DESCALE_P2_4
paddd xmm5,xmm1
paddd xmm3,xmm1
psrad xmm5,DESCALE_P2_4
psrad xmm3,DESCALE_P2_4
packssdw xmm4,xmm3 ; xmm4=(00 10 20 30 02 12 22 32)
packssdw xmm7,xmm5 ; xmm7=(01 11 21 31 03 13 23 33)
movdqa xmm0,xmm4 ; transpose coefficients(phase 1)
punpcklwd xmm4,xmm7 ; xmm4=(00 01 10 11 20 21 30 31)
punpckhwd xmm0,xmm7 ; xmm0=(02 03 12 13 22 23 32 33)
movdqa xmm6,xmm4 ; transpose coefficients(phase 2)
punpckldq xmm4,xmm0 ; xmm4=(00 01 02 03 10 11 12 13)
punpckhdq xmm6,xmm0 ; xmm6=(20 21 22 23 30 31 32 33)
packsswb xmm4,xmm6 ; xmm4=(00 01 02 03 10 11 12 13 20 ..)
paddb xmm4,[rel PB_CENTERJSAMP]
pshufd xmm2,xmm4,0x39 ; xmm2=(10 11 12 13 20 21 22 23 30 ..)
pshufd xmm1,xmm4,0x4E ; xmm1=(20 21 22 23 30 31 32 33 00 ..)
pshufd xmm3,xmm4,0x93 ; xmm3=(30 31 32 33 00 01 02 03 10 ..)
mov rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW]
mov rsi, JSAMPROW [rdi+1*SIZEOF_JSAMPROW]
movd XMM_DWORD [rdx+rax*SIZEOF_JSAMPLE], xmm4
movd XMM_DWORD [rsi+rax*SIZEOF_JSAMPLE], xmm2
mov rdx, JSAMPROW [rdi+2*SIZEOF_JSAMPROW]
mov rsi, JSAMPROW [rdi+3*SIZEOF_JSAMPROW]
movd XMM_DWORD [rdx+rax*SIZEOF_JSAMPLE], xmm1
movd XMM_DWORD [rsi+rax*SIZEOF_JSAMPLE], xmm3
uncollect_args
mov rsp,rbp ; rsp <- aligned rbp
pop rsp ; rsp <- original rbp
pop rbp
ret
; --------------------------------------------------------------------------
;
; Perform dequantization and inverse DCT on one block of coefficients,
; producing a reduced-size 2x2 output block.
;
; GLOBAL(void)
; jsimd_idct_2x2_sse2 (void * dct_table, JCOEFPTR coef_block,
; JSAMPARRAY output_buf, JDIMENSION output_col)
;
; r10 = void * dct_table
; r11 = JCOEFPTR coef_block
; r12 = JSAMPARRAY output_buf
; r13 = JDIMENSION output_col
align 16
global EXTN(jsimd_idct_2x2_sse2)
EXTN(jsimd_idct_2x2_sse2):
push rbp
mov rax,rsp
mov rbp,rsp
collect_args
push rbx
; ---- Pass 1: process columns from input.
mov rdx, r10 ; quantptr
mov rsi, r11 ; inptr
; | input: | result: |
; | 00 01 ** 03 ** 05 ** 07 | |
; | 10 11 ** 13 ** 15 ** 17 | |
; | ** ** ** ** ** ** ** ** | |
; | 30 31 ** 33 ** 35 ** 37 | A0 A1 A3 A5 A7 |
; | ** ** ** ** ** ** ** ** | B0 B1 B3 B5 B7 |
; | 50 51 ** 53 ** 55 ** 57 | |
; | ** ** ** ** ** ** ** ** | |
; | 70 71 ** 73 ** 75 ** 77 | |
; -- Odd part
movdqa xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
movdqa xmm1, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
pmullw xmm0, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
pmullw xmm1, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
movdqa xmm2, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
movdqa xmm3, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
pmullw xmm2, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
pmullw xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
; xmm0=(10 11 ** 13 ** 15 ** 17), xmm1=(30 31 ** 33 ** 35 ** 37)
; xmm2=(50 51 ** 53 ** 55 ** 57), xmm3=(70 71 ** 73 ** 75 ** 77)
pcmpeqd xmm7,xmm7
pslld xmm7,WORD_BIT ; xmm7={0x0000 0xFFFF 0x0000 0xFFFF ..}
movdqa xmm4,xmm0 ; xmm4=(10 11 ** 13 ** 15 ** 17)
movdqa xmm5,xmm2 ; xmm5=(50 51 ** 53 ** 55 ** 57)
punpcklwd xmm4,xmm1 ; xmm4=(10 30 11 31 ** ** 13 33)
punpcklwd xmm5,xmm3 ; xmm5=(50 70 51 71 ** ** 53 73)
pmaddwd xmm4,[rel PW_F362_MF127]
pmaddwd xmm5,[rel PW_F085_MF072]
psrld xmm0,WORD_BIT ; xmm0=(11 -- 13 -- 15 -- 17 --)
pand xmm1,xmm7 ; xmm1=(-- 31 -- 33 -- 35 -- 37)
psrld xmm2,WORD_BIT ; xmm2=(51 -- 53 -- 55 -- 57 --)
pand xmm3,xmm7 ; xmm3=(-- 71 -- 73 -- 75 -- 77)
por xmm0,xmm1 ; xmm0=(11 31 13 33 15 35 17 37)
por xmm2,xmm3 ; xmm2=(51 71 53 73 55 75 57 77)
pmaddwd xmm0,[rel PW_F362_MF127]
pmaddwd xmm2,[rel PW_F085_MF072]
paddd xmm4,xmm5 ; xmm4=tmp0[col0 col1 **** col3]
paddd xmm0,xmm2 ; xmm0=tmp0[col1 col3 col5 col7]
; -- Even part
movdqa xmm6, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
pmullw xmm6, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
; xmm6=(00 01 ** 03 ** 05 ** 07)
movdqa xmm1,xmm6 ; xmm1=(00 01 ** 03 ** 05 ** 07)
pslld xmm6,WORD_BIT ; xmm6=(-- 00 -- ** -- ** -- **)
pand xmm1,xmm7 ; xmm1=(-- 01 -- 03 -- 05 -- 07)
psrad xmm6,(WORD_BIT-CONST_BITS-2) ; xmm6=tmp10[col0 **** **** ****]
psrad xmm1,(WORD_BIT-CONST_BITS-2) ; xmm1=tmp10[col1 col3 col5 col7]
; -- Final output stage
movdqa xmm3,xmm6
movdqa xmm5,xmm1
paddd xmm6,xmm4 ; xmm6=data0[col0 **** **** ****]=(A0 ** ** **)
paddd xmm1,xmm0 ; xmm1=data0[col1 col3 col5 col7]=(A1 A3 A5 A7)
psubd xmm3,xmm4 ; xmm3=data1[col0 **** **** ****]=(B0 ** ** **)
psubd xmm5,xmm0 ; xmm5=data1[col1 col3 col5 col7]=(B1 B3 B5 B7)
movdqa xmm2,[rel PD_DESCALE_P1_2] ; xmm2=[rel PD_DESCALE_P1_2]
punpckldq xmm6,xmm3 ; xmm6=(A0 B0 ** **)
movdqa xmm7,xmm1
punpcklqdq xmm1,xmm5 ; xmm1=(A1 A3 B1 B3)
punpckhqdq xmm7,xmm5 ; xmm7=(A5 A7 B5 B7)
paddd xmm6,xmm2
psrad xmm6,DESCALE_P1_2
paddd xmm1,xmm2
paddd xmm7,xmm2
psrad xmm1,DESCALE_P1_2
psrad xmm7,DESCALE_P1_2
; -- Prefetch the next coefficient block
prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 0*32]
prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 1*32]
prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 2*32]
prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 3*32]
; ---- Pass 2: process rows, store into output array.
mov rdi, r12 ; (JSAMPROW *)
mov rax, r13
; | input:| result:|
; | A0 B0 | |
; | A1 B1 | C0 C1 |
; | A3 B3 | D0 D1 |
; | A5 B5 | |
; | A7 B7 | |
; -- Odd part
packssdw xmm1,xmm1 ; xmm1=(A1 A3 B1 B3 A1 A3 B1 B3)
packssdw xmm7,xmm7 ; xmm7=(A5 A7 B5 B7 A5 A7 B5 B7)
pmaddwd xmm1,[rel PW_F362_MF127]
pmaddwd xmm7,[rel PW_F085_MF072]
paddd xmm1,xmm7 ; xmm1=tmp0[row0 row1 row0 row1]
; -- Even part
pslld xmm6,(CONST_BITS+2) ; xmm6=tmp10[row0 row1 **** ****]
; -- Final output stage
movdqa xmm4,xmm6
paddd xmm6,xmm1 ; xmm6=data0[row0 row1 **** ****]=(C0 C1 ** **)
psubd xmm4,xmm1 ; xmm4=data1[row0 row1 **** ****]=(D0 D1 ** **)
punpckldq xmm6,xmm4 ; xmm6=(C0 D0 C1 D1)
paddd xmm6,[rel PD_DESCALE_P2_2]
psrad xmm6,DESCALE_P2_2
packssdw xmm6,xmm6 ; xmm6=(C0 D0 C1 D1 C0 D0 C1 D1)
packsswb xmm6,xmm6 ; xmm6=(C0 D0 C1 D1 C0 D0 C1 D1 ..)
paddb xmm6,[rel PB_CENTERJSAMP]
pextrw ebx,xmm6,0x00 ; ebx=(C0 D0 -- --)
pextrw ecx,xmm6,0x01 ; ecx=(C1 D1 -- --)
mov rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW]
mov rsi, JSAMPROW [rdi+1*SIZEOF_JSAMPROW]
mov WORD [rdx+rax*SIZEOF_JSAMPLE], bx
mov WORD [rsi+rax*SIZEOF_JSAMPLE], cx
pop rbx
uncollect_args
pop rbp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16
@@ -1,158 +0,0 @@
;
; jquantf.asm - sample data conversion and quantization (64-bit SSE & SSE2)
;
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2009 D. R. Commander
;
; Based on
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; [TAB8]
%include "jsimdext.inc"
%include "jdct.inc"
; --------------------------------------------------------------------------
SECTION SEG_TEXT
BITS 64
;
; Load data into workspace, applying unsigned->signed conversion
;
; GLOBAL(void)
; jsimd_convsamp_float_sse2 (JSAMPARRAY sample_data, JDIMENSION start_col,
; FAST_FLOAT * workspace);
;
; r10 = JSAMPARRAY sample_data
; r11 = JDIMENSION start_col
; r12 = FAST_FLOAT * workspace
align 16
global EXTN(jsimd_convsamp_float_sse2)
EXTN(jsimd_convsamp_float_sse2):
push rbp
mov rax,rsp
mov rbp,rsp
collect_args
push rbx
pcmpeqw xmm7,xmm7
psllw xmm7,7
packsswb xmm7,xmm7 ; xmm7 = PB_CENTERJSAMPLE (0x808080..)
mov rsi, r10
mov rax, r11
mov rdi, r12
mov rcx, DCTSIZE/2
.convloop:
mov rbx, JSAMPROW [rsi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *)
mov rdx, JSAMPROW [rsi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *)
movq xmm0, XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE]
movq xmm1, XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE]
psubb xmm0,xmm7 ; xmm0=(01234567)
psubb xmm1,xmm7 ; xmm1=(89ABCDEF)
punpcklbw xmm0,xmm0 ; xmm0=(*0*1*2*3*4*5*6*7)
punpcklbw xmm1,xmm1 ; xmm1=(*8*9*A*B*C*D*E*F)
punpcklwd xmm2,xmm0 ; xmm2=(***0***1***2***3)
punpckhwd xmm0,xmm0 ; xmm0=(***4***5***6***7)
punpcklwd xmm3,xmm1 ; xmm3=(***8***9***A***B)
punpckhwd xmm1,xmm1 ; xmm1=(***C***D***E***F)
psrad xmm2,(DWORD_BIT-BYTE_BIT) ; xmm2=(0123)
psrad xmm0,(DWORD_BIT-BYTE_BIT) ; xmm0=(4567)
cvtdq2ps xmm2,xmm2 ; xmm2=(0123)
cvtdq2ps xmm0,xmm0 ; xmm0=(4567)
psrad xmm3,(DWORD_BIT-BYTE_BIT) ; xmm3=(89AB)
psrad xmm1,(DWORD_BIT-BYTE_BIT) ; xmm1=(CDEF)
cvtdq2ps xmm3,xmm3 ; xmm3=(89AB)
cvtdq2ps xmm1,xmm1 ; xmm1=(CDEF)
movaps XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_FAST_FLOAT)], xmm2
movaps XMMWORD [XMMBLOCK(0,1,rdi,SIZEOF_FAST_FLOAT)], xmm0
movaps XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_FAST_FLOAT)], xmm3
movaps XMMWORD [XMMBLOCK(1,1,rdi,SIZEOF_FAST_FLOAT)], xmm1
add rsi, byte 2*SIZEOF_JSAMPROW
add rdi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT
dec rcx
jnz short .convloop
pop rbx
uncollect_args
pop rbp
ret
; --------------------------------------------------------------------------
;
; Quantize/descale the coefficients, and store into coef_block
;
; GLOBAL(void)
; jsimd_quantize_float_sse2 (JCOEFPTR coef_block, FAST_FLOAT * divisors,
; FAST_FLOAT * workspace);
;
; r10 = JCOEFPTR coef_block
; r11 = FAST_FLOAT * divisors
; r12 = FAST_FLOAT * workspace
align 16
global EXTN(jsimd_quantize_float_sse2)
EXTN(jsimd_quantize_float_sse2):
push rbp
mov rax,rsp
mov rbp,rsp
collect_args
mov rsi, r12
mov rdx, r11
mov rdi, r10
mov rax, DCTSIZE2/16
.quantloop:
movaps xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_FAST_FLOAT)]
movaps xmm1, XMMWORD [XMMBLOCK(0,1,rsi,SIZEOF_FAST_FLOAT)]
mulps xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FAST_FLOAT)]
mulps xmm1, XMMWORD [XMMBLOCK(0,1,rdx,SIZEOF_FAST_FLOAT)]
movaps xmm2, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_FAST_FLOAT)]
movaps xmm3, XMMWORD [XMMBLOCK(1,1,rsi,SIZEOF_FAST_FLOAT)]
mulps xmm2, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FAST_FLOAT)]
mulps xmm3, XMMWORD [XMMBLOCK(1,1,rdx,SIZEOF_FAST_FLOAT)]
cvtps2dq xmm0,xmm0
cvtps2dq xmm1,xmm1
cvtps2dq xmm2,xmm2
cvtps2dq xmm3,xmm3
packssdw xmm0,xmm1
packssdw xmm2,xmm3
movdqa XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_JCOEF)], xmm0
movdqa XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_JCOEF)], xmm2
add rsi, byte 16*SIZEOF_FAST_FLOAT
add rdx, byte 16*SIZEOF_FAST_FLOAT
add rdi, byte 16*SIZEOF_JCOEF
dec rax
jnz short .quantloop
uncollect_args
pop rbp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16
@@ -1,187 +0,0 @@
;
; jquanti.asm - sample data conversion and quantization (64-bit SSE2)
;
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2009 D. R. Commander
;
; Based on
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; [TAB8]
%include "jsimdext.inc"
%include "jdct.inc"
; --------------------------------------------------------------------------
SECTION SEG_TEXT
BITS 64
;
; Load data into workspace, applying unsigned->signed conversion
;
; GLOBAL(void)
; jsimd_convsamp_sse2 (JSAMPARRAY sample_data, JDIMENSION start_col,
; DCTELEM * workspace);
;
; r10 = JSAMPARRAY sample_data
; r11 = JDIMENSION start_col
; r12 = DCTELEM * workspace
align 16
global EXTN(jsimd_convsamp_sse2)
EXTN(jsimd_convsamp_sse2):
push rbp
mov rax,rsp
mov rbp,rsp
collect_args
push rbx
pxor xmm6,xmm6 ; xmm6=(all 0's)
pcmpeqw xmm7,xmm7
psllw xmm7,7 ; xmm7={0xFF80 0xFF80 0xFF80 0xFF80 ..}
mov rsi, r10
mov rax, r11
mov rdi, r12
mov rcx, DCTSIZE/4
.convloop:
mov rbx, JSAMPROW [rsi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *)
mov rdx, JSAMPROW [rsi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *)
movq xmm0, XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE] ; xmm0=(01234567)
movq xmm1, XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE] ; xmm1=(89ABCDEF)
mov rbx, JSAMPROW [rsi+2*SIZEOF_JSAMPROW] ; (JSAMPLE *)
mov rdx, JSAMPROW [rsi+3*SIZEOF_JSAMPROW] ; (JSAMPLE *)
movq xmm2, XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE] ; xmm2=(GHIJKLMN)
movq xmm3, XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE] ; xmm3=(OPQRSTUV)
punpcklbw xmm0,xmm6 ; xmm0=(01234567)
punpcklbw xmm1,xmm6 ; xmm1=(89ABCDEF)
paddw xmm0,xmm7
paddw xmm1,xmm7
punpcklbw xmm2,xmm6 ; xmm2=(GHIJKLMN)
punpcklbw xmm3,xmm6 ; xmm3=(OPQRSTUV)
paddw xmm2,xmm7
paddw xmm3,xmm7
movdqa XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_DCTELEM)], xmm0
movdqa XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_DCTELEM)], xmm1
movdqa XMMWORD [XMMBLOCK(2,0,rdi,SIZEOF_DCTELEM)], xmm2
movdqa XMMWORD [XMMBLOCK(3,0,rdi,SIZEOF_DCTELEM)], xmm3
add rsi, byte 4*SIZEOF_JSAMPROW
add rdi, byte 4*DCTSIZE*SIZEOF_DCTELEM
dec rcx
jnz short .convloop
pop rbx
uncollect_args
pop rbp
ret
; --------------------------------------------------------------------------
;
; Quantize/descale the coefficients, and store into coef_block
;
; This implementation is based on an algorithm described in
; "How to optimize for the Pentium family of microprocessors"
; (http://www.agner.org/assem/).
;
; GLOBAL(void)
; jsimd_quantize_sse2 (JCOEFPTR coef_block, DCTELEM * divisors,
; DCTELEM * workspace);
;
%define RECIPROCAL(m,n,b) XMMBLOCK(DCTSIZE*0+(m),(n),(b),SIZEOF_DCTELEM)
%define CORRECTION(m,n,b) XMMBLOCK(DCTSIZE*1+(m),(n),(b),SIZEOF_DCTELEM)
%define SCALE(m,n,b) XMMBLOCK(DCTSIZE*2+(m),(n),(b),SIZEOF_DCTELEM)
; r10 = JCOEFPTR coef_block
; r11 = DCTELEM * divisors
; r12 = DCTELEM * workspace
align 16
global EXTN(jsimd_quantize_sse2)
EXTN(jsimd_quantize_sse2):
push rbp
mov rax,rsp
mov rbp,rsp
collect_args
mov rsi, r12
mov rdx, r11
mov rdi, r10
mov rax, DCTSIZE2/32
.quantloop:
movdqa xmm4, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_DCTELEM)]
movdqa xmm5, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_DCTELEM)]
movdqa xmm6, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_DCTELEM)]
movdqa xmm7, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_DCTELEM)]
movdqa xmm0,xmm4
movdqa xmm1,xmm5
movdqa xmm2,xmm6
movdqa xmm3,xmm7
psraw xmm4,(WORD_BIT-1)
psraw xmm5,(WORD_BIT-1)
psraw xmm6,(WORD_BIT-1)
psraw xmm7,(WORD_BIT-1)
pxor xmm0,xmm4
pxor xmm1,xmm5
pxor xmm2,xmm6
pxor xmm3,xmm7
psubw xmm0,xmm4 ; if (xmm0 < 0) xmm0 = -xmm0;
psubw xmm1,xmm5 ; if (xmm1 < 0) xmm1 = -xmm1;
psubw xmm2,xmm6 ; if (xmm2 < 0) xmm2 = -xmm2;
psubw xmm3,xmm7 ; if (xmm3 < 0) xmm3 = -xmm3;
paddw xmm0, XMMWORD [CORRECTION(0,0,rdx)] ; correction + roundfactor
paddw xmm1, XMMWORD [CORRECTION(1,0,rdx)]
paddw xmm2, XMMWORD [CORRECTION(2,0,rdx)]
paddw xmm3, XMMWORD [CORRECTION(3,0,rdx)]
pmulhuw xmm0, XMMWORD [RECIPROCAL(0,0,rdx)] ; reciprocal
pmulhuw xmm1, XMMWORD [RECIPROCAL(1,0,rdx)]
pmulhuw xmm2, XMMWORD [RECIPROCAL(2,0,rdx)]
pmulhuw xmm3, XMMWORD [RECIPROCAL(3,0,rdx)]
pmulhuw xmm0, XMMWORD [SCALE(0,0,rdx)] ; scale
pmulhuw xmm1, XMMWORD [SCALE(1,0,rdx)]
pmulhuw xmm2, XMMWORD [SCALE(2,0,rdx)]
pmulhuw xmm3, XMMWORD [SCALE(3,0,rdx)]
pxor xmm0,xmm4
pxor xmm1,xmm5
pxor xmm2,xmm6
pxor xmm3,xmm7
psubw xmm0,xmm4
psubw xmm1,xmm5
psubw xmm2,xmm6
psubw xmm3,xmm7
movdqa XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_DCTELEM)], xmm0
movdqa XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_DCTELEM)], xmm1
movdqa XMMWORD [XMMBLOCK(2,0,rdi,SIZEOF_DCTELEM)], xmm2
movdqa XMMWORD [XMMBLOCK(3,0,rdi,SIZEOF_DCTELEM)], xmm3
add rsi, byte 32*SIZEOF_DCTELEM
add rdx, byte 32*SIZEOF_DCTELEM
add rdi, byte 32*SIZEOF_JCOEF
dec rax
jnz near .quantloop
uncollect_args
pop rbp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16
@@ -1,757 +0,0 @@
/*
* jsimd_x86_64.c
*
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright 2009-2011, 2014 D. R. Commander
*
* Based on the x86 SIMD extension for IJG JPEG library,
* Copyright (C) 1999-2006, MIYASAKA Masaru.
* For conditions of distribution and use, see copyright notice in jsimdext.inc
*
* This file contains the interface between the "normal" portions
* of the library and the SIMD implementations when running on a
* 64-bit x86 architecture.
*/
#define JPEG_INTERNALS
#include "../jinclude.h"
#include "../jpeglib.h"
#include "../jsimd.h"
#include "../jdct.h"
#include "../jsimddct.h"
#include "jsimd.h"
/*
* In the PIC cases, we have no guarantee that constants will keep
* their alignment. This macro allows us to verify it at runtime.
*/
#define IS_ALIGNED(ptr, order) (((size_t)ptr & ((1 << order) - 1)) == 0)
#define IS_ALIGNED_SSE(ptr) (IS_ALIGNED(ptr, 4)) /* 16 byte alignment */
GLOBAL(int)
jsimd_can_rgb_ycc (void)
{
/* The code is optimised for these values only */
if (BITS_IN_JSAMPLE != 8)
return 0;
if (sizeof(JDIMENSION) != 4)
return 0;
if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
return 0;
if (!IS_ALIGNED_SSE(jconst_rgb_ycc_convert_sse2))
return 0;
return 1;
}
GLOBAL(int)
jsimd_can_rgb_gray (void)
{
/* The code is optimised for these values only */
if (BITS_IN_JSAMPLE != 8)
return 0;
if (sizeof(JDIMENSION) != 4)
return 0;
if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
return 0;
if (!IS_ALIGNED_SSE(jconst_rgb_gray_convert_sse2))
return 0;
return 1;
}
GLOBAL(int)
jsimd_can_ycc_rgb (void)
{
/* The code is optimised for these values only */
if (BITS_IN_JSAMPLE != 8)
return 0;
if (sizeof(JDIMENSION) != 4)
return 0;
if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
return 0;
if (!IS_ALIGNED_SSE(jconst_ycc_rgb_convert_sse2))
return 0;
return 1;
}
GLOBAL(int)
jsimd_can_ycc_rgb565 (void)
{
return 0;
}
GLOBAL(void)
jsimd_rgb_ycc_convert (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows)
{
void (*sse2fct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
switch(cinfo->in_color_space) {
case JCS_EXT_RGB:
sse2fct=jsimd_extrgb_ycc_convert_sse2;
break;
case JCS_EXT_RGBX:
case JCS_EXT_RGBA:
sse2fct=jsimd_extrgbx_ycc_convert_sse2;
break;
case JCS_EXT_BGR:
sse2fct=jsimd_extbgr_ycc_convert_sse2;
break;
case JCS_EXT_BGRX:
case JCS_EXT_BGRA:
sse2fct=jsimd_extbgrx_ycc_convert_sse2;
break;
case JCS_EXT_XBGR:
case JCS_EXT_ABGR:
sse2fct=jsimd_extxbgr_ycc_convert_sse2;
break;
case JCS_EXT_XRGB:
case JCS_EXT_ARGB:
sse2fct=jsimd_extxrgb_ycc_convert_sse2;
break;
default:
sse2fct=jsimd_rgb_ycc_convert_sse2;
break;
}
sse2fct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
}
GLOBAL(void)
jsimd_rgb_gray_convert (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows)
{
void (*sse2fct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
switch(cinfo->in_color_space) {
case JCS_EXT_RGB:
sse2fct=jsimd_extrgb_gray_convert_sse2;
break;
case JCS_EXT_RGBX:
case JCS_EXT_RGBA:
sse2fct=jsimd_extrgbx_gray_convert_sse2;
break;
case JCS_EXT_BGR:
sse2fct=jsimd_extbgr_gray_convert_sse2;
break;
case JCS_EXT_BGRX:
case JCS_EXT_BGRA:
sse2fct=jsimd_extbgrx_gray_convert_sse2;
break;
case JCS_EXT_XBGR:
case JCS_EXT_ABGR:
sse2fct=jsimd_extxbgr_gray_convert_sse2;
break;
case JCS_EXT_XRGB:
case JCS_EXT_ARGB:
sse2fct=jsimd_extxrgb_gray_convert_sse2;
break;
default:
sse2fct=jsimd_rgb_gray_convert_sse2;
break;
}
sse2fct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
}
GLOBAL(void)
jsimd_ycc_rgb_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows)
{
void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
switch(cinfo->out_color_space) {
case JCS_EXT_RGB:
sse2fct=jsimd_ycc_extrgb_convert_sse2;
break;
case JCS_EXT_RGBX:
case JCS_EXT_RGBA:
sse2fct=jsimd_ycc_extrgbx_convert_sse2;
break;
case JCS_EXT_BGR:
sse2fct=jsimd_ycc_extbgr_convert_sse2;
break;
case JCS_EXT_BGRX:
case JCS_EXT_BGRA:
sse2fct=jsimd_ycc_extbgrx_convert_sse2;
break;
case JCS_EXT_XBGR:
case JCS_EXT_ABGR:
sse2fct=jsimd_ycc_extxbgr_convert_sse2;
break;
case JCS_EXT_XRGB:
case JCS_EXT_ARGB:
sse2fct=jsimd_ycc_extxrgb_convert_sse2;
break;
default:
sse2fct=jsimd_ycc_rgb_convert_sse2;
break;
}
sse2fct(cinfo->output_width, input_buf, input_row, output_buf, num_rows);
}
GLOBAL(void)
jsimd_ycc_rgb565_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows)
{
}
GLOBAL(int)
jsimd_can_h2v2_downsample (void)
{
/* The code is optimised for these values only */
if (BITS_IN_JSAMPLE != 8)
return 0;
if (sizeof(JDIMENSION) != 4)
return 0;
return 1;
}
GLOBAL(int)
jsimd_can_h2v1_downsample (void)
{
/* The code is optimised for these values only */
if (BITS_IN_JSAMPLE != 8)
return 0;
if (sizeof(JDIMENSION) != 4)
return 0;
return 1;
}
GLOBAL(void)
jsimd_h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data)
{
jsimd_h2v2_downsample_sse2(cinfo->image_width, cinfo->max_v_samp_factor,
compptr->v_samp_factor, compptr->width_in_blocks,
input_data, output_data);
}
GLOBAL(void)
jsimd_h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data)
{
jsimd_h2v1_downsample_sse2(cinfo->image_width, cinfo->max_v_samp_factor,
compptr->v_samp_factor, compptr->width_in_blocks,
input_data, output_data);
}
GLOBAL(int)
jsimd_can_h2v2_upsample (void)
{
/* The code is optimised for these values only */
if (BITS_IN_JSAMPLE != 8)
return 0;
if (sizeof(JDIMENSION) != 4)
return 0;
return 1;
}
GLOBAL(int)
jsimd_can_h2v1_upsample (void)
{
/* The code is optimised for these values only */
if (BITS_IN_JSAMPLE != 8)
return 0;
if (sizeof(JDIMENSION) != 4)
return 0;
return 1;
}
GLOBAL(void)
jsimd_h2v2_upsample (j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JSAMPARRAY input_data,
JSAMPARRAY * output_data_ptr)
{
jsimd_h2v2_upsample_sse2(cinfo->max_v_samp_factor, cinfo->output_width,
input_data, output_data_ptr);
}
GLOBAL(void)
jsimd_h2v1_upsample (j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JSAMPARRAY input_data,
JSAMPARRAY * output_data_ptr)
{
jsimd_h2v1_upsample_sse2(cinfo->max_v_samp_factor, cinfo->output_width,
input_data, output_data_ptr);
}
GLOBAL(int)
jsimd_can_h2v2_fancy_upsample (void)
{
/* The code is optimised for these values only */
if (BITS_IN_JSAMPLE != 8)
return 0;
if (sizeof(JDIMENSION) != 4)
return 0;
if (!IS_ALIGNED_SSE(jconst_fancy_upsample_sse2))
return 0;
return 1;
}
GLOBAL(int)
jsimd_can_h2v1_fancy_upsample (void)
{
/* The code is optimised for these values only */
if (BITS_IN_JSAMPLE != 8)
return 0;
if (sizeof(JDIMENSION) != 4)
return 0;
if (!IS_ALIGNED_SSE(jconst_fancy_upsample_sse2))
return 0;
return 1;
}
GLOBAL(void)
jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JSAMPARRAY input_data,
JSAMPARRAY * output_data_ptr)
{
jsimd_h2v2_fancy_upsample_sse2(cinfo->max_v_samp_factor,
compptr->downsampled_width, input_data,
output_data_ptr);
}
GLOBAL(void)
jsimd_h2v1_fancy_upsample (j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JSAMPARRAY input_data,
JSAMPARRAY * output_data_ptr)
{
jsimd_h2v1_fancy_upsample_sse2(cinfo->max_v_samp_factor,
compptr->downsampled_width, input_data,
output_data_ptr);
}
GLOBAL(int)
jsimd_can_h2v2_merged_upsample (void)
{
/* The code is optimised for these values only */
if (BITS_IN_JSAMPLE != 8)
return 0;
if (sizeof(JDIMENSION) != 4)
return 0;
if (!IS_ALIGNED_SSE(jconst_merged_upsample_sse2))
return 0;
return 1;
}
GLOBAL(int)
jsimd_can_h2v1_merged_upsample (void)
{
/* The code is optimised for these values only */
if (BITS_IN_JSAMPLE != 8)
return 0;
if (sizeof(JDIMENSION) != 4)
return 0;
if (!IS_ALIGNED_SSE(jconst_merged_upsample_sse2))
return 0;
return 1;
}
GLOBAL(void)
jsimd_h2v2_merged_upsample (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf)
{
void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
switch(cinfo->out_color_space) {
case JCS_EXT_RGB:
sse2fct=jsimd_h2v2_extrgb_merged_upsample_sse2;
break;
case JCS_EXT_RGBX:
case JCS_EXT_RGBA:
sse2fct=jsimd_h2v2_extrgbx_merged_upsample_sse2;
break;
case JCS_EXT_BGR:
sse2fct=jsimd_h2v2_extbgr_merged_upsample_sse2;
break;
case JCS_EXT_BGRX:
case JCS_EXT_BGRA:
sse2fct=jsimd_h2v2_extbgrx_merged_upsample_sse2;
break;
case JCS_EXT_XBGR:
case JCS_EXT_ABGR:
sse2fct=jsimd_h2v2_extxbgr_merged_upsample_sse2;
break;
case JCS_EXT_XRGB:
case JCS_EXT_ARGB:
sse2fct=jsimd_h2v2_extxrgb_merged_upsample_sse2;
break;
default:
sse2fct=jsimd_h2v2_merged_upsample_sse2;
break;
}
sse2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
}
GLOBAL(void)
jsimd_h2v1_merged_upsample (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf)
{
void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
switch(cinfo->out_color_space) {
case JCS_EXT_RGB:
sse2fct=jsimd_h2v1_extrgb_merged_upsample_sse2;
break;
case JCS_EXT_RGBX:
case JCS_EXT_RGBA:
sse2fct=jsimd_h2v1_extrgbx_merged_upsample_sse2;
break;
case JCS_EXT_BGR:
sse2fct=jsimd_h2v1_extbgr_merged_upsample_sse2;
break;
case JCS_EXT_BGRX:
case JCS_EXT_BGRA:
sse2fct=jsimd_h2v1_extbgrx_merged_upsample_sse2;
break;
case JCS_EXT_XBGR:
case JCS_EXT_ABGR:
sse2fct=jsimd_h2v1_extxbgr_merged_upsample_sse2;
break;
case JCS_EXT_XRGB:
case JCS_EXT_ARGB:
sse2fct=jsimd_h2v1_extxrgb_merged_upsample_sse2;
break;
default:
sse2fct=jsimd_h2v1_merged_upsample_sse2;
break;
}
sse2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
}
GLOBAL(int)
jsimd_can_convsamp (void)
{
/* The code is optimised for these values only */
if (DCTSIZE != 8)
return 0;
if (BITS_IN_JSAMPLE != 8)
return 0;
if (sizeof(JDIMENSION) != 4)
return 0;
if (sizeof(DCTELEM) != 2)
return 0;
return 1;
}
GLOBAL(int)
jsimd_can_convsamp_float (void)
{
/* The code is optimised for these values only */
if (DCTSIZE != 8)
return 0;
if (BITS_IN_JSAMPLE != 8)
return 0;
if (sizeof(JDIMENSION) != 4)
return 0;
if (sizeof(FAST_FLOAT) != 4)
return 0;
return 1;
}
GLOBAL(void)
jsimd_convsamp (JSAMPARRAY sample_data, JDIMENSION start_col,
DCTELEM * workspace)
{
jsimd_convsamp_sse2(sample_data, start_col, workspace);
}
GLOBAL(void)
jsimd_convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col,
FAST_FLOAT * workspace)
{
jsimd_convsamp_float_sse2(sample_data, start_col, workspace);
}
GLOBAL(int)
jsimd_can_fdct_islow (void)
{
/* The code is optimised for these values only */
if (DCTSIZE != 8)
return 0;
if (sizeof(DCTELEM) != 2)
return 0;
if (!IS_ALIGNED_SSE(jconst_fdct_islow_sse2))
return 0;
return 1;
}
GLOBAL(int)
jsimd_can_fdct_ifast (void)
{
/* The code is optimised for these values only */
if (DCTSIZE != 8)
return 0;
if (sizeof(DCTELEM) != 2)
return 0;
if (!IS_ALIGNED_SSE(jconst_fdct_ifast_sse2))
return 0;
return 1;
}
GLOBAL(int)
jsimd_can_fdct_float (void)
{
/* The code is optimised for these values only */
if (DCTSIZE != 8)
return 0;
if (sizeof(FAST_FLOAT) != 4)
return 0;
if (!IS_ALIGNED_SSE(jconst_fdct_float_sse))
return 0;
return 1;
}
GLOBAL(void)
jsimd_fdct_islow (DCTELEM * data)
{
jsimd_fdct_islow_sse2(data);
}
GLOBAL(void)
jsimd_fdct_ifast (DCTELEM * data)
{
jsimd_fdct_ifast_sse2(data);
}
GLOBAL(void)
jsimd_fdct_float (FAST_FLOAT * data)
{
jsimd_fdct_float_sse(data);
}
GLOBAL(int)
jsimd_can_quantize (void)
{
/* The code is optimised for these values only */
if (DCTSIZE != 8)
return 0;
if (sizeof(JCOEF) != 2)
return 0;
if (sizeof(DCTELEM) != 2)
return 0;
return 1;
}
GLOBAL(int)
jsimd_can_quantize_float (void)
{
/* The code is optimised for these values only */
if (DCTSIZE != 8)
return 0;
if (sizeof(JCOEF) != 2)
return 0;
if (sizeof(FAST_FLOAT) != 4)
return 0;
return 1;
}
GLOBAL(void)
jsimd_quantize (JCOEFPTR coef_block, DCTELEM * divisors,
DCTELEM * workspace)
{
jsimd_quantize_sse2(coef_block, divisors, workspace);
}
GLOBAL(void)
jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors,
FAST_FLOAT * workspace)
{
jsimd_quantize_float_sse2(coef_block, divisors, workspace);
}
GLOBAL(int)
jsimd_can_idct_2x2 (void)
{
/* The code is optimised for these values only */
if (DCTSIZE != 8)
return 0;
if (sizeof(JCOEF) != 2)
return 0;
if (BITS_IN_JSAMPLE != 8)
return 0;
if (sizeof(JDIMENSION) != 4)
return 0;
if (sizeof(ISLOW_MULT_TYPE) != 2)
return 0;
if (!IS_ALIGNED_SSE(jconst_idct_red_sse2))
return 0;
return 1;
}
GLOBAL(int)
jsimd_can_idct_4x4 (void)
{
/* The code is optimised for these values only */
if (DCTSIZE != 8)
return 0;
if (sizeof(JCOEF) != 2)
return 0;
if (BITS_IN_JSAMPLE != 8)
return 0;
if (sizeof(JDIMENSION) != 4)
return 0;
if (sizeof(ISLOW_MULT_TYPE) != 2)
return 0;
if (!IS_ALIGNED_SSE(jconst_idct_red_sse2))
return 0;
return 1;
}
GLOBAL(void)
jsimd_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
jsimd_idct_2x2_sse2(compptr->dct_table, coef_block, output_buf, output_col);
}
GLOBAL(void)
jsimd_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
jsimd_idct_4x4_sse2(compptr->dct_table, coef_block, output_buf, output_col);
}
GLOBAL(int)
jsimd_can_idct_islow (void)
{
/* The code is optimised for these values only */
if (DCTSIZE != 8)
return 0;
if (sizeof(JCOEF) != 2)
return 0;
if (BITS_IN_JSAMPLE != 8)
return 0;
if (sizeof(JDIMENSION) != 4)
return 0;
if (sizeof(ISLOW_MULT_TYPE) != 2)
return 0;
if (!IS_ALIGNED_SSE(jconst_idct_islow_sse2))
return 0;
return 1;
}
GLOBAL(int)
jsimd_can_idct_ifast (void)
{
/* The code is optimised for these values only */
if (DCTSIZE != 8)
return 0;
if (sizeof(JCOEF) != 2)
return 0;
if (BITS_IN_JSAMPLE != 8)
return 0;
if (sizeof(JDIMENSION) != 4)
return 0;
if (sizeof(IFAST_MULT_TYPE) != 2)
return 0;
if (IFAST_SCALE_BITS != 2)
return 0;
if (!IS_ALIGNED_SSE(jconst_idct_ifast_sse2))
return 0;
return 1;
}
GLOBAL(int)
jsimd_can_idct_float (void)
{
if (DCTSIZE != 8)
return 0;
if (sizeof(JCOEF) != 2)
return 0;
if (BITS_IN_JSAMPLE != 8)
return 0;
if (sizeof(JDIMENSION) != 4)
return 0;
if (sizeof(FAST_FLOAT) != 4)
return 0;
if (sizeof(FLOAT_MULT_TYPE) != 4)
return 0;
if (!IS_ALIGNED_SSE(jconst_idct_float_sse2))
return 0;
return 1;
}
GLOBAL(void)
jsimd_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
jsimd_idct_islow_sse2(compptr->dct_table, coef_block, output_buf,
output_col);
}
GLOBAL(void)
jsimd_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
jsimd_idct_ifast_sse2(compptr->dct_table, coef_block, output_buf,
output_col);
}
GLOBAL(void)
jsimd_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
jsimd_idct_float_sse2(compptr->dct_table, coef_block, output_buf,
output_col);
}
-110
View File
@@ -1,110 +0,0 @@
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
/* Define to 1 if you have the `feenableexcept' function. */
#define HAVE_FEENABLEEXCEPT 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the `m' library (-lm). */
#define HAVE_LIBM 1
/* Define to 1 if you have the `z' library (-lz). */
#define HAVE_LIBZ 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the `memset' function. */
#define HAVE_MEMSET 1
/* Define to 1 if you have the `pow' function. */
#define HAVE_POW 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#define LT_OBJDIR ".libs/"
/* Name of package */
#define PACKAGE "libpng"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "png-mng-implement@lists.sourceforge.net"
/* Define to the full name of this package. */
#define PACKAGE_NAME "libpng"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "libpng 1.6.16"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "libpng"
/* Define to the home page for this package. */
#define PACKAGE_URL ""
/* Define to the version of this package. */
#define PACKAGE_VERSION "1.6.16"
/* Turn on ARM Neon optimizations at run-time */
/* #undef PNG_ARM_NEON_API_SUPPORTED */
/* Check for ARM Neon support at run-time */
/* #undef PNG_ARM_NEON_CHECK_SUPPORTED */
/* Enable ARM Neon optimizations */
/* #undef PNG_ARM_NEON_OPT */
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define to 1 if your <sys/time.h> declares `struct tm'. */
/* #undef TM_IN_SYS_TIME */
/* Version number of package */
#define VERSION "1.6.16"
/* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */
/* Define to the equivalent of the C99 'restrict' keyword, or to
nothing if this is not supported. Do not define if restrict is
supported directly. */
#define restrict __restrict
/* Work around a bug in Sun C++: it does not support _Restrict or
__restrict__, even though the corresponding Sun C compiler ends up with
"#define restrict _Restrict" or "#define restrict __restrict__" in the
previous line. Perhaps some future version of Sun C++ will work with
restrict; if so, hopefully it defines __RESTRICT like Sun C does. */
#if defined __SUNPRO_CC && !defined __RESTRICT
# define _Restrict
# define __restrict__
#endif
/* Define to `unsigned int' if <sys/types.h> does not define. */
/* #undef size_t */
Binary file not shown.

Before

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 291 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 285 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 427 B

Loaded 100 of 1121 files, more files were not shown because too many files have changed in this diff. Show more