2 * Copyright © 2012 Intel Corporation
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28 #include <sys/types.h>
36 #include "wcap-decode.h"
39 wcap_decoder_decode_rectangle(struct wcap_decoder *decoder,
40 struct wcap_rectangle *rect)
42 uint32_t v, *p = decoder->p, *d;
43 int width = rect->x2 - rect->x1, height = rect->y2 - rect->y1;
44 int x, i, j, k, l, count = width * height;
45 unsigned char r, g, b, dr, dg, db;
47 d = decoder->frame + (rect->y2 - 1) * decoder->width;
56 j = 1 << (l - 0xe0 + 7);
62 for (k = 0; k < j; k++) {
63 r = (d[x] >> 16) + dr;
66 d[x] = 0xff000000 | (r << 16) | (g << 8) | b;
77 printf("rle encoding longer than expected (%d expected %d)\n",
84 wcap_decoder_get_frame(struct wcap_decoder *decoder)
86 struct wcap_rectangle *rects;
87 struct wcap_frame_header *header;
92 if (decoder->p == decoder->end)
96 decoder->msecs = header->msecs;
99 rects = (void *) (header + 1);
100 decoder->p = (uint32_t *) (rects + header->nrects);
101 for (i = 0; i < header->nrects; i++) {
102 width = rects[i].x2 - rects[i].x1;
103 height = rects[i].y2 - rects[i].y1;
104 wcap_decoder_decode_rectangle(decoder, &rects[i]);
110 struct wcap_decoder *
111 wcap_decoder_create(const char *filename)
113 struct wcap_decoder *decoder;
114 struct wcap_header *header;
118 decoder = malloc(sizeof *decoder);
122 decoder->fd = open(filename, O_RDONLY);
123 if (decoder->fd == -1) {
128 fstat(decoder->fd, &buf);
129 decoder->size = buf.st_size;
130 decoder->map = mmap(NULL, decoder->size,
131 PROT_READ, MAP_PRIVATE, decoder->fd, 0);
133 header = decoder->map;
134 decoder->format = header->format;
136 decoder->width = header->width;
137 decoder->height = header->height;
138 decoder->p = header + 1;
139 decoder->end = decoder->map + decoder->size;
141 frame_size = header->width * header->height * 4;
142 decoder->frame = malloc(frame_size);
143 memset(decoder->frame, 0, frame_size);
149 wcap_decoder_destroy(struct wcap_decoder *decoder)
151 munmap(decoder->map, decoder->size);
152 free(decoder->frame);