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, a first memory stores
encoded data of a shorter encode length among encoded data generated by a
first encoding unit which performs lossy encoding and encoded data
generated by a second encoding unit which performs lossless encoding. A
second memory stores encoded data from a second encoding unit. When an
encoding sequence control unit determines that the encoded data amount in
the first memory has exceeded the target data amount, the encoding
sequence control unit discards data in the first memory, sets a
quantization parameter for a higher compression ratio for the first
encoding unit, and causes the first encoding unit to execute encoding.
Encoded data before the encoded data amount is determined to have
exceeded the target data amount is re-encoded by a re-encoding unit.