Reputation: 540
Ultimately, what I'm trying to do is apply gamma correction to some bitmaps that I load at runtime. I was able to create a BitmapData
object, then create a Bitmap
from the BitmapData
, and I was able to add the Bitmap
to the stage with addChild
. So far so good. But if I try altering the BitmapData
in any way (either before or after creating the Bitmap
) I get warnings like these:
Warning: The method BitmapData::fillRect() is not implemented
Warning: The method BitmapData::paletteMap() is not implemented
Warning: The method BitmapData::clone() is not implemented
To simplify things as much as possible, let's just try to run the example code at https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#paletteMap()
I create a blank ActionScript 3 document, press F9 and I copy and paste this code into the timeline, on Layer_1: Frame 1:
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;
var myBitmapData:BitmapData = new BitmapData(80, 80, false, 0x00FF0000);
myBitmapData.fillRect(new Rectangle(20, 20, 40, 40), 0x0000FF00);
var redArray:Array = new Array(256);
var greenArray:Array = new Array(256);
for(var i:uint = 0; i < 255; i++) {
redArray[i] = 0x00000000;
greenArray[i] = 0x00000000;
}
redArray[0xFF] = 0x0000FF00;
greenArray[0xFF] = 0x00FF0000;
var bottomHalf:Rectangle = new Rectangle(0, 0, 100, 40);
var pt:Point = new Point(0, 0);
myBitmapData.paletteMap(myBitmapData, bottomHalf, pt, redArray, greenArray);
var bm1:Bitmap = new Bitmap(myBitmapData);
addChild(bm1);
That's all just copied directly from the example. And when I try running that, the log tells me that fillRect
and paletteMap
are not implemented. I've tried in Animate 19 and Flash Pro CS6 with the same results in both places.
Any idea what I'm doing wrong? Why are BitmapData
's methods not implemented and how do I implement them?
Upvotes: 1
Views: 123
Reputation: 540
The problem is with the Scaleform Launcher, which I was using to test the movie. Instead of testing with the Scaleform Launcher, go to Control > Test. Everything seems to be working fine there.
Unfortunately, if you depend on the Scaleform integration for interacting with Flash from inside a game engine, you won't be able to modify bitmaps from inside Flash. Scaleform seems to have left out all the code behind bitmapData
's methods.
And I think it's not likely that anyone will ever again need to run gamma correction on bitmaps in Flash, but just in case, here's how you do it:
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;
var bitmapData:BitmapData = new BeforeColorCorrection();
var rectangle:Rectangle = new Rectangle(0, 0, bitmapData.width, bitmapData.height);
var point:Point = new Point(0, 0);
var redGamma:Array = new Array(256);
var greenGamma:Array = new Array(256);
var blueGamma:Array = new Array(256);
var gamma:Number = 2.0;
var corrected:Number;
var i:int
for(i = 0; i <= 255; i++)
{
corrected = 255 * Math.pow((i / 255.0), (1.0 / gamma));
redGamma[i] = uint(corrected) << 16;
greenGamma[i] = uint(corrected) << 8;
blueGamma[i] = uint(corrected);
}
bitmapData.paletteMap(bitmapData, rectangle, point, redGamma, greenGamma, blueGamma);
var bitmap:Bitmap = new Bitmap(bitmapData);
addChild(bitmap);
BeforeColorCorrection
is an image in my library with "Export for ActionScript" checked. If Scaleform worked, I would replace that image during gameplay and run a function to brighten it via gamma correction.
Upvotes: 1