addframe.m 992 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. function addframe(vw,img)
  2. %WORKED=ADDFRAME(VW)
  3. % Writes a video frame. VW must be a videoWriter object and IMG a 2D
  4. % numeric array with 1 or 3 channels that is autoconverted to a uint8
  5. % image as follows:
  6. %
  7. % type assumed range
  8. % ---- -------------
  9. % uint8 0 to 255
  10. % double 0 to 1
  11. % logical 0 to 1
  12. %
  13. %SEE ALSO
  14. % videoWriter
  15. %
  16. %Copyright (c) 2007 Gerald Dalley
  17. %See "MIT.txt" in the installation directory for licensing details (especially
  18. %when using this library on GNU/Linux).
  19. [h,w,d] = size(img);
  20. if (isa(img, 'uint8'))
  21. if (h ~= vw.h || w ~= vw.w)
  22. img = uint8(255*imresize(double(img)/255, [vw.h vw.w]));
  23. else
  24. % no changes needed
  25. end
  26. elseif (isa(img, 'double') || islogical(img))
  27. if (h ~= vw.h || w ~= vw.w)
  28. img = uint8(255*imresize(img, [vw.h vw.w]));
  29. else
  30. img = uint8(255*img);
  31. end
  32. else
  33. error('Invalid image type.');
  34. end
  35. if (d == 1)
  36. img = repmat(img, [1 1 3]);
  37. end
  38. feval(vw.plugin, 'addframe', vw.handle, img);