603
657
tmpmap[i*3+2] = map256[i+512];
606
memcpy(map256, tmpmap, 3 * 256);
660
memcpy (map256, tmpmap, 3 * 256);
611
dispatch_resID(guint ID, FILE *fd, guint32 *offset, guint32 Size)
665
dispatch_resID (guint ID,
613
if ( (ID < 0x0bb6) && (ID >0x07d0) )
670
if ( (ID <= 0x0bb6) && (ID >= 0x07d0) ) /* 2998 && 2000 */
615
IFDBG printf ("\t\tPath data is irrelevant to GIMP at this time.\n");
616
throwchunk(Size, fd, "dispatch_res path throw");
672
IFDBG printf ("\t\tThe psd plugin does not currently support reading path data.\n");
673
throwchunk (Size, fd, "dispatch_res path throw");
617
674
(*offset) += Size;
624
gint32 remaining = Size;
626
IFDBG printf ("\t\tALPHA CHANNEL NAMES:\n");
633
slen = getguchar (fd, "alpha channel name length");
637
/* Check for (Mac?) Photoshop (4?) file-writing bug */
638
if (slen > remaining)
640
IFDBG {printf("\nYay, a file bug. "
641
"Yuck. Photoshop 4/Mac? "
642
"I'll work around you.\n");fflush(stdout);}
648
guint32 alpha_name_len;
649
gchar* sname = getstring(slen, fd, "alpha channel name");
651
alpha_name_len = strlen(sname);
653
(*offset) += alpha_name_len;
654
remaining -= alpha_name_len;
656
sname = sanitise_string(sname);
658
psd_image.aux_channel[psd_image.num_aux_channels].name =
661
IFDBG printf("\t\t\tname: \"%s\"\n",
662
psd_image.aux_channel[psd_image.num_aux_channels].name);
666
psd_image.aux_channel[psd_image.num_aux_channels].name =
669
{printf("\t\t\tNull channel name %d.\n",
670
psd_image.num_aux_channels);fflush(stdout);}
673
psd_image.num_aux_channels++;
675
if (psd_image.num_aux_channels > MAX_CHANNELS)
677
printf("\nPSD: Sorry - this image has too many "
678
"aux channels. Tell Adam!\n");
682
while (remaining > 0);
688
dumpchunk(remaining, fd, "alphaname padding 0 throw");
690
throwchunk(remaining, fd, "alphaname padding 0 throw");
691
(*offset) += remaining;
697
IFDBG printf("\t\tDISPLAYINFO STRUCTURE: unhandled\n");
698
throwchunk(Size, fd, "dispatch_res");
701
case 0x03f0: /* FIXME: untested */
703
psd_image.caption = getpascalstring(fd, "caption string");
706
if (psd_image.caption)
708
IFDBG printf("\t\t\tcontent: \"%s\"\n",psd_image.caption);
709
(*offset) += strlen(psd_image.caption);
714
IFDBG printf("\t\tBACKGROUND COLOR: unhandled\n");
715
throwchunk(Size, fd, "dispatch_res");
719
IFDBG printf("\t\tGREY/MULTICHANNEL HALFTONING INFO: unhandled\n");
720
throwchunk(Size, fd, "dispatch_res");
724
IFDBG printf("\t\tCOLOUR HALFTONING INFO: unhandled\n");
725
throwchunk(Size, fd, "dispatch_res");
729
IFDBG printf("\t\tDUOTONE HALFTONING INFO: unhandled\n");
730
throwchunk(Size, fd, "dispatch_res");
734
IFDBG printf("\t\tGREYSCALE/MULTICHANNEL TRANSFER FUNCTION: unhandled\n");
735
throwchunk(Size, fd, "dispatch_res");
739
IFDBG printf("\t\tCOLOUR TRANSFER FUNCTION: unhandled\n");
740
throwchunk(Size, fd, "dispatch_res");
744
IFDBG printf("\t\tDUOTONE TRANSFER FUNCTION: unhandled\n");
745
throwchunk(Size, fd, "dispatch_res");
749
IFDBG printf("\t\tDUOTONE IMAGE INFO: unhandled\n");
750
throwchunk(Size, fd, "dispatch_res");
754
IFDBG printf("\t\tEFFECTIVE BLACK/WHITE VALUES: unhandled\n");
755
throwchunk(Size, fd, "dispatch_res");
759
IFDBG printf("\t\tQUICK MASK INFO: unhandled\n");
760
throwchunk(Size, fd, "dispatch_res");
765
IFDBG printf("\t\tLAYER STATE INFO:\n");
766
psd_image.active_layer_num = getgshort(fd, "ID target_layer_num");
768
IFDBG printf("\t\t\ttarget: %d\n",(gint)psd_image.active_layer_num);
773
IFDBG printf("\t\tLAYER GROUP INFO: unhandled\n");
774
IFDBG printf("\t\t\t(Inferred number of layers: %d)\n",(gint)(Size/2));
775
throwchunk(Size, fd, "dispatch_res");
779
IFDBG printf ("\t\tIMAGE MODE FOR RAW FORMAT: unhandled\n");
780
throwchunk(Size, fd, "dispatch_res");
785
gint32 remaining = Size;
787
IFDBG printf ("\t\tGUIDE INFORMATION:\n");
791
gshort magic1, magic2, magic3, magic4, magic5, magic6;
795
magic1 = getgshort(fd, "guide"); (*offset) += 2;
796
magic2 = getgshort(fd, "guide"); (*offset) += 2;
797
magic3 = getgshort(fd, "guide"); (*offset) += 2;
798
magic4 = getgshort(fd, "guide"); (*offset) += 2;
799
magic5 = getgshort(fd, "guide"); (*offset) += 2;
800
magic6 = getgshort(fd, "guide"); (*offset) += 2;
803
IFDBG printf("\t\t\tMagic: %d %d %d %d %d %d\n",
804
magic1, magic2, magic3, magic4, magic5, magic6);
805
IFDBG printf("\t\t\tMagic: 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
806
magic1, magic2, magic3, magic4, magic5, magic6);
808
num_guides = getglong(fd, "guide");
809
(*offset) += 4; remaining -= 4;
811
if (remaining != num_guides*5)
813
IFDBG printf ("** FUNNY AMOUNT OF GUIDE DATA (%d)\n",
815
goto funny_amount_of_guide_data;
818
IFDBG printf("\t\t\tNumber of guides is %ld\n", num_guides);
819
psd_image.num_guides = num_guides;
820
psd_image.guides = g_new(PSDguide, num_guides);
821
guide = psd_image.guides;
823
for (i = 0; i < num_guides; i++, guide++)
825
guide->position = getglong(fd, "guide");
827
guide->horizontal = (1 == getguchar(fd, "guide"));
828
(*offset) += 5; remaining -= 5;
830
if (guide->horizontal)
833
RINT((double)(guide->position * (magic4>>8))
834
/(double)(magic4&255));
839
RINT((double)(guide->position * (magic6>>8))
840
/(double)(magic6&255));
843
IFDBG printf("\t\t\tGuide %d at %d, %s\n", i+1,
845
guide->horizontal ? "horizontal" : "vertical");
849
funny_amount_of_guide_data:
855
printf ("** GUIDE INFORMATION DROSS: ");
856
dumpchunk(remaining, fd, "dispatch_res");
860
throwchunk(remaining, fd, "dispatch_res");
863
(*offset) += remaining;
869
IFDBG printf ("\t\tResolution Info:\n");
870
psd_image.resolution_is_set = 1;
872
psd_image.resolution.hRes = getglong(fd, "hRes");
873
psd_image.resolution.hRes_unit = getgshort(fd, "hRes_unit");
874
psd_image.resolution.widthUnit = getgshort(fd, "WidthUnit");
875
psd_image.resolution.vRes = getglong(fd, "vRes");
876
psd_image.resolution.vRes_unit = getgshort(fd, "vRes_unit");
877
psd_image.resolution.heightUnit = getgshort(fd, "HeightUnit");
879
IFDBG printf("\t\t\tres = %f, %f\n",
880
psd_image.resolution.hRes / 65536.0,
881
psd_image.resolution.vRes / 65536.0);
893
IFDBG printf ("\t\t<Field is irrelevant to GIMP at this time.>\n");
894
throwchunk(Size, fd, "dispatch_res");
900
IFDBG printf ("\t\t<Obsolete Photoshop 2.0 field.>\n");
901
throwchunk(Size, fd, "dispatch_res");
908
IFDBG printf ("\t\t<Obsolete field.>\n");
909
throwchunk(Size, fd, "dispatch_res");
679
case 0x03ee: /* 1006 */
681
gint32 remaining = Size;
683
IFDBG printf ("\t\tALPHA CHANNEL NAMES:\n");
690
slen = getguchar (fd, "alpha channel name length");
694
/* Check for (Mac?) Photoshop (4?) file-writing bug */
695
if (slen > remaining)
697
IFDBG {printf("\nYay, a file bug. "
698
"Yuck. Photoshop 4/Mac? "
699
"I'll work around you.\n");fflush(stdout);}
705
guint32 alpha_name_len;
706
gchar* sname = getstring(slen, fd, "alpha channel name");
708
alpha_name_len = strlen (sname);
710
(*offset) += alpha_name_len;
711
remaining -= alpha_name_len;
713
sname = sanitise_string (sname);
715
psd_image.aux_channel[psd_image.num_aux_channels].name =
718
IFDBG printf("\t\t\tname: \"%s\"\n",
719
psd_image.aux_channel[psd_image.num_aux_channels].name);
723
psd_image.aux_channel[psd_image.num_aux_channels].name =
726
{printf("\t\t\tNull channel name %d.\n",
727
psd_image.num_aux_channels);fflush(stdout);}
730
psd_image.num_aux_channels++;
732
if (psd_image.num_aux_channels > MAX_CHANNELS)
734
g_message (_("Cannot handle PSD file with more than %d channels"),
739
while (remaining > 0);
745
dumpchunk (remaining, fd, "alphaname padding 0 throw");
747
throwchunk (remaining, fd, "alphaname padding 0 throw");
748
(*offset) += remaining;
753
case 0x03ef: /* 1007 */
754
IFDBG printf("\t\tDISPLAYINFO STRUCTURE: unhandled\n");
755
throwchunk (Size, fd, "dispatch_res");
758
case 0x03f0: /* 1008 */ /* FIXME: untested */
760
psd_image.caption = getpascalstring(fd, "caption string");
763
if (psd_image.caption)
765
IFDBG printf("\t\t\tcontent: \"%s\"\n",psd_image.caption);
766
(*offset) += strlen(psd_image.caption);
770
case 0x03f2: /* 1010 */
771
IFDBG printf("\t\tBACKGROUND COLOR: unhandled\n");
772
throwchunk (Size, fd, "dispatch_res");
775
case 0x03f4: /* 1012 */
776
IFDBG printf("\t\tGREY/MULTICHANNEL HALFTONING INFO: unhandled\n");
777
throwchunk (Size, fd, "dispatch_res");
780
case 0x03f5: /* 1013 */
781
IFDBG printf("\t\tCOLOUR HALFTONING INFO: unhandled\n");
782
throwchunk (Size, fd, "dispatch_res");
785
case 0x03f6: /* 1014 */
786
IFDBG printf("\t\tDUOTONE HALFTONING INFO: unhandled\n");
787
throwchunk (Size, fd, "dispatch_res");
790
case 0x03f7: /* 1015 */
791
IFDBG printf("\t\tGREYSCALE/MULTICHANNEL TRANSFER FUNCTION: unhandled\n");
792
throwchunk (Size, fd, "dispatch_res");
795
case 0x03f8: /* 1016 */
796
IFDBG printf("\t\tCOLOUR TRANSFER FUNCTION: unhandled\n");
797
throwchunk (Size, fd, "dispatch_res");
800
case 0x03f9: /* 1017 */
801
IFDBG printf("\t\tDUOTONE TRANSFER FUNCTION: unhandled\n");
802
throwchunk (Size, fd, "dispatch_res");
805
case 0x03fa: /* 1018 */
806
IFDBG printf("\t\tDUOTONE IMAGE INFO: unhandled\n");
807
throwchunk (Size, fd, "dispatch_res");
810
case 0x03fb: /* 1019 */
811
IFDBG printf("\t\tEFFECTIVE BLACK/WHITE VALUES: unhandled\n");
812
throwchunk (Size, fd, "dispatch_res");
815
case 0x03fe: /* 1022 */
816
IFDBG printf("\t\tQUICK MASK INFO: unhandled\n");
817
throwchunk (Size, fd, "dispatch_res");
820
case 0x0400: /* 1024 */
822
IFDBG printf("\t\tLAYER STATE INFO:\n");
823
psd_image.active_layer_num = getgint16(fd, "ID target_layer_num");
825
IFDBG printf("\t\t\ttarget: %d\n",(gint)psd_image.active_layer_num);
829
case 0x0402: /* 1026 */
830
IFDBG printf("\t\tLAYER GROUP INFO: unhandled\n");
831
IFDBG printf("\t\t\t(Inferred number of layers: %d)\n",(gint)(Size/2));
832
throwchunk (Size, fd, "dispatch_res");
835
case 0x0405: /* 1029 */
836
IFDBG printf ("\t\tIMAGE MODE FOR RAW FORMAT: unhandled\n");
837
throwchunk (Size, fd, "dispatch_res");
840
case 0x0408: /* 1032 */
842
gint32 remaining = Size;
844
IFDBG printf ("\t\tGUIDE INFORMATION:\n");
848
gint16 magic1, magic2, magic3, magic4, magic5, magic6;
852
magic1 = getgint16(fd, "guide"); (*offset) += 2;
853
magic2 = getgint16(fd, "guide"); (*offset) += 2;
854
magic3 = getgint16(fd, "guide"); (*offset) += 2;
855
magic4 = getgint16(fd, "guide"); (*offset) += 2;
856
magic5 = getgint16(fd, "guide"); (*offset) += 2;
857
magic6 = getgint16(fd, "guide"); (*offset) += 2;
860
IFDBG printf("\t\t\tSize: %d\n", Size);
861
IFDBG printf("\t\t\tMagic: %d %d %d %d %d %d\n",
862
magic1, magic2, magic3, magic4, magic5, magic6);
864
IFDBG printf("\t\t\tMagic: 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
865
magic1, magic2, magic3, magic4, magic5, magic6);
867
num_guides = getgint32(fd, "guide");
868
(*offset) += 4; remaining -= 4;
870
if (remaining != num_guides*5)
872
IFDBG printf ("** FUNNY AMOUNT OF GUIDE DATA (%d)\n",
874
goto funny_amount_of_guide_data;
877
IFDBG printf("\t\t\tNumber of guides is %d\n", num_guides);
878
psd_image.num_guides = num_guides;
879
psd_image.guides = g_new(PSDguide, num_guides);
880
guide = psd_image.guides;
882
for (i = 0; i < num_guides; i++, guide++)
884
guide->position = getgint32(fd, "guide");
885
IFDBG printf ("Position: %d %x\n", guide->position,
887
guide->horizontal = (1 == getguchar(fd, "guide"));
888
(*offset) += 5; remaining -= 5;
890
if (guide->horizontal)
893
RINT((double)(guide->position * (magic4>>8))
894
/(double)(magic4&255));
899
RINT((double)(guide->position * (magic6>>8))
900
/(double)(magic6&255));
903
IFDBG printf("\t\t\tGuide %d at %d, %s\n", i+1,
905
guide->horizontal ? "horizontal" : "vertical");
909
funny_amount_of_guide_data:
915
printf ("** GUIDE INFORMATION DROSS: ");
916
dumpchunk(remaining, fd, "dispatch_res");
920
throwchunk (remaining, fd, "dispatch_res");
923
(*offset) += remaining;
927
case 0x03ed: /* 1005 */
929
IFDBG printf ("\t\tResolution Info:\n");
930
psd_image.resolution_is_set = 1;
932
psd_image.resolution.hRes = getgint32(fd, "hRes");
933
psd_image.resolution.hRes_unit = getgint16(fd, "hRes_unit");
934
psd_image.resolution.widthUnit = getgint16(fd, "WidthUnit");
935
psd_image.resolution.vRes = getgint32(fd, "vRes");
936
psd_image.resolution.vRes_unit = getgint16(fd, "vRes_unit");
937
psd_image.resolution.heightUnit = getgint16(fd, "HeightUnit");
939
IFDBG printf("\t\t\tres = %f, %f\n",
940
psd_image.resolution.hRes / 65536.0,
941
psd_image.resolution.vRes / 65536.0);
944
case 0x0409: /* 1033 */
945
/* DATA LAYOUT for thumbail resource */
946
/* 4 bytes format (1 = jfif, 0 = raw) */
947
/* 4 bytes width width of thumbnail */
948
/* 4 bytes height height of thumbnail */
949
/* 4 bytes widthbytes for validation only?*/
950
/* 4 bytes size for validation only?*/
951
/* 4 bytes compressed size for validation only?*/
952
/* 2 bytes bits per pixel Always 24? */
953
/* 2 bytes planes Always 1? */
954
/* size bytes data JFIF (or raw) data */
955
IFDBG printf("\t\t<Photoshop 4.0 style thumbnail (BGR)> unhandled\n");
956
/* for resource 0x0409 we have to swap the r and b channels
958
throwchunk (Size, fd, "dispatch_res");
961
case 0x040C: /* 1036 */
963
IFDBG printf("\t\t<Photoshop 5.0 style thumbnail (RGB)> unhandled\n");
964
throwchunk (Size, fd, "dispatch_res");
967
case 0x03e9: /* 1001 */
968
case 0x03f1: /* 1009 */
969
case 0x03f3: /* 1011 */
970
case 0x03fd: /* 1021 */
971
case 0x0401: /* 1025 */
972
case 0x0404: /* 1028 */
973
case 0x0406: /* 1030 */
974
case 0x0bb7: /* 2999 */
975
case 0x2710: /* 10000 */
976
IFDBG printf ("\t\t<Field is irrelevant to GIMP at this time.>\n");
977
throwchunk (Size, fd, "dispatch_res");
981
case 0x03e8: /* 1000 */
982
case 0x03eb: /* 1003 */
983
IFDBG printf ("\t\t<Obsolete Photoshop 2.0 field.>\n");
984
throwchunk (Size, fd, "dispatch_res");
988
case 0x03fc: /* 1020 */
989
case 0x03ff: /* 1023 */
990
case 0x0403: /* 1027 */
991
IFDBG printf ("\t\t<Obsolete field.>\n");
992
throwchunk (Size, fd, "dispatch_res");
916
printf ("\t\t<Undocumented field.>\n");
917
dumpchunk(Size, fd, "dispatch_res");
920
throwchunk(Size, fd, "dispatch_res");
999
printf ("\t\t<Undocumented field.>\n");
1000
dumpchunk(Size, fd, "dispatch_res");
1003
throwchunk (Size, fd, "dispatch_res");
928
do_layer_record(FILE *fd, guint32 *offset, gint layernum)
1011
do_layer_record (FILE *fd,
930
1015
PSDlayer *layer;
931
gint32 top, left, bottom, right;
932
guint32 extradatasize, layermaskdatasize, layerrangesdatasize;
1016
gint32 top, left, bottom, right;
1017
guint32 extradatasize, layermaskdatasize, layerrangesdatasize;
938
1023
IFDBG printf("\t\t\tLAYER RECORD (layer %d)\n", (int)layernum);
940
1025
layer = psd_image.layer + layernum;
942
1027
/* table 11-12 */
943
top = getglong (fd, "layer top");
945
left = getglong (fd, "layer left");
947
bottom = getglong (fd, "layer bottom");
949
right = getglong (fd, "layer right");
1028
top = getgint32 (fd, "layer top");
1030
left = getgint32 (fd, "layer left");
1032
bottom = getgint32 (fd, "layer bottom");
1034
right = getgint32 (fd, "layer right");
954
layer->width = right - left;
1039
layer->width = right - left;
955
1040
layer->height = bottom - top;
957
1042
IFDBG printf("\t\t\t\tLayer extents: (%d,%d) -> (%d,%d)\n",
958
left,top,right,bottom);
1043
left,top,right,bottom);
960
layer->num_channels = getgshort (fd, "layer num_channels");
1045
layer->num_channels = getgint16 (fd, "layer num_channels");
963
1048
IFDBG printf("\t\t\t\tNumber of channels: %d\n",
964
(int)layer->num_channels);
1049
(int)layer->num_channels);
966
1051
if (layer->num_channels)
968
1053
layer->channel = g_new(PSDchannel, layer->num_channels);
970
1055
for (i = 0; i < layer->num_channels; i++)
972
PSDchannel *channel = layer->channel + i;
975
IFDBG printf("\t\t\t\tCHANNEL LENGTH INFO (%d)\n", i);
977
channel->type = getgshort(fd, "channel id");
979
IFDBG printf("\t\t\t\t\tChannel TYPE: %d\n", channel->type);
981
channel->compressedsize = getglong(fd, "channeldatalength");
983
IFDBG printf("\t\t\t\t\tChannel Data Length: %d\n",
984
channel->compressedsize);
1057
PSDchannel *channel = layer->channel + i;
1060
IFDBG printf("\t\t\t\tCHANNEL LENGTH INFO (%d)\n", i);
1062
channel->type = getgint16(fd, "channel id");
1064
IFDBG printf("\t\t\t\t\tChannel TYPE: %d\n", channel->type);
1066
channel->compressedsize = getgint32(fd, "channeldatalength");
1068
IFDBG printf("\t\t\t\t\tChannel Data Length: %d\n",
1069
channel->compressedsize);
987
1072
IFDBG printf("\t\t\t\tOo-er, layer has no channels. Hmm.\n");
1032
1117
getguchar(fd, "layer record filler");
1035
extradatasize = getglong(fd, "layer extra data size");
1120
extradatasize = getgint32(fd, "layer extra data size");
1037
1122
IFDBG printf("\t\t\t\tEXTRA DATA SIZE: %d\n",extradatasize);
1039
1124
/* FIXME: should do something with this data */
1040
/*throwchunk(extradatasize, fd, "layer extradata throw");
1125
/*throwchunk (extradatasize, fd, "layer extradata throw");
1041
1126
(*offset) += extradatasize;*/
1043
1128
totaloff = (*offset) + extradatasize;
1045
1130
/* table 11-14 */
1046
layermaskdatasize = getglong(fd, "layer mask data size");
1131
layermaskdatasize = getgint32(fd, "layer mask data size");
1048
1133
IFDBG printf("\t\t\t\t\tLAYER MASK DATA SIZE: %d\n", layermaskdatasize);
1050
1135
if (layermaskdatasize)
1052
top = getglong(fd, "lmask top");
1054
left = getglong(fd, "lmask left");
1056
bottom = getglong(fd, "lmask bottom");
1058
right = getglong(fd, "lmask right");
1141
top = getgint32(fd, "lmask top");
1143
left = getgint32(fd, "lmask left");
1145
bottom = getgint32(fd, "lmask bottom");
1147
right = getgint32(fd, "lmask right");
1061
1150
layer->lm_x = left;
1062
1151
layer->lm_y = top;
1063
1152
layer->lm_width = right - left;
1064
1153
layer->lm_height = bottom - top;
1066
getglong(fd, "lmask data throw");
1069
/* throwchunk(layermaskdatasize, fd, "layer mask data throw");
1070
(*offset) += layermaskdatasize;*/
1155
color = getguchar(fd, "lmask color");
1156
flags = getguchar(fd, "lmask flags");
1160
IFDBG printf ("\t\t\t\t\t\ttop: %d\n", top);
1161
IFDBG printf ("\t\t\t\t\t\tleft: %d\n", left);
1162
IFDBG printf ("\t\t\t\t\t\tbottom: %d\n", bottom);
1163
IFDBG printf ("\t\t\t\t\t\tright: %d\n", right);
1164
IFDBG printf ("\t\t\t\t\t\tcolor: %d\n", color);
1165
IFDBG printf ("\t\t\t\t\t\tflags: %X\n", flags);
1166
IFDBG printf ("\t\t\t\t\t\t\trelative: %d\n", flags & 0x1);
1167
IFDBG printf ("\t\t\t\t\t\t\tvisible: %d\n", ((flags & 0x2) >> 1));
1168
IFDBG printf ("\t\t\t\t\t\t\tinvert: %d\n", ((flags & 0x4) >> 2));
1170
throwchunk (layermaskdatasize - o, fd, "extra layer mask data");
1171
(*offset) += layermaskdatasize;
1073
layerrangesdatasize = getglong(fd, "layer ranges data size");
1075
IFDBG printf("\t\t\t\t\t\tLAYER RANGES DATA SIZE: %d\n",layermaskdatasize);
1174
layerrangesdatasize = getgint32 (fd, "layer ranges data size");
1176
IFDBG printf("\t\t\t\t\t\tLAYER RANGES DATA SIZE: %d\n", layermaskdatasize);
1077
1178
if (layerrangesdatasize)
1079
throwchunk(layerrangesdatasize, fd, "layer ranges data throw");
1180
throwchunk (layerrangesdatasize, fd, "layer ranges data throw");
1080
1181
(*offset) += layerrangesdatasize;
1083
layer->name = getpascalstring(fd, "layer name");
1184
layer->name = getpascalstring (fd, "layer name");
1086
1187
if (layer->name)
1088
(*offset) += strlen(layer->name);
1189
(*offset) += strlen (layer->name);
1089
1190
IFDBG printf("\t\t\t\t\t\tLAYER NAME: '%s'\n", layer->name);
1090
layer->name = sanitise_string(layer->name);
1191
layer->name = sanitise_string (layer->name);
1094
IFDBG printf("\t\t\t\t\t\tNULL LAYER NAME\n");
1195
IFDBG printf ("\t\t\t\t\t\tNULL LAYER NAME\n");
1096
1197
/* If no layermask data - set offset and size from layer data */
1097
1198
if (! layermaskdatasize)
1100
fprintf(stderr, "Setting layer mask data layer\n");
1200
IFDBG g_printerr ("Setting layer mask data layer\n");
1102
psd_image.layer[layernum].lm_x = psd_image.layer[layernum].x;
1103
psd_image.layer[layernum].lm_y = psd_image.layer[layernum].y;
1104
psd_image.layer[layernum].lm_width = psd_image.layer[layernum].width;
1202
psd_image.layer[layernum].lm_x = psd_image.layer[layernum].x;
1203
psd_image.layer[layernum].lm_y = psd_image.layer[layernum].y;
1204
psd_image.layer[layernum].lm_width = psd_image.layer[layernum].width;
1105
1205
psd_image.layer[layernum].lm_height = psd_image.layer[layernum].height;
1108
1208
if (totaloff-(*offset) > 0)
1112
printf("Warning: layer record dross: ");
1113
dumpchunk(totaloff-(*offset), fd, "layer record dross throw");
1212
printf ("Warning: layer record dross: ");
1213
dumpchunk (totaloff-(*offset), fd, "layer record dross throw");
1117
throwchunk(totaloff-(*offset), fd, "layer record dross throw");
1217
throwchunk (totaloff-(*offset), fd, "layer record dross throw");
1119
1219
(*offset) = totaloff;
1124
do_layer_struct(FILE *fd, guint32 *offset)
1224
do_layer_struct (FILE *fd,
1128
IFDBG printf("\t\tLAYER STRUCTURE SECTION\n");
1229
IFDBG printf ("\t\tLAYER STRUCTURE SECTION\n");
1130
psd_image.num_layers = getgshort(fd, "layer struct numlayers");
1231
psd_image.num_layers = getgint16 (fd, "layer struct numlayers");
1133
1234
IFDBG printf("\t\t\tCanonical number of layers: %d%s\n",
1134
psd_image.num_layers>0?
1135
(int)psd_image.num_layers:abs(psd_image.num_layers),
1136
psd_image.num_layers>0?"":" (absolute/alpha)");
1235
psd_image.num_layers>0?
1236
(int)psd_image.num_layers:abs(psd_image.num_layers),
1237
psd_image.num_layers>0?"":" (absolute/alpha)");
1138
1239
if (psd_image.num_layers < 0)
1163
1265
PSDlayer *layer = psd_image.layer + layeri;
1165
1267
for (channeli = 0; channeli < layer->num_channels; channeli++)
1167
PSDchannel *channel = layer->channel + channeli;
1169
if (channel->type == -2)
1171
channel->width = layer->lm_width;
1172
channel->height = layer->lm_height;
1176
channel->width = layer->width;
1177
channel->height = layer->height;
1180
fgetpos(fd, &channel->fpos);
1182
throwchunk(channel->compressedsize, fd, "channel data skip");
1183
(*offset) += channel->compressedsize;
1269
PSDchannel *channel = layer->channel + channeli;
1271
if (channel->type == -2)
1273
channel->width = layer->lm_width;
1274
channel->height = layer->lm_height;
1278
channel->width = layer->width;
1279
channel->height = layer->height;
1282
fgetpos (fd, &channel->fpos);
1284
throwchunk (channel->compressedsize, fd, "channel data skip");
1285
(*offset) += channel->compressedsize;
1189
seek_to_and_unpack_pixeldata(FILE* fd, gint layeri, gint channeli)
1291
seek_to_and_unpack_pixeldata (FILE *fd,
1195
1299
PSDchannel *channel = &psd_image.layer[layeri].channel[channeli];
1197
1301
fsetpos(fd, &channel->fpos);
1199
compression = getgshort(fd, "layer channel compression type");
1303
compression = getgint16(fd, "layer channel compression type");
1202
width = channel->width;
1306
width = channel->width;
1203
1307
height = channel->height;
1207
printf("\t\t\tLayer (%d) Channel (%d:%d) Compression: %d (%s)\n",
1212
compression==0?"raw":(compression==1?"RLE":"*UNKNOWN!*"));
1311
printf ("\t\t\tLayer (%d) Channel (%d:%d) Compression: %d (%s)\n",
1316
compression==0?"raw":(compression==1?"RLE":"*UNKNOWN!*"));
1217
1321
channel->data = g_malloc (width * height);
1219
tmpline = g_malloc(width + 1);
1323
tmpline = g_malloc (width + 1);
1221
1325
switch (compression)
1223
1327
case 0: /* raw data */
1227
for (linei = 0; linei < height; linei++)
1229
xfread(fd, channel->data + linei * width, width,
1230
"raw channel line");
1331
for (linei = 0; linei < height; linei++)
1333
xfread (fd, channel->data + linei * width, width,
1334
"raw channel line");
1235
/* Pad raw data to multiple of 2? */
1236
if ((height * width) & 1)
1238
getguchar(fd, "raw channel padding");
1339
/* Pad raw data to multiple of 2? */
1340
if ((height * width) & 1)
1342
getguchar (fd, "raw channel padding");
1244
1348
case 1: /* RLE, one row at a time, padded to an even width */
1249
/* we throw this away because in theory we can trust the
1250
data to unpack to the right length... hmm... */
1251
throwchunk(height * 2, fd, "widthlist");
1252
offset += height * 2;
1256
/*IFDBG {printf("\nHere comes the guitar solo...\n");
1259
for (linei=0; linei<height; linei++)
1261
/*printf(" %d ", *offset);*/
1262
unpack_pb_channel(fd, tmpline,
1266
memcpy(channel->data + linei * width, tmpline, width);
1269
IFDBG {printf("\t\t\t\t\tActual compressed size was %d bytes\n"
1270
, offset-blockread);fflush(stdout);}
1353
/* we throw this away because in theory we can trust the
1354
data to unpack to the right length... hmm... */
1355
throwchunk (height * 2, fd, "widthlist");
1356
offset += height * 2;
1360
/*IFDBG {printf("\nHere comes the guitar solo...\n");
1363
for (linei = 0; linei < height; linei++)
1365
/*printf(" %d ", *offset);*/
1366
unpack_pb_channel (fd, tmpline,
1370
memcpy (channel->data + linei * width, tmpline, width);
1373
IFDBG {printf("\t\t\t\t\tActual compressed size was %d bytes\n",
1374
offset-blockread);fflush(stdout);}
1273
1378
default: /* *unknown* */
1274
1379
IFDBG {printf("\nEEP!\n");fflush(stdout);}
1275
1380
g_message ("*** Unknown compression type in channel.");
1283
do_layers(FILE *fd, guint32 *offset)
1388
do_layers (FILE *fd,
1285
1391
guint32 section_length;
1287
section_length = getglong(fd, "layerinfo sectionlength");
1393
section_length = getgint32 (fd, "layerinfo sectionlength");
1290
IFDBG printf("\tLAYER INFO SECTION\n");
1291
IFDBG printf("\t\tSECTION LENGTH: %u\n",section_length);
1293
do_layer_struct(fd, offset);
1295
do_layer_pixeldata(fd, offset);
1396
IFDBG printf ("\tLAYER INFO SECTION\n");
1397
IFDBG printf ("\t\tSECTION LENGTH: %u\n", section_length);
1399
do_layer_struct (fd, offset);
1401
do_layer_pixeldata (fd, offset);
1299
do_layer_and_mask(FILE *fd)
1405
do_layer_and_mask (FILE *fd)
1301
1407
guint32 offset = 0;
1302
guint32 Size = PSDheader.miscsizelen;
1304
guint32 offset_now = ftell(fd);
1306
IFDBG printf("LAYER AND MASK INFO\n");
1307
IFDBG printf("\tSECTION LENGTH: %u\n",Size);
1309
if (Size == 0) return;
1311
do_layers(fd, &offset);
1408
guint32 Size = PSDheader.miscsizelen;
1410
glong offset_now = ftell (fd);
1412
IFDBG printf ("LAYER AND MASK INFO\n");
1413
IFDBG printf ("\tSECTION LENGTH: %u\n", Size);
1418
do_layers (fd, &offset);
1313
1420
IFDBG {printf("And...?\n");fflush(stdout);}
1315
1422
if (offset < Size)
1319
printf("PSD: Supposedly there are %d bytes of mask info left.\n",
1321
if ((Size-offset == 4) || (Size-offset == 24))
1322
printf(" That sounds good to me.\n");
1324
printf(" That sounds strange to me.\n");
1426
printf ("PSD: Supposedly there are %d bytes of mask info left.\n",
1428
if ((Size-offset == 4) || (Size-offset == 24))
1429
printf(" That sounds good to me.\n");
1431
printf(" That sounds strange to me.\n");
1328
1435
/* if ((getguchar(fd, "mask info throw")!=0) ||
1329
(getguchar(fd, "mask info throw")!=0) ||
1330
(getguchar(fd, "mask info throw")!=0) ||
1331
(getguchar(fd, "mask info throw")!=0))
1333
printf("*** This mask info block looks pretty bogus.\n");
1436
(getguchar(fd, "mask info throw")!=0) ||
1437
(getguchar(fd, "mask info throw")!=0) ||
1438
(getguchar(fd, "mask info throw")!=0))
1440
printf("*** This mask info block looks pretty bogus.\n");
1337
1444
printf("PSD: Stern warning - no mask info.\n");
1679
aux_data = g_malloc(width * height);
1795
aux_data = g_malloc (width * height);
1681
int pix, chan, aux_index;
1683
GimpDrawable* chdrawable;
1797
int pix, chan, aux_index;
1799
GimpDrawable *chdrawable;
1686
1802
gimp_rgb_set (&colour, 0.0, 0.0, 0.0);
1688
for (chan=psstep-num_wanted; chan<psstep; chan++)
1804
for (chan = psstep - num_wanted; chan < psstep; chan++)
1690
for (pix = 0; pix < width * height; pix++)
1692
aux_data [pix] = src [pix * psstep + chan];
1695
aux_index = chan - (psstep - num_wanted);
1696
validate_aux_channel_name (aux_index);
1698
channel_ID = gimp_channel_new (image_ID,
1806
for (pix = 0; pix < width * height; pix++)
1808
aux_data [pix] = src [pix * psstep + chan];
1811
aux_index = chan - (psstep - num_wanted);
1812
validate_aux_channel_name (aux_index);
1814
channel_ID = gimp_channel_new (image_ID,
1699
1815
psd_image.aux_channel[aux_index].name,
1701
1817
100.0, &colour);
1702
gimp_image_add_channel (image_ID, channel_ID, 0);
1703
gimp_drawable_set_visible (channel_ID, FALSE);
1705
chdrawable = gimp_drawable_get (channel_ID);
1707
gimp_pixel_rgn_init (&pixel_rgn, chdrawable,
1708
0, 0, chdrawable->width, chdrawable->height,
1710
gimp_pixel_rgn_set_rect (&pixel_rgn, aux_data,
1711
0, 0, chdrawable->width, chdrawable->height);
1713
gimp_drawable_flush (chdrawable);
1714
gimp_drawable_detach (chdrawable);
1818
gimp_image_add_channel (image_ID, channel_ID, 0);
1819
gimp_drawable_set_visible (channel_ID, FALSE);
1821
chdrawable = gimp_drawable_get (channel_ID);
1823
gimp_pixel_rgn_init (&pixel_rgn, chdrawable,
1824
0, 0, chdrawable->width, chdrawable->height,
1826
gimp_pixel_rgn_set_rect (&pixel_rgn, aux_data,
1827
0, 0, chdrawable->width, chdrawable->height);
1829
gimp_drawable_flush (chdrawable);
1830
gimp_drawable_detach (chdrawable);
1717
1833
g_free(aux_data);
1719
IFDBG printf("Done with that.\n\n");
1835
IFDBG printf ("Done with that.\n\n");
1723
resize_mask(guchar* src, guchar* dest,
1724
gint32 src_x, gint32 src_y,
1725
gint32 src_w, gint32 src_h,
1726
gint32 dest_w, gint32 dest_h)
1839
resize_mask (guchar *src,
1730
IFDBG printf("--> %p %p : %d %d . %d %d . %d %d\n",
1736
for (y=0; y<dest_h; y++)
1850
IFDBG printf ("--> %p %p : %d %d . %d %d . %d %d\n",
1856
for (y = 0; y < dest_h; y++)
1738
for (x=0; x<dest_w; x++)
1740
/* Avoid a 1-pixel border top-left */
1741
if ((x>=src_x) && (x<src_x+src_w) &&
1742
(y>=src_y) && (y<src_y+src_h))
1744
dest[dest_w * y + x] =
1745
src[src_w * (y-src_y) + (x-src_x)];
1749
dest[dest_w * y + x] = 255;
1858
for (x = 0; x < dest_w; x++)
1860
/* Avoid a 1-pixel border top-left */
1861
if ((x >= src_x) && (x < src_x + src_w) &&
1862
(y >= src_y) && (y < src_y + src_h))
1864
dest[dest_w * y + x] =
1865
src[src_w * (y - src_y) + (x - src_x)];
1869
dest[dest_w * y + x] = 255;
1756
1876
load_image (const gchar *name)
1762
guchar *dest = NULL, *temp;
1763
long channels, nguchars;
1764
psd_imagetype imagetype;
1765
gboolean cmyk = FALSE;
1767
gint32 image_ID = -1;
1768
gint32 layer_ID = -1;
1769
GimpDrawable *drawable = NULL;
1770
GimpPixelRgn pixel_rgn;
1773
int red_chan, grn_chan, blu_chan, alpha_chan, ichan;
1775
IFDBG printf("------- %s ---------------------------------\n",name);
1777
fd = fopen (name, "rb");
1881
guchar *dest = NULL, *temp;
1882
long channels, nguchars;
1883
psd_imagetype imagetype;
1884
gboolean cmyk = FALSE;
1886
gint32 image_ID = -1;
1887
gint32 layer_ID = -1;
1888
GimpDrawable *drawable = NULL;
1889
GimpPixelRgn pixel_rgn;
1892
int red_chan, grn_chan, blu_chan, alpha_chan, ichan;
1894
IFDBG printf ("------- %s ---------------------------------\n",name);
1896
fd = g_fopen (name, "rb");
1780
1899
g_message (_("Could not open '%s' for reading: %s"),
1809
1926
psd_image.resolution.vRes *= factor;
1812
gimp_image_set_resolution (image_ID,
1929
gimp_image_set_resolution (image_ID,
1813
1930
psd_image.resolution.hRes / 65536.0,
1814
1931
psd_image.resolution.vRes / 65536.0);
1816
/* currently can only set one unit for the image so we use the
1817
horizontal unit from the psd image */
1818
gimp_image_set_unit (image_ID,
1933
/* currently can only set one unit for the image so we use the
1934
horizontal unit from the psd image */
1935
gimp_image_set_unit (image_ID,
1819
1936
psd_unit_to_gimp_unit (psd_image.resolution.widthUnit));
1822
1939
fgetpos (fd, &tmpfpos);
1824
1941
for (lnum = 0; lnum < psd_image.num_layers; lnum++)
1827
guchar* merged_data = NULL;
1828
PSDlayer *layer = psd_image.layer + lnum;
1831
* since ps supports sloppy bounding boxes it is possible to
1832
* have a 0x0 or Xx0 or 0xY layer. Gimp doesn't support a
1833
* 0x0 layer so we will just skip these. We might be able
1834
* to do something better here.
1836
if ((layer->width == 0) || (layer->height == 0))
1838
IFDBG printf("(bad layer dimensions -- skipping)");
1841
numc = layer->num_channels;
1843
IFDBG printf("Hey, it's a LAYER with %d channels!\n", numc);
1849
IFDBG printf("It's GRAY.\n");
1850
if (!psd_layer_has_alpha(layer))
1852
merged_data = g_malloc(layer->width * layer->height);
1853
seek_to_and_unpack_pixeldata(fd, lnum, 0);
1854
memcpy(merged_data, layer->channel[0].data,
1855
layer->width * layer->height);
1857
g_free(layer->channel[0].data);
1861
seek_to_and_unpack_pixeldata(fd, lnum, 0);
1862
seek_to_and_unpack_pixeldata(fd, lnum, 1);
1864
chans_to_GRAYA (layer->channel[1].data,
1865
layer->channel[0].data,
1866
layer->width * layer->height);
1868
g_free(layer->channel[0].data);
1869
g_free(layer->channel[1].data);
1872
layer_ID = gimp_layer_new (image_ID,
1876
(numc==1) ? GIMP_GRAY_IMAGE : GIMP_GRAYA_IMAGE,
1877
(100.0 * layer->opacity) / 255.0,
1878
psd_lmode_to_gimp_lmode(layer->blendkey));
1880
}; break; /* case GIMP_GRAY */
1884
IFDBG printf("It's RGB, %dx%d.\n", layer->width,
1886
if (!psd_layer_has_alpha(layer))
1888
seek_to_and_unpack_pixeldata(fd, lnum, 0);
1889
seek_to_and_unpack_pixeldata(fd, lnum, 1);
1890
seek_to_and_unpack_pixeldata(fd, lnum, 2);
1892
chans_to_RGB (layer->channel[0].data,
1893
layer->channel[1].data,
1894
layer->channel[2].data,
1898
g_free(layer->channel[0].data);
1899
g_free(layer->channel[1].data);
1900
g_free(layer->channel[2].data);
1903
fprintf(stderr, "YAH0a\n");
1907
seek_to_and_unpack_pixeldata(fd, lnum, 0);
1908
seek_to_and_unpack_pixeldata(fd, lnum, 1);
1909
seek_to_and_unpack_pixeldata(fd, lnum, 2);
1910
seek_to_and_unpack_pixeldata(fd, lnum, 3);
1912
/* Fix for unexpected layer data order for files
1913
* from PS files created by PanoTools. Rather
1914
* than assuming an order, we find the actual order.
1917
red_chan = grn_chan = blu_chan = alpha_chan = -1;
1919
for (ichan=0; ichan<numc; ichan++)
1921
switch(psd_image.layer[lnum].channel[ichan].type)
1923
case 0: red_chan = ichan; break;
1924
case 1: grn_chan = ichan; break;
1925
case 2: blu_chan = ichan; break;
1926
case -1: alpha_chan = ichan; break;
1930
if ((red_chan < 0) ||
1935
g_message ("Error: Cannot identify required RGBA channels");
1941
chans_to_RGBA (psd_image.layer[lnum].channel[red_chan].data,
1942
psd_image.layer[lnum].channel[grn_chan].data,
1943
psd_image.layer[lnum].channel[blu_chan].data,
1944
psd_image.layer[lnum].channel[alpha_chan].data,
1945
psd_image.layer[lnum].width *
1946
psd_image.layer[lnum].height);
1948
g_free(layer->channel[0].data);
1949
g_free(layer->channel[1].data);
1950
g_free(layer->channel[2].data);
1951
g_free(layer->channel[3].data);
1954
fprintf(stderr, "YAH0b\n");
1958
fprintf(stderr, "YAH1\n");
1960
layer_ID = gimp_layer_new (image_ID,
1961
psd_image.layer[lnum].name,
1962
psd_image.layer[lnum].width,
1963
psd_image.layer[lnum].height,
1964
psd_layer_has_alpha(&psd_image.layer[lnum]) ?
1944
guchar *merged_data = NULL;
1945
PSDlayer *layer = psd_image.layer + lnum;
1946
gboolean empty = FALSE;
1949
* Since PS supports sloppy bounding boxes it is possible to
1950
* have a 0x0 or Xx0 or 0xY layer. Gimp doesn't support a
1951
* 0x0 layer so we insert an empty layer of image size
1954
if ((layer->width == 0) || (layer->height == 0))
1960
layer->width = gimp_image_width (image_ID);
1961
layer->height = gimp_image_height (image_ID);
1964
numc = layer->num_channels;
1966
IFDBG printf ("Hey, it's a LAYER with %d channels!\n", numc);
1972
IFDBG printf("It's GRAY.\n");
1975
if (!psd_layer_has_alpha (layer))
1977
merged_data = g_malloc (layer->width * layer->height);
1978
seek_to_and_unpack_pixeldata (fd, lnum, 0);
1979
memcpy (merged_data, layer->channel[0].data,
1980
layer->width * layer->height);
1982
g_free (layer->channel[0].data);
1986
seek_to_and_unpack_pixeldata (fd, lnum, 0);
1987
seek_to_and_unpack_pixeldata (fd, lnum, 1);
1988
merged_data = chans_to_GRAYA (layer->channel[1].data,
1989
layer->channel[0].data,
1993
g_free (layer->channel[0].data);
1994
g_free (layer->channel[1].data);
1998
layer_ID = gimp_layer_new (image_ID,
2003
GIMP_GRAY_IMAGE : GIMP_GRAYA_IMAGE,
2004
(100.0 * layer->opacity) / 255.0,
2005
psd_lmode_to_gimp_lmode (layer->blendkey));
2011
IFDBG printf ("It's RGB, %dx%d.\n", layer->width,
2016
if (!psd_layer_has_alpha (layer))
2018
seek_to_and_unpack_pixeldata (fd, lnum, 0);
2019
seek_to_and_unpack_pixeldata (fd, lnum, 1);
2020
seek_to_and_unpack_pixeldata (fd, lnum, 2);
2021
merged_data = chans_to_RGB (layer->channel[0].data,
2022
layer->channel[1].data,
2023
layer->channel[2].data,
2027
g_free (layer->channel[0].data);
2028
g_free (layer->channel[1].data);
2029
g_free (layer->channel[2].data);
2031
IFDBG g_printerr ("YAH0a\n");
2035
seek_to_and_unpack_pixeldata (fd, lnum, 0);
2036
seek_to_and_unpack_pixeldata (fd, lnum, 1);
2037
seek_to_and_unpack_pixeldata (fd, lnum, 2);
2038
seek_to_and_unpack_pixeldata (fd, lnum, 3);
2040
/* Fix for unexpected layer data order for files
2041
* from PS files created by PanoTools. Rather
2042
* than assuming an order, we find the actual order.
2045
red_chan = grn_chan = blu_chan = alpha_chan = -1;
2047
for (ichan = 0; ichan < numc; ichan++)
2049
switch (psd_image.layer[lnum].channel[ichan].type)
2051
case 0: red_chan = ichan; break;
2052
case 1: grn_chan = ichan; break;
2053
case 2: blu_chan = ichan; break;
2054
case -1: alpha_chan = ichan; break;
2058
if ((red_chan < 0) ||
2063
g_message ("Error: Cannot identify required RGBA channels");
2068
chans_to_RGBA (psd_image.layer[lnum].channel[red_chan].data,
2069
psd_image.layer[lnum].channel[grn_chan].data,
2070
psd_image.layer[lnum].channel[blu_chan].data,
2071
psd_image.layer[lnum].channel[alpha_chan].data,
2072
psd_image.layer[lnum].width *
2073
psd_image.layer[lnum].height);
2075
g_free (layer->channel[0].data);
2076
g_free (layer->channel[1].data);
2077
g_free (layer->channel[2].data);
2078
g_free (layer->channel[3].data);
2080
IFDBG g_printerr ("YAH0b\n");
2084
IFDBG g_printerr ("YAH1\n");
2086
layer_ID = gimp_layer_new (image_ID,
2087
psd_image.layer[lnum].name,
2088
psd_image.layer[lnum].width,
2089
psd_image.layer[lnum].height,
2090
psd_layer_has_alpha (&psd_image.layer[lnum]) ?
1965
2091
GIMP_RGBA_IMAGE : GIMP_RGB_IMAGE,
1966
(100.0 * (double)psd_image.layer[lnum].opacity) / 255.0,
1967
psd_lmode_to_gimp_lmode(psd_image.layer[lnum].blendkey));
1970
fprintf(stderr, "YAH2\n");
1972
}; break; /* case GIMP_RGB */
1976
g_message ("Error: Sorry, can't deal with a layered image of this type.\n");
1978
}; break; /* default */
1981
gimp_image_add_layer (image_ID, layer_ID, 0);
1984
fprintf(stderr, "YAH3\n");
1986
/* Do a layer mask if it exists */
1987
for (iter = 0; iter < layer->num_channels; iter++)
1989
if (layer->channel[iter].type == -2) /* is mask */
1995
fprintf(stderr, "YAH3m\n");
1997
lm_data = g_malloc(layer->width * layer->height);
2092
(100.0 * psd_image.layer[lnum].opacity) / 255.0,
2093
psd_lmode_to_gimp_lmode(psd_image.layer[lnum].blendkey));
2095
IFDBG g_printerr ("YAH2\n");
2100
g_message ("Error: Sorry, can't deal with a layered image of this type.\n");
2104
gimp_image_add_layer (image_ID, layer_ID, 0);
2106
IFDBG g_printerr ("YAH3\n");
2108
/* Do a layer mask if it exists */
2109
for (iter = 0; !empty && iter < layer->num_channels; iter++)
2111
if (layer->channel[iter].type == -2) /* is mask */
2116
IFDBG g_printerr ("Unpacking a layer mask!\n");
2118
lm_data = g_malloc (layer->width * layer->height);
1999
2120
#if PANOTOOLS_FIX
2003
seek_to_and_unpack_pixeldata(fd, lnum, iter);
2004
/* PS layer masks can be a different size to
2005
their owning layer, so we have to resize them. */
2006
resize_mask(layer->channel[iter].data,
2008
layer->lm_x - layer->x,
2009
layer->lm_y - layer->y,
2010
layer->lm_width, layer->lm_height,
2011
layer->width, layer->height);
2013
/* won't be needing the original data any more */
2014
g_free(layer->channel[iter].data);
2016
/* give it to GIMP */
2017
mask_id = gimp_layer_create_mask(layer_ID, 0);
2124
seek_to_and_unpack_pixeldata (fd, lnum, iter);
2125
/* PS layer masks can be a different size to
2126
their owning layer, so we have to resize them. */
2127
resize_mask (layer->channel[iter].data,
2129
layer->lm_x - layer->x,
2130
layer->lm_y - layer->y,
2131
layer->lm_width, layer->lm_height,
2132
layer->width, layer->height);
2134
/* won't be needing the original data any more */
2135
g_free (layer->channel[iter].data);
2137
/* give it to GIMP */
2138
mask_id = gimp_layer_create_mask (layer_ID, 0);
2019
2140
#if PANOTOOLS_FIX
2020
/* Convert the layer RGB data (not the mask) to RGBA */
2141
/* Convert the layer RGB data (not the mask) to RGBA */
2021
2142
tmp = merged_data;
2022
merged_data = RGB_to_RGBA (tmp,
2143
merged_data = RGB_to_RGBA (tmp,
2023
2144
psd_image.layer[lnum].width *
2024
2145
psd_image.layer[lnum].height);
2027
/* Add alpha - otherwise cannot add layer mask */
2028
gimp_layer_add_alpha (layer_ID);
2148
/* Add alpha - otherwise cannot add layer mask */
2149
gimp_layer_add_alpha (layer_ID);
2151
/* Add layer mask */
2030
2152
#endif /* PANOTOOLS_FIX */
2031
/* Add layer mask */
2032
gimp_layer_add_mask (layer_ID, mask_id);
2034
drawable = gimp_drawable_get (mask_id);
2036
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0,
2037
layer->width, layer->height,
2039
gimp_pixel_rgn_set_rect (&pixel_rgn, lm_data, 0, 0,
2040
layer->width, layer->height);
2044
gimp_drawable_flush (drawable);
2045
gimp_drawable_detach (drawable);
2050
fprintf(stderr, "YAH4\n");
2052
gimp_layer_translate (layer_ID, layer->x, layer->y);
2054
gimp_layer_set_preserve_trans (layer_ID, layer->protecttrans);
2055
gimp_drawable_set_visible (layer_ID, layer->visible);
2057
drawable = gimp_drawable_get (layer_ID);
2060
fprintf(stderr, "YAH5 - merged_data=%p, drawable=%p, drawdim=%dx%dx%d\n",
2067
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0,
2068
layer->width, layer->height,
2070
gimp_pixel_rgn_set_rect (&pixel_rgn, merged_data, 0, 0,
2071
layer->width, layer->height);
2074
fprintf(stderr, "YAH6\n");
2076
gimp_drawable_flush (drawable);
2077
gimp_drawable_detach (drawable);
2080
g_free (merged_data);
2082
gimp_progress_update ((double)(lnum+1.0) /
2083
(double)psd_image.num_layers);
2153
IFDBG printf ("Adding layer mask %d to layer %d\n",
2156
gimp_layer_add_mask (layer_ID, mask_id);
2158
drawable = gimp_drawable_get (mask_id);
2160
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0,
2161
layer->width, layer->height,
2163
gimp_pixel_rgn_set_rect (&pixel_rgn, lm_data, 0, 0,
2164
layer->width, layer->height);
2168
gimp_drawable_flush (drawable);
2169
gimp_drawable_detach (drawable);
2173
IFDBG g_printerr ("YAH4\n");
2175
gimp_layer_translate (layer_ID, layer->x, layer->y);
2177
gimp_layer_set_lock_alpha (layer_ID, layer->protecttrans);
2178
gimp_drawable_set_visible (layer_ID, layer->visible);
2180
drawable = gimp_drawable_get (layer_ID);
2182
IFDBG g_printerr ("YAH5 - merged_data=%p, drawable=%p, drawdim=%dx%dx%d\n",
2191
gimp_drawable_fill (layer_ID, GIMP_TRANSPARENT_FILL);
2195
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0,
2196
layer->width, layer->height,
2198
gimp_pixel_rgn_set_rect (&pixel_rgn, merged_data, 0, 0,
2199
layer->width, layer->height);
2201
IFDBG g_printerr ("YAH6\n");
2204
gimp_drawable_flush (drawable);
2205
gimp_drawable_detach (drawable);
2208
g_free (merged_data);
2210
gimp_progress_update ((double) (lnum+1.0) /
2211
(double) psd_image.num_layers);
2085
2214
fsetpos (fd, &tmpfpos);
2100
if (want_aux || (psd_image.num_layers==0)) /* Photoshop2-style: NO LAYERS. */
2229
if (want_aux || (psd_image.num_layers == 0)) /* Photoshop2-style: NO LAYERS. */
2103
IFDBG printf("Image data %ld chars\n", PSDheader.imgdatalen);
2231
IFDBG printf ("Image data %ld chars\n", PSDheader.imgdatalen);
2105
2233
step = PSDheader.channels;
2107
2235
imagetype = PSD_UNKNOWN_IMAGE;
2108
switch (PSDheader.mode)
2110
case 0: /* Bitmap */
2111
imagetype = PSD_BITMAP_IMAGE;
2113
case 1: /* Grayscale */
2114
imagetype = PSD_GRAY_IMAGE;
2116
case 2: /* Indexed Colour */
2117
imagetype = PSD_INDEXED_IMAGE;
2119
case 3: /* RGB Colour */
2120
imagetype = PSD_RGB_IMAGE;
2122
case 4: /* CMYK Colour */
2124
switch (PSDheader.channels)
2127
imagetype = PSD_RGB_IMAGE;
2130
imagetype = PSD_RGBA_IMAGE;
2133
printf("%s: cannot handle CMYK with more than 5 channels\n",
2139
case 7: /* Multichannel (?) */
2140
case 8: /* Duotone */
2141
case 9: /* Lab Colour */
2237
switch (PSDheader.mode)
2239
case 0: /* Bitmap */
2240
imagetype = PSD_BITMAP_IMAGE;
2242
case 1: /* Grayscale */
2243
imagetype = PSD_GRAY_IMAGE;
2245
case 2: /* Indexed Colour */
2246
imagetype = PSD_INDEXED_IMAGE;
2248
case 3: /* RGB Colour */
2249
imagetype = PSD_RGB_IMAGE;
2251
case 4: /* CMYK Colour */
2253
switch (PSDheader.channels)
2256
imagetype = PSD_RGB_IMAGE;
2259
imagetype = PSD_RGBA_IMAGE;
2262
g_message (_("Cannot handle PSD files in CMYK color with more than 5 channels"));
2267
case 7: /* Multichannel (?) */
2268
case 8: /* Duotone */
2269
case 9: /* Lab Colour */
2147
2275
if (imagetype == PSD_UNKNOWN_IMAGE)
2149
printf("%s: Image type %d (%s) is not supported in this data format\n",
2150
prog_name, PSDheader.mode,
2151
(PSDheader.mode > 10) ?
2152
"<out of range>" : modename[PSDheader.mode]);
2277
g_message (_("Cannot handle image mode %d (%s)"),
2279
(PSDheader.mode >= G_N_ELEMENTS (modename)) ?
2280
"<out of range>" : modename[PSDheader.mode]);
2157
2284
if ((PSDheader.bpp != 8) && (PSDheader.bpp != 1))
2159
printf("%s: The GIMP only supports 8-bit or 1-bit deep PSD images "
2286
g_message (_("Cannot handle %d bits per channel PSD files"), PSDheader.bpp);
2166
"psd:%d gimp:%d gimpbase:%d\n",
2168
psd_type_to_gimp_type(imagetype),
2169
psd_type_to_gimp_base_type(imagetype)
2290
IFDBG printf ("psd:%d gimp:%d gimpbase:%d\n",
2292
psd_type_to_gimp_type(imagetype),
2293
psd_type_to_gimp_base_type(imagetype));
2175
/* gimp doesn't like 0 width/height drawables. */
2176
if ((PSDheader.columns == 0) || (PSDheader.rows == 0))
2178
IFDBG printf("(bad psd2-style image dimensions -- skipping)");
2298
/* gimp doesn't like 0 width/height drawables. */
2299
if ((PSDheader.columns == 0) || (PSDheader.rows == 0))
2301
IFDBG printf ("(bad psd2-style image dimensions -- skipping)");
2183
image_ID = gimp_image_new (PSDheader.columns, PSDheader.rows,
2184
psd_type_to_gimp_base_type(imagetype));
2185
gimp_image_set_filename (image_ID, name);
2186
if (psd_type_to_gimp_base_type(imagetype) == GIMP_INDEXED)
2188
if ((psd_image.colmaplen%3)!=0)
2189
printf("PSD: Colourmap looks screwed! Aiee!\n");
2190
if (psd_image.colmaplen==0)
2191
printf("PSD: Indexed image has no colourmap!\n");
2192
if (psd_image.colmaplen!=768)
2193
printf("PSD: Warning: Indexed image is %ld!=256 colours.\n",
2194
psd_image.colmaplen/3);
2195
if (psd_image.colmaplen==768)
2197
reshuffle_cmap(psd_image.colmapdata);
2198
gimp_image_set_colormap (image_ID,
2306
image_ID = gimp_image_new (PSDheader.columns, PSDheader.rows,
2307
psd_type_to_gimp_base_type(imagetype));
2308
gimp_image_set_filename (image_ID, name);
2309
if (psd_type_to_gimp_base_type (imagetype) == GIMP_INDEXED)
2311
if ((psd_image.colmaplen % 3) != 0)
2312
printf("PSD: Colourmap looks screwed! Aiee!\n");
2313
if (psd_image.colmaplen == 0)
2314
printf("PSD: Indexed image has no colourmap!\n");
2315
if (psd_image.colmaplen != 768)
2316
printf("PSD: Warning: Indexed image is %d!=256 colours.\n",
2317
psd_image.colmaplen / 3);
2318
if (psd_image.colmaplen == 768)
2320
reshuffle_cmap (psd_image.colmapdata);
2321
gimp_image_set_colormap (image_ID,
2199
2322
psd_image.colmapdata,
2204
layer_ID = gimp_layer_new (image_ID, _("Background"),
2205
PSDheader.columns, PSDheader.rows,
2206
psd_type_to_gimp_type(imagetype),
2207
100, GIMP_NORMAL_MODE);
2209
gimp_image_add_layer (image_ID, layer_ID, 0);
2210
drawable = gimp_drawable_get (layer_ID);
2327
layer_ID = gimp_layer_new (image_ID, _("Background"),
2328
PSDheader.columns, PSDheader.rows,
2329
psd_type_to_gimp_type(imagetype),
2330
100, GIMP_NORMAL_MODE);
2332
gimp_image_add_layer (image_ID, layer_ID, 0);
2333
drawable = gimp_drawable_get (layer_ID);
2217
switch (PSDheader.mode)
2219
case 1: /* Grayscale */
2222
case 2: /* Indexed Colour */
2225
case 3: /* RGB Colour */
2229
printf("aux? Aieeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee!!!!!!!!!\n");
2234
channels = PSDheader.channels - channels;
2236
if (psd_image.absolute_alpha)
2339
switch (PSDheader.mode)
2341
case 1: /* Grayscale */
2344
case 2: /* Indexed Colour */
2347
case 3: /* RGB Colour */
2351
printf ("aux? Aieeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee!!!!!!!!!\n");
2356
channels = PSDheader.channels - channels;
2358
if (psd_image.absolute_alpha)
2243
channels = gimp_drawable_bpp(drawable->drawable_id);
2247
dest = g_malloc( step * PSDheader.columns * PSDheader.rows );
2365
channels = gimp_drawable_bpp (drawable->drawable_id);
2369
dest = g_malloc (step * PSDheader.columns * PSDheader.rows);
2249
2371
if (PSDheader.compression == 1)
2251
nguchars = PSDheader.columns * PSDheader.rows;
2252
temp = g_malloc (PSDheader.imgdatalen);
2253
xfread (fd, temp, PSDheader.imgdatalen, "image data");
2256
gimp_progress_update ((double)1.00);
2258
if(imagetype==PSD_BITMAP_IMAGE) /* convert bitmap to grayscale */
2373
nguchars = PSDheader.columns * PSDheader.rows;
2374
temp = g_malloc (PSDheader.imgdatalen);
2375
xfread (fd, temp, PSDheader.imgdatalen, "image data");
2378
gimp_progress_update (1.0);
2380
if (imagetype == PSD_BITMAP_IMAGE) /* convert bitmap to grayscale */
2263
2385
g_malloc (((PSDheader.columns + 7) >> 3) * PSDheader.rows);
2265
decode (PSDheader.imgdatalen,
2387
decode (PSDheader.imgdatalen,
2266
2388
nguchars >> 3, temp,monobuf, step);
2267
bitmap2gray (monobuf, dest,
2389
bitmap2gray (monobuf, dest,
2268
2390
PSDheader.columns, PSDheader.rows);
2274
decode(PSDheader.imgdatalen, nguchars, temp, dest, step);
2279
gimp_progress_update (1.0);
2281
cmykbuf = g_malloc (step * nguchars);
2282
decode (PSDheader.imgdatalen, nguchars, temp, cmykbuf, step);
2284
cmyk2rgb (cmykbuf, dest, PSDheader.columns, PSDheader.rows,
2396
decode (PSDheader.imgdatalen, nguchars, temp, dest, step);
2401
gimp_progress_update (1.0);
2403
cmykbuf = g_malloc (step * nguchars);
2404
decode (PSDheader.imgdatalen, nguchars, temp, cmykbuf, step);
2406
cmyk2rgb (cmykbuf, dest, PSDheader.columns, PSDheader.rows,
2295
gimp_progress_update ((double)1.00);
2297
xfread_interlaced(fd, dest, PSDheader.imgdatalen,
2298
"raw image data", step);
2302
gimp_progress_update ((double)1.00);
2304
cmykbuf = g_malloc(PSDheader.imgdatalen);
2305
xfread_interlaced(fd, cmykbuf, PSDheader.imgdatalen,
2306
"raw cmyk image data", step);
2308
cmykp2rgb(cmykbuf, dest,
2309
PSDheader.columns, PSDheader.rows, step > 4);
2417
gimp_progress_update (1.0);
2419
xfread_interlaced (fd, dest, PSDheader.imgdatalen,
2420
"raw image data", step);
2424
gimp_progress_update (10);
2426
cmykbuf = g_malloc (PSDheader.imgdatalen);
2427
xfread_interlaced (fd, cmykbuf, PSDheader.imgdatalen,
2428
"raw cmyk image data", step);
2430
cmykp2rgb (cmykbuf, dest,
2431
PSDheader.columns, PSDheader.rows, step > 4);
2315
2437
if (want_aux) /* want_aux */
2317
extract_channels(dest, channels, step,
2319
PSDheader.columns, PSDheader.rows);
2439
extract_channels (dest, channels, step,
2441
PSDheader.columns, PSDheader.rows);
2321
goto finish_up; /* Haha! Look! A goto! */
2443
goto finish_up; /* Haha! Look! A goto! */
2325
gimp_progress_update ((double)1.00);
2327
if (channels == step) /* gimp bpp == psd bpp */
2330
if (psd_type_to_gimp_type(imagetype)==GIMP_INDEXEDA_IMAGE)
2332
printf("@@@@ Didn't know that this could happen...\n");
2333
for (iter=0; iter<drawable->width*drawable->height; iter++)
2335
dest[iter*2+1] = 255;
2339
gimp_pixel_rgn_init (&pixel_rgn, drawable,
2340
0, 0, drawable->width, drawable->height,
2342
gimp_pixel_rgn_set_rect (&pixel_rgn, dest,
2343
0, 0, drawable->width, drawable->height);
2345
gimp_drawable_flush (drawable);
2346
gimp_drawable_detach (drawable);
2350
IFDBG printf("Uhhh... uhm... extra channels... heavy...\n");
2352
extract_data_and_channels(dest, channels, step,
2354
drawable->width, drawable->height);
2447
gimp_progress_update (1.0);
2449
if (channels == step) /* gimp bpp == psd bpp */
2452
if (psd_type_to_gimp_type (imagetype) == GIMP_INDEXEDA_IMAGE)
2454
printf ("@@@@ Didn't know that this could happen...\n");
2455
for (iter = 0; iter < drawable->width * drawable->height; iter++)
2457
dest[iter * 2 + 1] = 255;
2461
gimp_pixel_rgn_init (&pixel_rgn, drawable,
2462
0, 0, drawable->width, drawable->height,
2464
gimp_pixel_rgn_set_rect (&pixel_rgn, dest,
2465
0, 0, drawable->width, drawable->height);
2467
gimp_drawable_flush (drawable);
2468
gimp_drawable_detach (drawable);
2472
IFDBG printf ("Uhhh... uhm... extra channels... heavy...\n");
2474
extract_data_and_channels (dest, channels, step,
2476
drawable->width, drawable->height);
2364
2485
if (psd_image.colmaplen > 0)
2365
g_free(psd_image.colmapdata);
2486
g_free(psd_image.colmapdata);
2368
2489
if (psd_image.num_guides > 0)
2370
2491
PSDguide *guide = psd_image.guides;
2373
IFDBG printf("--- Adding %d Guides\n", psd_image.num_guides);
2494
IFDBG printf ("--- Adding %d Guides\n", psd_image.num_guides);
2375
2496
for (i = 0; i < psd_image.num_guides; i++, guide++)
2377
if (guide->horizontal)
2378
gimp_image_add_hguide (image_ID, guide->position);
2380
gimp_image_add_vguide (image_ID, guide->position);
2498
if (guide->horizontal)
2499
gimp_image_add_hguide (image_ID, guide->position);
2501
gimp_image_add_vguide (image_ID, guide->position);
2384
gimp_displays_flush();
2505
gimp_displays_flush ();
2386
IFDBG printf("--- %d layers : pos %ld : a-alph %d ---\n",
2387
psd_image.num_layers, (long int)ftell(fd),
2388
psd_image.absolute_alpha);
2507
IFDBG printf ("--- %d layers : pos %ld : a-alph %d ---\n",
2508
psd_image.num_layers, ftell (fd),
2509
psd_image.absolute_alpha);
2390
2511
return image_ID;
2394
decode(long clen, long uclen, guchar *src, guchar* dst, int step)
2401
for (i = 0; i < PSDheader.rows*PSDheader.channels; ++i)
2403
l -= PSDheader.rowlength[i];
2407
g_warning("decode: %ld should be zero\n", (long)l);
2410
w = PSDheader.rowlength;
2412
packbitsdecode(&clen, uclen, src, dst++, step);
2414
for (j = 0; j < step-1; ++j)
2416
for (i = 0; i < PSDheader.rows; ++i)
2420
packbitsdecode(&clen, uclen, src, dst++, step);
2423
IFDBG printf("clen %ld\n", clen);
2526
for (i = 0; i < PSDheader.rows*PSDheader.channels; ++i)
2528
l -= PSDheader.rowlength[i];
2532
g_warning("decode: %d should be zero\n", l);
2535
w = PSDheader.rowlength;
2537
packbitsdecode (&clen, uclen, src, dst++, step);
2539
for (j = 0; j < step-1; ++j)
2541
for (i = 0; i < PSDheader.rows; ++i)
2546
packbitsdecode (&clen, uclen, src, dst++, step);
2549
IFDBG printf ("clen %ld\n", clen);
2427
2553
* Decode a PackBits data stream.
2430
packbitsdecode(long * clenp, long uclen, guchar *src, guchar *dst, int step)
2556
packbitsdecode (long *clenp,
2433
gint32 clen = *clenp;
2435
while ((clen > 0) && (uclen > 0)) {
2439
if (n < 0) { /* replicate next guchar -n+1 times */
2441
if (n == -128) /* nop */
2445
for (b = *src++; n > 0; --n) {
2449
} else { /* copy next n+1 guchars literally */
2450
for (b = ++n; b > 0; --b) {
2459
printf("%s: unexpected EOF while reading image data\n", prog_name);
2563
gint32 clen = *clenp;
2565
while ((clen > 0) && (uclen > 0))
2573
/* replicate next guchar -n+1 times */
2576
if (n == -128) /* nop */
2580
for (b = *src++; n > 0; --n)
2588
/* copy next n+1 guchars literally */
2590
for (b = ++n; b > 0; --b)
2603
printf ("PSD: unexpected EOF while reading image data\n");
2466
2611
* Decode a PackBits channel from file.
2469
unpack_pb_channel(FILE *fd, guchar *dst, gint32 unpackedlen, guint32 *offset)
2614
unpack_pb_channel (FILE *fd,
2472
gint32 upremain = unpackedlen;
2474
while (upremain > 0)
2476
n = (int) getguchar(fd, "packbits1");
2482
{ /* replicate next guchar -n+1 times */
2483
if (n == -128) /* nop */
2488
b = getguchar(fd, "packbits2");
2492
if (upremain >= 0) {
2500
{ /* copy next n+1 guchars literally */
2501
for (b = ++n; b > 0; --b)
2503
const guchar c = getguchar(fd, "packbits3");
2504
if (upremain >= 0) {
2517
printf("*** Unpacking overshot destination (%d) buffer by %d bytes!\n",
2620
gint32 upremain = unpackedlen;
2622
while (upremain > 0)
2624
n = (int) getguchar(fd, "packbits1");
2631
/* replicate next guchar -n+1 times */
2633
if (n == -128) /* nop */
2638
b = getguchar(fd, "packbits2");
2653
/* copy next n+1 guchars literally */
2655
for (b = ++n; b > 0; --b)
2657
const guchar c = getguchar (fd, "packbits3");
2674
printf("*** Unpacking overshot destination (%d) buffer by %d bytes!\n",
2524
cmyk2rgb(unsigned char * src, unsigned char * dst,
2525
long width, long height, int alpha)
2681
cmyk2rgb (unsigned char *src,
2531
for (i = 0; i < height; i++) {
2532
for (j = 0; j < width; j++) {
2538
gimp_cmyk_to_rgb_int (&r, &g, &b, &k);
2549
gimp_progress_update ((double)(2.0*(double)height)/
2550
((double)height+(double)i));
2690
for (i = 0; i < height; i++)
2692
for (j = 0; j < width; j++)
2699
gimp_cmyk_to_rgb_int (&r, &g, &b, &k);
2710
gimp_progress_update ((2.0 * height) / ((double) height + (double) i));
2694
getguchar(FILE *fd, gchar *why)
2866
getguchar (FILE *fd,
2700
2873
if (tmp == EOF)
2702
printf("%s: unexpected EOF while reading '%s' chunk\n",
2875
printf ("PSD: unexpected EOF while reading '%s' chunk\n", why);
2710
getgshort(FILE *fd, gchar *why)
2883
getgint16 (FILE *fd,
2714
b1 = getguchar(fd, why);
2715
b2 = getguchar(fd, why);
2888
b1 = getguchar (fd, why);
2889
b2 = getguchar (fd, why);
2717
return (gshort) ((b1 * 256) + b2);
2891
return (gint16) ((b1 * 256) + b2);
2721
getglong(FILE *fd, gchar *why)
2895
getgint32 (FILE *fd,
2723
2898
guchar s1, s2, s3, s4;
2725
s1 = getguchar(fd, why);
2726
s2 = getguchar(fd, why);
2727
s3 = getguchar(fd, why);
2728
s4 = getguchar(fd, why);
2900
s1 = getguchar (fd, why);
2901
s2 = getguchar (fd, why);
2902
s3 = getguchar (fd, why);
2903
s4 = getguchar (fd, why);
2730
return (glong) ((s1*256*256*256) + (s2*256*256) + (s3*256) + s4);
2905
return (gint32) ((s1 * 256 * 256 * 256) +
2734
xfread(FILE * fd, void * buf, long len, gchar *why)
2736
if (fread(buf, len, 1, fd) == 0)
2917
if (fread (buf, len, 1, fd) == 0)
2738
printf("%s: unexpected EOF while reading '%s' chunk\n",
2919
printf ("PSD: unexpected EOF while reading '%s' chunk\n", why);
2745
xfread_interlaced(FILE* fd, guchar* buf, long len, gchar *why, gint step)
2925
xfread_interlaced (FILE *fd,
2748
gint pix, pos, bpplane;
2932
gint pix, pos, bpplane;
2934
bpplane = len / step;
2936
if (len % step != 0)
2754
printf("PSD: Stern warning: data size is not a factor of step size!\n");
2938
printf ("PSD: Stern warning: data size is not a factor of step size!\n");
2757
for (pix=0; pix<step; pix++)
2941
for (pix = 0; pix < step; pix++)
2759
2943
dest = buf + pix;
2761
for (pos=0; pos<bpplane; pos++)
2763
*dest = getguchar(fd, why);
2945
for (pos = 0; pos < bpplane; pos++)
2947
*dest = getguchar (fd, why);
2770
read_whole_file(FILE * fd)
2954
read_whole_file (FILE *fd)
2777
xfread(fd, &PSDheader.signature, 4, "signature");
2778
PSDheader.version = getgshort(fd, "version");
2779
xfread(fd, &dummy, 6, "reserved");
2780
PSDheader.channels = getgshort(fd, "channels");
2781
PSDheader.rows = getglong(fd, "rows");
2782
PSDheader.columns = getglong(fd, "columns");
2783
PSDheader.bpp = getgshort(fd, "depth");
2784
PSDheader.mode = getgshort(fd, "mode");
2787
psd_image.num_layers = 0;
2788
psd_image.type = PSDheader.mode;
2789
psd_image.colmaplen = 0;
2961
xfread (fd, &PSDheader.signature, 4, "signature");
2962
PSDheader.version = getgint16 (fd, "version");
2963
xfread (fd, &dummy, 6, "reserved");
2964
PSDheader.channels = getgint16 (fd, "channels");
2965
PSDheader.rows = getgint32 (fd, "rows");
2966
PSDheader.columns = getgint32 (fd, "columns");
2967
PSDheader.bpp = getgint16 (fd, "depth");
2968
PSDheader.mode = getgint16 (fd, "mode");
2971
psd_image.num_layers = 0;
2972
psd_image.type = PSDheader.mode;
2973
psd_image.colmaplen = 0;
2790
2974
psd_image.num_aux_channels = 0;
2791
psd_image.num_guides = 0;
2794
psd_image.colmaplen = getglong(fd, "color data length");
2975
psd_image.num_guides = 0;
2978
psd_image.colmaplen = getgint32 (fd, "color data length");
2796
2980
if (psd_image.colmaplen > 0)
2798
psd_image.colmapdata = g_malloc(psd_image.colmaplen);
2799
xfread(fd, psd_image.colmapdata, psd_image.colmaplen, "colormap");
2982
psd_image.colmapdata = g_malloc (psd_image.colmaplen);
2983
xfread (fd, psd_image.colmapdata, psd_image.colmaplen, "colormap");
2803
PSDheader.imgreslen = getglong(fd, "image resource length");
2987
PSDheader.imgreslen = getgint32 (fd, "image resource length");
2804
2988
if (PSDheader.imgreslen > 0)
2806
do_image_resources(fd);
2990
do_image_resources (fd);
2810
PSDheader.miscsizelen = getglong(fd, "misc size data length");
2994
PSDheader.miscsizelen = getgint32 (fd, "misc size data length");
2811
2995
if (PSDheader.miscsizelen > 0)
2813
do_layer_and_mask(fd);
2997
do_layer_and_mask (fd);
2817
PSDheader.compression = getgshort(fd, "compression");
2818
IFDBG printf("<<compr:%d>>", (int)PSDheader.compression);
3001
PSDheader.compression = getgint16 (fd, "compression");
3002
IFDBG printf("<<compr:%d>>", (int) PSDheader.compression);
2819
3003
if (PSDheader.compression == 1) /* RLE */
2821
PSDheader.rowlength = g_malloc(PSDheader.rows *
2822
PSDheader.channels * sizeof(gushort));
2823
for (i = 0; i < PSDheader.rows*PSDheader.channels; ++i)
2824
PSDheader.rowlength[i] = getgshort(fd, "x");
3005
PSDheader.rowlength = g_malloc (PSDheader.rows *
3006
PSDheader.channels * sizeof(guint16));
3008
for (i = 0; i < PSDheader.rows * PSDheader.channels; ++i)
3009
PSDheader.rowlength[i] = getgint16 (fd, "x");
2827
fseek(fd, 0, SEEK_END);
2828
PSDheader.imgdatalen = ftell(fd)-pos;
2829
fseek(fd, pos, SEEK_SET);
2832
if (strncmp(PSDheader.signature, "8BPS", 4) != 0)
3012
fseek (fd, 0, SEEK_END);
3013
PSDheader.imgdatalen = ftell (fd) - pos;
3014
fseek (fd, pos, SEEK_SET);
3017
if (strncmp (PSDheader.signature, "8BPS", 4) != 0)
2834
printf("%s: not an Adobe Photoshop PSD file\n", prog_name);
3019
g_message (_("This is not an Adobe Photoshop PSD file"));
2837
3022
if (PSDheader.version != 1)
2839
printf("%s: bad version number '%d', not 1\n",
2840
prog_name, PSDheader.version);
3024
g_message (_("The PSD file has bad version number '%d', not 1"), PSDheader.version);
2843
3027
w = PSDheader.mode;
2844
IFDBG printf("HEAD:\n"
2845
"\tChannels %d\n\tRows %ld\n\tColumns %ld\n\tDepth %d\n\tMode %d (%s)\n"
2846
"\tColour data %ld guchars\n",
2847
PSDheader.channels, PSDheader.rows,
2848
PSDheader.columns, PSDheader.bpp,
2849
w, modename[w < 10 ? w : 10],
2850
psd_image.colmaplen);
3028
IFDBG printf ("HEAD:\n"
3029
"\tChannels %d\n\tRows %d\n\tColumns %d\n\tDepth %d\n\tMode %d (%s)\n"
3030
"\tColour data %d guchars\n",
3031
PSDheader.channels, PSDheader.rows,
3032
PSDheader.columns, PSDheader.bpp,
3033
w, modename[w < 10 ? w : 10],
3034
psd_image.colmaplen);
2851
3035
/* printf("\tImage resource length: %lu\n", PSDheader.imgreslen);*/
2852
IFDBG printf("\tLayer/Mask Data length: %lu\n", PSDheader.miscsizelen);
3036
IFDBG printf ("\tLayer/Mask Data length: %u\n", PSDheader.miscsizelen);
2853
3037
w = PSDheader.compression;
2854
IFDBG printf("\tCompression %d (%s)\n", w, w ? "RLE" : "raw");
3038
IFDBG printf ("\tCompression %d (%s)\n", w, w ? "RLE" : "raw");