Fastest way to "learn" an image's pixels?

Just starting out? Need help? Post your questions and find answers here.
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: Fastest way to "learn" an image's pixels?

Post by Seymour Clufley »

I also did this version, for feeding an image's pixels into a "2-dimensional array inside a structure":

Code: Select all

#MaxIW = 1600
#MaxIH = 1200

Structure PixelMatrixColumn
   y.i[#MaxIH+1]
EndStructure

Structure PixelMatrix
  x.PixelMatrixColumn[#MaxIW+1] ; colour matrix
EndStructure

Macro Pixel(strucname,x,y)
  strucname\pixelmatrix\x[x]\y[y]
EndMacro

Procedure.b ImageIntoStructuredPixelArray(img.i, *st,fieldoffset.i, free.b)
  
  If Not IsImage(img) : ProcedureReturn #False : EndIf
  
  iw = ImageWidth(img)
  ih = ImageHeight(img)
  id = ImageDepth(img)
  
  *mem = AllocateMemory(iw*ih << 2)
  CopyImageToMemory(img,*mem)
  If free
      FreeImage(img)
  EndIf
  
  *px.LONG = *mem
  
  
  *strcptr.LONG = *st + fieldoffset
  *strcptr-SizeOf(INTEGER)
  For x = 0 To iw-1
      ycounter = x
      For y = 0 To ih-1
          *strcptr+SizeOf(INTEGER)
          If y<ih And x<iw
              *px = *mem + (ycounter<<2)
              ;*strcptr\l = RGBA(*px\l >> 16 & $FF, *px\l >> 8 & $FF, *px\l & $FF, *px\l >> 24 & $FF)
              If id=32
                  alpha = *px\l >> 24 & $FF
              Else
                  alpha = 255
              EndIf
              *strcptr\l = RGBA(*px\l >> 16 & $FF, *px\l >> 8 & $FF, *px\l & $FF, alpha)
          EndIf
          ycounter+iw
      Next y
      *strcptr+SizeOf(INTEGER)
      *strcptr + ((#MaxIH-ih)*SizeOf(INTEGER))
  Next x
  
  FreeMemory(*mem)
  
  ProcedureReturn #True
  
EndProcedure
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Post Reply