~ubuntu-branches/ubuntu/utopic/lebiniou/utopic

« back to all changes in this revision

Viewing changes to src/pictures.c

  • Committer: Package Import Robot
  • Author(s): Olivier Girondel
  • Date: 2012-04-22 22:07:40 UTC
  • mfrom: (6.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20120422220740-xncgwhc3g71nopnu
Tags: 3.18-1
* New upstream release 3.18.
* Support older libswscale.
* Add missing Build-Depends: libfreetype6-dev, libasound2-dev,
  libpulse-dev. (Closes: #669437)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright 1994-2011 Olivier Girondel
 
2
 *  Copyright 1994-2012 Olivier Girondel
3
3
 *
4
4
 *  This file is part of lebiniou.
5
5
 *
17
17
 *  along with lebiniou. If not, see <http://www.gnu.org/licenses/>.
18
18
 */
19
19
 
 
20
#include <inttypes.h>
20
21
#include "globals.h"
21
22
#include "pictures.h"
22
23
#include "brandom.h"
47
48
  DIR *dir;
48
49
  struct dirent *entry;
49
50
  GSList *tmp = NULL;
50
 
  u_short size = 0;
 
51
  uint16_t size = 0;
51
52
  GSList *t;
52
53
  PBar_t *pb = NULL;
53
54
  gchar **tokens, **theme;
87
88
    }
88
89
 
89
90
    while ((entry = readdir(dir)) != NULL) {
90
 
      long hash;
 
91
      uint32_t hash;
91
92
      Picture8_t *pic;
92
93
 
93
94
      if (entry->d_name[0] == '.')
94
95
        continue;
95
96
 
96
 
      pic = Picture8_new();
97
97
      hash = FNV_hash(entry->d_name);
98
98
 
99
 
      if (Picture8_load(pic, hash, directoryname,
100
 
                      entry->d_name) != 0) {
101
 
        Picture8_delete(pic);
102
 
        continue;
103
 
      }
104
 
 
105
 
      tmp = g_slist_prepend(tmp, (gpointer)pic);
106
 
      size++;
107
 
 
108
 
      if (libbiniou_verbose && !(size % 5))
109
 
        pbar_step(pb);
110
 
 
 
99
      char ignore = 0;
111
100
      for (t = g_slist_next(tmp);
112
101
           t != NULL;
113
102
           t = g_slist_next(t))
114
 
        if (((Picture8_t *)t->data)->id == hash)
115
 
          xerror("Duplicated picture hash: %s / %s, %li\n",
116
 
                 ((Picture8_t *)t->data)->name, entry->d_name, hash);
 
103
        if (((Picture8_t *)t->data)->id == hash) {
 
104
          const char *name = ((Picture8_t *)t->data)->name;
 
105
 
 
106
          if (strcmp(name, entry->d_name))
 
107
            printf("[!] Ignoring picture '%s'\n"
 
108
                   "[!]   (same hash as '%s': %"PRIu32")\n",
 
109
                   entry->d_name, name, hash);
 
110
          ignore = 1;
 
111
        }
 
112
 
 
113
      if (!ignore) {
 
114
        pic = Picture8_new();
 
115
 
 
116
        if (Picture8_load(pic, hash, directoryname,
 
117
                          entry->d_name) != 0) {
 
118
          Picture8_delete(pic);
 
119
        } else {
 
120
          size++;
 
121
          if (libbiniou_verbose && !(size % 5))
 
122
            pbar_step(pb);
 
123
 
 
124
          tmp = g_slist_prepend(tmp, (gpointer)pic);
 
125
        }
 
126
      }
117
127
    }
 
128
 
118
129
    if (closedir(dir) == -1)
119
130
      xperror("closedir");
120
131
    g_free(directoryname);
130
141
  }
131
142
 
132
143
  if (size) {
133
 
    u_short i;
 
144
    uint16_t i;
134
145
 
135
146
    pictures->pics = xmalloc(size*sizeof(Picture8_t *));
136
147
    for (i = 0, t = tmp;
154
165
Pictures_delete()
155
166
{
156
167
  if (pictures != NULL) {
157
 
    u_short i;
 
168
    uint16_t i;
158
169
 
159
170
    for (i = 0; i < pictures->size; i++)
160
171
      Picture8_delete(pictures->pics[i]);
165
176
 
166
177
 
167
178
const char *
168
 
Pictures_name(const long id)
 
179
Pictures_name(const uint32_t id)
169
180
{
170
 
  u_short i;
 
181
  uint16_t i;
171
182
  
172
183
  if (pictures == NULL) {
173
184
    printf("[!] No pictures loaded\n");
181
192
  if (id == 0)
182
193
    return pictures->pics[0]->dname;
183
194
 
184
 
  printf("[!] Pictures_name: id %li not found\n", id);
 
195
  printf("[!] Pictures_name: id %"PRIu16" not found\n", id);
185
196
 
186
197
  return NULL;
187
198
}
188
199
 
189
200
 
190
 
int
191
 
Pictures_index(const long id)
 
201
int32_t
 
202
Pictures_index(const uint32_t id)
192
203
{
193
 
  u_short i;
 
204
  uint16_t i;
194
205
  
195
206
  if (pictures == NULL) {
196
207
    printf("[!] No pictures loaded\n");
201
212
    if (pictures->pics[i]->id == id)
202
213
      return i;
203
214
 
204
 
  printf("[!] Pictures_index: id %li not found\n", id);
 
215
  printf("[!] Pictures_index: id %"PRIu16" not found\n", id);
205
216
 
206
217
  return -1;
207
218
}
208
219
 
209
220
 
210
 
long
 
221
uint32_t
211
222
Pictures_find(const char *name)
212
223
{
213
 
  u_short i;
 
224
  uint16_t i;
214
225
 
215
226
  if (pictures == NULL) {
216
227
    printf("[!] No pictures loaded\n");
217
 
    return -1;
 
228
    return 0;
218
229
  }
219
230
  
220
231
  for (i = 0; i < pictures->size; i++)
226
237
}
227
238
 
228
239
 
229
 
long
 
240
uint32_t
230
241
Pictures_random_id()
231
242
{
232
243
  uint32_t idx;
241
252
const Picture8_t *
242
253
Pictures_random()
243
254
{
244
 
  uint32_t idx;
 
255
  uint16_t idx;
245
256
 
246
257
  assert(pictures != NULL);
247
258
  idx = b_rand_int_range(0, pictures->size-1);