Blend two bitmaps in a new BitmapData, using a blend shader

Hello

I have:

Two images of the same size as bitmap BitmapData.

I want to:

A largest BitmapData, with the two images mixed in a slope like that...

1st row: [BitmapData 1]

2nd row: [BitmapData BitmapData 2 1 mixed up on the top of the page, alpha 0.1]

Row 3: [1 BitmapData with BitmapData 2 mixed up on 0.2, alpha]

Row 4: [1 BitmapData with BitmapData 2 mixed on 0.3, alpha]

....

Line n: [BitmapData [2]

------------------------------------

I can easily implement this using the standard alpha blending. However, I would use my own algorithm of mix, and do it with actionscript is too slow. Therefore, I would like to implement the merge as a Pixel Bender shader function. I came here to make a function that works with the standard alpha blending and no shader custom involved:

protected function createGradientLookupTable( bitmapAtBlend0:BitmapData, bitmapAtBlend1:BitmapData, steps:uint ):BitmapData {
    var gradient:BitmapData = new BitmapData( 256, bitmapAtBlend0.height * steps );
    var translationMatrix:Matrix = new Matrix();
    var alphaTransform:ColorTransform = new ColorTransform();

    for( var row:int = 0; row < steps; row++ ) {
        gradient.draw(bitmapAtBlend0, translationMatrix);
        alphaTransform.alphaMultiplier = row / ( steps - 1 );
        gradient.draw(bitmapAtBlend1, translationMatrix, alphaTransform );
        translationMatrix.translate( 0, bitmapAtBlend0.height );
    }

    return gradient;
}

This method works. At first, I did a fusion of shader to Pixel Bender, just to check if I can load into my Flash Builder project and operate standard alpha. This filter works in Pixel Bender 2.5:

<languageVersion : 1.0;>
kernel BlendHCL
<   namespace : "com.yadayada";
    vendor : "Yada Yada";
    version : 1;
    description : "Blends colors using hue chroma luma";
>
{
    input image4 src1;
    input image4 src2;
    output pixel4 dst;

    parameter float alpha;

    void
    evaluatePixel()
    {
        float4 pixelBottom = sampleNearest(src1,outCoord());
        float4 pixelTop = sampleNearest(src2,outCoord());

        dst = pixelBottom + ( pixelTop - pixelBottom ) * alpha;

    }
}

Don't mind the description etc., currently it's supposed to only must accept a parameter alpha and mix using the standard alpha blending. Just to see I can make it work. Here is my Actionscript code is modified to use the custom mixer, this code does NOT work:

protected function createGradientLookupTable( bitmapAtBlend0:BitmapData, bitmapAtBlend1:BitmapData, steps:uint ):BitmapData {
    var gradient:BitmapData = new BitmapData( 256, bitmapAtBlend0.height * steps );
    var translationMatrix:Matrix = new Matrix();
    var bitmap1:Bitmap = new Bitmap( bitmapAtBlend1 );
    var blendShader:Shader = new Shader( blendShaderCode );

    for( var row:int = 0; row < steps; row++ ) {
        gradient.draw(bitmapAtBlend0, translationMatrix);
        blendShader.data.alpha.value = [ row / ( steps - 1 ) ];
        bitmap1.blendShader = blendShader;
        try {
//            gradient.draw( bitmap1, translationMatrix ); // doesn't work
            gradient.draw( bitmap1, translationMatrix, null, BlendMode.SHADER ); // doesn't work either
        }
        catch( e:Error ) {
            trace( "Error happened! " + e.message ); // No error messages reported
        }
        translationMatrix.translate( 0, bitmapAtBlend0.height );
    }

    return gradient;
}

This code change does not report the errors, it is just as if the alpha is always 1.0. The second image completely replaces the first. This is the expected result if the shader blend is not implemented at all. All the example code that I find using a blend shader, mixes just the colors directly on the screen, not in a new Bitmap or BitmapData object. Can anyone help?

PS: Debugging in Flash Builder 4.7 and inspect the variables indicate that I have an object valid shader (blendShader).

It seems to me I couldn't do it as I wanted. Instead, I created a shader that could create the gradient while only once and actually an object instance ShaderJob in Flash to do the job. Here is the code of the shader which results from:



kernel BlendHCL
<   namespace : "com.yadayada";
    vendor : "Yada Yada";
    version : 1;
    description : "Blends colors using hue chroma luma";
>
{

    input image4 src1;
    input image4 src2;
    output pixel4 dst;

    parameter float imageHeight
    <
        minValue:     1.0;
        maxValue:    64.0;
        defaultValue: 2.0;
        description: "The height of the images that will be blended in the gradient result";
    >;

    parameter float steps
    <
        minValue:      2.0;
        maxValue:   1024.0;
        defaultValue: 64.0;
        description: "The number of shades in the gradient";
    >;

    void
    evaluatePixel()
    {

        float2 sampleCoord = outCoord();

        sampleCoord.y = mod( sampleCoord.y, imageHeight );

        float4 pixelBottom = sampleNearest(src1,sampleCoord);
        float4 pixelTop = sampleNearest(src2,sampleCoord);

        float alpha = floor( outCoord().y / imageHeight ) / ( steps - 1.0 );

        dst = pixelBottom + ( pixelTop - pixelBottom ) * alpha;

    }
}

The following Actionscript code:

          public function createGradientLookupTable(bitmapAtBlend0:BitmapData, bitmapAtBlend1:BitmapData, steps:uint):BitmapData {
               var shader:Shader = new Shader( blendShaderCode );

               shader.data.imageHeight.value = [ Number( bitmapAtBlend0.height ) ];
               shader.data.steps.value = [ Number( steps ) ];

               shader.data.src1.input = bitmapAtBlend0;
               shader.data.src2.input = bitmapAtBlend1;

               var result:BitmapData = new BitmapData( 256, bitmapAtBlend0.height * steps );

               var shaderJob:ShaderJob = new ShaderJob(shader, result);

               shaderJob.start( true );

               return result;

          }


It worked. The shader still conducting a standard alpha blending, but now I go to do the actual shader of coding.

Tags: Flex

Similar Questions

  • How to put windows 7 pro on the new computer using the same key on the side of the other computer

    I have a computer comes with windows 7 pro. I am now building a new computer. How to put windows 7 pro on the new computer using the same key on the side of the computer. I don't have a Windows 7 disc.

    Original title: Windows 7 pro

    Tuesday, October 14, 2014 20:31:20 + 0000, 4hammond wrote:

    I have a computer comes with windows 7 pro. I am now building a new computer. How to put windows 7 pro on the new computer using the same key on the side of the computer. I don't have a Windows 7 disc.

    You can not, for at least one (and two possible) reasons.

    1. it isn't clean if you want to have two computers, or you
    you want to remove from the old computer and put it on the new. If
    you want once, you can't do that - the rule is very clear: there
    a copy (or a license) for each computer.

    There is nothing new here. This is exactly the same rule that has been in
    effect on all versions of Windows from at least with Windows 3.1.

    2. but even if you want it on a single and from uninstall
    the old computer, you can't do it. It is because if it came with the
    computer, it is an OEM version and the biggest drawback to he a
    OEM version, is that its license it permanently binds to the first
    It is installed on the computer. He can never legally be moved to another
    computer, sold or assigned (except with the original computer).

  • When you create a new DPS use sizes offered by InDesign or the size of the unit?

    Hi all

    When you create a new DP, use sizes offered by InDesign or the size of the unit?  I fell on this question when I was looking for the sizes of the various devices and found that the iPhone 5 s, iPhone5c and iPhone4s sizes differ the defauly dimensions offered by InDesign.

    Also, should I worry about the DPI of resolution?  With the iPhone, they all seem to be 326ppi, but when it comes to other devices it's something I should consider?  Ideally, I could create DPS apps for all devices offered in digital publishing in InDesign (iPhone, iPad, Kindle Fire/Nook and Android).

    Thanks for any help you can provide.

    Also, if it helps I use InDesign CC.

    1024 x 768 using and creating PDF articles you will get OK with the two resolutions of the iPad, and Bob L. said, result 'quite decent one size fits all' for all other devices.

  • How to change the page that appears when I open the page new tab using the sign + on the tab bar?

    every time I open a new tab using + sign on the tabs bar, a Web site appears, which I was not aware. I want just the old rear setting. It must be my fault of friends. Help, please.

    You can do this on the topic: config page by resetting the pref browser.newtab.url via the context menu.

    See this article on the page tab (topic: newtab):

  • How to get a normal white page when open a new tab, using ' + '.

    When you open a new tab, using '+', I want Firefox to open the blank page. But it shows all my sites from the browsing history. 'White page' is with images-hyperlinks to these Web pages! How to get a normal white page without images-hyperlinks in navigation history without deleting all browsing history?

    Click on the button 'Hide new tab page' in the upper right corner of the page

  • Offers day and slow downloads WiFi (very slow).  Is there a way that I can download some updates and new programs using my macbook pro (to a public site in the city) and transfer it on my iMac which is too heavy to cart autour?

    Difficulty to access the updates and downloads with very slow wifi ("country").  Is it possible that I can download some updates and new programs using my MaBbook Pro (retina) on a public site in the city and transfer them on my iMac which is too heavy to cart autour?

    New programs, Yes.

    Updates, depends on what you're updating.

  • How can I change the settings of "undisclosed recipients" when send mail.  New to using a Mac.  Thank you

    How can I change the settings of "undisclosed recipients" on my Mac Mini... new to using Mac!  Thank you

    What you mean?

    If you enter a recipient in the BCC line other recipients will not see another. Recipients will see undisclosed recipients.

    Leave the line blank

  • Loading iTunes library of old, defunct macbook to new macbook using backups Time Machine

    Hello. How can I get iTunes library from my old Macbook loaded on my new Macbook using the backup Time Machine that exists from the old machine. The new mac is connected to the time machine, I can open Time machine, see the backups, but get nowhere when you attempt to load the library in iTunes on my new Macbook. I see the file .itl from the old machine to backups... where can I go from here?

    The iTunes library on the new machine is empty, so save is not a matter of concern.

    Thank you!

    Message from ludovic 06/2014: library iTunes backup restore Time Machine - https://discussions.apple.com/message/26104480#26104480 useful advice where to restore to a new drive: http://pondini.org/TM/B6.html -> https://web.archive.org/web/20150511032110/http://pondini.org/OSX/Home.html and https://discussions.apple.com/message/27599985#27599985 make sure you go back enough for the version you want.  If Time Machine backup just the version "later" may be one you don't want to.

  • Wanted: PXI-2530 for sale, new or used

    PXI-2530 is obsolete. I would like to buy new or used if someone is selling. Please note that I am looking for PXI-2530 and not PXI-2530 b

    http://www.artisantg.com/TestMeasurement/75929-2/National_Instruments_PXI_2530_High_Density_Multicon...

    These guys have them

  • Make a new file using the "Save as".

    Bit of feedback to the staff HERE...

    We use LabVIEW 8.6. and, at least in this implementation, trying to make a new VI using the command save as product a menu of choices, including none make sense to me. Sorry, but I can't say which of them will produce only makes a new file with a changed name to be refined. Trial and error product folders, but not files, replaces the original file (why would I do that, I chose save as no record) and about each result other than what I was trying to accomplish.

    May you fix this in a future release, but for 8.6, I feel that I must take a class just to save the new file.

    you're not alone...

    Have you tried "open extra copy?  This is probably what you want.  It will not copy the original and will keep the open source.

  • create the new file using report generation express vi

    Hello

    In my application, I need to write that certain data in spreadsheet Excel. For whom I created an excel template and I used the express vi report generation Toolkit to record appropriate data in the columns of the place. I need a new file created every day by the name of the day and write the data that he rest of the day. I have problems, create the new file using this express vi. I tried to use the low level vi but not able to make properly.

    Join my code and the excel template.

    Help, please.

    Thank you!

    I suspect that your problem is illegal characters (' / ') in your path, certainly it is the case in your original vi. You need to format your path, something like this (underscore instead of a slash stroke):

  • I get the same two updates Microsoft fixit fixit, KB2656351 & used KB2600217

    I get the same two updates Microsoft fixit fixit, KB2656351 & used KB2600217

    TIP: See paragraph .NET Framework specific to 4 first of all, the resolution method 2 (only!) on this page-online http://support.microsoft.com/kb/976982

    After the execution of the repair, given to zero & test.

  • Xperia Z2 be two what is the new application after the update of Lollipop.

    Hello.

    I update my Z2 Lollipop mobile yesterday. After that, I have two icons for what's new. Teh, I checked in the application window and the fouund as I have two app for Whats new with size 9.52 MB and MB 13,28. In 9.52 MB size app has option to uninstall updates and 13,28 MB a option disable only. So it seems like an update of the previous which is the new application. But I wonder why I have two icons in the Menu which is confused. Cannot install sony people to update the previous app withouting new or the previous unintastall and install a new one.

    Can someone tell me how I can get the lates version of which is the new app but remove the old version (not Unintall support because it Sony inbuild app.)

    Thank you.

    With respect,

    Samadhi

    Thank you for the information. Since it appeared after a software update, I suggest you reinstall the latest version of the software via PC Companion to see if it helps.

    In PC Companion, you press start on the support Zone > begin on updating the software of the phone/Tablet > repair phone/Tablet (the blue clickable link in the message) > proceed without going through your device connected to the computer.

    Follow the instructions that appear in the program and do not connect your device to this guide explains how to connect.

    Note that this software repair will erase your personal data. Don't forget to backup your data.

  • If I'm downloading new contacts using download list, select Eloqua Contact ID as a single match field?

    Hello


    If I'm downloading new contacts using download list, select Eloqua Contact ID as a single match field?


    Thank you

    Hello

    No, Eloqua Contact ID can be selected in the field of single match for new contacts.

    However, if you download information to update existing contacts, the ID of Eloqua Contact records can be selected.

    Thank you

    edynamic expert Eloqua

  • Dear Sir/dear Madam, two days ago I registered to use creation of cloud photography package 300 THB per month LR + PS. And I see the promotion for this package 240 THB per month. Could you please help to change promoting 240 THB? Thank you.

    Dear Sir/dear Madam, two days ago I registered to use creation of cloud photography package 300 THB per month LR + PS. And I see the promotion for this package 240 THB per month. Could you please help to change promoting 240 THB? Thank you.

    This is an open forum, not Adobe support... below to connect with Adobe personnel to help

    While the forums are open 24/7 you can't contact Adobe support at any time

    Chat support: Mon - Fri 05:00-19:00 (US Pacific Time)<=== note="" days="" and="">

    Don't forget to stay signed with your Adobe ID before accessing the link below

    Creative cloud support (all creative cloud customer service problems)

    http://helpx.Adobe.com/x-productkb/global/service-CCM.html

Maybe you are looking for

  • IE8 with SAP Business Warehouse

    After installing IE8 update I can't use SAP Business Warehouse queries, which return the error messages.  I uninstalled IE8 and the update of security for Microsoft Office Excel 2007 KB969682, which restored the BW feature on our professional XP lapt

  • Deleting a folder in Windows Vista Public

    Hello I have a new computer laptop, & found this public record on this matter, did not want so I deleted it... but when I restarted my PC, he was back... is there a way I could permanently delete this folder on my computer.

  • What is the chip attached to the lid back to?

    Recently, I broke down my back. I bought a replacement official Amazon search and followed by a YouTube video of disassembly to replace. Once I removed the original back cover I found a print/chip circuit board glued to it is inside the surface. It h

  • assignment of ringtone by program

    Hello Is it possible to set the ringtone progammatically for some contacts in the address book. If no incident based support control is useful in this case

  • BlackBerry Smartphones Internet works is not on my "BOLD"

    For the last 3 days I have not received emails and could not connect to the Internet, even when I'm home with my turned on wifi. I still get calls and text messages. Please help, thanks