Skip to content

Commit

Permalink
Merge pull request #398 from pygame/camera-vidcapture-cleanup
Browse files Browse the repository at this point in the history
Clean up _camera_vidcapture.py unused code, and document a bit.
  • Loading branch information
illume committed Feb 17, 2018
2 parents 3c8e608 + f0c5a5f commit c46c084
Showing 1 changed file with 28 additions and 33 deletions.
61 changes: 28 additions & 33 deletions lib/_camera_vidcapture.py
@@ -1,7 +1,17 @@
"""pygame.camera.Camera implementation using the videocapture module for windows.
http://videocapture.sourceforge.net/
Binary windows wheels:
https://www.lfd.uci.edu/~gohlke/pythonlibs/#videocapture
"""
import pygame

def list_cameras():
"""Always only lists one camera.
Functionality not supported in videocapture module.
"""
return [0]

# this just cycles through all the cameras trying to open them
Expand All @@ -15,7 +25,6 @@ def list_cameras():

return cameras


def init():
global vidcap
try:
Expand All @@ -30,7 +39,6 @@ def quit():
del vidcap



class Camera:

def __init__(self, device =0,
Expand Down Expand Up @@ -78,61 +86,48 @@ def get_buffer(self):
return self.dev.getbuffer()

def start(self):
""" Not implemented.
"""
"""

def set_controls(self, **kwargs):
"""
""" Not implemented.
"""

def stop(self):
"""
""" Not implemented.
"""

def get_image(self, dest_surf = None):
"""
"""
return self.get_surface(dest_surf)

def get_surface(self, dest_surf = None):
"""Returns a pygame Surface.
"""
abuffer, width, height = self.get_buffer()
if abuffer:
if 1:
surf = pygame.image.frombuffer(abuffer, (width, height), "RGB")
surf = pygame.image.frombuffer(abuffer, (width, height), "RGB")

# swap it from a BGR surface to an RGB surface.
r,g,b,a = surf.get_masks()
surf.set_masks((b,g,r,a))
# swap it from a BGR surface to an RGB surface.
r,g,b,a = surf.get_masks()
surf.set_masks((b,g,r,a))

r,g,b,a = surf.get_shifts()
surf.set_shifts((b,g,r,a))
r,g,b,a = surf.get_shifts()
surf.set_shifts((b,g,r,a))

surf = pygame.transform.flip(surf, 0,1)

# if there is a destination surface given, we blit onto that.
if dest_surf:
dest_surf.blit(surf, (0,0))
else:
dest_surf = surf
return dest_surf
surf = pygame.transform.flip(surf, 0,1)

# if there is a destination surface given, we blit onto that.
if dest_surf:
dest_surf.blit(surf, (0,0))
else:

# Need to flip the image.
surf = pygame.image.fromstring(abuffer, (width, height), "RGB", 1)
# swap it from a BGR surface to an RGB surface.
r,g,b,a = surf.get_masks()
surf.set_masks((b,g,r,a))

r,g,b,a = surf.get_shifts()
surf.set_shifts((b,g,r,a))
return surf

dest_surf = surf
return dest_surf

if __name__ == "__main__":
import pygame.examples.camera

pygame.camera.Camera = Camera
pygame.camera.list_cameras = list_cameras
pygame.examples.camera.main()


0 comments on commit c46c084

Please sign in to comment.