~ubuntu-branches/ubuntu/raring/vice/raring

« back to all changes in this revision

Viewing changes to src/gfxoutputdrv/pcxdrv.c

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2009-03-31 00:37:15 UTC
  • mfrom: (1.1.7 upstream) (9.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090331003715-i5yisvcfv7mgz3eh
Tags: 2.1.dfsg-1
* New major upstream release (closes: #495937).
* Add desktop files (closes: #501181).

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
  screenshot->gfxoutputdrv_data = sdata;
97
97
  sdata->line = 0;
98
98
  sdata->ext_filename=util_add_extension_const(filename, pcx_drv.default_extension);
99
 
  sdata->fd = fopen(filename, "wb");
 
99
  sdata->fd = fopen(sdata->ext_filename, "wb");
100
100
 
101
101
  if (sdata->fd==NULL)
102
102
  {
256
256
  return 0;
257
257
}
258
258
 
 
259
#ifdef FEATURE_CPUMEMHISTORY
 
260
static FILE *pcxdrv_memmap_fd;
 
261
static char *pcxdrv_memmap_ext_filename;
 
262
static BYTE *pcxdrv_memmap_pcx_data;
 
263
 
 
264
static int pcxdrv_close_memmap(BYTE *palette)
 
265
{
 
266
  BYTE pcx_color_prefix[2]="\x0c";
 
267
 
 
268
  fwrite(pcx_color_prefix, 1, 1, pcxdrv_memmap_fd);
 
269
 
 
270
  fwrite(palette, 3*256, 1, pcxdrv_memmap_fd);
 
271
 
 
272
  fclose(pcxdrv_memmap_fd);
 
273
  lib_free(pcxdrv_memmap_pcx_data);
 
274
  lib_free(pcxdrv_memmap_ext_filename);
 
275
 
 
276
  return 0;
 
277
}
 
278
 
 
279
static int pcxdrv_write_memmap(int line, int x_size, BYTE *gfx)
 
280
{
 
281
  BYTE color,amount;
 
282
  unsigned int i,j=0;
 
283
 
 
284
  color=gfx[(line*x_size)];
 
285
  amount=1;
 
286
  for (i = 1; i<x_size; i++)
 
287
  {
 
288
    if (gfx[(line*x_size)+i]==color)
 
289
    {
 
290
      amount=amount+1;
 
291
      if (amount==63)
 
292
      {
 
293
        pcxdrv_memmap_pcx_data[j]=0xff;
 
294
        pcxdrv_memmap_pcx_data[j+1]=color;
 
295
        j=j+2;
 
296
        amount=0;
 
297
      }
 
298
    }
 
299
    else
 
300
    {
 
301
      if (amount==0)
 
302
      {
 
303
        color=gfx[(line*x_size)+i];
 
304
        amount=1;
 
305
      }
 
306
      else
 
307
      {
 
308
        if (amount>1)
 
309
        {
 
310
          pcxdrv_memmap_pcx_data[j]=0xc0 | amount;
 
311
          pcxdrv_memmap_pcx_data[j+1]=color;
 
312
          j=j+2;
 
313
          color=gfx[(line*x_size)+i];
 
314
          amount=1;
 
315
        }
 
316
        else
 
317
        {
 
318
          if (color>0xbf)
 
319
          {
 
320
            pcxdrv_memmap_pcx_data[j]=0xc1;
 
321
            pcxdrv_memmap_pcx_data[j+1]=color;
 
322
            j=j+2;
 
323
          }
 
324
          else
 
325
          {
 
326
            pcxdrv_memmap_pcx_data[j]=color;
 
327
            j++;
 
328
          }
 
329
          color=gfx[(line*x_size)+i];
 
330
          amount=1;
 
331
        }
 
332
      }
 
333
    }
 
334
  }
 
335
  if (amount==1)
 
336
  {
 
337
    if (color>0xbf)
 
338
    {
 
339
      pcxdrv_memmap_pcx_data[j]=0xc1;
 
340
      pcxdrv_memmap_pcx_data[j+1]=color;
 
341
      j=j+2;
 
342
    }
 
343
    else
 
344
    {
 
345
      pcxdrv_memmap_pcx_data[j]=color;
 
346
      j++;
 
347
    }
 
348
  }
 
349
  else
 
350
  {
 
351
    if (amount>1)
 
352
    {
 
353
      pcxdrv_memmap_pcx_data[j]=0xc0 | amount;
 
354
      pcxdrv_memmap_pcx_data[j+1]=color;
 
355
      j=j+2;
 
356
    }
 
357
  }
 
358
 
 
359
  if (fwrite(pcxdrv_memmap_pcx_data, j, 1, pcxdrv_memmap_fd)<1)
 
360
    return -1;
 
361
 
 
362
  return 0;
 
363
}
 
364
 
 
365
static int pcxdrv_write_file_header_memmap(int x_size, int y_size)
 
366
{
 
367
  BYTE header[128];
 
368
 
 
369
  memset(header, 0, sizeof(header));
 
370
 
 
371
  header[0]=0xa;
 
372
  header[1]=5;
 
373
  header[2]=1;
 
374
  header[3]=8;
 
375
 
 
376
  util_word_to_le_buf(&header[8], (WORD)(x_size-1));
 
377
  util_word_to_le_buf(&header[10], (WORD)(y_size-1));
 
378
 
 
379
  util_word_to_le_buf(&header[12], (WORD)(0));
 
380
  util_word_to_le_buf(&header[14], (WORD)(0));
 
381
 
 
382
  header[65]=1;
 
383
  util_word_to_le_buf(&header[66], (WORD)(x_size));
 
384
 
 
385
  if (fwrite(header, sizeof(header), 1, pcxdrv_memmap_fd)<1)
 
386
    return -1;
 
387
 
 
388
  return 0;
 
389
}
 
390
 
 
391
static int pcxdrv_open_memmap(const char *filename, int x_size, int y_size)
 
392
{
 
393
  pcxdrv_memmap_ext_filename=util_add_extension_const(filename, pcx_drv.default_extension);
 
394
  pcxdrv_memmap_fd = fopen(pcxdrv_memmap_ext_filename, "wb");
 
395
 
 
396
  if (pcxdrv_memmap_fd==NULL)
 
397
  {
 
398
    lib_free(pcxdrv_memmap_ext_filename);
 
399
    return -1;
 
400
  }
 
401
 
 
402
  if (pcxdrv_write_file_header_memmap(x_size, y_size)<0)
 
403
  {
 
404
    fclose(pcxdrv_memmap_fd);
 
405
    lib_free(pcxdrv_memmap_ext_filename);
 
406
    return -1;
 
407
  }
 
408
 
 
409
  pcxdrv_memmap_pcx_data = (BYTE *)lib_malloc(x_size*2);
 
410
 
 
411
  return 0;
 
412
}
 
413
 
 
414
static int pcxdrv_save_memmap(const char *filename, int x_size, int y_size, BYTE *gfx, BYTE *palette)
 
415
{
 
416
  int line;
 
417
 
 
418
  if (pcxdrv_open_memmap(filename, x_size, y_size) < 0)
 
419
    return -1;
 
420
 
 
421
  for (line = 0; line < y_size; line++)
 
422
  {
 
423
    pcxdrv_write_memmap(line, x_size, gfx);
 
424
  }
 
425
 
 
426
  if (pcxdrv_close_memmap(palette) < 0)
 
427
    return -1;
 
428
 
 
429
  return 0;
 
430
}
 
431
#endif
 
432
 
259
433
static gfxoutputdrv_t pcx_drv =
260
434
{
261
435
    "PCX",
265
439
    pcxdrv_close,
266
440
    pcxdrv_write,
267
441
    pcxdrv_save,
 
442
#ifdef FEATURE_CPUMEMHISTORY
 
443
    NULL,
 
444
    pcxdrv_save_memmap
 
445
#else
268
446
    NULL
 
447
#endif
269
448
};
270
449
 
271
450
void gfxoutput_init_pcx(void)