~ubuntu-branches/debian/squeeze/ghostscript/squeeze

« back to all changes in this revision

Viewing changes to src/gxclist.c

  • Committer: Bazaar Package Importer
  • Author(s): Masayuki Hatta (mhatta)
  • Date: 2009-01-04 12:09:59 UTC
  • mfrom: (16.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090104120959-m9lbagj775ucg0h3
Tags: 8.63.dfsg.1-2
libgs-dev: put versioned dependency on libgs8 - closes: #510691

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
13
 
14
 
/*$Id: gxclist.c 8528 2008-02-17 22:32:15Z leonardo $ */
 
14
/*$Id: gxclist.c 8721 2008-05-09 02:18:14Z ray $ */
15
15
/* Command list document- and page-level code. */
16
16
#include "memory_.h"
17
17
#include "string_.h"
45
45
        case 1: return ENUM_OBJ((cdev->writer.image_enum_id != gs_no_id ?
46
46
                     cdev->writer.color_space.space : 0));
47
47
        case 2: return ENUM_OBJ(cdev->writer.pinst);
 
48
        case 3: return ENUM_OBJ(cdev->writer.cropping_stack);
48
49
        default:
49
50
        return ENUM_USING(st_imager_state, &cdev->writer.imager_state,
50
51
                  sizeof(gs_imager_state), index - 3);
75
76
            RELOC_VAR(cdev->writer.color_space.space);
76
77
        }
77
78
        RELOC_VAR(cdev->writer.pinst);
 
79
        RELOC_VAR(cdev->writer.cropping_stack);
78
80
        RELOC_USING(st_imager_state, &cdev->writer.imager_state,
79
81
            sizeof(gs_imager_state));
80
82
    } else {
87
89
    }
88
90
} RELOC_PTRS_END
89
91
public_st_device_clist();
 
92
private_st_clist_writer_cropping_buffer();
90
93
 
91
94
/* Forward declarations of driver procedures */
92
 
static dev_proc_open_device(clist_open);
 
95
dev_proc_open_device(clist_open);
93
96
static dev_proc_output_page(clist_output_page);
94
97
static dev_proc_close_device(clist_close);
95
98
static dev_proc_get_band(clist_get_band);
464
467
    cdev->undercolor_removal_id = gs_no_id;
465
468
    cdev->device_halftone_id = gs_no_id;
466
469
    cdev->image_enum_id = gs_no_id;
467
 
    cdev->cropping_by_path = false;
 
470
    cdev->cropping_min = cdev->save_cropping_min = 0;
 
471
    cdev->cropping_max = cdev->save_cropping_max = cdev->height;
 
472
    cdev->cropping_stack = NULL;
 
473
    cdev->cropping_level = 0;
 
474
    cdev->mask_id_count = cdev->mask_id = cdev->temp_mask_id = 0;
468
475
    return 0;
469
476
}
470
477
/*
613
620
 
614
621
/* Open the device by initializing the device state and opening the */
615
622
/* scratch files. */
616
 
static int
 
623
int
617
624
clist_open(gx_device *dev)
618
625
{
619
626
    gx_device_clist_writer * const cdev =
661
668
 
662
669
    /* If this is a reader clist, which is about to be reset to a writer,
663
670
     * free any band_complexity_array memory used by same.
 
671
     * since we have been rendering, shut down threads
664
672
     */
665
 
    if (!CLIST_IS_WRITER((gx_device_clist *)dev))
666
 
        gx_clist_reader_free_band_complexity_array( (gx_device_clist *)dev );
 
673
    if (!CLIST_IS_WRITER((gx_device_clist *)dev)) {
 
674
        gx_clist_reader_free_band_complexity_array( (gx_device_clist *)dev );
 
675
        clist_teardown_render_threads(dev);
 
676
    }
667
677
 
668
678
    if (flush) {
669
679
        if (cdev->page_cfile != 0)
878
888
    return min(dev->height - start, band_height);
879
889
}
880
890
 
881
 
 
882
 
 
883
 
 
884
891
/* copy constructor if from != NULL
885
892
 * default constructor if from == NULL
886
893
 */
901
908
#endif
902
909
    }
903
910
}
 
911
 
 
912
int 
 
913
clist_writer_push_no_cropping(gx_device_clist_writer *cdev)
 
914
{
 
915
    clist_writer_cropping_buffer_t *buf = gs_alloc_struct(cdev->memory, 
 
916
                clist_writer_cropping_buffer_t,
 
917
                &st_clist_writer_cropping_buffer, "clist_writer_transparency_push");
 
918
 
 
919
    if (buf == NULL)
 
920
        return_error(gs_error_VMerror);
 
921
    if_debug1('v', "[v]push cropping[%d]\n", cdev->cropping_level);
 
922
    buf->next = cdev->cropping_stack;
 
923
    cdev->cropping_stack = buf;
 
924
    buf->cropping_min = cdev->cropping_min;
 
925
    buf->cropping_max = cdev->cropping_max;
 
926
    buf->mask_id = cdev->mask_id;
 
927
    buf->temp_mask_id = cdev->temp_mask_id;
 
928
    cdev->cropping_level++;
 
929
    return 0;
 
930
}
 
931
 
 
932
int 
 
933
clist_writer_push_cropping(gx_device_clist_writer *cdev, int ry, int rheight)
 
934
{
 
935
    int code = clist_writer_push_no_cropping(cdev);
 
936
    
 
937
    if (code < 0)
 
938
        return 0;
 
939
    cdev->cropping_min = max(cdev->cropping_min, ry);
 
940
    cdev->cropping_max = min(cdev->cropping_max, ry + rheight);
 
941
    return 0;
 
942
}
 
943
 
 
944
int 
 
945
clist_writer_pop_cropping(gx_device_clist_writer *cdev)
 
946
{
 
947
    clist_writer_cropping_buffer_t *buf = cdev->cropping_stack;
 
948
 
 
949
    if (buf == NULL)
 
950
        return_error(gs_error_unregistered); /*Must not happen. */
 
951
    cdev->cropping_min = buf->cropping_min;
 
952
    cdev->cropping_max = buf->cropping_max;
 
953
    cdev->mask_id = buf->mask_id;
 
954
    cdev->temp_mask_id = buf->temp_mask_id;
 
955
    cdev->cropping_stack = buf->next;
 
956
    cdev->cropping_level--;
 
957
    if_debug1('v', "[v]pop cropping[%d]\n", cdev->cropping_level);
 
958
    gs_free_object(cdev->memory, buf, "clist_writer_transparency_pop");
 
959
    return 0;
 
960
}
 
961
 
 
962
int 
 
963
clist_writer_check_empty_cropping_stack(gx_device_clist_writer *cdev)
 
964
{
 
965
    if (cdev->cropping_stack != NULL) {
 
966
        if_debug1('v', "[v]Error: left %d cropping(s)\n", cdev->cropping_level);
 
967
        return_error(gs_error_unregistered); /* Must not happen */
 
968
    }
 
969
    return 0;
 
970
}
 
971
 
 
972
/* Retrieve total size for cfile and bfile. */
 
973
int clist_data_size(const gx_device_clist *cdev, int select)
 
974
{
 
975
    const gx_band_page_info_t *pinfo = &cdev->common.page_info;
 
976
    clist_file_ptr pfile = (!select ? pinfo->bfile : pinfo->cfile);
 
977
    const char *fname = (!select ? pinfo->bfname : pinfo->cfname);
 
978
    int code, size;
 
979
 
 
980
    code = pinfo->io_procs->fseek(pfile, 0, SEEK_END, fname);
 
981
    if (code < 0)
 
982
        return_error(gs_error_unregistered); /* Must not happen. */
 
983
    code = pinfo->io_procs->ftell(pfile);
 
984
    if (code < 0)
 
985
        return_error(gs_error_unregistered); /* Must not happen. */
 
986
    size = code;
 
987
    return size;
 
988
}
 
989
 
 
990
/* Get command list data. */
 
991
int
 
992
clist_get_data(const gx_device_clist *cdev, int select, int offset, byte *buf, int length)
 
993
{
 
994
    const gx_band_page_info_t *pinfo = &cdev->common.page_info;
 
995
    clist_file_ptr pfile = (!select ? pinfo->bfile : pinfo->cfile);
 
996
    const char *fname = (!select ? pinfo->bfname : pinfo->cfname);
 
997
    int code;
 
998
 
 
999
    code = pinfo->io_procs->fseek(pfile, offset, SEEK_SET, fname);
 
1000
    if (code < 0)
 
1001
        return_error(gs_error_unregistered); /* Must not happen. */
 
1002
    /* This assumes that fread_chars doesn't return prematurely
 
1003
       when the buffer is not fully filled and the end of stream is not reached. */
 
1004
    return pinfo->io_procs->fread_chars(buf, length, pfile);
 
1005
}
 
1006
 
 
1007
/* Put command list data. */
 
1008
int
 
1009
clist_put_data(const gx_device_clist *cdev, int select, int offset, const byte *buf, int length)
 
1010
{
 
1011
    const gx_band_page_info_t *pinfo = &cdev->common.page_info;
 
1012
    clist_file_ptr pfile = (!select ? pinfo->bfile : pinfo->cfile);
 
1013
    int code;
 
1014
 
 
1015
    code = pinfo->io_procs->ftell(pfile);
 
1016
    if (code < 0)
 
1017
        return_error(gs_error_unregistered); /* Must not happen. */
 
1018
    if (code != offset) {
 
1019
        /* Assuming a consecutive writing only. */
 
1020
        return_error(gs_error_unregistered); /* Must not happen. */
 
1021
    }
 
1022
    /* This assumes that fwrite_chars doesn't return prematurely
 
1023
       when the buffer is not fully written, except with an error. */
 
1024
    return pinfo->io_procs->fwrite_chars(buf, length, pfile);
 
1025
}
 
1026