Author Topic: Limitation  (Read 3195 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
Limitation
« on: November 19, 2011, 06:04:16 AM »
Deleted...
« Last Edit: May 05, 2015, 12:15:09 PM by Peter »

Charles Pegge

  • Guest
Re: Limitation
« Reply #1 on: November 19, 2011, 02:00:50 PM »
Hi Peter,

Arrays are static but they can be mapped to any memory location and used as an overlay.
Ubounds do not need to be specified in this case.

To demonstrate the mapping of arrays data structures, this is my revised BMP process example. It can read the BMP header, access the pixels with an array, and create a new BMP file.

Code: OxygenBasic
  1.  '===============
  2. 'bmp file loader
  3. '===============
  4.  
  5.  'Charles Pegge
  6. '19:25 19/11/2011
  7.  
  8.  'details of BMP format:
  9. 'wikipedia.org/wiki/BMP_file_format
  10.  
  11.  packed type BmpMapHeader
  12.    short bfType
  13.    long  bfSize
  14.    short bfReserved1
  15.    short bfReserved2
  16.    long  bfOffBits
  17.    long  biSize
  18.    long  biWidth
  19.    long  biHeight
  20.    short biPlanes
  21.    short biBitCount
  22.    long  biCompression
  23.    long  biSizeImage
  24.    long  biXPelsPerMeter
  25.    long  biYPelsPerMeter
  26.    long  biClrUsed
  27.    long  biClrImportant
  28.  end type
  29.  
  30.  
  31.   packed type pixel24
  32.     byte b,g,r
  33.   end type
  34.  
  35.  
  36.   packed type pixel32
  37.     byte b,g,r,a
  38.   end type
  39.  
  40.    
  41.  
  42.   string bmpfile="t.bmp" 'choose your file
  43.  string bmpdata
  44.   getfile bmpfile,bmpdata
  45.   sys le=len bmpdata
  46.   '
  47.  BmpMapHeader *d : @d = *bmpdata
  48.  
  49.   'DISPLAY HEADER VALUES
  50.  '
  51.  '-----------------------------------
  52.  function DispBmpInfo(BmpMapHeader*d)
  53.   '===================================
  54.  '
  55.  'capture signature to string
  56.  '
  57.  string n="    "
  58.   **n=?d
  59.   n=left n,2
  60.   '
  61.  string cr=chr(13)+chr(10)
  62.   string tab=chr(9)
  63.   string pr="BMP HEADER DATA FOR " bmpfile cr cr
  64.  
  65.   def    p pr=pr+ %1 tab %2 cr
  66.    '
  67. '------------------------------------------
  68.  p  "Signature:        "  n
  69.   p  "File Size:        "  d.bfSize
  70.   p  "Bit data offset : "  d.bfOffBits
  71.   p  "Header size:      "  d.bisize
  72.   p  "Image Width:      "  d.biWidth
  73.   p  "Image Height:     "  d.biHeight
  74.   p  "Bit planes:       "  d.biPlanes
  75.   p  "Bits per pixel:   "  d.biBitCount
  76.   p  "Compression:      "  d.biCompression
  77.   p  "Size of Image:    "  d.biSizeImage
  78.   p  "Xpixels per metre:"  d.biXPelsPerMeter
  79.   p  "Ypixels per metre:"  d.biYPelsPerMeter
  80.   p  "Colours used:     "  d.biClrUsed
  81.   p  "Colours important:"  d.biClrImportant
  82.   '------------------------------------------
  83.  
  84.   print pr
  85.   '
  86.  end function
  87.  
  88.  
  89.   if bmpdata then DispBmpInfo d
  90.  
  91.  
  92.   'TEST PIXEL READING
  93.  '==================
  94.  
  95.   'pixel24 *pix : @pix = *BmpData + d.bfOffBits
  96.  'print pix(1).r
  97.  
  98.  
  99.   'CREATE A BMP FILE FROM SCRATCH
  100.  '==============================
  101.  
  102.   pixel24 *pix '3 color pixel
  103.  sys offs=64, w=16, h=16, bits=8*sizeof pix
  104.   BmpMapHeader *hdr
  105.   sys le=offs+w*h*sizeof pix
  106.   BmpData=nuls le
  107.   @hdr = *BmpData   'map header overlay
  108.  @pix = @hdr+offs  'map pixel overlay
  109.  
  110.  
  111.   'ENTER METRICS INTO THE HEADER
  112.  '=============================
  113.  
  114.   hdr<=0x4d42,le,0,0,offs,40,w,h,1,bits,0,w*h*sizeof pix
  115.  
  116.  
  117.   'FILL IN PIXELS
  118.  '==============
  119.  
  120.   scope
  121.  
  122.   indexbase 0
  123.   for y=1 to 14
  124.      for x=1 to 14
  125.        pix(y*w+x)<=0,160,128 ' b g r
  126.    next
  127.   next
  128.  
  129.   end scope  
  130.  
  131.  
  132.   'SAVE BMP FILE
  133.  '=============
  134.  
  135.   string fname="s.bmp"
  136.   putfile fname,BmpData
  137.   print "Created: " fname
  138.  
  139.  
  140.   '====
  141.  done:
  142.   '====
  143.  
  144.   BmpData=""
  145.  
  146.  
  147. '=====
  148. 'NOTES
  149. '=====
  150.  
  151. '----------------------------------------------------------------------------------------------------------
  152. ' BMP file formats
  153. '
  154. ' The BITMAPFILEHEADER:
  155. '----------------------------------------------------------------------------------------------------------
  156. 'start size name           description
  157. '----------------------------------------------------------------------------------------------------------
  158. '0     2    bfType         must always be set to 'BM' to declare that this is a .bmp-file.
  159. '2     4    bfSize         the size of the file in bytes.
  160. '4     2    bfReserved1    must always be set to zero.
  161. '8     2    bfReserved2    must always be set to zero.
  162. '10    4    bfOffBits      the offset from the beginning of the file to the bitmap data.
  163. '----------------------------------------------------------------------------------------------------------
  164. '
  165. '
  166. ' The BITMAPINFOHEADER:
  167. '----------------------------------------------------------------------------------------------------------
  168. 'start size name            description
  169. '----------------------------------------------------------------------------------------------------------
  170. '14    4    biSize          size of the BITMAPINFOHEADER structure, in bytes.
  171. '18    4    biWidth         width of the image, in pixels.
  172. '22    4    biHeight        height of the image, in pixels.
  173. '26    2    biPlanes        number of planes of the target device, must be set to zero.
  174. '28    2    biBitCount      number of bits per pixel.
  175. '30    4    biCompression   type of compression, usually set to zero (no compression).
  176. '34    4    biSizeImage     size of the image data, in bytes. If there is no compression, it is valid to set this member to zero.
  177. '38    4    biXPelsPerMeter horizontal pixels per meter on the designated targer device, usually set to zero.
  178. '42    4    biYPelsPerMeter vertical pixels per meter on the designated targer device, usually set to zero.
  179. '46    4    biClrUsed       number of colors used in the bitmap, if set to zero the number of colors is calculated using the biBitCount member.
  180. '50    4    biClrImportant  number of color that are 'important' for the bitmap, if set to zero, all colors are important.
  181. '----------------------------------------------------------------------------------------------------------
  182.  
  183.  

Charles
« Last Edit: November 19, 2011, 02:07:09 PM by Charles Pegge »

efgee

  • Guest
Re: Limitation
« Reply #2 on: November 20, 2011, 06:31:03 PM »
What means this: codeout = code1 ? code1 : code2

Suppose it means if code1 is true than codeout equals code1 otherwise codeout equals code2

Charles Pegge

  • Guest
Re: Limitation
« Reply #3 on: November 22, 2011, 12:18:54 AM »
I don't know what it means.  In Oxygen  '?' is a cast operator equivalent to <sys>

bstring s="ok"
print ? s
print <sys> s


Peter,

You can do multiple assignments like this. I have just checked

sys a,b,c,d
if a=0 then a=b=c=d=42
print a "   " b "    " c  "    " d


But the variables have to be declared first. Autodim only works for one variable at a time.

Charles
« Last Edit: November 22, 2011, 12:29:02 AM by Charles Pegge »

Charles Pegge

  • Guest
Re: Limitation
« Reply #4 on: November 26, 2011, 03:19:00 AM »

Peter,

Here is one way to create dynamic arrays. These can be dimensioned by a variable at run time but should be erased when finished.

def dynamic %1 * %2 : @ %2=getmemory %3 * sizeof %2


Code: OxygenBasic
  1. 'dynamic dim
  2. '===========
  3.  
  4. def dynamic %1 * %2 : @ %2=getmemory %3 * sizeof %2
  5.  
  6. sys a=10*5
  7.  
  8. dynamic string d a
  9.  
  10.  
  11. d[a-7]=999
  12. print d[a-7]
  13. freememory @d
  14.  

Charles

Charles Pegge

  • Guest
Re: Limitation
« Reply #5 on: November 26, 2011, 03:46:08 AM »

They will not self-destruct in 10 seconds  ;D