Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Whitespace cleanup

  • Loading branch information...
commit c7d86152f0e450aee1be7855d2120d22df477cb0 1 parent c0b9e7b
David Reid authored
69 include/erl_img.hrl
View
@@ -1,5 +1,5 @@
%%
-%% image format A R G B
+%% image format A R G B
%% pixel data 16 16 16 16
%%
-ifndef(__ERL_IMG_HRL__).
@@ -28,11 +28,11 @@
5 -> <<0,0,0,0,0>>;
6 -> <<0,0,0,0,0,0>>;
7 -> <<0,0,0,0,0,0,0>>;
- N -> list_to_binary(lists:duplicate(N,0))
- end).
+ N -> list_to_binary(lists:duplicate(N,0))
+ end).
-define(IMAGE_TYPES, [?IMAGE_JPEG,
- ?IMAGE_TIFF,
+ ?IMAGE_TIFF,
?IMAGE_GIF,
?IMAGE_PNG,
?IMAGE_BMP,
@@ -40,42 +40,41 @@
?VIDEO_MPEG]).
-record(erl_pixmap,
- {
- top = 0,
- left = 0,
- width = 0,
- height = 0,
- palette, %% list [{R,G,B}]
- format, %% pixmap format
- attributes = [], %% extension codes
- pixels = [] %% [ {Ri,binary(Row)} ]
- }).
+ {
+ top = 0,
+ left = 0,
+ width = 0,
+ height = 0,
+ palette, %% list [{R,G,B}]
+ format, %% pixmap format
+ attributes = [], %% extension codes
+ pixels = [] %% [ {Ri,binary(Row)} ]
+ }).
-record(erl_image,
- {
- type, %% module name of image handler
- name, %% Image name (no path)
- filename, %% Full filename
- size, %% File size
- extension, %% extension used
- mtime, %% file creation date {{YYYY,MM,DD},{HH,MM,SS}}
+ {
+ type, %% module name of image handler
+ name, %% Image name (no path)
+ filename, %% Full filename
+ size, %% File size
+ extension, %% extension used
+ mtime, %% file creation date {{YYYY,MM,DD},{HH,MM,SS}}
itime, %% image creation date {{YYYY,MM,DD},{HH,MM,SS}}
comment = "", %% image comment (if present)
- format, %% pixel format:
- %% gray4, gray8,
- %% palette4, palette8
- %% b8g8r8 r8g8b8 r8g8b8a8
- width, %% Image width
- height, %% Image height
- depth, %% Image depth
- bytes_pp = 3, %% bytes per pixel
- alignment = 1,
+ format, %% pixel format:
+ %% gray4, gray8,
+ %% palette4, palette8
+ %% b8g8r8 r8g8b8 r8g8b8a8
+ width, %% Image width
+ height, %% Image height
+ depth, %% Image depth
+ bytes_pp = 3, %% bytes per pixel
+ alignment = 1,
attributes = [], %% list of attributes [{atom(Key),term(Value)}]
- order, %% sample order left_to_right or right_to_left
- palette, %% list [{R,G,B}]
- pixmaps = [] %% [#erl_pixmap]
- }).
+ order, %% sample order left_to_right or right_to_left
+ palette, %% list [{R,G,B}]
+ pixmaps = [] %% [#erl_pixmap]
+ }).
-endif.
-
14 src/adler.erl
View
@@ -7,7 +7,7 @@
-export([adler32/1, adler32/2]).
--define(BASE, 65521). %% largest prime smaller than 65536
+-define(BASE, 65521). %% largest prime smaller than 65536
-define(NMAX, 5552).
adler32(Bin) ->
@@ -25,20 +25,16 @@ adler_n(Adler, Offs, S1, S2, Bin, 0) ->
Len = size(Bin) - Offs,
K = if Len < ?NMAX -> Len; true -> ?NMAX end,
if K == 0 ->
- (S2 bsl 16) bor S1;
+ (S2 bsl 16) bor S1;
true ->
- adler_n(Adler, Offs, S11, S12, Bin, K)
+ adler_n(Adler, Offs, S11, S12, Bin, K)
end;
adler_n(Adler, Offs, S1, S2, Bin, I) when I >= 8 ->
<<_:Offs/binary, C0,C1,C2,C3,C4,C5,C6,C7,_/binary>> = Bin,
S11 = S1+C0,
adler_n(Adler, Offs+8,
- S11+C1+C2+C3+C4+C5+C6+C7,
- S2+8*S11+7*C1+6*C2+5*C3+4*C4+3*C5+2*C6+C7, Bin, I-8);
+ S11+C1+C2+C3+C4+C5+C6+C7,
+ S2+8*S11+7*C1+6*C2+5*C3+4*C4+3*C5+2*C6+C7, Bin, I-8);
adler_n(Adler, Offs, S1, S2, Bin, I) ->
<<_:Offs/binary, C0,_/binary>> = Bin,
adler_n(Adler, Offs+1, S1+C0, S2+S1+C0, Bin, I-1).
-
-
-
-
172 src/erl_img.erl
View
@@ -39,23 +39,23 @@ nib(N) -> (N-10)+$A.
%% Check a header of least 64 bytes
magic([Type|Ts], Bin) ->
case apply(Type, magic, [Bin]) of
- true -> {true, Type };
- false -> magic(Ts, Bin)
+ true -> {true, Type };
+ false -> magic(Ts, Bin)
end;
-magic([], _Bin) ->
+magic([], _Bin) ->
false.
%% Read file mtime information
file_info(File, _IMG) ->
case file:read_file_info(File) of
- {ok, Info} when Info#file_info.type == regular,
- Info#file_info.size > 0 ->
- {ok, {Info#file_info.mtime,Info#file_info.size}};
- {ok, _Other} ->
- {error, bad_file};
- Error ->
- Error
+ {ok, Info} when Info#file_info.type == regular,
+ Info#file_info.size > 0 ->
+ {ok, {Info#file_info.mtime,Info#file_info.size}};
+ {ok, _Other} ->
+ {error, bad_file};
+ Error ->
+ Error
end.
@@ -63,31 +63,31 @@ file_info(File, _IMG) ->
read_magic_info(Fd) ->
file:position(Fd, 0),
case file:read(Fd, 64) of
- {ok, Bin} ->
- case magic(?IMAGE_TYPES, Bin) of
- {true, Type} ->
- read_info(Type, Fd);
- false ->
- {error, not_supported}
- end;
- Error ->
- Error
+ {ok, Bin} ->
+ case magic(?IMAGE_TYPES, Bin) of
+ {true, Type} ->
+ read_info(Type, Fd);
+ false ->
+ {error, not_supported}
+ end;
+ Error ->
+ Error
end.
-
+
magic_info(File) ->
case file:open(File,[raw,binary,read]) of
- {ok,Fd} ->
- Res = read_magic_info(Fd),
- file:close(Fd),
- case Res of
- {ok,IMG} ->
- {ok,IMG#erl_image { filename = File,
- name = filename:basename(File) }};
- Error ->
- Error
- end;
- Error -> Error
+ {ok,Fd} ->
+ Res = read_magic_info(Fd),
+ file:close(Fd),
+ case Res of
+ {ok,IMG} ->
+ {ok,IMG#erl_image { filename = File,
+ name = filename:basename(File) }};
+ Error ->
+ Error
+ end;
+ Error -> Error
end.
@@ -101,30 +101,30 @@ extensions(IMG) ->
read_file_info(File) ->
case file_info(File, #erl_image { }) of
- {ok, {MTime,Size}} ->
- case magic_info(File) of
- {ok,IMG} ->
- {ok,IMG#erl_image { mtime = MTime,
- size = Size}};
- Error ->
- Error
- end;
- Error -> Error
+ {ok, {MTime,Size}} ->
+ case magic_info(File) of
+ {ok,IMG} ->
+ {ok,IMG#erl_image { mtime = MTime,
+ size = Size}};
+ Error ->
+ Error
+ end;
+ Error -> Error
end.
load(File) ->
case file:open(File, [raw, binary, read]) of
- {ok,Fd} ->
- Res = case read_magic_info(Fd) of
- {ok, IMG} ->
- read(Fd, IMG#erl_image { filename = File });
- Error ->
- Error
- end,
- file:close(Fd),
- Res;
- Error -> Error
+ {ok,Fd} ->
+ Res = case read_magic_info(Fd) of
+ {ok, IMG} ->
+ read(Fd, IMG#erl_image { filename = File });
+ Error ->
+ Error
+ end,
+ file:close(Fd),
+ Res;
+ Error -> Error
end.
save(IMG) ->
@@ -132,30 +132,30 @@ save(IMG) ->
save(File, IMG) ->
case file:open(File, [raw, binary, write]) of
- {ok,Fd} ->
- Res = write(Fd, IMG),
- file:close(Fd),
- Res;
- Error ->
- Error
+ {ok,Fd} ->
+ Res = write(Fd, IMG),
+ file:close(Fd),
+ Res;
+ Error ->
+ Error
end.
to_binary(IMG) ->
case file:open(<<>>, [ram, binary, write]) of
- {ok,Fd} ->
- ok = write(Fd, IMG),
- case ram_file:get_file_close(Fd) of
- {ok, Data} ->
- {ok,Data};
- Error ->
- Error
- end;
- Error ->
- Error
+ {ok,Fd} ->
+ ok = write(Fd, IMG),
+ case ram_file:get_file_close(Fd) of
+ {ok, Data} ->
+ {ok,Data};
+ Error ->
+ Error
+ end;
+ Error ->
+ Error
end.
-
-
+
+
read_info(Type, Fd) ->
file:position(Fd, 0),
@@ -164,7 +164,7 @@ read_info(Type, Fd) ->
write_info(Type, Fd, IMG) ->
file:position(Fd, 0),
apply(Type, write_info, [Fd,IMG]).
-
+
read(Fd,IMG) ->
file:position(Fd, 0),
apply(IMG#erl_image.type, read, [Fd,IMG]).
@@ -181,34 +181,34 @@ attribute(IMG, Key) ->
attribute(IMG, Key, Default) ->
case lists:keysearch(Key, 1, IMG#erl_image.attributes) of
- {value, {_, Value}} -> Value;
- false -> Default
+ {value, {_, Value}} -> Value;
+ false -> Default
end.
-set_attribute(IMG, Key, Value) ->
- As = IMG#erl_image.attributes,
+set_attribute(IMG, Key, Value) ->
+ As = IMG#erl_image.attributes,
As1 = case lists:keysearch(Key, 1, As) of
- false -> [{Key,Value}|As];
- {value,_} ->
- lists:keyreplace(Key, 1, As, {Key,Value})
- end,
+ false -> [{Key,Value}|As];
+ {value,_} ->
+ lists:keyreplace(Key, 1, As, {Key,Value})
+ end,
IMG#erl_image { attributes = As1 }.
-
+
dir_info(Dir) ->
case file:list_dir(Dir) of
- {ok, Listing} ->
- dir_list(Listing,Dir);
- Error ->
- Error
+ {ok, Listing} ->
+ dir_list(Listing,Dir);
+ Error ->
+ Error
end.
dir_list([File|Fs], Dir) ->
case read_file_info(filename:join(Dir, File)) of
- {ok,IMG} ->
- [IMG|dir_list(Fs, Dir)];
- _Error ->
- dir_list(Fs, Dir)
+ {ok,IMG} ->
+ [IMG|dir_list(Fs, Dir)];
+ _Error ->
+ dir_list(Fs, Dir)
end;
dir_list([], _Dir) ->
[].
93 src/exif.erl
View
@@ -11,55 +11,50 @@
decode_tag(Tag) when is_integer(Tag) ->
case Tag of
- ?ExposureTime -> 'ExposureTime';
- ?FNumber -> 'FNumber';
- ?ExposureProgram -> 'ExposureProgram';
- ?ISOSpeedRatings -> 'ISOSpeedRatings';
- ?ExifVersion -> 'ExifVersion';
- ?DateTimeOriginal -> 'DateTimeOriginal';
- ?DateTimeDigitized -> 'DateTimeDigitized';
- ?ComponentsConfiguration -> 'ComponentsConfiguration';
- ?CompressedBitsPerPixel -> 'CompressedBitsPerPixel';
- ?ShutterSpeedValue -> 'ShutterSpeedValue';
- ?ApertureValue -> 'ApertureValue';
- ?BrightnessValue -> 'BrightnessValue';
- ?ExposureBiasValue -> 'ExposureBiasValue';
- ?MaxApertureValue -> 'MaxApertureValue';
- ?SubjectDistance -> 'SubjectDistance';
- ?MeteringMode -> 'MeteringMode';
- ?LightSource -> 'LightSource';
- ?Flash -> 'Flash';
- ?FocalLength -> 'FocalLength';
- ?MakerNote -> 'MakerNote';
- ?UserComment -> 'UserComment';
- ?SubsecTime -> 'SubsecTime';
- ?SubsecTimeOriginal -> 'SubsecTimeOriginal';
- ?SubsecTimeDigitized -> 'SubsecTimeDigitized';
- ?FlashPixVersion -> 'FlashPixVersion';
- ?ColorSpace -> 'ColorSpace';
- ?ExifImageWidth -> 'ExifImageWidth';
- ?ExifImageHeight -> 'ExifImageHeight';
- ?RelatedSoundFile -> 'RelatedSoundFile';
- ?ExifInteroperabilityOffset -> 'ExifInteroperabilityOffset';
- ?FocalPlaneXResolution -> 'FocalPlaneXResolution';
- ?FocalPlaneYResolution -> 'FocalPlaneYResolution';
- ?FocalPlaneResolutionUnit -> 'FocalPlaneResolutionUnit';
- ?ExposureIndex -> 'ExposureIndex';
- ?SensingMethod -> 'SensingMethod';
- ?FileSource -> 'FileSource';
- ?SceneType -> 'SceneType';
- ?CFAPattern -> 'CFAPattern';
- ?InteroperabilityIndex -> 'InteroperabilityIndex';
- ?InteroperabilityVersion -> 'InteroperabilityVersion';
- ?RelatedImageFileFormat -> 'RelatedImageFileFormat';
- ?RelatedImageWidth -> 'RelatedImageWidth';
- ?RelatedImageLength -> 'RelatedImageLength';
- Tag -> Tag
+ ?ExposureTime -> 'ExposureTime';
+ ?FNumber -> 'FNumber';
+ ?ExposureProgram -> 'ExposureProgram';
+ ?ISOSpeedRatings -> 'ISOSpeedRatings';
+ ?ExifVersion -> 'ExifVersion';
+ ?DateTimeOriginal -> 'DateTimeOriginal';
+ ?DateTimeDigitized -> 'DateTimeDigitized';
+ ?ComponentsConfiguration -> 'ComponentsConfiguration';
+ ?CompressedBitsPerPixel -> 'CompressedBitsPerPixel';
+ ?ShutterSpeedValue -> 'ShutterSpeedValue';
+ ?ApertureValue -> 'ApertureValue';
+ ?BrightnessValue -> 'BrightnessValue';
+ ?ExposureBiasValue -> 'ExposureBiasValue';
+ ?MaxApertureValue -> 'MaxApertureValue';
+ ?SubjectDistance -> 'SubjectDistance';
+ ?MeteringMode -> 'MeteringMode';
+ ?LightSource -> 'LightSource';
+ ?Flash -> 'Flash';
+ ?FocalLength -> 'FocalLength';
+ ?MakerNote -> 'MakerNote';
+ ?UserComment -> 'UserComment';
+ ?SubsecTime -> 'SubsecTime';
+ ?SubsecTimeOriginal -> 'SubsecTimeOriginal';
+ ?SubsecTimeDigitized -> 'SubsecTimeDigitized';
+ ?FlashPixVersion -> 'FlashPixVersion';
+ ?ColorSpace -> 'ColorSpace';
+ ?ExifImageWidth -> 'ExifImageWidth';
+ ?ExifImageHeight -> 'ExifImageHeight';
+ ?RelatedSoundFile -> 'RelatedSoundFile';
+ ?ExifInteroperabilityOffset -> 'ExifInteroperabilityOffset';
+ ?FocalPlaneXResolution -> 'FocalPlaneXResolution';
+ ?FocalPlaneYResolution -> 'FocalPlaneYResolution';
+ ?FocalPlaneResolutionUnit -> 'FocalPlaneResolutionUnit';
+ ?ExposureIndex -> 'ExposureIndex';
+ ?SensingMethod -> 'SensingMethod';
+ ?FileSource -> 'FileSource';
+ ?SceneType -> 'SceneType';
+ ?CFAPattern -> 'CFAPattern';
+ ?InteroperabilityIndex -> 'InteroperabilityIndex';
+ ?InteroperabilityVersion -> 'InteroperabilityVersion';
+ ?RelatedImageFileFormat -> 'RelatedImageFileFormat';
+ ?RelatedImageWidth -> 'RelatedImageWidth';
+ ?RelatedImageLength -> 'RelatedImageLength';
+ Tag -> Tag
end;
decode_tag(Tag) ->
Tag.
-
-
-
-
-
120 src/gpsinfo.erl
View
@@ -14,80 +14,80 @@
collect_gpsinfo(_Fd, T, Info) ->
Key = decode_tag(T#tiff_entry.tag),
- ?dbg("GPS_INFO(~s) ~p ~p ~p\n",
- [T#tiff_entry.ifd,Key,T#tiff_entry.type,T#tiff_entry.value]),
+ ?dbg("GPS_INFO(~s) ~p ~p ~p\n",
+ [T#tiff_entry.ifd,Key,T#tiff_entry.type,T#tiff_entry.value]),
[{Key,T#tiff_entry.value} | Info].
decode_tag(Tag) when is_integer(Tag) ->
case Tag of
- ?GPSVersionID -> 'GPSVersionID';
- ?GPSLatitudeRef -> 'GPSLatitudeRef';
- ?GPSLatitude -> 'GPSLatitude';
- ?GPSLongitudeRef -> 'GPSLongitudeRef';
- ?GPSLongitude -> 'GPSLongitude';
- ?GPSAltitudeRef -> 'GPSAltitudeRef';
- ?GPSAltitude -> 'GPSAltitude';
- ?GPSTimeStamp -> 'GPSTimeStamp';
- ?GPSSatellites -> 'GPSSatellites';
- ?GPSStatus -> 'GPSStatus';
- ?GPSMeasureMode -> 'GPSMeasureMode';
- ?GPSDOP -> 'GPSDOP';
- ?GPSSpeedRef -> 'GPSSpeedRef';
- ?GPSSpeed -> 'GPSSpeed';
- ?GPSTrackRef -> 'GPSTrackRef';
- ?GPSTrack -> 'GPSTrack';
- ?GPSImgDirectionRef -> 'GPSImgDirectionRef';
- ?GPSImgDirection -> 'GPSImgDirection';
- ?GPSMapDatum -> 'GPSMapDatum';
- ?GPSDestLatitudeRef -> 'GPSDestLatitudeRef';
- ?GPSDestLatitude -> 'GPSDestLatitude';
- ?GPSDestLongitudeRef -> 'GPSDestLongitudeRef';
- ?GPSDestLongitude -> 'GPSDestLongitude';
- ?GPSDestBearingRef -> 'GPSDestBearingRef';
- ?GPSDestBearing -> 'GPSDestBearing';
- ?GPSDestDistanceRef -> 'GPSDestDistanceRef';
- ?GPSDestDistance -> 'GPSDestDistance';
- ?GPSProcessingMethod -> 'GPSProcessingMethod';
- ?GPSAreaInformation -> 'GPSAreaInformation';
- ?GPSDateStamp -> 'GPSDateStamp';
- ?GPSDifferential -> 'GPSDifferential';
- Tag -> Tag
+ ?GPSVersionID -> 'GPSVersionID';
+ ?GPSLatitudeRef -> 'GPSLatitudeRef';
+ ?GPSLatitude -> 'GPSLatitude';
+ ?GPSLongitudeRef -> 'GPSLongitudeRef';
+ ?GPSLongitude -> 'GPSLongitude';
+ ?GPSAltitudeRef -> 'GPSAltitudeRef';
+ ?GPSAltitude -> 'GPSAltitude';
+ ?GPSTimeStamp -> 'GPSTimeStamp';
+ ?GPSSatellites -> 'GPSSatellites';
+ ?GPSStatus -> 'GPSStatus';
+ ?GPSMeasureMode -> 'GPSMeasureMode';
+ ?GPSDOP -> 'GPSDOP';
+ ?GPSSpeedRef -> 'GPSSpeedRef';
+ ?GPSSpeed -> 'GPSSpeed';
+ ?GPSTrackRef -> 'GPSTrackRef';
+ ?GPSTrack -> 'GPSTrack';
+ ?GPSImgDirectionRef -> 'GPSImgDirectionRef';
+ ?GPSImgDirection -> 'GPSImgDirection';
+ ?GPSMapDatum -> 'GPSMapDatum';
+ ?GPSDestLatitudeRef -> 'GPSDestLatitudeRef';
+ ?GPSDestLatitude -> 'GPSDestLatitude';
+ ?GPSDestLongitudeRef -> 'GPSDestLongitudeRef';
+ ?GPSDestLongitude -> 'GPSDestLongitude';
+ ?GPSDestBearingRef -> 'GPSDestBearingRef';
+ ?GPSDestBearing -> 'GPSDestBearing';
+ ?GPSDestDistanceRef -> 'GPSDestDistanceRef';
+ ?GPSDestDistance -> 'GPSDestDistance';
+ ?GPSProcessingMethod -> 'GPSProcessingMethod';
+ ?GPSAreaInformation -> 'GPSAreaInformation';
+ ?GPSDateStamp -> 'GPSDateStamp';
+ ?GPSDifferential -> 'GPSDifferential';
+ Tag -> Tag
end;
decode_tag(Tag) ->
Tag.
latitude(GPSInfo) ->
case proplists:get_value('GPSLatitudeRef', GPSInfo) of
- undefined ->
- undefined;
- Ref ->
- case proplists:get_value('GPSLatitude', GPSInfo) of
- undefined ->
- undefined;
- Sexagesimal ->
- Dec = sexagesimal_to_decimal(Sexagesimal),
- case Ref of
- ["N"] -> Dec;
- ["S"] -> -Dec
- end
- end
+ undefined ->
+ undefined;
+ Ref ->
+ case proplists:get_value('GPSLatitude', GPSInfo) of
+ undefined ->
+ undefined;
+ Sexagesimal ->
+ Dec = sexagesimal_to_decimal(Sexagesimal),
+ case Ref of
+ ["N"] -> Dec;
+ ["S"] -> -Dec
+ end
+ end
end.
longitude(GPSInfo) ->
case proplists:get_value('GPSLongitudeRef', GPSInfo) of
- undefined ->
- undefined;
- Ref ->
- case proplists:get_value('GPSLongitude', GPSInfo) of
- undefined ->
- undefined;
- Sexagesimal ->
- Dec = sexagesimal_to_decimal(Sexagesimal),
- case Ref of
- ["E"] -> Dec;
- ["W"] -> -Dec
- end
- end
+ undefined ->
+ undefined;
+ Ref ->
+ case proplists:get_value('GPSLongitude', GPSInfo) of
+ undefined ->
+ undefined;
+ Sexagesimal ->
+ Dec = sexagesimal_to_decimal(Sexagesimal),
+ case Ref of
+ ["E"] -> Dec;
+ ["W"] -> -Dec
+ end
+ end
end.
sexagesimal_to_decimal([{N1,D1}, {N2,D2}, {N3,D3}]) ->
101 src/image_bmp.erl
View
@@ -13,24 +13,24 @@
-define(BMP_HEADER(FileSz, Offset),
- $B:8,$M:8,
- FileSz:32/little,
- 0:16, 0:16,
- Offset:32/little).
+ $B:8,$M:8,
+ FileSz:32/little,
+ 0:16, 0:16,
+ Offset:32/little).
-define(BMP_INFO(HSize,Width,Height,Planes,BitCount,Compression,
- ImageSize,XRes,YRes,ColorsUsed,ImportantColors),
- HSize:32/little,
- Width:32/little,
- Height:32/little,
- Planes:16/little,
- BitCount:16/little,
- Compression:32/little,
- ImageSize:32/little,
- XRes:32/little,
- YRes:32/little,
- ColorsUsed:32/little,
- ImportantColors:32/little).
+ ImageSize,XRes,YRes,ColorsUsed,ImportantColors),
+ HSize:32/little,
+ Width:32/little,
+ Height:32/little,
+ Planes:16/little,
+ BitCount:16/little,
+ Compression:32/little,
+ ImageSize:32/little,
+ XRes:32/little,
+ YRes:32/little,
+ ColorsUsed:32/little,
+ ImportantColors:32/little).
magic(<<$B,$M, _/binary>>) -> true;
magic(_) -> false.
@@ -42,23 +42,23 @@ extensions() -> [".bmp" ].
read_info(Fd) ->
case file:read(Fd, 54) of
- {ok, << ?BMP_HEADER(_Size,_Offset),
- ?BMP_INFO(_,Width,Height,Planes,_BitCount,
- Compression,_,_,_,_,_) >> } ->
- {ok, #erl_image { type = ?MODULE,
- width = Width,
- height = Height,
- depth = Planes,
- format = b8g8r8,
- bytes_pp = 3,
- alignment = 4,
- order = left_to_right,
- attributes = [{'Compression',Compression}]
- }};
- {ok, _} ->
- {error, bad_magic};
- Error ->
- Error
+ {ok, << ?BMP_HEADER(_Size,_Offset),
+ ?BMP_INFO(_,Width,Height,Planes,_BitCount,
+ Compression,_,_,_,_,_) >> } ->
+ {ok, #erl_image { type = ?MODULE,
+ width = Width,
+ height = Height,
+ depth = Planes,
+ format = b8g8r8,
+ bytes_pp = 3,
+ alignment = 4,
+ order = left_to_right,
+ attributes = [{'Compression',Compression}]
+ }};
+ {ok, _} ->
+ {error, bad_magic};
+ Error ->
+ Error
end.
@@ -68,18 +68,18 @@ write_info(_Fd, _IMG) ->
read(Fd, IMG, RowFun, St0) ->
file:position(Fd, 54),
case read_pixels(Fd, IMG, RowFun, St0) of
- {ok,PIX} ->
- {ok, IMG#erl_image { pixmaps = [PIX] }};
- Error -> Error
+ {ok,PIX} ->
+ {ok, IMG#erl_image { pixmaps = [PIX] }};
+ Error -> Error
end.
%% load image
read(Fd, IMG) ->
- read(Fd, IMG,
- fun(_, Row, Ri, St) ->
- ?dbg("bmp: load row ~p\n", [Ri]),
- [{Ri,Row}|St] end,
- []).
+ read(Fd, IMG,
+ fun(_, Row, Ri, St) ->
+ ?dbg("bmp: load row ~p\n", [Ri]),
+ [{Ri,Row}|St] end,
+ []).
%% save image
write(_Fd, _IMG) ->
@@ -91,7 +91,7 @@ read_pixels(Fd, IMG, RowFun, St0) ->
Height = IMG#erl_image.height,
RowLength = Width*3 + ?PAD_Len(Width*3, 4),
PIX = #erl_pixmap { width = Width, height = Height,
- format = IMG#erl_image.format },
+ format = IMG#erl_image.format },
read_pixels(Fd, PIX, 0, Height, RowLength, RowFun, St0).
@@ -99,16 +99,9 @@ read_pixels(_Fd, PIX, NRows, NRows, _BytesPerRow, _RowFun, St) ->
{ok,PIX#erl_pixmap { pixels = St }};
read_pixels(Fd, PIX, Ri, NRows, BytesPerRow, RowFun, St) ->
case file:read(Fd, BytesPerRow) of
- {ok,Row} ->
- St1 = RowFun(PIX, Row, Ri, St),
- read_pixels(Fd, PIX, Ri+1, NRows, BytesPerRow, RowFun, St1);
- Error ->
- Error
+ {ok,Row} ->
+ St1 = RowFun(PIX, Row, Ri, St),
+ read_pixels(Fd, PIX, Ri+1, NRows, BytesPerRow, RowFun, St1);
+ Error ->
+ Error
end.
-
-
-
-
-
-
-
584 src/image_gif.erl
View
@@ -36,39 +36,39 @@ magic(_) -> false.
mime_type() -> "image/gif".
extensions() -> [ ".gif" ].
-
+
read_info(Fd) ->
case file:read(Fd, 10) of
- {ok, <<?MAGIC87,
- Width:16/little-unsigned-integer,
- Height:16/little-unsigned-integer,_/binary>>} ->
- {ok,#erl_image { type = ?MODULE,
- width = Width,
- height = Height,
- format = palette8,
- order = left_to_right,
- depth = 8 }};
- {ok, <<?MAGIC89,
- Width:16/little-unsigned-integer,
- Height:16/little-unsigned-integer,_/binary>>} ->
- {ok,#erl_image { type = ?MODULE,
- width = Width,
- height = Height,
- format = palette8,
- order = left_to_right,
- depth = 8 }};
- {ok, _} ->
- {error, bad_magic};
- Error ->
- Error
+ {ok, <<?MAGIC87,
+ Width:16/little-unsigned-integer,
+ Height:16/little-unsigned-integer,_/binary>>} ->
+ {ok,#erl_image { type = ?MODULE,
+ width = Width,
+ height = Height,
+ format = palette8,
+ order = left_to_right,
+ depth = 8 }};
+ {ok, <<?MAGIC89,
+ Width:16/little-unsigned-integer,
+ Height:16/little-unsigned-integer,_/binary>>} ->
+ {ok,#erl_image { type = ?MODULE,
+ width = Width,
+ height = Height,
+ format = palette8,
+ order = left_to_right,
+ depth = 8 }};
+ {ok, _} ->
+ {error, bad_magic};
+ Error ->
+ Error
end.
write_info(Fd, IMG) ->
%% Should version be configurable?
file:write(Fd, <<?MAGIC89,
- (IMG#erl_image.width):16/little-unsigned-integer,
- (IMG#erl_image.height):16/little-unsigned-integer>>).
+ (IMG#erl_image.width):16/little-unsigned-integer,
+ (IMG#erl_image.height):16/little-unsigned-integer>>).
%% The Grammar.
@@ -92,191 +92,191 @@ write_info(Fd, IMG) ->
read(Fd,IMG,RowFun,St0) ->
file:position(Fd, 6),
case file:read(Fd, 7) of
- {ok, <<_Width:16/little, _Hight:16/little,
- Map:1, _Cr:3, Sort:1, Pix:3,
- Background:8,
- AspectRatio:8>>} ->
- Palette = read_palette(Fd, Map, Pix+1),
- ?dbg("sizeof(palette)=~p Map=~w, Cr=~w, Sort=~w, Pix=~w\n",
- [length(Palette),Map,Cr,Sort,Pix]),
- ?dbg("Background=~w, AspectRatio=~w\n",
- [Background, AspectRatio]),
- As = [{'Background',Background},
- {'AspectRatio',AspectRatio},
- {'Sort',Sort} | IMG#erl_image.attributes],
- IMG1 = IMG#erl_image { palette = Palette, attributes = As},
- read_data(Fd, IMG1, RowFun, St0, []);
- Error ->
- Error
+ {ok, <<_Width:16/little, _Hight:16/little,
+ Map:1, _Cr:3, Sort:1, Pix:3,
+ Background:8,
+ AspectRatio:8>>} ->
+ Palette = read_palette(Fd, Map, Pix+1),
+ ?dbg("sizeof(palette)=~p Map=~w, Cr=~w, Sort=~w, Pix=~w\n",
+ [length(Palette),Map,Cr,Sort,Pix]),
+ ?dbg("Background=~w, AspectRatio=~w\n",
+ [Background, AspectRatio]),
+ As = [{'Background',Background},
+ {'AspectRatio',AspectRatio},
+ {'Sort',Sort} | IMG#erl_image.attributes],
+ IMG1 = IMG#erl_image { palette = Palette, attributes = As},
+ read_data(Fd, IMG1, RowFun, St0, []);
+ Error ->
+ Error
end.
read(Fd, IMG) ->
- read(Fd, IMG,
- fun(_, Row, Ri, St) ->
- ?dbg("gif: load row ~p\n", [Ri]),
- [{Ri,Row}|St] end,
- []).
+ read(Fd, IMG,
+ fun(_, Row, Ri, St) ->
+ ?dbg("gif: load row ~p\n", [Ri]),
+ [{Ri,Row}|St] end,
+ []).
read_data(Fd, IMG, RowFun, St0, As) ->
case file:read(Fd, 1) of
- {ok, <<?EXTENSION>>} ->
- ?dbg("Extension\n",[]),
- read_extension(Fd, IMG, RowFun, St0, As);
- {ok, <<?IMAGE>>} ->
- ?dbg("Image\n",[]),
- case file:read(Fd, 9) of
- {ok, <<Left:16/little, Top:16/little,
- Width:16/little, Height:16/little,
- Map:1, Interlaced:1, Sort:1,_:2, Pix:3>>} ->
- Palette = read_palette(Fd, Map, Pix+1),
- As1 = [{'Interlaced', Interlaced},
- {'Sort', Sort} | As],
- Pixmap0 =
- #erl_pixmap { top = Top,
- left = Left,
- width = Width,
- height = Height,
- format = IMG#erl_image.format,
- palette = Palette,
- attributes = As1
- },
- ?dbg("pix=~w, sizeof(palette)=~p\n", [Pix,Palette]),
- case read_pixels(Fd,Pixmap0,RowFun,St0,
- Width,Height,Interlaced) of
- {ok, Pixmap1} ->
- %% ?dbg("Pixmap = ~p\n", [Pixmap2]),
- Ps = IMG#erl_image.pixmaps ++ [Pixmap1],
- read_data(Fd, IMG#erl_image { pixmaps = Ps },
- RowFun, St0, []);
- Error -> Error
- end;
- Error -> Error
- end;
- {ok, <<?TRAILER>>} ->
- ?dbg("Trailer\n",[]),
- {ok, IMG};
- Error ->
- Error
+ {ok, <<?EXTENSION>>} ->
+ ?dbg("Extension\n",[]),
+ read_extension(Fd, IMG, RowFun, St0, As);
+ {ok, <<?IMAGE>>} ->
+ ?dbg("Image\n",[]),
+ case file:read(Fd, 9) of
+ {ok, <<Left:16/little, Top:16/little,
+ Width:16/little, Height:16/little,
+ Map:1, Interlaced:1, Sort:1,_:2, Pix:3>>} ->
+ Palette = read_palette(Fd, Map, Pix+1),
+ As1 = [{'Interlaced', Interlaced},
+ {'Sort', Sort} | As],
+ Pixmap0 =
+ #erl_pixmap { top = Top,
+ left = Left,
+ width = Width,
+ height = Height,
+ format = IMG#erl_image.format,
+ palette = Palette,
+ attributes = As1
+ },
+ ?dbg("pix=~w, sizeof(palette)=~p\n", [Pix,Palette]),
+ case read_pixels(Fd,Pixmap0,RowFun,St0,
+ Width,Height,Interlaced) of
+ {ok, Pixmap1} ->
+ %% ?dbg("Pixmap = ~p\n", [Pixmap2]),
+ Ps = IMG#erl_image.pixmaps ++ [Pixmap1],
+ read_data(Fd, IMG#erl_image { pixmaps = Ps },
+ RowFun, St0, []);
+ Error -> Error
+ end;
+ Error -> Error
+ end;
+ {ok, <<?TRAILER>>} ->
+ ?dbg("Trailer\n",[]),
+ {ok, IMG};
+ Error ->
+ Error
end.
read_extension(Fd, IMG,RowFun,St0,As) ->
case file:read(Fd, 1) of
- {ok,<<?COM_EXTENSION>>} ->
- read_comment(Fd, IMG,RowFun,St0,As);
- {ok,<<?APP_EXTENSION>>} ->
- read_app(Fd, IMG,RowFun,St0,As);
- {ok,<<?CTL_EXTENSION>>} ->
- read_ctl(Fd, IMG,RowFun,St0,As);
- {ok,<<?TXT_EXTENSION>>} ->
- read_txt(Fd, IMG,RowFun,St0,As);
- {ok, _} ->
- read_blocks(Fd), %% skip
- read_data(Fd, IMG,RowFun,St0,As)
+ {ok,<<?COM_EXTENSION>>} ->
+ read_comment(Fd, IMG,RowFun,St0,As);
+ {ok,<<?APP_EXTENSION>>} ->
+ read_app(Fd, IMG,RowFun,St0,As);
+ {ok,<<?CTL_EXTENSION>>} ->
+ read_ctl(Fd, IMG,RowFun,St0,As);
+ {ok,<<?TXT_EXTENSION>>} ->
+ read_txt(Fd, IMG,RowFun,St0,As);
+ {ok, _} ->
+ read_blocks(Fd), %% skip
+ read_data(Fd, IMG,RowFun,St0,As)
end.
read_ctl(Fd, IMG,RowFun,St0,As) ->
?dbg("Control block\n",[]),
case read_block(Fd) of
- {ok, <<_:3, DisposalMethod:3, UserInput:1, Transparent:1,
- DelayTime:16/unsigned-little,
- TransparentColor:8>>} ->
- case read_block(Fd) of
- terminator ->
- As1 = [{'TransparentColor', TransparentColor},
- {'DelayTime', DelayTime},
- {'UserInput', UserInput},
- {'Transparent', Transparent},
- {'DisposalMethod', DisposalMethod} | As],
- read_data(Fd,IMG,RowFun,St0,As1);
- {ok,_} ->
- {error, bad_ctl_block};
- Error -> Error
- end;
- Error -> Error
+ {ok, <<_:3, DisposalMethod:3, UserInput:1, Transparent:1,
+ DelayTime:16/unsigned-little,
+ TransparentColor:8>>} ->
+ case read_block(Fd) of
+ terminator ->
+ As1 = [{'TransparentColor', TransparentColor},
+ {'DelayTime', DelayTime},
+ {'UserInput', UserInput},
+ {'Transparent', Transparent},
+ {'DisposalMethod', DisposalMethod} | As],
+ read_data(Fd,IMG,RowFun,St0,As1);
+ {ok,_} ->
+ {error, bad_ctl_block};
+ Error -> Error
+ end;
+ Error -> Error
end.
read_comment(Fd, IMG,RowFun,St0,As) ->
?dbg("Comment block\n",[]),
case read_blocks(Fd) of
- {ok, Comment} ->
- read_data(Fd,
- IMG#erl_image { comment = binary_to_list(Comment)}
- ,RowFun,St0,As);
- Error -> Error
+ {ok, Comment} ->
+ read_data(Fd,
+ IMG#erl_image { comment = binary_to_list(Comment)}
+ ,RowFun,St0,As);
+ Error -> Error
end.
read_txt(Fd, IMG,RowFun,St0,As) ->
?dbg("Text block\n",[]),
case read_block(Fd) of
- {ok, <<GridLeft:16/little, GridTop:16/little,
- _GridWidth:16/little, _GridHeight:16/little,
- CellWidth:8, CellHeight:8,
- Foreground:8, Background:8>>} ->
- case read_blocks(Fd) of
- {ok,Bin} ->
- As1 =
- [{'TextGridLeftPosition', GridLeft},
- {'TextGridTopPosition', GridTop},
- {'CharacterCellWidth', CellWidth},
- {'CharacterCellHeight', CellHeight},
- {'TextForegroundColorIndex', Foreground},
- {'TextBackgroundColorIndex', Background},
- {'Text', binary_to_list(Bin)} | As],
- read_data(Fd,IMG,RowFun,St0,As1);
- Error ->
- Error
- end;
- terminator ->
- {error, bad_txt_block};
- Error -> Error
+ {ok, <<GridLeft:16/little, GridTop:16/little,
+ _GridWidth:16/little, _GridHeight:16/little,
+ CellWidth:8, CellHeight:8,
+ Foreground:8, Background:8>>} ->
+ case read_blocks(Fd) of
+ {ok,Bin} ->
+ As1 =
+ [{'TextGridLeftPosition', GridLeft},
+ {'TextGridTopPosition', GridTop},
+ {'CharacterCellWidth', CellWidth},
+ {'CharacterCellHeight', CellHeight},
+ {'TextForegroundColorIndex', Foreground},
+ {'TextBackgroundColorIndex', Background},
+ {'Text', binary_to_list(Bin)} | As],
+ read_data(Fd,IMG,RowFun,St0,As1);
+ Error ->
+ Error
+ end;
+ terminator ->
+ {error, bad_txt_block};
+ Error -> Error
end.
-
+
read_app(Fd, IMG,RowFun,St0,As) ->
?dbg("Application block\n",[]),
case read_block(Fd) of
- {ok, <<Ident:8/binary, AuthCode:3/binary>>} ->
- case read_blocks(Fd) of
- {ok, AppData} ->
- As1 =
- [{'ApplicationIdentifier', binary_to_list(Ident)},
- {'ApplicationAuthenticationCode',
- binary_to_list(AuthCode)},
- {'ApplicationData', AppData} |
- IMG#erl_image.attributes],
- read_data(Fd,IMG#erl_image { attributes = As1},
- RowFun,St0,As);
- Error ->
- Error
- end;
- terminator ->
- {error, bad_app_block};
- Error ->
- Error
+ {ok, <<Ident:8/binary, AuthCode:3/binary>>} ->
+ case read_blocks(Fd) of
+ {ok, AppData} ->
+ As1 =
+ [{'ApplicationIdentifier', binary_to_list(Ident)},
+ {'ApplicationAuthenticationCode',
+ binary_to_list(AuthCode)},
+ {'ApplicationData', AppData} |
+ IMG#erl_image.attributes],
+ read_data(Fd,IMG#erl_image { attributes = As1},
+ RowFun,St0,As);
+ Error ->
+ Error
+ end;
+ terminator ->
+ {error, bad_app_block};
+ Error ->
+ Error
end.
-
+
%%
%% Read One block
-%% return
+%% return
%% {ok, Block}
%% terminator
%% | {error,Reason}
%%
-%%
+%%
%%
read_block(Fd) ->
case file:read(Fd, 1) of
- {ok, <<0>>} ->
- terminator;
- {ok, <<Size>>} ->
- file:read(Fd, Size);
- Error ->
- Error
+ {ok, <<0>>} ->
+ terminator;
+ {ok, <<Size>>} ->
+ file:read(Fd, Size);
+ Error ->
+ Error
end.
@@ -288,24 +288,24 @@ read_blocks(Fd) ->
read_blocks(Fd,Acc) ->
case read_block(Fd) of
- {ok,Bin} -> read_blocks(Fd,<<Acc/binary,Bin/binary>>);
- terminator -> {ok, Acc};
- Error -> Error
+ {ok,Bin} -> read_blocks(Fd,<<Acc/binary,Bin/binary>>);
+ terminator -> {ok, Acc};
+ Error -> Error
end.
-read_palette(_Fd, 0, _Pixel) ->
+read_palette(_Fd, 0, _Pixel) ->
undefined;
read_palette(Fd, 1, Pixel) ->
Sz = (1 bsl Pixel),
case file:read(Fd, Sz*3) of
- {ok, Bin} ->
- rd_palette(Bin, [], Sz)
+ {ok, Bin} ->
+ rd_palette(Bin, [], Sz)
end.
-rd_palette(_Bin, Map, 0) ->
+rd_palette(_Bin, Map, 0) ->
reverse(Map);
rd_palette(<<R:8,G:8,B:8, Bin/binary>>, Map, I) ->
rd_palette(Bin, [{R,G,B} | Map], I-1).
@@ -318,28 +318,28 @@ write(Fd, IMG) ->
Background = attribute('Background',IMG#erl_image.attributes,0),
AspectRatio = attribute('AspectRatio', IMG#erl_image.attributes,0),
if is_list(Palette) ->
- PLen = length(Palette),
- ColorRes = if PLen > 0, PLen =< 256 ->
- trunc(math:log(PLen)/math:log(2))+1;
- PLen > 0 ->
- 8;
- true ->
- 1
- end,
- Map = 1,
- Cr = ColorRes - 1,
- Sort = 0,
- Pix = ColorRes - 1,
- file:write(Fd, <<Map:1, Cr:3, Sort:1, Pix:3>>),
- file:write(Fd, <<Background:8, AspectRatio:8>>),
- write_palette(Fd, IMG#erl_image.palette, Pix+1);
+ PLen = length(Palette),
+ ColorRes = if PLen > 0, PLen =< 256 ->
+ trunc(math:log(PLen)/math:log(2))+1;
+ PLen > 0 ->
+ 8;
+ true ->
+ 1
+ end,
+ Map = 1,
+ Cr = ColorRes - 1,
+ Sort = 0,
+ Pix = ColorRes - 1,
+ file:write(Fd, <<Map:1, Cr:3, Sort:1, Pix:3>>),
+ file:write(Fd, <<Background:8, AspectRatio:8>>),
+ write_palette(Fd, IMG#erl_image.palette, Pix+1);
true ->
- Map = 0,
- Cr = 0,
- Sort = 0,
- Pix = 0,
- file:write(Fd, <<Map:1, Cr:3, Sort:1, Pix:3>>),
- file:write(Fd, <<Background:8, AspectRatio:8>>)
+ Map = 0,
+ Cr = 0,
+ Sort = 0,
+ Pix = 0,
+ file:write(Fd, <<Map:1, Cr:3, Sort:1, Pix:3>>),
+ file:write(Fd, <<Background:8, AspectRatio:8>>)
end,
write_data(Fd, IMG),
file:write(Fd, <<?TRAILER>>).
@@ -364,13 +364,13 @@ write_pixmaps(Fd, IMG, [Pm|Pms]) ->
UserInput = attribute('UserInput', Pm#erl_pixmap.attributes, 0),
DelayTime = attribute('DelayTime', Pm#erl_pixmap.attributes, 0),
Transparent = attribute('Transparent', Pm#erl_pixmap.attributes, 0),
- TransparentColor = attribute('TransparentColor',
- Pm#erl_pixmap.attributes, 0),
+ TransparentColor = attribute('TransparentColor',
+ Pm#erl_pixmap.attributes, 0),
file:write(Fd, <<?EXTENSION, ?CTL_EXTENSION>>),
- write_blocks(Fd, <<0:3, DisposalMethod:3,
- UserInput:1, Transparent:1,
- DelayTime:16/unsigned-little,
- TransparentColor:8>>),
+ write_blocks(Fd, <<0:3, DisposalMethod:3,
+ UserInput:1, Transparent:1,
+ DelayTime:16/unsigned-little,
+ TransparentColor:8>>),
write_image(Fd, Pm),
write_pixmaps(Fd, IMG, Pms);
write_pixmaps(_Fd, _IMG, []) ->
@@ -380,50 +380,50 @@ write_pixmaps(_Fd, _IMG, []) ->
write_image(Fd, Pm) ->
file:write(Fd, <<?IMAGE>>),
file:write(Fd,
- <<(Pm#erl_pixmap.left):16/little,
- (Pm#erl_pixmap.top):16/little,
- (Pm#erl_pixmap.width):16/little,
- (Pm#erl_pixmap.height):16/little>>),
+ <<(Pm#erl_pixmap.left):16/little,
+ (Pm#erl_pixmap.top):16/little,
+ (Pm#erl_pixmap.width):16/little,
+ (Pm#erl_pixmap.height):16/little>>),
Palette = Pm#erl_pixmap.palette,
Interlaced = attribute('Interlaced', Pm#erl_pixmap.attributes, 0),
%% Special code for none compressed data!!!
Inline = attribute('Inline', Pm#erl_pixmap.attributes, 0),
if is_list(Palette) ->
- PLen = length(Palette),
- ColorRes = if PLen > 0, PLen =< 256 ->
- trunc(math:log(PLen)/math:log(2))+1;
- PLen > 0 ->
- 8;
- true ->
- 1
- end,
- Sort = 0,
- Pix = ColorRes - 1,
- Map = 1,
- file:write(Fd, <<Map:1, Interlaced:1, Sort:1, 0:2, Pix:3>>),
- write_palette(Fd, Palette, Pix+1);
+ PLen = length(Palette),
+ ColorRes = if PLen > 0, PLen =< 256 ->
+ trunc(math:log(PLen)/math:log(2))+1;
+ PLen > 0 ->
+ 8;
+ true ->
+ 1
+ end,
+ Sort = 0,
+ Pix = ColorRes - 1,
+ Map = 1,
+ file:write(Fd, <<Map:1, Interlaced:1, Sort:1, 0:2, Pix:3>>),
+ write_palette(Fd, Palette, Pix+1);
true ->
- Sort = 0,
- Pix = 0,
- Map = 0,
- file:write(Fd, <<Map:1, Interlaced:1, Sort:1, 0:2, Pix:3>>)
+ Sort = 0,
+ Pix = 0,
+ Map = 0,
+ file:write(Fd, <<Map:1, Interlaced:1, Sort:1, 0:2, Pix:3>>)
end,
write_pixels(Fd,
- Pm#erl_pixmap.pixels,
- Pm#erl_pixmap.width,
- Pm#erl_pixmap.height, Interlaced, Inline).
+ Pm#erl_pixmap.pixels,
+ Pm#erl_pixmap.width,
+ Pm#erl_pixmap.height, Interlaced, Inline).
write_pixels(Fd, Pixels, Width, Height, Interlaced, Inline) ->
Bin = collect_pixels(Pixels, Width, Height, Interlaced),
- {LZWCodeSize, Bin1} =
- if Inline == 1 ->
- %% FIXME: check that all pixels are 7 bit !!!!!
- {7,<<128, Bin/binary, 129>>};
- true ->
- lzw:compress_gif(Bin)
- end,
+ {LZWCodeSize, Bin1} =
+ if Inline == 1 ->
+ %% FIXME: check that all pixels are 7 bit !!!!!
+ {7,<<128, Bin/binary, 129>>};
+ true ->
+ lzw:compress_gif(Bin)
+ end,
?dbg("compress: orig_size=~w, size=~w codesize=~w\n",
- [size(Bin), size(Bin1), LZWCodeSize]),
+ [size(Bin), size(Bin1), LZWCodeSize]),
file:write(Fd, <<LZWCodeSize>>),
write_blocks(Fd, Bin1).
@@ -434,24 +434,24 @@ write_pixels(Fd, Pixels, Width, Height, Interlaced, Inline) ->
collect_pixels(Rows, Width, Height, Interlaced) ->
SortedRows = lists:sort(Rows),
if Interlaced == 1 ->
- collect_interlaced(SortedRows,Width,Height,[],[],[],[]);
+ collect_interlaced(SortedRows,Width,Height,[],[],[],[]);
true ->
- collect_raw(SortedRows,Width,Height,[])
+ collect_raw(SortedRows,Width,Height,[])
end.
collect_raw([{Ri,Row} | Rows], Width, Height,Acc) when Ri < Height ->
Sz = size(Row),
R = if Sz > Width ->
- %% remove pixels
- <<Bin:Width/binary, _/binary>> = Row,
- Bin;
- Sz < Width ->
- %% add pixels
- <<Row/binary,
- (list_to_binary(lists:duplicate(Width-Sz,0)))/binary>>;
- true ->
- Row
- end,
+ %% remove pixels
+ <<Bin:Width/binary, _/binary>> = Row,
+ Bin;
+ Sz < Width ->
+ %% add pixels
+ <<Row/binary,
+ (list_to_binary(lists:duplicate(Width-Sz,0)))/binary>>;
+ true ->
+ Row
+ end,
collect_raw(Rows, Width, Height, [R | Acc]);
collect_raw([{_Ri,_Row} | Rows], Width, Height, Acc) ->
%% ignore line out of range
@@ -461,61 +461,61 @@ collect_raw([], _Width, _Height, Acc) ->
collect_interlaced([{Ri,Row}|Rows],Width,Height,R1,R2,R3,R4) ->
case Ri band 7 of
- 0 -> collect_interlaced(Rows,Width,Height,[Row|R1],R2,R3,R4);
- 1 -> collect_interlaced(Rows,Width,Height,R1,R2,R3,[Row|R4]);
- 2 -> collect_interlaced(Rows,Width,Height,R1,R2,[Row|R3],R4);
- 3 -> collect_interlaced(Rows,Width,Height,R1,R2,R3,[Row|R4]);
- 4 -> collect_interlaced(Rows,Width,Height,R1,[Row|R2],R3,R4);
- 5 -> collect_interlaced(Rows,Width,Height,R1,R2,R3,[Row|R4]);
- 6 -> collect_interlaced(Rows,Width,Height,R1,R2,[Row|R3],R4);
- 7 -> collect_interlaced(Rows,Width,Height,R1,R2,R3,[Row|R4])
+ 0 -> collect_interlaced(Rows,Width,Height,[Row|R1],R2,R3,R4);
+ 1 -> collect_interlaced(Rows,Width,Height,R1,R2,R3,[Row|R4]);
+ 2 -> collect_interlaced(Rows,Width,Height,R1,R2,[Row|R3],R4);
+ 3 -> collect_interlaced(Rows,Width,Height,R1,R2,R3,[Row|R4]);
+ 4 -> collect_interlaced(Rows,Width,Height,R1,[Row|R2],R3,R4);
+ 5 -> collect_interlaced(Rows,Width,Height,R1,R2,R3,[Row|R4]);
+ 6 -> collect_interlaced(Rows,Width,Height,R1,R2,[Row|R3],R4);
+ 7 -> collect_interlaced(Rows,Width,Height,R1,R2,R3,[Row|R4])
end;
collect_interlaced([],_Width,_Height,R1,R2,R3,R4) ->
list_to_binary([reverse(R1),reverse(R2),reverse(R3),reverse(R4)]).
-
-
+
+
write_blocks(Fd, Bin) ->
write_blocks(Fd, Bin, 0, size(Bin)).
write_blocks(Fd, Bin, Pos, Size) ->
Sz = Size - Pos,
if Sz > 255 ->
- <<_:Pos/binary, Block:255/binary, _/binary>> = Bin,
- file:write(Fd, <<255, Block/binary>>),
- write_blocks(Fd, Bin, Pos+255, Size);
+ <<_:Pos/binary, Block:255/binary, _/binary>> = Bin,
+ file:write(Fd, <<255, Block/binary>>),
+ write_blocks(Fd, Bin, Pos+255, Size);
true ->
- <<_:Pos/binary, Block:Sz/binary, _/binary>> = Bin,
- file:write(Fd, <<Sz, Block/binary>>),
- file:write(Fd, <<0>>)
+ <<_:Pos/binary, Block:Sz/binary, _/binary>> = Bin,
+ file:write(Fd, <<Sz, Block/binary>>),
+ file:write(Fd, <<0>>)
end.
read_pixels(Fd,Pix0,RowFun,St0,Width,Height,Interlaced) ->
case file:read(Fd, 1) of
- {ok, <<LZWCodeSize>>} ->
- case read_image(Fd,LZWCodeSize,Width,Height) of
- {ok,Data} ->
- case Interlaced of
- 1 ->
- interlaced_data(Data,Pix0,RowFun,St0,Width,Height);
- 0 ->
- raw_data(Data,Pix0,RowFun,St0,0,Width)
- end;
- Error ->
- Error
- end;
- Error ->
- Error
+ {ok, <<LZWCodeSize>>} ->
+ case read_image(Fd,LZWCodeSize,Width,Height) of
+ {ok,Data} ->
+ case Interlaced of
+ 1 ->
+ interlaced_data(Data,Pix0,RowFun,St0,Width,Height);
+ 0 ->
+ raw_data(Data,Pix0,RowFun,St0,0,Width)
+ end;
+ Error ->
+ Error
+ end;
+ Error ->
+ Error
end.
read_image(Fd, LZWCodeSize, _Width, _Height) ->
case read_blocks(Fd) of
- {ok,Bin} ->
- ?dbg("LZWCodeSize=~p compressed=~p\n", [LZWCodeSize, size(Bin)]),
- {ok,lzw:decompress_gif(Bin, LZWCodeSize)};
- Error ->
- Error
+ {ok,Bin} ->
+ ?dbg("LZWCodeSize=~p compressed=~p\n", [LZWCodeSize, size(Bin)]),
+ {ok,lzw:decompress_gif(Bin, LZWCodeSize)};
+ Error ->
+ Error
end.
@@ -524,18 +524,18 @@ read_image(Fd, LZWCodeSize, _Width, _Height) ->
%%
raw_data(Bin,Pix,RowFun,St0,Ri,Width) ->
case Bin of
- <<Row:Width/binary, Bin1/binary>> ->
- St1 = RowFun(Pix,Row,Ri,St0),
- raw_data(Bin1,Pix,RowFun,St1,Ri+1,Width);
- <<>> ->
- {ok, Pix#erl_pixmap { pixels = St0 }}
+ <<Row:Width/binary, Bin1/binary>> ->
+ St1 = RowFun(Pix,Row,Ri,St0),
+ raw_data(Bin1,Pix,RowFun,St1,Ri+1,Width);
+ <<>> ->
+ {ok, Pix#erl_pixmap { pixels = St0 }}
end.
%% Read interlaced data
%%
%% 0 R1a
%% 1 R4a
-%% 2 R3a
+%% 2 R3a
%% 3 R4b
%% 4 R2a
%% 5 R4c
@@ -556,18 +556,12 @@ raster_data(Bin,Pix,RowFun,St0,Height,Ri,Rs,Width) ->
<<Row:Width/binary, Bin1/binary>> = Bin,
St1 = RowFun(Pix,Row,Ri,St0),
raster_data(Bin1,Pix,RowFun,St1,Height,Ri+Rs,Rs,Width).
-
+
attribute(Name, List, Default) ->
case lists:keysearch(Name, 1, List) of
- false ->
- Default;
- {value,{_,Value}} ->
- Value
+ false ->
+ Default;
+ {value,{_,Value}} ->
+ Value
end.
-
-
-
-
-
-
298 src/image_jpeg.erl
View
@@ -1,4 +1,4 @@
-%%% File : img_jpg.erl
+%%% File : image_jpg.erl
%%% Author : Tony Rogvall <tony@bix.hemma.se>
%%% Description : JPG image processing (Exif/JPG files)
%%% Created : 5 Mar 2003 by Tony Rogvall <tony@bix.hemma.se>
@@ -34,18 +34,18 @@ magic(_) -> false.
mime_type() -> "image/jpeg".
extensions() -> [".jpeg", ".jpg"].
-
+
read_info(Fd) ->
case file:read(Fd, 2) of
- {ok, <<?M_SOI:16>>} ->
- read_sections(Fd,
- #erl_image { type = ?MODULE,
- order = upper_left
- });
- {ok,_} ->
- {error, bad_magic};
- Error -> Error
+ {ok, <<?M_SOI:16>>} ->
+ read_sections(Fd,
+ #erl_image { type = ?MODULE,
+ order = upper_left
+ });
+ {ok,_} ->
+ {error, bad_magic};
+ Error -> Error
end.
write_info(_Fd, _IMG) ->
@@ -64,33 +64,33 @@ write(_Fd,_IMG) ->
read_sections(Fd, IMG) ->
case file:read(Fd, 4) of
- eof ->
- {ok,IMG};
- {ok,<<Marker:16,Len:16>>} ->
- read_section(Fd,Marker,Len-2,IMG);
- {ok,_} ->
- {error, bad_file};
- Error -> Error
+ eof ->
+ {ok,IMG};
+ {ok,<<Marker:16,Len:16>>} ->
+ read_section(Fd,Marker,Len-2,IMG);
+ {ok,_} ->
+ {error, bad_file};
+ Error -> Error
end.
read_section(Fd,Marker,Len,IMG) ->
if Marker == ?M_SOS -> {ok,IMG};
- Marker == ?M_EOI -> {ok,IMG};
+ Marker == ?M_EOI -> {ok,IMG};
Marker == ?M_COM ->
- case file:read(Fd, Len) of
- {ok,Bin} ->
- read_sections(Fd, IMG#erl_image {comment=
- binary_to_list(Bin)});
- _Error ->
- {error, bad_file}
- end;
+ case file:read(Fd, Len) of
+ {ok,Bin} ->
+ read_sections(Fd, IMG#erl_image {comment=
+ binary_to_list(Bin)});
+ _Error ->
+ {error, bad_file}
+ end;
Marker == ?M_APP1 ->
- case file:read(Fd, Len) of
- {ok,<<"Exif",0,0,Bin/binary>>} ->
- read_sections(Fd, process_exif(Bin,IMG));
- {ok,_} ->
- read_sections(Fd, IMG)
- end;
+ case file:read(Fd, Len) of
+ {ok,<<"Exif",0,0,Bin/binary>>} ->
+ read_sections(Fd, process_exif(Bin,IMG));
+ {ok,_} ->
+ read_sections(Fd, IMG)
+ end;
Marker == ?M_SOF0;
Marker == ?M_SOF1;
Marker == ?M_SOF2;
@@ -104,55 +104,55 @@ read_section(Fd,Marker,Len,IMG) ->
Marker == ?M_SOF13;
Marker == ?M_SOF14;
Marker == ?M_SOF15 ->
- case file:read(Fd, Len) of
- {ok,Bin} ->
- read_sections(Fd, process_sofn(Bin,IMG));
- Error ->
- Error
- end;
+ case file:read(Fd, Len) of
+ {ok,Bin} ->
+ read_sections(Fd, process_sofn(Bin,IMG));
+ Error ->
+ Error
+ end;
true ->
- file:position(Fd, {cur,Len}),
- read_sections(Fd, IMG)
+ file:position(Fd, {cur,Len}),
+ read_sections(Fd, IMG)
end.
process_sofn(<<Depth:8,Height:16,Width:16,_Components:8,_Bin/binary>>, IMG) ->
IMG#erl_image { depth = Depth,
- height = Height,
- width = Width }.
+ height = Height,
+ width = Width }.
%% Maker OLYMP
collect_olymp(_Fd, T, St) ->
_Key = erl_img:hex16(T#tiff_entry.tag),
- ?dbg("OLYMP(~s) ~p ~p ~p\n",
- [T#tiff_entry.ifd,_Key,T#tiff_entry.type, T#tiff_entry.value]),
+ ?dbg("OLYMP(~s) ~p ~p ~p\n",
+ [T#tiff_entry.ifd,_Key,T#tiff_entry.type, T#tiff_entry.value]),
St.
%% Maker Nikon
collect_nikon(_Fd, T, St) ->
_Key = erl_img:hex16(T#tiff_entry.tag),
- ?dbg("Nikon(~s) ~p ~p ~p\n",
- [T#tiff_entry.ifd,_Key,T#tiff_entry.type, T#tiff_entry.value]),
+ ?dbg("Nikon(~s) ~p ~p ~p\n",
+ [T#tiff_entry.ifd,_Key,T#tiff_entry.type, T#tiff_entry.value]),
St.
%% Maker FUJIFILM
collect_fujifilm(_Fd, T, St) ->
_Key = erl_img:hex16(T#tiff_entry.tag),
- ?dbg("Fujifilm(~s) ~p ~p ~p\n",
- [T#tiff_entry.ifd,_Key,T#tiff_entry.type, T#tiff_entry.value]),
+ ?dbg("Fujifilm(~s) ~p ~p ~p\n",
+ [T#tiff_entry.ifd,_Key,T#tiff_entry.type, T#tiff_entry.value]),
St.
%% Maker Sony DSC
collect_sony(_Fd, T, St) ->
_Key = erl_img:hex16(T#tiff_entry.tag),
- ?dbg("Sony(~s) ~p ~p ~p\n",
- [T#tiff_entry.ifd,_Key,T#tiff_entry.type, T#tiff_entry.value]),
+ ?dbg("Sony(~s) ~p ~p ~p\n",
+ [T#tiff_entry.ifd,_Key,T#tiff_entry.type, T#tiff_entry.value]),
St.
%% Maker other
collect_other(_Fd, T, St) ->
_Key = erl_img:hex16(T#tiff_entry.tag),
- ?dbg("Maker(~s) ~p ~p ~p\n",
- [T#tiff_entry.ifd,_Key,T#tiff_entry.type, T#tiff_entry.value]),
+ ?dbg("Maker(~s) ~p ~p ~p\n",
+ [T#tiff_entry.ifd,_Key,T#tiff_entry.type, T#tiff_entry.value]),
St.
collect_maker(_Fd, T, St) ->
@@ -162,119 +162,119 @@ collect_maker_fixme(Fd, T, St) ->
?dbg("Tif entry=~p\n", [T]),
MakerBin = T#tiff_entry.value,
case MakerBin of
- <<"OLYMP",0,1,0,_/binary>> ->
- image_tiff:scan_ifd(Fd,
- [$0,$:|T#tiff_entry.ifd],
- T#tiff_entry.offs+8,
- T#tiff_entry.endian,
- fun collect_olymp/3, St);
- <<"Nikon",0,1,0,_/binary>> ->
- image_tiff:scan_ifd(Fd,
- [$0,$:|T#tiff_entry.ifd],
- T#tiff_entry.offs+8,
- T#tiff_entry.endian,
- fun collect_nikon/3, St);
- <<"SONY DSC ",0,0,0,_/binary>> ->
- %% NOT working - what is SONY doing ?
- image_tiff:scan_ifd(Fd,
- [$0,$:|T#tiff_entry.ifd],
- T#tiff_entry.offs+14,
- T#tiff_entry.endian,
- fun collect_sony/3, St);
- <<"FUJIFILM",Offset:32/little>> ->
- image_tiff:scan_ifd_bin(MakerBin,
- [$0,$:|T#tiff_entry.ifd],
- Offset, little,
- fun collect_fujifilm/3, St);
- _ ->
- image_tiff:scan_ifd(Fd,
- [$0,$:|T#tiff_entry.ifd],
- T#tiff_entry.offs+8,
- T#tiff_entry.endian,
- fun collect_other/3, St)
+ <<"OLYMP",0,1,0,_/binary>> ->
+ image_tiff:scan_ifd(Fd,
+ [$0,$:|T#tiff_entry.ifd],
+ T#tiff_entry.offs+8,
+ T#tiff_entry.endian,
+ fun collect_olymp/3, St);
+ <<"Nikon",0,1,0,_/binary>> ->
+ image_tiff:scan_ifd(Fd,
+ [$0,$:|T#tiff_entry.ifd],
+ T#tiff_entry.offs+8,
+ T#tiff_entry.endian,
+ fun collect_nikon/3, St);
+ <<"SONY DSC ",0,0,0,_/binary>> ->
+ %% NOT working - what is SONY doing ?
+ image_tiff:scan_ifd(Fd,
+ [$0,$:|T#tiff_entry.ifd],
+ T#tiff_entry.offs+14,
+ T#tiff_entry.endian,
+ fun collect_sony/3, St);
+ <<"FUJIFILM",Offset:32/little>> ->
+ image_tiff:scan_ifd_bin(MakerBin,
+ [$0,$:|T#tiff_entry.ifd],
+ Offset, little,
+ fun collect_fujifilm/3, St);
+ _ ->
+ image_tiff:scan_ifd(Fd,
+ [$0,$:|T#tiff_entry.ifd],
+ T#tiff_entry.offs+8,
+ T#tiff_entry.endian,
+ fun collect_other/3, St)
end.
collect_exif(Fd, T, St) ->
_Key = exif:decode_tag(T#tiff_entry.tag),
- ?dbg("EXIF(~s) ~p ~p ~p\n",
- [T#tiff_entry.ifd,_Key,T#tiff_entry.type, T#tiff_entry.value]),
+ ?dbg("EXIF(~s) ~p ~p ~p\n",
+ [T#tiff_entry.ifd,_Key,T#tiff_entry.type, T#tiff_entry.value]),
case T#tiff_entry.tag of
- ?ExifInteroperabilityOffset ->
- [Offset] = T#tiff_entry.value,
- %% could be handle by a collect_interop?
- case image_tiff:scan_ifd(Fd, [$0,$.|T#tiff_entry.ifd],
- Offset, T#tiff_entry.endian,
- fun collect_exif/3, St) of
- {ok, St1} ->
- St1;
- _Error ->
- St
- end;
- ?MakerNote ->
- case collect_maker(Fd, T, St) of
- {ok,St1} ->
- St1;
- _Error ->
- St
- end;
- _ ->
- St
+ ?ExifInteroperabilityOffset ->
+ [Offset] = T#tiff_entry.value,
+ %% could be handle by a collect_interop?
+ case image_tiff:scan_ifd(Fd, [$0,$.|T#tiff_entry.ifd],
+ Offset, T#tiff_entry.endian,
+ fun collect_exif/3, St) of
+ {ok, St1} ->
+ St1;
+ _Error ->
+ St
+ end;
+ ?MakerNote ->
+ case collect_maker(Fd, T, St) of
+ {ok,St1} ->
+ St1;
+ _Error ->
+ St
+ end;
+ _ ->
+ St
end.
%% Image info collector functions
collect_tiff(Fd, T, St) ->
Key = image_tiff:decode_tag(T#tiff_entry.tag),
- ?dbg("TIFF(~s) ~p ~p ~p\n",
- [T#tiff_entry.ifd,Key,T#tiff_entry.type, T#tiff_entry.value]),
+ ?dbg("TIFF(~s) ~p ~p ~p\n",
+ [T#tiff_entry.ifd,Key,T#tiff_entry.type, T#tiff_entry.value]),
case T#tiff_entry.tag of
- ?ImageWidth ->
- [Width] = T#tiff_entry.value,
- St#erl_image { width = Width };
- ?ImageLength ->
- [Length] = T#tiff_entry.value,
- St#erl_image { height = Length };
- ?BitsPerSample ->
- Bs = T#tiff_entry.value,
- St#erl_image { depth = lists:sum(Bs) };
- ?ImageDescription ->
- [Value] = T#tiff_entry.value,
- St#erl_image { comment = Value };
- ?DateTime ->
- [Value] = T#tiff_entry.value,
- case string:tokens(Value, ": ") of
- [YYYY,MM,DD,H,M,S] ->
- DateTime = {{list_to_integer(YYYY),
- list_to_integer(MM),
- list_to_integer(DD)},
- {list_to_integer(H),
- list_to_integer(M),
- list_to_integer(S)}},
- St#erl_image { itime = DateTime};
- _ ->
- St
- end;
- ?ExifOffset ->
- [Offset] = T#tiff_entry.value,
- case image_tiff:scan_ifd(Fd, [$0,$.|T#tiff_entry.ifd],
- Offset, T#tiff_entry.endian,
- fun collect_exif/3, St) of
- {ok, St1} ->
- St1;
- _Error ->
- St
- end;
- _ ->
- Value = T#tiff_entry.value,
- As = St#erl_image.attributes,
- St#erl_image { attributes = [{Key,Value}|As]}
+ ?ImageWidth ->
+ [Width] = T#tiff_entry.value,
+ St#erl_image { width = Width };
+ ?ImageLength ->
+ [Length] = T#tiff_entry.value,
+ St#erl_image { height = Length };
+ ?BitsPerSample ->
+ Bs = T#tiff_entry.value,
+ St#erl_image { depth = lists:sum(Bs) };
+ ?ImageDescription ->
+ [Value] = T#tiff_entry.value,
+ St#erl_image { comment = Value };
+ ?DateTime ->
+ [Value] = T#tiff_entry.value,
+ case string:tokens(Value, ": ") of
+ [YYYY,MM,DD,H,M,S] ->
+ DateTime = {{list_to_integer(YYYY),
+ list_to_integer(MM),
+ list_to_integer(DD)},
+ {list_to_integer(H),
+ list_to_integer(M),
+ list_to_integer(S)}},
+ St#erl_image { itime = DateTime};
+ _ ->
+ St
+ end;
+ ?ExifOffset ->
+ [Offset] = T#tiff_entry.value,
+ case image_tiff:scan_ifd(Fd, [$0,$.|T#tiff_entry.ifd],
+ Offset, T#tiff_entry.endian,
+ fun collect_exif/3, St) of
+ {ok, St1} ->
+ St1;
+ _Error ->
+ St
+ end;
+ _ ->
+ Value = T#tiff_entry.value,
+ As = St#erl_image.attributes,
+ St#erl_image { attributes = [{Key,Value}|As]}
end.
process_exif(Bin, IMG) ->
case image_tiff:scan_binary(Bin, fun collect_tiff/3, IMG) of
- {ok, IMG1} ->
- IMG1;
- _Error ->
- IMG
+ {ok, IMG1} ->
+ IMG1;
+ _Error ->
+ IMG
end.
323 src/image_png.erl
View
@@ -38,88 +38,88 @@ magic(_) -> false.
mime_type() -> "image/png".
extensions() -> [ ".png" ].
-
+
read_info(Fd) ->
case file:read(Fd, 8) of
- {ok, << ?MAGIC >> } ->
- scan_info(Fd, #erl_image { type = ?MODULE }, true);
- {ok, _} ->
- {error, bad_magic};
- Error ->
- Error
+ {ok, << ?MAGIC >> } ->
+ scan_info(Fd, #erl_image { type = ?MODULE }, true);
+ {ok, _} ->
+ {error, bad_magic};
+ Error ->
+ Error
end.
scan_info(Fd, IMG, First) ->
case read_chunk_hdr(Fd) of
- {ok, Length, Type} ->
- scan_info(Fd, IMG, First, Type, Length);
- Error ->
- Error
+ {ok, Length, Type} ->
+ scan_info(Fd, IMG, First, Type, Length);
+ Error ->
+ Error
end.
scan_info(Fd, IMG, true, ?IHDR, Length) ->
case read_chunk_crc(Fd,Length) of
- {ok, <<Width:32, Height:32, BitDepth:8,
- ColorType:8, CompressionMethod:8,
- FilterMethod:8, InterlaceMethod:8, _/binary >>} ->
- scan_info(Fd, IMG#erl_image {
- width = Width,
- height = Height,
- depth = BitDepth,
- format = format(ColorType,BitDepth),
- order = left_to_right,
- attributes =
- [ {'ColorType', ColorType},
- {'Compression', CompressionMethod},
- {'Filter', FilterMethod },
- {'Interlace', InterlaceMethod }]}, false);
- Error -> Error
+ {ok, <<Width:32, Height:32, BitDepth:8,
+ ColorType:8, CompressionMethod:8,
+ FilterMethod:8, InterlaceMethod:8, _/binary >>} ->
+ scan_info(Fd, IMG#erl_image {
+ width = Width,
+ height = Height,
+ depth = BitDepth,
+ format = format(ColorType,BitDepth),
+ order = left_to_right,
+ attributes =
+ [ {'ColorType', ColorType},
+ {'Compression', CompressionMethod},
+ {'Filter', FilterMethod },
+ {'Interlace', InterlaceMethod }]}, false);
+ Error -> Error
end;
scan_info(Fd, IMG, false, ?tEXt, Length) ->
case read_chunk_crc(Fd, Length) of
- {ok, Bin} ->
- scan_info(Fd, update_txt(IMG, Bin), false);
- Error -> Error
+ {ok, Bin} ->
+ scan_info(Fd, update_txt(IMG, Bin), false);
+ Error -> Error
end;
scan_info(Fd, IMG, false, ?zTXt, Length) ->
case read_chunk_crc(Fd, Length) of
- {ok, CBin} ->
- Bin = zlib:uncompress(CBin),
- scan_info(Fd, update_txt(IMG, Bin), false);
- Error -> Error
+ {ok, CBin} ->
+ Bin = zlib:uncompress(CBin),
+ scan_info(Fd, update_txt(IMG, Bin), false);
+ Error -> Error
end;
scan_info(Fd, IMG, false, ?bKGD, Length) ->
CT = attribute(IMG, 'ColorType', undefined),
case read_chunk_crc(Fd, Length) of
- {ok, <<Index:8>>} when CT==3 ->
- scan_info(Fd, set_attribute(IMG, 'Background', Index), false);
- {ok, <<Gray:16>>} when CT==0; CT==4 ->
- scan_info(Fd, set_attribute(IMG, 'Background', Gray), false);
- {ok, <<R:16,G:16,B:16>>} when CT==2; CT==6 ->
- scan_info(Fd, set_attribute(IMG, 'Background', {R,G,B}), false);
- {ok, _Data} ->
- ?dbg("bKGD other=~p\n", [_Data]),
- scan_info(Fd, IMG, false);
- Error -> Error
+ {ok, <<Index:8>>} when CT==3 ->
+ scan_info(Fd, set_attribute(IMG, 'Background', Index), false);
+ {ok, <<Gray:16>>} when CT==0; CT==4 ->
+ scan_info(Fd, set_attribute(IMG, 'Background', Gray), false);
+ {ok, <<R:16,G:16,B:16>>} when CT==2; CT==6 ->
+ scan_info(Fd, set_attribute(IMG, 'Background', {R,G,B}), false);
+ {ok, _Data} ->
+ ?dbg("bKGD other=~p\n", [_Data]),
+ scan_info(Fd, IMG, false);
+ Error -> Error
end;
scan_info(Fd, IMG, false, ?tIME, Length) ->
case read_chunk_crc(Fd, Length) of
- {ok, <<Year:16, Mon:8, Day:8, H:8, M:8, S:8>>} ->
- scan_info(Fd, IMG#erl_image { mtime = {{Year,Mon,Day},
- {H,M,S}} }, false);
- {ok, _Data} ->
- ?dbg("tIME other=~p\n", [_Data]),
- scan_info(Fd, IMG, false);
- Error -> Error
+ {ok, <<Year:16, Mon:8, Day:8, H:8, M:8, S:8>>} ->
+ scan_info(Fd, IMG#erl_image { mtime = {{Year,Mon,Day},
+ {H,M,S}} }, false);
+ {ok, _Data} ->
+ ?dbg("tIME other=~p\n", [_Data]),
+ scan_info(Fd, IMG, false);
+ Error -> Error
end;
scan_info(Fd, IMG, false, ?pHYs, Length) ->
case read_chunk_crc(Fd, Length) of
- {ok, <<X:32, Y:32, _Unit:8>>} ->
- scan_info(Fd, set_attribute(IMG,'Physical',{X,Y,meter}),false);
- {ok, _Data} ->
- ?dbg("pHYs other=~p\n", [_Data]),
- scan_info(Fd, IMG, false);
- Error -> Error
+ {ok, <<X:32, Y:32, _Unit:8>>} ->
+ scan_info(Fd, set_attribute(IMG,'Physical',{X,Y,meter}),false);
+ {ok, _Data} ->
+ ?dbg("pHYs other=~p\n", [_Data]),
+ scan_info(Fd, IMG, false);
+ Error -> Error
end;
scan_info(_Fd, IMG, false, ?IEND, 0) ->
{ok, IMG};
@@ -131,16 +131,16 @@ scan_info(Fd, IMG, false, _Type, Length) ->
%% Update txt attributes
update_txt(IMG, Txt) ->
case txt(binary_to_list(Txt), []) of
- {value,{Key,Value}} ->
- case Key of
- 'Comment' ->
- IMG#erl_image { comment = Value };
- _ ->
- As = [{Key,Value} | IMG#erl_image.attributes],
- IMG#erl_image { attributes = As }
- end;
- false ->
- IMG
+ {value,{Key,Value}} ->
+ case Key of
+ 'Comment' ->
+ IMG#erl_image { comment = Value };
+ _ ->
+ As = [{Key,Value} | IMG#erl_image.attributes],
+ IMG#erl_image { attributes = As }
+ end;
+ false ->
+ IMG
end.
@@ -214,12 +214,12 @@ write_info(_Fd, _IMG) ->
read(Fd, IMG) ->
- read(Fd, IMG,
- fun(_, Row, Ri, St) ->
- ?dbg("png: load row ~p\n", [Ri]),
- [{Ri,Row}|St] end,
- []).
-
+ read(Fd, IMG,
+ fun(_, Row, Ri, St) ->
+ ?dbg("png: load row ~p\n", [Ri]),
+ [{Ri,Row}|St] end,
+ []).
+
read(Fd, IMG, RowFun, St0) ->
file:position(Fd, 8), %% skip magic
@@ -228,18 +228,18 @@ read(Fd, IMG, RowFun, St0) ->
Resp = read_image(Fd, [], undefined, Z),
zlib:close(Z),
case Resp of
- {ok, Binary, Palette} ->
- {ok,Pixmap} = create_pixmap(IMG, Binary, Palette, RowFun, St0),
- {ok, IMG#erl_image { pixmaps = [Pixmap],
- palette = Palette }};
- Error -> Error
+ {ok, Binary, Palette} ->
+ {ok,Pixmap} = create_pixmap(IMG, Binary, Palette, RowFun, St0),
+ {ok, IMG#erl_image { pixmaps = [Pixmap],
+ palette = Palette }};
+ Error -> Error
end.
create_pixmap(IMG, Bin, Palette, RowFun, St0) ->
Pix0 = #erl_pixmap { width = IMG#erl_image.width,
- height = IMG#erl_image.height,