frame.c
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (C) 2010-2012 Ken Tossell
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the author nor other contributors may be
18 * used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
38 #include "libuvc.h"
39 #include "libuvc_internal.h"
40 
42 uvc_error_t uvc_ensure_frame_size(uvc_frame_t *frame, size_t need_bytes) {
43  if (frame->library_owns_data) {
44  if (!frame->data || frame->data_bytes != need_bytes) {
45  frame->data_bytes = need_bytes;
46  frame->data = realloc(frame->data, frame->data_bytes);
47  }
48  if (!frame->data)
49  return UVC_ERROR_NO_MEM;
50  return UVC_SUCCESS;
51  } else {
52  if (!frame->data || frame->data_bytes < need_bytes)
53  return UVC_ERROR_NO_MEM;
54  return UVC_SUCCESS;
55  }
56 }
57 
64 uvc_frame_t *uvc_allocate_frame(size_t data_bytes) {
65  uvc_frame_t *frame = malloc(sizeof(*frame));
66 
67  if (!frame)
68  return NULL;
69 
70  memset(frame, 0, sizeof(*frame));
71 
72  frame->library_owns_data = 1;
73 
74  if (data_bytes > 0) {
75  frame->data_bytes = data_bytes;
76  frame->data = malloc(data_bytes);
77 
78  if (!frame->data) {
79  free(frame);
80  return NULL;
81  }
82  }
83 
84  return frame;
85 }
86 
93  if (frame->data_bytes > 0 && frame->library_owns_data)
94  free(frame->data);
95 
96  free(frame);
97 }
98 
99 static inline unsigned char sat(int i) {
100  return (unsigned char)( i >= 255 ? 255 : (i < 0 ? 0 : i));
101 }
102 
110  if (uvc_ensure_frame_size(out, in->data_bytes) < 0)
111  return UVC_ERROR_NO_MEM;
112 
113  out->width = in->width;
114  out->height = in->height;
115  out->fourcc = in->fourcc;
116  out->step = in->step;
117  out->sequence = in->sequence;
118  out->capture_time = in->capture_time;
119  out->source = in->source;
120 
121  memcpy(out->data, in->data, in->data_bytes);
122 
123  return UVC_SUCCESS;
124 }
static unsigned char sat(int i)
Definition: frame.c:99
enum uvc_error uvc_error_t
size_t data_bytes
Definition: libuvc.h:368
uvc_error_t uvc_duplicate_frame(uvc_frame_t *in, uvc_frame_t *out)
Duplicate a frame, preserving color format.
Definition: frame.c:109
uint32_t height
Definition: libuvc.h:372
uvc_frame_t * uvc_allocate_frame(size_t data_bytes)
Allocate a frame structure.
Definition: frame.c:64
uint8_t library_owns_data
Definition: libuvc.h:390
uint32_t fourcc
Definition: libuvc.h:374
uint32_t width
Definition: libuvc.h:370
Implementation-specific UVC constants and structures.
uvc_error_t uvc_ensure_frame_size(uvc_frame_t *frame, size_t need_bytes)
Definition: frame.c:42
uvc_device_handle_t * source
Definition: libuvc.h:383
uint32_t sequence
Definition: libuvc.h:378
GLuint in
Definition: glext.h:8313
size_t step
Definition: libuvc.h:376
void uvc_free_frame(uvc_frame_t *frame)
Free a frame structure.
Definition: frame.c:92
struct timeval capture_time
Definition: libuvc.h:380
void * data
Definition: libuvc.h:366


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Fri Mar 13 2020 03:16:17