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 | 9 |
10 #include <list> | 10 #include <list> |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 | 137 |
138 char filename[256]; | 138 char filename[256]; |
139 snprintf(filename, sizeof(filename), "%s.%d.ppm", pdf_name, num); | 139 snprintf(filename, sizeof(filename), "%s.%d.ppm", pdf_name, num); |
140 FILE* fp = fopen(filename, "wb"); | 140 FILE* fp = fopen(filename, "wb"); |
141 if (!fp) | 141 if (!fp) |
142 return; | 142 return; |
143 fprintf(fp, "P6\n# PDF test render\n%d %d\n255\n", width, height); | 143 fprintf(fp, "P6\n# PDF test render\n%d %d\n255\n", width, height); |
144 // Source data is B, G, R, unused. | 144 // Source data is B, G, R, unused. |
145 // Dest data is R, G, B. | 145 // Dest data is R, G, B. |
146 char* result = new char[out_len]; | 146 char* result = new char[out_len]; |
147 if (result) { | 147 for (int h = 0; h < height; ++h) { |
148 for (int h = 0; h < height; ++h) { | 148 const char* src_line = buffer + (stride * h); |
149 const char* src_line = buffer + (stride * h); | 149 char* dest_line = result + (width * h * 3); |
150 char* dest_line = result + (width * h * 3); | 150 for (int w = 0; w < width; ++w) { |
151 for (int w = 0; w < width; ++w) { | 151 // R |
152 // R | 152 dest_line[w * 3] = src_line[(w * 4) + 2]; |
153 dest_line[w * 3] = src_line[(w * 4) + 2]; | 153 // G |
154 // G | 154 dest_line[(w * 3) + 1] = src_line[(w * 4) + 1]; |
155 dest_line[(w * 3) + 1] = src_line[(w * 4) + 1]; | 155 // B |
156 // B | 156 dest_line[(w * 3) + 2] = src_line[w * 4]; |
157 dest_line[(w * 3) + 2] = src_line[w * 4]; | |
158 } | |
159 } | 157 } |
160 fwrite(result, out_len, 1, fp); | |
161 delete [] result; | |
162 } | 158 } |
| 159 fwrite(result, out_len, 1, fp); |
| 160 delete[] result; |
163 fclose(fp); | 161 fclose(fp); |
164 } | 162 } |
165 | 163 |
166 static void WritePng(const char* pdf_name, int num, const void* buffer_void, | 164 static void WritePng(const char* pdf_name, int num, const void* buffer_void, |
167 int stride, int width, int height) { | 165 int stride, int width, int height) { |
168 if (!CheckDimensions(stride, width, height)) | 166 if (!CheckDimensions(stride, width, height)) |
169 return; | 167 return; |
170 | 168 |
171 std::vector<unsigned char> png_encoding; | 169 std::vector<unsigned char> png_encoding; |
172 const unsigned char* buffer = static_cast<const unsigned char*>(buffer_void); | 170 const unsigned char* buffer = static_cast<const unsigned char*>(buffer_void); |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 RenderPdf(filename, file_contents, file_length, options); | 636 RenderPdf(filename, file_contents, file_length, options); |
639 free(file_contents); | 637 free(file_contents); |
640 } | 638 } |
641 | 639 |
642 FPDF_DestroyLibrary(); | 640 FPDF_DestroyLibrary(); |
643 v8::V8::ShutdownPlatform(); | 641 v8::V8::ShutdownPlatform(); |
644 delete platform; | 642 delete platform; |
645 | 643 |
646 return 0; | 644 return 0; |
647 } | 645 } |
OLD | NEW |