Skip to content
This repository
Browse code

fixed: no thumbnails were created for images which need to be rotated…

… by FlipHorizontal, FlipVertical and Rotate180CCW + a small refactor.
  • Loading branch information...
commit 4d75c655458943c330edc5c81a163193c7360310 1 parent cbcdd0b
wsoltys authored January 23, 2013
55  xbmc/pictures/Picture.cpp
@@ -242,7 +242,7 @@ bool CPicture::ScaleImage(uint8_t *in_pixels, unsigned int in_width, unsigned in
242 242
 bool CPicture::OrientateImage(uint32_t *&pixels, unsigned int &width, unsigned int &height, int orientation)
243 243
 {
244 244
   // ideas for speeding these functions up: http://cgit.freedesktop.org/pixman/tree/pixman/pixman-fast-path.c
245  
-  uint32_t *out = NULL;
  245
+  bool out = false;
246 246
   switch (orientation)
247 247
   {
248 248
     case 1:
@@ -270,16 +270,10 @@ bool CPicture::OrientateImage(uint32_t *&pixels, unsigned int &width, unsigned i
270 270
       CLog::Log(LOGERROR, "Unknown orientation %i", orientation);
271 271
       break;
272 272
   }
273  
-  if (out)
274  
-  {
275  
-    pixels = out;
276  
-    std::swap(width, height);
277  
-    return true;
278  
-  }
279  
-  return false;
  273
+  return out;
280 274
 }
281 275
 
282  
-uint32_t *CPicture::FlipHorizontal(uint32_t *pixels, unsigned int width, unsigned int height)
  276
+bool CPicture::FlipHorizontal(uint32_t *&pixels, unsigned int &width, unsigned int &height)
283 277
 {
284 278
   // this can be done in-place easily enough
285 279
   for (unsigned int y = 0; y < height; ++y)
@@ -288,10 +282,10 @@ uint32_t *CPicture::FlipHorizontal(uint32_t *pixels, unsigned int width, unsigne
288 282
     for (unsigned int x = 0; x < width / 2; ++x)
289 283
       std::swap(line[x], line[width - 1 - x]);
290 284
   }
291  
-  return NULL;
  285
+  return true;
292 286
 }
293 287
 
294  
-uint32_t *CPicture::FlipVertical(uint32_t *pixels, unsigned int width, unsigned int height)
  288
+bool CPicture::FlipVertical(uint32_t *&pixels, unsigned int &width, unsigned int &height)
295 289
 {
296 290
   // this can be done in-place easily enough
297 291
   for (unsigned int y = 0; y < height / 2; ++y)
@@ -301,10 +295,10 @@ uint32_t *CPicture::FlipVertical(uint32_t *pixels, unsigned int width, unsigned
301 295
     for (unsigned int x = 0; x < width; ++x)
302 296
       std::swap(*line1++, *line2++);
303 297
   }
304  
-  return NULL;
  298
+  return true;
305 299
 }
306 300
 
307  
-uint32_t *CPicture::Rotate180CCW(uint32_t *pixels, unsigned int width, unsigned int height)
  301
+bool CPicture::Rotate180CCW(uint32_t *&pixels, unsigned int &width, unsigned int &height)
308 302
 {
309 303
   // this can be done in-place easily enough
310 304
   for (unsigned int y = 0; y < height / 2; ++y)
@@ -320,10 +314,10 @@ uint32_t *CPicture::Rotate180CCW(uint32_t *pixels, unsigned int width, unsigned
320 314
     for (unsigned int x = 0; x < width / 2; ++x)
321 315
       std::swap(line[x], line[width - 1 - x]);
322 316
   }
323  
-  return NULL;
  317
+  return true;
324 318
 }
325 319
 
326  
-uint32_t *CPicture::Rotate90CCW(uint32_t *pixels, unsigned int width, unsigned int height)
  320
+bool CPicture::Rotate90CCW(uint32_t *&pixels, unsigned int &width, unsigned int &height)
327 321
 {
328 322
   uint32_t *dest = new uint32_t[width * height * 4];
329 323
   if (dest)
@@ -339,16 +333,19 @@ uint32_t *CPicture::Rotate90CCW(uint32_t *pixels, unsigned int width, unsigned i
339 333
         src += width;
340 334
       }
341 335
     }
  336
+    delete[] pixels;
  337
+    pixels = dest;
  338
+    std::swap(width, height);
  339
+    return true;
342 340
   }
343  
-  delete[] pixels;
344  
-  return dest;
  341
+  return false;
345 342
 }
346 343
 
347  
-uint32_t *CPicture::Rotate270CCW(uint32_t *pixels, unsigned int width, unsigned int height)
  344
+bool CPicture::Rotate270CCW(uint32_t *&pixels, unsigned int &width, unsigned int &height)
348 345
 {
349 346
   uint32_t *dest = new uint32_t[width * height * 4];
350 347
   if (!dest)
351  
-    return NULL;
  348
+    return false;
352 349
 
353 350
   unsigned int d_height = width, d_width = height;
354 351
   for (unsigned int y = 0; y < d_height; y++)
@@ -363,14 +360,16 @@ uint32_t *CPicture::Rotate270CCW(uint32_t *pixels, unsigned int width, unsigned
363 360
   }
364 361
 
365 362
   delete[] pixels;
366  
-  return dest;
  363
+  pixels = dest;
  364
+  std::swap(width, height);
  365
+  return true;
367 366
 }
368 367
 
369  
-uint32_t *CPicture::Transpose(uint32_t *pixels, unsigned int width, unsigned int height)
  368
+bool CPicture::Transpose(uint32_t *&pixels, unsigned int &width, unsigned int &height)
370 369
 {
371 370
   uint32_t *dest = new uint32_t[width * height * 4];
372 371
   if (!dest)
373  
-    return NULL;
  372
+    return false;
374 373
 
375 374
   unsigned int d_height = width, d_width = height;
376 375
   for (unsigned int y = 0; y < d_height; y++)
@@ -385,14 +384,16 @@ uint32_t *CPicture::Transpose(uint32_t *pixels, unsigned int width, unsigned int
385 384
   }
386 385
 
387 386
   delete[] pixels;
388  
-  return dest;
  387
+  pixels = dest;
  388
+  std::swap(width, height);
  389
+  return true;
389 390
 }
390 391
 
391  
-uint32_t *CPicture::TransposeOffAxis(uint32_t *pixels, unsigned int width, unsigned int height)
  392
+bool CPicture::TransposeOffAxis(uint32_t *&pixels, unsigned int &width, unsigned int &height)
392 393
 {
393 394
   uint32_t *dest = new uint32_t[width * height * 4];
394 395
   if (!dest)
395  
-    return NULL;
  396
+    return false;
396 397
 
397 398
   unsigned int d_height = width, d_width = height;
398 399
   for (unsigned int y = 0; y < d_height; y++)
@@ -407,5 +408,7 @@ uint32_t *CPicture::TransposeOffAxis(uint32_t *pixels, unsigned int width, unsig
407 408
   }
408 409
 
409 410
   delete[] pixels;
410  
-  return dest;
  411
+  pixels = dest;
  412
+  std::swap(width, height);
  413
+  return true;
411 414
 }
14  xbmc/pictures/Picture.h
@@ -50,13 +50,13 @@ class CPicture
50 50
                          uint8_t *out_pixels, unsigned int out_width, unsigned int out_height, unsigned int out_pitch);
51 51
   static bool OrientateImage(uint32_t *&pixels, unsigned int &width, unsigned int &height, int orientation);
52 52
 
53  
-  static uint32_t *FlipHorizontal(uint32_t *pixels, unsigned int width, unsigned int height);
54  
-  static uint32_t *FlipVertical(uint32_t *pixels, unsigned int width, unsigned int height);
55  
-  static uint32_t *Rotate90CCW(uint32_t *pixels, unsigned int width, unsigned int height);
56  
-  static uint32_t *Rotate270CCW(uint32_t *pixels, unsigned int width, unsigned int height);
57  
-  static uint32_t *Rotate180CCW(uint32_t *pixels, unsigned int width, unsigned int height);
58  
-  static uint32_t *Transpose(uint32_t *pixels, unsigned int width, unsigned int height);
59  
-  static uint32_t *TransposeOffAxis(uint32_t *pixels, unsigned int width, unsigned int height);
  53
+  static bool FlipHorizontal(uint32_t *&pixels, unsigned int &width, unsigned int &height);
  54
+  static bool FlipVertical(uint32_t *&pixels, unsigned int &width, unsigned int &height);
  55
+  static bool Rotate90CCW(uint32_t *&pixels, unsigned int &width, unsigned int &height);
  56
+  static bool Rotate270CCW(uint32_t *&pixels, unsigned int &width, unsigned int &height);
  57
+  static bool Rotate180CCW(uint32_t *&pixels, unsigned int &width, unsigned int &height);
  58
+  static bool Transpose(uint32_t *&pixels, unsigned int &width, unsigned int &height);
  59
+  static bool TransposeOffAxis(uint32_t *&pixels, unsigned int &width, unsigned int &height);
60 60
 };
61 61
 
62 62
 //this class calls CreateThumbnailFromSurface in a CJob, so a png file can be written without halting the render thread

0 notes on commit 4d75c65

Please sign in to comment.
Something went wrong with that request. Please try again.