public GPhotoCameraFile(string dir, string name)
 {
     directory = dir;
     filename  = name;
     normal    = null;
     preview   = null;
 }
Example #2
0
        public void TestSaveMethod()
        {
            CameraFile cameraFile = new CameraFile();

            cameraFile.Load(TEST_FILE);

            MemoryStream savedStream = new MemoryStream();

            cameraFile.Save(savedStream);

            savedStream.Seek(0, SeekOrigin.Begin);

            CameraFile savedCameraFile = new CameraFile();

            savedCameraFile.Load(savedStream);

            savedStream.Close();

            Assert.AreEqual(cameraFile.ProjectionType, savedCameraFile.ProjectionType, "Projection types do not match");
            Assert.AreEqual(cameraFile.ModelView, savedCameraFile.ModelView, "Model view matrices do not match");
            Assert.AreEqual(cameraFile.Projection, savedCameraFile.Projection, "Projection matrices do not match");
            Assert.AreEqual(cameraFile.FieldOfView, savedCameraFile.FieldOfView, "Field of view values do not match");
            Assert.AreEqual(cameraFile.AspectRatio, savedCameraFile.AspectRatio, "Aspect ratio values do not match");
            Assert.AreEqual(cameraFile.NearPlane, savedCameraFile.NearPlane, "Near plane values do not match");
            Assert.AreEqual(cameraFile.FarPlane, savedCameraFile.FarPlane, "Far plane values do not match");
            Assert.AreEqual(cameraFile.Eye, savedCameraFile.Eye, "Eye positions do not match");
            Assert.AreEqual(cameraFile.Center, savedCameraFile.Center, "Center position do not match");
            Assert.AreEqual(cameraFile.Up, savedCameraFile.Up, "Up positions do not match");
        }
Example #3
0
 /// <summary>
 /// Updates the preview image with a new preview file from the camera.
 /// </summary>
 /// <param name="PreviewBitmap">The bitmap that acts as the image source for the preview display</param>
 public void UpdatePreview(WriteableBitmap PreviewBitmap)
 {
     using (CameraFile preview = ActiveCamera.Preview())
         using (ILockedFramebuffer bitmapBuffer = PreviewBitmap.Lock())
         {
             int bitmapBufferSize = bitmapBuffer.Size.Width * bitmapBuffer.Size.Height * 4;
             JpegDecoder.Decompress(preview.Data, preview.Size, bitmapBuffer.Address, bitmapBufferSize, TJPixelFormat.BGRA, TJFlags.None, out _, out _, out _);
         }
 }
Example #4
0
 /// <summary>
 /// Creates a writeable bitmap large enough to store the provided JPEG image. This bitmap can be reused
 /// for new JPEGs of the same size.
 /// </summary>
 /// <returns>A writeable bitmap with the correct dimensions for containing preview images.</returns>
 public WriteableBitmap CreateWriteableBitmapForPreview()
 {
     using (CameraFile preview = ActiveCamera.Preview())
     {
         JpegDecoder.GetImageInfo(preview.Data, preview.Size, TJPixelFormat.BGRA, out int width, out int height, out int stride, out int bufferSize);
         WriteableBitmap bitmap = new WriteableBitmap(new PixelSize(width, height), new Vector(96, 96), PixelFormat.Bgra8888);
         return(bitmap);
     }
 }
Example #5
0
 /// <summary>
 /// Captures an image from the active camera.
 /// </summary>
 /// <returns>The image's data and its name</returns>
 unsafe public (Bitmap ImageSource, string Filename) CaptureImage()
 {
     using (CameraFile file = ActiveCamera.Capture(CameraCaptureType.Image))
         using (UnmanagedMemoryStream stream = new UnmanagedMemoryStream((byte *)file.Data.ToPointer(), (long)file.Size))
         {
             Logger.Debug($"Image MIME: {file.MimeType}");
             Bitmap bitmap = new Bitmap(stream);
             return(bitmap, file.Name);
         }
 }
        private Guid SaveFile(byte[] data, string fileName)
        {
            CameraFile cFile = new CameraFile(new MemoryStream(data), "image/jpeg", fileName);
            List <HttpPostedFileBase> files = new List <HttpPostedFileBase>();

            files.Add(cFile);

            Guid guid = Guid.NewGuid();

            Transaction.ScaleAttachmentsController controller = new Transaction.ScaleAttachmentsController();
            controller.Save(files, guid.ToString());
            controller.Dispose();
            return(guid);
        }
Example #7
0
        static void testFileSystem(Camera cam)
        {
            Console.WriteLine($"################################ TEST File System ################################");

            List <StorageInfo> info = cam.storageInfo;

            foreach (StorageInfo sinfo in info)
            {
                Console.WriteLine($"{sinfo.label}\n\tStorage type: {sinfo.desc}\n\tRoot: {sinfo.root.path}\n\tAccess rights: {sinfo.accessRights}\n\tType: {sinfo.type}\n\tFile system type: {sinfo.fileSystemType}\n\tCapacity: {Utilities.GetKBytesReadable(sinfo.capacity)}\n\tFree space: {Utilities.GetKBytesReadable(sinfo.free)}");
            }

            CameraFile fi = CameraFile.Find(cam.storageInfo[0].root.fs[0], cam.captureImage()[0]);

            Console.WriteLine($"Captured {fi.filename}");

            if (CameraFile.Exists(cam, fi.path))
            {
                Console.WriteLine($"{fi.filename} exists");
            }
            else
            {
                Console.WriteLine($"{fi.filename} does not exist, but should!?");
            }

            cam.DownloadFile(fi.path, $"{Environment.CurrentDirectory}/{Path.GetFileName(fi.filename)}");
            Console.WriteLine($"File downloaded from {fi.path} to {Environment.CurrentDirectory}/{Path.GetFileName(fi.filename)}");

            fi.Delete();

            if (!CameraFile.Exists(cam, fi.path))
            {
                Console.WriteLine($"{fi.filename} has been deleted");
            }
            else
            {
                Console.WriteLine($"{fi.filename} still exists?!");
            }

            if (CameraFile.Exists(cam, $"{fi.pathWithoutExtension}.JPG"))
            {
                Console.WriteLine("JPG Found, deleting that aswell...");
                CameraFile.Delete(cam, $"{fi.pathWithoutExtension}.JPG");
            }

            Console.WriteLine($"################################ TEST File System ################################\n\n");
        }
Example #8
0
        public void TestLoadMethod()
        {
            Stream stream = File.OpenRead(TEST_FILE);

            stream.Seek(0, SeekOrigin.End);
            long fileSize = stream.Position;

            stream.Seek(0, SeekOrigin.Begin);

            CameraFile cameraFile = new CameraFile();

            cameraFile.Load(stream);

            long streamPosition = stream.Position;

            stream.Close();

            Assert.AreEqual(fileSize, streamPosition, "Not all of the file was read");
        }
    public void SaveFile(int index, string filename)
    {
        if (filename == null)
        {
            return;
        }

        //check if the directory exists
        if (!Directory.Exists(Path.GetDirectoryName(filename)))
        {
            throw new Exception(String.Format("Directory \"{0}\"does not exist", filename));               //FIXME
        }
        using (CameraFile camfile = GetFile(index)) {
            if (camfile == null)
            {
                throw new Exception("Unable to claim file");                  //FIXME
            }
            camfile.Save(filename);
        }
    }
Example #10
0
        static void testCapture(Camera cam)
        {
            Console.WriteLine($"################################ TEST Capture ################################");

            Console.WriteLine($"################### FAST 1/4000 ###################");

            cam.shutterSpeed = "1/4000";

            for (int i = 0; i < 5; i++)
            {
                var watch = System.Diagnostics.Stopwatch.StartNew();

                List <string> files = cam.captureImage();

                watch.Stop();
                var elapsedMs = watch.ElapsedMilliseconds;

                CameraFile file = CameraFile.Find(cam.storageInfo[0].root.fs[0], files[0]);
                Console.WriteLine($"Capture {i+1} {file.filename} " + (files.Count > 1 ? file.filename : "") + $" took {elapsedMs}ms");
            }

            Console.WriteLine($"################### BULB 5s ###################");

            cam.shutterSpeed = "bulb";

            for (int i = 0; i < 5; i++)
            {
                var watch = System.Diagnostics.Stopwatch.StartNew();

                List <string> files = cam.captureImage(5);

                watch.Stop();
                var elapsedMs = watch.ElapsedMilliseconds;

                CameraFile file = CameraFile.Find(cam.storageInfo[0].root.fs[0], files[0]);
                Console.WriteLine($"Capture {i+1} {file.filename} " + (files.Count > 1 ? file.filename : "") + $" took {elapsedMs}ms");
            }

            Console.WriteLine($"################################ TEST Capture ################################");
        }
    public Pixbuf GetPreviewPixbuf(GPhotoCameraFile camfile)
    {
        CameraFile cfile = GetPreview(camfile);

        if (cfile != null)
        {
            byte[] bytedata = cfile.GetDataAndSize();
            if (bytedata.Length > 0)
            {
                MemoryStream dataStream = new MemoryStream(bytedata);
                try {
                    return(new Pixbuf(dataStream));
                } catch (Exception e) {
                    // Actual errors with the data libgphoto gives us have been
                    // observed here see b.g.o #357569.
                    Console.WriteLine("Error retrieving preview image");
                    Console.WriteLine(e);
                }
            }
        }
        return(null);
    }