Skip to content
This repository has been archived by the owner on Dec 17, 2022. It is now read-only.

Commit

Permalink
Initial commit: erl_img-1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
davide committed Aug 20, 2009
0 parents commit ad1e703
Show file tree
Hide file tree
Showing 33 changed files with 3,978 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/short-desc
@@ -0,0 +1 @@
Image processing stuff (bmp, gif, jpeg, png, xpm, tiff, mpeg)
Binary file added ebin/erl_img.beam
Binary file not shown.
Binary file added ebin/exif.beam
Binary file not shown.
Binary file added ebin/image_bmp.beam
Binary file not shown.
Binary file added ebin/image_gif.beam
Binary file not shown.
Binary file added ebin/image_jpeg.beam
Binary file not shown.
Binary file added ebin/image_png.beam
Binary file not shown.
Binary file added ebin/image_tiff.beam
Binary file not shown.
Binary file added ebin/image_undef.beam
Binary file not shown.
Binary file added ebin/image_x_xpixmap.beam
Binary file not shown.
Binary file added ebin/lzw.beam
Binary file not shown.
Binary file added ebin/video_mpeg.beam
Binary file not shown.
81 changes: 81 additions & 0 deletions include/erl_img.hrl
@@ -0,0 +1,81 @@
%%
%% image format A R G B
%% pixel data 16 16 16 16
%%
-ifndef(__ERL_IMG_HRL__).
-define(__ERL_IMG_HRL__, true).

-define(IMAGE_JPEG, image_jpeg).
-define(IMAGE_TIFF, image_tiff).
-define(IMAGE_GIF, image_gif).
-define(IMAGE_PNG, image_png).
-define(IMAGE_BMP, image_bmp).
-define(IMAGE_X_XPIXMAP, image_x_xpixmap).
-define(IMAGE_UNDEF, image_undef).
-define(VIDEO_MPEG, video_mpeg).

-define(PAD_Len(L,A), (((A)-((L) rem (A))) rem (A))).

-define(PAD_Len8(L), ((8 - ((L) band 7)) band 7)).

-define(PAD(L,A),
case ?PAD4_Len(L,A) of
0 -> <<>>;
1 -> <<0>>;
2 -> <<0,0>>;
3 -> <<0,0,0>>;
4 -> <<0,0,0,0>>;
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).

-define(IMAGE_TYPES, [?IMAGE_JPEG,
?IMAGE_TIFF,
?IMAGE_GIF,
?IMAGE_PNG,
?IMAGE_BMP,
?IMAGE_X_XPIXMAP,
?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)} ]
}).


-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}}
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,
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]
}).

-endif.

35 changes: 35 additions & 0 deletions src/Makefile
@@ -0,0 +1,35 @@

EBIN = ../ebin
ERLC = erlc
ERLC_FLAGS = -I../include

OBJS = $(EBIN)/image_bmp.beam \
$(EBIN)/image_x_xpixmap.beam \
$(EBIN)/image_png.beam \
$(EBIN)/image_gif.beam \
$(EBIN)/image_jpeg.beam \
$(EBIN)/image_tiff.beam \
$(EBIN)/image_undef.beam \
$(EBIN)/video_mpeg.beam \
$(EBIN)/exif.beam \
$(EBIN)/lzw.beam \
$(EBIN)/erl_img.beam


debug: ERLC_FLAGS += -Ddebug


all: $(OBJS)

debug: all


$(OBJS): ../include/erl_img.hrl

$(EBIN)/image_tiff.beam: tiff.hrl
$(EBIN)/image_jpeg.beam: jpeg.hrl exif.hrl
$(EBIN)/exif.beam: exif.hrl

$(EBIN)/%.beam: %.erl
$(ERLC) $(ERLC_FLAGS) -o $(EBIN) $<

44 changes: 44 additions & 0 deletions src/adler.erl
@@ -0,0 +1,44 @@
%%% File : adler.erl
%%% Author : Tony Rogvall <tony@bit.hemma.se>
%%% Description : adler checksum
%%% Created : 8 Apr 2003 by Tony Rogvall <tony@bit.hemma.se>

-module(adler).

-export([adler32/1, adler32/2]).

-define(BASE, 65521). %% largest prime smaller than 65536
-define(NMAX, 5552).

adler32(Bin) ->
adler32(0, Bin).


adler32(Adler, Bin) ->
S1 = Adler band 16#ffff,
S2 = (Adler bsr 16) band 16#ffff,
adler_n(Adler, 0, S1, S2, Bin, 0).

adler_n(Adler, Offs, S1, S2, Bin, 0) ->
S11 = S1 rem ?BASE,
S12 = S2 rem ?BASE,
Len = size(Bin) - Offs,
K = if Len < ?NMAX -> Len; true -> ?NMAX end,
if K == 0 ->
(S2 bsl 16) bor S1;
true ->
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);
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).




34 changes: 34 additions & 0 deletions src/api.hrl
@@ -0,0 +1,34 @@
%%
%% These are the functions that make the image api
%%


%% magic(Bin) -> true | false
-export([magic/1]).

%% mime_type() -> <mime-type>
-export([mime_type/0]).

%% extensions() -> [ ".<ext1>" ... ".<extn>"]
-export([extensions/0]).

%% read_info(Fd) -> {ok, #erl_img} | Error
-export([read_info/1]).

%% write_info(Fd, #erl_img) -> ok | Error
-export([write_info/2]).

%% read(Fd, #erl_img) -> {ok, #erl_img'} | Error
%% read(Fd, #erl_img, RowFun, State) -> {ok, #erl_img'} | Error
%% RowFun = fun(#erl_img, Row, RowNumber, RowFormat, St) -> St'
%%
-export([read/2, read/4]).

%% write(Fd, #erl_img) -> ok | Error
-export([write/2]).






6 changes: 6 additions & 0 deletions src/dbg.hrl
@@ -0,0 +1,6 @@

-ifdef(debug).
-define(dbg(Fmt,Args), io:format((Fmt),(Args))).
-else.
-define(dbg(Fmt,Args), ok).
-endif.

0 comments on commit ad1e703

Please sign in to comment.