<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Can you BLOAD (basic graphics format) images in C?</title>
		<link>http://www.allegro.cc/forums/view/189469</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 11 Jun 2002 13:03:40 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Is there a way to load BSAVEd images (the basic image format) into a bitmap using allegro?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (MickyD)</author>
		<pubDate>Sun, 09 Jun 2002 05:51:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you have the definition of the format, you should be able to convert that struct into a bitmap. However, load_bitmap by itself cannot do that.</p><p>You can load anything in almost any language (in all serious language) if you know the format of it.</p><p>RB
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ReyBrujo)</author>
		<pubDate>Sun, 09 Jun 2002 05:54:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The first 7 bytes are junk - they are only useful for the BASIC interpreter. They contain some segment information, etc. All the bytes aferwards are the raw dump of what you saved using BSAVE.<br />I would guess that the first 4 bytes are the width and height (2 bytes each). The rest should be the raw pixel data, or a palette of some sort.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bob)</author>
		<pubDate>Sun, 09 Jun 2002 06:05:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I doubt that there is a palette. QBASIC is older than VGA
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matt Smith)</author>
		<pubDate>Sun, 09 Jun 2002 12:53:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" />*shocked*<br />someone still use grandfather&#039;s method to make games,and Bob still remember this super-old format!;D<br />..anyway you should use Paint/sprite editor or somthing to draw PCX image,then grab these .PCX file by Allegro Grabber,to make games
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johnny13)</author>
		<pubDate>Sun, 09 Jun 2002 13:23:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>MUAHAHAHAHAHAHAH!!!</p><p>I CAN&#039;T BELIEVE YOU THINK YOU CAN USE THE BLOAD FORMAT IN C/ALLEGRO!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanTheKat)</author>
		<pubDate>Sun, 09 Jun 2002 18:38:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>afaik there&#039;s no way to know the proper width/heigth of a bsave&#039;d file. byte 6&amp;7 of the header (raw data starts at byte 8) only indicate the total size of data, the programmer has to make sure of proper width by himself!<br />converting (if you know the correct dimensions) an 8 bit (mode 13 in qbasic) bsaved data into a BITMAP structure, which is 8 bpp (i.e. run the program in 8bpp colour depth, or use create_bitmap_ex();) assume you&#039;ve loaded the whole bsaved file to memory using fread() to an array of unsigned char with proper dimension:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> h<span class="k3">=</span><span class="n">0</span><span class="k2">;</span>h<span class="k3">&lt;</span>BSAVED_H<span class="k2">;</span>h<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="k2">{</span> <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> w<span class="k3">=</span><span class="n">0</span><span class="k2">;</span>w<span class="k3">&lt;</span>BSAVED_W<span class="k2">;</span>w<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
  <span class="k2">{</span> <a href="http://www.allegro.cc/manual/putpixel" target="_blank"><span class="a">putpixel</span></a><span class="k2">(</span>bitmap,w,h,bsaved<span class="k2">[</span><span class="k2">(</span>h<span class="k3">*</span>BSAVED_W<span class="k2">)</span><span class="k3">+</span>w<span class="k3">+</span><span class="n">8</span><span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
  <span class="k2">}</span>
<span class="k2">}</span>
</pre></div></div><p>
should do the trick then.<br />as for palletes I have no clue...</p><p>katman: you can read any type of file from c...whatever silly format it is.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Gabhonga)</author>
		<pubDate>Sun, 09 Jun 2002 19:45:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#039;ll try it.  Anyways someone asked if people still make games in QB.  yep, here is one I have been working on for a long time.  It is way better than you would expect (it being coded in QB and all).</p><p><a href="http://typosoft.qbasicnews.com/pedxing.put">http://typosoft.qbasicnews.com/pedxing.put</a><br />or no sound version<br /><a href="http://typosoft.qbasicnews.com/pedlite.zip">http://typosoft.qbasicnews.com/pedlite.zip</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (MickyD)</author>
		<pubDate>Sun, 09 Jun 2002 21:10:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Heh, time to show my QB backgrounds <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /></p><p>Ga Bhonga, that&#039;s not completely true... it depends from what source you bsaved your image.<br />Bsave stands for Binary Save and AFAIK it was meant as a general way to save blocks of memory to a file. Images came later. Normally QB people use BSAVE to save the entire VGA (mode 13h) screen, doing</p><div class="source-code snippet"><div class="inner"><pre>def seg<span class="k3">=</span><span class="k3">&amp;</span>ha000
bsave <span class="s">"image.bsv"</span>, <span class="n">0</span>, <span class="n">64000</span>
</pre></div></div><p>

IIRC that&#039;ll save 64000 bytes from address 0xA000:0 (mode 13h framebuffer address in real mode), that&#039;s an entire 320x200x8 screen. So no size info is saved, as there&#039;s no way to guess it from QB.<br />When you bsave a GETed sprite though, things are different, as QB stores sprite size information together with the actual bitmap data when GETing a sprite into a buffer...<br />I think the first word is the width/8 (don&#039;t ask me why /8), followed by the height in the next word.<br />So the format of a bsave file is as follows:</p><div class="source-code snippet"><div class="inner"><pre>byte   desc
<span class="n">0</span>      Identification byte. Must be <span class="n">0xFD</span>
<span class="n">1</span><span class="k3">-</span><span class="n">2</span>    Source segment from where the data was saved
<span class="n">3</span><span class="k3">-</span><span class="n">4</span>    Source offset
<span class="n">5</span><span class="k3">-</span><span class="n">6</span>    Length of saved data in bytes
<span class="n">7</span><span class="k3">-</span>...  the actual data
</pre></div></div><p>

So if the bsaved data was saved from a GET buffer, you&#039;ll also have:</p><div class="source-code snippet"><div class="inner"><pre><span class="n">7</span><span class="k3">-</span><span class="n">8</span>    Width of image <span class="k3">/</span> <span class="n">8</span>
<span class="n">9</span><span class="k3">-</span><span class="n">10</span>   Height of the image
<span class="n">11</span><span class="k3">-</span>... Image data
</pre></div></div><p>

Hope it helps coding your own C loading routines <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (lillo)</author>
		<pubDate>Sun, 09 Jun 2002 23:09:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>aah, didn&#039;t remember GET and PUT at all...::)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Gabhonga)</author>
		<pubDate>Sun, 09 Jun 2002 23:44:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How do you use fread to read a whole file and store every byte from that file into an array?  Here is what I have so far...</p><p>I&#039;m working with a 100x100 sprite bsaved with QB.</p><p> int w, h, BH, BW; <br /> int bsaved[5001]; // ((gfxX * gfxY) / 2) + 1<br /> <br /> BW = 100;<br /> BH = 100;<br /> FILE *fptr;<br /> fptr = fopen(&quot;c:/qbasic/pp/images/cpp.put&quot;, &quot;r&quot;);<br />  fread(bsaved, 7, 7, fptr);<br />  while (!feof(fptr)) { fread(bsaved, 486, 486, fptr); }<br /> fclose(fptr);<br /> for(int h=0;h&lt;BH;h++) <br /> { for(int w=0;w&lt;BW;w++) <br /> { putpixel(screen,h,w,bsaved[(h*BW)+w+8]); } <br /> } <br /> readkey();</p><p>This puts garbled pixels on the screen, but they are the right colors! <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />  Obviosly I don&#039;t much C or how to use fread.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (MickyD)</author>
		<pubDate>Mon, 10 Jun 2002 02:23:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I had trouble with fread, and the other file stuff, and I still do, heh.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanTheKat)</author>
		<pubDate>Mon, 10 Jun 2002 02:51:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>def seg=&amp;ha000 <br />bsave&quot;image.bsv&quot;,0,64000</p></div></div><p>it sucks! ah my eyes!<br />i hate do ugly(!)lowlevel thing in a Highlevel(kids)interpreter!&gt;:(<br />GAME MAKERS USE C!:P
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johnny13)</author>
		<pubDate>Mon, 10 Jun 2002 12:25:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>it sucks! ah my eyes!<br />i hate do ugly(!)lowlevel thing in a Highlevel(kids)interpreter!<br />GAME MAKERS USE C!</p></div></div><p>  <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" /></p><p>Oh yeah, let&#039;s start one of these discussions</p><p>But that info is kinda cool. It would allow us to write an importer / exporter for QB. There&#039;re some nice tools written in QB (mainly RPG related), and allowing to import / export data in that format might be very helpful (if you&#039;re doing a sprite editor for example).</p><p>It would allow you to adopt the complete QB userbase, which is still rather larger. It would also give some of the QB guys a nicer start in C coding (and maybe even enough motivation to switch).</p><p>To be honest, I never thought the BLOAD/ BSAVE format was specified... or has somebody reverse engineered it?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spellcaster)</author>
		<pubDate>Mon, 10 Jun 2002 15:09:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Here&#039;s an (untested) little function that should work like the other Allegro load_* image loading functions; if it finds additional data appended to the file it&#039;ll store it as palette data into the <i>palette</i> parameter, otherwise palette will remain unchanged.<br />I&#039;m assuming you only need to load GETed images saved with bsave. I&#039;ll also assume your images are mode 13h sprites, so 8bit only.<br />Another thing: I suspect the width/8 stored into a bsaved sprite file like I said was wrong; IIRC it was width*8, so you have to divide the saved word by 8 to get the original width...</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>load_bsv<span class="k2">(</span><span class="k1">char</span> <span class="k3">*</span>filename, <a href="http://www.allegro.cc/manual/RGB" target="_blank"><span class="a">RGB</span></a> <span class="k3">*</span>palette<span class="k2">)</span></td></tr><tr><td class="number">2</td><td><span class="k2">{</span></td></tr><tr><td class="number">3</td><td> <a href="http://www.allegro.cc/manual/PACKFILE" target="_blank"><span class="a">PACKFILE</span></a> <span class="k3">*</span>f<span class="k2">;</span></td></tr><tr><td class="number">4</td><td> <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>bmp <span class="k3">=</span> NULL<span class="k2">;</span></td></tr><tr><td class="number">5</td><td> <span class="k1">char</span> temp<span class="k2">[</span><span class="n">6</span><span class="k2">]</span><span class="k2">;</span></td></tr><tr><td class="number">6</td><td> <span class="k1">int</span> w, h, i<span class="k2">;</span></td></tr><tr><td class="number">7</td><td> </td></tr><tr><td class="number">8</td><td> <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><span class="k2">(</span>f <span class="k3">=</span> <a href="http://www.allegro.cc/manual/pack_fopen" target="_blank"><span class="a">pack_fopen</span></a><span class="k2">(</span>filename, F_READ<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span></td></tr><tr><td class="number">9</td><td>  <span class="k1">return</span> NULL<span class="k2">;</span></td></tr><tr><td class="number">10</td><td>&#160;</td></tr><tr><td class="number">11</td><td> <span class="c">/* check if it's a bsaved file */</span></td></tr><tr><td class="number">12</td><td> <span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/pack_getc" target="_blank"><span class="a">pack_getc</span></a><span class="k2">(</span>f<span class="k2">)</span> <span class="k3">!</span><span class="k3">=</span> <span class="n">0xfd</span><span class="k2">)</span></td></tr><tr><td class="number">13</td><td>  <span class="k1">goto</span> error<span class="k2">;</span></td></tr><tr><td class="number">14</td><td>&#160;</td></tr><tr><td class="number">15</td><td> <span class="c">/* skip source seg:off and length */</span></td></tr><tr><td class="number">16</td><td> <a href="http://www.allegro.cc/manual/pack_fread" target="_blank"><span class="a">pack_fread</span></a><span class="k2">(</span>temp, <span class="n">6</span>, f<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td> <span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/pack_feof" target="_blank"><span class="a">pack_feof</span></a><span class="k2">(</span>f<span class="k2">)</span><span class="k2">)</span></td></tr><tr><td class="number">18</td><td>  <span class="k1">goto</span> error<span class="k2">;</span></td></tr><tr><td class="number">19</td><td> </td></tr><tr><td class="number">20</td><td> <span class="c">/* get sprite dimensions */</span></td></tr><tr><td class="number">21</td><td> w <span class="k3">=</span> <a href="http://www.allegro.cc/manual/pack_igetw" target="_blank"><span class="a">pack_igetw</span></a><span class="k2">(</span>f<span class="k2">)</span> <span class="k3">/</span> <span class="n">8</span><span class="k2">;</span></td></tr><tr><td class="number">22</td><td> h <span class="k3">=</span> <a href="http://www.allegro.cc/manual/pack_igetw" target="_blank"><span class="a">pack_igetw</span></a><span class="k2">(</span>f<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">23</td><td>&#160;</td></tr><tr><td class="number">24</td><td> bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/create_bitmap_ex" target="_blank"><span class="a">create_bitmap_ex</span></a><span class="k2">(</span><span class="n">8</span>, w, h<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">25</td><td> <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>bmp<span class="k2">)</span></td></tr><tr><td class="number">26</td><td>  <span class="k1">goto</span> error<span class="k2">;</span></td></tr><tr><td class="number">27</td><td> </td></tr><tr><td class="number">28</td><td> <span class="c">/* load the sprite data */</span></td></tr><tr><td class="number">29</td><td> <span class="k1">for</span> <span class="k2">(</span>i<span class="k3">=</span><span class="n">0</span><span class="k2">;</span> i<span class="k3">&lt;</span>h<span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span></td></tr><tr><td class="number">30</td><td>  <a href="http://www.allegro.cc/manual/pack_fread" target="_blank"><span class="a">pack_fread</span></a><span class="k2">(</span>bmp-&gt;line<span class="k3">&lt;</span>i&gt;, w, f<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">31</td><td> </td></tr><tr><td class="number">32</td><td> <span class="c">/* check if there's an appended palette */</span></td></tr><tr><td class="number">33</td><td> <span class="k1">if</span> <span class="k2">(</span><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/pack_feof" target="_blank"><span class="a">pack_feof</span></a><span class="k2">(</span>f<span class="k2">)</span><span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> <span class="k2">(</span>palette<span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">34</td><td>  <span class="c">/* load appended data as palette data */</span></td></tr><tr><td class="number">35</td><td>  <span class="k1">for</span> <span class="k2">(</span>i<span class="k3">=</span><span class="n">0</span><span class="k2">;</span> i<span class="k3">&lt;</span><span class="n">256</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">36</td><td>   <a href="http://www.allegro.cc/manual/pack_fread" target="_blank"><span class="a">pack_fread</span></a><span class="k2">(</span>palette<span class="k3">&lt;</span>i&gt;, <span class="n">3</span>, f<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">37</td><td>   <span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/pack_feof" target="_blank"><span class="a">pack_feof</span></a><span class="k2">(</span>f<span class="k2">)</span><span class="k2">)</span></td></tr><tr><td class="number">38</td><td>    <span class="k1">break</span><span class="k2">;</span></td></tr><tr><td class="number">39</td><td>  <span class="k2">}</span></td></tr><tr><td class="number">40</td><td> <span class="k2">}</span></td></tr><tr><td class="number">41</td><td> </td></tr><tr><td class="number">42</td><td>error:</td></tr><tr><td class="number">43</td><td> <a href="http://www.allegro.cc/manual/pack_fclose" target="_blank"><span class="a">pack_fclose</span></a><span class="k2">(</span>f<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">44</td><td> <span class="k1">return</span> bmp<span class="k2">;</span></td></tr><tr><td class="number">45</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (lillo)</author>
		<pubDate>Mon, 10 Jun 2002 20:56:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>heh, cool <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />  That just might bring over a lot of QB programmers....that and my &quot;How to program C++ for QB programmers&quot; tutorial.  Mayhaps you should upload that source code somplace permemenant where people can download it?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mandrake Root Produc)</author>
		<pubDate>Mon, 10 Jun 2002 21:41:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>DUDE!  that worked!  Thank you sooo much.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (MickyD)</author>
		<pubDate>Mon, 10 Jun 2002 23:42:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Wow.  BLOADed graphics.  That was my first brush with file-based sprites, too.  I even figured out a way to make a (partially) clipping PUT drawing routine.</p><p>It only worked vertically...if the sprite was clipped horizontally it&#039;d do strange things.  I didn&#039;t know enough about how EGA video RAM was structured to make it more intelligent than that.  (in 4 4-bit planes, like the old VGA modes, in case you wonder. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />)</p><p>I haven&#039;t seen that in <b>ages</b>.  I&#039;ve even still got a few of my old <a href="http://www.gapingwolf.com/older.html">GWBASIC games</a> around...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (David Grace)</author>
		<pubDate>Tue, 11 Jun 2002 13:03:39 +0000</pubDate>
	</item>
</rss>
