OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <limits.h> | 5 #include <limits.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <wchar.h> | 9 #include <wchar.h> |
10 | 10 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 138 |
139 char filename[256]; | 139 char filename[256]; |
140 snprintf(filename, sizeof(filename), "%s.%d.ppm", pdf_name, num); | 140 snprintf(filename, sizeof(filename), "%s.%d.ppm", pdf_name, num); |
141 FILE* fp = fopen(filename, "wb"); | 141 FILE* fp = fopen(filename, "wb"); |
142 if (!fp) | 142 if (!fp) |
143 return; | 143 return; |
144 fprintf(fp, "P6\n# PDF test render\n%d %d\n255\n", width, height); | 144 fprintf(fp, "P6\n# PDF test render\n%d %d\n255\n", width, height); |
145 // Source data is B, G, R, unused. | 145 // Source data is B, G, R, unused. |
146 // Dest data is R, G, B. | 146 // Dest data is R, G, B. |
147 char* result = new char[out_len]; | 147 char* result = new char[out_len]; |
148 if (result) { | 148 for (int h = 0; h < height; ++h) { |
149 for (int h = 0; h < height; ++h) { | 149 const char* src_line = buffer + (stride * h); |
150 const char* src_line = buffer + (stride * h); | 150 char* dest_line = result + (width * h * 3); |
151 char* dest_line = result + (width * h * 3); | 151 for (int w = 0; w < width; ++w) { |
152 for (int w = 0; w < width; ++w) { | 152 // R |
153 // R | 153 dest_line[w * 3] = src_line[(w * 4) + 2]; |
154 dest_line[w * 3] = src_line[(w * 4) + 2]; | 154 // G |
155 // G | 155 dest_line[(w * 3) + 1] = src_line[(w * 4) + 1]; |
156 dest_line[(w * 3) + 1] = src_line[(w * 4) + 1]; | 156 // B |
157 // B | 157 dest_line[(w * 3) + 2] = src_line[w * 4]; |
158 dest_line[(w * 3) + 2] = src_line[w * 4]; | |
159 } | |
160 } | 158 } |
161 fwrite(result, out_len, 1, fp); | |
162 delete [] result; | |
163 } | 159 } |
| 160 fwrite(result, out_len, 1, fp); |
| 161 delete[] result; |
164 fclose(fp); | 162 fclose(fp); |
165 } | 163 } |
166 | 164 |
167 static void WritePng(const char* pdf_name, int num, const void* buffer_void, | 165 static void WritePng(const char* pdf_name, int num, const void* buffer_void, |
168 int stride, int width, int height) { | 166 int stride, int width, int height) { |
169 if (!CheckDimensions(stride, width, height)) | 167 if (!CheckDimensions(stride, width, height)) |
170 return; | 168 return; |
171 | 169 |
172 std::vector<unsigned char> png_encoding; | 170 std::vector<unsigned char> png_encoding; |
173 const unsigned char* buffer = static_cast<const unsigned char*>(buffer_void); | 171 const unsigned char* buffer = static_cast<const unsigned char*>(buffer_void); |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 RenderPdf(filename, file_contents, file_length, options); | 629 RenderPdf(filename, file_contents, file_length, options); |
632 free(file_contents); | 630 free(file_contents); |
633 } | 631 } |
634 | 632 |
635 FPDF_DestroyLibrary(); | 633 FPDF_DestroyLibrary(); |
636 v8::V8::ShutdownPlatform(); | 634 v8::V8::ShutdownPlatform(); |
637 delete platform; | 635 delete platform; |
638 | 636 |
639 return 0; | 637 return 0; |
640 } | 638 } |
OLD | NEW |