From: "chris.danx" <chris.danx@ntlworld.com>
To: Caml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Different function on Image format (uses camlImages)
Date: Thu, 27 Nov 2003 23:55:04 +0000 [thread overview]
Message-ID: <3FC68ED8.1000708@ntlworld.com> (raw)
In-Reply-To: <3FC68846.7020804@ntlworld.com>
chris.danx wrote:
> let img = match <image_format> with
> <rgb> -> OImage.rgb24 img
> | <rgba> -> OImage.rgba24 img
> in ...
>
> The problem is what should the things between the angled brackets be?
Zaps himself!!! I went off on a tangent there. I can tell which format
the image is but can't apply rgba_to_gl. The error is
File "texload.ml", line 35, characters 45-48:
This expression has type Image.rgb = Color.Rgb.t but is here used with type
Image.rgba = Color.Rgba.t
Line 35 is the [| 4 component array |] in rgba_to_gl. I think I
understand why i get this error, I'm just not sure I know how to resolve
it (i got it previously, but ripped out the pattern matching code for
the image format). It seems the image needs to be treated as
OImage.rgba32 but I'm a bit lost...
This is the complete script so far...
let rgb_to_gl img =
let w = img#width
and h = img#height in
let targ_img = GlPix.create `ubyte ~format:`rgb ~width:w ~height:h in
for i = 0 to w - 1 do
for j = 0 to h - 1 do
let pix = img#get i j in
Raw.sets (GlPix.to_raw targ_img)
~pos:(3*i*h+j)
[| pix.r; pix.g; pix.b |];
done
done;
targ_img;;
let rgba_to_gl img =
let w = img#width
and h = img#height in
let targ_img = GlPix.create `ubyte ~format:`rgba ~width:w
~height:h in
for i = 0 to w - 1 do
for j = 0 to h - 1 do
let pix = img#get i j in
Raw.sets (GlPix.to_raw targ_img)
~pos:(4*i*h+j)
[| pix.r; pix.g; pix.b; pix.alpha|];
done
done;
targ_img;;
class texture_loader
= object(self)
val mutable texts = Hashtbl.create 5;
method load (filename : string) (tex_id : string) =
try
let x = Hashtbl.find texts tex_id in
raise (Id_exists tex_id)
with
Not_found ->
let img = OImage.load filename [] in
let conv = match img#tag with
ClassRgb24 -> rgb_to_gl
| ClassRgba32 -> rgba_to_gl
in
Hashtbl.add texts tex_id (conv img);
()
end;;
let _ =
let tex = new texture_loader in
tex#load "NeHe.bmp" "bob";;
Chris
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2003-11-27 23:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-27 23:27 chris.danx
2003-11-27 23:55 ` chris.danx [this message]
2003-11-29 0:36 ` chris.danx
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3FC68ED8.1000708@ntlworld.com \
--to=chris.danx@ntlworld.com \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox