How to know if a DAT file is a GRP before load it?
Root / Programming Questions / [.]
Javo118Created:
I'd think you can always load a DAT into an empty array and it will auto-expand to the length of the file's elements.
If the array you're using is already too large, use POP() repeatedly into a dummy variable to empty the array.
WHILE LEN(ARRAY) DUMMY=POP(ARRAY) WENDThen, you can perform tests on the data to see if it's really a GRP. The three tests I can think of that would be the easiest to run and most reliable are these, sorted from simple and fast to slow and more complex. Number one: Check the length of the array with pre-chosen resolutions.
- 512*512=262144
- 400*240=96000
- 320*240=76800
FOR I=0 TO LEN(ARRAY)-1 IF (ARRAY[I])!=(ARRAY[I] AND &H0000FFFF) THEN ISGRP=0 NEXTNumber 3: The noise test. If you don't trust the tests before, this might be the last one you need. Pick a resolution/aspect ratio to test, then run a test on all of the rows and columns of the array as an image. For row, calculate each pixel's difference in color with the pixel to its left with subtraction and ABS(). Average all of the resulting values for every pixel in the image into one value. We'll call it "HN". Repeat this process vertically, checking every pixel with their pixel above. average these values into the variable "VN". Now, if VN is significantly higher than HN, that might mean the horizontal resolution is wrong. you can test a bunch until VN is closest to the value of HN. Now, you can average VN and HN yet again into "TN". Now you have a heuristic to truly test if the data is coherent enough to be an image. You can run tests on GRPs and other data to find the threshold value to separate GRP's and other data. Awesome! Let's test the code!
Type mismatch in 0:6(LOAD)