Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8eb955b9 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change I5e482bbc into eclair

* changes:
  Add new RenderScript sample: ImageProcessing.
parents c08efb27 d7fa122d
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
#
# Copyright (C) 2009 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)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := $(call all-java-files-under, src)
#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript

LOCAL_PACKAGE_NAME := ImageProcessing

include $(BUILD_PACKAGE)
+16 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.rs.image">

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application android:label="Image Processing">
        <activity android:name="ImageProcessingActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
+74.6 KiB
Loading image diff...
+38 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 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.
-->

<merge xmlns:android="http://schemas.android.com/apk/res/android">

    <SurfaceView
        android:id="@+id/surface"
        android:layout_width="1dip"
        android:layout_height="1dip" />

    <ImageView
        android:id="@+id/display"
        android:layout_width="320dip"
        android:layout_height="266dip" />
    
    <SeekBar
        android:id="@+id/threshold"
        android:layout_marginBottom="10dip"
        android:layout_marginLeft="10dip"
        android:layout_marginRight="10dip"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom" />

</merge>
 No newline at end of file
+44 −0
Original line number Diff line number Diff line
struct color_s {
    char b;
    char g;
    char r;
    char a;
};

void filter(struct color_s *in, struct color_s *out, struct vec3_s *luminanceVector) {
    struct vec3_s pixel;
    pixel.x = (in->r & 0xFF) / 255.0f;
    pixel.y = (in->g & 0xFF) / 255.0f;
    pixel.z = (in->b & 0xFF) / 255.0f;

    float luminance = vec3Dot(luminanceVector, &pixel);
    luminance = maxf(0.0f, luminance - Params->threshold);
    vec3Scale(&pixel, signf(luminance));

    out->a = in->a;
    out->r = pixel.x * 255.0f;
    out->g = pixel.y * 255.0f;
    out->b = pixel.z * 255.0f;
}

void main() {
    struct color_s *in = (struct color_s *) InPixel;
    struct color_s *out = (struct color_s *) OutPixel;
    
    struct vec3_s luminanceVector;
    luminanceVector.x = 0.2125f;
    luminanceVector.y = 0.7154f;
    luminanceVector.z = 0.0721f;

    int count = Params->inWidth * Params->inHeight;
    int i;

    for (i = 0; i < count; i++) {
        filter(in, out, &luminanceVector);

        in++;
        out++;
    }

    sendToClient(&count, 1, 4, 0);
}
Loading