? How to know if a DAT file is a GRP before load it? (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password
Creep into the Halloween / Horror Programming Contest (Deadline Extended)

How to know if a DAT file is a GRP before load it?

  • #1 ✎ 8 Javo118 Just that, I am trying to maje a list of all of the GRP of all the projects but dunno how to filter the list Posted
  • #2 ✎ 1261 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS There's no way to tell. :( Posted
  • #3 ✎ 8 Javo118 Mmmm so there is something that "load" it and if is not a GRP don't close my app? Something like "if load-error then show dialog" Posted
  • #4 ✎ 248 chicken OSP Contest 1 Contest Participant I participated in the first SmileBASIC Source OSP Contest! Avatar Embargo I didn't change my avatar for 90 days Website Good Page Hidden Achievements perhaps you could emulate the loading system? would be slow and require lots of setup, but it would work Posted
  • #5 ✎ 8 Javo118
    perhaps you could emulate the loading system? would be slow and require lots of setup, but it would work
    Can you explain it a little more? Please
    Posted
  • #6 ✎ 248 chicken OSP Contest 1 Contest Participant I participated in the first SmileBASIC Source OSP Contest! Avatar Embargo I didn't change my avatar for 90 days Website Good Page Hidden Achievements
    perhaps you could emulate the loading system? would be slow and require lots of setup, but it would work
    Can you explain it a little more? Please
    As in trying to pretend to load it as if it was a GRP. But the loading is not done by SB's internal tools, it's done by your code.
    Posted
  • #7 ✎ 1261 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Don't listen to ProgrammingChicken. It's impossible to do this. Posted
  • #8 ✎ 248 chicken OSP Contest 1 Contest Participant I participated in the first SmileBASIC Source OSP Contest! Avatar Embargo I didn't change my avatar for 90 days Website Good Page Hidden Achievements
    Don't listen to ProgrammingChicken. It's impossible to do this.
    *not feasible
    Posted
  • #9 ✎ 1261 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS You can't load a file without using LOAD, and LOADing into an array with the wrong number of dimensions causes an error. Therefor it is impossible to load a random DAT/GRP file. Posted Edited by 12Me21
  • #10 ✎ 248 chicken OSP Contest 1 Contest Participant I participated in the first SmileBASIC Source OSP Contest! Avatar Embargo I didn't change my avatar for 90 days Website Good Page Hidden Achievements
    You can't load a file without using LOAD, and LOADing into an array with the wrong number of dimensions causes an error. Therefor it is impossible to load a random DAT/GRP file.
    give us catch error pls smileboom
    Posted
  • #11 ✎ 8 Javo118 Yeah, i want a catch error T_T, well, this make my project a little buggy, i will continue it anyway, thanks both Posted
  • #12 ✎ 208 ColeslawProductions 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) WEND Then, 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.
    1. 512*512=262144
    2. 400*240=96000
    3. 320*240=76800
    You can check for as many resolutions as you want. Number two: Check the bits. GRP's are always 16-bit, and we're loading we're loading them into a 32-bit or 64-bit array. Use a FOR loop to check the entire array for elements that don't fit into this bitmask. "0000FFFF" FOR I=0 TO LEN(ARRAY)-1 IF (ARRAY[I])!=(ARRAY[I] AND &H0000FFFF) THEN ISGRP=0 NEXT Number 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)
    Posted Edited by ColeslawProductions
  • #13 ✎ 208 ColeslawProductions I've thought for months about how to make an auto-preview image viewer with these tests and i just find out now that they never would've worked Posted
  • #14 ✎ 1261 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS LOAD will automatically RESIZE the array, not just expand it so you don't have to empty it first Posted