According to this invention, encoded data of a target data amount is generated by one image input operation while both lossless encoding and lossy encoding are adopted. For this purpose, an encoding sequence control unit controls a first encoding unit for lossy (JPEG) encoding, a second encoding unit for lossless (JPEG-LS) encoding, first and second memories, and a re-encoding unit, and stores, in a first memory, encoded data of a target data amount or less that contains both losslessly and lossily encoded data. A correction unit corrects, of encoded data stored in the first memory, encoded data of an isolated type to the type of neighboring encoded data, and outputs the corrected data.