don't save every play frame by default
[sparrow.git] / play.c
blob0da504beb742cd7d167b4dab66ef4d689a65307f
1 /* Copyright (C) <2010> Douglas Bagnall <douglas@halo.gen.nz>
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Library General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
13 * You should have received a copy of the GNU Library General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 02111-1307, USA.
19 #include "sparrow.h"
20 #include "gstsparrow.h"
22 #include <string.h>
23 #include <math.h>
25 #define DEBUG_PLAY 0
27 typedef struct sparrow_play_s{
28 guint8 lut[256];
30 } sparrow_play_t;
33 static inline guint8
34 negate(sparrow_play_t *player, guint8 in){
35 return player->lut[in];
38 static void UNUSED
39 play_from_lut(GstSparrow *sparrow, guint8 *in, guint8 *out){
40 sparrow_map_t *map = &sparrow->map;
41 memset(out, 0, sparrow->out.size);
42 int x, y;
43 guint32 *line = (guint32 *)out;
44 for (y = 0; y < sparrow->out.height; y++){
45 sparrow_map_row_t *row = map->rows + y;
46 for(x = row->start; x < row->end; x++){
47 line[x] = ~0;
50 GST_DEBUG("row %p %d: s %d e%d line %d\n",
51 row, y, row->start, row->end, line);
53 line += sparrow->out.width;
57 static void
58 play_from_full_lut(GstSparrow *sparrow, guint8 *in, guint8 *out){
59 memset(out, 0, sparrow->out.size);
60 sparrow_play_t *player = sparrow->helper_struct;
61 guint i;
62 guint32 *out32 = (guint32 *)out;
63 guint32 *in32 = (guint32 *)in;
64 for (i = 0; i < sparrow->out.pixcount; i++){
65 if (sparrow->screenmask[i]){
66 int x = sparrow->map_lut[i].x >> SPARROW_MAP_LUT_SHIFT;
67 int y = sparrow->map_lut[i].y >> SPARROW_MAP_LUT_SHIFT;
68 if (x || y){
69 //out32[i] = ~in32[y * sparrow->in.width + x];
70 guint8 *ib = (guint8 *)&in32[y * sparrow->in.width + x];
71 guint8 *ob = (guint8 *)&out32[i];
72 ob[0] = player->lut[ib[0]];
73 ob[1] = player->lut[ib[1]];
74 ob[2] = player->lut[ib[2]];
75 ob[3] = player->lut[ib[3]];
79 if (DEBUG_PLAY && sparrow->debug){
80 debug_frame(sparrow, out, sparrow->out.width, sparrow->out.height, PIXSIZE);
86 INVISIBLE sparrow_state
87 mode_play(GstSparrow *sparrow, guint8 *in, guint8 *out){
88 //do actual stuff here
89 //memcpy(out, in, sparrow->out.size);
90 //simple_negation(out, sparrow->out.size);
91 #if USE_FULL_LUT
92 play_from_full_lut(sparrow, in, out);
93 #else
94 play_from_lut(sparrow, in, out);
95 #endif
96 return SPARROW_STATUS_QUO;
99 static const double GAMMA = 2.0;
100 static const double INV_GAMMA = 1.0 / 2.2;
101 static const double FALSE_CEILING = 275;
103 static void
104 init_gamma_lut(sparrow_play_t *player){
105 for (int i = 0; i < 256; i++){
106 /* for each colour:
107 1. perform inverse gamma calculation (-> linear colour space)
108 2. negate
109 3 undo gamma.
111 double x;
112 x = i / 255.01;
113 x = 1 - pow(x, INV_GAMMA);
114 x = pow(x, GAMMA) * FALSE_CEILING;
115 if (x > 255){
116 x = 255;
118 player->lut[i] = (guint8)x;
123 INVISIBLE void init_play(GstSparrow *sparrow){
124 GST_DEBUG("starting play mode\n");
125 sparrow_play_t *player = zalloc_aligned_or_die(sizeof(sparrow_play_t));
126 sparrow->helper_struct = player;
127 init_gamma_lut(player);
130 INVISIBLE void finalise_play(GstSparrow *sparrow){
131 GST_DEBUG("leaving play mode\n");