+ /* Release the reference to the image metadata and decrement reference
+ * counts on the streams referenced by files in the image. */
+ put_image_metadata(wim->image_metadata[image - 1], wim->lookup_table);
+
+ /* Remove the empty slot from the image metadata array. */
+ memmove(&wim->image_metadata[image - 1], &wim->image_metadata[image],
+ (wim->hdr.image_count - image) *
+ sizeof(wim->image_metadata[0]));
+
+ /* Decrement the image count. */
+ --wim->hdr.image_count;
+
+ /* Remove the image from the XML information. */
+ xml_delete_image(&wim->wim_info, image);
+
+ /* Fix the boot index. */
+ if (wim->hdr.boot_idx == image)
+ wim->hdr.boot_idx = 0;
+ else if (wim->hdr.boot_idx > image)
+ wim->hdr.boot_idx--;
+
+ /* The image is no longer valid. */
+ wim->current_image = WIMLIB_NO_IMAGE;
+ return 0;
+}
+
+/* API function documented in wimlib.h */
+WIMLIBAPI int
+wimlib_delete_image(WIMStruct *wim, int image)
+{
+ int ret;
+ int first, last;