10. Renderscript

  • Description: What is Renderscript
  • Practical part: Create Renderscript apps

Lecture

Practical

Task 1 - Blurred image

The application will display an image passed through a Gaussian blur filter next to the original image. To obtain the blurred image, use the ScriptIntrinsicBlur script.

Fill in the TODOs in MainActivity.java:

  1. Create the RenderScript context
  2. Create input Allocation from input bitmap
  3. Create output Allocation from output bitmap
  4. Load the ScriptIntrinsicBlur script
    • Hint: use Element.U8_4(mRS) as the second argument for the create method
  5. Set the radius for the blur (float between 0 and 25)
  6. Set input allocation for the script
  7. Execute script
  8. Copy output allocation into the output bitmap

Documentation:

Task 2 - Greyscale image

The application will display an image in greyscale and the original image. To obtain the grayscale image write a script that converts each pixel into greyscale.

Fill in the TODOs in mono.rs:

  1. The RenderScript version
  2. The package name
  3. Unpack the color in a float4
    • Hint: rsUnpackColor8888
  4. Make the dot product of the color and the multiplier to obtain the pixel in greyscale
    • Hint: dot function
  5. Repack the result float to a color and return the color
    • Hint: rsPackColorTo8888

Fill in the TODOs in MainActivity.java:

  1. Create the RenderScript context
  2. Create input Allocation from input bitmap
  3. Create output Allocation from output bitmap
  4. Load the script
  5. Execute script
  6. Copy output allocation into the output bitmap

Documentation:

Task 3 - Changing image saturation

The application will display an image and you can change dynamically the saturation of the image using a SeekBar. To obtain the image with a new saturation write a script that changes the saturation of each pixel.

Fill in the TODOs in saturation.rs:

  1. The RenderScript version
  2. The package name
  3. Unpack the color in a float4
  4. Make the dot product of the color and the multiplier to obtain the pixel in greyscale
  5. Apply mix function
    • Hint: use parameters - pixel in greyscale, pixel in original color and saturation level
  6. Repack the result float to a color and return the color

Fill in the TODOs in MainActivity.java:

  1. Create the RenderScript context
  2. Create input Allocation from input bitmap
  3. Create output Allocations from output bitmaps
    • Hint: mOutAllocations[i], mBitmapsOut[i]
  4. Load the script
  5. Set saturation value (global variable in the script)
  6. Execute script
    • Hint: mOutAllocations[index]
  7. Copy output allocation into the output bitmap
    • Hint: mOutAllocations[index], mBitmapsOut[index]

Documentation:

Task 4 - Changing image blur, emboss and hue

The application will display an image and you dynamically apply different levels of blur, emboss and hue to the image using a SeekBar. Use intrinsic scripts that apply these filters.

Fill in the TODOs in MainActivity.java:

  1. Create the RenderScript context
  2. Create input Allocation from input bitmap
  3. Create output Allocations from output bitmaps
    • Hint: mOutAllocations[i], mBitmapsOut[i]
  4. Load ScriptIntrinsicBlur script
  5. Load ScriptIntrinsicConvolve5x5 script
  6. Load ScriptIntrinsicColorMatrix
  7. Set radius for blur
  8. Set input allocation for ScriptIntrinsicBlur script
  9. Execute ScriptIntrinsicBlur script
  10. Set coefficients for ScriptIntrinsicConvolve5x5 script
  11. Set input allocation for ScriptIntrinsicConvolve5x5 script
  12. Execute ScriptIntrinsicConvolve5x5 script
  13. Set color matrix for ScriptIntrinsicColorMatrix script
  14. Execute ScriptIntrinsicColorMatrix script
  15. Copy output allocation to output bitmap

Documentation:

ndk/courses/10.txt ยท Last modified: 2014/08/10 14:00 by petre.eftime
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0