File: pictfader.c

package info (click to toggle)
lebiniou 3.18-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 5,396 kB
  • sloc: ansic: 20,369; sh: 4,169; makefile: 834; awk: 194
file content (168 lines) | stat: -rw-r--r-- 3,681 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 *  Copyright 1994-2012 Olivier Girondel
 *
 *  This file is part of lebiniou.
 *
 *  lebiniou is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  lebiniou is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with lebiniou. If not, see <http://www.gnu.org/licenses/>.
 */

#include "constants.h"
#include "brandom.h"
#include "pictfader.h"
#include "pictures.h"
#include "globals.h"


PictFader_t *
PictFader_new(const u_short size)
{
  PictFader_t *pf = xcalloc(1, sizeof(PictFader_t));

  pf->on = 0;
  pf->cur = Picture8_new();
  if (pictures != NULL)
    pf->dst = pictures->pics[0];
  pf->fader = Fader_new(BUFFSIZE);
  pf->shf = Shuffler_new(size);
  Shuffler_set_mode(pf->shf, BS_RANDOM);
#ifdef XDEBUG
  Shuffler_verbose(pf->shf);
#endif

  PictFader_set(pf);

  return pf;
}


void
PictFader_delete(PictFader_t *pf)
{
  Picture8_delete(pf->cur);
  Fader_delete(pf->fader);
  Shuffler_delete(pf->shf);
  xfree(pf);
}


void
PictFader_init(PictFader_t *pf)
{
  Fader_t *fader = pf->fader;
  u_long i;
  const Buffer8_t *src = pf->cur->buff;
  const Buffer8_t *dst = pf->dst->buff;
  
  Fader_init(fader);
  for (i = BUFFSIZE; i--; ) { /* i < BUFFSIZE; i++) { */
    /* delta values for fading */
    fader->delta[i] = (long)(
			      ((float)dst->buffer[i] - (float)src->buffer[i])
			      / (float)(fader->max)
			      * MFACTOR);
    
    /* initial values for fading */
    /*fader->tmp[i] = (float)src->buffer[i];*/
    fader->tmp[i] = (u_long)src->buffer[i]*MFACTOR;
  }
  Fader_start(fader);
}


void
PictFader_run(PictFader_t *pf)
{
  Fader_t *fader = pf->fader;
  const u_long elapsed = Fader_elapsed(fader);

  Fader_start(fader);
  fader->faded += elapsed;

  if (fader->faded < fader->max) {
    /* now do some fading stuff #~{@ */
    /* we spent (elapsed) msecs */
    Pixel_t *ptr = pf->cur->buff->buffer;
/*     float   *tmp = fader->tmp; */
/*     float   *delta = fader->delta; */
    u_long   *tmp = fader->tmp;
    long   *delta = fader->delta;
    u_long i;

    for (i = BUFFSIZE; i--; ptr++, tmp++, delta++)
      /**ptr = (Pixel_t)(*tmp += (elapsed * *delta));*/
    *ptr = (Pixel_t)((*tmp += (elapsed * *delta))/MFACTOR);
  } else {
    /* we're done */
    fader->fading = 0;
    /* copy, just in case */
    Picture8_copy(pf->dst, pf->cur);
  }
}


void
PictFader_set(PictFader_t *pf)
{
  Fader_t *fader = pf->fader;

  pf->dst = pictures->pics[fader->target];

  if (pf->dst->name != NULL) {
    if (libbiniou_verbose)
      printf("[i] Using picture '%s'\n", pf->dst->name);
  } else
    xerror("Picture without name, WTF #@!\n");

  if (pf->cur != NULL && pf->dst->id != pf->cur->id) {
    if (fader->fade)
      PictFader_init(pf);
    else
      pf->cur = pf->dst;

    fader->fading = fader->fade;
  }
}


void
PictFader_prev(PictFader_t *pf)
{
  DEC(pf->fader->target, pf->shf->size);
  PictFader_set(pf);
}


void
PictFader_next(PictFader_t *pf)
{
  INC(pf->fader->target, pf->shf->size);
  PictFader_set(pf);
}


void
PictFader_random(PictFader_t *pf)
{
  pf->fader->target = Shuffler_get(pf->shf);
  PictFader_set(pf);
}


int
PictFader_ring(const PictFader_t *pf)
{
  const Fader_t *fader = pf->fader;

  return (fader->fading && (b_timer_elapsed(fader->timer)*MFACTOR));
}