Advertisement
Guest User

AmbiLED draft

a guest
Aug 21st, 2011
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.55 KB | None | 0 0
  1. ---------------------------------------------------------------------------------------------------------
  2. AmbiLED 2011, Mariusz Grzybacz - FREE Open Source software
  3. ---------------------------------------------------------------------------------------------------------
  4. to control any DIY AmbiLight system
  5. writted for Windows 7 x64/x86
  6. ---------------------------------------------------------------------------------------------------------
  7.  
  8. 1] Window handle finder (based on a spy++) for profile maker
  9. (TODO: Auto detection of surface capture method D3D9/10/11, OpenGL??, GDI)
  10.  
  11. 2] Capture methods: D3D9/10/11 Hook (+Vertex Mode selection, for some people with lo-GPU,
  12. Software mode improves speed and LockableBackBuffer defaultly enabled =dramaticly speed improve),
  13. OpenGL??, .NET, GDI BitBlt + Reserved, Mirror Driver, Video Card capture??,
  14. External TCP Port: 32890? maybe faster way??=(Simple:Left,Right,Top,Bottom;
  15. Extended specified RGB channels must match unit channels)
  16.  
  17. Web links:
  18. Blt+Reverse: http://stereopsis.com/blttest/
  19. Mirror Driver support? http://demoforge.com/dfmirage.htm
  20. Sharp SDK: http://www.demoforge.com/sdk/MirrSharp.zip
  21. Win7 .NET vs GDI: http://blog.bobcravens.com/2009/04/fastest-screen-capture-using-c-vista-vs-win7/
  22. Display>Video card: http://www.splitmedialabs.com/media-toolkits ]
  23. [ used this code for handle Finder: http://www.codeproject.com/KB/graphics/screen_capturing.aspx ]
  24.  
  25. 3] Main display surface profile builder
  26. (eg. movie/surface size is 1920x800, 2.40:1 and it needs to match the led stripes positions.
  27. So solution is default for all inputs, surface in a size coresponding to the display device
  28. resolution 1920x1080, 16:9, with captured image inside in exactly same size & position
  29. as as original one.
  30. Note: Useful for multiple chanels for a side - this will prevent to light a stripe located
  31. on a black part of screen)
  32.  
  33. 4] Auto-Run (Injection)Capturing(new Thread) from detected Process.Name in a system from Applications
  34. profiles list with custom settings for different applications
  35. -- Two profile states: Normal, Exclusive
  36. (when enabled capturing in Normal state, then only new detected Process.Name with Exclusive flag set
  37. in profile will immediately pause Auto-Run timmer, then abort current working profile, Starts new
  38. and resume Auto-Run Timer. And for same flag state priority, capture switch to new profile depends
  39. on global settings [Profile triggering: Always, No-use])
  40.  
  41. 5] User dynamic channels creation
  42. User creates channels dynamicly as a RECTs to scan X,Y,W,H in specified by a user order
  43. - MoMoLight v4 protocol - didn't confirmed this with Marc Nieuwenhuizen yet, who still helps
  44. on this. He mades an alternative with MoodLight support.
  45.  
  46. 6] Colour-calculation:
  47. -- TODO: Surface blur - didn't study how to do this and prefered to do this on DX Surface
  48. ** Get pixels through unsafe bitmap method to improve the speed and calculate average **
  49. -- TODO: Intelligent Pixel Colour Threshold (NO IDEA HOW? When Surface blur does NOT solve desribed
  50. bellow issue, which is ONLY LAST ONE to make PERFECT AMBILIGHT SYSTEM, then need to find a way
  51. in some math maybe to eliminate:
  52. +++) very low, but random colours blinking on darkness pictures - moving picture with shiny stars...
  53. ...on a dark sky - like a swimming colour dots
  54. +++) fade in/out to white top/bottom side because of scrolled text at end of the movie)
  55.  
  56. 7] Voodoo Modes: Simple, Game [Priority selection and Cycles count], True-Cinema +Expansion
  57.  
  58. 8] Managed Colour-processing effects list for True-Cinema +Expansion mode (Add/Del, Move Up/Down)
  59. a] Voodoo input settings
  60. -- Expand individually/together *(Multiple)
  61. increase the lights level that can be used to adjust the brightness to match the one
  62. on a display device (*3), best solution for daytime watching (*10).
  63. IDEA: Useful with very cheap addon which is Foto-resistor that could be as extension for
  64. Ambi-module, which can perform room light measures for automatic lightning level adjustment!)
  65. -- Colour Quantize
  66. -- Colour Threshold (TODO: Like a curve in Photoshop or Sony Sound Forge)
  67. -- Progressive GreyScale *(_level_Brightness)
  68. b] True-Cinema calculations
  69. -- Dynamic Colour Smoother *(_cycles_Smooth; _level_Aggression) [modes: Individual/Together]
  70. Normally movie has have something around, let's say 25fps and while using classic MoMoLight
  71. controller v1/v2 with 3 RGB channels at baud rate 9600, software is able to transfer ~133,33
  72. colour arrays. So why do not make colour changes more smooth and protect in same time from
  73. unwanted and bad looking flickering on small picture changes?
  74. Smooth colours calculates difference between two last colours on a channels and determinate
  75. dynamicly smooth cycle length. While doing smooth cycle, even longer then few retreive cycles
  76. it always reads current colour values and speeds up or down if necessary to attack aggressively,
  77. faster or slower if needed - depends on a colour difference. It's a like a "Colour Smooth Slider"
  78. to bring user "True-Cinema" AmbiLight. Anyway works fine! :)
  79. Cycles count number depends on Cycle Interval which depends on interface.speed+transmit.protocol
  80. with some reserve upto 20% for Aggressive Events attacks.
  81. ev1 if buffer for one data shot to the AmbiLED module is NOT empty then drop new data
  82. to allow current buffer data flyout =this protects buffer from overload and delays
  83. send notify to log window: "Increase cycle interval to prevent buffer overloads
  84. and data drops."
  85. useful for first configuration and slow connection interface.speed eg. 9600 bauds
  86. note: Aggression Level for each Expand multipler needs to be set manually
  87. because of unknown LED intensity, room lightness, ...
  88. my settings: (day-light)var.multiplier=10, _level_Aggression=128
  89. (night)var.multiplier=4, _level_Aggression=96
  90. c] Voodoo output settings
  91. - Dynamic Color Increasing (not needed when users needs correct Gamma settings) - like a Smoother
  92. gets reset to Increase=10 (no increasing) from trigger Aggressive and works only when
  93. Aggressive set Together (All RGB channels) (NOT RECOMENDANTED)
  94. - Gamma (important to calibrate LEDs to match light from display device)
  95. - Colour compensation for each R, G, B colour - green wall behind a TV? reduce it!
  96.  
  97. ------------------------------------------------------------------------------------------
  98. How True-Cinema works? Described in few steps on preferred mode Individual Smoother.
  99. Thread.1--] Init Capture method
  100.  
  101. Thread.1a1] DoRequest capture method, copy to unsafe Bitmap and extract average colours
  102. for all specified RGB channels into _data_tempReceivedRGB
  103.  
  104. Thread.1a2] Apply Voodoo Input filters on _data_tempReceivedRGB
  105.  
  106. Thread.1a3] Copy temp array to _data_ReceivedRGB array and sets _trg_Received=true
  107. // NOTE: cannot start new Thread.2 from this point because this abort can
  108. cause in damage settings, broken data in arrays and cycles drops
  109.  
  110. Thread.1a4] if capture method != D3Dx then Thread.Sleep (Interval - (Start-Stop))
  111.  
  112. Thread.1a5] Start new Thread.1
  113.  
  114.  
  115. Thread.2--] Init True-Cinema cycle, _chX_cycle_count++
  116. Thread.2a1] When triggered that new data arrives, then:
  117. *make Array copy of data from _data_CurrentRGB to _data_PreviousRGB
  118. *and from _data_ReceivedRGB into _data_CurrentRGB
  119. *also reset _trg_Received
  120. (Note: steps bellow are executed on each channel in one cycle)
  121.  
  122. Thread.2a2] check colour difference between
  123. __data_CurrentRGB[chX][c] and _data_PreviousRGB[chX][c].
  124.  
  125. Thread.2a3] When _chX_colour_diff is >_level_Aggression then sets _chX_state_Aggressive flag
  126. to enabled for chX, apply new colous, reset all states and QUIT
  127. // check for new cycles count
  128.  
  129. Thread.2a4] When _chX_colour_diff <= _level_Aggression then
  130. *calculate new smooth cycle count progressively. Example results:
  131. _chX_colour_diff=0 then _tmp_cycles_Smooth=_max_smooth (32)
  132. _chX_colour_diff=_level_Aggression/2 then _tmp_cycles_Smooth=_max_smooth/2 (16)
  133. _chX_colour_diff=_level_Aggression-1 then _tmp_cycles_Smooth=1 (no smooth)
  134.  
  135. Thread.2a5]*if _tmp_cycles_smooth < _chX_cycles_smooth then
  136. *execute _reset_cycle_state(X)
  137. - calculate colour from previous cycle and save in working buffers
  138. *execute getColorFromSmoothCycle(_chX_cycle_count, _chX_cycles_smooth,
  139. _data_CurrentRGB[chX][c], _data_PreviousRGB[chX][c]) : _data_OutputRGB
  140. - reset cycle count for this channel set _chX_cycle_count = 0
  141. otherwise do the same, but global flag _smooth.LikeOldPlatformGame must be DISABLED?
  142. *execute _reset_cycle_state(X)
  143.  
  144. NOTE: standard smooth cycle calculation
  145. Thread.2a6]*execute getColorFromSmoothCycle(_chX_cycle_count, _chX_cycles_smooth,
  146. _data_CurrentRGB[chX][c], _data_PreviousRGB[chX][c]) : _data_OutputRGB
  147.  
  148. Thread.2a7]*if _chX_cycle_count = _chX_cycles_smooth then _chX_cycle_count = -1
  149. Thread.2a8]*Apply Voodoo Output filters on _data_OutputRGB and execute Send on new Thread
  150. Thread.2a9]*Thread.Sleep (Interval - (Start-Stop)) +abort triggered from _trg_Received
  151. Thread.2aA]*Start new Thread.2
  152.  
  153. Thread.3a] Data send thread (Previous != Current) then Send
  154. ------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement