wcap: Move wcap structs and constants to a shader header
authorKristian Høgsberg <krh@bitplanet.net>
Fri, 25 May 2012 21:55:20 +0000 (17:55 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Fri, 25 May 2012 21:55:20 +0000 (17:55 -0400)
src/screenshooter.c
wcap-decode/wcap-decode.c
wcap-decode/wcap-decode.h [new file with mode: 0644]

index d9f26ba..e3e8779 100644 (file)
@@ -31,6 +31,8 @@
 #include "compositor.h"
 #include "screenshooter-server-protocol.h"
 
+#include "../wcap-decode/wcap-decode.h"
+
 struct screenshooter {
        struct wl_object base;
        struct weston_compositor *ec;
@@ -324,12 +326,6 @@ weston_recorder_frame_notify(struct wl_listener *listener, void *data)
        pixman_region32_fini(&damage);
 }
 
-#define WCAP_HEADER_MAGIC      0x57434150
-#define WCAP_FORMAT_XRGB8888   0x34325258
-#define WCAP_FORMAT_XBGR8888   0x34324258
-#define WCAP_FORMAT_RGBX8888   0x34325852
-#define WCAP_FORMAT_BGRX8888   0x34325842
-
 static void
 weston_recorder_create(struct weston_output *output, const char *filename)
 {
index 4f1d870..f6798c6 100644 (file)
 
 #include <cairo.h>
 
-struct wcap_header {
-       uint32_t width, height;
-};
-
-struct wcap_frame_header {
-       uint32_t msecs;
-       uint32_t nrects;
-};
-
-struct wcap_rectangle {
-       int32_t x1, y1, x2, y2;
-};
-
-struct wcap_decoder {
-       int fd;
-       size_t size;
-       void *map, *p, *end;
-       uint32_t *frame;
-       int width, height;
-};
+#include "wcap-decode.h"
 
 static void
 wcap_decoder_decode_rectangle(struct wcap_decoder *decoder,
@@ -92,7 +73,7 @@ wcap_decoder_decode_rectangle(struct wcap_decoder *decoder,
        decoder->p = p;
 }
 
-static int
+int
 wcap_decoder_get_frame(struct wcap_decoder *decoder)
 {
        struct wcap_rectangle *rects;
@@ -158,61 +139,3 @@ wcap_decoder_destroy(struct wcap_decoder *decoder)
        free(decoder->frame);
        free(decoder);
 }
-
-static void
-write_png(struct wcap_decoder *decoder, const char *filename)
-{
-       cairo_surface_t *surface;
-
-       surface = cairo_image_surface_create_for_data((unsigned char *) decoder->frame,
-                                                     CAIRO_FORMAT_ARGB32,
-                                                     decoder->width,
-                                                     decoder->height,
-                                                     decoder->width * 4);
-       cairo_surface_write_to_png(surface, filename);
-       cairo_surface_destroy(surface);
-}
-
-static void
-write_all_pngs(struct wcap_decoder *decoder, int frame)
-{
-       char filename[200];
-       int i;
-
-       i = 0;
-       while (wcap_decoder_get_frame(decoder)) {
-               if (i == frame || frame == -1) {
-                       snprintf(filename, sizeof filename,
-                                "wcap-frame-%d.png", i);
-                       write_png(decoder, filename);
-                       printf("wrote %s\n", filename);
-               }
-               i++;
-       }
-}
-
-int main(int argc, char *argv[])
-{
-       struct wcap_decoder *decoder;
-       int i, output_frame;
-
-       if (argc != 2 && argc != 3) {
-               fprintf(stderr, "usage: wcap-decode WCAP_FILE [FRAME]\n");
-               return 1;
-       }                       
-
-       decoder = wcap_decoder_create(argv[1]);
-       output_frame = -1;
-       if (argc == 3)
-               output_frame = strtol(argv[2], NULL, 0);
-
-       if (0)
-               write_all_pngs(decoder, -1);
-       else
-               write_webm(decoder);
-
-       printf("wcap file: size %dx%d, %d frames\n",
-              decoder->width, decoder->height, i);
-
-       wcap_decoder_destroy(decoder);
-}
diff --git a/wcap-decode/wcap-decode.h b/wcap-decode/wcap-decode.h
new file mode 100644 (file)
index 0000000..598e490
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _WCAP_DECODE_
+#define _WCAP_DECODE_
+
+#define WCAP_HEADER_MAGIC      0x57434150
+
+#define WCAP_FORMAT_XRGB8888   0x34325258
+#define WCAP_FORMAT_XBGR8888   0x34324258
+#define WCAP_FORMAT_RGBX8888   0x34325852
+#define WCAP_FORMAT_BGRX8888   0x34325842
+
+struct wcap_header {
+       uint32_t magic;
+       uint32_t format;
+       uint32_t width, height;
+};
+
+struct wcap_frame_header {
+       uint32_t msecs;
+       uint32_t nrects;
+};
+
+struct wcap_rectangle {
+       int32_t x1, y1, x2, y2;
+};
+
+struct wcap_decoder {
+       int fd;
+       size_t size;
+       void *map, *p, *end;
+       uint32_t *frame;
+       int width, height;
+};
+
+int wcap_decoder_get_frame(struct wcap_decoder *decoder);
+struct wcap_decoder *wcap_decoder_create(const char *filename);
+void wcap_decoder_destroy(struct wcap_decoder *decoder);
+
+#endif