atmo.cpp
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:83k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2. * atmo.cpp : "Atmo Light" video filter
  3. *****************************************************************************
  4. * Copyright (C) 2000-2006 the VideoLAN team
  5. * $Id: 2e78693a616aadcc9dc6a879569ab2a46f25f8d2 $
  6. *
  7. * Authors: André Weber (WeberAndre@gmx.de)
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  22. *****************************************************************************/
  23. /*****************************************************************************
  24. * Preamble
  25. *****************************************************************************/
  26. #include <stdlib.h>                                      /* malloc(), free() */
  27. #include <string.h>
  28. #include <math.h>                                            /* sin(), cos() */
  29. #ifdef HAVE_CONFIG_H
  30. # include "config.h"
  31. #endif
  32. // #define __ATMO_DEBUG__
  33. // [:Zs]+$
  34. #include <vlc_common.h>
  35. #include <vlc_plugin.h>
  36. #include <vlc_vout.h>
  37. #include <vlc_playlist.h>
  38. #include "vlc_filter.h"
  39. #include "AtmoDefs.h"
  40. #include "AtmoDynData.h"
  41. #include "AtmoLiveView.h"
  42. #include "AtmoTools.h"
  43. #include "AtmoExternalCaptureInput.h"
  44. #include "AtmoConfig.h"
  45. #include "AtmoConnection.h"
  46. #include "AtmoSerialConnection.h"
  47. /*****************************************************************************
  48. * Local prototypes
  49. *****************************************************************************/
  50. /* directly to vlc related functions required that the module is accepted */
  51. static int  CreateFilter    ( vlc_object_t * );
  52. static void DestroyFilter   ( vlc_object_t * );
  53. static picture_t * Filter( filter_t *, picture_t *);
  54. /* callback for global variable state pause / continue / stop events */
  55. static void AddStateVariableCallback( filter_t *);
  56. static void DelStateVariableCallback( filter_t *);
  57. static int StateCallback(vlc_object_t *, char const *,
  58.                          vlc_value_t, vlc_value_t, void *);
  59. /* callback for variable crop-update */
  60. static void AddCropVariableCallback( filter_t *);
  61. static void DelCropVariableCallback( filter_t *);
  62. static int CropCallback(vlc_object_t *, char const *,
  63.                         vlc_value_t, vlc_value_t, void *);
  64. /* callback for atmo settings variables whose change
  65.    should be immediately realized and applied to output
  66. */
  67. static void DelAtmoSettingsVariablesCallbacks(filter_t *);
  68. static void AddAtmoSettingsVariablesCallbacks(filter_t *);
  69. static int AtmoSettingsCallback(vlc_object_t *, char const *,
  70.                                 vlc_value_t, vlc_value_t, void *);
  71. #if defined(__ATMO_DEBUG__)
  72. static void atmo_parse_crop(char *psz_cropconfig,
  73.                             video_format_t fmt_in,
  74.                             video_format_t fmt_render,
  75.                             int &i_visible_width,
  76.                             int &i_visible_height,
  77.                             int &i_x_offset,
  78.                             int &i_y_offset );
  79. #endif
  80. /* function to shutdown the fade thread which is started on pause*/
  81. static void CheckAndStopFadeThread(filter_t *);
  82. /* extracts a small RGB (BGR) Image from an YUV image */
  83. static void ExtractMiniImage_YUV(filter_sys_t *, picture_t *, uint8_t *);
  84. #if defined(__ATMO_DEBUG__)
  85. void SaveBitmap(filter_sys_t *p_sys, uint8_t *p_pixels, char *psz_filename);
  86. #endif
  87. /*****************************************************************************
  88. * External Prototypes for the AtmoCtrlLib.DLL
  89. *****************************************************************************/
  90. /*
  91. * if effectmode = emLivePicture then the source could be GDI (Screencapture)
  92. * or External - this means another application delivers Pixeldata to AtmoWin
  93. * Clientsoftware through  AtmoCtrlLib.DLL and the COM Api
  94. */
  95. #define lvsGDI           0
  96. #define lvsExternal      1
  97. /*
  98. strings for settings menus and hints
  99. */
  100. #define MODULE_DESCRIPTION N_ ( 
  101.  "This module allows to control an so called AtmoLight device "
  102.  "connected to your computer.n"
  103.  "AtmoLight is the homegrown version of what Philips calls AmbiLight.n"
  104.  "If you need further information feel free to visit us atnn"
  105.  "http://www.vdr-wiki.de/wiki/index.php/Atmo-pluginn "
  106.  "http://www.vdr-wiki.de/wiki/index.php/AtmoWinnn"
  107.  "You can find there detailed descriptions on how to build it for yourself "
  108.  "and where to get the required parts.n" 
  109.  "You can also have a look at pictures and some movies showing such a device " 
  110.  "in live action.")
  111. #if defined( __ATMO_DEBUG__ )
  112. #   define SAVEFRAMES_TEXT     N_("Save Debug Frames")
  113. #   define SAVEFRAMES_LONGTEXT N_("Write every 128th miniframe to a folder.")
  114. #   define FRAMEPATH_TEXT      N_("Debug Frame Folder")
  115. #   define FRAMEPATH_LONGTEXT  N_("The path where the debugframes " 
  116.                                   "should be saved")
  117. #endif
  118. #define WIDTH_TEXT             N_("Extracted Image Width")
  119. #define WIDTH_LONGTEXT         N_("The width of the mini image for " 
  120.                                   "further processing (64 is default)")
  121. #define HEIGHT_TEXT            N_("Extracted Image Height")
  122. #define HEIGHT_LONGTEXT        N_("The height of the mini image for " 
  123.                                   "further processing (48 is default)")
  124. #define PCOLOR_TEXT            N_("Color when paused")
  125. #define PCOLOR_LONGTEXT        N_("Set the color to show if the user " 
  126.                                   "pauses the video. (Have light to get " 
  127.                                   "another beer?)")
  128. #define PCOLOR_RED_TEXT        N_("Pause-Red")
  129. #define PCOLOR_RED_LONGTEXT    N_("Red component of the pause color")
  130. #define PCOLOR_GREEN_TEXT      N_("Pause-Green")
  131. #define PCOLOR_GREEN_LONGTEXT  N_("Green component of the pause color")
  132. #define PCOLOR_BLUE_TEXT       N_("Pause-Blue")
  133. #define PCOLOR_BLUE_LONGTEXT   N_("Blue component of the pause color")
  134. #define FADESTEPS_TEXT         N_("Pause-Fadesteps")
  135. #define FADESTEPS_LONGTEXT     N_("Number of steps to change current color " 
  136.                                   "to pause color (each step takes 40ms)")
  137. #define ECOLOR_RED_TEXT        N_("End-Red")
  138. #define ECOLOR_RED_LONGTEXT    N_("Red component of the shutdown color")
  139. #define ECOLOR_GREEN_TEXT      N_("End-Green")
  140. #define ECOLOR_GREEN_LONGTEXT  N_("Green component of the shutdown color")
  141. #define ECOLOR_BLUE_TEXT       N_("End-Blue")
  142. #define ECOLOR_BLUE_LONGTEXT   N_("Blue component of the shutdown color")
  143. #define EFADESTEPS_TEXT        N_("End-Fadesteps")
  144. #define EFADESTEPS_LONGTEXT  N_("Number of steps to change current color to " 
  145.                              "end color for dimming up the light in cinema " 
  146.                              "style... (each step takes 40ms)")
  147. #define USEWHITEADJ_TEXT       N_("Use Software White adjust")
  148. #define USEWHITEADJ_LONGTEXT   N_("Should the buildin driver do a white " 
  149.                                   "adjust or your LED stripes? recommend.")
  150. #define WHITE_RED_TEXT         N_("White Red")
  151. #define WHITE_RED_LONGTEXT     N_("Red value of a pure white on your "
  152.                                   "LED stripes.")
  153. #define WHITE_GREEN_TEXT       N_("White Green")
  154. #define WHITE_GREEN_LONGTEXT   N_("Green value of a pure white on your "
  155.                                   "LED stripes.")
  156. #define WHITE_BLUE_TEXT        N_("White Blue")
  157. #define WHITE_BLUE_LONGTEXT    N_("Blue value of a pure white on your "
  158.                                   "LED stripes.")
  159. #define SERIALDEV_TEXT         N_("Serial Port/Device")
  160. #define SERIALDEV_LONGTEXT   N_("Name of the serial port where the AtmoLight "
  161.                                 "controller is attached to.n" 
  162.                                 "On Windows usually something like COM1 or " 
  163.                                 "COM2. On Linux /dev/ttyS01 f.e.")
  164. #define EDGE_TEXT            N_("Edge Weightning")
  165. #define EDGE_LONGTEXT        N_("Increasing this value will result in color "
  166.                                 "more depending on the border of the frame.")
  167. #define BRIGHTNESS_TEXT     N_("Brightness")
  168. #define BRIGHTNESS_LONGTEXT N_("Overall brightness of your LED stripes")
  169. #define DARKNESS_TEXT       N_("Darkness Limit")
  170. #define DARKNESS_LONGTEXT   N_("Pixels with a saturation lower than this will "
  171.                                "be ignored. Should be greater than one for "
  172.                                "letterboxed videos.")
  173. #define HUEWINSIZE_TEXT     N_("Hue windowing")
  174. #define HUEWINSIZE_LONGTEXT N_("Used for statistics.")
  175. #define SATWINSIZE_TEXT     N_("Sat windowing")
  176. #define SATWINSIZE_LONGTEXT N_("Used for statistics.")
  177. #define MEANLENGTH_TEXT     N_("Filter length (ms)")
  178. #define MEANLENGTH_LONGTEXT N_("Time it takes until a color is completely "
  179.                                 "changed. This prevents flickering.")
  180. #define MEANTHRESHOLD_TEXT     N_("Filter threshold")
  181. #define MEANTHRESHOLD_LONGTEXT N_("How much a color has to be changed for an "
  182.                                   "immediate color change.")
  183. #define MEANPERCENTNEW_TEXT     N_("Filter Smoothness (in %)")
  184. #define MEANPERCENTNEW_LONGTEXT N_("Filter Smoothness")
  185. /* FIXME: WTF?!! feepk, July 6 '08 */
  186. #define FILTERMODE_TEXT        N_("Filter mode")
  187. #define FILTERMODE_LONGTEXT    N_("kind of filtering which should be use to "
  188.                                   "calcuate the color output")
  189. static const int pi_filtermode_values[] = {
  190.        (int)afmNoFilter,
  191.        (int)afmCombined,
  192.        (int)afmPercent
  193. };
  194. static const char *const ppsz_filtermode_descriptions[] = {
  195.         N_("No Filtering"),
  196.         N_("Combined"),
  197.         N_("Percent")
  198. };
  199. #define FRAMEDELAY_TEXT       N_("Frame delay")
  200. #define FRAMEDELAY_LONGTEXT   N_("Helps to get the video output and the light "
  201.                                  "effects in sync. Values around 20ms should " 
  202.                                  "do the trick.")
  203. #define CHANNEL_0_ASSIGN_TEXT N_("Channel summary")
  204. #define CHANNEL_1_ASSIGN_TEXT N_("Channel left")
  205. #define CHANNEL_2_ASSIGN_TEXT N_("Channel right")
  206. #define CHANNEL_3_ASSIGN_TEXT N_("Channel top")
  207. #define CHANNEL_4_ASSIGN_TEXT N_("Channel bottom")
  208. #define CHANNELASSIGN_LONGTEXT N_("Maps the hardware channel X to logical "
  209.                                   "channel Y to fix wrong wiring :-)")
  210. static const int pi_channel_assignment_values[] = {
  211.     -1,
  212.      0,
  213.      1,
  214.      2,
  215.      3,
  216.      4
  217. };
  218. static const char *const ppsz_channel_assignment_descriptions[] = {
  219.         N_("disabled"),
  220.         N_("summary"),
  221.         N_("left"),
  222.         N_("right"),
  223.         N_("top"),
  224.         N_("bottom")
  225. };
  226. #define ZONE_0_GRADIENT_TEXT N_("Summary gradient")
  227. #define ZONE_1_GRADIENT_TEXT N_("Left gradient")
  228. #define ZONE_2_GRADIENT_TEXT N_("Right gradient")
  229. #define ZONE_3_GRADIENT_TEXT N_("Top gradient")
  230. #define ZONE_4_GRADIENT_TEXT N_("Bottom gradient")
  231. #define ZONE_X_GRADIENT_LONG_TEXT N_("Defines a small bitmap with 64x48 "
  232.                                      "pixels, containing a grayscale gradient")
  233. #if defined( WIN32 )
  234. #   define ATMOWINEXE_TEXT      N_("Filename of AtmoWinA.exe")
  235. #   define ATMOWINEXE_LONGTEXT  N_("if you want the AtmoLight control "
  236.                                    "software to be launched by VLC, enter the "
  237.                                    "complete path of AtmoWinA.exe here.")
  238. #   define USEBUILDIN_TEXT      N_("Use built-in AtmoLight")
  239. #   define USEBUILDIN_LONGTEXT N_("VLC will directly use your AtmoLight "
  240.                                   "hardware without running the external "
  241.                                   "AtmoWinA.exe Userspace driver.")
  242. #endif
  243. #define CFG_PREFIX "atmo-"
  244. /*****************************************************************************
  245. * Module descriptor
  246. *****************************************************************************/
  247. vlc_module_begin ()
  248. set_description( N_("AtmoLight Filter") )
  249. set_help( MODULE_DESCRIPTION )
  250. set_shortname( N_( "AtmoLight" ))
  251. set_capability( "video filter2", 0 )
  252. set_category( CAT_VIDEO )
  253. set_subcategory( SUBCAT_VIDEO_VFILTER )
  254. #if defined(WIN32)
  255. set_section( N_("Choose between the built-in AtmoLight "
  256.                  "driver or the external" ), 0 )
  257. /*
  258.     only on win32 exists the option to use the buildin driver or
  259.     the more flexible external driver application
  260. */
  261. add_bool(CFG_PREFIX "usebuildin", true, NULL,
  262.          USEBUILDIN_TEXT, USEBUILDIN_LONGTEXT, false)
  263. add_string(CFG_PREFIX "serialdev", "COM1", NULL,
  264.            SERIALDEV_TEXT, SERIALDEV_LONGTEXT, false )
  265. /*
  266.     on win32 the executeable external driver application
  267.     for automatic start if needed
  268. */
  269. add_file(CFG_PREFIX "atmowinexe", NULL, NULL,
  270.          ATMOWINEXE_TEXT, ATMOWINEXE_LONGTEXT, false )
  271. #else
  272. set_section( N_("Enter the connection of your AtmoLight hardware" ), 0 )
  273. add_string(CFG_PREFIX "serialdev", "/dev/ttyS01", NULL,
  274.            SERIALDEV_TEXT, SERIALDEV_LONGTEXT, false )
  275. #endif
  276. /*
  277.     color which is showed if you want durring pausing
  278.     your movie ... used for both buildin / external
  279. */
  280. set_section( N_("Illuminate the room with this color on pause" ), 0 )
  281. add_bool(CFG_PREFIX "usepausecolor", false, NULL,
  282.          PCOLOR_TEXT, PCOLOR_LONGTEXT, false)
  283. add_integer_with_range(CFG_PREFIX "pcolor-red",   0, 0, 255, NULL,
  284.                        PCOLOR_RED_TEXT, PCOLOR_RED_LONGTEXT, false)
  285. add_integer_with_range(CFG_PREFIX "pcolor-green", 0, 0, 255, NULL,
  286.                        PCOLOR_GREEN_TEXT, PCOLOR_GREEN_LONGTEXT, false)
  287. add_integer_with_range(CFG_PREFIX "pcolor-blue",  192, 0, 255, NULL,
  288.                        PCOLOR_BLUE_TEXT, PCOLOR_BLUE_LONGTEXT, false)
  289. add_integer_with_range(CFG_PREFIX "fadesteps", 50, 1, 250, NULL,
  290.                        FADESTEPS_TEXT, FADESTEPS_LONGTEXT, false)
  291. /*
  292.     color which is showed if you finished watching your movie ...
  293.     used for both buildin / external
  294. */
  295. set_section( N_("Illuminate the room with this color on shutdown" ), 0 )
  296. add_integer_with_range(CFG_PREFIX "ecolor-red",   192, 0, 255, NULL,
  297.                        ECOLOR_RED_TEXT,   ECOLOR_RED_LONGTEXT,   false)
  298. add_integer_with_range(CFG_PREFIX "ecolor-green", 192, 0, 255, NULL,
  299.                        ECOLOR_GREEN_TEXT, ECOLOR_GREEN_LONGTEXT, false)
  300. add_integer_with_range(CFG_PREFIX "ecolor-blue",  192, 0, 255, NULL,
  301.                        ECOLOR_BLUE_TEXT,  ECOLOR_BLUE_LONGTEXT,  false)
  302. add_integer_with_range(CFG_PREFIX "efadesteps",    50, 1, 250, NULL,
  303.                        EFADESTEPS_TEXT,   EFADESTEPS_LONGTEXT,    false)
  304. /*
  305.  settings only for the buildin driver (if external driver app is used
  306.  these parameters are ignored.)
  307.  definition of parameters for the buildin filter ...
  308. */
  309. set_section( N_("Settings for the built-in Live Video Processor only" ), 0 )
  310. add_integer_with_range(CFG_PREFIX "EdgeWeightning",   8, 1, 30, NULL,
  311.                        EDGE_TEXT, EDGE_LONGTEXT, false)
  312. add_integer_with_range(CFG_PREFIX "Brightness",   100, 50, 300, NULL,
  313.                        BRIGHTNESS_TEXT, BRIGHTNESS_LONGTEXT, false)
  314. add_integer_with_range(CFG_PREFIX "DarknessLimit",   5, 0, 10, NULL,
  315.                        DARKNESS_TEXT, DARKNESS_LONGTEXT, false)
  316. add_integer_with_range(CFG_PREFIX "HueWinSize",   3, 0, 5, NULL,
  317.                        HUEWINSIZE_TEXT, HUEWINSIZE_LONGTEXT, false)
  318. add_integer_with_range(CFG_PREFIX "SatWinSize",   3, 0, 5, NULL,
  319.                        SATWINSIZE_TEXT, SATWINSIZE_LONGTEXT, false)
  320. add_integer(CFG_PREFIX "filtermode", (int)afmCombined, NULL,
  321.             FILTERMODE_TEXT, FILTERMODE_LONGTEXT, false )
  322. change_integer_list(pi_filtermode_values, ppsz_filtermode_descriptions, NULL )
  323. add_integer_with_range(CFG_PREFIX "MeanLength",    300, 300, 5000, NULL,
  324.                        MEANLENGTH_TEXT, MEANLENGTH_LONGTEXT, false)
  325. add_integer_with_range(CFG_PREFIX "MeanThreshold",  40, 1, 100, NULL,
  326.                        MEANTHRESHOLD_TEXT, MEANTHRESHOLD_LONGTEXT, false)
  327. add_integer_with_range(CFG_PREFIX "PercentNew", 50, 1, 100, NULL,
  328.                       MEANPERCENTNEW_TEXT, MEANPERCENTNEW_LONGTEXT, false)
  329. add_integer_with_range(CFG_PREFIX "FrameDelay", 18, 0, 35, NULL,
  330.                        FRAMEDELAY_TEXT, FRAMEDELAY_LONGTEXT, false)
  331. /*
  332.   output channel reordering
  333. */
  334. set_section( N_("Change channel assignment (fixes wrong wiring)" ), 0 )
  335. add_integer( CFG_PREFIX "channel_0", 0, NULL,
  336.             CHANNEL_0_ASSIGN_TEXT, CHANNELASSIGN_LONGTEXT, false )
  337. change_integer_list( pi_channel_assignment_values,
  338.                      ppsz_channel_assignment_descriptions, 0 )
  339. add_integer( CFG_PREFIX "channel_1", 1, NULL,
  340.             CHANNEL_1_ASSIGN_TEXT, CHANNELASSIGN_LONGTEXT, false )
  341. change_integer_list( pi_channel_assignment_values,
  342.                      ppsz_channel_assignment_descriptions, 0 )
  343. add_integer( CFG_PREFIX "channel_2", 2, NULL,
  344.             CHANNEL_2_ASSIGN_TEXT, CHANNELASSIGN_LONGTEXT, false )
  345. change_integer_list( pi_channel_assignment_values,
  346.                      ppsz_channel_assignment_descriptions, 0 )
  347. add_integer( CFG_PREFIX "channel_3", 3, NULL,
  348.             CHANNEL_3_ASSIGN_TEXT, CHANNELASSIGN_LONGTEXT, false )
  349. change_integer_list( pi_channel_assignment_values,
  350.                      ppsz_channel_assignment_descriptions, 0 )
  351. add_integer( CFG_PREFIX "channel_4", 4, NULL,
  352.             CHANNEL_4_ASSIGN_TEXT, CHANNELASSIGN_LONGTEXT, false )
  353. change_integer_list( pi_channel_assignment_values,
  354.                      ppsz_channel_assignment_descriptions, 0 )
  355. /*
  356.   LED color white calibration
  357. */
  358. set_section( N_("Adjust the white light to your LED stripes" ), 0 )
  359. add_bool(CFG_PREFIX "whiteadj", true, NULL,
  360.          USEWHITEADJ_TEXT, USEWHITEADJ_LONGTEXT, false)
  361. add_integer_with_range(CFG_PREFIX "white-red",   255, 0, 255, NULL,
  362.                        WHITE_RED_TEXT,   WHITE_RED_LONGTEXT,   false)
  363. add_integer_with_range(CFG_PREFIX "white-green", 255, 0, 255, NULL,
  364.                        WHITE_GREEN_TEXT, WHITE_GREEN_LONGTEXT, false)
  365. add_integer_with_range(CFG_PREFIX "white-blue",  255, 0, 255, NULL,
  366.                        WHITE_BLUE_TEXT,  WHITE_BLUE_LONGTEXT,  false)
  367. /* end of definition of parameter for the buildin filter ... part 1 */
  368. /*
  369. only for buildin (external has own definition) per default the calucation
  370. used linear gradients for assigning a priority to the pixel - depending
  371. how near they are to the border ...for changing this you can create 64x48
  372. Pixel BMP files - which contain your own grayscale... (you can produce funny
  373. effects with this...) the images MUST not compressed, should have 24-bit per
  374. pixel, or a simple 256 color grayscale palette
  375. */
  376. set_section( N_("Change gradients" ), 0 )
  377. add_file(CFG_PREFIX "gradient_zone_0", NULL, NULL,
  378.          ZONE_0_GRADIENT_TEXT, ZONE_X_GRADIENT_LONG_TEXT, true )
  379. add_file(CFG_PREFIX "gradient_zone_1", NULL, NULL,
  380.          ZONE_1_GRADIENT_TEXT, ZONE_X_GRADIENT_LONG_TEXT, true )
  381. add_file(CFG_PREFIX "gradient_zone_2", NULL, NULL,
  382.          ZONE_2_GRADIENT_TEXT, ZONE_X_GRADIENT_LONG_TEXT, true )
  383. add_file(CFG_PREFIX "gradient_zone_3", NULL, NULL,
  384.          ZONE_3_GRADIENT_TEXT, ZONE_X_GRADIENT_LONG_TEXT, true )
  385. add_file(CFG_PREFIX "gradient_zone_4", NULL, NULL,
  386.          ZONE_4_GRADIENT_TEXT, ZONE_X_GRADIENT_LONG_TEXT, true )
  387. #if defined(__ATMO_DEBUG__)
  388. add_bool(CFG_PREFIX "saveframes", false, NULL,
  389.          SAVEFRAMES_TEXT, SAVEFRAMES_LONGTEXT, false)
  390. add_string(CFG_PREFIX "framepath", "", NULL,
  391.            FRAMEPATH_TEXT, FRAMEPATH_LONGTEXT, false )
  392. #endif
  393. /*
  394.    may be later if computers gets more power ;-) than now we increase
  395.    the samplesize from which we do the stats for output color calculation
  396. */
  397. add_integer_with_range(CFG_PREFIX "width",  64, 64, 512, NULL,
  398.                        WIDTH_TEXT,  WIDTH_LONGTEXT, true)
  399. add_integer_with_range(CFG_PREFIX "height", 48, 48, 384, NULL,
  400.                        HEIGHT_TEXT,  HEIGHT_LONGTEXT, true)
  401. add_shortcut( "atmo" )
  402. set_callbacks( CreateFilter, DestroyFilter  )
  403. vlc_module_end ()
  404. static const char *const ppsz_filter_options[] = {
  405. #if defined(WIN32)
  406.         "usebuildin",
  407. #endif
  408.         "serialdev",
  409.         "EdgeWeightning",
  410.         "Brightness",
  411.         "DarknessLimit",
  412.         "HueWinSize",
  413.         "SatWinSize",
  414.         "filtermode",
  415.         "MeanLength",
  416.         "MeanThreshold",
  417.         "PercentNew",
  418.         "FrameDelay",
  419.         "channel_0",
  420.         "channel_1",
  421.         "channel_2",
  422.         "channel_3",
  423.         "channel_4",
  424.         "whiteadj",
  425.         "white-red",
  426.         "white-green",
  427.         "white-blue",
  428.         "usepausecolor",
  429.         "pcolor-red",
  430.         "pcolor-green",
  431.         "pcolor-blue",
  432.         "fadesteps",
  433.         "ecolor-red",
  434.         "ecolor-green",
  435.         "ecolor-blue",
  436.         "efadesteps",
  437. #if defined(WIN32 )
  438.         "usebuildin",
  439.         "atmowinexe",
  440. #endif
  441. #if defined(__ATMO_DEBUG__)
  442.         "saveframes" ,
  443.         "framepath",
  444. #endif
  445.         "width",
  446.         "height",
  447.         "gradient_zone_0",
  448.         "gradient_zone_1",
  449.         "gradient_zone_2",
  450.         "gradient_zone_3",
  451.         "gradient_zone_4",
  452.         NULL
  453. };
  454. /*****************************************************************************
  455. * fadethread_t: Color Fading Thread
  456. *****************************************************************************
  457. * changes slowly the color of the output if videostream gets paused...
  458. *****************************************************************************
  459. */
  460. typedef struct
  461. {
  462.     VLC_COMMON_MEMBERS
  463.         filter_t *p_filter;
  464.     /* tell the thread which color should be the target of fading */
  465.     uint8_t ui_red;
  466.     uint8_t ui_green;
  467.     uint8_t ui_blue;
  468.     /* how many steps should happen until this */
  469.     int i_steps;
  470. } fadethread_t;
  471. static void *FadeToColorThread(vlc_object_t *);
  472. /*****************************************************************************
  473. * filter_sys_t: AtmoLight filter method descriptor
  474. *****************************************************************************
  475. * It describes the AtmoLight specific properties of an video filter.
  476. *****************************************************************************/
  477. struct filter_sys_t
  478. {
  479.     /*
  480.     special for the access of the p_fadethread member all other members
  481.     need no special protection so far!
  482.     */
  483.     vlc_mutex_t filter_lock;
  484.     bool b_enabled;
  485.     int32_t i_AtmoOldEffect;
  486.     bool b_pause_live;
  487.     int32_t i_atmo_width;
  488.     int32_t i_atmo_height;
  489. #if defined(__ATMO_DEBUG__)
  490.     bool  b_saveframes;
  491.     int i_framecounter;
  492.     char sz_framepath[MAX_PATH];
  493. #endif
  494.     /* light color durring movie pause ... */
  495.     bool  b_usepausecolor;
  496.     uint8_t ui_pausecolor_red;
  497.     uint8_t ui_pausecolor_green;
  498.     uint8_t ui_pausecolor_blue;
  499.     int i_fadesteps;
  500.     /* light color on movie finish ... */
  501.     uint8_t ui_endcolor_red;
  502.     uint8_t ui_endcolor_green;
  503.     uint8_t ui_endcolor_blue;
  504.     int i_endfadesteps;
  505.     fadethread_t *p_fadethread;
  506.     /* Variables for buildin driver only... */
  507.     /* is only present and initialized if the internal driver is used*/
  508.     CAtmoConfig *p_atmo_config;
  509.     /* storage for temporal settings "volatile" */
  510.     CAtmoDynData *p_atmo_dyndata;
  511.     /* initialized for buildin driver with AtmoCreateTransferBuffers */
  512.     BITMAPINFOHEADER mini_image_format;
  513.     /* is only use buildin driver! */
  514.     uint8_t *p_atmo_transfer_buffer;
  515.     /* end buildin driver */
  516.     /*
  517.     contains the real output size of the video calculated on
  518.     change event of the variable "crop" from vout
  519.     */
  520.     int32_t i_crop_x_offset;
  521.     int32_t i_crop_y_offset;
  522.     int32_t i_crop_width;
  523.     int32_t i_crop_height;
  524.     void (*pf_extract_mini_image) (filter_sys_t *p_sys,
  525.         picture_t *p_inpic,
  526.         uint8_t *p_transfer_dest);
  527. #if defined( WIN32 )
  528.     /* External Library as wrapper arround COM Stuff */
  529.     HINSTANCE h_AtmoCtrl;
  530.     int32_t (*pf_ctrl_atmo_initialize) (void);
  531.     void (*pf_ctrl_atmo_finalize) (int32_t what);
  532.     int32_t (*pf_ctrl_atmo_switch_effect) (int32_t);
  533.     int32_t (*pf_ctrl_atmo_set_live_source) (int32_t);
  534.     void (*pf_ctrl_atmo_create_transfer_buffers) (int32_t, int32_t,
  535.                                                   int32_t , int32_t);
  536.     uint8_t* (*pf_ctrl_atmo_lock_transfer_buffer) (void);
  537.     void (*pf_ctrl_atmo_send_pixel_data) (void);
  538. #endif
  539. };
  540. /*
  541. initialize previously configured Atmo Light environment
  542. - if internal is enabled try to access the device on the serial port
  543. - if not internal is enabled and we are on win32 try to initialize
  544. the previously loaded DLL ...
  545. Return Values may be: -1 (failed for some reason - filter will be disabled)
  546. 1 Ok. lets rock
  547. */
  548. static int32_t AtmoInitialize(filter_t *p_filter, bool b_for_thread)
  549. {
  550.     filter_sys_t *p_sys = p_filter->p_sys;
  551.     if(p_sys->p_atmo_config)
  552.     {
  553.         if(b_for_thread == false)
  554.         {
  555.             /* open com port */
  556.             /* setup Output Threads ... */
  557.             msg_Dbg( p_filter, "open serial connection %s",
  558.                 p_sys->p_atmo_config->getSerialDevice());
  559.             if(CAtmoTools::RecreateConnection(p_sys->p_atmo_dyndata) == ATMO_TRUE)
  560.             {
  561.                 msg_Dbg( p_filter, "start live view thread ...");
  562.                 CAtmoTools::SwitchEffect(p_sys->p_atmo_dyndata, emLivePicture);
  563.                 msg_Dbg( p_filter, "live view thread launched...");
  564.                 return 1;
  565.             } else {
  566.                 msg_Err( p_filter,"failed to open serial device? some other software/driver may use it?");
  567.             }
  568.         }
  569. #if defined(WIN32)
  570.     } else if(p_sys->pf_ctrl_atmo_initialize)
  571.     {
  572.         /* on win32 with active ctrl dll */
  573.         return p_sys->pf_ctrl_atmo_initialize();
  574. #endif
  575.     }
  576.     return -1;
  577. }
  578. /*
  579. prepare the shutdown of the effect threads,
  580. for build in filter - close the serialport after finishing the threads...
  581. cleanup possible loaded DLL...
  582. */
  583. static void AtmoFinalize(filter_t *p_filter, int32_t what)
  584. {
  585.     filter_sys_t *p_sys = p_filter->p_sys;
  586.     if(p_sys->p_atmo_config)
  587.     {
  588.         if(what == 1)
  589.         {
  590.             CAtmoDynData *p_atmo_dyndata = p_sys->p_atmo_dyndata;
  591.             if(p_atmo_dyndata)
  592.             {
  593.                 p_atmo_dyndata->LockCriticalSection();
  594.                 CThread *p_effect_thread = p_atmo_dyndata->getEffectThread();
  595.                 p_atmo_dyndata->setEffectThread(NULL);
  596.                 if(p_effect_thread != NULL)
  597.                 {
  598.                     /*
  599.                     forced the thread to die...
  600.                     and wait for termination of the thread
  601.                     */
  602.                     p_effect_thread->Terminate();
  603.                     delete p_effect_thread;
  604.                     msg_Dbg( p_filter, "effect thread died peacefully");
  605.                 }
  606.                 /*
  607.                 close serial port if it is open (all OS specific is inside
  608.                 CAtmoSerialConnection implemented / defined)
  609.                 */
  610.                 CAtmoConnection *p_atmo_connection =
  611.                                  p_atmo_dyndata->getAtmoConnection();
  612.                 p_atmo_dyndata->setAtmoConnection(NULL);
  613.                 if(p_atmo_connection) {
  614.                     p_atmo_connection->CloseConnection();
  615.                     delete p_atmo_connection;
  616.                 }
  617.                 p_atmo_dyndata->UnLockCriticalSection();
  618.             }
  619.         }
  620. #if defined(WIN32)
  621.     } else if(p_sys->pf_ctrl_atmo_finalize)
  622.     {
  623.         /* on win32 with active ctrl dll */
  624.         p_sys->pf_ctrl_atmo_finalize(what);
  625. #endif
  626.     }
  627. }
  628. /*
  629. switch the current light effect - does only something on win32, with the
  630. external  libraries - if the buildin effects are used nothing happens
  631. */
  632. static int32_t AtmoSwitchEffect(filter_t *p_filter, int32_t newMode)
  633. {
  634.     filter_sys_t *p_sys = p_filter->p_sys;
  635.     if(p_sys->p_atmo_config)
  636.     {
  637.         /*
  638.         buildin driver
  639.         doesnt know different modes for effects so this
  640.         function call would just do nothing special
  641.         in this case
  642.         */
  643. #if defined(WIN32)
  644.     } else if(p_sys->pf_ctrl_atmo_switch_effect)
  645.     {
  646.         /* on win32 with active ctrl dll */
  647.         return p_sys->pf_ctrl_atmo_switch_effect(newMode);
  648. #endif
  649.     }
  650.     return emDisabled;
  651. }
  652. /*
  653. set the current live picture source, does only something on win32,
  654. with the external libraries - if the buildin effects are used nothing
  655. happens...
  656. */
  657. static int32_t AtmoSetLiveSource(filter_t *p_filter, int32_t newSource)
  658. {
  659.     filter_sys_t *p_sys = p_filter->p_sys;
  660.     if(p_sys->p_atmo_config)
  661.     {
  662.         /*
  663.         buildin driver
  664.         doesnt know different sources so this
  665.         function call would just do nothing special
  666.         in this case
  667.         */
  668. #if defined(WIN32)
  669.     } else if(p_sys->pf_ctrl_atmo_set_live_source)
  670.     {
  671.         /* on win32 with active ctrl dll */
  672.         return p_sys->pf_ctrl_atmo_set_live_source(newSource);
  673. #endif
  674.     }
  675.     return lvsGDI;
  676. }
  677. /*
  678. setup the pixel transferbuffers which is used to transfer pixeldata from
  679. the filter to the effect thread, and possible accross the process
  680. boundaries on win32, with the external DLL
  681. */
  682. static void AtmoCreateTransferBuffers(filter_t *p_filter,
  683.                                       int32_t FourCC,
  684.                                       int32_t bytePerPixel,
  685.                                       int32_t width,
  686.                                       int32_t height)
  687. {
  688.     filter_sys_t *p_sys = p_filter->p_sys;
  689.     if(p_sys->p_atmo_config)
  690.     {
  691.         /*
  692.         we need a buffer where the image is stored (only for transfer
  693.         to the processing thread)
  694.         */
  695.         if(p_sys->p_atmo_transfer_buffer)
  696.             free(p_sys->p_atmo_transfer_buffer);
  697.         p_sys->p_atmo_transfer_buffer = (uint8_t *)malloc(bytePerPixel *
  698.                                                           width *  height);
  699.         memset(&p_sys->mini_image_format,0,sizeof(BITMAPINFOHEADER));
  700.         p_sys->mini_image_format.biSize = sizeof(BITMAPINFOHEADER);
  701.         p_sys->mini_image_format.biWidth = width;
  702.         p_sys->mini_image_format.biHeight = height;
  703.         p_sys->mini_image_format.biBitCount = bytePerPixel*8;
  704.         p_sys->mini_image_format.biCompression = FourCC;
  705. #if defined(WIN32)
  706.     } else if(p_sys->pf_ctrl_atmo_create_transfer_buffers)
  707.     {
  708.         /* on win32 with active ctrl dll */
  709.         p_sys->pf_ctrl_atmo_create_transfer_buffers(FourCC,
  710.             bytePerPixel,
  711.             width,
  712.             height);
  713. #endif
  714.     }
  715. }
  716. /*
  717. acquire the transfer buffer pointer the buildin version only
  718. returns the pointer to the allocated buffer ... the
  719. external version on win32 has to do some COM stuff to lock the
  720. Variant Byte array which is behind the buffer
  721. */
  722. static uint8_t* AtmoLockTransferBuffer(filter_t *p_filter)
  723. {
  724.     filter_sys_t *p_sys = p_filter->p_sys;
  725.     if(p_sys->p_atmo_config)
  726.     {
  727.         return p_sys->p_atmo_transfer_buffer;
  728. #if defined(WIN32)
  729.     } else if(p_sys->pf_ctrl_atmo_lock_transfer_buffer)
  730.     {
  731.         /* on win32 with active ctrl dll */
  732.         return p_sys->pf_ctrl_atmo_lock_transfer_buffer();
  733. #endif
  734.     }
  735.     return NULL;
  736. }
  737. /*
  738. send the content of current pixel buffer got with AtmoLockTransferBuffer
  739. to the processing threads
  740. - build in version - will forward the data to AtmoExternalCaptureInput Thread
  741. - win32 external - will do the same, but across the process boundaries via
  742. COM to the AtmoWinA.exe Process
  743. */
  744. static void AtmoSendPixelData(filter_t *p_filter)
  745. {
  746.     filter_sys_t *p_sys = p_filter->p_sys;
  747.     if(p_sys->p_atmo_config && p_sys->p_atmo_transfer_buffer)
  748.     {
  749.         CAtmoDynData *p_atmo_dyndata = p_sys->p_atmo_dyndata;
  750.         if(p_atmo_dyndata)
  751.         {
  752.             /*
  753.             the cast will go Ok because we are inside videolan there is only
  754.             this kind of effect thread implemented!
  755.             */
  756.             CAtmoLiveView *p_atmo_live_view_thread =
  757.                 (CAtmoLiveView *)p_atmo_dyndata->getEffectThread();
  758.             if(p_atmo_live_view_thread)
  759.             {
  760.                 /*
  761.                 the same as above inside videolan only this single kind of
  762.                 input exists so we can cast without further tests!
  763.                 */
  764.                 CAtmoExternalCaptureInput *p_atmo_external_capture_input_thread =
  765.                     (CAtmoExternalCaptureInput *)p_atmo_live_view_thread->getAtmoInput();
  766.                 if(p_atmo_external_capture_input_thread)
  767.                 {
  768.                     /*
  769.                     this call will do a 1:1 copy of this buffer, and wakeup
  770.                     the thread from normal sleeping
  771.                     */
  772.                     p_atmo_external_capture_input_thread->
  773.                         DeliverNewSourceDataPaket(&p_sys->mini_image_format,
  774.                         p_sys->p_atmo_transfer_buffer);
  775.                 }
  776.             }
  777.         }
  778. #if defined(WIN32)
  779.     } else if(p_sys->pf_ctrl_atmo_send_pixel_data)
  780.     {
  781.         /* on win32 with active ctrl dll */
  782.         p_sys->pf_ctrl_atmo_send_pixel_data();
  783. #endif
  784.     }
  785. }
  786. /*
  787.     Shutdown AtmoLight finally - is call from DestroyFilter
  788.     does the cleanup restores the effectmode on the external Software
  789.     (only win32) and possible setup the final light ...
  790. */
  791. static void Atmo_Shutdown(filter_t *p_filter)
  792. {
  793.     filter_sys_t *p_sys = p_filter->p_sys;
  794.     if(p_sys->b_enabled == true)
  795.     {
  796.         /*
  797.         if there is a still running show pause color thread kill him!
  798.         */
  799.         CheckAndStopFadeThread(p_filter);
  800.         if(p_sys->p_atmo_config || (p_sys->i_AtmoOldEffect == emStaticColor))
  801.         {
  802.             /*
  803.             fade to end color (in case of external AtmoWin Software
  804.             assume that the static color will equal to this
  805.             one to get a soft change and no flash!
  806.             */
  807.             p_sys->b_pause_live = true;
  808.             // perpare spawn fadeing thread
  809.             vlc_mutex_lock( &p_sys->filter_lock );
  810.             p_sys->p_fadethread = (fadethread_t *)vlc_object_create( p_filter,
  811.                                                         sizeof(fadethread_t) );
  812.             p_sys->p_fadethread->p_filter = p_filter;
  813.             p_sys->p_fadethread->ui_red   = p_sys->ui_endcolor_red;
  814.             p_sys->p_fadethread->ui_green = p_sys->ui_endcolor_green;
  815.             p_sys->p_fadethread->ui_blue  = p_sys->ui_endcolor_blue;
  816.             p_sys->p_fadethread->i_steps  = p_sys->i_endfadesteps;
  817.             if( vlc_thread_create( p_sys->p_fadethread,
  818.                 "AtmoLight fadeing",
  819.                 FadeToColorThread,
  820.                 VLC_THREAD_PRIORITY_LOW ) )
  821.             {
  822.                 msg_Err( p_filter, "cannot create FadeToColorThread" );
  823.                 vlc_object_release( p_sys->p_fadethread );
  824.                 p_sys->p_fadethread = NULL;
  825.                 vlc_mutex_unlock( &p_sys->filter_lock );
  826.             } else {
  827.                 vlc_mutex_unlock( &p_sys->filter_lock );
  828.                 /* wait for the thread... */
  829.                 vlc_thread_join(p_sys->p_fadethread);
  830.                 vlc_object_release(p_sys->p_fadethread);
  831.                 p_sys->p_fadethread = NULL;
  832.             }
  833.         }
  834.         if(p_sys->i_AtmoOldEffect != emLivePicture)
  835.             AtmoSwitchEffect(p_filter, p_sys->i_AtmoOldEffect);
  836.         else
  837.             AtmoSetLiveSource(p_filter, lvsGDI);
  838.         AtmoFinalize(p_filter, 1);
  839.         /* disable filter method .. */
  840.         p_sys->b_enabled = false;
  841.     }
  842. }
  843. /*
  844. initialize the filter_sys_t structure with the data from the settings
  845. variables - if the external filter on win32 is enabled try loading the DLL,
  846. if this fails fallback to the buildin software
  847. */
  848. static void Atmo_SetupParameters(filter_t *p_filter)
  849. {
  850.     bool b_use_buildin_driver = true;
  851.     char *psz_path;
  852.     filter_sys_t *p_sys =  p_filter->p_sys;
  853.     /* default filter disabled until DLL loaded and Init Success!*/
  854.     p_sys->b_enabled             = false;
  855.     /* setup default mini image size (may be later a user option) */
  856.     p_sys->i_atmo_width          = 64;
  857.     p_sys->i_atmo_height         = 48;
  858.     vlc_mutex_init( &p_sys->filter_lock );
  859. #if defined(WIN32)
  860.     /*
  861.     only on WIN32 the user has the choice between
  862.     internal driver and external
  863.     */
  864.     b_use_buildin_driver = var_CreateGetBoolCommand( p_filter,
  865.         CFG_PREFIX "usebuildin" );
  866.     if(b_use_buildin_driver == false) {
  867.         /* Load the Com Wrapper Library (source available) */
  868.         p_sys->h_AtmoCtrl = LoadLibraryA("AtmoCtrlLib.dll");
  869.         if(p_sys->h_AtmoCtrl != NULL)
  870.         {
  871.             msg_Dbg( p_filter, "LoadLibrary('AtmoCtrlLib.dll'); Success");
  872.             /* importing all required functions I hope*/
  873.             p_sys->pf_ctrl_atmo_initialize =
  874.                 (int32_t (*)(void))GetProcAddress(p_sys->h_AtmoCtrl,"AtmoInitialize");
  875.             if(!p_sys->pf_ctrl_atmo_initialize)
  876.                 msg_Err( p_filter, "export AtmoInitialize missing.");
  877.             p_sys->pf_ctrl_atmo_finalize =
  878.                 (void (*)(int32_t))GetProcAddress(p_sys->h_AtmoCtrl,"AtmoFinalize");
  879.             if(!p_sys->pf_ctrl_atmo_finalize)
  880.                 msg_Err( p_filter, "export AtmoFinalize missing.");
  881.             p_sys->pf_ctrl_atmo_switch_effect =
  882.                 (int32_t(*)(int32_t))GetProcAddress(p_sys->h_AtmoCtrl,"AtmoSwitchEffect");
  883.             if(!p_sys->pf_ctrl_atmo_switch_effect)
  884.                 msg_Err( p_filter, "export AtmoSwitchEffect missing.");
  885.             p_sys->pf_ctrl_atmo_set_live_source =
  886.                 (int32_t(*)(int32_t))GetProcAddress(p_sys->h_AtmoCtrl,"AtmoSetLiveSource");
  887.             if(!p_sys->pf_ctrl_atmo_set_live_source)
  888.                 msg_Err( p_filter, "export AtmoSetLiveSource missing.");
  889.             p_sys->pf_ctrl_atmo_create_transfer_buffers =
  890.                 (void (*)(int32_t, int32_t, int32_t , int32_t))GetProcAddress(p_sys->h_AtmoCtrl,"AtmoCreateTransferBuffers");
  891.             if(!p_sys->pf_ctrl_atmo_create_transfer_buffers)
  892.                 msg_Err( p_filter, "export AtmoCreateTransferBuffers missing.");
  893.             p_sys->pf_ctrl_atmo_lock_transfer_buffer=
  894.                 (uint8_t*(*) (void))GetProcAddress(p_sys->h_AtmoCtrl,"AtmoLockTransferBuffer");
  895.             if(!p_sys->pf_ctrl_atmo_lock_transfer_buffer)
  896.                 msg_Err( p_filter, "export AtmoLockTransferBuffer missing.");
  897.             p_sys->pf_ctrl_atmo_send_pixel_data =
  898.                 (void (*)(void))GetProcAddress(p_sys->h_AtmoCtrl,"AtmoSendPixelData");
  899.             if(!p_sys->pf_ctrl_atmo_send_pixel_data)
  900.                 msg_Err( p_filter, "export AtmoSendPixelData missing.");
  901.         } else {
  902.             /* the DLL is missing try internal filter ...*/
  903.             msg_Warn( p_filter, "AtmoCtrlLib.dll missing fallback to internal driver");
  904.             b_use_buildin_driver = true;
  905.         }
  906.     }
  907. #endif
  908.     if(b_use_buildin_driver == true) {
  909.         msg_Dbg( p_filter, "use buildin driver");
  910.         /*
  911.         now we have to read a lof of options from the config dialog
  912.         most important the serial device if not set ... we can skip
  913.         the rest and disable the filter...
  914.         */
  915.         char *psz_serialdev = var_CreateGetStringCommand( p_filter,
  916.                                                       CFG_PREFIX "serialdev" );
  917.         if(psz_serialdev && (strlen(psz_serialdev)>0)) {
  918.             msg_Dbg( p_filter, "use buildin driver on port %s",psz_serialdev);
  919.             p_sys->p_atmo_config = new CAtmoConfig();
  920.             p_sys->p_atmo_config->setSerialDevice(psz_serialdev);
  921.             p_sys->p_atmo_config->setLiveViewFilterMode(
  922.                 (AtmoFilterMode)var_CreateGetIntegerCommand( p_filter,
  923.                                                        CFG_PREFIX "filtermode")
  924.                 );
  925.             p_sys->p_atmo_config->setLiveViewFilter_PercentNew(
  926.                 var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "PercentNew")
  927.                 );
  928.             p_sys->p_atmo_config->setLiveViewFilter_MeanLength(
  929.                 var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "MeanLength")
  930.                 );
  931.             p_sys->p_atmo_config->setLiveViewFilter_MeanThreshold(
  932.                 var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "MeanThreshold")
  933.                 );
  934.             p_sys->p_atmo_config->setLiveView_EdgeWeighting(
  935.                 var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "EdgeWeightning")
  936.                 );
  937.             p_sys->p_atmo_config->setLiveView_BrightCorrect(
  938.                 var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "Brightness")
  939.                 );
  940.             p_sys->p_atmo_config->setLiveView_DarknessLimit(
  941.                 var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "DarknessLimit")
  942.                 );
  943.             p_sys->p_atmo_config->setLiveView_HueWinSize(
  944.                 var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "HueWinSize")
  945.                 );
  946.             p_sys->p_atmo_config->setLiveView_SatWinSize(
  947.                 var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "SatWinSize")
  948.                 );
  949.             /* currently not required inside vlc */
  950.             p_sys->p_atmo_config->setLiveView_WidescreenMode( 0 );
  951.             p_sys->p_atmo_config->setLiveView_FrameDelay(
  952.                 var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "FrameDelay")
  953.                 );
  954.             p_sys->p_atmo_config->setUseSoftwareWhiteAdj(
  955.                 var_CreateGetBoolCommand( p_filter, CFG_PREFIX "whiteadj")
  956.                 );
  957.             p_sys->p_atmo_config->setWhiteAdjustment_Red(
  958.                 var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "white-red")
  959.                 );
  960.             p_sys->p_atmo_config->setWhiteAdjustment_Green(
  961.                 var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "white-green")
  962.                 );
  963.             p_sys->p_atmo_config->setWhiteAdjustment_Blue(
  964.                 var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "white-blue")
  965.                 );
  966.             tChannelAssignment *p_channel_assignment =
  967.                                  p_sys->p_atmo_config->getChannelAssignment(0);
  968.             p_channel_assignment->mappings[0] = var_CreateGetIntegerCommand(
  969.                                              p_filter, CFG_PREFIX "channel_0");
  970.             p_channel_assignment->mappings[1] = var_CreateGetIntegerCommand(
  971.                                              p_filter, CFG_PREFIX "channel_1");
  972.             p_channel_assignment->mappings[2] = var_CreateGetIntegerCommand(
  973.                                              p_filter, CFG_PREFIX "channel_2");
  974.             p_channel_assignment->mappings[3] = var_CreateGetIntegerCommand(
  975.                                              p_filter, CFG_PREFIX "channel_3");
  976.             p_channel_assignment->mappings[4] = var_CreateGetIntegerCommand(
  977.                                              p_filter, CFG_PREFIX "channel_4");
  978.             for(int i=0;i<ATMO_NUM_CHANNELS;i++)
  979.                 msg_Dbg( p_filter, "map software channel %d to hardware channel %d",
  980.                 p_channel_assignment->mappings[i],
  981.                 i
  982.                 );
  983.             // gradient_zone_0
  984.             char psz_gradient_var_name[30];
  985.             char *psz_gradient_file;
  986.             for(int i=0;i<ATMO_NUM_CHANNELS;i++)
  987.             {
  988.                 sprintf(psz_gradient_var_name, CFG_PREFIX "gradient_zone_%d", i);
  989.                 psz_gradient_file = var_CreateGetStringCommand(
  990.                     p_filter,
  991.                     psz_gradient_var_name
  992.                     );
  993.                 if(psz_gradient_file && strlen(psz_gradient_file)>0)
  994.                 {
  995.                     msg_Dbg( p_filter, "loading gradientfile %s for "
  996.                                        "zone %d", psz_gradient_file, i);
  997.                     int i_res = p_sys->p_atmo_config->getZoneDefinition(i)->
  998.                                 LoadGradientFromBitmap(psz_gradient_file);
  999.                     if(i_res != ATMO_LOAD_GRADIENT_OK)
  1000.                     {
  1001.                         msg_Err( p_filter,"failed to load gradient '%s' with "
  1002.                                           "error %d",psz_gradient_file,i_res);
  1003.                     }
  1004.                 }
  1005.                 free( psz_gradient_file );
  1006.             }
  1007.             p_sys->p_atmo_dyndata = new CAtmoDynData((vlc_object_t *)p_filter,
  1008.                 p_sys->p_atmo_config
  1009.                 );
  1010.             msg_Dbg( p_filter, "buildin driver initialized");
  1011.             free(psz_serialdev);
  1012.         } else {
  1013.             msg_Err(p_filter,"no serial devicename set");
  1014.         }
  1015.     }
  1016.     switch( p_filter->fmt_in.video.i_chroma )
  1017.     {
  1018.     case VLC_FOURCC('I','4','2','0'):
  1019.     case VLC_FOURCC('I','Y','U','V'):
  1020.     case VLC_FOURCC('Y','V','1','2'):
  1021.     case VLC_FOURCC('Y','V','1','6'):
  1022.     case VLC_FOURCC('Y','V','U','9'):
  1023.         // simple enough? Dionoea?
  1024.         p_sys->pf_extract_mini_image = ExtractMiniImage_YUV;
  1025.         break;
  1026.     default:
  1027.         msg_Dbg( p_filter, "InitFilter-unsupported chroma: %4.4s",
  1028.                             (char *)&p_filter->fmt_in.video.i_chroma);
  1029.         p_sys->pf_extract_mini_image = NULL;
  1030.     }
  1031.     p_sys->i_crop_x_offset  = 0;
  1032.     p_sys->i_crop_y_offset  = 0;
  1033.     p_sys->i_crop_width     = p_filter->fmt_in.video.i_visible_width;
  1034.     p_sys->i_crop_height    = p_filter->fmt_in.video.i_visible_height;
  1035.     msg_Dbg( p_filter, "set default crop %d,%d %dx%d",p_sys->i_crop_x_offset,
  1036.         p_sys->i_crop_y_offset,
  1037.         p_sys->i_crop_width,
  1038.         p_sys->i_crop_height );
  1039. #if defined(__ATMO_DEBUG__)
  1040.     /* save debug images to a folder as Bitmap files ? */
  1041.     p_sys->b_saveframes  = var_CreateGetBoolCommand( p_filter,
  1042.         CFG_PREFIX "saveframes"
  1043.         );
  1044.     msg_Dbg(p_filter,"saveframes = %d", (int)p_sys->b_saveframes);
  1045.     /*
  1046.     read debug image folder from config
  1047.     */
  1048.     psz_path = var_CreateGetStringCommand( p_filter, CFG_PREFIX "framepath" );
  1049.     if(psz_path != NULL)
  1050.     {
  1051.         strcpy(p_sys->sz_framepath, psz_path);
  1052. #if defined( WIN32 )
  1053.         size_t i_strlen = strlen(p_sys->sz_framepath);
  1054.         if((i_strlen>0) && (p_sys->sz_framepath[i_strlen-1] != '\'))
  1055.         {
  1056.             p_sys->sz_framepath[i_strlen] = '\';
  1057.             p_sys->sz_framepath[i_strlen+1] = 0;
  1058.         }
  1059. #endif
  1060.         free(psz_path);
  1061.     }
  1062.     msg_Dbg(p_filter,"saveframesfolder %s",p_sys->sz_framepath);
  1063. #endif
  1064.     /*
  1065.        size of extracted image by default 64x48 (other imagesizes are
  1066.        currently ignored by AtmoWin)
  1067.     */
  1068.     p_sys->i_atmo_width  = var_CreateGetIntegerCommand( p_filter,
  1069.         CFG_PREFIX "width");
  1070.     p_sys->i_atmo_height = var_CreateGetIntegerCommand( p_filter,
  1071.         CFG_PREFIX "height");
  1072.     msg_Dbg(p_filter,"mini image size %d * %d pixels", p_sys->i_atmo_width,
  1073.         p_sys->i_atmo_height);
  1074.     /*
  1075.     because atmowin could also be used for lighten up the room - I think if you
  1076.     pause the video it would be useful to get a little bit more light into to
  1077.     your living room? - instead switching on a lamp?
  1078.     */
  1079.     p_sys->b_usepausecolor = var_CreateGetBoolCommand( p_filter,
  1080.         CFG_PREFIX "usepausecolor" );
  1081.     p_sys->ui_pausecolor_red = (uint8_t)var_CreateGetIntegerCommand( p_filter,
  1082.         CFG_PREFIX "pcolor-red");
  1083.     p_sys->ui_pausecolor_green = (uint8_t)var_CreateGetIntegerCommand( p_filter,
  1084.         CFG_PREFIX "pcolor-green");
  1085.     p_sys->ui_pausecolor_blue = (uint8_t)var_CreateGetIntegerCommand( p_filter,
  1086.         CFG_PREFIX "pcolor-blue");
  1087.     p_sys->i_fadesteps = var_CreateGetIntegerCommand( p_filter,
  1088.         CFG_PREFIX "fadesteps");
  1089.     if(p_sys->i_fadesteps < 1)
  1090.         p_sys->i_fadesteps = 1;
  1091.     msg_Dbg(p_filter,"use pause color %d, RGB: %d, %d, %d, Fadesteps: %d",
  1092.         (int)p_sys->b_usepausecolor,
  1093.         p_sys->ui_pausecolor_red,
  1094.         p_sys->ui_pausecolor_green,
  1095.         p_sys->ui_pausecolor_blue,
  1096.         p_sys->i_fadesteps);
  1097.     /*
  1098.     this color is use on shutdown of the filter - the define the
  1099.     final light after playback... may be used to dim up the light -
  1100.     how it happens in the cinema...
  1101.     */
  1102.     p_sys->ui_endcolor_red = (uint8_t)var_CreateGetIntegerCommand( p_filter,
  1103.         CFG_PREFIX "ecolor-red");
  1104.     p_sys->ui_endcolor_green = (uint8_t)var_CreateGetIntegerCommand( p_filter,
  1105.         CFG_PREFIX "ecolor-green");
  1106.     p_sys->ui_endcolor_blue = (uint8_t)var_CreateGetIntegerCommand( p_filter,
  1107.         CFG_PREFIX "ecolor-blue");
  1108.     p_sys->i_endfadesteps = var_CreateGetIntegerCommand( p_filter,
  1109.         CFG_PREFIX "efadesteps");
  1110.     if(p_sys->i_endfadesteps < 1)
  1111.         p_sys->i_endfadesteps = 1;
  1112.     msg_Dbg(p_filter,"use ende color RGB: %d, %d, %d, Fadesteps: %d",
  1113.         p_sys->ui_endcolor_red,
  1114.         p_sys->ui_endcolor_green,
  1115.         p_sys->ui_endcolor_blue,
  1116.         p_sys->i_endfadesteps);
  1117.     /* if the external DLL was loaded successfully call AtmoInitialize -
  1118.     (must be done for each thread where you wan't to use AtmoLight!
  1119.     */
  1120.     int i = AtmoInitialize(p_filter, false);
  1121. #if defined( WIN32 )
  1122.     if((i != 1) && !b_use_buildin_driver)
  1123.     {
  1124.         /* COM Server for AtmoLight not running ?
  1125.         if the exe path is configured try to start the "userspace" driver
  1126.         */
  1127.         psz_path = var_CreateGetStringCommand( p_filter,
  1128.                                                CFG_PREFIX "atmowinexe" );
  1129.         if(psz_path != NULL)
  1130.         {
  1131.             STARTUPINFO startupinfo;
  1132.             PROCESS_INFORMATION pinfo;
  1133.             memset(&startupinfo, 0, sizeof(STARTUPINFO));
  1134.             startupinfo.cb = sizeof(STARTUPINFO);
  1135.             if(CreateProcess(psz_path, NULL, NULL, NULL,
  1136.                 FALSE, 0, NULL, NULL, &startupinfo, &pinfo) == TRUE)
  1137.             {
  1138.                 msg_Dbg(p_filter,"launched AtmoWin from %s",psz_path);
  1139.                 WaitForInputIdle(pinfo.hProcess, 5000);
  1140.                 /*
  1141.                 retry to initialize the library COM ... functionality
  1142.                 after the server was launched
  1143.                 */
  1144.                 i = AtmoInitialize(p_filter, false);
  1145.             } else {
  1146.                 msg_Err(p_filter,"failed to launch AtmoWin from %s", psz_path);
  1147.             }
  1148.             free(psz_path);
  1149.         }
  1150.     }
  1151. #endif
  1152.     if(i == 1) /* Init Atmolight success... */
  1153.     {
  1154.         msg_Dbg( p_filter, "AtmoInitialize Ok!");
  1155.         /* Setup Transferbuffers for 64 x 48 , RGB with 32bit Per Pixel */
  1156.         AtmoCreateTransferBuffers(p_filter, BI_RGB, 4,
  1157.             p_sys->i_atmo_width,
  1158.             p_sys->i_atmo_height
  1159.             );
  1160.         /* say the userspace driver that a live mode should be activated
  1161.         the functions returns the old mode for later restore!
  1162.         */
  1163.         p_sys->i_AtmoOldEffect = AtmoSwitchEffect(p_filter, emLivePicture);
  1164.         /*
  1165.         live view can have two differnt source the AtmoWinA
  1166.         internal GDI Screencapture and the external one - which we
  1167.         need here...
  1168.         */
  1169.         AtmoSetLiveSource(p_filter, lvsExternal);
  1170.         /* enable other parts only if everything is fine */
  1171.         p_sys->b_enabled = true;
  1172.     }
  1173. }
  1174. /*****************************************************************************
  1175. * CreateFilter: allocates AtmoLight video thread output method
  1176. *****************************************************************************
  1177. * This function allocates and initializes a AtmoLight vout method.
  1178. *****************************************************************************/
  1179. static int CreateFilter( vlc_object_t *p_this )
  1180. {
  1181.     filter_t *p_filter = (filter_t *)p_this;
  1182.     filter_sys_t *p_sys;
  1183.     /* Allocate structure */
  1184.     p_sys = (filter_sys_t *)malloc( sizeof( filter_sys_t ) );
  1185.     p_filter->p_sys = p_sys;
  1186.     if( p_filter->p_sys == NULL )
  1187.         return VLC_ENOMEM;
  1188.     /* set all entries to zero */
  1189.     memset(p_sys, 0, sizeof( filter_sys_t ));
  1190.     /* further Setup Function pointers for videolan for calling my filter */
  1191.     p_filter->pf_video_filter = Filter;
  1192.     config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
  1193.                        p_filter->p_cfg );
  1194.     AddStateVariableCallback(p_filter);
  1195.     AddCropVariableCallback(p_filter);
  1196.     AddAtmoSettingsVariablesCallbacks(p_filter);
  1197.     Atmo_SetupParameters(p_filter);
  1198.     return VLC_SUCCESS;
  1199. }
  1200. /*****************************************************************************
  1201. * DestroyFilter: destroy AtmoLight video thread output method
  1202. *****************************************************************************
  1203. * Terminate an output method created by CreateFilter
  1204. *****************************************************************************/
  1205. static void DestroyFilter( vlc_object_t *p_this )
  1206. {
  1207.     filter_t *p_filter = (filter_t *)p_this;
  1208.     filter_sys_t *p_sys =  p_filter->p_sys;
  1209.     DelStateVariableCallback(p_filter);
  1210.     DelCropVariableCallback(p_filter);
  1211.     DelAtmoSettingsVariablesCallbacks(p_filter);
  1212.     Atmo_Shutdown(p_filter);
  1213. #if defined( WIN32 )
  1214.     if(p_sys->h_AtmoCtrl != NULL)
  1215.     {
  1216.         FreeLibrary(p_sys->h_AtmoCtrl);
  1217.     }
  1218. #endif
  1219.     delete p_sys->p_atmo_dyndata;
  1220.     delete p_sys->p_atmo_config;
  1221.     vlc_mutex_destroy( &p_sys->filter_lock );
  1222.     free( p_sys );
  1223. }
  1224. /*
  1225. function stolen from some other videolan source filter ;-)
  1226. for the moment RGB is OK... but better would be a direct transformation
  1227. from YUV --> HSV
  1228. */
  1229. static inline void yuv_to_rgb( uint8_t *r, uint8_t *g, uint8_t *b,
  1230.                               uint8_t y1, uint8_t u1, uint8_t v1 )
  1231. {
  1232.     /* macros used for YUV pixel conversions */
  1233. #   define SCALEBITS 10
  1234. #   define ONE_HALF  (1 << (SCALEBITS - 1))
  1235. #   define FIX(x)    ((int) ((x) * (1<<SCALEBITS) + 0.5))
  1236. #   define CLAMP( x ) (((x) > 255) ? 255 : ((x) < 0) ? 0 : (x));
  1237.     int y, cb, cr, r_add, g_add, b_add;
  1238.     cb = u1 - 128;
  1239.     cr = v1 - 128;
  1240.     r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;
  1241.     g_add = - FIX(0.34414*255.0/224.0) * cb
  1242.         - FIX(0.71414*255.0/224.0) * cr + ONE_HALF;
  1243.     b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;
  1244.     y = (y1 - 16) * FIX(255.0/219.0);
  1245.     *r = CLAMP((y + r_add) >> SCALEBITS);
  1246.     *g = CLAMP((y + g_add) >> SCALEBITS);
  1247.     *b = CLAMP((y + b_add) >> SCALEBITS);
  1248. }
  1249. /******************************************************************************
  1250. * ExtractMiniImage_YUV: extract a small image from the picture as 24-bit RGB
  1251. *******************************************************************************
  1252. * p_sys is a pointer to
  1253. * p_inpic is the source frame
  1254. * p_transfer_dest is the target buffer for the picture must be big enough!
  1255. * (in win32 enviroment this buffer comes from the external DLL where it is
  1256. * create as "variant array" and returned through the AtmoLockTransferbuffer
  1257. */
  1258. static void ExtractMiniImage_YUV(filter_sys_t *p_sys,
  1259.                                  picture_t *p_inpic,
  1260.                                  uint8_t *p_transfer_dest)
  1261. {
  1262.     int i_col;
  1263.     int i_row;
  1264.     uint8_t *p_src_y;
  1265.     uint8_t *p_src_u;
  1266.     uint8_t *p_src_v;
  1267.     uint8_t *p_rgb_dst_line_red;
  1268.     uint8_t *p_rgb_dst_line_green;
  1269.     uint8_t *p_rgb_dst_line_blue;
  1270.     int i_xpos_y;
  1271.     int i_xpos_u;
  1272.     int i_xpos_v;
  1273.     /* calcute Pointers for Storage of B G R (A) */
  1274.     p_rgb_dst_line_blue      = p_transfer_dest;
  1275.     p_rgb_dst_line_green     = p_transfer_dest + 1;
  1276.     p_rgb_dst_line_red       = p_transfer_dest + 2 ;
  1277.     int i_row_count = p_sys->i_atmo_height + 1;
  1278.     int i_col_count = p_sys->i_atmo_width + 1;
  1279.     int i_y_row,i_u_row,i_v_row,i_pixel_row;
  1280.     int i_pixel_col;
  1281.     /*  these two ugly loops extract the small image - goes it faster? how?
  1282.     the loops are so designed that there is a small border around the extracted
  1283.     image so we wont get column and row - zero from the frame, and not the most
  1284.     right and bottom pixels --- which may be clipped on computers useing TV out
  1285.     - through overscan!
  1286.     TODO: try to find out if the output is clipped through VLC - and try here
  1287.     to ingore the clipped away area for a better result!
  1288.     TODO: performance improvement in InitFilter percalculated the offsets of
  1289.     the lines inside the planes so I can save (i_row_count * 3) 2xMUL and
  1290.     one time DIV the same could be done for the inner loop I think...
  1291.     */
  1292.     for(i_row = 1; i_row < i_row_count; i_row++)
  1293.     {
  1294.         // calcute the current Lines in the source planes for this outputrow
  1295.         /*  Adresscalcuation  pointer to plane  Length of one pixelrow in bytes
  1296.         calculate row now number
  1297.         */
  1298.         /*
  1299.            p_inpic->format? transform Pixel row into row of plane...
  1300.            how? simple? fast? good?
  1301.         */
  1302.         /* compute the source pixel row and respect the active cropping */
  1303.         i_pixel_row = (i_row * p_sys->i_crop_height) / i_row_count
  1304.             + p_sys->i_crop_y_offset;
  1305.         /*
  1306.         trans for these Pixel row into the row of each plane ..
  1307.         because planesize can differ from image size
  1308.         */
  1309.         i_y_row = (i_pixel_row * p_inpic->p[Y_PLANE].i_visible_lines) /
  1310.             p_inpic->format.i_visible_height;
  1311.         i_u_row = (i_pixel_row * p_inpic->p[U_PLANE].i_visible_lines) /
  1312.             p_inpic->format.i_visible_height;
  1313.         i_v_row = (i_pixel_row * p_inpic->p[V_PLANE].i_visible_lines) /
  1314.             p_inpic->format.i_visible_height;
  1315.         /* calculate  the pointers to the pixeldata for this row
  1316.            in each plane
  1317.         */
  1318.         p_src_y = p_inpic->p[Y_PLANE].p_pixels +
  1319.             p_inpic->p[Y_PLANE].i_pitch * i_y_row;
  1320.         p_src_u = p_inpic->p[U_PLANE].p_pixels +
  1321.             p_inpic->p[U_PLANE].i_pitch * i_u_row;
  1322.         p_src_v = p_inpic->p[V_PLANE].p_pixels +
  1323.             p_inpic->p[V_PLANE].i_pitch * i_v_row;
  1324.         for(i_col = 1; i_col < i_col_count; i_col++)
  1325.         {
  1326.             i_pixel_col = (i_col * p_sys->i_crop_width) / i_col_count +
  1327.                 p_sys->i_crop_x_offset;
  1328.             /*
  1329.             trans for these Pixel row into the row of each plane ..
  1330.             because planesize can differ from image size
  1331.             */
  1332.             i_xpos_y = (i_pixel_col * p_inpic->p[Y_PLANE].i_visible_pitch) /
  1333.                 p_inpic->format.i_visible_width;
  1334.             i_xpos_u = (i_pixel_col * p_inpic->p[U_PLANE].i_visible_pitch) /
  1335.                 p_inpic->format.i_visible_width;
  1336.             i_xpos_v = (i_pixel_col * p_inpic->p[V_PLANE].i_visible_pitch) /
  1337.                 p_inpic->format.i_visible_width;
  1338.             yuv_to_rgb(p_rgb_dst_line_red,
  1339.                 p_rgb_dst_line_green,
  1340.                 p_rgb_dst_line_blue,
  1341.                 p_src_y[i_xpos_y],
  1342.                 p_src_u[i_xpos_u],
  1343.                 p_src_v[i_xpos_v]);
  1344.             /* +4 because output image should be RGB32 with dword alignment! */
  1345.             p_rgb_dst_line_red   += 4;
  1346.             p_rgb_dst_line_green += 4;
  1347.             p_rgb_dst_line_blue  += 4;
  1348.         }
  1349.     }
  1350. }
  1351. /******************************************************************************
  1352. * SaveBitmap: Saves the content of a transferbuffer as Bitmap to disk
  1353. *******************************************************************************
  1354. * just for debugging
  1355. * p_sys -> configuration if Atmo from there the function will get height and
  1356. *          width
  1357. * p_pixels -> should be the dword aligned BGR(A) image data
  1358. * psz_filename -> filename where to store
  1359. */
  1360. #if defined(__ATMO_DEBUG__)
  1361. void SaveBitmap(filter_sys_t *p_sys, uint8_t *p_pixels, char *psz_filename)
  1362. {
  1363.     /* for debug out only used*/
  1364.     BITMAPINFO bmp_info;
  1365.     BITMAPFILEHEADER  bmp_fileheader;
  1366.     FILE *fp_bitmap;
  1367.     memset(&bmp_info, 0, sizeof(BITMAPINFO));
  1368.     bmp_info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  1369.     bmp_info.bmiHeader.biSizeImage   = p_sys->i_atmo_height *
  1370.                                        p_sys->i_atmo_width * 4;
  1371.     bmp_info.bmiHeader.biCompression = BI_RGB;
  1372.     bmp_info.bmiHeader.biWidth        = p_sys->i_atmo_width;
  1373.     bmp_info.bmiHeader.biHeight       = -p_sys->i_atmo_height;
  1374.     bmp_info.bmiHeader.biBitCount     = 32;
  1375.     bmp_info.bmiHeader.biPlanes       = 1;
  1376.     bmp_fileheader.bfReserved1 = 0;
  1377.     bmp_fileheader.bfReserved2 = 0;
  1378.     bmp_fileheader.bfSize = sizeof(BITMAPFILEHEADER) +
  1379.                             sizeof(BITMAPINFOHEADER) +
  1380.                             bmp_info.bmiHeader.biSizeImage;
  1381.     bmp_fileheader.bfType = VLC_TWOCC('M','B');
  1382.     bmp_fileheader.bfOffBits = sizeof(BITMAPFILEHEADER) +
  1383.                                sizeof(BITMAPINFOHEADER);
  1384.     fp_bitmap = fopen(psz_filename,"wb");
  1385.     if( fp_bitmap != NULL)
  1386.     {
  1387.         fwrite(&bmp_fileheader, sizeof(BITMAPFILEHEADER), 1, fp_bitmap);
  1388.         fwrite(&bmp_info.bmiHeader, sizeof(BITMAPINFOHEADER), 1, fp_bitmap);
  1389.         fwrite(p_pixels, bmp_info.bmiHeader.biSizeImage, 1, fp_bitmap);
  1390.         fclose(fp_bitmap);
  1391.     }
  1392. }
  1393. #endif
  1394. /****************************************************************************
  1395. * CreateMiniImage: extracts a 64x48 pixel image from the frame
  1396. * (there is a small border arround thats why the loops starts with one
  1397. * instead zero) without any interpolation
  1398. *****************************************************************************/
  1399. static void CreateMiniImage( filter_t *p_filter, picture_t *p_inpic)
  1400. {
  1401.     filter_sys_t *p_sys = p_filter->p_sys;
  1402.     /*
  1403.     pointer to RGB Buffer created in external libary as safe array which
  1404.     is locked inside AtmoLockTransferBuffer
  1405.     */
  1406.     uint8_t *p_transfer = NULL;
  1407. #if defined( __ATMO_DEBUG__ )
  1408.     /* for debug out only used*/
  1409.     char sz_filename[MAX_PATH];
  1410. #endif
  1411.     /*
  1412.     Lock the before created VarArray (AtmoCreateTransferBuffers)
  1413.     inside my wrapper library and give me a pointer to the buffer!
  1414.     below linux a global buffer may be used and protected with a mutex?
  1415.     */
  1416.     p_transfer = AtmoLockTransferBuffer(p_filter);
  1417.     if(p_transfer == NULL)
  1418.     {
  1419.         msg_Err( p_filter, "AtmoLight no transferbuffer available. "
  1420.                            "AtmoLight will be disabled!");
  1421.         p_sys->b_enabled = false;
  1422.         return;
  1423.     }
  1424.     /*
  1425.     do the call via pointer to function instead of having a
  1426.     case structure here
  1427.     */
  1428.     p_sys->pf_extract_mini_image(p_sys, p_inpic, p_transfer);
  1429. #if defined( __ATMO_DEBUG__ )
  1430.     /*
  1431.     if debugging enabled save every 128th image to disk
  1432.     */
  1433.     if((p_sys->b_saveframes == true) && (p_sys->sz_framepath[0] != 0 ))
  1434.     {
  1435.         if((p_sys->i_framecounter & 127) == 0)
  1436.         {
  1437.             sprintf(sz_filename,"%satmo_dbg_%06d.bmp",p_sys->sz_framepath,
  1438.                 p_sys->i_framecounter);
  1439.             msg_Dbg(p_filter, "SaveFrame %s",sz_filename);
  1440.             SaveBitmap(p_sys, p_transfer, sz_filename);
  1441.         }
  1442.         p_sys->i_framecounter++;
  1443.     }
  1444. #endif
  1445.     /* show the colors on the wall */
  1446.     AtmoSendPixelData(p_filter);
  1447. }
  1448. /*****************************************************************************
  1449. * Filter: calls the extract method and forwards the incomming picture 1:1
  1450. *****************************************************************************
  1451. *
  1452. *****************************************************************************/
  1453. static picture_t * Filter( filter_t *p_filter, picture_t *p_pic )
  1454. {
  1455.     filter_sys_t *p_sys = p_filter->p_sys;
  1456.     if( !p_pic ) return NULL;
  1457.     if((p_sys->b_enabled == true) &&
  1458.         (p_sys->pf_extract_mini_image != NULL) &&
  1459.         (p_sys->b_pause_live == false))
  1460.     {
  1461.         CreateMiniImage(p_filter, p_pic);
  1462.     }
  1463.     return p_pic;
  1464. }
  1465. /*****************************************************************************
  1466. * FadeToColorThread: Threadmethod which changes slowly the color
  1467. * to a target color defined in p_fadethread struct
  1468. * use for: Fade to Pause Color,  and Fade to End Color
  1469. *****************************************************************************/
  1470. static void *FadeToColorThread(vlc_object_t *obj)
  1471. {
  1472.     fadethread_t *p_fadethread = (fadethread_t *)obj;
  1473.     filter_sys_t *p_sys = (filter_sys_t *)p_fadethread->p_filter->p_sys;
  1474.     int i_steps_done = 0;
  1475.     int i_index;
  1476.     int i_pause_red;
  1477.     int i_pause_green;
  1478.     int i_pause_blue;
  1479.     int i_src_red;
  1480.     int i_src_green;
  1481.     int i_src_blue;
  1482.     uint8_t *p_source = NULL;
  1483.     int canc = vlc_savecancel ();
  1484.     /* initialize AtmoWin for this thread! */
  1485.     AtmoInitialize(p_fadethread->p_filter , true);
  1486.     uint8_t *p_transfer = AtmoLockTransferBuffer( p_fadethread->p_filter );
  1487.     if(p_transfer != NULL) {
  1488.         /* safe colors as "32bit" Integers to avoid overflows*/
  1489.         i_pause_red   = p_fadethread->ui_red;
  1490.         i_pause_blue  = p_fadethread->ui_blue;
  1491.         i_pause_green = p_fadethread->ui_green;
  1492.         /*
  1493.         allocate a temporary buffer for the last send
  1494.         image size less then 15kb
  1495.         */
  1496.         int i_size = 4 * p_sys->i_atmo_width * p_sys->i_atmo_height;
  1497.         p_source = (uint8_t *)malloc( i_size );
  1498.         if(p_source != NULL)
  1499.         {
  1500.             /*
  1501.             get a copy of the last transfered image as orign for the
  1502.             fading steps...
  1503.             */
  1504.             memcpy(p_source, p_transfer, i_size);
  1505.             /* send the same pixel data again... to unlock the buffer! */
  1506.             AtmoSendPixelData( p_fadethread->p_filter );
  1507.             while( (vlc_object_alive (p_fadethread)) &&
  1508.                 (i_steps_done < p_fadethread->i_steps))
  1509.             {
  1510.                 p_transfer = AtmoLockTransferBuffer( p_fadethread->p_filter );
  1511.                 if(!p_transfer) break; /* should not happen if it worked
  1512.                                        one time in the code above! */
  1513.                 i_steps_done++;
  1514.                 /*
  1515.                 move all pixels in the mini image (64x48) one step closer to
  1516.                 the desired color these loop takes the most time of this
  1517.                 thread improvements wellcome!
  1518.                 */
  1519.                 for(i_index = 0;
  1520.                     (i_index < i_size) && (vlc_object_alive (p_fadethread));
  1521.                     i_index+=4)
  1522.                 {
  1523.                     i_src_blue  = p_source[i_index+0];
  1524.                     i_src_green = p_source[i_index+1];
  1525.                     i_src_red   = p_source[i_index+2];
  1526.                     p_transfer[i_index+0] = (uint8_t) (((
  1527.                         (i_pause_blue  - i_src_blue)
  1528.                         * i_steps_done)/p_fadethread->i_steps)
  1529.                         + i_src_blue);
  1530.                     p_transfer[i_index+1] = (uint8_t) (((
  1531.                         (i_pause_green - i_src_green)
  1532.                         * i_steps_done)/p_fadethread->i_steps)
  1533.                         + i_src_green);
  1534.                     p_transfer[i_index+2] = (uint8_t) (((
  1535.                         (i_pause_red   - i_src_red)
  1536.                         * i_steps_done)/p_fadethread->i_steps)
  1537.                         + i_src_red);
  1538.                 }
  1539.                 /* send image to lightcontroller */
  1540.                 AtmoSendPixelData( p_fadethread->p_filter );
  1541.                 /* is there something like and interruptable sleep inside
  1542.                 the VLC libaries? inside native win32 I would use an Event
  1543.                 (CreateEvent) and here an WaitForSingleObject?
  1544.                 */
  1545.                 if(!vlc_object_alive (p_fadethread)) break;
  1546.                 msleep(10000);
  1547.                 if(!vlc_object_alive (p_fadethread)) break;
  1548.                 msleep(10000);
  1549.                 if(!vlc_object_alive (p_fadethread)) break;
  1550.                 msleep(10000);
  1551.                 if(!vlc_object_alive (p_fadethread)) break;
  1552.                 msleep(10000);
  1553.             }
  1554.             free(p_source);
  1555.         } else {
  1556.             /* in failure of malloc also unlock buffer  */
  1557.             AtmoSendPixelData(p_fadethread->p_filter);
  1558.         }
  1559.     }
  1560.     /* call indirect to OleUnitialize() for this thread */
  1561.     AtmoFinalize(p_fadethread->p_filter, 0);
  1562.     vlc_restorecancel (canc);
  1563.     return NULL;
  1564. }
  1565. /*****************************************************************************
  1566. * CheckAndStopFadeThread: if there is a fadethread structure left, or running.
  1567. ******************************************************************************
  1568. * this function will stop the thread ... and waits for its termination
  1569. * before removeing the objects from vout_sys_t ...
  1570. ******************************************************************************/
  1571. static void CheckAndStopFadeThread(filter_t *p_filter)
  1572. {
  1573.     filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
  1574.     vlc_mutex_lock( &p_sys->filter_lock );
  1575.     if(p_sys->p_fadethread != NULL)
  1576.     {
  1577.         msg_Dbg(p_filter, "kill still running fadeing thread...");
  1578.         p_sys->p_fadethread->b_die = true;
  1579.         vlc_thread_join(p_sys->p_fadethread);
  1580.         vlc_object_release(p_sys->p_fadethread);
  1581.         p_sys->p_fadethread = NULL;
  1582.     }
  1583.     vlc_mutex_unlock( &p_sys->filter_lock );
  1584. }
  1585. /*****************************************************************************
  1586. * StateCallback: Callback for the inputs variable "State" to get notified
  1587. * about Pause and Continue Playback events.
  1588. *****************************************************************************/
  1589. static int StateCallback( vlc_object_t *p_this, char const *psz_cmd,
  1590.                          vlc_value_t oldval, vlc_value_t newval,
  1591.                          void *p_data )
  1592. {
  1593.     filter_t *p_filter = (filter_t *)p_data;
  1594.     filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
  1595.     if((p_sys->b_usepausecolor == true) && (p_sys->b_enabled == true))
  1596.     {
  1597.         msg_Dbg(p_filter, "state change from: %d to %d", oldval.i_int,
  1598.             newval.i_int);
  1599.         if((newval.i_int == PAUSE_S) && (oldval.i_int == PLAYING_S))
  1600.         {
  1601.             /* tell the other thread to stop sending images to light
  1602.                controller */
  1603.             p_sys->b_pause_live = true;
  1604.             // ggf. alten Thread abräumen should not happen....
  1605.             CheckAndStopFadeThread(p_filter);
  1606.             // perpare spawn fadeing thread
  1607.             vlc_mutex_lock( &p_sys->filter_lock );
  1608.             /*
  1609.             launch only a new thread if there is none active!
  1610.             or waiting for cleanup
  1611.             */
  1612.             if(p_sys->p_fadethread == NULL)
  1613.             {
  1614.                 p_sys->p_fadethread = (fadethread_t *)vlc_object_create(
  1615.                      p_filter,
  1616.                      sizeof(fadethread_t) );
  1617.                 p_sys->p_fadethread->p_filter = p_filter;
  1618.                 p_sys->p_fadethread->ui_red   = p_sys->ui_pausecolor_red;
  1619.                 p_sys->p_fadethread->ui_green = p_sys->ui_pausecolor_green;
  1620.                 p_sys->p_fadethread->ui_blue  = p_sys->ui_pausecolor_blue;
  1621.                 p_sys->p_fadethread->i_steps  = p_sys->i_fadesteps;
  1622.                 if( vlc_thread_create( p_sys->p_fadethread,
  1623.                     "AtmoLight fadeing",
  1624.                     FadeToColorThread,
  1625.                     VLC_THREAD_PRIORITY_LOW ) )
  1626.                 {
  1627.                     msg_Err( p_filter, "cannot create FadeToColorThread" );
  1628.                     vlc_object_release( p_sys->p_fadethread );
  1629.                     p_sys->p_fadethread = NULL;
  1630.                 }
  1631.             }
  1632.             vlc_mutex_unlock( &p_sys->filter_lock );
  1633.         }
  1634.         if((newval.i_int == PLAYING_S) && (oldval.i_int == PAUSE_S))
  1635.         {
  1636.             /* playback continues check thread state */
  1637.             CheckAndStopFadeThread(p_filter);
  1638.             /* reactivate the Render function... to do its normal work */
  1639.             p_sys->b_pause_live = false;
  1640.         }
  1641.     }
  1642.     return VLC_SUCCESS;
  1643. }
  1644. /*****************************************************************************
  1645. * AddPlaylistInputThreadStateCallback: Setup call back on "State" Variable
  1646. *****************************************************************************
  1647. * Add Callback function to the "state" variable of the input thread..
  1648. * first find the PlayList and get the input thread from there to attach
  1649. * my callback? is vlc_object_find the right way for this??
  1650. *****************************************************************************/
  1651. static void AddStateVariableCallback(filter_t *p_filter)
  1652. {
  1653.     playlist_t *p_playlist = pl_Hold( p_filter );
  1654.     input_thread_t *p_input = playlist_CurrentInput( p_playlist );
  1655.     if(p_input)
  1656.     {
  1657.         var_AddCallback( p_input, "state", StateCallback, p_filter );
  1658.         vlc_object_release( p_input );
  1659.     }
  1660.     pl_Release( p_filter );
  1661. }
  1662. /*****************************************************************************
  1663. * DelPlaylistInputThreadStateCallback: Remove call back on "State" Variable
  1664. *****************************************************************************
  1665. * Delete the callback function to the "state" variable of the input thread...
  1666. * first find the PlayList and get the input thread from there to attach
  1667. * my callback? is vlc_object_find the right way for this??
  1668. *****************************************************************************/
  1669. static void DelStateVariableCallback( filter_t *p_filter )
  1670. {
  1671.     playlist_t *p_playlist = pl_Hold( p_filter );
  1672.     input_thread_t *p_input = playlist_CurrentInput( p_playlist );
  1673.     if(p_input)
  1674.     {
  1675.         var_DelCallback( p_input, "state", StateCallback, p_filter );
  1676.         vlc_object_release( p_input );
  1677.     }
  1678.     pl_Release( p_filter );
  1679. }
  1680. static int CropCallback(vlc_object_t *p_this, char const *psz_cmd,
  1681.                         vlc_value_t oldval, vlc_value_t newval,
  1682.                         void *p_data)
  1683. {
  1684.     vout_thread_t *p_vout = (vout_thread_t *)p_this;
  1685.     filter_t *p_filter = (filter_t *)p_data;
  1686.     filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
  1687.     /*
  1688.     //if the handler is attache to crop variable directly!
  1689.     int i_visible_width, i_visible_height, i_x_offset, i_y_offset;
  1690.     atmo_parse_crop(newval.psz_string, p_vout->fmt_render,
  1691.     p_vout->fmt_render,
  1692.     i_visible_width, i_visible_height,
  1693.     i_x_offset, i_y_offset);
  1694.     p_sys->i_crop_x_offset  = i_x_offset;
  1695.     p_sys->i_crop_y_offset  = i_y_offset;
  1696.     p_sys->i_crop_width     = i_visible_width;
  1697.     p_sys->i_crop_height    = i_visible_height;
  1698.     */
  1699.     p_sys->i_crop_x_offset  = p_vout->fmt_in.i_x_offset;
  1700.     p_sys->i_crop_y_offset  = p_vout->fmt_in.i_y_offset;
  1701.     p_sys->i_crop_width     = p_vout->fmt_in.i_visible_width;
  1702.     p_sys->i_crop_height    = p_vout->fmt_in.i_visible_height;
  1703.     msg_Dbg(p_filter, "cropping picture %ix%i to %i,%i,%ix%i",
  1704.         p_vout->fmt_in.i_width,
  1705.         p_vout->fmt_in.i_height,
  1706.         p_sys->i_crop_x_offset,
  1707.         p_sys->i_crop_y_offset,
  1708.         p_sys->i_crop_width,
  1709.         p_sys->i_crop_height
  1710.         );
  1711.     return VLC_SUCCESS;
  1712. }
  1713. static void AddCropVariableCallback( filter_t *p_filter)
  1714. {
  1715.     vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find( p_filter,
  1716.         VLC_OBJECT_VOUT,
  1717.         FIND_ANYWHERE );
  1718.     if( p_vout )
  1719.     {
  1720.         var_AddCallback( p_vout, "crop-update", CropCallback, p_filter );
  1721.         vlc_object_release( p_vout );
  1722.     }
  1723. }
  1724. static void DelCropVariableCallback( filter_t *p_filter)
  1725. {
  1726.     vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find( p_filter,
  1727.         VLC_OBJECT_VOUT,
  1728.         FIND_ANYWHERE );
  1729.     if( p_vout )
  1730.     {
  1731.         var_DelCallback( p_vout, "crop-update", CropCallback, p_filter );
  1732.         vlc_object_release( p_vout );
  1733.     }
  1734. }
  1735. /****************************************************************************
  1736. * StateCallback: Callback for the inputs variable "State" to get notified
  1737. * about Pause and Continue Playback events.
  1738. *****************************************************************************/
  1739. static int AtmoSettingsCallback( vlc_object_t *p_this, char const *psz_var,
  1740.                                  vlc_value_t oldval, vlc_value_t newval,
  1741.                                  void *p_data )
  1742. {
  1743.     filter_t *p_filter = (filter_t *)p_data;
  1744.     filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
  1745.     CAtmoConfig *p_atmo_config = p_sys->p_atmo_config;
  1746.     if(p_atmo_config)
  1747.     {
  1748.        msg_Dbg(p_filter, "apply AtmoSettingsCallback %s (int: %d -> %d)",
  1749.              psz_var,
  1750.              oldval.i_int,
  1751.              newval.i_int
  1752.        );
  1753.         if( !strcmp( psz_var, CFG_PREFIX "filtermode" ))
  1754.             p_atmo_config->setLiveViewFilterMode( (AtmoFilterMode)newval.i_int);
  1755.         else if( !strcmp( psz_var, CFG_PREFIX "PercentNew" ))
  1756.                  p_atmo_config->setLiveViewFilter_PercentNew( newval.i_int );
  1757.         else if( !strcmp( psz_var, CFG_PREFIX "MeanLength" ))
  1758.                  p_atmo_config->setLiveViewFilter_MeanLength( newval.i_int );
  1759.         else if( !strcmp( psz_var, CFG_PREFIX "MeanThreshold" ))
  1760.                  p_atmo_config->setLiveViewFilter_MeanThreshold( newval.i_int );
  1761.         else if( !strcmp( psz_var, CFG_PREFIX "EdgeWeightning" ))
  1762.                  p_atmo_config->setLiveView_EdgeWeighting( newval.i_int );
  1763.         else if( !strcmp( psz_var, CFG_PREFIX "Brightness" ))
  1764.                  p_atmo_config->setLiveView_BrightCorrect( newval.i_int );
  1765.         else if( !strcmp( psz_var, CFG_PREFIX "DarknessLimit" ))
  1766.                  p_atmo_config->setLiveView_DarknessLimit( newval.i_int );
  1767.         else if( !strcmp( psz_var, CFG_PREFIX "HueWinSize" ))
  1768.                  p_atmo_config->setLiveView_HueWinSize( newval.i_int );
  1769.         else if( !strcmp( psz_var, CFG_PREFIX "SatWinSize" ))
  1770.                  p_atmo_config->setLiveView_SatWinSize( newval.i_int );
  1771.         else if( !strcmp( psz_var, CFG_PREFIX "FrameDelay" ))
  1772.                  p_atmo_config->setLiveView_FrameDelay( newval.i_int );
  1773.         else if( !strcmp( psz_var, CFG_PREFIX "whiteadj" ))
  1774.                  p_atmo_config->setUseSoftwareWhiteAdj( newval.b_bool );
  1775.         else if( !strcmp( psz_var, CFG_PREFIX "white-red" ))
  1776.                  p_atmo_config->setWhiteAdjustment_Red( newval.i_int );
  1777.         else if( !strcmp( psz_var, CFG_PREFIX "white-green" ))
  1778.                  p_atmo_config->setWhiteAdjustment_Green( newval.i_int );
  1779.         else if( !strcmp( psz_var, CFG_PREFIX "white-blue" ))
  1780.                  p_atmo_config->setWhiteAdjustment_Blue( newval.i_int );
  1781.     }
  1782.     return VLC_SUCCESS;
  1783. }
  1784. static void AddAtmoSettingsVariablesCallbacks(filter_t *p_filter)
  1785. {
  1786.    var_AddCallback( p_filter, CFG_PREFIX "filtermode",
  1787.                     AtmoSettingsCallback, p_filter );
  1788.    var_AddCallback( p_filter, CFG_PREFIX "PercentNew",
  1789.                     AtmoSettingsCallback, p_filter );
  1790.    var_AddCallback( p_filter, CFG_PREFIX "MeanLength",
  1791.                     AtmoSettingsCallback, p_filter );
  1792.    var_AddCallback( p_filter, CFG_PREFIX "MeanThreshold",
  1793.                     AtmoSettingsCallback, p_filter );
  1794.    var_AddCallback( p_filter, CFG_PREFIX "EdgeWeightning",
  1795.                     AtmoSettingsCallback, p_filter );
  1796.    var_AddCallback( p_filter, CFG_PREFIX "Brightness",
  1797.                     AtmoSettingsCallback, p_filter );
  1798.    var_AddCallback( p_filter, CFG_PREFIX "DarknessLimit",
  1799.                     AtmoSettingsCallback, p_filter );
  1800.    var_AddCallback( p_filter, CFG_PREFIX "HueWinSize",
  1801.                     AtmoSettingsCallback, p_filter );
  1802.    var_AddCallback( p_filter, CFG_PREFIX "SatWinSize",
  1803.                     AtmoSettingsCallback, p_filter );
  1804.    var_AddCallback( p_filter, CFG_PREFIX "FrameDelay",
  1805.                     AtmoSettingsCallback, p_filter );
  1806.    var_AddCallback( p_filter, CFG_PREFIX "whiteadj",
  1807.                     AtmoSettingsCallback, p_filter );
  1808.    var_AddCallback( p_filter, CFG_PREFIX "white-red",
  1809.                     AtmoSettingsCallback, p_filter );
  1810.    var_AddCallback( p_filter, CFG_PREFIX "white-green",
  1811.                     AtmoSettingsCallback, p_filter );
  1812.    var_AddCallback( p_filter, CFG_PREFIX "white-blue",
  1813.                     AtmoSettingsCallback, p_filter );
  1814. }
  1815. static void DelAtmoSettingsVariablesCallbacks( filter_t *p_filter )
  1816. {
  1817.    var_DelCallback( p_filter, CFG_PREFIX "filtermode",
  1818.                     AtmoSettingsCallback, p_filter );
  1819.    var_DelCallback( p_filter, CFG_PREFIX "PercentNew",
  1820.                     AtmoSettingsCallback, p_filter );
  1821.    var_DelCallback( p_filter, CFG_PREFIX "MeanLength",
  1822.                     AtmoSettingsCallback, p_filter );
  1823.    var_DelCallback( p_filter, CFG_PREFIX "MeanThreshold",
  1824.                     AtmoSettingsCallback, p_filter );
  1825.    var_DelCallback( p_filter, CFG_PREFIX "EdgeWeightning",
  1826.                     AtmoSettingsCallback, p_filter );
  1827.    var_DelCallback( p_filter, CFG_PREFIX "Brightness",
  1828.                     AtmoSettingsCallback, p_filter );
  1829.    var_DelCallback( p_filter, CFG_PREFIX "DarknessLimit",
  1830.                     AtmoSettingsCallback, p_filter );
  1831.    var_DelCallback( p_filter, CFG_PREFIX "HueWinSize",
  1832.                     AtmoSettingsCallback, p_filter );
  1833.    var_DelCallback( p_filter, CFG_PREFIX "SatWinSize",
  1834.                     AtmoSettingsCallback, p_filter );
  1835.    var_DelCallback( p_filter, CFG_PREFIX "FrameDelay",
  1836.                     AtmoSettingsCallback, p_filter );
  1837.    var_DelCallback( p_filter, CFG_PREFIX "whiteadj",
  1838.                     AtmoSettingsCallback, p_filter );
  1839.    var_DelCallback( p_filter, CFG_PREFIX "white-red",
  1840.                     AtmoSettingsCallback, p_filter );
  1841.    var_DelCallback( p_filter, CFG_PREFIX "white-green",
  1842.                     AtmoSettingsCallback, p_filter );
  1843.    var_DelCallback( p_filter, CFG_PREFIX "white-blue",
  1844.                     AtmoSettingsCallback, p_filter );
  1845. }
  1846. #if defined(__ATMO_DEBUG__)
  1847. static void atmo_parse_crop(char *psz_cropconfig,
  1848.                             video_format_t fmt_in,
  1849.                             video_format_t fmt_render,
  1850.                             int &i_visible_width, int &i_visible_height,
  1851.                             int &i_x_offset, int &i_y_offset )
  1852. {
  1853.     int64_t i_aspect_num, i_aspect_den;
  1854.     unsigned int i_width, i_height;
  1855.     i_visible_width  = fmt_in.i_visible_width;
  1856.     i_visible_height = fmt_in.i_visible_height;
  1857.     i_x_offset       = fmt_in.i_x_offset;
  1858.     i_y_offset       = fmt_in.i_y_offset;
  1859.     char *psz_end = NULL, *psz_parser = strchr( psz_cropconfig, ':' );
  1860.     if( psz_parser )
  1861.     {
  1862.         /* We're using the 3:4 syntax */
  1863.         i_aspect_num = strtol( psz_cropconfig, &psz_end, 10 );
  1864.         if( psz_end == psz_cropconfig || !i_aspect_num ) return;
  1865.         i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
  1866.         if( psz_end == psz_parser || !i_aspect_den ) return;
  1867.         i_width = fmt_in.i_sar_den * fmt_render.i_visible_height *
  1868.             i_aspect_num / i_aspect_den / fmt_in.i_sar_num;
  1869.         i_height = fmt_render.i_visible_width*fmt_in.i_sar_num *
  1870.             i_aspect_den / i_aspect_num / fmt_in.i_sar_den;
  1871.         if( i_width < fmt_render.i_visible_width )
  1872.         {
  1873.             i_x_offset = fmt_render.i_x_offset +
  1874.                 (fmt_render.i_visible_width - i_width) / 2;
  1875.             i_visible_width = i_width;
  1876.         }
  1877.         else
  1878.         {
  1879.             i_y_offset = fmt_render.i_y_offset +
  1880.                 (fmt_render.i_visible_height - i_height) / 2;
  1881.             i_visible_height = i_height;
  1882.         }
  1883.     }
  1884.     else
  1885.     {
  1886.         psz_parser = strchr( psz_cropconfig, 'x' );
  1887.         if( psz_parser )
  1888.         {
  1889.             /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
  1890.             unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
  1891.             i_crop_width = strtol( psz_cropconfig, &psz_end, 10 );
  1892.             if( psz_end != psz_parser ) return;
  1893.             psz_parser = strchr( ++psz_end, '+' );
  1894.             i_crop_height = strtol( psz_end, &psz_end, 10 );
  1895.             if( psz_end != psz_parser ) return;
  1896.             psz_parser = strchr( ++psz_end, '+' );
  1897.             i_crop_left = strtol( psz_end, &psz_end, 10 );
  1898.             if( psz_end != psz_parser ) return;
  1899.             psz_end++;
  1900.             i_crop_top = strtol( psz_end, &psz_end, 10 );
  1901.             if( *psz_end != '' ) return;
  1902.             i_width = i_crop_width;
  1903.             i_visible_width = i_width;
  1904.             i_height = i_crop_height;
  1905.             i_visible_height = i_height;
  1906.             i_x_offset = i_crop_left;
  1907.             i_y_offset = i_crop_top;
  1908.         }
  1909.         else
  1910.         {
  1911.             /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
  1912.             unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
  1913.             psz_parser = strchr( psz_cropconfig, '+' );
  1914.             i_crop_left = strtol( psz_cropconfig, &psz_end, 10 );
  1915.             if( psz_end != psz_parser ) return;
  1916.             psz_parser = strchr( ++psz_end, '+' );
  1917.             i_crop_top = strtol( psz_end, &psz_end, 10 );
  1918.             if( psz_end != psz_parser ) return;
  1919.             psz_parser = strchr( ++psz_end, '+' );
  1920.             i_crop_right = strtol( psz_end, &psz_end, 10 );
  1921.             if( psz_end != psz_parser ) return;
  1922.             psz_end++;
  1923.             i_crop_bottom = strtol( psz_end, &psz_end, 10 );
  1924.             if( *psz_end != '' ) return;
  1925.             i_width = fmt_render.i_visible_width - i_crop_left - i_crop_right;
  1926.             i_visible_width = i_width;
  1927.             i_height = fmt_render.i_visible_height - i_crop_top - i_crop_bottom;
  1928.             i_visible_height = i_height;
  1929.             i_x_offset = i_crop_left;
  1930.             i_y_offset = i_crop_top;
  1931.         }
  1932.     }
  1933. }
  1934. #endif