Thread: efficiency problem..

  1. #1
    Registered User
    Join Date
    Jul 2002

    efficiency problem..

    i am writing a bit of code that uses the following equation:

    basically this derives a merged value based on alpha transparency value when merging 2 images.
    Now, i am kinda reversing it to obtain the alpha info. The following variables in this situation are known values:
    tot, top, btm
    i (alpha info) isnt known.

    I cant rearrange this equation however, it seems to cancel out..
    My current solution is extremely inefficient, it involves looping through for all values of i (255 of em) with the known variables until the lhs==rhs. Then i know the alpha. This has to be done for each pixel and its too slow to be practical.

    Does anybody know either 1)how to rearrange the above to get i, or if this is impossible 2)some more efficient method of getting i from the above without looping through all values until i is found..

    thx in advance

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    I think this is what you want...

    tot = i*top + (1 - i)*btm
    tot = i*top + btm - i*btm
    tot - btm = i*top - i*btm
    tot - btm = i*(top - btm)
    (tot - btm) / (top - btm) = i

  3. #3
    Registered User
    Join Date
    Jul 2002
    ah yes, thats it, feel kinda stupid for not being able to figure that out for myself

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM