| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrCaps.h" | 8 #include "GrCaps.h" |
| 9 #include "GrContextFactory.h" | 9 #include "GrContextFactory.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 } | 99 } |
| 100 | 100 |
| 101 static void write_png(const png_bytep rgba, png_uint_32 width, png_uint_32 heigh
t, SkWStream& out) { | 101 static void write_png(const png_bytep rgba, png_uint_32 width, png_uint_32 heigh
t, SkWStream& out) { |
| 102 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL,
NULL); | 102 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL,
NULL); |
| 103 SkASSERT(png != nullptr); | 103 SkASSERT(png != nullptr); |
| 104 png_infop info_ptr = png_create_info_struct(png); | 104 png_infop info_ptr = png_create_info_struct(png); |
| 105 SkASSERT(info_ptr != nullptr); | 105 SkASSERT(info_ptr != nullptr); |
| 106 if (setjmp(png_jmpbuf(png))) { | 106 if (setjmp(png_jmpbuf(png))) { |
| 107 SkFAIL("png encode error"); | 107 SkFAIL("png encode error"); |
| 108 } | 108 } |
| 109 png_set_IHDR(png, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGBA, PNG_INTER
LACE_NONE, | 109 png_set_IHDR(png, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERL
ACE_NONE, |
| 110 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); | 110 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
| 111 png_set_compression_level(png, 1); | 111 png_set_compression_level(png, 1); |
| 112 png_bytepp rows = (png_bytepp) sk_malloc_throw(height * sizeof(png_byte*)); | 112 png_bytepp rows = (png_bytepp) sk_malloc_throw(height * sizeof(png_byte*)); |
| 113 png_bytep pixels = (png_bytep) sk_malloc_throw(width * height * 3); |
| 113 for (png_size_t y = 0; y < height; ++y) { | 114 for (png_size_t y = 0; y < height; ++y) { |
| 114 rows[y] = (png_bytep) rgba + y * width * 4; | 115 const png_bytep src = rgba + y * width * 4; |
| 116 rows[y] = pixels + y * width * 3; |
| 117 // convert from RGBA to RGB |
| 118 for (png_size_t x = 0; x < width; ++x) { |
| 119 rows[y][x * 3] = src[x * 4]; |
| 120 rows[y][x * 3 + 1] = src[x * 4 + 1]; |
| 121 rows[y][x * 3 + 2] = src[x * 4 + 2]; |
| 122 } |
| 115 } | 123 } |
| 116 png_set_filter(png, 0, PNG_NO_FILTERS); | 124 png_set_filter(png, 0, PNG_NO_FILTERS); |
| 117 png_set_rows(png, info_ptr, &rows[0]); | 125 png_set_rows(png, info_ptr, &rows[0]); |
| 118 png_set_write_fn(png, &out, write_png_callback, NULL); | 126 png_set_write_fn(png, &out, write_png_callback, NULL); |
| 119 png_write_png(png, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); | 127 png_write_png(png, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); |
| 120 png_destroy_write_struct(&png, NULL); | 128 png_destroy_write_struct(&png, NULL); |
| 121 sk_free(rows); | 129 sk_free(rows); |
| 122 } | 130 } |
| 123 | 131 |
| 124 SkData* writeCanvasToPng(SkCanvas* canvas) { | 132 SkData* writeCanvasToPng(SkCanvas* canvas) { |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 MHD_stop_daemon(daemon); | 631 MHD_stop_daemon(daemon); |
| 624 return 0; | 632 return 0; |
| 625 } | 633 } |
| 626 | 634 |
| 627 #if !defined SK_BUILD_FOR_IOS | 635 #if !defined SK_BUILD_FOR_IOS |
| 628 int main(int argc, char** argv) { | 636 int main(int argc, char** argv) { |
| 629 SkCommandLineFlags::Parse(argc, argv); | 637 SkCommandLineFlags::Parse(argc, argv); |
| 630 return skiaserve_main(); | 638 return skiaserve_main(); |
| 631 } | 639 } |
| 632 #endif | 640 #endif |
| OLD | NEW |