According to this invention, degradation of the image quality of a decoded
image is reduced while losslessly encoded data and lossily encoded data
coexist. For this purpose, a first encoding unit performs JPEG encoding
for each pixel block, and a second encoding unit performs JPEG-LS
encoding. Letting Lx be the code length of encoded data generated by the
first encoding unit and Ly be the code length of encoded data generated
by the second encoding unit, an encoding sequence control unit selects
one of the two encoded data and stores the selected data in a first
memory in accordance with whether Lx and Ly satisfy a predetermined
non-linear boundary function f( ): Ly.gtoreq.f(Lx). At this time, when
the axis of abscissas represents the code length of the encoded data
generated by the second encoding unit and the axis of ordinates
represents that of the encoded data generated by the first encoding unit,
the non-linear boundary function f( ) has a curved portion at the two
code lengths.