diff options
author | Dan Willemsen <dwillemsen@google.com> | 2019-06-19 15:08:13 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-06-19 15:08:13 -0700 |
commit | 7e41373003950b89bb8e42b471fe4a1a718139d5 (patch) | |
tree | e72ed953d9fe7db3a4fa40dced6cb8c13fae27b5 | |
parent | de8eec63430055d88f016b2177050615275977b6 (diff) | |
parent | a2801f323dc19a75fce889e552773b98d874a7bd (diff) | |
download | Gallery2-7e41373003950b89bb8e42b471fe4a1a718139d5.tar.gz |
Merge changes Ie4ea31b8,I87ff245c am: 1fce6e83f1
am: a2801f323d
Change-Id: I0c867441cafa2fe66d27321298ac8396735ba0ff
35 files changed, 166 insertions, 4266 deletions
diff --git a/Android.bp b/Android.bp new file mode 100644 index 000000000..ca9a173ae --- /dev/null +++ b/Android.bp @@ -0,0 +1,44 @@ +android_app { + name: "Gallery2", + + static_libs: [ + "androidx.fragment_fragment", + "androidx.legacy_legacy-support-core-ui", + "androidx.core_core", + "androidx.legacy_legacy-support-v13", + "com.android.gallery3d.common2", + "xmp_toolkit", + "mp4parser", + ], + + srcs: [ + "src/**/*.java", + "src_pd/**/*.java", + ], + + resource_dirs: ["res"], + + product_specific: true, + + overrides: [ + "Gallery", + "Gallery3D", + "GalleryNew3D", + ], + + sdk_version: "current", + + jni_libs: [ + "libjni_eglfence", + "libjni_filtershow_filters", + "libjni_jpegstream", + ], + + optimize: { + proguard_flags_files: ["proguard.flags"], + }, + + libs: ["org.apache.http.legacy"], + + jarjar_rules: "jarjar-rules.txt", +} diff --git a/Android.mk b/Android.mk deleted file mode 100644 index 22ad7079a..000000000 --- a/Android.mk +++ /dev/null @@ -1,49 +0,0 @@ -LOCAL_PATH:= $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := optional - -LOCAL_STATIC_ANDROID_LIBRARIES := \ - androidx.fragment_fragment \ - androidx.legacy_legacy-support-core-ui \ - androidx.core_core \ - androidx.legacy_legacy-support-v13 - -LOCAL_STATIC_JAVA_LIBRARIES := \ - com.android.gallery3d.common2 \ - xmp_toolkit \ - mp4parser - -LOCAL_SRC_FILES := \ - $(call all-java-files-under, src) \ - $(call all-renderscript-files-under, src) \ - $(call all-java-files-under, src_pd) - -LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/res - -LOCAL_USE_AAPT2 := true - -LOCAL_PACKAGE_NAME := Gallery2 - -LOCAL_PRODUCT_MODULE := true - -LOCAL_OVERRIDES_PACKAGES := Gallery Gallery3D GalleryNew3D - -LOCAL_SDK_VERSION := current - -LOCAL_JNI_SHARED_LIBRARIES := \ - libjni_eglfence \ - libjni_filtershow_filters \ - libjni_jpegstream - -LOCAL_PROGUARD_FLAG_FILES := proguard.flags - -LOCAL_JAVA_LIBRARIES += org.apache.http.legacy - -LOCAL_JARJAR_RULES := $(LOCAL_PATH)/jarjar-rules.txt - -include $(BUILD_PACKAGE) - -# Use the following include to make gallery test apk -include $(call all-makefiles-under, $(LOCAL_PATH)) diff --git a/gallerycommon/Android.bp b/gallerycommon/Android.bp new file mode 100644 index 000000000..9ce3e9ff6 --- /dev/null +++ b/gallerycommon/Android.bp @@ -0,0 +1,19 @@ +// Copyright 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. + +java_library { + name: "com.android.gallery3d.common2", + srcs: ["src/**/*.java"], + sdk_version: "16", +} diff --git a/gallerycommon/Android.mk b/gallerycommon/Android.mk deleted file mode 100644 index 1d341472c..000000000 --- a/gallerycommon/Android.mk +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 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. - -LOCAL_PATH := $(call my-dir) - -# Build the com.android.emailcommon static library. At the moment, this includes -# the emailcommon files themselves plus everything under src/org (apache code). All of our -# AIDL files are also compiled into the static library - -include $(CLEAR_VARS) - -LOCAL_MODULE := com.android.gallery3d.common2 -LOCAL_SRC_FILES := $(call all-java-files-under, src) -LOCAL_SDK_VERSION := 16 - -include $(BUILD_STATIC_JAVA_LIBRARY) diff --git a/jni/Android.bp b/jni/Android.bp new file mode 100644 index 000000000..0c0ecb7f8 --- /dev/null +++ b/jni/Android.bp @@ -0,0 +1,66 @@ +cc_defaults { + name: "gallery2_jni_defaults", + product_specific: true, + + cflags: [ + "-Wall", + "-Wextra", + "-Werror", + + // to fix implicit conversion from 'int' to 'char', (255 to -1, 128 to -128) + "-Wno-error=constant-conversion", + + "-Wno-unused-parameter", + ], + sdk_version: "9", + shared_libs: ["liblog"], +} + +cc_library_shared { + name: "libjni_eglfence", + defaults: ["gallery2_jni_defaults"], + + cflags: ["-DEGL_EGLEXT_PROTOTYPES"], + shared_libs: ["libEGL"], + srcs: ["jni_egl_fence.cpp"], +} + +// Filtershow +cc_library_shared { + name: "libjni_filtershow_filters", + defaults: ["gallery2_jni_defaults"], + + srcs: [ + "filters/gradient.c", + "filters/saturated.c", + "filters/exposure.c", + "filters/edge.c", + "filters/contrast.c", + "filters/hue.c", + "filters/shadows.c", + "filters/highlight.c", + "filters/hsv.c", + "filters/vibrance.c", + "filters/geometry.c", + "filters/negative.c", + "filters/redEyeMath.c", + "filters/fx.c", + "filters/wbalance.c", + "filters/redeye.c", + "filters/bwfilter.c", + "filters/tinyplanet.cc", + "filters/kmeans.cc", + ], + + cflags: [ + "-ffast-math", + "-O3", + "-funroll-loops", + ], + shared_libs: ["libjnigraphics"], + arch: { + arm: { + instruction_set: "arm", + }, + }, +} diff --git a/jni/Android.mk b/jni/Android.mk deleted file mode 100644 index c08d7be89..000000000 --- a/jni/Android.mk +++ /dev/null @@ -1,63 +0,0 @@ -LOCAL_PATH:= $(call my-dir) - -Gallery2_jni_cflags := \ - -Wall -Wextra -Werror \ - -Wno-error=constant-conversion \ - -Wno-unused-parameter \ - -# to fix implicit conversion from 'int' to 'char', (255 to -1, 128 to -128) - -include $(CLEAR_VARS) - -LOCAL_CFLAGS += -DEGL_EGLEXT_PROTOTYPES -LOCAL_CFLAGS += $(Gallery2_jni_cflags) - -LOCAL_SRC_FILES := jni_egl_fence.cpp - -LOCAL_SDK_VERSION := 9 - -LOCAL_MODULE_TAGS := optional - -LOCAL_MODULE := libjni_eglfence - -LOCAL_PRODUCT_MODULE := true - -LOCAL_LDLIBS := -llog -lEGL - - -include $(BUILD_SHARED_LIBRARY) - -# Filtershow - -include $(CLEAR_VARS) - -LOCAL_CPP_EXTENSION := .cc -LOCAL_SDK_VERSION := 9 -LOCAL_MODULE := libjni_filtershow_filters -LOCAL_PRODUCT_MODULE := true -LOCAL_SRC_FILES := filters/gradient.c \ - filters/saturated.c \ - filters/exposure.c \ - filters/edge.c \ - filters/contrast.c \ - filters/hue.c \ - filters/shadows.c \ - filters/highlight.c \ - filters/hsv.c \ - filters/vibrance.c \ - filters/geometry.c \ - filters/negative.c \ - filters/redEyeMath.c \ - filters/fx.c \ - filters/wbalance.c \ - filters/redeye.c \ - filters/bwfilter.c \ - filters/tinyplanet.cc \ - filters/kmeans.cc - -LOCAL_CFLAGS += -ffast-math -O3 -funroll-loops -LOCAL_CFLAGS += $(Gallery2_jni_cflags) -LOCAL_LDLIBS := -llog -ljnigraphics -LOCAL_ARM_MODE := arm - -include $(BUILD_SHARED_LIBRARY) diff --git a/jni/Application.mk b/jni/Application.mk deleted file mode 100644 index 22d188e59..000000000 --- a/jni/Application.mk +++ /dev/null @@ -1 +0,0 @@ -APP_PLATFORM := android-9 diff --git a/jni_jpegstream/Android.bp b/jni_jpegstream/Android.bp new file mode 100644 index 000000000..49350c6c1 --- /dev/null +++ b/jni_jpegstream/Android.bp @@ -0,0 +1,37 @@ +// Jpeg Streaming native +cc_library_shared { + name: "libjni_jpegstream", + product_specific: true, + + static_libs: ["libjpeg_static_ndk"], + shared_libs: ["liblog"], + + arch: { + arm: { + instruction_set: "arm", + }, + }, + cflags: [ + "-ffast-math", + "-O3", + "-funroll-loops", + + "-Wall", + "-Wextra", + "-Werror", + ], + local_include_dirs: ["src"], + sdk_version: "17", + stl: "c++_static", + + srcs: [ + "src/inputstream_wrapper.cpp", + "src/jpegstream.cpp", + "src/jerr_hook.cpp", + "src/jpeg_hook.cpp", + "src/jpeg_writer.cpp", + "src/jpeg_reader.cpp", + "src/outputstream_wrapper.cpp", + "src/stream_wrapper.cpp", + ], +} diff --git a/jni_jpegstream/Android.mk b/jni_jpegstream/Android.mk deleted file mode 100644 index f1ea324fe..000000000 --- a/jni_jpegstream/Android.mk +++ /dev/null @@ -1,36 +0,0 @@ -LOCAL_PATH:= $(call my-dir) - -# Jpeg Streaming native - -include $(CLEAR_VARS) - -LOCAL_MODULE := libjni_jpegstream - -LOCAL_NDK_STL_VARIANT := c++_static - -LOCAL_C_INCLUDES := $(LOCAL_PATH) \ - $(LOCAL_PATH)/src - -LOCAL_STATIC_LIBRARIES := libjpeg_static_ndk - -LOCAL_SDK_VERSION := 17 -LOCAL_ARM_MODE := arm -LOCAL_PRODUCT_MODULE := true - -LOCAL_CFLAGS += -ffast-math -O3 -funroll-loops -LOCAL_CFLAGS += -Wall -Wextra -Werror -LOCAL_LDLIBS := -llog - -LOCAL_CPP_EXTENSION := .cpp -LOCAL_SRC_FILES := \ - src/inputstream_wrapper.cpp \ - src/jpegstream.cpp \ - src/jerr_hook.cpp \ - src/jpeg_hook.cpp \ - src/jpeg_writer.cpp \ - src/jpeg_reader.cpp \ - src/outputstream_wrapper.cpp \ - src/stream_wrapper.cpp - - -include $(BUILD_SHARED_LIBRARY) diff --git a/res/layout/editor_grad_button.xml b/res/layout/editor_grad_button.xml deleted file mode 100644 index 4d1b10b6b..000000000 --- a/res/layout/editor_grad_button.xml +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- - 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. ---> - -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_weight="1" - android:layout_alignParentTop="true" - android:layout_marginLeft="26dp" - android:layout_marginTop="21dp" - android:orientation="horizontal" > - - <com.android.gallery3d.filtershow.ui.FramedTextButton - android:id="@+id/editorGradButton" - android:layout_width="84dip" - android:layout_height="84dip" - android:layout_gravity="center_vertical|left" - android:background="@drawable/filtershow_button_background" - android:scaleType="centerInside" - android:visibility="visible" - android:text="@string/editor_grad_style" /> - - <ToggleButton - android:id="@+id/editor_grad_new" - android:layout_width="84dip" - android:layout_height="84dip" - android:layout_gravity="center_vertical|left" - android:background="@drawable/filtershow_grad_button" - android:scaleType="centerInside" - android:visibility="visible" - android:textOff="@string/editor_grad_new" - android:textOn="@string/editor_grad_new" /> - -</LinearLayout>
\ No newline at end of file diff --git a/res/layout/filtershow_grad_editor.xml b/res/layout/filtershow_grad_editor.xml deleted file mode 100644 index 6c4721e62..000000000 --- a/res/layout/filtershow_grad_editor.xml +++ /dev/null @@ -1,29 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- - 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. ---> - -<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@+id/gradEditor" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_weight="1" > - - <com.android.gallery3d.filtershow.imageshow.ImageGrad - android:id="@+id/imageShow" - android:layout_width="match_parent" - android:layout_height="wrap_content" /> - - </FrameLayout>
\ No newline at end of file diff --git a/res/layout/filtershow_vignette_editor.xml b/res/layout/filtershow_vignette_editor.xml deleted file mode 100644 index 9c9b4cb59..000000000 --- a/res/layout/filtershow_vignette_editor.xml +++ /dev/null @@ -1,30 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- - 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. ---> - -<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:iconbutton="http://schemas.android.com/apk/res/com.android.gallery3d" - android:id="@+id/vignetteEditor" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_weight="1" > - - <com.android.gallery3d.filtershow.imageshow.ImageVignette - android:id="@+id/imageVignette" - android:layout_width="match_parent" - android:layout_height="wrap_content" /> - - </FrameLayout>
\ No newline at end of file diff --git a/res/values/filtershow_ids.xml b/res/values/filtershow_ids.xml index 460da61aa..b22d1a505 100644 --- a/res/values/filtershow_ids.xml +++ b/res/values/filtershow_ids.xml @@ -48,6 +48,4 @@ <item type="id" name="editorRotate" /> <item type="id" name="editorStraighten" /> <item type="id" name="editorParametric" /> - <item type="id" name="editorGrad" /> - <item type="id" name="editorChanSat" /> </resources> diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java index d0bc29ad0..937c5290b 100644 --- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java +++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java @@ -79,11 +79,9 @@ import com.android.gallery3d.filtershow.category.SwipableView; import com.android.gallery3d.filtershow.data.UserPresetsManager; import com.android.gallery3d.filtershow.editors.BasicEditor; import com.android.gallery3d.filtershow.editors.Editor; -import com.android.gallery3d.filtershow.editors.EditorChanSat; import com.android.gallery3d.filtershow.editors.EditorColorBorder; import com.android.gallery3d.filtershow.editors.EditorCrop; import com.android.gallery3d.filtershow.editors.EditorDraw; -import com.android.gallery3d.filtershow.editors.EditorGrad; import com.android.gallery3d.filtershow.editors.EditorManager; import com.android.gallery3d.filtershow.editors.EditorMirror; import com.android.gallery3d.filtershow.editors.EditorPanel; @@ -516,8 +514,6 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL } private void fillEditors() { - mEditorPlaceHolder.addEditor(new EditorChanSat()); - mEditorPlaceHolder.addEditor(new EditorGrad()); mEditorPlaceHolder.addEditor(new EditorDraw()); mEditorPlaceHolder.addEditor(new EditorColorBorder()); mEditorPlaceHolder.addEditor(new BasicEditor()); diff --git a/src/com/android/gallery3d/filtershow/editors/EditorChanSat.java b/src/com/android/gallery3d/filtershow/editors/EditorChanSat.java deleted file mode 100644 index abf0a690f..000000000 --- a/src/com/android/gallery3d/filtershow/editors/EditorChanSat.java +++ /dev/null @@ -1,383 +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.android.gallery3d.filtershow.editors; - -import android.content.Context; -import android.graphics.Bitmap; -import android.os.Handler; -import android.view.LayoutInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.widget.LinearLayout; -import android.widget.PopupMenu; -import android.widget.SeekBar; -import android.widget.SeekBar.OnSeekBarChangeListener; - -import android.widget.TextView; -import com.android.gallery3d.R; -import com.android.gallery3d.filtershow.FilterShowActivity; -import com.android.gallery3d.filtershow.controller.BasicParameterStyle; -import com.android.gallery3d.filtershow.controller.BitmapCaller; -import com.android.gallery3d.filtershow.controller.FilterView; -import com.android.gallery3d.filtershow.controller.Parameter; -import com.android.gallery3d.filtershow.filters.FilterBasicRepresentation; -import com.android.gallery3d.filtershow.filters.FilterChanSatRepresentation; -import com.android.gallery3d.filtershow.filters.FilterRepresentation; -import com.android.gallery3d.filtershow.imageshow.MasterImage; -import com.android.gallery3d.filtershow.pipeline.ImagePreset; - -public class EditorChanSat extends ParametricEditor implements OnSeekBarChangeListener, FilterView { - public static final int ID = R.id.editorChanSat; - private final String LOGTAG = "EditorGrunge"; - private SwapButton mButton; - private final Handler mHandler = new Handler(); - - private SeekBar mMainBar; - private SeekBar mRedBar; - private SeekBar mYellowBar; - private SeekBar mGreenBar; - private SeekBar mCyanBar; - private SeekBar mBlueBar; - private SeekBar mMagentaBar; - private TextView mMainValue; - private TextView mRedValue; - private TextView mYellowValue; - private TextView mGreenValue; - private TextView mCyanValue; - private TextView mBlueValue; - private TextView mMagentaValue; - - int[] mMenuStrings = { - R.string.editor_chan_sat_main, - R.string.editor_chan_sat_red, - R.string.editor_chan_sat_yellow, - R.string.editor_chan_sat_green, - R.string.editor_chan_sat_cyan, - R.string.editor_chan_sat_blue, - R.string.editor_chan_sat_magenta - }; - - String mCurrentlyEditing = null; - - public EditorChanSat() { - super(ID, R.layout.filtershow_default_editor, R.id.basicEditor); - } - - @Override - public String calculateUserMessage(Context context, String effectName, Object parameterValue) { - FilterRepresentation rep = getLocalRepresentation(); - if (rep == null || !(rep instanceof FilterChanSatRepresentation)) { - return ""; - } - FilterChanSatRepresentation csrep = (FilterChanSatRepresentation) rep; - int mode = csrep.getParameterMode(); - String paramString; - - paramString = mContext.getString(mMenuStrings[mode]); - - int val = csrep.getCurrentParameter(); - return paramString + ((val > 0) ? " +" : " ") + val; - } - - @Override - public void openUtilityPanel(final LinearLayout accessoryViewList) { - mButton = (SwapButton) accessoryViewList.findViewById(R.id.applyEffect); - mButton.setText(mContext.getString(R.string.editor_chan_sat_main)); - - if (useCompact(mContext)) { - final PopupMenu popupMenu = new PopupMenu(mImageShow.getActivity(), mButton); - - popupMenu.getMenuInflater().inflate(R.menu.filtershow_menu_chan_sat, - popupMenu.getMenu()); - - popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - selectMenuItem(item); - return true; - } - }); - mButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View arg0) { - popupMenu.show(); - ((FilterShowActivity)mContext).onShowMenu(popupMenu); - } - }); - mButton.setListener(this); - - FilterChanSatRepresentation csrep = getChanSatRep(); - String menuString = mContext.getString(mMenuStrings[0]); - switchToMode(csrep, FilterChanSatRepresentation.MODE_MASTER, menuString); - } else { - mButton.setText(mContext.getString(R.string.saturation)); - } - } - - @Override - public void reflectCurrentFilter() { - if (useCompact(mContext)) { - super.reflectCurrentFilter(); - updateText(); - return; - } - mLocalRepresentation = null; - if (getLocalRepresentation() != null - && getLocalRepresentation() instanceof FilterChanSatRepresentation) { - FilterChanSatRepresentation rep = - (FilterChanSatRepresentation) getLocalRepresentation(); - int value = rep.getValue(FilterChanSatRepresentation.MODE_MASTER); - mMainBar.setProgress(value + 100); - mMainValue.setText("" + value); - value = rep.getValue(FilterChanSatRepresentation.MODE_RED); - mRedBar.setProgress(value + 100); - mRedValue.setText("" + value); - value = rep.getValue(FilterChanSatRepresentation.MODE_YELLOW); - mYellowBar.setProgress(value + 100); - mYellowValue.setText("" + value); - value = rep.getValue(FilterChanSatRepresentation.MODE_GREEN); - mGreenBar.setProgress(value + 100); - mGreenValue.setText("" + value); - value = rep.getValue(FilterChanSatRepresentation.MODE_CYAN); - mCyanBar.setProgress(value + 100); - mCyanValue.setText("" + value); - value = rep.getValue(FilterChanSatRepresentation.MODE_BLUE); - mBlueBar.setProgress(value + 100); - mBlueValue.setText("" + value); - value = rep.getValue(FilterChanSatRepresentation.MODE_MAGENTA); - mMagentaBar.setProgress(value + 100); - mMagentaValue.setText("" + value); - String text = mContext.getString(rep.getTextId()).toUpperCase(); - mFilterTitle.setText(text); - updateText(); - } - } - - @Override - public void setUtilityPanelUI(View actionButton, View editControl) { - if (useCompact(mContext)) { - super.setUtilityPanelUI(actionButton, editControl); - return; - } - mActionButton = actionButton; - mEditControl = editControl; - mEditTitle.setCompoundDrawables(null, null, null, null); - LinearLayout group = (LinearLayout) editControl; - LayoutInflater inflater = - (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - LinearLayout controls = (LinearLayout) inflater.inflate( - R.layout.filtershow_saturation_controls, group, false); - ViewGroup.LayoutParams lp = new LinearLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - controls.setLayoutParams(lp); - group.removeAllViews(); - group.addView(controls); - mMainBar = (SeekBar) controls.findViewById(R.id.mainSeekbar); - mMainBar.setMax(200); - mMainBar.setOnSeekBarChangeListener(this); - mMainValue = (TextView) controls.findViewById(R.id.mainValue); - mRedBar = (SeekBar) controls.findViewById(R.id.redSeekBar); - mRedBar.setMax(200); - mRedBar.setOnSeekBarChangeListener(this); - mRedValue = (TextView) controls.findViewById(R.id.redValue); - mYellowBar = (SeekBar) controls.findViewById(R.id.yellowSeekBar); - mYellowBar.setMax(200); - mYellowBar.setOnSeekBarChangeListener(this); - mYellowValue = (TextView) controls.findViewById(R.id.yellowValue); - mGreenBar = (SeekBar) controls.findViewById(R.id.greenSeekBar); - mGreenBar.setMax(200); - mGreenBar.setOnSeekBarChangeListener(this); - mGreenValue = (TextView) controls.findViewById(R.id.greenValue); - mCyanBar = (SeekBar) controls.findViewById(R.id.cyanSeekBar); - mCyanBar.setMax(200); - mCyanBar.setOnSeekBarChangeListener(this); - mCyanValue = (TextView) controls.findViewById(R.id.cyanValue); - mBlueBar = (SeekBar) controls.findViewById(R.id.blueSeekBar); - mBlueBar.setMax(200); - mBlueBar.setOnSeekBarChangeListener(this); - mBlueValue = (TextView) controls.findViewById(R.id.blueValue); - mMagentaBar = (SeekBar) controls.findViewById(R.id.magentaSeekBar); - mMagentaBar.setMax(200); - mMagentaBar.setOnSeekBarChangeListener(this); - mMagentaValue = (TextView) controls.findViewById(R.id.magentaValue); - } - - public int getParameterIndex(int id) { - switch (id) { - case R.id.editor_chan_sat_main: - return FilterChanSatRepresentation.MODE_MASTER; - case R.id.editor_chan_sat_red: - return FilterChanSatRepresentation.MODE_RED; - case R.id.editor_chan_sat_yellow: - return FilterChanSatRepresentation.MODE_YELLOW; - case R.id.editor_chan_sat_green: - return FilterChanSatRepresentation.MODE_GREEN; - case R.id.editor_chan_sat_cyan: - return FilterChanSatRepresentation.MODE_CYAN; - case R.id.editor_chan_sat_blue: - return FilterChanSatRepresentation.MODE_BLUE; - case R.id.editor_chan_sat_magenta: - return FilterChanSatRepresentation.MODE_MAGENTA; - } - return -1; - } - - @Override - public void detach() { - if (mButton == null) { - return; - } - mButton.setListener(null); - mButton.setOnClickListener(null); - } - - private void updateSeekBar(FilterChanSatRepresentation rep) { - mControl.updateUI(); - } - - @Override - protected Parameter getParameterToEdit(FilterRepresentation rep) { - if (rep instanceof FilterChanSatRepresentation) { - FilterChanSatRepresentation csrep = (FilterChanSatRepresentation) rep; - Parameter param = csrep.getFilterParameter(csrep.getParameterMode()); - if (param instanceof BasicParameterStyle) { - param.setFilterView(EditorChanSat.this); - } - return param; - } - return null; - } - - private FilterChanSatRepresentation getChanSatRep() { - FilterRepresentation rep = getLocalRepresentation(); - if (rep != null - && rep instanceof FilterChanSatRepresentation) { - FilterChanSatRepresentation csrep = (FilterChanSatRepresentation) rep; - return csrep; - } - return null; - } - - @Override - public void computeIcon(int n, BitmapCaller caller) { - FilterChanSatRepresentation rep = getChanSatRep(); - if (rep == null) return; - rep = (FilterChanSatRepresentation) rep.copy(); - ImagePreset preset = new ImagePreset(); - preset.addFilter(rep); - Bitmap src = MasterImage.getImage().getThumbnailBitmap(); - caller.available(src); - } - - protected void selectMenuItem(MenuItem item) { - if (getLocalRepresentation() != null - && getLocalRepresentation() instanceof FilterChanSatRepresentation) { - FilterChanSatRepresentation csrep = - (FilterChanSatRepresentation) getLocalRepresentation(); - - switchToMode(csrep, getParameterIndex(item.getItemId()), item.getTitle().toString()); - - } - } - - protected void switchToMode(FilterChanSatRepresentation csrep, int mode, String title) { - if (csrep == null) { - return; - } - csrep.setParameterMode(mode); - mCurrentlyEditing = title; - mButton.setText(mCurrentlyEditing); - { - Parameter param = getParameterToEdit(csrep); - - control(param, mEditControl); - } - updateSeekBar(csrep); - mView.invalidate(); - } - - @Override - public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) { - FilterChanSatRepresentation rep = getChanSatRep(); - int value = progress - 100; - switch (sbar.getId()) { - case R.id.mainSeekbar: - rep.setParameterMode(FilterChanSatRepresentation.MODE_MASTER); - mMainValue.setText("" + value); - break; - case R.id.redSeekBar: - rep.setParameterMode(FilterChanSatRepresentation.MODE_RED); - mRedValue.setText("" + value); - break; - case R.id.yellowSeekBar: - rep.setParameterMode(FilterChanSatRepresentation.MODE_YELLOW); - mYellowValue.setText("" + value); - break; - case R.id.greenSeekBar: - rep.setParameterMode(FilterChanSatRepresentation.MODE_GREEN); - mGreenValue.setText("" + value); - break; - case R.id.cyanSeekBar: - rep.setParameterMode(FilterChanSatRepresentation.MODE_CYAN); - mCyanValue.setText("" + value); - break; - case R.id.blueSeekBar: - rep.setParameterMode(FilterChanSatRepresentation.MODE_BLUE); - mBlueValue.setText("" + value); - break; - case R.id.magentaSeekBar: - rep.setParameterMode(FilterChanSatRepresentation.MODE_MAGENTA); - mMagentaValue.setText("" + value); - break; - } - rep.setCurrentParameter(value); - commitLocalRepresentation(); - } - - @Override - public void swapLeft(MenuItem item) { - super.swapLeft(item); - mButton.setTranslationX(0); - mButton.animate().translationX(mButton.getWidth()).setDuration(SwapButton.ANIM_DURATION); - Runnable updateButton = new Runnable() { - @Override - public void run() { - mButton.animate().cancel(); - mButton.setTranslationX(0); - } - }; - mHandler.postDelayed(updateButton, SwapButton.ANIM_DURATION); - selectMenuItem(item); - } - - @Override - public void swapRight(MenuItem item) { - super.swapRight(item); - mButton.setTranslationX(0); - mButton.animate().translationX(-mButton.getWidth()).setDuration(SwapButton.ANIM_DURATION); - Runnable updateButton = new Runnable() { - @Override - public void run() { - mButton.animate().cancel(); - mButton.setTranslationX(0); - } - }; - mHandler.postDelayed(updateButton, SwapButton.ANIM_DURATION); - selectMenuItem(item); - } -} diff --git a/src/com/android/gallery3d/filtershow/editors/EditorGrad.java b/src/com/android/gallery3d/filtershow/editors/EditorGrad.java deleted file mode 100644 index 059121634..000000000 --- a/src/com/android/gallery3d/filtershow/editors/EditorGrad.java +++ /dev/null @@ -1,433 +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.android.gallery3d.filtershow.editors; - -import android.content.Context; -import android.view.LayoutInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.FrameLayout; -import android.widget.LinearLayout; -import android.widget.PopupMenu; -import android.widget.SeekBar; -import android.widget.SeekBar.OnSeekBarChangeListener; -import android.widget.TextView; -import android.widget.ToggleButton; - -import com.android.gallery3d.R; -import com.android.gallery3d.filtershow.FilterShowActivity; -import com.android.gallery3d.filtershow.controller.Control; -import com.android.gallery3d.filtershow.controller.FilterView; -import com.android.gallery3d.filtershow.controller.Parameter; -import com.android.gallery3d.filtershow.controller.ParameterActionAndInt; -import com.android.gallery3d.filtershow.filters.FilterGradRepresentation; -import com.android.gallery3d.filtershow.filters.FilterRepresentation; -import com.android.gallery3d.filtershow.imageshow.ImageGrad; -import com.android.gallery3d.filtershow.imageshow.MasterImage; - -public class EditorGrad extends ParametricEditor - implements OnSeekBarChangeListener, ParameterActionAndInt { - private static final String LOGTAG = "EditorGrad"; - public static final int ID = R.id.editorGrad; - PopupMenu mPopupMenu; - ToggleButton mAddModeButton; - String mEffectName = ""; - private static final int MODE_BRIGHTNESS = FilterGradRepresentation.PARAM_BRIGHTNESS; - private static final int MODE_SATURATION = FilterGradRepresentation.PARAM_SATURATION; - private static final int MODE_CONTRAST = FilterGradRepresentation.PARAM_CONTRAST; - private static final int ADD_ICON = R.drawable.ic_grad_add; - private static final int DEL_ICON = R.drawable.ic_grad_del; - private int mSliderMode = MODE_BRIGHTNESS; - ImageGrad mImageGrad; - ParamAdapter []mAdapters = new ParamAdapter[3]; - public EditorGrad() { - super(ID, R.layout.filtershow_grad_editor, R.id.gradEditor); - } - - @Override - public void createEditor(Context context, FrameLayout frameLayout) { - super.createEditor(context, frameLayout); - mImageGrad = (ImageGrad) mImageShow; - mImageGrad.setEditor(this); - - } - - public void clearAddMode() { - mAddModeButton.setChecked(false); - FilterRepresentation tmpRep = getLocalRepresentation(); - if (tmpRep instanceof FilterGradRepresentation) { - updateMenuItems((FilterGradRepresentation) tmpRep); - } - } - - @Override - public void reflectCurrentFilter() { - super.reflectCurrentFilter(); - FilterRepresentation tmpRep = getLocalRepresentation(); - if (tmpRep instanceof FilterGradRepresentation) { - FilterGradRepresentation rep = (FilterGradRepresentation) tmpRep; - boolean f = rep.showParameterValue(); - - mImageGrad.setRepresentation(rep); - } - } - - public void updateSeekBar(FilterGradRepresentation rep) { - if (ParametricEditor.useCompact(mContext)) { - mControl.updateUI(); - } else { - updateParameters(); - } - } - - @Override - public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) { - FilterRepresentation tmpRep = getLocalRepresentation(); - if (tmpRep instanceof FilterGradRepresentation) { - FilterGradRepresentation rep = (FilterGradRepresentation) tmpRep; - int min = rep.getParameterMin(mSliderMode); - int value = progress + min; - rep.setParameter(mSliderMode, value); - mView.invalidate(); - commitLocalRepresentation(); - } - } - - @Override - public void openUtilityPanel(final LinearLayout accessoryViewList) { - Button view = (Button) accessoryViewList.findViewById(R.id.applyEffect); - if (useCompact(mContext)) { - view.setText(mContext.getString(R.string.editor_grad_brightness)); - view.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View arg0) { - showPopupMenu(accessoryViewList); - } - }); - - setUpPopupMenu(view); - setEffectName(); - } else { - view.setText(mContext.getString(R.string.grad)); - } - } - - private void updateMenuItems(FilterGradRepresentation rep) { - int n = rep.getNumberOfBands(); - } - - public void setEffectName() { - if (mPopupMenu != null) { - MenuItem item = mPopupMenu.getMenu().findItem(R.id.editor_grad_brightness); - mEffectName = item.getTitle().toString(); - } - } - - @Override - public void setUtilityPanelUI(View actionButton, View editControl) { - if (ParametricEditor.useCompact(mContext)) { - super.setUtilityPanelUI(actionButton, editControl); - return; - } - mSeekBar = (SeekBar) editControl.findViewById(R.id.primarySeekBar); - if (mSeekBar != null) { - mSeekBar.setVisibility(View.GONE); - } - LayoutInflater inflater = - (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - LinearLayout lp = (LinearLayout) inflater.inflate( - R.layout.filtershow_grad_ui, (ViewGroup) editControl, true); - - mAdapters[0] = new ParamAdapter(R.id.gradContrastSeekBar, R.id.gradContrastValue, - lp, MODE_CONTRAST); - mAdapters[1] = new ParamAdapter(R.id.gradBrightnessSeekBar, R.id.gradBrightnessValue, - lp, MODE_BRIGHTNESS); - mAdapters[2] = new ParamAdapter(R.id.gradSaturationSeekBar, R.id.gradSaturationValue, - lp, MODE_SATURATION); - lp.findViewById(R.id.gradAddButton).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - fireLeftAction(); - } - }); - lp.findViewById(R.id.gradDelButton).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - fireRightAction(); - } - }); - setMenuIcon(false); - } - - public void updateParameters() { - FilterGradRepresentation rep = getGradRepresentation(); - for (int i = 0; i < mAdapters.length; i++) { - mAdapters[i].updateValues(rep); - } - } - - private class ParamAdapter implements OnSeekBarChangeListener { - SeekBar mSlider; - TextView mTextView; - int mMin = -100; - int mMax = 100; - int mMode; - - public ParamAdapter(int seekId, int textId, LinearLayout layout, int mode) { - mSlider = (SeekBar) layout.findViewById(seekId); - mTextView = (TextView) layout.findViewById(textId); - mSlider.setMax(mMax - mMin); - mMode = mode; - FilterGradRepresentation rep = getGradRepresentation(); - if (rep != null){ - updateValues(rep); - } - mSlider.setOnSeekBarChangeListener(this); - } - - public void updateValues(FilterGradRepresentation rep) { - int value = rep.getParameter(mMode); - mTextView.setText(Integer.toString(value)); - mSlider.setProgress(value - mMin); - } - - @Override - public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - FilterGradRepresentation rep = getGradRepresentation(); - int value = progress + mMin; - rep.setParameter(mMode, value); - if (mSliderMode != mMode) { - mSliderMode = mMode; - mEffectName = mContext.getResources().getString(getModeNameid(mMode)); - mEffectName = mEffectName.toUpperCase(); - } - mTextView.setText(Integer.toString(value)); - mView.invalidate(); - commitLocalRepresentation(); - } - - private int getModeNameid(int mode) { - switch (mode) { - case MODE_CONTRAST: - return R.string.editor_grad_contrast; - case MODE_BRIGHTNESS: - return R.string.editor_grad_brightness; - case MODE_SATURATION: - return R.string.editor_grad_saturation; - } - return 0; - } - - @Override - public void onStartTrackingTouch(SeekBar seekBar) { - - } - - @Override - public void onStopTrackingTouch(SeekBar seekBar) { - - } - } - - private void showPopupMenu(LinearLayout accessoryViewList) { - Button button = (Button) accessoryViewList.findViewById(R.id.applyEffect); - if (button == null) { - return; - } - - if (mPopupMenu == null) { - setUpPopupMenu(button); - } - mPopupMenu.show(); - ((FilterShowActivity)mContext).onShowMenu(mPopupMenu); - } - - private void setUpPopupMenu(Button button) { - mPopupMenu = new PopupMenu(mImageShow.getActivity(), button); - mPopupMenu.getMenuInflater() - .inflate(R.menu.filtershow_menu_grad, mPopupMenu.getMenu()); - FilterGradRepresentation rep = (FilterGradRepresentation) getLocalRepresentation(); - if (rep == null) { - return; - } - updateMenuItems(rep); - hackFixStrings(mPopupMenu.getMenu()); - setEffectName(); - updateText(); - - mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - FilterRepresentation tmpRep = getLocalRepresentation(); - - if (tmpRep instanceof FilterGradRepresentation) { - FilterGradRepresentation rep = (FilterGradRepresentation) tmpRep; - int cmdID = item.getItemId(); - switch (cmdID) { - case R.id.editor_grad_brightness: - mSliderMode = MODE_BRIGHTNESS; - mEffectName = item.getTitle().toString(); - break; - case R.id.editor_grad_contrast: - mSliderMode = MODE_CONTRAST; - mEffectName = item.getTitle().toString(); - break; - case R.id.editor_grad_saturation: - mSliderMode = MODE_SATURATION; - mEffectName = item.getTitle().toString(); - break; - } - updateMenuItems(rep); - updateSeekBar(rep); - - commitLocalRepresentation(); - mView.invalidate(); - } - return true; - } - }); - } - - @Override - public String calculateUserMessage(Context context, String effectName, Object parameterValue) { - FilterGradRepresentation rep = getGradRepresentation(); - if (rep == null) { - return mEffectName; - } - int val = rep.getParameter(mSliderMode); - return mEffectName.toUpperCase() + ((val > 0) ? " +" : " ") + val; - } - - private FilterGradRepresentation getGradRepresentation() { - FilterRepresentation tmpRep = getLocalRepresentation(); - if (tmpRep instanceof FilterGradRepresentation) { - return (FilterGradRepresentation) tmpRep; - } - return null; - } - - @Override - public int getMaximum() { - FilterGradRepresentation rep = getGradRepresentation(); - if (rep == null) { - return 0; - } - return rep.getParameterMax(mSliderMode); - } - - @Override - public int getMinimum() { - FilterGradRepresentation rep = getGradRepresentation(); - if (rep == null) { - return 0; - } - return rep.getParameterMin(mSliderMode); - } - - @Override - public int getDefaultValue() { - return 0; - } - - @Override - public int getValue() { - FilterGradRepresentation rep = getGradRepresentation(); - if (rep == null) { - return 0; - } - return rep.getParameter(mSliderMode); - } - - @Override - public String getValueString() { - return null; - } - - @Override - public void setValue(int value) { - FilterGradRepresentation rep = getGradRepresentation(); - if (rep == null) { - return; - } - rep.setParameter(mSliderMode, value); - } - - @Override - public String getParameterName() { - return mEffectName; - } - - @Override - public String getParameterType() { - return sParameterType; - } - - @Override - public void setController(Control c) { - - } - - @Override - public void fireLeftAction() { - FilterGradRepresentation rep = getGradRepresentation(); - if (rep == null) { - return; - } - rep.addBand(MasterImage.getImage().getOriginalBounds()); - updateMenuItems(rep); - updateSeekBar(rep); - - commitLocalRepresentation(); - mView.invalidate(); - } - - @Override - public int getLeftIcon() { - return ADD_ICON; - } - - @Override - public void fireRightAction() { - FilterGradRepresentation rep = getGradRepresentation(); - if (rep == null) { - return; - } - rep.deleteCurrentBand(); - - updateMenuItems(rep); - updateSeekBar(rep); - commitLocalRepresentation(); - mView.invalidate(); - } - - @Override - public int getRightIcon() { - return DEL_ICON; - } - - @Override - public void setFilterView(FilterView editor) { - - } - - @Override - public void copyFrom(Parameter src) { - - } -} diff --git a/src/com/android/gallery3d/filtershow/editors/EditorVignette.java b/src/com/android/gallery3d/filtershow/editors/EditorVignette.java deleted file mode 100644 index 630a1a9da..000000000 --- a/src/com/android/gallery3d/filtershow/editors/EditorVignette.java +++ /dev/null @@ -1,380 +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.android.gallery3d.filtershow.editors; - -import android.content.Context; -import android.os.Handler; -import android.view.LayoutInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.FrameLayout; -import android.widget.LinearLayout; -import android.widget.PopupMenu; -import android.widget.SeekBar; -import android.widget.TextView; - -import com.android.gallery3d.R; -import com.android.gallery3d.filtershow.FilterShowActivity; -import com.android.gallery3d.filtershow.controller.BasicParameterInt; -import com.android.gallery3d.filtershow.controller.Parameter; -import com.android.gallery3d.filtershow.filters.FilterVignetteRepresentation; -import com.android.gallery3d.filtershow.filters.FilterRepresentation; -import com.android.gallery3d.filtershow.imageshow.ImageVignette; - -public class EditorVignette extends ParametricEditor { - public static final int ID = R.id.vignetteEditor; - private static final String LOGTAG = "EditorVignettePlanet"; - ImageVignette mImageVignette; - - private SeekBar mVignetteBar; - private SeekBar mExposureBar; - private SeekBar mSaturationBar; - private SeekBar mContrastBar; - private SeekBar mFalloffBar; - - - private TextView mVignetteValue; - private TextView mExposureValue; - private TextView mSaturationValue; - private TextView mContrastValue; - private TextView mFalloffValue; - - private SwapButton mButton; - private final Handler mHandler = new Handler(); - - int[] mMenuStrings = { - R.string.vignette_main, - R.string.vignette_exposure, - R.string.vignette_saturation, - R.string.vignette_contrast, - R.string.vignette_falloff, - }; - - String mCurrentlyEditing = null; - - - public EditorVignette() { - super(ID, R.layout.filtershow_vignette_editor, R.id.imageVignette); - } - - @Override - public void createEditor(Context context, FrameLayout frameLayout) { - super.createEditor(context, frameLayout); - mImageVignette = (ImageVignette) mImageShow; - mImageVignette.setEditor(this); - } - - @Override - public void reflectCurrentFilter() { - if (useCompact(mContext)) { - super.reflectCurrentFilter(); - - FilterRepresentation rep = getLocalRepresentation(); - if (rep != null && getLocalRepresentation() instanceof FilterVignetteRepresentation) { - FilterVignetteRepresentation drawRep = (FilterVignetteRepresentation) rep; - mImageVignette.setRepresentation(drawRep); - } - updateText(); - return; - } - mLocalRepresentation = null; - if (getLocalRepresentation() != null - && getLocalRepresentation() instanceof FilterVignetteRepresentation) { - FilterVignetteRepresentation rep = - (FilterVignetteRepresentation) getLocalRepresentation(); - int min; - int []mode = { - FilterVignetteRepresentation.MODE_VIGNETTE, - FilterVignetteRepresentation.MODE_EXPOSURE, - FilterVignetteRepresentation.MODE_SATURATION, - FilterVignetteRepresentation.MODE_CONTRAST, - FilterVignetteRepresentation.MODE_FALLOFF - }; - SeekBar []sliders = { - mVignetteBar, - mExposureBar, - mSaturationBar, - mContrastBar, - mFalloffBar - }; - TextView []label = { - mVignetteValue, - mExposureValue, - mSaturationValue, - mContrastValue, - mFalloffValue - }; - for (int i = 0; i < mode.length; i++) { - BasicParameterInt p = (BasicParameterInt) rep.getFilterParameter(mode[i]); - int value = p.getValue(); - sliders[i].setMax(p.getMaximum() - p.getMinimum()); - sliders[i].setProgress(value - p.getMinimum()); - label[i].setText("" + value); - } - - mImageVignette.setRepresentation(rep); - String text = mContext.getString(rep.getTextId()).toUpperCase(); - mFilterTitle.setText(text); - updateText(); - } - } - - - - @Override - public String calculateUserMessage(Context context, String effectName, Object parameterValue) { - FilterRepresentation rep = getLocalRepresentation(); - if (rep == null || !(rep instanceof FilterVignetteRepresentation)) { - return ""; - } - FilterVignetteRepresentation csrep = (FilterVignetteRepresentation) rep; - int mode = csrep.getParameterMode(); - String paramString; - - paramString = mContext.getString(mMenuStrings[mode]); - - int val = csrep.getCurrentParameter(); - return paramString + ((val > 0) ? " +" : " ") + val; - } - - @Override - public void openUtilityPanel(final LinearLayout accessoryViewList) { - mButton = (SwapButton) accessoryViewList.findViewById(R.id.applyEffect); - mButton.setText(mContext.getString(R.string.vignette_main)); - - if (useCompact(mContext)) { - final PopupMenu popupMenu = new PopupMenu(mImageShow.getActivity(), mButton); - - popupMenu.getMenuInflater().inflate(R.menu.filtershow_menu_vignette, - popupMenu.getMenu()); - - popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - selectMenuItem(item); - return true; - } - }); - mButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View arg0) { - popupMenu.show(); - ((FilterShowActivity)mContext).onShowMenu(popupMenu); - } - }); - mButton.setListener(this); - - FilterVignetteRepresentation csrep = getVignetteRep(); - String menuString = mContext.getString(mMenuStrings[0]); - switchToMode(csrep, FilterVignetteRepresentation.MODE_VIGNETTE, menuString); - } else { - mButton.setText(mContext.getString(R.string.vignette_main)); - } - } - - @Override - public void setUtilityPanelUI(View actionButton, View editControl) { - if (useCompact(mContext)) { - super.setUtilityPanelUI(actionButton, editControl); - return; - } - mActionButton = actionButton; - mEditControl = editControl; - mEditTitle.setCompoundDrawables(null, null, null, null); - LinearLayout group = (LinearLayout) editControl; - LayoutInflater inflater = - (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - LinearLayout controls = (LinearLayout) inflater.inflate( - R.layout.filtershow_vignette_controls, group, false); - ViewGroup.LayoutParams lp = new LinearLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - controls.setLayoutParams(lp); - group.removeAllViews(); - group.addView(controls); - - mVignetteBar = (SeekBar) controls.findViewById(R.id.mainVignetteSeekbar); - mVignetteBar.setMax(200); - mVignetteBar.setOnSeekBarChangeListener(this); - mVignetteValue = (TextView) controls.findViewById(R.id.mainVignetteValue); - mExposureBar = (SeekBar) controls.findViewById(R.id.exposureSeekBar); - mExposureBar.setMax(200); - mExposureBar.setOnSeekBarChangeListener(this); - mExposureValue = (TextView) controls.findViewById(R.id.exposureValue); - mSaturationBar = (SeekBar) controls.findViewById(R.id.saturationSeekBar); - mSaturationBar.setMax(200); - mSaturationBar.setOnSeekBarChangeListener(this); - mSaturationValue = (TextView) controls.findViewById(R.id.saturationValue); - mContrastBar = (SeekBar) controls.findViewById(R.id.contrastSeekBar); - mContrastBar.setMax(200); - mContrastBar.setOnSeekBarChangeListener(this); - mContrastValue = (TextView) controls.findViewById(R.id.contrastValue); - mFalloffBar = (SeekBar) controls.findViewById(R.id.falloffSeekBar); - mFalloffBar.setMax(200); - mFalloffBar.setOnSeekBarChangeListener(this); - mFalloffValue = (TextView) controls.findViewById(R.id.falloffValue); - } - - public int getParameterIndex(int id) { - switch (id) { - case R.id.editor_vignette_main: - return FilterVignetteRepresentation.MODE_VIGNETTE; - case R.id.editor_vignette_saturation: - return FilterVignetteRepresentation.MODE_SATURATION; - case R.id.editor_vignette_contrast: - return FilterVignetteRepresentation.MODE_CONTRAST; - case R.id.editor_vignette_exposure: - return FilterVignetteRepresentation.MODE_EXPOSURE; - case R.id.editor_vignette_falloff: - return FilterVignetteRepresentation.MODE_FALLOFF; - } - return -1; - } - - @Override - public void detach() { - if (mButton == null) { - return; - } - mButton.setListener(null); - mButton.setOnClickListener(null); - } - - private void updateSeekBar(FilterVignetteRepresentation rep) { - mControl.updateUI(); - } - - @Override - protected Parameter getParameterToEdit(FilterRepresentation rep) { - if (rep instanceof FilterVignetteRepresentation) { - FilterVignetteRepresentation csrep = (FilterVignetteRepresentation) rep; - Parameter param = csrep.getFilterParameter(csrep.getParameterMode()); - - return param; - } - return null; - } - - private FilterVignetteRepresentation getVignetteRep() { - FilterRepresentation rep = getLocalRepresentation(); - if (rep != null - && rep instanceof FilterVignetteRepresentation) { - FilterVignetteRepresentation csrep = (FilterVignetteRepresentation) rep; - return csrep; - } - return null; - } - - protected void selectMenuItem(MenuItem item) { - if (getLocalRepresentation() != null - && getLocalRepresentation() instanceof FilterVignetteRepresentation) { - FilterVignetteRepresentation csrep = - (FilterVignetteRepresentation) getLocalRepresentation(); - - switchToMode(csrep, getParameterIndex(item.getItemId()), item.getTitle().toString()); - } - } - - protected void switchToMode(FilterVignetteRepresentation csrep, int mode, String title) { - if (csrep == null) { - return; - } - csrep.setParameterMode(mode); - mCurrentlyEditing = title; - mButton.setText(mCurrentlyEditing); - { - Parameter param = getParameterToEdit(csrep); - - control(param, mEditControl); - } - updateSeekBar(csrep); - mView.invalidate(); - } - - @Override - public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) { - FilterVignetteRepresentation rep = getVignetteRep(); - int value = progress; - BasicParameterInt p; - switch (sbar.getId()) { - case R.id.mainVignetteSeekbar: - rep.setParameterMode(FilterVignetteRepresentation.MODE_VIGNETTE); - p = rep.getFilterParameter(rep.getParameterMode()); - value += p.getMinimum(); - mVignetteValue.setText("" + value); - break; - case R.id.exposureSeekBar: - rep.setParameterMode(FilterVignetteRepresentation.MODE_EXPOSURE); - p = rep.getFilterParameter(rep.getParameterMode()); - value += p.getMinimum(); - mExposureValue.setText("" + value); - break; - case R.id.saturationSeekBar: - rep.setParameterMode(FilterVignetteRepresentation.MODE_SATURATION); - p = rep.getFilterParameter(rep.getParameterMode()); - value += p.getMinimum(); - mSaturationValue.setText("" + value); - break; - case R.id.contrastSeekBar: - rep.setParameterMode(FilterVignetteRepresentation.MODE_CONTRAST); - p = rep.getFilterParameter(rep.getParameterMode()); - value += p.getMinimum(); - mContrastValue.setText("" + value); - break; - case R.id.falloffSeekBar: - rep.setParameterMode(FilterVignetteRepresentation.MODE_FALLOFF); - p = rep.getFilterParameter(rep.getParameterMode()); - value += p.getMinimum(); - mFalloffValue.setText("" + value); - break; - } - rep.setCurrentParameter(value); - commitLocalRepresentation(); - } - - @Override - public void swapLeft(MenuItem item) { - super.swapLeft(item); - mButton.setTranslationX(0); - mButton.animate().translationX(mButton.getWidth()).setDuration(SwapButton.ANIM_DURATION); - Runnable updateButton = new Runnable() { - @Override - public void run() { - mButton.animate().cancel(); - mButton.setTranslationX(0); - } - }; - mHandler.postDelayed(updateButton, SwapButton.ANIM_DURATION); - selectMenuItem(item); - } - - @Override - public void swapRight(MenuItem item) { - super.swapRight(item); - mButton.setTranslationX(0); - mButton.animate().translationX(-mButton.getWidth()).setDuration(SwapButton.ANIM_DURATION); - Runnable updateButton = new Runnable() { - @Override - public void run() { - mButton.animate().cancel(); - mButton.setTranslationX(0); - } - }; - mHandler.postDelayed(updateButton, SwapButton.ANIM_DURATION); - selectMenuItem(item); - } -} diff --git a/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java b/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java index 8350ff356..b79381d7f 100644 --- a/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java +++ b/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java @@ -107,31 +107,18 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface { } } - public void freeRSFilterScripts() { - for (Class c : mFilters.keySet()) { - ImageFilter filter = mFilters.get(c); - if (filter != null && filter instanceof ImageFilterRS) { - ((ImageFilterRS) filter).resetScripts(); - } - } - } - protected void addFilterClasses(Vector<Class> filters) { filters.add(ImageFilterTinyPlanet.class); filters.add(ImageFilterRedEye.class); filters.add(ImageFilterWBalance.class); filters.add(ImageFilterExposure.class); - filters.add(ImageFilterVignette.class); - filters.add(ImageFilterGrad.class); filters.add(ImageFilterContrast.class); filters.add(ImageFilterShadows.class); filters.add(ImageFilterHighlights.class); filters.add(ImageFilterVibrance.class); - filters.add(ImageFilterSharpen.class); filters.add(ImageFilterCurves.class); filters.add(ImageFilterDraw.class); filters.add(ImageFilterHue.class); - filters.add(ImageFilterChanSat.class); filters.add(ImageFilterSaturated.class); filters.add(ImageFilterBwFilter.class); filters.add(ImageFilterNegative.class); @@ -289,16 +276,12 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface { mEffects.add(getRepresentation(ImageFilterTinyPlanet.class)); mEffects.add(getRepresentation(ImageFilterWBalance.class)); mEffects.add(getRepresentation(ImageFilterExposure.class)); - mEffects.add(getRepresentation(ImageFilterVignette.class)); - mEffects.add(getRepresentation(ImageFilterGrad.class)); mEffects.add(getRepresentation(ImageFilterContrast.class)); mEffects.add(getRepresentation(ImageFilterShadows.class)); mEffects.add(getRepresentation(ImageFilterHighlights.class)); mEffects.add(getRepresentation(ImageFilterVibrance.class)); - mEffects.add(getRepresentation(ImageFilterSharpen.class)); mEffects.add(getRepresentation(ImageFilterCurves.class)); mEffects.add(getRepresentation(ImageFilterHue.class)); - mEffects.add(getRepresentation(ImageFilterChanSat.class)); mEffects.add(getRepresentation(ImageFilterBwFilter.class)); mEffects.add(getRepresentation(ImageFilterNegative.class)); mEffects.add(getRepresentation(ImageFilterEdge.class)); diff --git a/src/com/android/gallery3d/filtershow/filters/FilterChanSatRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterChanSatRepresentation.java deleted file mode 100644 index 6c5274da1..000000000 --- a/src/com/android/gallery3d/filtershow/filters/FilterChanSatRepresentation.java +++ /dev/null @@ -1,212 +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.android.gallery3d.filtershow.filters; - -import android.util.JsonReader; -import android.util.JsonWriter; - -import com.android.gallery3d.R; -import com.android.gallery3d.filtershow.controller.BasicParameterInt; -import com.android.gallery3d.filtershow.controller.Parameter; -import com.android.gallery3d.filtershow.controller.ParameterSet; -import com.android.gallery3d.filtershow.editors.EditorChanSat; -import com.android.gallery3d.filtershow.imageshow.ControlPoint; -import com.android.gallery3d.filtershow.imageshow.Spline; - -import java.io.IOException; -import java.util.Vector; - -/** - * Representation for a filter that has per channel & Master saturation - */ -public class FilterChanSatRepresentation extends FilterRepresentation implements ParameterSet { - private static final String LOGTAG = "FilterChanSatRepresentation"; - private static final String ARGS = "ARGS"; - private static final String SERIALIZATION_NAME = "channelsaturation"; - - public static final int MODE_MASTER = 0; - public static final int MODE_RED = 1; - public static final int MODE_YELLOW = 2; - public static final int MODE_GREEN = 3; - public static final int MODE_CYAN = 4; - public static final int MODE_BLUE = 5; - public static final int MODE_MAGENTA = 6; - private int mParameterMode = MODE_MASTER; - - private static int MINSAT = -100; - private static int MAXSAT = 100; - private BasicParameterInt mParamMaster = new BasicParameterInt(MODE_MASTER, 0, MINSAT, MAXSAT); - private BasicParameterInt mParamRed = new BasicParameterInt(MODE_RED, 0, MINSAT, MAXSAT); - private BasicParameterInt mParamYellow = new BasicParameterInt(MODE_YELLOW, 0, MINSAT, MAXSAT); - private BasicParameterInt mParamGreen = new BasicParameterInt(MODE_GREEN, 0, MINSAT, MAXSAT); - private BasicParameterInt mParamCyan = new BasicParameterInt(MODE_CYAN, 0, MINSAT, MAXSAT); - private BasicParameterInt mParamBlue = new BasicParameterInt(MODE_BLUE, 0, MINSAT, MAXSAT); - private BasicParameterInt mParamMagenta = new BasicParameterInt(MODE_MAGENTA, 0, MINSAT, MAXSAT); - - private BasicParameterInt[] mAllParam = { - mParamMaster, - mParamRed, - mParamYellow, - mParamGreen, - mParamCyan, - mParamBlue, - mParamMagenta}; - - public FilterChanSatRepresentation() { - super("ChannelSaturation"); - setTextId(R.string.saturation); - setFilterType(FilterRepresentation.TYPE_NORMAL); - setSerializationName(SERIALIZATION_NAME); - setFilterClass(ImageFilterChanSat.class); - setEditorId(EditorChanSat.ID); - setSupportsPartialRendering(true); - } - - public String toString() { - return getName() + " : " + mParamRed + ", " + mParamCyan + ", " + mParamRed - + ", " + mParamGreen + ", " + mParamMaster + ", " + mParamYellow; - } - - @Override - public FilterRepresentation copy() { - FilterChanSatRepresentation representation = new FilterChanSatRepresentation(); - copyAllParameters(representation); - return representation; - } - - @Override - protected void copyAllParameters(FilterRepresentation representation) { - super.copyAllParameters(representation); - representation.useParametersFrom(this); - } - - public void useParametersFrom(FilterRepresentation a) { - if (a instanceof FilterChanSatRepresentation) { - FilterChanSatRepresentation representation = (FilterChanSatRepresentation) a; - - for (int i = 0; i < mAllParam.length; i++) { - mAllParam[i].copyFrom(representation.mAllParam[i]); - } - } - } - - @Override - public boolean equals(FilterRepresentation representation) { - if (!super.equals(representation)) { - return false; - } - if (representation instanceof FilterChanSatRepresentation) { - FilterChanSatRepresentation rep = (FilterChanSatRepresentation) representation; - for (int i = 0; i < mAllParam.length; i++) { - if (rep.getValue(i) != getValue(i)) - return false; - } - return true; - } - return false; - } - - public int getValue(int mode) { - return mAllParam[mode].getValue(); - } - - public void setValue(int mode, int value) { - mAllParam[mode].setValue(value); - } - - public int getMinimum() { - return mParamMaster.getMinimum(); - } - - public int getMaximum() { - return mParamMaster.getMaximum(); - } - - public int getParameterMode() { - return mParameterMode; - } - - public void setParameterMode(int parameterMode) { - mParameterMode = parameterMode; - } - - public int getCurrentParameter() { - return getValue(mParameterMode); - } - - public void setCurrentParameter(int value) { - setValue(mParameterMode, value); - } - - @Override - public int getNumberOfParameters() { - return 6; - } - - @Override - public Parameter getFilterParameter(int index) { - return mAllParam[index]; - } - - @Override - public void serializeRepresentation(JsonWriter writer) throws IOException { - writer.beginObject(); - - writer.name(ARGS); - writer.beginArray(); - writer.value(getValue(MODE_MASTER)); - writer.value(getValue(MODE_RED)); - writer.value(getValue(MODE_YELLOW)); - writer.value(getValue(MODE_GREEN)); - writer.value(getValue(MODE_CYAN)); - writer.value(getValue(MODE_BLUE)); - writer.value(getValue(MODE_MAGENTA)); - writer.endArray(); - writer.endObject(); - } - - @Override - public void deSerializeRepresentation(JsonReader sreader) throws IOException { - sreader.beginObject(); - - while (sreader.hasNext()) { - String name = sreader.nextName(); - if (name.startsWith(ARGS)) { - sreader.beginArray(); - sreader.hasNext(); - setValue(MODE_MASTER, sreader.nextInt()); - sreader.hasNext(); - setValue(MODE_RED, sreader.nextInt()); - sreader.hasNext(); - setValue(MODE_YELLOW, sreader.nextInt()); - sreader.hasNext(); - setValue(MODE_GREEN, sreader.nextInt()); - sreader.hasNext(); - setValue(MODE_CYAN, sreader.nextInt()); - sreader.hasNext(); - setValue(MODE_BLUE, sreader.nextInt()); - sreader.hasNext(); - setValue(MODE_MAGENTA, sreader.nextInt()); - sreader.hasNext(); - sreader.endArray(); - } else { - sreader.skipValue(); - } - } - sreader.endObject(); - } -}
\ No newline at end of file diff --git a/src/com/android/gallery3d/filtershow/filters/FilterGradRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterGradRepresentation.java deleted file mode 100644 index 928c3eae9..000000000 --- a/src/com/android/gallery3d/filtershow/filters/FilterGradRepresentation.java +++ /dev/null @@ -1,497 +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.android.gallery3d.filtershow.filters; - -import android.graphics.Rect; -import android.util.JsonReader; -import android.util.JsonWriter; - -import com.android.gallery3d.R; -import com.android.gallery3d.filtershow.editors.EditorGrad; -import com.android.gallery3d.filtershow.imageshow.MasterImage; -import com.android.gallery3d.filtershow.imageshow.Line; - -import java.io.IOException; -import java.util.Vector; - -public class FilterGradRepresentation extends FilterRepresentation - implements Line { - private static final String LOGTAG = "FilterGradRepresentation"; - public static final int MAX_POINTS = 16; - public static final int PARAM_BRIGHTNESS = 0; - public static final int PARAM_SATURATION = 1; - public static final int PARAM_CONTRAST = 2; - private static final double ADD_MIN_DIST = .05; - private static String LINE_NAME = "Point"; - private static final String SERIALIZATION_NAME = "grad"; - - public FilterGradRepresentation() { - super("Grad"); - setSerializationName(SERIALIZATION_NAME); - creatExample(); - setOverlayId(R.drawable.filtershow_button_grad); - setFilterClass(ImageFilterGrad.class); - setTextId(R.string.grad); - setEditorId(EditorGrad.ID); - } - - public void trimVector(){ - int n = mBands.size(); - for (int i = n; i < MAX_POINTS; i++) { - mBands.add(new Band()); - } - for (int i = MAX_POINTS; i < n; i++) { - mBands.remove(i); - } - } - - Vector<Band> mBands = new Vector<Band>(); - Band mCurrentBand; - - static class Band { - private boolean mask = true; - - private int xPos1 = -1; - private int yPos1 = 100; - private int xPos2 = -1; - private int yPos2 = 100; - private int brightness = -40; - private int contrast = 0; - private int saturation = 0; - - - public Band() { - } - - public Band(int x, int y) { - xPos1 = x; - yPos1 = y+30; - xPos2 = x; - yPos2 = y-30; - } - - public Band(Band copy) { - mask = copy.mask; - xPos1 = copy.xPos1; - yPos1 = copy.yPos1; - xPos2 = copy.xPos2; - yPos2 = copy.yPos2; - brightness = copy.brightness; - contrast = copy.contrast; - saturation = copy.saturation; - } - - } - - @Override - public String toString() { - int count = 0; - for (Band point : mBands) { - if (!point.mask) { - count++; - } - } - return "c=" + mBands.indexOf(mCurrentBand) + "[" + mBands.size() + "]" + count; - } - - private void creatExample() { - Band p = new Band(); - p.mask = false; - p.xPos1 = -1; - p.yPos1 = 100; - p.xPos2 = -1; - p.yPos2 = 100; - p.brightness = -50; - p.contrast = 0; - p.saturation = 0; - mBands.add(0, p); - mCurrentBand = p; - trimVector(); - } - - @Override - public void useParametersFrom(FilterRepresentation a) { - FilterGradRepresentation rep = (FilterGradRepresentation) a; - Vector<Band> tmpBands = new Vector<Band>(); - int n = (rep.mCurrentBand == null) ? 0 : rep.mBands.indexOf(rep.mCurrentBand); - for (Band band : rep.mBands) { - tmpBands.add(new Band(band)); - } - mCurrentBand = null; - mBands = tmpBands; - mCurrentBand = mBands.elementAt(n); - } - - @Override - public FilterRepresentation copy() { - FilterGradRepresentation representation = new FilterGradRepresentation(); - copyAllParameters(representation); - return representation; - } - - @Override - protected void copyAllParameters(FilterRepresentation representation) { - super.copyAllParameters(representation); - representation.useParametersFrom(this); - } - - @Override - public boolean equals(FilterRepresentation representation) { - if (representation instanceof FilterGradRepresentation) { - FilterGradRepresentation rep = (FilterGradRepresentation) representation; - int n = getNumberOfBands(); - if (rep.getNumberOfBands() != n) { - return false; - } - for (int i = 0; i < mBands.size(); i++) { - Band b1 = mBands.get(i); - Band b2 = rep.mBands.get(i); - if (b1.mask != b2.mask - || b1.brightness != b2.brightness - || b1.contrast != b2.contrast - || b1.saturation != b2.saturation - || b1.xPos1 != b2.xPos1 - || b1.xPos2 != b2.xPos2 - || b1.yPos1 != b2.yPos1 - || b1.yPos2 != b2.yPos2) { - return false; - } - } - return true; - } - return false; - } - - public int getNumberOfBands() { - int count = 0; - for (Band point : mBands) { - if (!point.mask) { - count++; - } - } - return count; - } - - public int addBand(Rect rect) { - mBands.add(0, mCurrentBand = new Band(rect.centerX(), rect.centerY())); - mCurrentBand.mask = false; - int x = (mCurrentBand.xPos1 + mCurrentBand.xPos2)/2; - int y = (mCurrentBand.yPos1 + mCurrentBand.yPos2)/2; - double addDelta = ADD_MIN_DIST * Math.max(rect.width(), rect.height()); - boolean moved = true; - int count = 0; - int toMove = mBands.indexOf(mCurrentBand); - - while (moved) { - moved = false; - count++; - if (count > 14) { - break; - } - - for (Band point : mBands) { - if (point.mask) { - break; - } - } - - for (Band point : mBands) { - if (point.mask) { - break; - } - int index = mBands.indexOf(point); - - if (toMove != index) { - double dist = Math.hypot(point.xPos1 - x, point.yPos1 - y); - if (dist < addDelta) { - moved = true; - mCurrentBand.xPos1 += addDelta; - mCurrentBand.yPos1 += addDelta; - mCurrentBand.xPos2 += addDelta; - mCurrentBand.yPos2 += addDelta; - x = (mCurrentBand.xPos1 + mCurrentBand.xPos2)/2; - y = (mCurrentBand.yPos1 + mCurrentBand.yPos2)/2; - - if (mCurrentBand.yPos1 > rect.bottom) { - mCurrentBand.yPos1 = (int) (rect.top + addDelta); - } - if (mCurrentBand.xPos1 > rect.right) { - mCurrentBand.xPos1 = (int) (rect.left + addDelta); - } - } - } - } - } - trimVector(); - return 0; - } - - public void deleteCurrentBand() { - int index = mBands.indexOf(mCurrentBand); - mBands.remove(mCurrentBand); - trimVector(); - if (getNumberOfBands() == 0) { - addBand(MasterImage.getImage().getOriginalBounds()); - } - mCurrentBand = mBands.get(0); - } - - public void nextPoint(){ - int index = mBands.indexOf(mCurrentBand); - int tmp = index; - Band point; - int k = 0; - do { - index = (index+1)% mBands.size(); - point = mBands.get(index); - if (k++ >= mBands.size()) { - break; - } - } - while (point.mask == true); - mCurrentBand = mBands.get(index); - } - - public void setSelectedPoint(int pos) { - mCurrentBand = mBands.get(pos); - } - - public int getSelectedPoint() { - return mBands.indexOf(mCurrentBand); - } - - public boolean[] getMask() { - boolean[] ret = new boolean[mBands.size()]; - int i = 0; - for (Band point : mBands) { - ret[i++] = !point.mask; - } - return ret; - } - - public int[] getXPos1() { - int[] ret = new int[mBands.size()]; - int i = 0; - for (Band point : mBands) { - ret[i++] = point.xPos1; - } - return ret; - } - - public int[] getYPos1() { - int[] ret = new int[mBands.size()]; - int i = 0; - for (Band point : mBands) { - ret[i++] = point.yPos1; - } - return ret; - } - - public int[] getXPos2() { - int[] ret = new int[mBands.size()]; - int i = 0; - for (Band point : mBands) { - ret[i++] = point.xPos2; - } - return ret; - } - - public int[] getYPos2() { - int[] ret = new int[mBands.size()]; - int i = 0; - for (Band point : mBands) { - ret[i++] = point.yPos2; - } - return ret; - } - - public int[] getBrightness() { - int[] ret = new int[mBands.size()]; - int i = 0; - for (Band point : mBands) { - ret[i++] = point.brightness; - } - return ret; - } - - public int[] getContrast() { - int[] ret = new int[mBands.size()]; - int i = 0; - for (Band point : mBands) { - ret[i++] = point.contrast; - } - return ret; - } - - public int[] getSaturation() { - int[] ret = new int[mBands.size()]; - int i = 0; - for (Band point : mBands) { - ret[i++] = point.saturation; - } - return ret; - } - - public int getParameter(int type) { - switch (type){ - case PARAM_BRIGHTNESS: - return mCurrentBand.brightness; - case PARAM_SATURATION: - return mCurrentBand.saturation; - case PARAM_CONTRAST: - return mCurrentBand.contrast; - } - throw new IllegalArgumentException("no such type " + type); - } - - public int getParameterMax(int type) { - switch (type) { - case PARAM_BRIGHTNESS: - return 100; - case PARAM_SATURATION: - return 100; - case PARAM_CONTRAST: - return 100; - } - throw new IllegalArgumentException("no such type " + type); - } - - public int getParameterMin(int type) { - switch (type) { - case PARAM_BRIGHTNESS: - return -100; - case PARAM_SATURATION: - return -100; - case PARAM_CONTRAST: - return -100; - } - throw new IllegalArgumentException("no such type " + type); - } - - public void setParameter(int type, int value) { - mCurrentBand.mask = false; - switch (type) { - case PARAM_BRIGHTNESS: - mCurrentBand.brightness = value; - break; - case PARAM_SATURATION: - mCurrentBand.saturation = value; - break; - case PARAM_CONTRAST: - mCurrentBand.contrast = value; - break; - default: - throw new IllegalArgumentException("no such type " + type); - } - } - - @Override - public void setPoint1(float x, float y) { - mCurrentBand.xPos1 = (int)x; - mCurrentBand.yPos1 = (int)y; - } - - @Override - public void setPoint2(float x, float y) { - mCurrentBand.xPos2 = (int)x; - mCurrentBand.yPos2 = (int)y; - } - - @Override - public float getPoint1X() { - return mCurrentBand.xPos1; - } - - @Override - public float getPoint1Y() { - return mCurrentBand.yPos1; - } - @Override - public float getPoint2X() { - return mCurrentBand.xPos2; - } - - @Override - public float getPoint2Y() { - return mCurrentBand.yPos2; - } - - @Override - public void serializeRepresentation(JsonWriter writer) throws IOException { - writer.beginObject(); - int len = mBands.size(); - int count = 0; - - for (int i = 0; i < len; i++) { - Band point = mBands.get(i); - if (point.mask) { - continue; - } - writer.name(LINE_NAME + count); - count++; - writer.beginArray(); - writer.value(point.xPos1); - writer.value(point.yPos1); - writer.value(point.xPos2); - writer.value(point.yPos2); - writer.value(point.brightness); - writer.value(point.contrast); - writer.value(point.saturation); - writer.endArray(); - } - writer.endObject(); - } - - @Override - public void deSerializeRepresentation(JsonReader sreader) throws IOException { - sreader.beginObject(); - Vector<Band> points = new Vector<Band>(); - - while (sreader.hasNext()) { - String name = sreader.nextName(); - if (name.startsWith(LINE_NAME)) { - int pointNo = Integer.parseInt(name.substring(LINE_NAME.length())); - sreader.beginArray(); - Band p = new Band(); - p.mask = false; - sreader.hasNext(); - p.xPos1 = sreader.nextInt(); - sreader.hasNext(); - p.yPos1 = sreader.nextInt(); - sreader.hasNext(); - p.xPos2 = sreader.nextInt(); - sreader.hasNext(); - p.yPos2 = sreader.nextInt(); - sreader.hasNext(); - p.brightness = sreader.nextInt(); - sreader.hasNext(); - p.contrast = sreader.nextInt(); - sreader.hasNext(); - p.saturation = sreader.nextInt(); - sreader.hasNext(); - sreader.endArray(); - points.add(p); - - } else { - sreader.skipValue(); - } - } - mBands = points; - trimVector(); - mCurrentBand = mBands.get(0); - sreader.endObject(); - } -} diff --git a/src/com/android/gallery3d/filtershow/filters/FilterVignetteRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterVignetteRepresentation.java deleted file mode 100644 index 512594f5a..000000000 --- a/src/com/android/gallery3d/filtershow/filters/FilterVignetteRepresentation.java +++ /dev/null @@ -1,266 +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.android.gallery3d.filtershow.filters; - -import android.util.JsonReader; -import android.util.JsonWriter; - -import com.android.gallery3d.R; -import com.android.gallery3d.filtershow.controller.BasicParameterInt; -import com.android.gallery3d.filtershow.controller.Parameter; -import com.android.gallery3d.filtershow.editors.EditorVignette; -import com.android.gallery3d.filtershow.imageshow.Oval; - -import java.io.IOException; - -public class FilterVignetteRepresentation extends FilterRepresentation implements Oval { - private static final String LOGTAG = "FilterVignetteRepresentation"; - - private float mCenterX = .5f; - private float mCenterY = .5f; - private float mRadiusX = .5f; - private float mRadiusY = .5f; - public static final int MODE_VIGNETTE = 0; - public static final int MODE_EXPOSURE = 1; - public static final int MODE_SATURATION = 2; - public static final int MODE_CONTRAST = 3; - public static final int MODE_FALLOFF = 4; - private static int MIN = -100; - private static int MAX = 100; - private static int MAXFALLOF = 200; - - private BasicParameterInt mParamVignette = new BasicParameterInt(MODE_VIGNETTE, 50, MIN, MAX); - private BasicParameterInt mParamExposure = new BasicParameterInt(MODE_EXPOSURE, 0, MIN, MAX); - private BasicParameterInt mParamSaturation = new BasicParameterInt(MODE_SATURATION, 0, MIN, MAX); - private BasicParameterInt mParamContrast = new BasicParameterInt(MODE_CONTRAST, 0, MIN, MAX); - private BasicParameterInt mParamFalloff = new BasicParameterInt(MODE_FALLOFF, 40, 0, MAXFALLOF); - private BasicParameterInt[] mAllParam = { - mParamVignette, - mParamExposure, - mParamSaturation, - mParamContrast, - mParamFalloff}; - private int mParameterMode; - - public FilterVignetteRepresentation() { - super("Vignette"); - setSerializationName("VIGNETTE"); - setShowParameterValue(true); - setFilterType(FilterRepresentation.TYPE_VIGNETTE); - setTextId(R.string.vignette); - setEditorId(EditorVignette.ID); - setName("Vignette"); - setFilterClass(ImageFilterVignette.class); - } - - @Override - public void useParametersFrom(FilterRepresentation a) { - super.useParametersFrom(a); - FilterVignetteRepresentation rep = (FilterVignetteRepresentation) a; - mCenterX = rep.mCenterX; - mCenterY = rep.mCenterY; - mRadiusX = rep.mRadiusX; - mRadiusY = rep.mRadiusY; - mParamVignette.setValue(rep.mParamVignette.getValue()); - mParamExposure.setValue(rep.mParamExposure.getValue()); - mParamSaturation.setValue(rep.mParamSaturation.getValue()); - mParamContrast.setValue(rep.mParamContrast.getValue()); - mParamFalloff.setValue(rep.mParamFalloff.getValue()); - } - - public int getValue(int mode) { - return mAllParam[mode].getValue(); - } - - public void setValue(int mode, int value) { - mAllParam[mode].setValue(value); - } - - @Override - public String toString() { - return getName() + " : " + mCenterX + ", " + mCenterY + " radius: " + mRadiusX; - } - - @Override - public FilterRepresentation copy() { - FilterVignetteRepresentation representation = new FilterVignetteRepresentation(); - copyAllParameters(representation); - return representation; - } - - @Override - protected void copyAllParameters(FilterRepresentation representation) { - super.copyAllParameters(representation); - representation.useParametersFrom(this); - } - - @Override - public void setCenter(float centerX, float centerY) { - mCenterX = centerX; - mCenterY = centerY; - } - - @Override - public float getCenterX() { - return mCenterX; - } - - @Override - public float getCenterY() { - return mCenterY; - } - - @Override - public void setRadius(float radiusX, float radiusY) { - mRadiusX = radiusX; - mRadiusY = radiusY; - } - - @Override - public void setRadiusX(float radiusX) { - mRadiusX = radiusX; - } - - @Override - public void setRadiusY(float radiusY) { - mRadiusY = radiusY; - } - - @Override - public float getRadiusX() { - return mRadiusX; - } - - @Override - public float getRadiusY() { - return mRadiusY; - } - - public boolean isCenterSet() { - return !Float.isNaN(mCenterX); - } - - @Override - public boolean isNil() { - return false; - } - - @Override - public boolean equals(FilterRepresentation representation) { - if (!super.equals(representation)) { - return false; - } - if (representation instanceof FilterVignetteRepresentation) { - FilterVignetteRepresentation rep = (FilterVignetteRepresentation) representation; - for (int i = 0; i < mAllParam.length; i++) { - if (mAllParam[i].getValue() != rep.mAllParam[i].getValue()) - return false; - } - if (rep.getCenterX() == getCenterX() - && rep.getCenterY() == getCenterY() - && rep.getRadiusX() == getRadiusX() - && rep.getRadiusY() == getRadiusY()) { - return true; - } - } - return false; - } - - private static final String ELLIPSE = "ellipse"; - private static final String ARGS = "adjust"; - @Override - public void serializeRepresentation(JsonWriter writer) throws IOException { - writer.beginObject(); - writer.name(ELLIPSE); - writer.beginArray(); - writer.value(mCenterX); - writer.value(mCenterY); - writer.value(mRadiusX); - writer.value(mRadiusY); - writer.endArray(); - - writer.name(ARGS); - writer.beginArray(); - writer.value(mParamVignette.getValue()); - writer.value(mParamExposure.getValue()); - writer.value(mParamSaturation.getValue()); - writer.value(mParamContrast.getValue()); - writer.value(mParamFalloff.getValue()); - writer.endArray(); - writer.endObject(); - } - - - @Override - public void deSerializeRepresentation(JsonReader sreader) throws IOException { - sreader.beginObject(); - - while (sreader.hasNext()) { - String name = sreader.nextName(); - if (name.startsWith(ELLIPSE)) { - sreader.beginArray(); - sreader.hasNext(); - mCenterX = (float) sreader.nextDouble(); - sreader.hasNext(); - mCenterY = (float) sreader.nextDouble(); - sreader.hasNext(); - mRadiusX = (float) sreader.nextDouble(); - sreader.hasNext(); - mRadiusY = (float) sreader.nextDouble(); - sreader.hasNext(); - sreader.endArray(); - } else if (name.startsWith(ARGS)) { - sreader.beginArray(); - sreader.hasNext(); - mParamVignette.setValue(sreader.nextInt()); - sreader.hasNext(); - mParamExposure.setValue(sreader.nextInt()); - sreader.hasNext(); - mParamSaturation.setValue(sreader.nextInt()); - sreader.hasNext(); - mParamContrast.setValue(sreader.nextInt()); - sreader.hasNext(); - mParamFalloff.setValue(sreader.nextInt()); - sreader.hasNext(); - sreader.endArray(); - } else { - sreader.skipValue(); - } - } - sreader.endObject(); - } - public int getParameterMode() { - return mParameterMode; - } - - public void setParameterMode(int parameterMode) { - mParameterMode = parameterMode; - } - - public int getCurrentParameter() { - return getValue(mParameterMode); - } - - public void setCurrentParameter(int value) { - setValue(mParameterMode, value); - } - - public BasicParameterInt getFilterParameter(int index) { - return mAllParam[index]; - } - -} diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterChanSat.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterChanSat.java deleted file mode 100644 index 8482eac32..000000000 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterChanSat.java +++ /dev/null @@ -1,161 +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.android.gallery3d.filtershow.filters; - -import android.graphics.Bitmap; -import android.graphics.Matrix; -import android.renderscript.Allocation; -import android.renderscript.Element; -import android.renderscript.RenderScript; -import android.renderscript.Script.LaunchOptions; -import android.renderscript.Type; - -import com.android.gallery3d.R; -import com.android.gallery3d.filtershow.pipeline.FilterEnvironment; - -public class ImageFilterChanSat extends ImageFilterRS { - private static final String LOGTAG = "ImageFilterChanSat"; - private ScriptC_saturation mScript; - private Bitmap mSourceBitmap; - - private static final int STRIP_SIZE = 64; - - FilterChanSatRepresentation mParameters = new FilterChanSatRepresentation(); - private Bitmap mOverlayBitmap; - - public ImageFilterChanSat() { - mName = "ChannelSat"; - } - - @Override - public FilterRepresentation getDefaultRepresentation() { - return new FilterChanSatRepresentation(); - } - - @Override - public void useRepresentation(FilterRepresentation representation) { - mParameters = (FilterChanSatRepresentation) representation; - } - - @Override - protected void resetAllocations() { - - } - - @Override - public void resetScripts() { - if (mScript != null) { - mScript.destroy(); - mScript = null; - } - } - @Override - protected void createFilter(android.content.res.Resources res, float scaleFactor, - int quality) { - createFilter(res, scaleFactor, quality, getInPixelsAllocation()); - } - - @Override - protected void createFilter(android.content.res.Resources res, float scaleFactor, - int quality, Allocation in) { - RenderScript rsCtx = getRenderScriptContext(); - - Type.Builder tb_float = new Type.Builder(rsCtx, Element.F32_4(rsCtx)); - tb_float.setX(in.getType().getX()); - tb_float.setY(in.getType().getY()); - mScript = new ScriptC_saturation(rsCtx); - } - - - private Bitmap getSourceBitmap() { - assert (mSourceBitmap != null); - return mSourceBitmap; - } - - @Override - public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) { - if (SIMPLE_ICONS && FilterEnvironment.QUALITY_ICON == quality) { - return bitmap; - } - - mSourceBitmap = bitmap; - Bitmap ret = super.apply(bitmap, scaleFactor, quality); - mSourceBitmap = null; - - return ret; - } - - @Override - protected void bindScriptValues() { - int width = getInPixelsAllocation().getType().getX(); - int height = getInPixelsAllocation().getType().getY(); - } - - - - @Override - protected void runFilter() { - int []sat = new int[7]; - for(int i = 0;i<sat.length ;i ++){ - sat[i] = mParameters.getValue(i); - } - - - int width = getInPixelsAllocation().getType().getX(); - int height = getInPixelsAllocation().getType().getY(); - Matrix m = getOriginalToScreenMatrix(width, height); - - - mScript.set_saturation(sat); - - mScript.invoke_setupGradParams(); - runSelectiveAdjust( - getInPixelsAllocation(), getOutPixelsAllocation()); - - } - - private void runSelectiveAdjust(Allocation in, Allocation out) { - int width = in.getType().getX(); - int height = in.getType().getY(); - - LaunchOptions options = new LaunchOptions(); - int ty; - options.setX(0, width); - - for (ty = 0; ty < height; ty += STRIP_SIZE) { - int endy = ty + STRIP_SIZE; - if (endy > height) { - endy = height; - } - options.setY(ty, endy); - mScript.forEach_selectiveAdjust(in, out, options); - if (checkStop()) { - return; - } - } - } - - private boolean checkStop() { - RenderScript rsCtx = getRenderScriptContext(); - rsCtx.finish(); - if (getEnvironment().needsStop()) { - return true; - } - return false; - } -} - diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterGrad.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterGrad.java deleted file mode 100644 index 4d5a79c04..000000000 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterGrad.java +++ /dev/null @@ -1,190 +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.android.gallery3d.filtershow.filters; - -import android.graphics.Bitmap; -import android.graphics.Color; -import android.graphics.Matrix; - -import com.android.gallery3d.R; -import com.android.gallery3d.filtershow.pipeline.FilterEnvironment; - -import android.graphics.Bitmap; -import android.graphics.Color; -import android.graphics.Matrix; -import android.renderscript.Allocation; -import android.renderscript.Element; -import android.renderscript.RenderScript; -import android.renderscript.Script.LaunchOptions; -import android.renderscript.Type; -import android.util.Log; - -import com.android.gallery3d.R; -import com.android.gallery3d.filtershow.pipeline.FilterEnvironment; - -public class ImageFilterGrad extends ImageFilterRS { - private static final String LOGTAG = "ImageFilterGrad"; - private ScriptC_grad mScript; - private Bitmap mSourceBitmap; - private static final int RADIUS_SCALE_FACTOR = 160; - - private static final int STRIP_SIZE = 64; - - FilterGradRepresentation mParameters = new FilterGradRepresentation(); - private Bitmap mOverlayBitmap; - - public ImageFilterGrad() { - mName = "grad"; - } - - @Override - public FilterRepresentation getDefaultRepresentation() { - return new FilterGradRepresentation(); - } - - @Override - public void useRepresentation(FilterRepresentation representation) { - mParameters = (FilterGradRepresentation) representation; - } - - @Override - protected void resetAllocations() { - - } - - @Override - public void resetScripts() { - if (mScript != null) { - mScript.destroy(); - mScript = null; - } - } - @Override - protected void createFilter(android.content.res.Resources res, float scaleFactor, - int quality) { - createFilter(res, scaleFactor, quality, getInPixelsAllocation()); - } - - @Override - protected void createFilter(android.content.res.Resources res, float scaleFactor, - int quality, Allocation in) { - RenderScript rsCtx = getRenderScriptContext(); - - Type.Builder tb_float = new Type.Builder(rsCtx, Element.F32_4(rsCtx)); - tb_float.setX(in.getType().getX()); - tb_float.setY(in.getType().getY()); - mScript = new ScriptC_grad(rsCtx); - } - - - private Bitmap getSourceBitmap() { - assert (mSourceBitmap != null); - return mSourceBitmap; - } - - @Override - public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) { - if (SIMPLE_ICONS && FilterEnvironment.QUALITY_ICON == quality) { - return bitmap; - } - - mSourceBitmap = bitmap; - Bitmap ret = super.apply(bitmap, scaleFactor, quality); - mSourceBitmap = null; - - return ret; - } - - @Override - protected void bindScriptValues() { - int width = getInPixelsAllocation().getType().getX(); - int height = getInPixelsAllocation().getType().getY(); - mScript.set_inputWidth(width); - mScript.set_inputHeight(height); - } - - @Override - protected void runFilter() { - int[] x1 = mParameters.getXPos1(); - int[] y1 = mParameters.getYPos1(); - int[] x2 = mParameters.getXPos2(); - int[] y2 = mParameters.getYPos2(); - - int width = getInPixelsAllocation().getType().getX(); - int height = getInPixelsAllocation().getType().getY(); - Matrix m = getOriginalToScreenMatrix(width, height); - float[] coord = new float[2]; - for (int i = 0; i < x1.length; i++) { - coord[0] = x1[i]; - coord[1] = y1[i]; - m.mapPoints(coord); - x1[i] = (int) coord[0]; - y1[i] = (int) coord[1]; - coord[0] = x2[i]; - coord[1] = y2[i]; - m.mapPoints(coord); - x2[i] = (int) coord[0]; - y2[i] = (int) coord[1]; - } - - mScript.set_mask(mParameters.getMask()); - mScript.set_xPos1(x1); - mScript.set_yPos1(y1); - mScript.set_xPos2(x2); - mScript.set_yPos2(y2); - - mScript.set_brightness(mParameters.getBrightness()); - mScript.set_contrast(mParameters.getContrast()); - mScript.set_saturation(mParameters.getSaturation()); - - mScript.invoke_setupGradParams(); - runSelectiveAdjust( - getInPixelsAllocation(), getOutPixelsAllocation()); - - } - - private void runSelectiveAdjust(Allocation in, Allocation out) { - int width = in.getType().getX(); - int height = in.getType().getY(); - - LaunchOptions options = new LaunchOptions(); - int ty; - options.setX(0, width); - - for (ty = 0; ty < height; ty += STRIP_SIZE) { - int endy = ty + STRIP_SIZE; - if (endy > height) { - endy = height; - } - options.setY(ty, endy); - mScript.forEach_selectiveAdjust(in, out, options); - if (checkStop()) { - return; - } - } - } - - private boolean checkStop() { - RenderScript rsCtx = getRenderScriptContext(); - rsCtx.finish(); - if (getEnvironment().needsStop()) { - return true; - } - return false; - } -} - diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java deleted file mode 100644 index 3c54456b6..000000000 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java +++ /dev/null @@ -1,257 +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.android.gallery3d.filtershow.filters; - -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.renderscript.*; -import android.util.Log; -import android.content.res.Resources; -import com.android.gallery3d.R; -import com.android.gallery3d.filtershow.pipeline.PipelineInterface; - -public abstract class ImageFilterRS extends ImageFilter { - private static final String LOGTAG = "ImageFilterRS"; - private boolean DEBUG = false; - private int mLastInputWidth = 0; - private int mLastInputHeight = 0; - private long mLastTimeCalled; - - public static boolean PERF_LOGGING = false; - - private static ScriptC_grey mGreyConvert = null; - private static RenderScript mRScache = null; - - private volatile boolean mResourcesLoaded = false; - - protected abstract void createFilter(android.content.res.Resources res, - float scaleFactor, int quality); - - protected void createFilter(android.content.res.Resources res, - float scaleFactor, int quality, Allocation in) {} - protected void bindScriptValues(Allocation in) {} - - protected abstract void runFilter(); - - protected void update(Bitmap bitmap) { - getOutPixelsAllocation().copyTo(bitmap); - } - - protected RenderScript getRenderScriptContext() { - PipelineInterface pipeline = getEnvironment().getPipeline(); - return pipeline.getRSContext(); - } - - protected Allocation getInPixelsAllocation() { - PipelineInterface pipeline = getEnvironment().getPipeline(); - return pipeline.getInPixelsAllocation(); - } - - protected Allocation getOutPixelsAllocation() { - PipelineInterface pipeline = getEnvironment().getPipeline(); - return pipeline.getOutPixelsAllocation(); - } - - @Override - public void apply(Allocation in, Allocation out) { - long startOverAll = System.nanoTime(); - if (PERF_LOGGING) { - long delay = (startOverAll - mLastTimeCalled) / 1000; - String msg = String.format("%s; image size %dx%d; ", getName(), - in.getType().getX(), in.getType().getY()); - msg += String.format("called after %.2f ms (%.2f FPS); ", - delay / 1000.f, 1000000.f / delay); - Log.i(LOGTAG, msg); - } - mLastTimeCalled = startOverAll; - long startFilter = 0; - long endFilter = 0; - if (!mResourcesLoaded) { - PipelineInterface pipeline = getEnvironment().getPipeline(); - createFilter(pipeline.getResources(), getEnvironment().getScaleFactor(), - getEnvironment().getQuality(), in); - mResourcesLoaded = true; - } - startFilter = System.nanoTime(); - bindScriptValues(in); - run(in, out); - if (PERF_LOGGING) { - getRenderScriptContext().finish(); - endFilter = System.nanoTime(); - long endOverAll = System.nanoTime(); - String msg = String.format("%s; image size %dx%d; ", getName(), - in.getType().getX(), in.getType().getY()); - long timeOverAll = (endOverAll - startOverAll) / 1000; - long timeFilter = (endFilter - startFilter) / 1000; - msg += String.format("over all %.2f ms (%.2f FPS); ", - timeOverAll / 1000.f, 1000000.f / timeOverAll); - msg += String.format("run filter %.2f ms (%.2f FPS)", - timeFilter / 1000.f, 1000000.f / timeFilter); - Log.i(LOGTAG, msg); - } - } - - protected void run(Allocation in, Allocation out) {} - - @Override - public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) { - if (bitmap == null || bitmap.getWidth() == 0 || bitmap.getHeight() == 0) { - return bitmap; - } - try { - PipelineInterface pipeline = getEnvironment().getPipeline(); - if (DEBUG) { - Log.v(LOGTAG, "apply filter " + getName() + " in pipeline " + pipeline.getName()); - } - Resources rsc = pipeline.getResources(); - boolean sizeChanged = false; - if (getInPixelsAllocation() != null - && ((getInPixelsAllocation().getType().getX() != mLastInputWidth) - || (getInPixelsAllocation().getType().getY() != mLastInputHeight))) { - sizeChanged = true; - } - if (pipeline.prepareRenderscriptAllocations(bitmap) - || !isResourcesLoaded() || sizeChanged) { - freeResources(); - createFilter(rsc, scaleFactor, quality); - setResourcesLoaded(true); - mLastInputWidth = getInPixelsAllocation().getType().getX(); - mLastInputHeight = getInPixelsAllocation().getType().getY(); - } - bindScriptValues(); - runFilter(); - update(bitmap); - if (DEBUG) { - Log.v(LOGTAG, "DONE apply filter " + getName() + " in pipeline " + pipeline.getName()); - } - } catch (android.renderscript.RSIllegalArgumentException e) { - Log.e(LOGTAG, "Illegal argument? " + e); - } catch (android.renderscript.RSRuntimeException e) { - Log.e(LOGTAG, "RS runtime exception ? " + e); - } catch (java.lang.OutOfMemoryError e) { - // Many of the renderscript filters allocated large (>16Mb resources) in order to apply. - System.gc(); - displayLowMemoryToast(); - Log.e(LOGTAG, "not enough memory for filter " + getName(), e); - } - return bitmap; - } - - protected static Allocation convertBitmap(RenderScript RS, Bitmap bitmap) { - return Allocation.createFromBitmap(RS, bitmap, - Allocation.MipmapControl.MIPMAP_NONE, - Allocation.USAGE_SCRIPT | Allocation.USAGE_GRAPHICS_TEXTURE); - } - - private static Allocation convertRGBAtoA(RenderScript RS, Bitmap bitmap) { - if (RS != mRScache || mGreyConvert == null) { - mGreyConvert = new ScriptC_grey(RS); - mRScache = RS; - } - - Type.Builder tb_a8 = new Type.Builder(RS, Element.A_8(RS)); - - Allocation bitmapTemp = convertBitmap(RS, bitmap); - if (bitmapTemp.getType().getElement().isCompatible(Element.A_8(RS))) { - return bitmapTemp; - } - - tb_a8.setX(bitmapTemp.getType().getX()); - tb_a8.setY(bitmapTemp.getType().getY()); - Allocation bitmapAlloc = Allocation.createTyped(RS, tb_a8.create(), - Allocation.MipmapControl.MIPMAP_NONE, - Allocation.USAGE_SCRIPT | Allocation.USAGE_GRAPHICS_TEXTURE); - mGreyConvert.forEach_RGBAtoA(bitmapTemp, bitmapAlloc); - bitmapTemp.destroy(); - return bitmapAlloc; - } - - public Allocation loadScaledResourceAlpha(int resource, int inSampleSize) { - Resources res = getEnvironment().getPipeline().getResources(); - final BitmapFactory.Options options = new BitmapFactory.Options(); - options.inSampleSize = inSampleSize; - Bitmap bitmap = BitmapFactory.decodeResource( - res, - resource, options); - Allocation ret = convertRGBAtoA(getRenderScriptContext(), bitmap); - bitmap.recycle(); - return ret; - } - - public Allocation loadScaledResourceAlpha(int resource, int w, int h, int inSampleSize) { - Resources res = getEnvironment().getPipeline().getResources(); - final BitmapFactory.Options options = new BitmapFactory.Options(); - options.inSampleSize = inSampleSize; - Bitmap bitmap = BitmapFactory.decodeResource( - res, - resource, options); - Bitmap resizeBitmap = Bitmap.createScaledBitmap(bitmap, w, h, true); - Allocation ret = convertRGBAtoA(getRenderScriptContext(), resizeBitmap); - resizeBitmap.recycle(); - bitmap.recycle(); - return ret; - } - - public Allocation loadResourceAlpha(int resource) { - return loadScaledResourceAlpha(resource, 1); - } - - public Allocation loadResource(int resource) { - Resources res = getEnvironment().getPipeline().getResources(); - final BitmapFactory.Options options = new BitmapFactory.Options(); - options.inPreferredConfig = Bitmap.Config.ARGB_8888; - Bitmap bitmap = BitmapFactory.decodeResource( - res, - resource, options); - Allocation ret = convertBitmap(getRenderScriptContext(), bitmap); - bitmap.recycle(); - return ret; - } - - private boolean isResourcesLoaded() { - return mResourcesLoaded; - } - - private void setResourcesLoaded(boolean resourcesLoaded) { - mResourcesLoaded = resourcesLoaded; - } - - /** - * Bitmaps and RS Allocations should be cleared here - */ - abstract protected void resetAllocations(); - - /** - * RS Script objects (and all other RS objects) should be cleared here - */ - public abstract void resetScripts(); - - /** - * Scripts values should be bound here - */ - abstract protected void bindScriptValues(); - - public void freeResources() { - if (!isResourcesLoaded()) { - return; - } - resetAllocations(); - mLastInputWidth = 0; - mLastInputHeight = 0; - setResourcesLoaded(false); - } -} diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java deleted file mode 100644 index bfec89f6b..000000000 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java +++ /dev/null @@ -1,108 +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.android.gallery3d.filtershow.filters; - -import com.android.gallery3d.R; -import com.android.gallery3d.filtershow.editors.BasicEditor; - -public class ImageFilterSharpen extends ImageFilterRS { - private static final String SERIALIZATION_NAME = "SHARPEN"; - private static final String LOGTAG = "ImageFilterSharpen"; - private ScriptC_convolve3x3 mScript; - - private FilterBasicRepresentation mParameters; - - public ImageFilterSharpen() { - mName = "Sharpen"; - } - - public FilterRepresentation getDefaultRepresentation() { - FilterRepresentation representation = new FilterBasicRepresentation("Sharpen", 0, 0, 100); - representation.setSerializationName(SERIALIZATION_NAME); - representation.setShowParameterValue(true); - representation.setFilterClass(ImageFilterSharpen.class); - representation.setTextId(R.string.sharpness); - representation.setOverlayId(R.drawable.filtershow_button_colors_sharpen); - representation.setEditorId(BasicEditor.ID); - representation.setSupportsPartialRendering(true); - return representation; - } - - public void useRepresentation(FilterRepresentation representation) { - FilterBasicRepresentation parameters = (FilterBasicRepresentation) representation; - mParameters = parameters; - } - - @Override - protected void resetAllocations() { - // nothing to do - } - - @Override - public void resetScripts() { - if (mScript != null) { - mScript.destroy(); - mScript = null; - } - } - - @Override - protected void createFilter(android.content.res.Resources res, float scaleFactor, - int quality) { - if (mScript == null) { - mScript = new ScriptC_convolve3x3(getRenderScriptContext()); - } - } - - private void computeKernel() { - float scaleFactor = getEnvironment().getScaleFactor(); - float p1 = mParameters.getValue() * scaleFactor; - float value = p1 / 100.0f; - float f[] = new float[9]; - float p = value; - f[0] = -p; - f[1] = -p; - f[2] = -p; - f[3] = -p; - f[4] = 8 * p + 1; - f[5] = -p; - f[6] = -p; - f[7] = -p; - f[8] = -p; - mScript.set_gCoeffs(f); - } - - @Override - protected void bindScriptValues() { - int w = getInPixelsAllocation().getType().getX(); - int h = getInPixelsAllocation().getType().getY(); - mScript.set_gWidth(w); - mScript.set_gHeight(h); - } - - @Override - protected void runFilter() { - if (mParameters == null) { - return; - } - computeKernel(); - mScript.set_gIn(getInPixelsAllocation()); - mScript.bind_gPixels(getInPixelsAllocation()); - mScript.forEach_root(getInPixelsAllocation(), getOutPixelsAllocation()); - } - -} diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterVignette.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterVignette.java deleted file mode 100644 index 0d0dd3b08..000000000 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterVignette.java +++ /dev/null @@ -1,166 +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.android.gallery3d.filtershow.filters; - -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Matrix; -import android.graphics.Rect; -import com.android.gallery3d.R; -import com.android.gallery3d.filtershow.imageshow.MasterImage; -import com.android.gallery3d.filtershow.pipeline.FilterEnvironment; -import android.renderscript.Allocation; -import android.renderscript.Element; -import android.renderscript.RenderScript; -import android.renderscript.Script.LaunchOptions; -import android.renderscript.Type; -import android.util.Log; - -public class ImageFilterVignette extends ImageFilterRS { - private static final String LOGTAG = "ImageFilterVignette"; - private Bitmap mOverlayBitmap; - private ScriptC_vignette mScript; - FilterVignetteRepresentation mParameters; - public static final int MODE_VIGNETTE = FilterVignetteRepresentation.MODE_VIGNETTE; - public static final int MODE_EXPOSURE = FilterVignetteRepresentation.MODE_EXPOSURE; - public static final int MODE_SATURATION = FilterVignetteRepresentation.MODE_SATURATION; - public static final int MODE_CONTRAST = FilterVignetteRepresentation.MODE_CONTRAST; - public static final int MODE_FALLOFF = FilterVignetteRepresentation.MODE_FALLOFF; - - public ImageFilterVignette() { - mName = "Vignette"; - } - - @Override - public FilterRepresentation getDefaultRepresentation() { - FilterVignetteRepresentation representation = new FilterVignetteRepresentation(); - return representation; - } - - @Override - public void useRepresentation(FilterRepresentation representation) { - mParameters = (FilterVignetteRepresentation) representation; - } - - native protected void nativeApplyFilter( - Bitmap bitmap, int w, int h, int cx, int cy, float radx, float rady, - float strength, float finalValue); - - private float calcRadius(float cx, float cy, int w, int h) { - float d = cx; - if (d < (w - cx)) { - d = w - cx; - } - if (d < cy) { - d = cy; - } - if (d < (h - cy)) { - d = h - cy; - } - return d * d * 2.0f; - } - - @Override - protected void createFilter(Resources res, float scaleFactor, int quality) { - RenderScript rsCtx = getRenderScriptContext(); - - mScript = new ScriptC_vignette(rsCtx); - } - - @Override - protected void runFilter() { - - int w = getInPixelsAllocation().getType().getX(); - int h = getInPixelsAllocation().getType().getY(); - - float cx = w / 2; - float cy = h / 2; - float r = calcRadius(cx, cy, w, h); - float rx = r; - float ry = r; - - float[]c = new float[2]; - if (mParameters.isCenterSet()) { - Matrix m = getOriginalToScreenMatrix(w, h); - Rect bounds = MasterImage.getImage().getOriginalBounds(); - c[0] = bounds.right * mParameters.getCenterX(); - c[1] = bounds.bottom * mParameters.getCenterY(); - m.mapPoints(c); - cx = c[0]; - cy = c[1]; - c[0] = bounds.right * mParameters.getRadiusX(); - c[1] = bounds.bottom * mParameters.getRadiusY(); - m.mapVectors(c); - rx = c[0]; - ry = c[1]; - } - - mScript.set_inputWidth(w); - mScript.set_inputHeight(h); - int v = mParameters.getValue(MODE_VIGNETTE); - mScript.set_finalSubtract((v < 0) ? v : 0); - mScript.set_finalBright((v > 0) ? -v : 0); - mScript.set_finalSaturation(mParameters.getValue(MODE_SATURATION)); - mScript.set_finalContrast(mParameters.getValue(MODE_CONTRAST)); - mScript.set_centerx(cx); - mScript.set_centery(cy); - mScript.set_radiusx(rx); - mScript.set_radiusy(ry); - mScript.set_strength(mParameters.getValue(MODE_FALLOFF)/10.f); - mScript.invoke_setupVignetteParams(); - mScript.forEach_vignette(getInPixelsAllocation(), getOutPixelsAllocation()); - } - - @Override - public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) { - if (SIMPLE_ICONS && FilterEnvironment.QUALITY_ICON == quality) { - if (mOverlayBitmap == null) { - Resources res = getEnvironment().getPipeline().getResources(); - mOverlayBitmap = IconUtilities.getFXBitmap(res, - R.drawable.filtershow_icon_vignette); - } - - Canvas c = new Canvas(bitmap); - int dim = Math.max(bitmap.getWidth(), bitmap.getHeight()); - Rect r = new Rect(0, 0, dim, dim); - c.drawBitmap(mOverlayBitmap, null, r, null); - return bitmap; - } - Bitmap ret = super.apply(bitmap, scaleFactor, quality); - return bitmap; - } - - - @Override - protected void resetAllocations() { - - } - - @Override - public void resetScripts() { - - } - - @Override - protected void bindScriptValues() { - int width = getInPixelsAllocation().getType().getX(); - int height = getInPixelsAllocation().getType().getY(); - mScript.set_inputWidth(width); - mScript.set_inputHeight(height); - } -} diff --git a/src/com/android/gallery3d/filtershow/filters/convolve3x3.rs b/src/com/android/gallery3d/filtershow/filters/convolve3x3.rs deleted file mode 100644 index 2acffab06..000000000 --- a/src/com/android/gallery3d/filtershow/filters/convolve3x3.rs +++ /dev/null @@ -1,67 +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. - */ - -#pragma version(1) -#pragma rs java_package_name(com.android.gallery3d.filtershow.filters) -#pragma rs_fp_relaxed - -int32_t gWidth; -int32_t gHeight; -const uchar4 *gPixels; -rs_allocation gIn; - -float gCoeffs[9]; - -void root(const uchar4 *in, uchar4 *out, const void *usrData, uint32_t x, uint32_t y) { - uint32_t x1 = min((int32_t)x+1, gWidth-1); - uint32_t x2 = max((int32_t)x-1, 0); - uint32_t y1 = min((int32_t)y+1, gHeight-1); - uint32_t y2 = max((int32_t)y-1, 0); - - float4 p00 = rsUnpackColor8888(gPixels[x1 + gWidth * y1]); - float4 p01 = rsUnpackColor8888(gPixels[x + gWidth * y1]); - float4 p02 = rsUnpackColor8888(gPixels[x2 + gWidth * y1]); - float4 p10 = rsUnpackColor8888(gPixels[x1 + gWidth * y]); - float4 p11 = rsUnpackColor8888(gPixels[x + gWidth * y]); - float4 p12 = rsUnpackColor8888(gPixels[x2 + gWidth * y]); - float4 p20 = rsUnpackColor8888(gPixels[x1 + gWidth * y2]); - float4 p21 = rsUnpackColor8888(gPixels[x + gWidth * y2]); - float4 p22 = rsUnpackColor8888(gPixels[x2 + gWidth * y2]); - - p00 *= gCoeffs[0]; - p01 *= gCoeffs[1]; - p02 *= gCoeffs[2]; - p10 *= gCoeffs[3]; - p11 *= gCoeffs[4]; - p12 *= gCoeffs[5]; - p20 *= gCoeffs[6]; - p21 *= gCoeffs[7]; - p22 *= gCoeffs[8]; - - p00 += p01; - p02 += p10; - p11 += p12; - p20 += p21; - - p22 += p00; - p02 += p11; - - p20 += p22; - p20 += p02; - - p20 = clamp(p20, 0.f, 1.f); - *out = rsPackColorTo8888(p20.r, p20.g, p20.b); -} diff --git a/src/com/android/gallery3d/filtershow/filters/grad.rs b/src/com/android/gallery3d/filtershow/filters/grad.rs deleted file mode 100644 index ddbafd349..000000000 --- a/src/com/android/gallery3d/filtershow/filters/grad.rs +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2012 Unknown - * - * 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. - */ - -#pragma version(1) -#pragma rs java_package_name(com.android.gallery3d.filtershow.filters) - -#define MAX_POINTS 16 - -uint32_t inputWidth; -uint32_t inputHeight; -static const float Rf = 0.2999f; -static const float Gf = 0.587f; -static const float Bf = 0.114f; -//static const float size_scale = 0.01f; - -typedef struct { - rs_matrix3x3 colorMatrix; - float rgbOff; - float dx; - float dy; - float off; -} UPointData; -int mNumberOfLines; -// input data -bool mask[MAX_POINTS]; -int xPos1[MAX_POINTS]; -int yPos1[MAX_POINTS]; -int xPos2[MAX_POINTS]; -int yPos2[MAX_POINTS]; -int size[MAX_POINTS]; -int brightness[MAX_POINTS]; -int contrast[MAX_POINTS]; -int saturation[MAX_POINTS]; - -// generated data -static UPointData grads[MAX_POINTS]; - -void setupGradParams() { - int k = 0; - for (int i = 0; i < MAX_POINTS; i++) { - if (!mask[i]) { - continue; - } - float x1 = xPos1[i]; - float y1 = yPos1[i]; - float x2 = xPos2[i]; - float y2 = yPos2[i]; - - float denom = (y2 * y2 - 2 * y1 * y2 + x2 * x2 - 2 * x1 * x2 + y1 * y1 + x1 * x1); - if (denom == 0) { - continue; - } - grads[k].dy = (y1 - y2) / denom; - grads[k].dx = (x1 - x2) / denom; - grads[k].off = (y2 * y2 + x2 * x2 - x1 * x2 - y1 * y2) / denom; - - float S = 1+saturation[i]/100.f; - float MS = 1-S; - float Rt = Rf * MS; - float Gt = Gf * MS; - float Bt = Bf * MS; - - float b = 1+brightness[i]/100.f; - float c = 1+contrast[i]/100.f; - b *= c; - grads[k].rgbOff = .5f - c/2.f; - rsMatrixSet(&grads[i].colorMatrix, 0, 0, b * (Rt + S)); - rsMatrixSet(&grads[i].colorMatrix, 1, 0, b * Gt); - rsMatrixSet(&grads[i].colorMatrix, 2, 0, b * Bt); - rsMatrixSet(&grads[i].colorMatrix, 0, 1, b * Rt); - rsMatrixSet(&grads[i].colorMatrix, 1, 1, b * (Gt + S)); - rsMatrixSet(&grads[i].colorMatrix, 2, 1, b * Bt); - rsMatrixSet(&grads[i].colorMatrix, 0, 2, b * Rt); - rsMatrixSet(&grads[i].colorMatrix, 1, 2, b * Gt); - rsMatrixSet(&grads[i].colorMatrix, 2, 2, b * (Bt + S)); - - k++; - } - mNumberOfLines = k; -} - -void init() { - -} - -uchar4 __attribute__((kernel)) selectiveAdjust(const uchar4 in, uint32_t x, - uint32_t y) { - float4 pixel = rsUnpackColor8888(in); - - float4 wsum = pixel; - wsum.a = 0.f; - for (int i = 0; i < mNumberOfLines; i++) { - UPointData* grad = &grads[i]; - float t = clamp(x*grad->dx+y*grad->dy+grad->off,0.f,1.0f); - wsum.xyz = wsum.xyz*(1-t)+ - t*(rsMatrixMultiply(&grad->colorMatrix ,wsum.xyz)+grad->rgbOff); - - } - - pixel.rgb = wsum.rgb; - pixel.a = 1.0f; - - uchar4 out = rsPackColorTo8888(clamp(pixel, 0.f, 1.0f)); - return out; -} - - - diff --git a/src/com/android/gallery3d/filtershow/filters/grey.rs b/src/com/android/gallery3d/filtershow/filters/grey.rs deleted file mode 100644 index e01880360..000000000 --- a/src/com/android/gallery3d/filtershow/filters/grey.rs +++ /dev/null @@ -1,22 +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. - */ - -#pragma version(1) -#pragma rs java_package_name(com.android.gallery3d.filtershow.filters) - -uchar __attribute__((kernel)) RGBAtoA(uchar4 in) { - return in.r; -} diff --git a/src/com/android/gallery3d/filtershow/filters/saturation.rs b/src/com/android/gallery3d/filtershow/filters/saturation.rs deleted file mode 100644 index 5b216406d..000000000 --- a/src/com/android/gallery3d/filtershow/filters/saturation.rs +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (C) 2012 Unknown - * - * 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. - */ - -#pragma version(1) -#pragma rs java_package_name(com.android.gallery3d.filtershow.filters) - -#define MAX_CHANELS 7 -#define MAX_HUE 4096 -static const int ABITS = 4; -static const int HSCALE = 256; -static const int k1=255 << ABITS; -static const int k2=HSCALE << ABITS; - -static const float Rf = 0.2999f; -static const float Gf = 0.587f; -static const float Bf = 0.114f; - -rs_matrix3x3 colorMatrix_min; -rs_matrix3x3 colorMatrix_max; - -int mNumberOfLines; -// input data -int saturation[MAX_CHANELS]; -float sat[MAX_CHANELS]; - -float satLut[MAX_HUE]; -// generated data - - -void setupGradParams() { - - int master = saturation[0]; - int max = master+saturation[1]; - int min = max; - - // calculate the minimum and maximum saturation - for (int i = 1; i < MAX_CHANELS; i++) { - int v = master+saturation[i]; - if (max < v) { - max = v; - } - else if (min > v) { - min = v; - } - } - // generate a lookup table for all hue 0 to 4K which goes from 0 to 1 0=min sat 1 = max sat - min = min - 1; - for(int i = 0; i < MAX_HUE ; i++) { - float p = i * 6 / (float)MAX_HUE; - int ip = ((int)(p + .5f)) % 6; - int v = master + saturation[ip + 1]; - satLut[i] = (v - min)/(float)(max - min); - } - - float S = 1 + max / 100.f; - float MS = 1 - S; - float Rt = Rf * MS; - float Gt = Gf * MS; - float Bt = Bf * MS; - float b = 1.f; - - // Generate 2 color matrix one at min sat and one at max - rsMatrixSet(&colorMatrix_max, 0, 0, b * (Rt + S)); - rsMatrixSet(&colorMatrix_max, 1, 0, b * Gt); - rsMatrixSet(&colorMatrix_max, 2, 0, b * Bt); - rsMatrixSet(&colorMatrix_max, 0, 1, b * Rt); - rsMatrixSet(&colorMatrix_max, 1, 1, b * (Gt + S)); - rsMatrixSet(&colorMatrix_max, 2, 1, b * Bt); - rsMatrixSet(&colorMatrix_max, 0, 2, b * Rt); - rsMatrixSet(&colorMatrix_max, 1, 2, b * Gt); - rsMatrixSet(&colorMatrix_max, 2, 2, b * (Bt + S)); - - S = 1 + min / 100.f; - MS = 1-S; - Rt = Rf * MS; - Gt = Gf * MS; - Bt = Bf * MS; - b = 1; - - rsMatrixSet(&colorMatrix_min, 0, 0, b * (Rt + S)); - rsMatrixSet(&colorMatrix_min, 1, 0, b * Gt); - rsMatrixSet(&colorMatrix_min, 2, 0, b * Bt); - rsMatrixSet(&colorMatrix_min, 0, 1, b * Rt); - rsMatrixSet(&colorMatrix_min, 1, 1, b * (Gt + S)); - rsMatrixSet(&colorMatrix_min, 2, 1, b * Bt); - rsMatrixSet(&colorMatrix_min, 0, 2, b * Rt); - rsMatrixSet(&colorMatrix_min, 1, 2, b * Gt); - rsMatrixSet(&colorMatrix_min, 2, 2, b * (Bt + S)); -} - -static ushort rgb2hue( uchar4 rgb) -{ - int iMin,iMax,chroma; - - int ri = rgb.r; - int gi = rgb.g; - int bi = rgb.b; - short rv,rs,rh; - - if (ri > gi) { - iMax = max (ri, bi); - iMin = min (gi, bi); - } else { - iMax = max (gi, bi); - iMin = min (ri, bi); - } - - rv = (short) (iMax << ABITS); - - if (rv == 0) { - return 0; - } - - chroma = iMax - iMin; - rs = (short) ((k1 * chroma) / iMax); - if (rs == 0) { - return 0; - } - - if ( ri == iMax ) { - rh = (short) ((k2 * (6 * chroma + gi - bi))/(6 * chroma)); - if (rh >= k2) { - rh -= k2; - } - return rh; - } - - if (gi == iMax) { - return(short) ((k2 * (2 * chroma + bi - ri)) / (6 * chroma)); - } - - return (short) ((k2 * (4 * chroma + ri - gi)) / (6 * chroma)); -} - -uchar4 __attribute__((kernel)) selectiveAdjust(const uchar4 in, uint32_t x, - uint32_t y) { - float4 pixel = rsUnpackColor8888(in); - - int hue = rgb2hue(in); - - float t = satLut[hue]; - pixel.xyz = rsMatrixMultiply(&colorMatrix_min ,pixel.xyz) * (1 - t) + - t * (rsMatrixMultiply(&colorMatrix_max ,pixel.xyz)); - - pixel.a = 1.0f; - return rsPackColorTo8888(clamp(pixel, 0.f, 1.0f)); -} diff --git a/src/com/android/gallery3d/filtershow/filters/vignette.rs b/src/com/android/gallery3d/filtershow/filters/vignette.rs deleted file mode 100644 index 7ab466348..000000000 --- a/src/com/android/gallery3d/filtershow/filters/vignette.rs +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2013 Unknown - * - * 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. - */ - -#pragma version(1) -#pragma rs java_package_name(com.android.gallery3d.filtershow.filters) - -uint32_t inputWidth; -uint32_t inputHeight; -float centerx; -float centery; -float radiusx; -float radiusy; -float strength; -float finalBright; -float finalSaturation; -float finalContrast; -float finalSubtract; -rs_matrix3x3 colorMatrix; -float scalex; -float scaley; -float offset; -static const float Rf = 0.2999f; -static const float Gf = 0.587f; -static const float Bf = 0.114f; - - -void setupVignetteParams() { - scalex = 1.f / radiusx; - scaley = 1.f / radiusy; - - float S = 1 + finalSaturation / 100.f; - float MS = 1 - S; - float Rt = Rf * MS; - float Gt = Gf * MS; - float Bt = Bf * MS; - - float b = 1 + finalBright / 100.f; - float c = 1 + finalContrast / 100.f; - b *= c; - offset = .5f - c / 2.f - finalSubtract / 100.f; - rsMatrixSet(&colorMatrix, 0, 0, b * (Rt + S)); - rsMatrixSet(&colorMatrix, 1, 0, b * Gt); - rsMatrixSet(&colorMatrix, 2, 0, b * Bt); - rsMatrixSet(&colorMatrix, 0, 1, b * Rt); - rsMatrixSet(&colorMatrix, 1, 1, b * (Gt + S)); - rsMatrixSet(&colorMatrix, 2, 1, b * Bt); - rsMatrixSet(&colorMatrix, 0, 2, b * Rt); - rsMatrixSet(&colorMatrix, 1, 2, b * Gt); - rsMatrixSet(&colorMatrix, 2, 2, b * (Bt + S)); -} - -uchar4 __attribute__((kernel)) vignette(const uchar4 in, uint32_t x, uint32_t y) { - float4 pixel = rsUnpackColor8888(in); - float radx = (x - centerx) * scalex; - float rady = (y - centery) * scaley; - float dist = strength * (sqrt(radx * radx + rady * rady) - 1.f); - float t = (1.f + dist / sqrt(1.f + dist* dist)) * .5f; - float4 wsum = pixel; - wsum.xyz = wsum.xyz * (1 - t) + t * (rsMatrixMultiply(&colorMatrix, wsum.xyz) + offset); - wsum.a = 1.0f; - uchar4 out = rsPackColorTo8888(clamp(wsum, 0.f, 1.0f)); - return out; -} diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageGrad.java b/src/com/android/gallery3d/filtershow/imageshow/ImageGrad.java deleted file mode 100644 index b55cc2bc4..000000000 --- a/src/com/android/gallery3d/filtershow/imageshow/ImageGrad.java +++ /dev/null @@ -1,215 +0,0 @@ -package com.android.gallery3d.filtershow.imageshow; -/* - * 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. - */ - -import android.content.Context; -import android.content.res.Resources; -import android.graphics.Canvas; -import android.graphics.Matrix; -import android.util.AttributeSet; -import android.view.MotionEvent; - -import com.android.gallery3d.R; -import com.android.gallery3d.filtershow.editors.EditorGrad; -import com.android.gallery3d.filtershow.filters.FilterGradRepresentation; - -public class ImageGrad extends ImageShow { - private static final String LOGTAG = "ImageGrad"; - private FilterGradRepresentation mGradRep; - private EditorGrad mEditorGrad; - private float mMinTouchDist; - private int mActiveHandle = -1; - private GradControl mEllipse; - - Matrix mToScr = new Matrix(); - float[] mPointsX = new float[FilterGradRepresentation.MAX_POINTS]; - float[] mPointsY = new float[FilterGradRepresentation.MAX_POINTS]; - - public ImageGrad(Context context) { - super(context); - Resources res = context.getResources(); - mMinTouchDist = res.getDimensionPixelSize(R.dimen.gradcontrol_min_touch_dist); - mEllipse = new GradControl(context); - mEllipse.setShowReshapeHandles(false); - } - - public ImageGrad(Context context, AttributeSet attrs) { - super(context, attrs); - Resources res = context.getResources(); - mMinTouchDist = res.getDimensionPixelSize(R.dimen.gradcontrol_min_touch_dist); - mEllipse = new GradControl(context); - mEllipse.setShowReshapeHandles(false); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - int mask = event.getActionMasked(); - - if (mActiveHandle == -1) { - if (MotionEvent.ACTION_DOWN != mask) { - return super.onTouchEvent(event); - } - if (event.getPointerCount() == 1) { - mActiveHandle = mEllipse.getCloseHandle(event.getX(), event.getY()); - if (mActiveHandle == -1) { - float x = event.getX(); - float y = event.getY(); - float min_d = Float.MAX_VALUE; - int pos = -1; - for (int i = 0; i < mPointsX.length; i++) { - if (mPointsX[i] == -1) { - continue; - } - float d = (float) Math.hypot(x - mPointsX[i], y - mPointsY[i]); - if ( min_d > d) { - min_d = d; - pos = i; - } - } - if (min_d > mMinTouchDist){ - pos = -1; - } - - if (pos != -1) { - mGradRep.setSelectedPoint(pos); - resetImageCaches(this); - mEditorGrad.updateSeekBar(mGradRep); - mEditorGrad.commitLocalRepresentation(); - invalidate(); - } - } - } - if (mActiveHandle == -1) { - return super.onTouchEvent(event); - } - } else { - switch (mask) { - case MotionEvent.ACTION_UP: { - - mActiveHandle = -1; - break; - } - case MotionEvent.ACTION_DOWN: { - break; - } - } - } - float x = event.getX(); - float y = event.getY(); - - mEllipse.setScrImageInfo(getScreenToImageMatrix(true), - MasterImage.getImage().getOriginalBounds()); - - switch (mask) { - case (MotionEvent.ACTION_DOWN): { - mEllipse.actionDown(x, y, mGradRep); - break; - } - case (MotionEvent.ACTION_UP): - case (MotionEvent.ACTION_MOVE): { - mEllipse.actionMove(mActiveHandle, x, y, mGradRep); - setRepresentation(mGradRep); - break; - } - } - invalidate(); - mEditorGrad.commitLocalRepresentation(); - return true; - } - - public void setRepresentation(FilterGradRepresentation pointRep) { - mGradRep = pointRep; - Matrix toImg = getScreenToImageMatrix(false); - - toImg.invert(mToScr); - - float[] c1 = new float[] { mGradRep.getPoint1X(), mGradRep.getPoint1Y() }; - float[] c2 = new float[] { mGradRep.getPoint2X(), mGradRep.getPoint2Y() }; - - if (c1[0] == -1) { - float cx = MasterImage.getImage().getOriginalBounds().width() / 2; - float cy = MasterImage.getImage().getOriginalBounds().height() / 2; - float rx = Math.min(cx, cy) * .4f; - - mGradRep.setPoint1(cx, cy-rx); - mGradRep.setPoint2(cx, cy+rx); - c1[0] = cx; - c1[1] = cy-rx; - mToScr.mapPoints(c1); - if (getWidth() != 0) { - mEllipse.setPoint1(c1[0], c1[1]); - c2[0] = cx; - c2[1] = cy+rx; - mToScr.mapPoints(c2); - mEllipse.setPoint2(c2[0], c2[1]); - } - mEditorGrad.commitLocalRepresentation(); - } else { - mToScr.mapPoints(c1); - mToScr.mapPoints(c2); - mEllipse.setPoint1(c1[0], c1[1]); - mEllipse.setPoint2(c2[0], c2[1]); - } - } - - public void drawOtherPoints(Canvas canvas) { - computCenterLocations(); - for (int i = 0; i < mPointsX.length; i++) { - if (mPointsX[i] != -1) { - mEllipse.paintGrayPoint(canvas, mPointsX[i], mPointsY[i]); - } - } - } - - public void computCenterLocations() { - int x1[] = mGradRep.getXPos1(); - int y1[] = mGradRep.getYPos1(); - int x2[] = mGradRep.getXPos2(); - int y2[] = mGradRep.getYPos2(); - int selected = mGradRep.getSelectedPoint(); - boolean m[] = mGradRep.getMask(); - float[] c = new float[2]; - for (int i = 0; i < m.length; i++) { - if (selected == i || !m[i]) { - mPointsX[i] = -1; - continue; - } - - c[0] = (x1[i]+x2[i])/2; - c[1] = (y1[i]+y2[i])/2; - mToScr.mapPoints(c); - - mPointsX[i] = c[0]; - mPointsY[i] = c[1]; - } - } - - public void setEditor(EditorGrad editorGrad) { - mEditorGrad = editorGrad; - } - - @Override - public void onDraw(Canvas canvas) { - super.onDraw(canvas); - if (mGradRep == null) { - return; - } - setRepresentation(mGradRep); - mEllipse.draw(canvas); - drawOtherPoints(canvas); - } - -} diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageVignette.java b/src/com/android/gallery3d/filtershow/imageshow/ImageVignette.java deleted file mode 100644 index 957128749..000000000 --- a/src/com/android/gallery3d/filtershow/imageshow/ImageVignette.java +++ /dev/null @@ -1,240 +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.android.gallery3d.filtershow.imageshow; - -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Matrix; -import android.util.AttributeSet; -import android.view.MotionEvent; - -import com.android.gallery3d.filtershow.editors.EditorVignette; -import com.android.gallery3d.filtershow.filters.FilterVignetteRepresentation; - -public class ImageVignette extends ImageShow { - private static final String LOGTAG = "ImageVignette"; - - private FilterVignetteRepresentation mVignetteRep; - private EditorVignette mEditorVignette; - private OvalSpaceAdapter mScreenOval = new OvalSpaceAdapter(); - private int mActiveHandle = -1; - - EclipseControl mElipse; - - public ImageVignette(Context context) { - super(context); - mElipse = new EclipseControl(context); - } - - public ImageVignette(Context context, AttributeSet attrs) { - super(context, attrs); - mElipse = new EclipseControl(context); - } - - static class OvalSpaceAdapter implements Oval { - private Oval mOval; - Matrix mToScr; - Matrix mToImage; - int mImgWidth; - int mImgHeight; - float[] mTmp = new float[2]; - float mTmpRadiusX; - float mTmpRadiusY; - - public void setImageOval(Oval oval) { - mOval = oval; - } - - public void setTransform(Matrix toScr, Matrix toImage, int imgWidth, int imgHeight) { - mToScr = toScr; - mToImage = toImage; - mImgWidth = imgWidth; - mImgHeight = imgHeight; - mTmpRadiusX = getRadiusX(); - mTmpRadiusY = getRadiusY(); - } - - @Override - public void setCenter(float x, float y) { - mTmp[0] = x; - mTmp[1] = y; - mToImage.mapPoints(mTmp); - mOval.setCenter(mTmp[0] / mImgWidth, mTmp[1] / mImgHeight); - } - - @Override - public void setRadius(float w, float h) { - mTmp[0] = mTmpRadiusX = w; - mTmp[1] = mTmpRadiusY = h; - mToImage.mapVectors(mTmp); - mOval.setRadius(mTmp[0] / mImgWidth, mTmp[1] / mImgHeight); - } - - @Override - public float getCenterX() { - mTmp[0] = mOval.getCenterX() * mImgWidth; - mTmp[1] = mOval.getCenterY() * mImgHeight; - mToScr.mapPoints(mTmp); - - return mTmp[0]; - } - - @Override - public float getCenterY() { - mTmp[0] = mOval.getCenterX() * mImgWidth; - mTmp[1] = mOval.getCenterY() * mImgHeight; - mToScr.mapPoints(mTmp); - return mTmp[1]; - } - - @Override - public float getRadiusX() { - mTmp[0] = mOval.getRadiusX() * mImgWidth; - mTmp[1] = mOval.getRadiusY() * mImgHeight; - mToScr.mapVectors(mTmp); - return Math.abs(mTmp[0]); - } - - @Override - public float getRadiusY() { - mTmp[0] = mOval.getRadiusX() * mImgWidth; - mTmp[1] = mOval.getRadiusY() * mImgHeight; - mToScr.mapVectors(mTmp); - return Math.abs(mTmp[1]); - } - - @Override - public void setRadiusY(float y) { - mTmp[0] = mTmpRadiusX; - mTmp[1] = mTmpRadiusY = y; - mToImage.mapVectors(mTmp); - mOval.setRadiusX(mTmp[0] / mImgWidth); - mOval.setRadiusY(mTmp[1] / mImgHeight); - } - - @Override - public void setRadiusX(float x) { - mTmp[0] = mTmpRadiusX = x; - mTmp[1] = mTmpRadiusY; - mToImage.mapVectors(mTmp); - mOval.setRadiusX(mTmp[0] / mImgWidth); - mOval.setRadiusY(mTmp[1] / mImgHeight); - } - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - int w = MasterImage.getImage().getOriginalBounds().width(); - int h = MasterImage.getImage().getOriginalBounds().height(); - int mask = event.getActionMasked(); - if (mActiveHandle == -1) { - if (MotionEvent.ACTION_DOWN != mask) { - return super.onTouchEvent(event); - } - if (event.getPointerCount() == 1) { - mActiveHandle = mElipse.getCloseHandle(event.getX(), event.getY()); - } - if (mActiveHandle == -1) { - return super.onTouchEvent(event); - } - } else { - switch (mask) { - case MotionEvent.ACTION_UP: - mActiveHandle = -1; - break; - case MotionEvent.ACTION_DOWN: - break; - } - } - float x = event.getX(); - float y = event.getY(); - - mElipse.setScrImageInfo(new Matrix(), - MasterImage.getImage().getOriginalBounds()); - - boolean didComputeEllipses = false; - switch (mask) { - case (MotionEvent.ACTION_DOWN): - mElipse.actionDown(x, y, mScreenOval); - break; - case (MotionEvent.ACTION_UP): - case (MotionEvent.ACTION_MOVE): - - mElipse.actionMove(mActiveHandle, x, y, mScreenOval); - setRepresentation(mVignetteRep); - didComputeEllipses = true; - break; - } - if (!didComputeEllipses) { - computeEllipses(); - } - invalidate(); - return true; - } - - public void setRepresentation(FilterVignetteRepresentation vignetteRep) { - mVignetteRep = vignetteRep; - mScreenOval.setImageOval(mVignetteRep); - computeEllipses(); - } - - public void computeEllipses() { - if (mVignetteRep == null) { - return; - } - float w = MasterImage.getImage().getOriginalBounds().width(); - float h = MasterImage.getImage().getOriginalBounds().height(); - Matrix toImg = getScreenToImageMatrix(false); - Matrix toScr = new Matrix(); - toImg.invert(toScr); - mScreenOval.setTransform(toScr, toImg, (int) w, (int) h); - - mElipse.setCenter(mScreenOval.getCenterX(), mScreenOval.getCenterY()); - mElipse.setRadius(mScreenOval.getRadiusX(), mScreenOval.getRadiusY()); - - mEditorVignette.commitLocalRepresentation(); - } - - public void setEditor(EditorVignette editorVignette) { - mEditorVignette = editorVignette; - } - - @Override - public void onSizeChanged(int w, int h, int oldw, int oldh) { - super.onSizeChanged(w, h, oldw, oldh); - computeEllipses(); - } - - @Override - public void onDraw(Canvas canvas) { - super.onDraw(canvas); - if (mVignetteRep == null) { - return; - } - float w = MasterImage.getImage().getOriginalBounds().width(); - float h = MasterImage.getImage().getOriginalBounds().height(); - Matrix toImg = getScreenToImageMatrix(false); - Matrix toScr = new Matrix(); - toImg.invert(toScr); - mScreenOval.setTransform(toScr, toImg, (int) w, (int) h); - mElipse.setCenter(mScreenOval.getCenterX(), mScreenOval.getCenterY()); - mElipse.setRadius(mScreenOval.getRadiusX(), mScreenOval.getRadiusY()); - - mElipse.draw(canvas); - } - -} diff --git a/src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java b/src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java index e5736d43c..6c6c2d9a2 100644 --- a/src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java +++ b/src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java @@ -314,9 +314,6 @@ public class ProcessingService extends Service { private void tearDownPipeline() { ImageFilter.resetStatics(); - FiltersManager.getPreviewManager().freeRSFilterScripts(); - FiltersManager.getManager().freeRSFilterScripts(); - FiltersManager.getHighresManager().freeRSFilterScripts(); FiltersManager.reset(); CachingPipeline.destroyRenderScriptContext(); } diff --git a/src_pd/com/android/gallery3d/filtershow/editors/EditorManager.java b/src_pd/com/android/gallery3d/filtershow/editors/EditorManager.java index e82d5617c..5f917829e 100644 --- a/src_pd/com/android/gallery3d/filtershow/editors/EditorManager.java +++ b/src_pd/com/android/gallery3d/filtershow/editors/EditorManager.java @@ -24,13 +24,10 @@ import com.android.gallery3d.filtershow.editors.EditorZoom; public class EditorManager { public static void addEditors(EditorPlaceHolder editorPlaceHolder) { - editorPlaceHolder.addEditor(new EditorGrad()); - editorPlaceHolder.addEditor(new EditorChanSat()); editorPlaceHolder.addEditor(new EditorZoom()); editorPlaceHolder.addEditor(new EditorCurves()); editorPlaceHolder.addEditor(new EditorTinyPlanet()); editorPlaceHolder.addEditor(new EditorDraw()); - editorPlaceHolder.addEditor(new EditorVignette()); editorPlaceHolder.addEditor(new EditorColorBorder()); editorPlaceHolder.addEditor(new EditorMirror()); editorPlaceHolder.addEditor(new EditorRotate()); |