function hLines = videohistplots(mode, varargin)
%VIDEOCELLPLOTS Helper function for plotting in videohistogram demo

%   Copyright 2004-2009 The MathWorks, Inc.
%   $Revision: 1.1.6.1 $  $Date: 2010/08/30 02:59:34 $

persistent firstTime;

switch mode
  case 'setup'
    figure('name', 'Histogram of R,G,B values in video', 'visible', 'off', ...
      'numbertitle', 'off');
    hLines = plot(ones(2,3));
    set(gca, 'XLim', [0 255], 'YLim', [0 400]);
    set(hLines(1), 'Color', [1 0 0]);
    set(hLines(2), 'Color', [0 1 0]);
    set(hLines(3), 'Color', [0 0 1]);
    legend('Red','Green','Blue');
    firstTime = true;

  case 'update'
    hLine = varargin{1};
    frame = varargin{2};
    if firstTime 
      set(get(get(hLine(1),'parent'),'parent'),'visible','on');
      firstTime= false;
    end
    set(hLine, 'ydata', frame);
    drawnow;
end


