webp-ffi 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.md +5 -1
- data/README.md +6 -6
- data/ext/webp_ffi/util.c +154 -10
- data/ext/webp_ffi/util.h +10 -7
- data/ext/webp_ffi/webp_ffi.c +14 -9
- data/lib/webp/c.rb +4 -1
- data/lib/webp/version.rb +1 -1
- data/spec/travis_build.sh +3 -3
- data/spec/webp_ffi_spec.rb +1 -1
- metadata +18 -18
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: e31c8360882b799459efbb17d02a0c8c05182264
         | 
| 4 | 
            +
              data.tar.gz: ad4344c8ce850645cc5f092d627e40860a2e4ae5
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9ebce606526ecd0e5e715f3f83e259ef43dba995dc07cda35fb7d8dbf16e38aadf7171c9092ec5809613cf8073af8251a44539ff51446c2161c42f3912e1c3c5
         | 
| 7 | 
            +
              data.tar.gz: dced6dcbbad67660e1b531317f60af8dcbcac734b2757baad107972e29ed4ed346445e6841f1f852a1909e006d4fff9c4856205935881e57604fb779b881745f
         | 
    
        data/.ruby-version
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            2. | 
| 1 | 
            +
            2.1.0
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -13,21 +13,21 @@ WebP is a new image format that provides lossless and lossy compression for imag | |
| 13 13 |  | 
| 14 14 | 
             
            ### Requirements
         | 
| 15 15 |  | 
| 16 | 
            -
            First of all you should have install libraries: libpng, libjpeg and  | 
| 16 | 
            +
            First of all you should have install libraries: libpng, libjpeg and libtiff.
         | 
| 17 17 |  | 
| 18 | 
            -
            For  | 
| 18 | 
            +
            For Ubuntu, Debian:
         | 
| 19 19 |  | 
| 20 20 | 
             
                sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
         | 
| 21 21 |  | 
| 22 22 | 
             
            For Mac OS:
         | 
| 23 23 |  | 
| 24 | 
            -
                 | 
| 24 | 
            +
                brew install libjpg libpng libtiff webp
         | 
| 25 25 |  | 
| 26 | 
            -
            or:
         | 
| 26 | 
            +
            or (for MacPorts):
         | 
| 27 27 |  | 
| 28 | 
            -
                 | 
| 28 | 
            +
                sudo port install jpeg libpng tiff
         | 
| 29 29 |  | 
| 30 | 
            -
            Next, you should [install libwebp](https://developers.google.com/speed/webp/docs/compiling).
         | 
| 30 | 
            +
            Next, you should [install libwebp](https://developers.google.com/speed/webp/docs/compiling) (if you didn't install it by `brew` in Mac OS). This gem is not support Windows systems (sorry).
         | 
| 31 31 |  | 
| 32 32 | 
             
            ### Final part
         | 
| 33 33 |  | 
    
        data/ext/webp_ffi/util.c
    CHANGED
    
    | @@ -280,6 +280,146 @@ static int UtilWritePPM(FILE* fout, const WebPDecBuffer* const buffer, int alpha | |
| 280 280 | 
             
              return 1;
         | 
| 281 281 | 
             
            }
         | 
| 282 282 |  | 
| 283 | 
            +
            static void PutLE16(uint8_t* const dst, uint32_t value) {
         | 
| 284 | 
            +
              dst[0] = (value >> 0) & 0xff;
         | 
| 285 | 
            +
              dst[1] = (value >> 8) & 0xff;
         | 
| 286 | 
            +
            }
         | 
| 287 | 
            +
             | 
| 288 | 
            +
            static void PutLE32(uint8_t* const dst, uint32_t value) {
         | 
| 289 | 
            +
              PutLE16(dst + 0, (value >>  0) & 0xffff);
         | 
| 290 | 
            +
              PutLE16(dst + 2, (value >> 16) & 0xffff);
         | 
| 291 | 
            +
            }
         | 
| 292 | 
            +
             | 
| 293 | 
            +
            #define BMP_HEADER_SIZE 54
         | 
| 294 | 
            +
            static int UtilWriteBMP(FILE* fout, const WebPDecBuffer* const buffer) {
         | 
| 295 | 
            +
              const int has_alpha = (buffer->colorspace != MODE_BGR);
         | 
| 296 | 
            +
              const uint32_t width = buffer->width;
         | 
| 297 | 
            +
              const uint32_t height = buffer->height;
         | 
| 298 | 
            +
              const uint8_t* const rgba = buffer->u.RGBA.rgba;
         | 
| 299 | 
            +
              const int stride = buffer->u.RGBA.stride;
         | 
| 300 | 
            +
              const uint32_t bytes_per_px = has_alpha ? 4 : 3;
         | 
| 301 | 
            +
              uint32_t y;
         | 
| 302 | 
            +
              const uint32_t line_size = bytes_per_px * width;
         | 
| 303 | 
            +
              const uint32_t bmp_stride = (line_size + 3) & ~3;   // pad to 4
         | 
| 304 | 
            +
              const uint32_t total_size = bmp_stride * height + BMP_HEADER_SIZE;
         | 
| 305 | 
            +
              uint8_t bmp_header[BMP_HEADER_SIZE] = { 0 };
         | 
| 306 | 
            +
             | 
| 307 | 
            +
              // bitmap file header
         | 
| 308 | 
            +
              PutLE16(bmp_header + 0, 0x4d42);                // signature 'BM'
         | 
| 309 | 
            +
              PutLE32(bmp_header + 2, total_size);            // size including header
         | 
| 310 | 
            +
              PutLE32(bmp_header + 6, 0);                     // reserved
         | 
| 311 | 
            +
              PutLE32(bmp_header + 10, BMP_HEADER_SIZE);      // offset to pixel array
         | 
| 312 | 
            +
              // bitmap info header
         | 
| 313 | 
            +
              PutLE32(bmp_header + 14, 40);                   // DIB header size
         | 
| 314 | 
            +
              PutLE32(bmp_header + 18, width);                // dimensions
         | 
| 315 | 
            +
              PutLE32(bmp_header + 22, -(int)height);         // vertical flip!
         | 
| 316 | 
            +
              PutLE16(bmp_header + 26, 1);                    // number of planes
         | 
| 317 | 
            +
              PutLE16(bmp_header + 28, bytes_per_px * 8);     // bits per pixel
         | 
| 318 | 
            +
              PutLE32(bmp_header + 30, 0);                    // no compression (BI_RGB)
         | 
| 319 | 
            +
              PutLE32(bmp_header + 34, 0);                    // image size (dummy)
         | 
| 320 | 
            +
              PutLE32(bmp_header + 38, 2400);                 // x pixels/meter
         | 
| 321 | 
            +
              PutLE32(bmp_header + 42, 2400);                 // y pixels/meter
         | 
| 322 | 
            +
              PutLE32(bmp_header + 46, 0);                    // number of palette colors
         | 
| 323 | 
            +
              PutLE32(bmp_header + 50, 0);                    // important color count
         | 
| 324 | 
            +
             | 
| 325 | 
            +
              // TODO(skal): color profile
         | 
| 326 | 
            +
             | 
| 327 | 
            +
              // write header
         | 
| 328 | 
            +
              if (fwrite(bmp_header, sizeof(bmp_header), 1, fout) != 1) {
         | 
| 329 | 
            +
                return 0;
         | 
| 330 | 
            +
              }
         | 
| 331 | 
            +
             | 
| 332 | 
            +
              // write pixel array
         | 
| 333 | 
            +
              for (y = 0; y < height; ++y) {
         | 
| 334 | 
            +
                if (fwrite(rgba + y * stride, line_size, 1, fout) != 1) {
         | 
| 335 | 
            +
                  return 0;
         | 
| 336 | 
            +
                }
         | 
| 337 | 
            +
                // write padding zeroes
         | 
| 338 | 
            +
                if (bmp_stride != line_size) {
         | 
| 339 | 
            +
                  const uint8_t zeroes[3] = { 0 };
         | 
| 340 | 
            +
                  if (fwrite(zeroes, bmp_stride - line_size, 1, fout) != 1) {
         | 
| 341 | 
            +
                    return 0;
         | 
| 342 | 
            +
                  }
         | 
| 343 | 
            +
                }
         | 
| 344 | 
            +
              }
         | 
| 345 | 
            +
              return 1;
         | 
| 346 | 
            +
            }
         | 
| 347 | 
            +
            #undef BMP_HEADER_SIZE
         | 
| 348 | 
            +
             | 
| 349 | 
            +
            #define NUM_IFD_ENTRIES 15
         | 
| 350 | 
            +
            #define EXTRA_DATA_SIZE 16
         | 
| 351 | 
            +
            // 10b for signature/header + n * 12b entries + 4b for IFD terminator:
         | 
| 352 | 
            +
            #define EXTRA_DATA_OFFSET (10 + 12 * NUM_IFD_ENTRIES + 4)
         | 
| 353 | 
            +
            #define TIFF_HEADER_SIZE (EXTRA_DATA_OFFSET + EXTRA_DATA_SIZE)
         | 
| 354 | 
            +
             | 
| 355 | 
            +
            static int UtilWriteTIFF(FILE* fout, const WebPDecBuffer* const buffer) {
         | 
| 356 | 
            +
              const int has_alpha = (buffer->colorspace != MODE_RGB);
         | 
| 357 | 
            +
              const uint32_t width = buffer->width;
         | 
| 358 | 
            +
              const uint32_t height = buffer->height;
         | 
| 359 | 
            +
              const uint8_t* const rgba = buffer->u.RGBA.rgba;
         | 
| 360 | 
            +
              const int stride = buffer->u.RGBA.stride;
         | 
| 361 | 
            +
              const uint8_t bytes_per_px = has_alpha ? 4 : 3;
         | 
| 362 | 
            +
              // For non-alpha case, we omit tag 0x152 (ExtraSamples).
         | 
| 363 | 
            +
              const uint8_t num_ifd_entries = has_alpha ? NUM_IFD_ENTRIES
         | 
| 364 | 
            +
                                                        : NUM_IFD_ENTRIES - 1;
         | 
| 365 | 
            +
              uint8_t tiff_header[TIFF_HEADER_SIZE] = {
         | 
| 366 | 
            +
                0x49, 0x49, 0x2a, 0x00,   // little endian signature
         | 
| 367 | 
            +
                8, 0, 0, 0,               // offset to the unique IFD that follows
         | 
| 368 | 
            +
                // IFD (offset = 8). Entries must be written in increasing tag order.
         | 
| 369 | 
            +
                num_ifd_entries, 0,       // Number of entries in the IFD (12 bytes each).
         | 
| 370 | 
            +
                0x00, 0x01, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0,    //  10: Width  (TBD)
         | 
| 371 | 
            +
                0x01, 0x01, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0,    //  22: Height (TBD)
         | 
| 372 | 
            +
                0x02, 0x01, 3, 0, bytes_per_px, 0, 0, 0,     //  34: BitsPerSample: 8888
         | 
| 373 | 
            +
                    EXTRA_DATA_OFFSET + 0, 0, 0, 0,
         | 
| 374 | 
            +
                0x03, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0,    //  46: Compression: none
         | 
| 375 | 
            +
                0x06, 0x01, 3, 0, 1, 0, 0, 0, 2, 0, 0, 0,    //  58: Photometric: RGB
         | 
| 376 | 
            +
                0x11, 0x01, 4, 0, 1, 0, 0, 0,                //  70: Strips offset:
         | 
| 377 | 
            +
                    TIFF_HEADER_SIZE, 0, 0, 0,               //      data follows header
         | 
| 378 | 
            +
                0x12, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0,    //  82: Orientation: topleft
         | 
| 379 | 
            +
                0x15, 0x01, 3, 0, 1, 0, 0, 0,                //  94: SamplesPerPixels
         | 
| 380 | 
            +
                    bytes_per_px, 0, 0, 0,
         | 
| 381 | 
            +
                0x16, 0x01, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0,    // 106: Rows per strip (TBD)
         | 
| 382 | 
            +
                0x17, 0x01, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0,    // 118: StripByteCount (TBD)
         | 
| 383 | 
            +
                0x1a, 0x01, 5, 0, 1, 0, 0, 0,                // 130: X-resolution
         | 
| 384 | 
            +
                    EXTRA_DATA_OFFSET + 8, 0, 0, 0,
         | 
| 385 | 
            +
                0x1b, 0x01, 5, 0, 1, 0, 0, 0,                // 142: Y-resolution
         | 
| 386 | 
            +
                    EXTRA_DATA_OFFSET + 8, 0, 0, 0,
         | 
| 387 | 
            +
                0x1c, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0,    // 154: PlanarConfiguration
         | 
| 388 | 
            +
                0x28, 0x01, 3, 0, 1, 0, 0, 0, 2, 0, 0, 0,    // 166: ResolutionUnit (inch)
         | 
| 389 | 
            +
                0x52, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0,    // 178: ExtraSamples: rgbA
         | 
| 390 | 
            +
                0, 0, 0, 0,                                  // 190: IFD terminator
         | 
| 391 | 
            +
                // EXTRA_DATA_OFFSET:
         | 
| 392 | 
            +
                8, 0, 8, 0, 8, 0, 8, 0,      // BitsPerSample
         | 
| 393 | 
            +
                72, 0, 0, 0, 1, 0, 0, 0      // 72 pixels/inch, for X/Y-resolution
         | 
| 394 | 
            +
              };
         | 
| 395 | 
            +
              uint32_t y;
         | 
| 396 | 
            +
             | 
| 397 | 
            +
              // Fill placeholders in IFD:
         | 
| 398 | 
            +
              PutLE32(tiff_header + 10 + 8, width);
         | 
| 399 | 
            +
              PutLE32(tiff_header + 22 + 8, height);
         | 
| 400 | 
            +
              PutLE32(tiff_header + 106 + 8, height);
         | 
| 401 | 
            +
              PutLE32(tiff_header + 118 + 8, width * bytes_per_px * height);
         | 
| 402 | 
            +
              if (!has_alpha) PutLE32(tiff_header + 178, 0);  // IFD terminator
         | 
| 403 | 
            +
             | 
| 404 | 
            +
              // write header
         | 
| 405 | 
            +
              if (fwrite(tiff_header, sizeof(tiff_header), 1, fout) != 1) {
         | 
| 406 | 
            +
                return 0;
         | 
| 407 | 
            +
              }
         | 
| 408 | 
            +
              // write pixel values
         | 
| 409 | 
            +
              for (y = 0; y < height; ++y) {
         | 
| 410 | 
            +
                if (fwrite(rgba + y * stride, bytes_per_px, width, fout) != width) {
         | 
| 411 | 
            +
                  return 0;
         | 
| 412 | 
            +
                }
         | 
| 413 | 
            +
              }
         | 
| 414 | 
            +
             | 
| 415 | 
            +
              return 1;
         | 
| 416 | 
            +
            }
         | 
| 417 | 
            +
             | 
| 418 | 
            +
            #undef TIFF_HEADER_SIZE
         | 
| 419 | 
            +
            #undef EXTRA_DATA_OFFSET
         | 
| 420 | 
            +
            #undef EXTRA_DATA_SIZE
         | 
| 421 | 
            +
            #undef NUM_IFD_ENTRIES
         | 
| 422 | 
            +
             | 
| 283 423 | 
             
            static int UtilWriteAlphaPlane(FILE* fout, const WebPDecBuffer* const buffer) {
         | 
| 284 424 | 
             
              const uint32_t width = buffer->width;
         | 
| 285 425 | 
             
              const uint32_t height = buffer->height;
         | 
| @@ -389,11 +529,11 @@ static InputFileFormat GetImageType(FILE* in_file) { | |
| 389 529 |  | 
| 390 530 | 
             
              magic = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
         | 
| 391 531 | 
             
              if (magic == 0x89504E47U) {
         | 
| 392 | 
            -
                format =  | 
| 532 | 
            +
                format = iPNG_;
         | 
| 393 533 | 
             
              } else if (magic >= 0xFFD8FF00U && magic <= 0xFFD8FFFFU) {
         | 
| 394 | 
            -
                format =  | 
| 534 | 
            +
                format = iJPEG_;
         | 
| 395 535 | 
             
              } else if (magic == 0x49492A00 || magic == 0x4D4D002A) {
         | 
| 396 | 
            -
                format =  | 
| 536 | 
            +
                format = iTIFF_;
         | 
| 397 537 | 
             
              }
         | 
| 398 538 | 
             
              return format;
         | 
| 399 539 | 
             
            }
         | 
| @@ -410,11 +550,11 @@ int UtilReadPicture(const char* const filename, WebPPicture* const pic, | |
| 410 550 | 
             
              if (pic->width == 0 || pic->height == 0) {
         | 
| 411 551 | 
             
                // If no size specified, try to decode it as PNG/JPEG (as appropriate).
         | 
| 412 552 | 
             
                const InputFileFormat format = GetImageType(in_file);
         | 
| 413 | 
            -
                if (format ==  | 
| 553 | 
            +
                if (format == iPNG_) {
         | 
| 414 554 | 
             
                  ok = UtilReadPNG(in_file, pic, keep_alpha);
         | 
| 415 | 
            -
                } else if (format ==  | 
| 555 | 
            +
                } else if (format == iJPEG_) {
         | 
| 416 556 | 
             
                  ok = UtilReadJPEG(in_file, pic);
         | 
| 417 | 
            -
                } else if (format ==  | 
| 557 | 
            +
                } else if (format == iTIFF_) {
         | 
| 418 558 | 
             
                  ok = UtilReadTIFF(filename, pic, keep_alpha);
         | 
| 419 559 | 
             
                }
         | 
| 420 560 | 
             
              } else {
         | 
| @@ -437,13 +577,17 @@ int UtilSaveOutput(const WebPDecBuffer* const buffer, | |
| 437 577 | 
             
                return 0;
         | 
| 438 578 | 
             
              }
         | 
| 439 579 |  | 
| 440 | 
            -
              if (format ==  | 
| 580 | 
            +
              if (format == oPNG) {
         | 
| 441 581 | 
             
                ok &= UtilWritePNG(fout, buffer);
         | 
| 442 | 
            -
              } else if (format ==  | 
| 582 | 
            +
              } else if (format == oPAM) {
         | 
| 443 583 | 
             
                ok &= UtilWritePPM(fout, buffer, 1);
         | 
| 444 | 
            -
              } else if (format ==  | 
| 584 | 
            +
              } else if (format == oPPM) {
         | 
| 445 585 | 
             
                ok &= UtilWritePPM(fout, buffer, 0);
         | 
| 446 | 
            -
              } else if (format ==  | 
| 586 | 
            +
              } else if (format == oBMP) {
         | 
| 587 | 
            +
                ok &= UtilWriteBMP(fout, buffer);
         | 
| 588 | 
            +
              } else if (format == oTIFF_) {
         | 
| 589 | 
            +
                ok &= UtilWriteTIFF(fout, buffer);
         | 
| 590 | 
            +
              } else if (format == oPGM || format == oYUV) {
         | 
| 447 591 | 
             
                ok &= UtilWritePGM(fout, buffer);
         | 
| 448 592 | 
             
              } else if (format == ALPHA_PLANE_ONLY) {
         | 
| 449 593 | 
             
                ok &= UtilWriteAlphaPlane(fout, buffer);
         | 
    
        data/ext/webp_ffi/util.h
    CHANGED
    
    | @@ -6,17 +6,20 @@ extern "C" { | |
| 6 6 | 
             
            #endif
         | 
| 7 7 |  | 
| 8 8 | 
             
            typedef enum {
         | 
| 9 | 
            -
               | 
| 10 | 
            -
               | 
| 11 | 
            -
               | 
| 12 | 
            -
               | 
| 9 | 
            +
              oPNG = 0,
         | 
| 10 | 
            +
              oPAM,
         | 
| 11 | 
            +
              oPPM,
         | 
| 12 | 
            +
              oPGM,
         | 
| 13 | 
            +
              oBMP,
         | 
| 14 | 
            +
              oTIFF_,
         | 
| 15 | 
            +
              oYUV,
         | 
| 13 16 | 
             
              ALPHA_PLANE_ONLY  // this is for experimenting only
         | 
| 14 17 | 
             
            } OutputFileFormat;
         | 
| 15 18 |  | 
| 16 19 | 
             
            typedef enum {
         | 
| 17 | 
            -
               | 
| 18 | 
            -
               | 
| 19 | 
            -
               | 
| 20 | 
            +
              iPNG_ = 0,
         | 
| 21 | 
            +
              iJPEG_,
         | 
| 22 | 
            +
              iTIFF_,  // 'TIFF' clashes with libtiff
         | 
| 20 23 | 
             
              UNSUPPORTED
         | 
| 21 24 | 
             
            } InputFileFormat;
         | 
| 22 25 |  | 
    
        data/ext/webp_ffi/webp_ffi.c
    CHANGED
    
    | @@ -3,14 +3,10 @@ | |
| 3 3 | 
             
            #include <stdlib.h>
         | 
| 4 4 | 
             
            #include <string.h>
         | 
| 5 5 |  | 
| 6 | 
            -
            #include "webp/decode.h"
         | 
| 7 | 
            -
            #include "webp/encode.h"
         | 
| 8 | 
            -
             | 
| 9 6 | 
             
            // utils
         | 
| 10 7 | 
             
            #include "./util.h"
         | 
| 11 8 | 
             
            #include "./webp_ffi.h"
         | 
| 12 9 |  | 
| 13 | 
            -
             | 
| 14 10 | 
             
            #if defined(__cplusplus) || defined(c_plusplus)
         | 
| 15 11 | 
             
            extern "C" {
         | 
| 16 12 | 
             
            #endif
         | 
| @@ -193,7 +189,7 @@ int webp_decode(const char *in_file, const char *out_file, const FfiWebpDecodeCo | |
| 193 189 | 
             
              WebPDecoderConfig config;
         | 
| 194 190 | 
             
              WebPDecBuffer* const output_buffer = &config.output;
         | 
| 195 191 | 
             
              WebPBitstreamFeatures* const bitstream = &config.input;
         | 
| 196 | 
            -
              OutputFileFormat format =  | 
| 192 | 
            +
              OutputFileFormat format = oPNG;
         | 
| 197 193 |  | 
| 198 194 | 
             
              if (!WebPInitDecoderConfig(&config)) {
         | 
| 199 195 | 
             
                //fprintf(stderr, "Library version mismatch!\n");
         | 
| @@ -239,16 +235,24 @@ int webp_decode(const char *in_file, const char *out_file, const FfiWebpDecodeCo | |
| 239 235 | 
             
              }
         | 
| 240 236 |  | 
| 241 237 | 
             
              switch (format) {
         | 
| 242 | 
            -
                case  | 
| 238 | 
            +
                case oPNG:
         | 
| 243 239 | 
             
                  output_buffer->colorspace = bitstream->has_alpha ? MODE_RGBA : MODE_RGB;
         | 
| 244 240 | 
             
                  break;
         | 
| 245 | 
            -
                case  | 
| 241 | 
            +
                case oPAM:
         | 
| 246 242 | 
             
                  output_buffer->colorspace = MODE_RGBA;
         | 
| 247 243 | 
             
                  break;
         | 
| 248 | 
            -
                case  | 
| 244 | 
            +
                case oPPM:
         | 
| 249 245 | 
             
                  output_buffer->colorspace = MODE_RGB;  // drops alpha for PPM
         | 
| 250 246 | 
             
                  break;
         | 
| 251 | 
            -
                case  | 
| 247 | 
            +
                case oBMP:
         | 
| 248 | 
            +
                  output_buffer->colorspace = bitstream->has_alpha ? MODE_BGRA : MODE_BGR;
         | 
| 249 | 
            +
                  break;
         | 
| 250 | 
            +
                case oTIFF_:    // note: force pre-multiplied alpha
         | 
| 251 | 
            +
                  output_buffer->colorspace =
         | 
| 252 | 
            +
                      bitstream->has_alpha ? MODE_rgbA : MODE_RGB;
         | 
| 253 | 
            +
                  break;
         | 
| 254 | 
            +
                case oPGM:
         | 
| 255 | 
            +
                case oYUV:
         | 
| 252 256 | 
             
                  output_buffer->colorspace = bitstream->has_alpha ? MODE_YUVA : MODE_YUV;
         | 
| 253 257 | 
             
                  break;
         | 
| 254 258 | 
             
                case ALPHA_PLANE_ONLY:
         | 
| @@ -258,6 +262,7 @@ int webp_decode(const char *in_file, const char *out_file, const FfiWebpDecodeCo | |
| 258 262 | 
             
                  free((void*)data);
         | 
| 259 263 | 
             
                  return 3;
         | 
| 260 264 | 
             
              }
         | 
| 265 | 
            +
             | 
| 261 266 | 
             
              status = WebPDecode(data, data_size, &config);
         | 
| 262 267 |  | 
| 263 268 | 
             
              if (status != VP8_STATUS_OK) {
         | 
    
        data/lib/webp/c.rb
    CHANGED
    
    | @@ -5,6 +5,9 @@ module WebP | |
| 5 5 | 
             
                              :pam,
         | 
| 6 6 | 
             
                              :ppm,
         | 
| 7 7 | 
             
                              :pgm,
         | 
| 8 | 
            +
                              :bmp,
         | 
| 9 | 
            +
                              :tiff,
         | 
| 10 | 
            +
                              :yuv,
         | 
| 8 11 | 
             
                              :alpha_plane_only )
         | 
| 9 12 | 
             
                # struct
         | 
| 10 13 | 
             
                class FfiWebpEncodeConfig < FFI::Struct
         | 
| @@ -37,7 +40,7 @@ module WebP | |
| 37 40 | 
             
                    :resize_w, :int,
         | 
| 38 41 | 
             
                    :resize_h, :int
         | 
| 39 42 | 
             
                end
         | 
| 40 | 
            -
             | 
| 43 | 
            +
             | 
| 41 44 | 
             
                class FfiWebpDecodeConfig < FFI::Struct
         | 
| 42 45 | 
             
                  layout  :output_format, OutputFileFormat,
         | 
| 43 46 | 
             
                    :bypass_filtering, :int,
         | 
    
        data/lib/webp/version.rb
    CHANGED
    
    
    
        data/spec/travis_build.sh
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            #/usr/bin/env sh
         | 
| 2 | 
            -
            wget http://webp.googlecode.com/files/libwebp-0. | 
| 3 | 
            -
            tar xvzf libwebp-0. | 
| 4 | 
            -
            cd libwebp-0. | 
| 2 | 
            +
            wget http://webp.googlecode.com/files/libwebp-0.4.0.tar.gz
         | 
| 3 | 
            +
            tar xvzf libwebp-0.4.0.tar.gz
         | 
| 4 | 
            +
            cd libwebp-0.4.0
         | 
| 5 5 | 
             
            ./configure
         | 
| 6 6 | 
             
            make
         | 
| 7 7 | 
             
            sudo make install
         | 
    
        data/spec/webp_ffi_spec.rb
    CHANGED
    
    | @@ -132,7 +132,7 @@ describe WebP do | |
| 132 132 | 
             
                  end
         | 
| 133 133 | 
             
                end
         | 
| 134 134 | 
             
                context "with output_format" do
         | 
| 135 | 
            -
                  [:png, :pam, :ppm, :pgm, :alpha_plane_only].each do |output_format|
         | 
| 135 | 
            +
                  [:png, :pam, :ppm, :pgm, :bmp, :tiff, :yuv, :alpha_plane_only].each do |output_format|
         | 
| 136 136 | 
             
                    factories[:webp].take(2).each do |image|
         | 
| 137 137 | 
             
                      it "#{image}.webp image to #{output_format}" do
         | 
| 138 138 | 
             
                        in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.webp"))
         | 
    
        metadata
    CHANGED
    
    | @@ -1,83 +1,83 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: webp-ffi
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Alexey Vasyliev
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2014-01-17 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: ffi
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 | 
            -
                - -  | 
| 17 | 
            +
                - - ">="
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 19 | 
             
                    version: 1.9.0
         | 
| 20 20 | 
             
              type: :runtime
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 | 
            -
                - -  | 
| 24 | 
            +
                - - ">="
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 26 | 
             
                    version: 1.9.0
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: ffi-compiler
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 30 | 
             
                requirements:
         | 
| 31 | 
            -
                - -  | 
| 31 | 
            +
                - - ">="
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 33 | 
             
                    version: 0.1.2
         | 
| 34 34 | 
             
              type: :runtime
         | 
| 35 35 | 
             
              prerelease: false
         | 
| 36 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 37 | 
             
                requirements:
         | 
| 38 | 
            -
                - -  | 
| 38 | 
            +
                - - ">="
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 40 | 
             
                    version: 0.1.2
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: bundler
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 44 | 
             
                requirements:
         | 
| 45 | 
            -
                - -  | 
| 45 | 
            +
                - - ">="
         | 
| 46 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 47 | 
             
                    version: '1.2'
         | 
| 48 48 | 
             
              type: :development
         | 
| 49 49 | 
             
              prerelease: false
         | 
| 50 50 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 | 
            -
                - -  | 
| 52 | 
            +
                - - ">="
         | 
| 53 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 54 | 
             
                    version: '1.2'
         | 
| 55 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 56 | 
             
              name: rake
         | 
| 57 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 58 | 
             
                requirements:
         | 
| 59 | 
            -
                - -  | 
| 59 | 
            +
                - - ">="
         | 
| 60 60 | 
             
                  - !ruby/object:Gem::Version
         | 
| 61 61 | 
             
                    version: '0'
         | 
| 62 62 | 
             
              type: :development
         | 
| 63 63 | 
             
              prerelease: false
         | 
| 64 64 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 65 | 
             
                requirements:
         | 
| 66 | 
            -
                - -  | 
| 66 | 
            +
                - - ">="
         | 
| 67 67 | 
             
                  - !ruby/object:Gem::Version
         | 
| 68 68 | 
             
                    version: '0'
         | 
| 69 69 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 70 70 | 
             
              name: rspec
         | 
| 71 71 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 72 | 
             
                requirements:
         | 
| 73 | 
            -
                - -  | 
| 73 | 
            +
                - - ">="
         | 
| 74 74 | 
             
                  - !ruby/object:Gem::Version
         | 
| 75 75 | 
             
                    version: 2.14.0
         | 
| 76 76 | 
             
              type: :development
         | 
| 77 77 | 
             
              prerelease: false
         | 
| 78 78 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 79 | 
             
                requirements:
         | 
| 80 | 
            -
                - -  | 
| 80 | 
            +
                - - ">="
         | 
| 81 81 | 
             
                  - !ruby/object:Gem::Version
         | 
| 82 82 | 
             
                    version: 2.14.0
         | 
| 83 83 | 
             
            description: Ruby wrapper for libwebp
         | 
| @@ -88,9 +88,9 @@ extensions: | |
| 88 88 | 
             
            - ext/webp_ffi/Rakefile
         | 
| 89 89 | 
             
            extra_rdoc_files: []
         | 
| 90 90 | 
             
            files:
         | 
| 91 | 
            -
            - .gitignore
         | 
| 92 | 
            -
            - .ruby-version
         | 
| 93 | 
            -
            - .travis.yml
         | 
| 91 | 
            +
            - ".gitignore"
         | 
| 92 | 
            +
            - ".ruby-version"
         | 
| 93 | 
            +
            - ".travis.yml"
         | 
| 94 94 | 
             
            - CHANGELOG.md
         | 
| 95 95 | 
             
            - Gemfile
         | 
| 96 96 | 
             
            - LICENSE.txt
         | 
| @@ -133,17 +133,17 @@ require_paths: | |
| 133 133 | 
             
            - lib
         | 
| 134 134 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 135 135 | 
             
              requirements:
         | 
| 136 | 
            -
              - -  | 
| 136 | 
            +
              - - ">="
         | 
| 137 137 | 
             
                - !ruby/object:Gem::Version
         | 
| 138 138 | 
             
                  version: '0'
         | 
| 139 139 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 140 140 | 
             
              requirements:
         | 
| 141 | 
            -
              - -  | 
| 141 | 
            +
              - - ">="
         | 
| 142 142 | 
             
                - !ruby/object:Gem::Version
         | 
| 143 143 | 
             
                  version: '0'
         | 
| 144 144 | 
             
            requirements: []
         | 
| 145 145 | 
             
            rubyforge_project: 
         | 
| 146 | 
            -
            rubygems_version: 2. | 
| 146 | 
            +
            rubygems_version: 2.2.1
         | 
| 147 147 | 
             
            signing_key: 
         | 
| 148 148 | 
             
            specification_version: 4
         | 
| 149 149 | 
             
            summary: Ruby wrapper for libwebp
         |