mirror of
https://github.com/cc65/cc65.git
synced 2025-01-12 02:30:44 +00:00
Add support for 4 pixels per plane
This commit is contained in:
parent
de30a57c0c
commit
817d129be8
171
src/sp65/pcx.c
171
src/sp65/pcx.c
@ -153,11 +153,12 @@ static PCXHeader* ReadPCXHeader (FILE* F, const char* Name)
|
|||||||
P->Compressed, Name);
|
P->Compressed, Name);
|
||||||
}
|
}
|
||||||
/* We support:
|
/* We support:
|
||||||
** - one plane with either 1 or 8 bits per pixel
|
* - one plane with either 1, 4 or 8 bits per pixel
|
||||||
** - three planes with 8 bits per pixel
|
* - three planes with 8 bits per pixel
|
||||||
** - four planes with 8 bits per pixel (does this exist?)
|
* - four planes with 8 bits per pixel (does this exist?)
|
||||||
*/
|
*/
|
||||||
if (!((P->BPP == 1 && P->Planes == 1) ||
|
if (!((P->BPP == 1 && P->Planes == 1) ||
|
||||||
|
(P->BPP == 4 && P->Planes == 1) ||
|
||||||
(P->BPP == 8 && (P->Planes == 1 || P->Planes == 3 || P->Planes == 4)))) {
|
(P->BPP == 8 && (P->Planes == 1 || P->Planes == 3 || P->Planes == 4)))) {
|
||||||
/* We could support others, but currently we don't */
|
/* We could support others, but currently we don't */
|
||||||
Error ("Unsupported PCX format: %u planes, %u bpp in PCX file '%s'",
|
Error ("Unsupported PCX format: %u planes, %u bpp in PCX file '%s'",
|
||||||
@ -204,11 +205,14 @@ static void DumpPCXHeader (const PCXHeader* P, const char* Name)
|
|||||||
static void ReadPlane (FILE* F, PCXHeader* P, unsigned char* L)
|
static void ReadPlane (FILE* F, PCXHeader* P, unsigned char* L)
|
||||||
/* Read one (possibly compressed) plane from the file */
|
/* Read one (possibly compressed) plane from the file */
|
||||||
{
|
{
|
||||||
if (P->Compressed) {
|
unsigned i;
|
||||||
|
|
||||||
|
if (P->Compressed) {
|
||||||
/* Uncompress RLE data */
|
/* Uncompress RLE data */
|
||||||
unsigned Remaining = P->Width;
|
signed Remaining = P->BytesPerPlane;
|
||||||
while (Remaining) {
|
signed WidthCounter = P->Width;
|
||||||
|
|
||||||
|
while (Remaining > 0) {
|
||||||
|
|
||||||
unsigned char C;
|
unsigned char C;
|
||||||
|
|
||||||
@ -224,21 +228,111 @@ static void ReadPlane (FILE* F, PCXHeader* P, unsigned char* L)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Write the data to the buffer */
|
/* Write the data to the buffer */
|
||||||
if (C > Remaining) {
|
switch (P->BPP) {
|
||||||
C = Remaining;
|
default:
|
||||||
}
|
for (i = 0; i < C; i++) {
|
||||||
memset (L, B, C);
|
if (WidthCounter > 0) {
|
||||||
|
*L = B;
|
||||||
/* Bump counters */
|
L += 1;
|
||||||
L += C;
|
WidthCounter -= 1;
|
||||||
Remaining -= C;
|
}
|
||||||
|
Remaining -= 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
for (i = 0; i < C; i++) {
|
||||||
|
if (WidthCounter > 0) {
|
||||||
|
*L = B >> 4;
|
||||||
|
L += 1;
|
||||||
|
WidthCounter -= 1;
|
||||||
|
}
|
||||||
|
if (WidthCounter > 0) {
|
||||||
|
*L = B & 15;
|
||||||
|
L += 1;
|
||||||
|
WidthCounter -= 1;
|
||||||
|
}
|
||||||
|
Remaining -= 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
for (i = 0; i < C; i++) {
|
||||||
|
if (WidthCounter > 0) {
|
||||||
|
*L = (B >> 6) & 3;
|
||||||
|
L += 1;
|
||||||
|
WidthCounter -= 1;
|
||||||
|
}
|
||||||
|
if (WidthCounter > 0) {
|
||||||
|
*L = (B >> 4) & 3;
|
||||||
|
L += 1;
|
||||||
|
WidthCounter -= 1;
|
||||||
|
}
|
||||||
|
if (WidthCounter > 0) {
|
||||||
|
*L = (B >> 2) & 3;
|
||||||
|
L += 1;
|
||||||
|
WidthCounter -= 1;
|
||||||
|
}
|
||||||
|
if (WidthCounter > 0) {
|
||||||
|
*L = B & 3;
|
||||||
|
L += 1;
|
||||||
|
WidthCounter -= 1;
|
||||||
|
}
|
||||||
|
Remaining -= 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
for (i = 0; i < C; i++) {
|
||||||
|
if (WidthCounter > 0) {
|
||||||
|
*L = (B >> 7) & 1;
|
||||||
|
L += 1;
|
||||||
|
WidthCounter -= 1;
|
||||||
|
}
|
||||||
|
if (WidthCounter > 0) {
|
||||||
|
*L = (B >> 6) & 1;
|
||||||
|
L += 1;
|
||||||
|
WidthCounter -= 1;
|
||||||
|
}
|
||||||
|
if (WidthCounter > 0) {
|
||||||
|
*L = (B >> 5) & 1;
|
||||||
|
L += 1;
|
||||||
|
WidthCounter -= 1;
|
||||||
|
}
|
||||||
|
if (WidthCounter > 0) {
|
||||||
|
*L = (B >> 4) & 1;
|
||||||
|
L += 1;
|
||||||
|
WidthCounter -= 1;
|
||||||
|
}
|
||||||
|
if (WidthCounter > 0) {
|
||||||
|
*L = (B >> 3) & 1;
|
||||||
|
L += 1;
|
||||||
|
WidthCounter -= 1;
|
||||||
|
}
|
||||||
|
if (WidthCounter > 0) {
|
||||||
|
*L = (B >> 2) & 1;
|
||||||
|
L += 1;
|
||||||
|
WidthCounter -= 1;
|
||||||
|
}
|
||||||
|
if (WidthCounter > 0) {
|
||||||
|
*L = (B >> 1) & 1;
|
||||||
|
L += 1;
|
||||||
|
WidthCounter -= 1;
|
||||||
|
}
|
||||||
|
if (WidthCounter > 0) {
|
||||||
|
*L = B & 1;
|
||||||
|
L += 1;
|
||||||
|
WidthCounter -= 1;
|
||||||
|
}
|
||||||
|
Remaining -= 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* Just read one line */
|
/* Just read one line */
|
||||||
ReadData (F, L, P->Width);
|
if (P->BPP == 4) {
|
||||||
|
printf("Not implemented\n");
|
||||||
|
} else {
|
||||||
|
ReadData (F, L, P->Width);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,25 +403,42 @@ Bitmap* ReadPCXFile (const Collection* A)
|
|||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* One plane with 8bpp is indexed */
|
if (P->BPP == 4) {
|
||||||
for (Y = 0, Px = B->Data; Y < P->Height; ++Y) {
|
/* One plane with 8bpp is indexed */
|
||||||
|
for (Y = 0, Px = B->Data; Y < P->Height; ++Y) {
|
||||||
|
|
||||||
/* Read the plane */
|
/* Read the plane */
|
||||||
ReadPlane (F, P, L);
|
ReadPlane (F, P, L);
|
||||||
|
|
||||||
/* Create pixels */
|
/* Create pixels */
|
||||||
for (X = 0; X < P->Width; ++X, ++Px) {
|
for (X = 0; X < P->Width; ++X, ++Px) {
|
||||||
if (L[X] > MaxIdx) {
|
if (L[X] > MaxIdx) {
|
||||||
MaxIdx = L[X];
|
MaxIdx = L[X];
|
||||||
|
}
|
||||||
|
Px->Index = L[X];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* One plane with 8bpp is indexed */
|
||||||
|
for (Y = 0, Px = B->Data; Y < P->Height; ++Y) {
|
||||||
|
|
||||||
|
/* Read the plane */
|
||||||
|
ReadPlane (F, P, L);
|
||||||
|
|
||||||
|
/* Create pixels */
|
||||||
|
for (X = 0; X < P->Width; ++X, ++Px) {
|
||||||
|
if (L[X] > MaxIdx) {
|
||||||
|
MaxIdx = L[X];
|
||||||
|
}
|
||||||
|
Px->Index = L[X];
|
||||||
}
|
}
|
||||||
Px->Index = L[X];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* One plane means we have a palette which is either part of the header
|
/* One plane means we have a palette which is either part of the header
|
||||||
** or follows.
|
* or follows.
|
||||||
*/
|
*/
|
||||||
if (P->PalInfo == 0) {
|
if (P->PalInfo == 0) {
|
||||||
|
|
||||||
/* Create the monochrome palette */
|
/* Create the monochrome palette */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user