Problems with replace-foreign-array
Hoping someone can help with with this and it's something really stupid I'm doing...
Next is to increase the size - easy enough - and then copy the data over. Everything seems to work just fine except the copying. I just keep running into problems. Here's some sample code. It's not exact, but should give the idea of what I'm doing:
I have a binary data (an image) loaded, that I'm going to increase in size to the next power of 2 for OpenGL. Simple enough (in C). I have the image data as a foreign array of unsigned bytes (note: I've gotten this through the Objective-C interface and NSBitmapImageRep -bitmapData).
Next is to increase the size - easy enough - and then copy the data over. Everything seems to work just fine except the copying. I just keep running into problems. Here's some sample code. It's not exact, but should give the idea of what I'm doing:
(let ((src-data (invoke image-rep "bitmapData")))
; note: the above fails with "Error: External format :ASCII got error
; reading #<Pointer to type (:UNSIGNED :CHAR) = #x0061B000> at
; position 0: Non-ASCII code 255." unless I do
; (set-locale-encodings :latin-1 nil).
;
; I have no idea why, but would appreciate any info here, too. :-)
; Assume here I get width, height, bytes-per-row, etc, and these are all correct,
; and that I've increased width and height to the next powers of 2.
(let* ((size (* new-height new-bytes-per-row))
(buffer (allocate-foreign-object :type '(:unsigned :char) :nelems size))
; note: the above fails with "Error: External format :ASCII got error
; reading #<Pointer to type (:UNSIGNED :CHAR) = #x0061B000> at
; position 0: Non-ASCII code 255." unless I do
; (set-locale-encodings :latin-1 nil).
;
; I have no idea why, but would appreciate any info here, too. :-)
; Assume here I get width, height, bytes-per-row, etc, and these are all correct,
; and that I've increased width and height to the next powers of 2.
(let* ((size (* new-height new-bytes-per-row))
(buffer (allocate-foreign-object :type '(:unsigned :char) :nelems size))
; Okay, everything is good so far, now we'll copy the data from the
; smaller image into the larger image.
(dotimes (y old-height)
(replace-foreign-array
buffer ; target location
src-data ; source location
:start1 (* y new-bytes-per-row)
:start2 (* y old-bytes-per-row)
:end2 (* (1+ y) old-bytes-per-row))
And this is where things go wrong. I've gotten a slew of different errors depending on what I put for start1, start2, and end2. I'm pretty sure from the documentation that 1's are for the destination and 2's are for the source. In my test case this actually doesn't matter since the bytes per row are the same in the old and new, and in fact, the source image is already powers of 2, so everything should be the same.
The errors I get are flavors of: "Error: Bounds 128, NIL are incorrect for array "ÿö÷"." I've been trying everything I can think of and am at a loss. Any help is much appreciated! :)
Jeff M..