| 1132 | } |
| 1133 | |
| 1134 | status_t preProcessImage(const Bundle* bundle, const sp<AaptAssets>& assets, |
| 1135 | const sp<AaptFile>& file, String8* outNewLeafName) |
| 1136 | { |
| 1137 | String8 ext(file->getPath().getPathExtension()); |
| 1138 | |
| 1139 | // We currently only process PNG images. |
| 1140 | if (strcmp(ext.string(), ".png") != 0) { |
| 1141 | return NO_ERROR; |
| 1142 | } |
| 1143 | |
| 1144 | // Example of renaming a file: |
| 1145 | //*outNewLeafName = file->getPath().getBasePath().getFileName(); |
| 1146 | //outNewLeafName->append(".nupng"); |
| 1147 | |
| 1148 | String8 printableName(file->getPrintableSource()); |
| 1149 | |
| 1150 | if (bundle->getVerbose()) { |
| 1151 | printf("Processing image: %s\n", printableName.string()); |
| 1152 | } |
| 1153 | |
| 1154 | png_structp read_ptr = NULL; |
| 1155 | png_infop read_info = NULL; |
| 1156 | FILE* fp; |
| 1157 | |
| 1158 | image_info imageInfo; |
| 1159 | |
| 1160 | png_structp write_ptr = NULL; |
| 1161 | png_infop write_info = NULL; |
| 1162 | |
| 1163 | status_t error = UNKNOWN_ERROR; |
| 1164 | |
| 1165 | const size_t nameLen = file->getPath().length(); |
| 1166 | |
| 1167 | fp = fopen(file->getSourceFile().string(), "rb"); |
| 1168 | if (fp == NULL) { |
| 1169 | fprintf(stderr, "%s: ERROR: Unable to open PNG file\n", printableName.string()); |
| 1170 | goto bail; |
| 1171 | } |
| 1172 | |
| 1173 | read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, (png_error_ptr)NULL, |
| 1174 | (png_error_ptr)NULL); |
| 1175 | if (!read_ptr) { |
| 1176 | goto bail; |
| 1177 | } |
| 1178 | |
| 1179 | read_info = png_create_info_struct(read_ptr); |
| 1180 | if (!read_info) { |
| 1181 | goto bail; |
| 1182 | } |
| 1183 | |
| 1184 | if (setjmp(png_jmpbuf(read_ptr))) { |
| 1185 | goto bail; |
| 1186 | } |
| 1187 | |
| 1188 | png_init_io(read_ptr, fp); |
| 1189 | |
| 1190 | read_png(printableName.string(), read_ptr, read_info, &imageInfo); |
| 1191 |
no test coverage detected