File repairing method and device, terminal equipment and readable storage medium

By extracting IFD and image data from damaged TIFF files and matching them with IFH, a repair file is assembled, solving the problem of unrepairable TIFF files and achieving complete file recovery.

CN116909997BActive Publication Date: 2026-04-21AFIRSTSOFT CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
AFIRSTSOFT CO LTD
Filing Date
2023-07-21
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

Current technology cannot effectively repair damaged TIFF files so that they can be opened normally.

Method used

Extract all IFDs and their corresponding image data from the damaged TIFF file, match an IFH for each IFD, and assemble them into a repair file containing the complete TIFF image.

Benefits of technology

It successfully repaired damaged TIFF files, enabling each repaired file to be opened normally and recovering multiple sets of image data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116909997B_ABST
    Figure CN116909997B_ABST
Patent Text Reader

Abstract

This application relates to the field of file restoration technology, and provides a method, apparatus, terminal device, and readable storage medium for file restoration. The file restoration method includes: obtaining a file to be restored, wherein the file to be restored is a damaged TIFF file; extracting all IFDs from the file to be restored; extracting the image data corresponding to each IFD from the file to be restored; matching each IFD with a corresponding IFH; assembling each IFD, its corresponding image data, and its corresponding IFH into a restored file, resulting in multiple restored files, each restored file containing a complete TIFF image. In the embodiments of this application, each restored file can be opened, thus realizing the restoration of damaged TIFF files.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of file restoration technology, and in particular relates to a file restoration method, apparatus, terminal device, and readable storage medium. Background Technology

[0002] Tag Image File Format (TIFF) is a flexible bitmap format primarily used to store images, including photographs and artwork. A TIFF file typically includes an IFH (image header), an IFD (image file directory), and the image data. The IFD may contain one or more DE (directory entries), and a single TIFF file may contain multiple copies of image data. When a TIFF file is corrupted, current techniques cannot repair it to make it openable. Summary of the Invention

[0003] This application provides a method, apparatus, terminal device, and readable storage medium for repairing files, which can solve the problem that related technologies cannot repair TIFF files.

[0004] In a first aspect, embodiments of this application provide a method for repairing files, including:

[0005] Obtain the file to be repaired; the file to be repaired is a corrupted TIFF file.

[0006] Extract all IFDs from the file to be repaired;

[0007] Extract the image data corresponding to each IFD from the file to be repaired;

[0008] Match each IFD with a corresponding IFH;

[0009] Each IFD, its corresponding image data, and its corresponding IFH are assembled into a repair file, resulting in multiple repair files. Each repair file contains a complete TIFF image.

[0010] Secondly, embodiments of this application provide a file repair apparatus, comprising:

[0011] The acquisition module is used to acquire the file to be repaired, which is a corrupted TIFF file;

[0012] The first extraction module is used to extract all IFDs from the file to be repaired;

[0013] The second extraction module is used to extract the image data corresponding to each IFD from the file to be repaired;

[0014] The matching module is used to match a corresponding IFH for each IFD;

[0015] The assembly module is used to assemble each IFD, its corresponding image data, and its corresponding IFH into a repair file, resulting in multiple repair files. Each repair file contains a complete TIFF image.

[0016] Thirdly, embodiments of this application provide a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the above-mentioned file repair method.

[0017] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the above-described file repair method.

[0018] Fifthly, embodiments of this application provide a computer program product that, when run on a terminal device, causes the terminal device to execute the aforementioned file repair method.

[0019] The beneficial effects of this application embodiment compared with the prior art are as follows: This application embodiment first obtains the file to be repaired, extracts all IFDs from the file to be repaired, then extracts the image data corresponding to each IFD from the file to be repaired, then matches each IFD with a corresponding IFH, and assembles each IFD, its corresponding image data, and its corresponding IFH into a repair file, resulting in multiple repair files containing complete TIFF images. This application embodiment extracts all IFDs and their corresponding image data from the file to be repaired, matches each IFD with a corresponding IFH, and assembles each IFD, its corresponding image data, and its corresponding IFH into a repair file. Each repair file records a complete TIFF image, which is equivalent to extracting multiple image data from a damaged TIFF file and supplementing the corresponding data to obtain multiple TIFF files recording a single TIFF image. Each repair file in this application embodiment can be opened, realizing the repair of damaged TIFF files. Attached Figure Description

[0020] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0021] Figure 1This is a schematic diagram illustrating the implementation process of a file repair method provided in an embodiment of this application;

[0022] Figure 2 This is a schematic diagram of the implementation process for extracting all IFDs provided in the embodiments of this application;

[0023] Figure 3 This is a schematic diagram illustrating the implementation process of determining the storage method of the file to be repaired, as provided in an embodiment of this application.

[0024] Figure 4 This is a schematic diagram of the implementation process for extracting image data provided in an embodiment of this application;

[0025] Figure 5 This is a schematic diagram of the implementation process for matching IFH provided in the embodiments of this application;

[0026] Figure 6 This is a schematic diagram of the implementation process for correcting the target DE according to an embodiment of this application;

[0027] Figure 7 This is a schematic diagram of the structure of a document repair device provided in an embodiment of this application;

[0028] Figure 8 This is a schematic diagram of the structure of the terminal device provided in the embodiments of this application. Detailed Implementation

[0029] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are protected by this application.

[0030] It should be noted that the terms "comprising," "including," and "having," and any variations thereof, in the specification, claims, and accompanying drawings of this application, are intended to cover non-exclusive inclusion. For example, a process, method, terminal, product, or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices. Terms such as "first" and "second" in the claims, specification, and accompanying drawings of this application, as well as relational terms, are used merely to distinguish one entity / operation / object from another entity / operation / object, and do not necessarily require or imply any such immediate relationship or order between these entities / operations / objects.

[0031] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a mutually exclusive, independent, or alternative embodiment. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0032] Tag Image File Format (TIFF) is a flexible bitmap format primarily used to store images, including photographs and artwork. A TIFF file typically includes an IFH (image header), an IFD (image file directory), and the image data. The IFD may contain one or more DE (directory entries), and a single TIFF file may contain multiple copies of image data. When a TIFF file is corrupted, current techniques cannot repair it to make it openable.

[0033] Specifically, TIFF files may become corrupted in the following two ways:

[0034] 1. When the IFH of a TIFF file is overwritten by dirty data, the "II" and "MM" identifiers in the IFH (the "II" and "MM" identifiers are used to determine the endianness of the TIFF file, and only after determining the endianness of the TIFF file can the data in the TIFF file be further parsed) may not be found, resulting in the inability to correctly parse the data in the TIFF file. At this time, reading the IFH of the TIFF file will directly report an error, indicating that the file is corrupted.

[0035] 2. When the IFD of a TIFF file is covered by dirty data, parsing the IFD will fail. Since the last 4 bytes of each IFD in the TIFF file record the offset position of the next IFD, when an IFD is parsed incorrectly, all the IFDs after it cannot be parsed. At this time, parsing the TIFF file will also directly report an error, indicating that the file is corrupted.

[0036] Therefore, this embodiment extracts all IFDs and the image data corresponding to each IFD from the file to be repaired, matches a corresponding IFH to each IFD, and assembles each IFD, its corresponding image data, and its corresponding IFH into a repair file. This can repair damaged TIFF files, enabling them to be opened normally.

[0037] To illustrate the technical solution of this application, specific embodiments are described below.

[0038] Figure 1This illustration shows a flowchart of a file repair method provided in an embodiment of this application. This method can be applied to terminal devices. Terminal devices can be mobile phones, tablets, laptops, ultra-mobile personal computers (UMPCs), netbooks, etc.

[0039] Specifically, the repair method for the above-mentioned file may include the following steps S101 to S105.

[0040] Step S101: Obtain the file to be repaired.

[0041] The file to be repaired is a corrupted TIFF file. A TIFF file includes an IFH (image file header), an IFD (image file directory), and image data. The IFD may contain one or more DE (directory entries).

[0042] Specifically, the format of a normal TIFF file is as follows:

[0043] The IFH (Intended Memory Number) is a fixed 8 bytes long. Bytes 0-1 record the IFH identifier. The IFH identifier specifies the byte order within the file, including "II" and "MM". The "II" identifier indicates that the corresponding TIFF file is stored in little-endian format (Intel format, low byte first, high byte last); the "MM" identifier indicates that the corresponding TIFF file is stored in big-endian format (Motorala format, high byte first, low byte last). Bytes 2-3 of the IFH record the TIFF file version number. Bytes 4-7 of the IFH record a 32-bit offset (the offset indicates the position of the corresponding data in the file to be repaired), pointing to the first image file directory (IFD) of the TIFF file, which can be located anywhere in the TIFF file.

[0044] The length of an IFD is not fixed. Bytes 0-1 indicate the number of DEs contained in the IFD. The middle bytes record the details of the DEs it contains, and the last 4 bytes record the offset position of the next IFD.

[0045] DE is a type of metadata owned by IFD, with a fixed length of 12 bytes. Bytes 0-1 are TAG identifiers, used to indicate the type of information stored in the DE, such as image width information. The value range for bytes 0-1 is 255 to 65535. When the value corresponding to bytes 0-1 is lower than 255, the data segment corresponding to that byte is not a DE. Bytes 2-3 indicate the data type stored in the DE, such as byte, ACSII code, etc. The value range for bytes 2-3 is 1 to 20. Bytes 4-7 can indicate the number of data bytes corresponding to bytes 2-3. For example, if the data type corresponding to bytes 2-3 is byte (8-bit unsigned integer), and bytes 4-7 store the value 100, then this DE block will indicate a data block of 100 bytes. The value range for bytes 4-7 cannot exceed the size of the TIFF file. For example, if the size of the TIFF file is 800 bytes, then the value range for bytes 4-7 cannot exceed 800 bytes. Bytes 8-11 can be used to store the offset of a data block or several data blocks (such as image data). The numerical range corresponding to bytes 8-11 cannot exceed the size of the TIFF file.

[0046] In the embodiments of this application, the terminal device can directly obtain the file to be repaired input by the user, or it can directly retrieve the file to be repaired stored in the memory. The embodiments of this application do not limit the method of obtaining the file to be repaired.

[0047] Step S102: Extract all IFDs from the file to be repaired.

[0048] In the embodiments of this application, the terminal device can select two bytes in the file to be repaired, assuming these two bytes are bytes 0-1 of the IFD (Information Decision Function), read the values ​​corresponding to these two bytes, and determine whether these values ​​are greater than a preset value. If they are greater, the device reads the data following these two bytes based on their values, and determines whether the data following these two bytes is a DE block based on the data structure characteristics of the DE block, and whether the number of DE blocks is equal to the values ​​corresponding to these two bytes. If they are equal, it indicates that these two bytes are bytes 0-1 of the IFD, and the IFD corresponding to these two bytes can be extracted.

[0049] If the value corresponding to these two bytes is less than a preset value, or if the number of DE blocks mentioned above is not equal to the value corresponding to these two bytes, then these two bytes are not the 0-1 bytes of the IFD. In this case, the second byte and the byte following the second byte can be assumed to be the 0-1 bytes of the IFD, and the above operation can be repeated until the 0-1 bytes of the IFD are determined and the corresponding IFD is extracted. By analogy, all IFDs can be extracted from the file to be repaired.

[0050] Step S103: Extract the image data corresponding to each IFD from the file to be repaired.

[0051] In the embodiments of this application, some DEs in the IFD record the offset positions of image data. Therefore, the terminal device can locate the DE that records the offset positions of image data in the IFD and extract the image data corresponding to that IFD based on the recorded offset positions. Similarly, image data corresponding to each IFD can be extracted from the file to be repaired.

[0052] Step S104: Match each IFD with a corresponding IFH.

[0053] In the embodiments of this application, the terminal device can first determine the file storage method of the file to be repaired, and use the file storage method of the file to be repaired as the file storage method of each IFH. It can also determine the version number of the file to be repaired under the file storage method of the file to be repaired, and use the version number of the file to be repaired as the file storage method of each IFH. That is, the file storage method and version number of the IFH corresponding to each IFD are consistent with the file storage method and version number of the file to be repaired.

[0054] In this embodiment, the repaired file obtained after repairing the file to be repaired has a structure with IFH first, image data in the middle, and IFD last. Therefore, the terminal device can obtain the length of the image data corresponding to the IFD and combine it with the length of the IFH to obtain the offset position of the IFD. By assembling the file storage method, version number, and corresponding IFD offset position of the IFH, a complete IFH can be obtained. Similarly, each IFD can be matched with a corresponding IFH.

[0055] Step S105: Assemble each IFD, its corresponding image data, and its corresponding IFH into a repair file to obtain multiple repair files.

[0056] The repair file contains a complete TIFF image.

[0057] In the embodiments of this application, after obtaining an IFD, its corresponding image data, and its corresponding IFH, the data can be assembled into a repair file with the IFH first, the image data in the middle, and the IFD last. This repair file contains an IFH, a set of image data, and an IFD. Multiple repair files can be obtained in this manner.

[0058] The beneficial effects of this application embodiment compared with the prior art are as follows: This application embodiment first obtains the file to be repaired, extracts all IFDs from the file to be repaired, then extracts the image data corresponding to each IFD from the file to be repaired, then matches each IFD with a corresponding IFH, and assembles each IFD, its corresponding image data, and its corresponding IFH into a repair file, resulting in multiple repair files containing complete TIFF images. This application embodiment extracts all IFDs and their corresponding image data from the file to be repaired, matches each IFD with a corresponding IFH, and assembles each IFD, its corresponding image data, and its corresponding IFH into a repair file. Each repair file records a complete TIFF image, which is equivalent to extracting multiple image data from a damaged TIFF file and supplementing the corresponding data to obtain multiple TIFF files recording a single TIFF image. Each repair file in this application embodiment can be opened, realizing the repair of damaged TIFF files.

[0059] like Figure 2 As shown, in some embodiments of this application, the above-mentioned extraction of all IFDs from the file to be repaired may specifically include steps S201 to S204.

[0060] Step S201: Determine the storage method for the file to be repaired.

[0061] The storage method is used to parse the data in the file to be repaired. The storage methods include big-endian storage and little-endian storage. Different storage methods will retrieve different data.

[0062] like Figure 3 As shown, in some embodiments of this application, the above-mentioned method of determining the storage method of the file to be repaired may specifically include steps S301 to S304.

[0063] Step S301: Assuming the storage method of the file to be repaired is the first storage method, parse the DE in the file to be repaired according to the first storage method.

[0064] In embodiments of this application, the first storage method can be big-endian or little-endian. Assuming the first storage method is little-endian, the terminal device can use little-endian storage to parse the data in the file to be repaired, including DE.

[0065] Step S302: When the number of DEs parsed consecutively exceeds a preset value, the storage method of the file to be repaired is determined to be the first storage method.

[0066] In the embodiments of this application, the preset value can be set according to usage experience, for example, it can be set to 10 times. When the terminal device uses the first storage method to parse the DE in the file to be repaired, and the number of DEs parsed consecutively exceeds the preset value, it can be said that using the first storage method to parse the DE in the file to be repaired is correct, that is, the storage method of the file to be repaired is the first storage method.

[0067] Step S303: When the number of DEs parsed consecutively does not exceed the preset value, assuming that the storage method of the file to be repaired is the second storage method, the DEs in the file to be repaired are parsed according to the second storage method.

[0068] In the embodiments of this application, when the terminal device uses the first storage method to parse the DE in the file to be repaired, but the number of consecutively parsed DEs does not exceed a preset value, it can be understood that using the first storage method to parse the DE in the file to be repaired is incorrect, that is, the storage method of the file to be repaired is not the first storage method. At this time, it can be assumed that the storage method of the file to be repaired is the second storage method, and the DE in the file to be repaired is parsed according to the second storage method.

[0069] Step S304: When the number of continuously parsed DEs exceeds a preset value, the storage method of the file to be repaired is determined to be the second storage method.

[0070] It is worth noting that the second storage method is different from the first storage method. That is, if the first storage method is little-endian, then the second storage method is big-endian, and vice versa.

[0071] In the embodiments of this application, when the terminal device uses the second storage method to parse the DE in the file to be repaired, and the number of DEs parsed consecutively exceeds a preset value, it can be said that using the second storage method to parse the DE in the file to be repaired is correct, that is, the storage method of the file to be repaired is the second storage method.

[0072] In some embodiments of this application, after step S304, if the number of consecutively parsed DEs does not exceed a preset value, it can be considered that the file to be repaired is not a TIFF file, or that the file to be repaired is too severely damaged, and the repair of the file to be repaired can be abandoned.

[0073] Step S202: Search for all target bytes in the file to be repaired based on the storage method of the file to be repaired.

[0074] The target byte is the byte in each IFD that records the number of DEs in that IFD, i.e., the 0-1 bytes of the IFD. Each target byte corresponds to one IFD, and each target byte records the first number of DEs contained in the corresponding IFD. The first number of DEs indicates the number of DEs in the corresponding IFD recorded by the target byte.

[0075] In the embodiments of this application, after determining the storage method of the file to be repaired, the terminal device can parse the file to be repaired according to the storage method of the file to be repaired and search for all target bytes in the file to be repaired.

[0076] Step S203: Find the number of second DEs contained in the IFD corresponding to each target byte in the file to be repaired.

[0077] In the embodiments of this application, since DE has a special structure, namely, DE includes four parts: TAG identifier, data type, quantity, and value or offset position, the terminal device can determine whether a piece of data is a DE based on the data structure of DE. When the structural characteristics of a piece of data satisfy the four structural characteristics of DE, it can be said that the data is a DE. By analogy, the number of second DEs contained in the IFD corresponding to each target byte can be obtained.

[0078] Step S204: When the number of the first DE is equal to the number of the second DE, extract the DE corresponding to each IFD according to the number of the first DE or the number of the second DE, and obtain all IFDs.

[0079] In the embodiments of this application, when the number of first DEs (the number of DEs in the corresponding IFD recorded in the target byte) in a segment of data is equal to the number of second DEs (the number of DEs found by searching the structure of DEs in the corresponding IFD), it can be said that this segment of data is an IFD. That is, a segment of data that satisfies the condition that the number of first DEs is equal to the number of second DEs can be identified as an IFD. At this time, the terminal device can extract all DEs in this segment of data and assemble them to obtain an IFD. In this way, all IFDs can be obtained.

[0080] like Figure 4 As shown, in some embodiments of this application, the above-mentioned extraction of image data corresponding to each IFD from the file to be repaired may specifically include steps S401 to S403.

[0081] Step S401: Find the first target DE that satisfies the first preset identifier from each IFD.

[0082] Wherein, the first preset identifier corresponds to the first target DE, the first preset identifier is used to identify the DE that stores the image data, and the first target DE stores the offset position of the image data.

[0083] In the embodiments of this application, different DEs have different identifiers, that is, a specific DE can be determined based on a specific identifier. Each IFD contains a DE at an offset position for storing image data. The terminal device can search for a DE (i.e., a first target DE) that satisfies a first preset identifier in each IFD, that is, the identifier of the first target DE is the same as the first preset identifier.

[0084] Step S402: Find the offset position of the corresponding image data from each first target DE.

[0085] In the embodiments of this application, the last 4 bytes of the first target DE record the offset position of the corresponding image data. After the terminal device finds all the first target DEs, it can read the last 4 bytes of each first target DE to obtain the offset position of the corresponding image data.

[0086] Step S403: Extract the image data corresponding to each IFD from the file to be repaired based on the offset position of each image data.

[0087] In the embodiments of this application, after obtaining the offset position of the image data corresponding to each IFD, the terminal device can jump to the offset position of each image data and extract the image data corresponding to each IFD.

[0088] like Figure 5 As shown, in some embodiments of this application, the above-mentioned matching of each IFD with a corresponding IFH may specifically include steps S501 to S505.

[0089] Step S501: Determine the storage method of the file to be repaired, and obtain the corresponding storage method bytes based on the storage method of the file to be repaired.

[0090] The storage method is used to parse the data in the file to be repaired. The storage method byte is used to characterize the storage method of the TIFF file.

[0091] In the embodiments of this application, the specific steps for determining the storage method of the file to be repaired can be referred to steps S301 to S304 above, and will not be repeated here. In IFH, different storage methods correspond to different storage method bytes. After determining the storage method of the file to be repaired, the terminal device can obtain the corresponding storage method bytes according to the storage method of the file to be repaired.

[0092] For example, assuming the file to be repaired is stored in little-endian format, the corresponding storage bytes would be 0x4949. If the file is stored in big-endian format, the corresponding storage bytes would be 0x4d4d.

[0093] Step S502: Determine the version number byte of IFH based on the storage method of the file to be repaired.

[0094] The version number byte is used to represent the version number of the IFH.

[0095] In the embodiments of this application, the version number of IFH is fixed, typically 42. Therefore, the terminal device can determine the version number byte of IFH based on the storage method of the file to be repaired, which is 2A.

[0096] Step S503: Obtain the length of the image data corresponding to each IFD.

[0097] In the embodiments of this application, after the terminal device extracts the image data corresponding to each IFD, the length of each image data can be obtained.

[0098] Step S504: Determine the offset position byte of each IFD based on the length of each image data.

[0099] The offset position byte is used to characterize the offset position of the IFD.

[0100] In the embodiments of this application, the last 4 bytes of IFH are used to characterize the offset position of the corresponding IFD. In the embodiments of this application, the structure of the repair file is IFH first, image data in the middle, and IFD last. The above data is assembled into a repair file, which contains an IFH, a set of image data, and an IFD. Therefore, after obtaining the length of the image data, the length of IFH and the length of the image data can be added together to obtain the offset position of the IFD, and then the corresponding offset position bytes are obtained.

[0101] Step S505: Assemble the storage method byte, version number byte, and each offset position byte to obtain the IFH corresponding to each IFD.

[0102] In the embodiments of this application, the terminal device can assemble the IFH corresponding to each IFD in the order of storage method byte first, version number byte in the middle, and offset position byte last.

[0103] like Figure 6 As shown, in some embodiments of this application, after extracting all IFDs from the file to be repaired, the file repair method may further include steps S601 to S606.

[0104] Step S601: Search for the second target DE that satisfies the second preset identifier from the IFD.

[0105] The second preset identifier is used to identify the DE storing the target information, which includes a timestamp and a filename. There can be multiple second preset identifiers to correspond to either the timestamp or the filename.

[0106] In the embodiments of this application, different DEs have different identifiers, that is, a specific DE can be determined based on a specific identifier. Some IFDs contain a DE at an offset position of a timestamp or filename. The terminal device can search for a DE (i.e., a second target DE) that satisfies a second preset identifier in the IFD, that is, the identifier of the second target DE is the same as the second preset identifier.

[0107] Step S602: Obtain the original offset position of the target information in the second target DE.

[0108] The original offset position is the offset position of the target information recorded in the file to be repaired in the second target DE.

[0109] In the embodiments of this application, the last 4 bytes of the second target DE record the original offset position of the target information. The terminal device can obtain the original offset position of the target information by reading the last 4 bytes of the second target DE.

[0110] Step S603: Locate the target information based on the original offset position of the target information.

[0111] In the embodiments of this application, the target information possesses strong characteristics. For example, the timestamp format is nnnn:nn:nn nn:nn:nn (n is 0-9), specifically 2017:04:04 17:49:13. Another example is that the filename usually ends with ".tiff" or ".tif". The terminal device can jump to the original offset position of the target information in the document to be repaired and determine whether the target information exists at the original offset position based on the above characteristics.

[0112] Step S604: If the target information is not found based on the offset position of the target information, then the target information is searched based on the data features of the target information.

[0113] In the embodiments of this application, if the target information is not found based on its offset position, it indicates that the offset position of the target information has deviated. In this case, the terminal device can locate the target information near its original offset position using the data characteristics of the target information.

[0114] Step S605: If the target information is found based on the data features of the target information, then obtain the actual offset position of the target information.

[0115] The actual offset position is the actual offset position of the target information in the file to be repaired.

[0116] In the embodiments of this application, if the target information is found by utilizing the data features of the target information, the offset position of the target information at this time can be obtained, and the actual offset position can be obtained.

[0117] Step S606: Correct the offset of all DEs in the IFD containing the second target DE according to the actual offset position.

[0118] In the embodiments of this application, the DEs in the IFD are continuous. When the offset position of the data recorded in one DE deviates, the offset positions of the data recorded in other DEs will also deviate in the same way. Therefore, after obtaining the offset position deviation, the terminal device can correct the offset of all DEs in the IFD containing the second target DE. Specifically, based on the original offset position and the actual offset position of the target information, the offset position deviation of the data recorded in the DE is obtained. Based on the offset position deviation, the content of the last 4 bytes of these DEs is modified from the original offset position of the data to the actual offset position.

[0119] The embodiments of this application can correct the offset positions of all DEs in the IFD based on the target information, thereby improving the success rate of repair.

[0120] In some embodiments of this application, the terminal device can record the actual offset of the target information and store it in a table. This allows for direct lookup of the actual offset position of the corresponding target information during correction, thereby improving the correction speed.

[0121] In some embodiments of this application, the method for repairing the above-mentioned file further includes: extracting all non-TIFF image data from the file to be repaired, wherein the non-TIFF image data includes JPEG images.

[0122] In the embodiments of this application, since TIFF files have good inclusiveness, the file to be repaired may also contain other image data besides TIFF format, such as JPEG image data.

[0123] Specifically, the terminal device can look for bytes containing 0xff 0xd8 0xff in the file to be repaired. This byte represents the header of the JPEG image data file. After the header, it looks for bytes containing 0xff 0xd9, which represents the footer of the JPEG image data file. Extracting this data from the header to the footer yields a JPEG image. This process can be repeated to obtain all JPEG images.

[0124] Figure 7This illustration shows a structural diagram of a file repair device according to an embodiment of this application. The file repair device 7 can be configured on a terminal device. Specifically, the file repair device 7 may include:

[0125] The acquisition module 701 is used to acquire the file to be repaired, which is a corrupted TIFF file;

[0126] The first extraction module 702 is used to extract all IFDs from the file to be repaired;

[0127] The second extraction module 703 is used to extract the image data corresponding to each IFD from the file to be repaired;

[0128] Matching module 704 is used to match a corresponding IFH for each IFD;

[0129] Assembly module 705 is used to assemble each IFD, the corresponding image data and the corresponding IFH into a repair file, resulting in multiple repair files, each containing a complete TIFF image.

[0130] The beneficial effects of this application embodiment compared with the prior art are as follows: This application embodiment first obtains the file to be repaired, extracts all IFDs from the file to be repaired, then extracts the image data corresponding to each IFD from the file to be repaired, then matches each IFD with a corresponding IFH, and assembles each IFD, its corresponding image data, and its corresponding IFH into a repair file, resulting in multiple repair files containing complete TIFF images. This application embodiment extracts all IFDs and their corresponding image data from the file to be repaired, matches each IFD with a corresponding IFH, and assembles each IFD, its corresponding image data, and its corresponding IFH into a repair file. Each repair file records a complete TIFF image, which is equivalent to extracting multiple image data from a damaged TIFF file and supplementing the corresponding data to obtain multiple TIFF files recording a single TIFF image. Each repair file in this application embodiment can be opened, realizing the repair of damaged TIFF files.

[0131] In some embodiments of this application, the first extraction module 702 is further configured to: determine the storage method of the file to be repaired, wherein the storage method is used to parse the data in the file to be repaired; search for all target bytes in the file to be repaired based on the storage method of the file to be repaired, wherein each target byte corresponds to an IFD, and each target byte records the number of first DEs contained in the corresponding IFD; search for the number of second DEs contained in the IFD corresponding to each target byte in the file to be repaired; when the number of first DEs is equal to the number of second DEs, extract the DEs corresponding to each IFD according to the number of first DEs or the number of second DEs, thereby obtaining all IFDs.

[0132] In some embodiments of this application, the first extraction module 702 is further configured to: assume that the storage method of the file to be repaired is a first storage method, and parse the DE in the file to be repaired according to the first storage method; when the number of consecutively parsed DEs exceeds a preset value, determine that the storage method of the file to be repaired is the first storage method; when the number of consecutively parsed DEs does not exceed the preset value, assume that the storage method of the file to be repaired is a second storage method, and parse the DE in the file to be repaired according to the second storage method; when the number of consecutively parsed DEs exceeds the preset value, determine that the storage method of the file to be repaired is the second storage method.

[0133] In some embodiments of this application, the IFD includes one or more DEs, and the second extraction module 703 is further configured to: find a first target DE that satisfies a first preset identifier from each IFD, the first preset identifier being used to identify the DE storing image data; find the offset position of the corresponding image data from each first target DE; and extract the image data corresponding to each IFD from the file to be repaired based on the offset position of each image data.

[0134] In some embodiments of this application, the matching module 704 is further configured to: determine the storage method of the file to be repaired; obtain the corresponding storage method byte based on the storage method of the file to be repaired; the storage method is used to parse the data in the file to be repaired; determine the version number byte of the IFH based on the storage method of the file to be repaired; obtain the length of the image data corresponding to each IFD; determine the offset position byte of each IFD based on the length of each image data; and assemble the storage method byte, the version number byte, and each offset position byte to obtain the IFH corresponding to each IFD.

[0135] In some embodiments of this application, the document repair device 7 further includes a correction module, configured to: search for a second target DE that satisfies a second preset identifier in the IFD, the second preset identifier being used to identify the DE storing target information, the target information including a timestamp and a filename; obtain the original offset position of the target information in the second target DE; search for the target information based on the original offset position of the target information; if the target information is not found based on the offset position of the target information, then search for the target information based on the data characteristics of the target information; if the target information is found based on the data characteristics of the target information, then obtain the actual offset position of the target information; and correct all DEs in the IFD containing the second target DE based on the actual offset position.

[0136] In some embodiments of this application, the file repair device 7 further includes a third extraction module for: extracting all non-TIFF image data from the file to be repaired, the non-TIFF image data including JPEG images.

[0137] like Figure 8 The diagram shown is a schematic of a terminal device provided in an embodiment of this application. The terminal device 8 may include: a processor 801, a memory 802, and a computer program 803 stored in the memory 802 and executable on the processor 801, such as a file repair program. When the processor 801 executes the computer program 803, it implements the steps in the aforementioned file repair method embodiments, for example... Figure 1 Steps S101 to S105 are shown. Alternatively, when the processor 801 executes the computer program 803, it implements the functions of each module / unit in the above-described device embodiments, for example... Figure 7 The module shown includes an acquisition module 701, a first extraction module 702, a second extraction module 703, a matching module 704, and an assembly module 705.

[0138] The computer program can be divided into one or more modules / units, which are stored in the memory 802 and executed by the processor 801 to complete this application. The one or more modules / units can be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program in the terminal device.

[0139] The terminal device may include, but is not limited to, a processor 801 and a memory 802. Those skilled in the art will understand that... Figure 8 This is merely an example of a terminal device and does not constitute a limitation on the terminal device. It may include more or fewer components than shown, or combine certain components, or different components. For example, the terminal device may also include input / output devices, network access devices, buses, etc.

[0140] The processor 801 may be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.

[0141] The memory 802 can be an internal storage unit of the terminal device, such as a hard drive or memory. The memory 802 can also be an external storage device of the terminal device, such as a plug-in hard drive, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card. Furthermore, the memory 802 can include both internal and external storage units of the terminal device. The memory 802 is used to store the computer program and other programs and data required by the terminal device. The memory 802 can also be used to temporarily store data that has been output or will be output.

[0142] It should be noted that, for the sake of convenience and brevity, the structure of the terminal device described above can also be referred to the specific description of the structure in the method embodiment, which will not be repeated here.

[0143] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0144] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, can implement the steps in the above-described file repair method.

[0145] This application provides a computer program product that, when run on a mobile terminal, enables the mobile terminal to implement the steps in the above-mentioned file repair method.

[0146] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0147] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for various specific applications, but such implementations should not be considered beyond the scope of this application.

[0148] In the embodiments provided in this application, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling or direct coupling or communication connection may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0149] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0150] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0151] If the integrated module / unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.

[0152] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

Claims

1. A method for repairing files, characterized in that, include: Obtain the file to be repaired, which is a corrupted TIFF file; Extract all IFDs from the file to be repaired; Extract the image data corresponding to each IFD from the file to be repaired; Assign a corresponding IFH to each of the IFDs; Each IFD, its corresponding image data, and its corresponding IFH are assembled into a repair file, resulting in multiple repair files, each containing a complete TIFF image; wherein, extracting all IFDs from the file to be repaired includes: Determine the storage method of the file to be repaired, the storage method being used to parse the data in the file to be repaired; Based on the storage method of the file to be repaired, all target bytes are searched in the file to be repaired. Each target byte corresponds to an IFD, and each target byte records the number of first DEs contained in the corresponding IFD. Find the number of second DEs contained in the IFD corresponding to each target byte in the file to be repaired; When the number of the first DE is equal to the number of the second DE, the DE corresponding to each IFD is extracted according to the number of the first DE or the number of the second DE, and all IFDs are obtained.

2. The file repair method as described in claim 1, characterized in that, Determining the storage method of the file to be repaired includes: Assuming the file to be repaired is stored in the first storage method, the DE in the file to be repaired is parsed according to the first storage method; When the number of consecutively parsed DEs exceeds a preset value, the storage method of the file to be repaired is determined to be the first storage method; When the number of DEs parsed consecutively does not exceed the preset value, assuming that the storage method of the file to be repaired is the second storage method, the DEs in the file to be repaired are parsed according to the second storage method. When the number of DEs parsed consecutively exceeds the preset value, the storage method of the file to be repaired is determined to be the second storage method.

3. The file repair method as described in claim 1, characterized in that, The IFD includes one or more DEs, and the step of extracting the image data corresponding to each IFD from the file to be repaired includes: Find the first target DE that satisfies the first preset identifier from each of the IFDs, where the first preset identifier is used to identify the DE that stores the image data; Find the offset position of the corresponding image data in each of the first targets DE; Based on the offset position of each of the image data, the image data corresponding to each IFD is extracted from the file to be repaired.

4. The file repair method as described in claim 1, characterized in that, Matching each IFD with a corresponding IFH includes: Determine the storage method of the file to be repaired, and obtain the corresponding storage method bytes based on the storage method of the file to be repaired. The storage method is used to parse the data in the file to be repaired. The version number byte of the IFH is determined based on the storage method of the file to be repaired; Obtain the length of the image data corresponding to each IFD; The offset position byte of each IFD is determined based on the length of each image data; The storage method byte, the version number byte, and each offset position byte are assembled to obtain the IFH corresponding to each IFD.

5. The file repair method as described in claim 1, characterized in that, After extracting all IFDs from the file to be repaired, the method further includes: Find a second target DE that satisfies the second preset identifier from the IFD. The second preset identifier is used to identify the DE that stores target information, including a timestamp and a filename. Obtain the original offset position of the target information in the second target DE; The target information is located based on its original offset position. If the target information is not found based on its offset position, then the target information is searched based on its data features. If the target information is found based on the data features of the target information, then the actual offset position of the target information is obtained; Based on the actual offset position, all DEs in the IFD containing the second target DE are corrected.

6. The method for repairing files as described in any one of claims 1 to 5, characterized in that, The method further includes: Extract all non-TIFF image data from the file to be repaired, including JPEG images.

7. A document repair device, characterized in that, include: The acquisition module is used to acquire the file to be repaired, which is a corrupted TIFF file; The first extraction module is used to extract all IFDs from the file to be repaired; The second extraction module is used to extract the image data corresponding to each IFD from the file to be repaired; The matching module is used to match a corresponding IFH for each IFD; An assembly module is used to assemble each IFD, the corresponding image data, and the corresponding IFH into a repair file, resulting in multiple repair files, each repair file containing a complete TIFF image; wherein, extracting all IFDs from the file to be repaired includes: Determine the storage method of the file to be repaired, the storage method being used to parse the data in the file to be repaired; Based on the storage method of the file to be repaired, all target bytes are searched in the file to be repaired. Each target byte corresponds to an IFD, and each target byte records the number of first DEs contained in the corresponding IFD. Find the number of second DEs contained in the IFD corresponding to each target byte in the file to be repaired; When the number of the first DE is equal to the number of the second DE, the DE corresponding to each IFD is extracted according to the number of the first DE or the number of the second DE, and all IFDs are obtained.

8. A terminal device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the file repair method as described in any one of claims 1 to 6.

9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the file repair method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Image file restoration method

    CN111028135A